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 43KB

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