You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomerController.php 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. <?php
  2. namespace App\Http\Controllers\CustomerService;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use PDF;
  10. use App\Staff;
  11. use App\Model\StaffDetail;
  12. use App\Model\Form;
  13. use App\Model\Subscriber;
  14. use App\Model\WorkOrder;
  15. use App\Model\PackageDetail;
  16. use App\Model\Company;
  17. use App\Model\Coverage;
  18. use App\Model\Product;
  19. use App\Model\Docket;
  20. class CustomerController extends Controller
  21. {
  22. function random_code($limit) {
  23. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  24. }
  25. function createWorkID($limit){
  26. $allowedNumbers = range(0, 9);
  27. shuffle($allowedNumbers);
  28. $digits = array_rand($allowedNumbers, $limit);
  29. $number = '';
  30. foreach($digits as $d){
  31. $number .= $allowedNumbers[$d];
  32. }
  33. $unique_id = $number;
  34. return $unique_id;
  35. }
  36. public function viewCustomer()
  37. {
  38. $id = Auth::guard('cs')->id();
  39. $user = Staff::with('StaffDetail')->find($id);
  40. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  41. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  42. $rs = count(WorkOrder::where('status','Reschedule')->get());
  43. $ss = count(WorkOrder::where('status','Suspend')->get());
  44. $cm = count(WorkOrder::where('status','Completed')->get());
  45. $coverage = Coverage::all();
  46. $company = Company::where('team','Dealer')->get();
  47. return view('customer-service.view_customer',compact('user','pp','sp','rs','ss','cm','coverage','company'));
  48. }
  49. public function getAllNewCustomer($type,$building,$dealer){
  50. $id = Auth::guard('cs')->id();
  51. $user = Staff::with('StaffDetail')->find($id);
  52. $i = 0; $n1 = ''; $street = ''; $labelD = '';
  53. $curr = Carbon::now()->getTimestamp();
  54. $today = Carbon::today();
  55. $dateS = Carbon::createFromFormat('Y-m-d', '2020-01-01');
  56. $start = $dateS->copy()->startOfDay();
  57. $nested_data = array();
  58. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  59. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  60. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  61. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  62. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  63. $form = Form::with(['Subscriber' => function($q) use ($building)
  64. {
  65. $q->where('building_name', $building)->get();
  66. }],'PackageDetail','WorkOrder')->where('type_service',$type)->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  67. }
  68. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  69. $form = Form::with(['Subscriber' => function($q) use ($building)
  70. {
  71. $q->where('building_name', $building)->get();
  72. }],'PackageDetail','WorkOrder')->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  73. }
  74. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  75. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  76. }
  77. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  78. $form = Form::with(['Subscriber' => function($q) use ($building)
  79. {
  80. $q->where('building_name', $building)->get();
  81. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  82. }
  83. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  84. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  85. }
  86. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  87. $form = Form::with(['Subscriber' => function($q) use ($building)
  88. {
  89. $q->where('building_name', $building)->get();
  90. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->whereBetween('created_at', array($start, $today))->orderBy('created_at', 'desc')->get();
  91. }
  92. if(!empty($form)){
  93. foreach ($form as $key => $f) {
  94. if(empty($f->WorkOrder)){
  95. $i++;
  96. $n1 = '';
  97. $reg_time = $f->created_at;
  98. $expiry_date = $reg_time->addDays(3);
  99. $expiry_date = $expiry_date->getTimestamp();
  100. if($curr < $expiry_date) {
  101. $n1 = "New/";
  102. }else{
  103. $n1 = "";
  104. }
  105. if(!empty($f->dealer_id)){
  106. $labelD = "D/";
  107. }else{
  108. $labelD = "";
  109. }
  110. if(!empty($f->Subscriber)){
  111. if($f->Subscriber->street != ''){
  112. $street = $f->Subscriber->street;
  113. }
  114. $wo = '';
  115. if($f->status_email == 'verified'){
  116. $work_order = '';
  117. if($f->type_application == 'R'){
  118. do {
  119. $work_order = 'WO-'.$this->createWorkID(4);
  120. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  121. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  122. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
  123. if(!empty($cov)){
  124. if($cov->status_building == 'non prelaid'){
  125. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  126. }
  127. }
  128. }else if($f->type_application == 'B'){
  129. do {
  130. $work_order = 'WO-'.$this->createWorkID(4);
  131. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  132. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  133. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
  134. if(!empty($cov)){
  135. if($cov->status_building == 'non prelaid'){
  136. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  137. }
  138. }
  139. }
  140. }else if($f->status_email == 'unverified'){
  141. $wo = '';
  142. }
  143. $building = ''; $unit = '-'; $address = ''; $name = '';
  144. if($f->type_application == 'R'){
  145. $name = $f->Subscriber->name;
  146. $building = $f->Subscriber->building_name;
  147. $unit = $f->Subscriber->unit_no;
  148. if($f->Subscriber->street != ''){
  149. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  150. }else {
  151. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  152. }
  153. }else if($f->type_application == 'B'){
  154. $name = $f->Subscriber->company_name;
  155. if($f->Subscriber->unit_no == ''){
  156. $unit = '-';
  157. }else {
  158. $unit = $f->Subscriber->unit_no;
  159. }
  160. $building = $f->Subscriber->street;
  161. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  162. }
  163. $nP = '';
  164. if($f->PackageDetail->voice_fee == 'Yes' || $f->PackageDetail->voice_fee == 'YES'){
  165. $nP = 'Yes';
  166. }else if($f->PackageDetail->voice_fee == 'No' || $f->PackageDetail->voice_fee == 'NO'){
  167. $nP = 'No';
  168. }else if($f->PackageDetail->voice_fee == ''){
  169. $nP = '-';
  170. }
  171. array_push($nested_data, array(
  172. 'formT' => $n1.$i.$f->type_application,
  173. 'type' => $f->type_service,
  174. 'name' => $labelD.$name,
  175. 'phone' => $f->Subscriber->phone1,
  176. 'unit' => $unit,
  177. 'building' => $building,
  178. 'street' => $address,
  179. // 'postcode' => $f->Subscriber->postcode,
  180. // 'city' => $f->Subscriber->city,
  181. 'need_phone' => $nP,
  182. 'email' => $f->status_email,
  183. 'action1' => $wo,
  184. 'action2' => $f->_id
  185. ));
  186. }
  187. }
  188. }
  189. }
  190. return \DataTables::of($nested_data)->make(true);
  191. }
  192. public function getAllNewCustomerss($type,$building,$dealer){
  193. $id = Auth::guard('cs')->id();
  194. $user = Staff::with('StaffDetail')->find($id);
  195. $i = 0; $n1 = ''; $street = ''; $labelD = '';
  196. $curr = Carbon::now()->getTimestamp();
  197. $nested_data = array();
  198. $customer = Subscriber::where('_id','5cb5444ecfe8c571a302d054')->first();
  199. $package = PackageDetail::where('_id','5cb5444ecfe8c571a302d054')->first();
  200. $wo = WorkOrder::where('_id','5cb5444ecfe8c571a302d054')->first();
  201. $f = Form::where('test','ayaya')->first();
  202. dd($f);
  203. $form = Form::with('PackageDetail','WorkOrder','Subscriber')->orderBy('created_at', 'desc')->where('_id','5cb5444ecfe8c571a302d054')->first();
  204. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  205. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  206. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  207. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  208. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  209. $form = Form::with(['Subscriber' => function($q) use ($building)
  210. {
  211. $q->where('building_name', $building)->get();
  212. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  213. }
  214. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  215. $form = Form::with(['Subscriber' => function($q) use ($building)
  216. {
  217. $q->where('building_name', $building)->get();
  218. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  219. }
  220. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  221. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  222. }
  223. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  224. $form = Form::with(['Subscriber' => function($q) use ($building)
  225. {
  226. $q->where('building_name', $building)->get();
  227. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  228. }
  229. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  230. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  231. }
  232. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  233. $form = Form::with(['Subscriber' => function($q) use ($building)
  234. {
  235. $q->where('building_name', $building)->get();
  236. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  237. }
  238. if(!empty($form)){
  239. foreach ($form as $key => $f) {
  240. // if(empty($f->WorkOrder)){
  241. $i++;
  242. $n1 = '';
  243. $reg_time = $f->created_at;
  244. $expiry_date = $reg_time->addDays(3);
  245. $expiry_date = $expiry_date->getTimestamp();
  246. if($curr < $expiry_date) {
  247. $n1 = "New/";
  248. }else{
  249. $n1 = "";
  250. }
  251. if(!empty($f->dealer_id)){
  252. $labelD = "D/";
  253. }else{
  254. $labelD = "";
  255. }
  256. if(!empty($f->Subscriber)){
  257. if($f->Subscriber->street != ''){
  258. $street = $f->Subscriber->street;
  259. }
  260. $wo = '';
  261. if($f->status_email == 'verified'){
  262. $work_order = '';
  263. if($f->type_application == 'R'){
  264. do {
  265. $work_order = 'WO-'.$this->createWorkID(4);
  266. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  267. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  268. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','R')->first();
  269. if(!empty($cov)){
  270. if($cov->status_building == 'non prelaid'){
  271. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  272. }
  273. }
  274. }else if($f->type_application == 'B'){
  275. do {
  276. $work_order = 'WO-'.$this->createWorkID(4);
  277. } while (WorkOrder::where("wo", "=", $work_order)->first() instanceof WorkOrder);
  278. $wo = $work_order.'/'.$f->Subscriber->subscriber_id;
  279. $cov = Coverage::where('building_name',$f->Subscriber->building_name)->where('Type','B')->first();
  280. if(!empty($cov)){
  281. if($cov->status_building == 'non prelaid'){
  282. $wo = 'Non/'.$work_order.'/'.$f->Subscriber->subscriber_id;
  283. }
  284. }
  285. }
  286. }else if($f->status_email == 'unverified'){
  287. $wo = '';
  288. }
  289. array_push($nested_data, array(
  290. $f->_id,
  291. // 'formT' => $n1.$i.$f->type_application,
  292. // 'type' => $f->type_service,
  293. // 'name' => $labelD.$f->Subscriber->name,
  294. // 'phone' => $f->Subscriber->phone1,
  295. // 'unit' => $f->Subscriber->unit_no,
  296. // 'building' => $f->Subscriber->building_name,
  297. // 'street' => $street,
  298. // 'postcode' => $f->Subscriber->postcode,
  299. // 'city' => $f->Subscriber->city,
  300. // 'email' => $f->status_email,
  301. // 'action1' => $wo,
  302. // 'action2' => $f->_id
  303. ));
  304. }
  305. // }
  306. }
  307. }
  308. dd($nested_data);
  309. return \DataTables::of($nested_data)->make(true);
  310. }
  311. public function deleteFormCustomer(Request $request){
  312. $form = Form::where('_id',$request->id)->first();
  313. if(!empty($form)){
  314. $form->delete();
  315. return 'true';
  316. }else {
  317. return 'false';
  318. }
  319. }
  320. public function editSubscriber($subscriber_id){
  321. $id = Auth::guard('cs')->id();
  322. $user = Staff::with('StaffDetail')->find($id);
  323. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  324. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  325. $rs = count(WorkOrder::where('status','Reschedule')->get());
  326. $ss = count(WorkOrder::where('status','Suspend')->get());
  327. $cm = count(WorkOrder::where('status','Completed')->get());
  328. $coverage = Coverage::all();
  329. $form = Subscriber::with('Form')->where('_id',$subscriber_id)->first();
  330. return view('customer-service.edit_subscriber',compact('user','pp','sp','rs','ss','cm','form','coverage'));
  331. }
  332. public function updateCustomerDetail(Request $request){
  333. $form = Subscriber::with('Form')->where('subscriber_id',$request->subscriber_id)->first();
  334. $phone = ''; $street = ''; $fax = '';
  335. if($request->phone2 != null){
  336. $phone = $request->phone2;
  337. }
  338. if($form->Form->type_application == 'R'){
  339. if($request->street != null){
  340. $street = $request->street;
  341. }
  342. $cov = Coverage::where('building_name',$request->building)->first();
  343. if(!empty($cov)){
  344. $building = $cov->building_name;
  345. $postcode = $cov->postcode;
  346. $city = $cov->city;
  347. $state = $cov->state;
  348. }else {
  349. $building = $request->building;
  350. $postcode = '-';
  351. $city = '-';
  352. $state = '-';
  353. }
  354. $form->name = $request->name;
  355. $form->ic = $request->ic;
  356. $form->email = $request->email;
  357. $form->phone1 = $request->phone1;
  358. $form->phone2 = $phone;
  359. $form->unit_no = $request->unit_no;
  360. $form->building_name = $building;
  361. $form->street = $street;
  362. $form->city = $city;
  363. $form->postcode = $postcode;
  364. $form->state = $state;
  365. $form->save();
  366. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  367. }else if($form->Form->type_application == 'B'){
  368. if($request->company_fax != null){
  369. $fax = $request->company_fax;
  370. }
  371. $form->company_reg = $request->company_reg;
  372. $form->company_num = $request->company_num;
  373. $form->company_fax = $fax;
  374. $form->company_name = $request->company_name;
  375. $form->unit_no = $request->unit_no;
  376. $form->street = $request->address;
  377. $form->city = $request->city;
  378. $form->postcode = $request->postcode;
  379. $form->state = $request->state;
  380. $form->name = $request->name;
  381. $form->ic = $request->ic;
  382. $form->designation = $request->designation;
  383. $form->email = $request->email;
  384. $form->phone1 = $request->phone1;
  385. $form->phone2 = $phone;
  386. $form->save();
  387. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  388. }
  389. }
  390. public function generateRPDF($subscriber_id) {
  391. $id = Auth::guard('cs')->id();
  392. $user = Staff::with('StaffDetail')->find($id);
  393. $product = Product::where('formT','R')->orderBy('created_at','asc')->get();
  394. $form = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
  395. $package = PackageDetail::where('_id',$form->_id)->first();
  396. $created_at = Carbon::parse($form->created_at)->toDateTimeString();
  397. $ext1 = pathinfo(public_path().$form->front_ic, PATHINFO_EXTENSION);
  398. $ext2 = pathinfo(public_path().$form->back_ic, PATHINFO_EXTENSION);
  399. $ext3 = pathinfo(public_path().$form->visaF, PATHINFO_EXTENSION);
  400. $ext4 = pathinfo(public_path().$form->visaB, PATHINFO_EXTENSION);
  401. $documentPath = 'document/'.$subscriber_id;
  402. $created = $form->Form->created_at->toDateString();
  403. $total = floatval($package->montly_fee) + floatval($package->deposit) + floatval($package->voice_fee) + floatval($package->upfront_payment);
  404. // dd($total);
  405. $pdf = PDF::loadView('pdf.residential-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','created_at','created'));
  406. $pdf->setPaper('A4', 'potrait');
  407. if(($ext1 == "jpeg" && $ext2 == "jpeg") || ($ext1 == "jpg" && $ext2 == "jpg")){
  408. if(($ext3 == "jpeg" && $ext4 == "jpeg") || ($ext3 == "jpg" && $ext4 == "jpg")){
  409. return $pdf->stream();
  410. }else{
  411. return $pdf->stream();
  412. }
  413. }else if($ext1 == "pdf" && $ext2 == "pdf" && $ext3 == "pdf" && $ext4 == "pdf"){
  414. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  415. $merges = PDFMerger::init();
  416. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  417. $merges->addPDF(public_path().$form->front_ic,'all');
  418. $merges->addPDF(public_path().$form->back_ic,'all');
  419. $merges->addPDF(public_path().$form->visaF,'all');
  420. $merges->addPDF(public_path().$form->visaB,'all');
  421. $merges->merge();
  422. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  423. }else if($ext1 == "pdf" && $ext2 == "pdf"){
  424. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  425. $merges = PDFMerger::init();
  426. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  427. $merges->addPDF(public_path().$form->front_ic,'all');
  428. $merges->addPDF(public_path().$form->back_ic,'all');
  429. $merges->merge();
  430. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  431. }else{
  432. return $pdf->stream();
  433. }
  434. }
  435. public function redirectPDF($sid){
  436. $form = Subscriber::with('Form')->where('_id',$sid)->first();
  437. if($form->Form->type_application == 'R'){
  438. return redirect('/customer-service/residential/generate-pdf/'.$form->subscriber_id);
  439. }else if($form->Form->type_application == 'B'){
  440. return redirect('/customer-service/business/generate-pdf/'.$form->subscriber_id);
  441. }
  442. }
  443. public function generateBPDF($subscriber_id) {
  444. $id = Auth::guard('cs')->id();
  445. $user = Staff::with('StaffDetail')->find($id);
  446. $product = Product::where('formT','B')->get();
  447. $form = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
  448. $package = PackageDetail::where('_id',$form->_id)->first();
  449. $dateSubmittion = date('d/m/Y', strtotime($form->created_at));
  450. $ext1 = pathinfo(public_path().$form->front_ic, PATHINFO_EXTENSION);
  451. $ext2 = pathinfo(public_path().$form->back_ic, PATHINFO_EXTENSION);
  452. $ext3 = pathinfo(public_path().$form->form24_49, PATHINFO_EXTENSION);
  453. $ext4 = pathinfo(public_path().$form->form9_44, PATHINFO_EXTENSION);
  454. $ext5 = pathinfo(public_path().$form->visaF, PATHINFO_EXTENSION);
  455. $ext6 = pathinfo(public_path().$form->visaB, PATHINFO_EXTENSION);
  456. $documentPath = 'document/'.$subscriber_id;
  457. // $pdf = PDF::loadView('pdf.business-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  458. if(strtotime($form->created_at) >= 1580774399){
  459. $pdf = PDF::loadView('pdf.newBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  460. }else {
  461. $pdf = PDF::loadView('pdf.oldBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  462. }
  463. $pdf->setPaper('A4', 'potrait');
  464. if(($ext1 == "jpeg" && $ext2 == "jpeg") || ($ext1 == "jpg" && $ext2 == "jpg") || ($ext1 == "JPG" && $ext2 == "JPG")){
  465. if($ext3 == "pdf" && $ext4 == "pdf"){
  466. if(($ext5 == "jpeg" && $ext6 == "jpeg") || ($ext5 == "jpg" && $ext6 == "jpg") || ($ext5 == "JPG" && $ext6 == "JPG")){
  467. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  468. $merges = PDFMerger::init();
  469. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  470. $merges->addPDF(public_path().$form->form24_49,'all');
  471. $merges->addPDF(public_path().$form->form9_44,'all');
  472. $merges->merge();
  473. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  474. }else if($ext5 == "pdf" && $ext6 == "pdf"){
  475. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  476. $merges = PDFMerger::init();
  477. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  478. $merges->addPDF(public_path().$form->visaF,'all');
  479. $merges->addPDF(public_path().$form->visaB,'all');
  480. $merges->addPDF(public_path().$form->form24_49,'all');
  481. $merges->addPDF(public_path().$form->form9_44,'all');
  482. $merges->merge();
  483. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  484. }else{
  485. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  486. $merges = PDFMerger::init();
  487. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  488. $merges->addPDF(public_path().$form->form24_49,'all');
  489. $merges->addPDF(public_path().$form->form9_44,'all');
  490. $merges->merge();
  491. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  492. }
  493. }else if(($ext3 == "jpeg" && $ext4 == "jpeg") || ($ext3 == "jpg" && $ext4 == "jpg") || ($ext3 == "JPG" && $ext4 == "JPG")){
  494. if(($ext5 == "jpeg" && $ext6 == "jpeg") || ($ext5 == "jpg" && $ext6 == "jpg") || ($ext5 == "JPG" && $ext6 == "JPG")){
  495. return $pdf->stream();
  496. }else if($ext5 == "pdf" && $ext6 == "pdf"){
  497. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  498. $merges = PDFMerger::init();
  499. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  500. $merges->addPDF(public_path().$form->visaF,'all');
  501. $merges->addPDF(public_path().$form->visaB,'all');
  502. $merges->merge();
  503. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  504. }else{
  505. return $pdf->stream();
  506. }
  507. }else if($ext3 == "" && $ext4 == "pdf"){
  508. if(($ext5 == "jpeg" && $ext6 == "jpeg") || ($ext5 == "jpg" && $ext6 == "jpg") || ($ext5 == "JPG" && $ext6 == "JPG")){
  509. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  510. $merges = PDFMerger::init();
  511. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  512. $merges->addPDF(public_path().$form->form9_44,'all');
  513. $merges->merge();
  514. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  515. }else if($ext5 == "pdf" && $ext6 == "pdf"){
  516. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  517. $merges = PDFMerger::init();
  518. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  519. $merges->addPDF(public_path().$form->visaF,'all');
  520. $merges->addPDF(public_path().$form->visaB,'all');
  521. $merges->addPDF(public_path().$form->form9_44,'all');
  522. $merges->merge();
  523. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  524. }else{
  525. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  526. $merges = PDFMerger::init();
  527. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  528. $merges->addPDF(public_path().$form->form9_44,'all');
  529. $merges->merge();
  530. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  531. }
  532. }else if($ext3 == "" && $ext4 == "jpg"){
  533. return $pdf->stream();
  534. }
  535. }else if($ext1 == "pdf" && $ext2 == "pdf"){
  536. if($ext3 == "pdf" && $ext4 == "pdf"){
  537. if($ext5 == "pdf" && $ext6 == "pdf"){
  538. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  539. $merges = PDFMerger::init();
  540. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  541. $merges->addPDF(public_path().$form->front_ic,'all');
  542. $merges->addPDF(public_path().$form->back_ic,'all');
  543. $merges->addPDF(public_path().$form->visaF,'all');
  544. $merges->addPDF(public_path().$form->visaB,'all');
  545. $merges->addPDF(public_path().$form->form24_49,'all');
  546. $merges->addPDF(public_path().$form->form9_44,'all');
  547. $merges->merge();
  548. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  549. }else if(($ext5 == "jpeg" && $ext6 == "jpeg") || ($ext5 == "jpg" && $ext6 == "jpg") || ($ext5 == "JPG" && $ext6 == "JPG")){
  550. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  551. $merges = PDFMerger::init();
  552. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  553. $merges->addPDF(public_path().$form->front_ic,'all');
  554. $merges->addPDF(public_path().$form->back_ic,'all');
  555. $merges->addPDF(public_path().$form->form24_49,'all');
  556. $merges->addPDF(public_path().$form->form9_44,'all');
  557. $merges->merge();
  558. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  559. }else{
  560. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  561. $merges = PDFMerger::init();
  562. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  563. $merges->addPDF(public_path().$form->front_ic,'all');
  564. $merges->addPDF(public_path().$form->back_ic,'all');
  565. $merges->addPDF(public_path().$form->form24_49,'all');
  566. $merges->addPDF(public_path().$form->form9_44,'all');
  567. $merges->merge();
  568. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  569. }
  570. }else if(($ext3 == "jpeg" && $ext4 == "jpeg") || ($ext3 == "jpg" && $ext4 == "jpg") || ($ext3 == "JPG" && $ext4 == "JPG")){
  571. if($ext5 == "pdf" && $ext6 == "pdf"){
  572. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  573. $merges = PDFMerger::init();
  574. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  575. $merges->addPDF(public_path().$form->front_ic,'all');
  576. $merges->addPDF(public_path().$form->back_ic,'all');
  577. $merges->addPDF(public_path().$form->visaF,'all');
  578. $merges->addPDF(public_path().$form->visaB,'all');
  579. $merges->merge();
  580. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  581. }else if(($ext5 == "jpeg" && $ext6 == "jpeg") || ($ext5 == "jpg" && $ext6 == "jpg") || ($ext5 == "JPG" && $ext6 == "JPG")){
  582. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  583. $merges = PDFMerger::init();
  584. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  585. $merges->addPDF(public_path().$form->front_ic,'all');
  586. $merges->addPDF(public_path().$form->back_ic,'all');
  587. $merges->merge();
  588. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  589. }else{
  590. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  591. $merges = PDFMerger::init();
  592. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  593. $merges->addPDF(public_path().$form->front_ic,'all');
  594. $merges->addPDF(public_path().$form->back_ic,'all');
  595. $merges->merge();
  596. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  597. }
  598. }else if($ext3 == "" && $ext4 == "pdf"){
  599. if($ext5 == "pdf" && $ext6 == "pdf"){
  600. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  601. $merges = PDFMerger::init();
  602. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  603. $merges->addPDF(public_path().$form->visaF,'all');
  604. $merges->addPDF(public_path().$form->visaB,'all');
  605. $merges->addPDF(public_path().$form->form9_44,'all');
  606. $merges->merge();
  607. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  608. }else{
  609. $pdf->save(public_path('/'.$documentPath.'/application.pdf'));
  610. $merges = PDFMerger::init();
  611. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  612. $merges->addPDF(public_path().$form->form9_44,'all');
  613. $merges->merge();
  614. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  615. }
  616. }
  617. }else {
  618. return $pdf->stream();
  619. }
  620. }
  621. public function viewSubscriber()
  622. {
  623. $id = Auth::guard('cs')->id();
  624. $user = Staff::with('StaffDetail')->find($id);
  625. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  626. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  627. $rs = count(WorkOrder::where('status','Reschedule')->get());
  628. $ss = count(WorkOrder::where('status','Suspend')->get());
  629. $cm = count(WorkOrder::where('status','Completed')->get());
  630. $rec = count(WorkOrder::where('nature_work','Rectification')->get());
  631. $re = count(Form::where('type_application','R')->get());
  632. $bu = count(Form::where('type_application','B')->get());
  633. $coverage = Coverage::all();
  634. $company = Company::where('team','Dealer')->get();
  635. return view('customer-service.view_subscriber', compact('user','pp','sp','rs','ss','cm','rec','re','bu','coverage','company'));
  636. }
  637. public function getAllRectification($type,$building,$dealer){
  638. $id = Auth::guard('cs')->id();
  639. $user = Staff::with('StaffDetail')->find($id);
  640. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  641. $curr = Carbon::now()->getTimestamp();
  642. $nested_data = array();
  643. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  644. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  645. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  646. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  647. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  648. $form = Form::with(['Subscriber' => function($q) use ($building)
  649. {
  650. $q->where('building_name', $building)->get();
  651. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  652. }
  653. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  654. $form = Form::with(['Subscriber' => function($q) use ($building)
  655. {
  656. $q->where('building_name', $building)->get();
  657. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  658. }
  659. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  660. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  661. }
  662. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  663. $form = Form::with(['Subscriber' => function($q) use ($building)
  664. {
  665. $q->where('building_name', $building)->get();
  666. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  667. }
  668. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  669. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  670. }
  671. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  672. $form = Form::with(['Subscriber' => function($q) use ($building)
  673. {
  674. $q->where('building_name', $building)->get();
  675. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  676. }
  677. $wo = 'null'; $do = 'null';
  678. if(!empty($form)){
  679. foreach ($form as $key => $f) {
  680. if(!empty($f->WorkOrder)){
  681. if($f->WorkOrder->nature_work == "Rectification" || $f->type_service == "Rectification") {
  682. $wo = $f->WorkOrder->wo;
  683. if($f->WorkOrder->status == "Completed"){
  684. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  685. if(!empty($doc)){
  686. $do = $doc->docket_id;
  687. }
  688. }else{
  689. $wo = $f->WorkOrder->wo;
  690. $do = "null";
  691. }
  692. $i++;
  693. $n1 = '';
  694. $reg_time = $f->created_at;
  695. $expiry_date = $reg_time->addDays(3);
  696. $expiry_date = $expiry_date->getTimestamp();
  697. if($curr < $expiry_date) {
  698. $n1 = "New/";
  699. }
  700. if(!empty($f->dealer_id)){
  701. $labelD = "D/";
  702. }
  703. if(!empty($f->Subscriber)){
  704. if($f->Subscriber->street != ''){
  705. $street = $f->Subscriber->street;
  706. }
  707. $name = '';
  708. if($f->type_application == 'R'){
  709. $name = $f->Subscriber->name;
  710. }else if($f->type_application == 'B'){
  711. $name = $f->Subscriber->building_name;
  712. }
  713. array_push($nested_data, array(
  714. 'formT' => $n1.$i.$f->type_application,
  715. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  716. 'type' => $f->type_service,
  717. 'name' => $labelD.$name,
  718. 'phone' => $f->Subscriber->phone1,
  719. 'unit' => $f->Subscriber->unit_no,
  720. 'building' => $f->Subscriber->building_name,
  721. 'street' => $street,
  722. 'postcode' => $f->Subscriber->postcode,
  723. 'city' => $f->Subscriber->city,
  724. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  725. 'action2' => $wo,
  726. 'action3' => $do
  727. ));
  728. }
  729. }
  730. }
  731. }
  732. }
  733. return \DataTables::of($nested_data)->make(true);
  734. }
  735. public function getAllResidential($type,$building,$dealer){
  736. $id = Auth::guard('cs')->id();
  737. $user = Staff::with('StaffDetail')->find($id);
  738. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  739. $curr = Carbon::now()->getTimestamp();
  740. $nested_data = array();
  741. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  742. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  743. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  744. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  745. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  746. $form = Form::with(['Subscriber' => function($q) use ($building)
  747. {
  748. $q->where('building_name', $building)->get();
  749. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  750. }
  751. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  752. $form = Form::with(['Subscriber' => function($q) use ($building)
  753. {
  754. $q->where('building_name', $building)->get();
  755. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  756. }
  757. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  758. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  759. }
  760. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  761. $form = Form::with(['Subscriber' => function($q) use ($building)
  762. {
  763. $q->where('building_name', $building)->get();
  764. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  765. }
  766. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  767. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  768. }
  769. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  770. $form = Form::with(['Subscriber' => function($q) use ($building)
  771. {
  772. $q->where('building_name', $building)->get();
  773. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  774. }
  775. $wo = 'null'; $do = 'null';
  776. if(!empty($form)){
  777. foreach ($form as $key => $f) {
  778. if(!empty($f->WorkOrder)){
  779. $wo = $f->WorkOrder->wo;
  780. if($f->WorkOrder->status == "Completed"){
  781. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  782. if(!empty($doc)){
  783. $do = $doc->docket_id;
  784. }
  785. }else{
  786. $wo = $f->WorkOrder->wo;
  787. $do = "null";
  788. }
  789. }else {
  790. $wo = "null";
  791. $do = "null";
  792. }
  793. if($f->type_application == 'R' && $f->type_service != "Rectification"){
  794. $i++;
  795. $n1 = '';
  796. $reg_time = $f->created_at;
  797. $expiry_date = $reg_time->addDays(3);
  798. $expiry_date = $expiry_date->getTimestamp();
  799. if($curr < $expiry_date) {
  800. $n1 = "New/";
  801. }else{
  802. $n1 = "";
  803. }
  804. if(!empty($f->dealer_id)){
  805. $labelD = "D/";
  806. }else {
  807. $labelD = "";
  808. }
  809. if(!empty($f->Subscriber)){
  810. if($f->Subscriber->street != ''){
  811. $street = $f->Subscriber->street;
  812. }
  813. array_push($nested_data, array(
  814. 'formT' => $n1.$i.$f->type_application,
  815. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  816. 'type' => $f->type_service,
  817. 'name' => $labelD.$f->Subscriber->name,
  818. 'phone' => $f->Subscriber->phone1,
  819. 'unit' => $f->Subscriber->unit_no,
  820. 'building' => $f->Subscriber->building_name,
  821. 'street' => $street,
  822. 'postcode' => $f->Subscriber->postcode,
  823. 'city' => $f->Subscriber->city,
  824. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  825. 'action2' => $wo,
  826. 'action3' => $do
  827. ));
  828. }
  829. }
  830. }
  831. }
  832. return \DataTables::of($nested_data)->make(true);
  833. }
  834. public function getAllBusiness($type,$building,$dealer){
  835. $id = Auth::guard('cs')->id();
  836. $user = Staff::with('StaffDetail')->find($id);
  837. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  838. $curr = Carbon::now()->getTimestamp();
  839. $nested_data = array();
  840. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  841. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  842. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  843. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  844. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  845. $form = Form::with(['Subscriber' => function($q) use ($building)
  846. {
  847. $q->where('building_name', $building)->get();
  848. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  849. }
  850. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  851. $form = Form::with(['Subscriber' => function($q) use ($building)
  852. {
  853. $q->where('building_name', $building)->get();
  854. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  855. }
  856. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  857. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  858. }
  859. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  860. $form = Form::with(['Subscriber' => function($q) use ($building)
  861. {
  862. $q->where('building_name', $building)->get();
  863. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  864. }
  865. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  866. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  867. }
  868. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  869. $form = Form::with(['Subscriber' => function($q) use ($building)
  870. {
  871. $q->where('building_name', $building)->get();
  872. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  873. }
  874. $wo = 'null'; $do = 'null';
  875. if(!empty($form)){
  876. foreach ($form as $key => $f) {
  877. if(!empty($f->WorkOrder)){
  878. $wo = $f->WorkOrder->wo;
  879. if($f->WorkOrder->status == "Completed"){
  880. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  881. if(!empty($doc)){
  882. $do = $doc->docket_id;
  883. }
  884. }else{
  885. $wo = $f->WorkOrder->wo;
  886. $do = "null";
  887. }
  888. }else {
  889. $wo = "null";
  890. $do = "null";
  891. }
  892. if($f->type_application == 'B' && $f->type_service != "Rectification"){
  893. $i++;
  894. $n1 = '';
  895. $reg_time = $f->created_at;
  896. $expiry_date = $reg_time->addDays(3);
  897. $expiry_date = $expiry_date->getTimestamp();
  898. if($curr < $expiry_date) {
  899. $n1 = "New/";
  900. }else{
  901. $n1 = "";
  902. }
  903. if(!empty($f->dealer_id)){
  904. $labelD = "D/";
  905. }else {
  906. $labelD = "";
  907. }
  908. if(!empty($f->Subscriber)){
  909. if($f->Subscriber->street != ''){
  910. $street = $f->Subscriber->street;
  911. }
  912. array_push($nested_data, array(
  913. 'formT' => $n1.$i.$f->type_application,
  914. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  915. 'type' => $f->type_service,
  916. 'name' => $labelD.$f->Subscriber->company_name,
  917. 'phone' => $f->Subscriber->phone1,
  918. 'unit' => $f->Subscriber->unit_no,
  919. 'building' => $f->Subscriber->building_name,
  920. 'street' => $street,
  921. 'postcode' => $f->Subscriber->postcode,
  922. 'city' => $f->Subscriber->city,
  923. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  924. 'action2' => $wo,
  925. 'action3' => $do
  926. ));
  927. }
  928. }
  929. }
  930. }
  931. return \DataTables::of($nested_data)->make(true);
  932. }
  933. public function getCustomerWo()
  934. {
  935. $curr = Carbon::now()->getTimestamp();
  936. $work_detail= WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
  937. $i = 0;
  938. $nested_data = array();
  939. if(!empty($work_detail)){
  940. foreach ($work_detail as $a)
  941. {
  942. $i++; $y = ''; $n1 = '';
  943. $reg_time = $a->created_at;
  944. $expiry_date = $reg_time->addDays(3);
  945. $expiry_date = $expiry_date->getTimestamp();
  946. if($curr < $expiry_date) {
  947. $n1 = "New/";
  948. }
  949. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  950. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  951. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  952. $inst_name = '';
  953. if(!empty($installer)){
  954. $inst_name = $installer->name;
  955. }
  956. array_push($nested_data, array(
  957. 'index' => $i.$n1,
  958. 'nature_work' => $a->nature_work,
  959. 'wo'=>$a->wo,
  960. 'customer_name' => $formDetail->SubscribersLaravel->name,
  961. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  962. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  963. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  964. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  965. 'customer_city' => $formDetail->SubscribersLaravel->city,
  966. 'contractor_id' => $contractor->name,
  967. 'installer_id' => $inst_name,
  968. 'dateTimeEnd' => $a->dateTimeEnd,
  969. 'status' => $a->status,
  970. 'action' => $a->id,
  971. ));
  972. }
  973. }
  974. return \DataTables::of($nested_data)->make(true);
  975. }
  976. public function filterCustomerWo($year, $month, $status)
  977. {
  978. $curr = Carbon::now()->getTimestamp();
  979. if($year == 'null' && $month == 'null' & $status !='null')
  980. {
  981. $nested_data = array();
  982. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->where('status', $status)->get();
  983. $i = 0;
  984. $nested_data = array();
  985. if(!empty($work_detail)){
  986. foreach ($work_detail as $a)
  987. {
  988. $i++; $y = ''; $n1 = '';
  989. $reg_time = $a->created_at;
  990. $expiry_date = $reg_time->addDays(3);
  991. $expiry_date = $expiry_date->getTimestamp();
  992. if($curr < $expiry_date) {
  993. $n1 = "New/";
  994. }else {
  995. $n1 = "";
  996. }
  997. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  998. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  999. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  1000. $inst_name = '';
  1001. if(!empty($installer)){
  1002. $inst_name = $installer->name;
  1003. }
  1004. array_push($nested_data, array(
  1005. 'index' => $i.$n1,
  1006. 'nature_work' => $a->nature_work,
  1007. 'wo'=>$a->wo,
  1008. 'customer_name' => $formDetail->SubscribersLaravel->name,
  1009. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  1010. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  1011. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  1012. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  1013. 'customer_city' => $formDetail->SubscribersLaravel->city,
  1014. 'contractor_id' => $contractor->name,
  1015. 'installer_id' => $inst_name,
  1016. 'dateTimeEnd' => $a->dateTimeEnd,
  1017. 'status' => $a->status,
  1018. 'action' => $a->id,
  1019. ));
  1020. }
  1021. }
  1022. }
  1023. if($year=='null' && $month == 'null' & $status == 'null')
  1024. {
  1025. $nested_data = array();
  1026. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
  1027. $i = 0;
  1028. $nested_data = array();
  1029. if(!empty($work_detail)){
  1030. foreach ($work_detail as $a)
  1031. {
  1032. $i++; $y = ''; $n1 = '';
  1033. $reg_time = $a->created_at;
  1034. $expiry_date = $reg_time->addDays(3);
  1035. $expiry_date = $expiry_date->getTimestamp();
  1036. if($curr < $expiry_date) {
  1037. $n1 = "New/";
  1038. }else {
  1039. $n1 = "";
  1040. }
  1041. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  1042. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  1043. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  1044. $inst_name = '';
  1045. if(!empty($installer)){
  1046. $inst_name = $installer->name;
  1047. }
  1048. array_push($nested_data, array(
  1049. 'index' => $i.$n1,
  1050. 'nature_work' => $a->nature_work,
  1051. 'wo'=>$a->wo,
  1052. 'customer_name' => $formDetail->SubscribersLaravel->name,
  1053. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  1054. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  1055. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  1056. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  1057. 'customer_city' => $formDetail->SubscribersLaravel->city,
  1058. 'contractor_id' => $contractor->name,
  1059. 'installer_id' => $inst_name,
  1060. 'dateTimeEnd' => $a->dateTimeEnd,
  1061. 'status' => $a->status,
  1062. 'action' => $a->id,
  1063. ));
  1064. }
  1065. }
  1066. }
  1067. if($year!='null' && $month!='nulll' && $status !='null')
  1068. {
  1069. $nested_data = array();
  1070. $start_month = $year."-".$month."-01 00:00:00";
  1071. $end_month = $year."-".$month."-32 23:59:59";
  1072. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
  1073. $i = 0;
  1074. $nested_data = array();
  1075. if(!empty($work_detail)){
  1076. foreach ($work_detail as $a)
  1077. {
  1078. $i++; $y = ''; $n1 = '';
  1079. $reg_time = $a->created_at;
  1080. $expiry_date = $reg_time->addDays(3);
  1081. $expiry_date = $expiry_date->getTimestamp();
  1082. if($curr < $expiry_date) {
  1083. $n1 = "New/";
  1084. }else {
  1085. $n1 = "";
  1086. }
  1087. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  1088. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  1089. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  1090. $inst_name = '';
  1091. if(!empty($installer)){
  1092. $inst_name = $installer->name;
  1093. }
  1094. array_push($nested_data, array(
  1095. 'index' => $i.$n1,
  1096. 'nature_work' => $a->nature_work,
  1097. 'wo'=>$a->wo,
  1098. 'customer_name' => $formDetail->SubscribersLaravel->name,
  1099. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  1100. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  1101. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  1102. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  1103. 'customer_city' => $formDetail->SubscribersLaravel->city,
  1104. 'contractor_id' => $contractor->name,
  1105. 'installer_id' => $inst_name,
  1106. 'dateTimeEnd' => $a->dateTimeEnd,
  1107. 'status' => $a->status,
  1108. 'action' => $a->id,
  1109. ));
  1110. }
  1111. }
  1112. }
  1113. if($year!='null' && $month!='null' && $status =='null')
  1114. {
  1115. $nested_data = array();
  1116. $start_month = $year."-".$month."-01 00:00:00";
  1117. $end_month = $year."-".$month."-32 23:59:59";
  1118. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
  1119. $i = 0;
  1120. $nested_data = array();
  1121. if(!empty($work_detail)){
  1122. foreach ($work_detail as $a)
  1123. {
  1124. $i++; $y = ''; $n1 = '';
  1125. $reg_time = $a->created_at;
  1126. $expiry_date = $reg_time->addDays(3);
  1127. $expiry_date = $expiry_date->getTimestamp();
  1128. if($curr < $expiry_date) {
  1129. $n1 = "New/";
  1130. }else {
  1131. $n1 = "";
  1132. }
  1133. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  1134. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  1135. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  1136. $inst_name = '';
  1137. if(!empty($installer)){
  1138. $inst_name = $installer->name;
  1139. }
  1140. array_push($nested_data, array(
  1141. 'index' => $i.$n1,
  1142. 'nature_work' => $a->nature_work,
  1143. 'wo'=>$a->wo,
  1144. 'customer_name' => $formDetail->SubscribersLaravel->name,
  1145. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  1146. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  1147. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  1148. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  1149. 'customer_city' => $formDetail->SubscribersLaravel->city,
  1150. 'contractor_id' => $contractor->name,
  1151. 'installer_id' => $inst_name,
  1152. 'dateTimeEnd' => $a->dateTimeEnd,
  1153. 'status' => $a->status,
  1154. 'action' => $a->id,
  1155. ));
  1156. }
  1157. }
  1158. }
  1159. return \DataTables::of($nested_data)->make(true);
  1160. }
  1161. public function deleteCustomerWo(Request $request)
  1162. {
  1163. $wo = WorkOrderLaravel::where('_id',$request->id)->first();
  1164. if(!empty($wo)){
  1165. $wo->delete();
  1166. return 'true';
  1167. }else {
  1168. return 'false';
  1169. }
  1170. }
  1171. public function getCountry()
  1172. {
  1173. $jsonString = file_get_contents(base_path('resources/views/customer-service/country.json'));
  1174. $data = json_decode($jsonString, true);
  1175. return $jsonString;
  1176. }
  1177. public function getBuilding()
  1178. {
  1179. $wK = Coverage::all();
  1180. $data = array();
  1181. foreach ($wK as $key=>$w) {
  1182. array_push($data, array(
  1183. 'name' => $w->address,
  1184. ));
  1185. }
  1186. // Read and parse our events JSON file into an array of event data arrays.
  1187. $json = json_encode($data);
  1188. // Send JSON to the client.
  1189. echo $json;
  1190. }
  1191. }