選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CustomerController.php 43KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  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(500)->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. $total = floatval($package->montly_fee) + floatval($package->deposit) + floatval($package->voice_fee) + floatval($package->upfront_payment);
  400. // dd($total);
  401. $pdf = PDF::loadView('pdf.residential-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','created_at','created'));
  402. $pdf->setPaper('A4', 'potrait');
  403. if($ext1 == "pdf" || $ext2 == "pdf" || $ext3 == "pdf" || $ext4 == "pdf" || $ext5 == "pdf" || $ext6 == "pdf" ){
  404. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  405. $merges = PDFMerger::init();
  406. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  407. if($ext1 == "pdf"){
  408. $merges->addPDF(public_path().$form->front_ic,'all');
  409. }
  410. if($ext2 == "pdf"){
  411. $merges->addPDF(public_path().$form->back_ic,'all');
  412. }
  413. if($ext3 == "pdf"){
  414. $merges->addPDF(public_path().$form->visaF,'all');
  415. }
  416. if($ext4 == "pdf"){
  417. $merges->addPDF(public_path().$form->visaB,'all');
  418. }
  419. if($ext5 == "pdf"){
  420. $merges->addPDF(public_path().$form->paymentReceipt,'all');
  421. }
  422. if($ext6 == "pdf"){
  423. $merges->addPDF(public_path().$form->soForm,'all');
  424. }
  425. $merges->merge();
  426. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  427. }else if(($ext1 == "jpeg" || $ext1 == "jpg" || $ext1 == "png" ) || ($ext2 == "jpeg" || $ext2 == "jpg" || $ext2 == "png" ) ||
  428. ($ext3 == "jpeg" || $ext3 == "jpg" || $ext3 == "png" ) ||($ext4 == "jpeg" || $ext4 == "jpg" || $ext4 == "png" ) ||
  429. ($ext5 == "jpeg" || $ext5 == "jpg" || $ext5 == "png" ) ||($ext6 == "jpeg" || $ext6 == "jpg" || $ext6 == "png" )){
  430. return $pdf->stream();
  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->form9_44, PATHINFO_EXTENSION);
  453. $ext4 = pathinfo(public_path().$form->paymentReceipt, PATHINFO_EXTENSION);
  454. $ext5 = pathinfo(public_path().$form->soForm, PATHINFO_EXTENSION);
  455. $documentPath = 'document/'.$subscriber_id;
  456. // $pdf = PDF::loadView('pdf.business-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  457. if(strtotime($form->created_at) >= 1580774399){
  458. $pdf = PDF::loadView('pdf.newBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','dateSubmittion'));
  459. }else {
  460. $pdf = PDF::loadView('pdf.oldBusiness-pdf', compact('form','package','product','ext1','ext2','ext3','ext4','ext5','ext6','dateSubmittion'));
  461. }
  462. $pdf->setPaper('A4', 'potrait');
  463. if($ext1 == "pdf" || $ext2 == "pdf" || $ext3 == "pdf" || $ext4 == "pdf" || $ext5 == "pdf" ){
  464. $pdf->save(public_path().'/'.$documentPath.'/application.pdf');
  465. $merges = PDFMerger::init();
  466. $merges->addPDF(public_path().'/'.$documentPath.'/application.pdf', 'all');
  467. if($ext1 == "pdf"){
  468. $merges->addPDF(public_path().$form->front_ic,'all');
  469. }
  470. if($ext2 == "pdf"){
  471. $merges->addPDF(public_path().$form->back_ic,'all');
  472. }
  473. if($ext3 == "pdf"){
  474. $merges->addPDF(public_path().$form->form9_44,'all');
  475. }
  476. if($ext4 == "pdf"){
  477. $merges->addPDF(public_path().$form->paymentReceipt,'all');
  478. }
  479. if($ext5 == "pdf"){
  480. $merges->addPDF(public_path().$form->soForm,'all');
  481. }
  482. $merges->merge();
  483. $merges->save(public_path().'/'.$documentPath.'/'.$subscriber_id.'.pdf',"browser");
  484. }else if(($ext1 == "jpeg" || $ext1 == "jpg" || $ext1 == "png" ) || ($ext2 == "jpeg" || $ext2 == "jpg" || $ext2 == "png" ) ||
  485. ($ext3 == "jpeg" || $ext3 == "jpg" || $ext3 == "png" ) ||($ext4 == "jpeg" || $ext4 == "jpg" || $ext4 == "png" ) ||
  486. ($ext5 == "jpeg" || $ext5 == "jpg" || $ext5 == "png" )){
  487. return $pdf->stream();
  488. }else {
  489. return $pdf->stream();
  490. }
  491. }
  492. public function viewSubscriber()
  493. {
  494. $id = Auth::guard('cs')->id();
  495. $user = Staff::with('StaffDetail')->find($id);
  496. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  497. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  498. $rs = count(WorkOrder::where('status','Reschedule')->get());
  499. $ss = count(WorkOrder::where('status','Suspend')->get());
  500. $cm = count(WorkOrder::where('status','Completed')->get());
  501. $rec = count(WorkOrder::where('nature_work','Rectification')->get());
  502. $re = count(Form::where('type_application','R')->get());
  503. $bu = count(Form::where('type_application','B')->get());
  504. $coverage = Coverage::all();
  505. $company = Company::where('team','Dealer')->get();
  506. return view('customer-service.view_subscriber', compact('user','pp','sp','rs','ss','cm','rec','re','bu','coverage','company'));
  507. }
  508. public function getAllRectification($type,$building,$dealer){
  509. $id = Auth::guard('cs')->id();
  510. $user = Staff::with('StaffDetail')->find($id);
  511. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  512. $curr = Carbon::now()->getTimestamp();
  513. $nested_data = array();
  514. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  515. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  516. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  517. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  518. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  519. $form = Form::with(['Subscriber' => function($q) use ($building)
  520. {
  521. $q->where('building_name', $building)->get();
  522. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  523. }
  524. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  525. $form = Form::with(['Subscriber' => function($q) use ($building)
  526. {
  527. $q->where('building_name', $building)->get();
  528. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  529. }
  530. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  531. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  532. }
  533. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  534. $form = Form::with(['Subscriber' => function($q) use ($building)
  535. {
  536. $q->where('building_name', $building)->get();
  537. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  538. }
  539. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  540. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  541. }
  542. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  543. $form = Form::with(['Subscriber' => function($q) use ($building)
  544. {
  545. $q->where('building_name', $building)->get();
  546. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  547. }
  548. $wo = 'null'; $do = 'null';
  549. if(!empty($form)){
  550. foreach ($form as $key => $f) {
  551. if(!empty($f->WorkOrder)){
  552. if($f->WorkOrder->nature_work == "Rectification" || $f->type_service == "Rectification") {
  553. $wo = $f->WorkOrder->wo;
  554. if($f->WorkOrder->status == "Completed"){
  555. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  556. if(!empty($doc)){
  557. $do = $doc->docket_id;
  558. }
  559. }else{
  560. $wo = $f->WorkOrder->wo;
  561. $do = "null";
  562. }
  563. $i++;
  564. $n1 = '';
  565. $reg_time = $f->created_at;
  566. $expiry_date = $reg_time->addDays(3);
  567. $expiry_date = $expiry_date->getTimestamp();
  568. if($curr < $expiry_date) {
  569. $n1 = "New/";
  570. }
  571. if(!empty($f->dealer_id)){
  572. $labelD = "D/";
  573. }
  574. if(!empty($f->Subscriber)){
  575. if($f->Subscriber->street != ''){
  576. $street = $f->Subscriber->street;
  577. }
  578. $name = '';
  579. if($f->type_application == 'R'){
  580. $name = $f->Subscriber->name;
  581. }else if($f->type_application == 'B'){
  582. $name = $f->Subscriber->building_name;
  583. }
  584. array_push($nested_data, array(
  585. 'formT' => $n1.$i.$f->type_application,
  586. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  587. 'type' => $f->type_service,
  588. 'name' => $labelD.$name,
  589. 'phone' => $f->Subscriber->phone1,
  590. 'unit' => $f->Subscriber->unit_no,
  591. 'building' => $f->Subscriber->building_name,
  592. 'street' => $street,
  593. 'postcode' => $f->Subscriber->postcode,
  594. 'city' => $f->Subscriber->city,
  595. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  596. 'action2' => $wo,
  597. 'action3' => $do
  598. ));
  599. }
  600. }
  601. }
  602. }
  603. }
  604. return \DataTables::of($nested_data)->make(true);
  605. }
  606. public function getAllResidential($type,$building,$dealer){
  607. $id = Auth::guard('cs')->id();
  608. $user = Staff::with('StaffDetail')->find($id);
  609. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  610. $curr = Carbon::now()->getTimestamp();
  611. $nested_data = array();
  612. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  613. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  614. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  615. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  616. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  617. $form = Form::with(['Subscriber' => function($q) use ($building)
  618. {
  619. $q->where('building_name', $building)->get();
  620. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  621. }
  622. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  623. $form = Form::with(['Subscriber' => function($q) use ($building)
  624. {
  625. $q->where('building_name', $building)->get();
  626. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  627. }
  628. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  629. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  630. }
  631. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  632. $form = Form::with(['Subscriber' => function($q) use ($building)
  633. {
  634. $q->where('building_name', $building)->get();
  635. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  636. }
  637. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  638. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  639. }
  640. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  641. $form = Form::with(['Subscriber' => function($q) use ($building)
  642. {
  643. $q->where('building_name', $building)->get();
  644. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  645. }
  646. $wo = 'null'; $do = 'null';
  647. if(!empty($form)){
  648. foreach ($form as $key => $f) {
  649. if(!empty($f->WorkOrder)){
  650. $wo = $f->WorkOrder->wo;
  651. if($f->WorkOrder->status == "Completed"){
  652. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  653. if(!empty($doc)){
  654. $do = $doc->docket_id;
  655. }
  656. }else{
  657. $wo = $f->WorkOrder->wo;
  658. $do = "null";
  659. }
  660. }else {
  661. $wo = "null";
  662. $do = "null";
  663. }
  664. if($f->type_application == 'R' && $f->type_service != "Rectification"){
  665. $i++;
  666. $n1 = '';
  667. $reg_time = $f->created_at;
  668. $expiry_date = $reg_time->addDays(3);
  669. $expiry_date = $expiry_date->getTimestamp();
  670. if($curr < $expiry_date) {
  671. $n1 = "New/";
  672. }else{
  673. $n1 = "";
  674. }
  675. if(!empty($f->dealer_id)){
  676. $labelD = "D/";
  677. }else {
  678. $labelD = "";
  679. }
  680. if(!empty($f->Subscriber)){
  681. if($f->Subscriber->street != ''){
  682. $street = $f->Subscriber->street;
  683. }
  684. array_push($nested_data, array(
  685. 'formT' => $n1.$i.$f->type_application,
  686. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  687. 'type' => $f->type_service,
  688. 'name' => $labelD.$f->Subscriber->name,
  689. 'phone' => $f->Subscriber->phone1,
  690. 'unit' => $f->Subscriber->unit_no,
  691. 'building' => $f->Subscriber->building_name,
  692. 'street' => $street,
  693. 'postcode' => $f->Subscriber->postcode,
  694. 'city' => $f->Subscriber->city,
  695. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  696. 'action2' => $wo,
  697. 'action3' => $do
  698. ));
  699. }
  700. }
  701. }
  702. }
  703. return \DataTables::of($nested_data)->make(true);
  704. }
  705. public function getAllBusiness($type,$building,$dealer){
  706. $id = Auth::guard('cs')->id();
  707. $user = Staff::with('StaffDetail')->find($id);
  708. $i = 0; $n1 = ''; $street = ''; $labelD = ''; $wo = '';
  709. $curr = Carbon::now()->getTimestamp();
  710. $nested_data = array();
  711. if($type == 'null' && $building == 'null' && $dealer == 'null'){
  712. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  713. }else if($type != 'null' && $building == 'null' && $dealer == 'null'){
  714. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  715. }else if($type != 'null' && $building != 'null' && $dealer == 'null'){
  716. $form = Form::with(['Subscriber' => function($q) use ($building)
  717. {
  718. $q->where('building_name', $building)->get();
  719. }],'PackageDetail','WorkOrder')->where('type_service',$type)->orderBy('created_at', 'desc')->get();
  720. }
  721. else if($type == 'null' && $building != 'null' && $dealer == 'null'){
  722. $form = Form::with(['Subscriber' => function($q) use ($building)
  723. {
  724. $q->where('building_name', $building)->get();
  725. }],'PackageDetail','WorkOrder')->orderBy('created_at', 'desc')->get();
  726. }
  727. else if($type == 'null' && $building == 'null' && $dealer != 'null'){
  728. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  729. }
  730. else if($type == 'null' && $building != 'null' && $dealer != 'null'){
  731. $form = Form::with(['Subscriber' => function($q) use ($building)
  732. {
  733. $q->where('building_name', $building)->get();
  734. }],'PackageDetail','WorkOrder')->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  735. }
  736. else if($type != 'null' && $building == 'null' && $dealer != 'null'){
  737. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  738. }
  739. else if($type != 'null' && $building != 'null' && $dealer != 'null'){
  740. $form = Form::with(['Subscriber' => function($q) use ($building)
  741. {
  742. $q->where('building_name', $building)->get();
  743. }],'PackageDetail','WorkOrder')->where('type_service',$type)->where('company_id',$dealer)->orderBy('created_at', 'desc')->get();
  744. }
  745. $wo = 'null'; $do = 'null';
  746. if(!empty($form)){
  747. foreach ($form as $key => $f) {
  748. if(!empty($f->WorkOrder)){
  749. $wo = $f->WorkOrder->wo;
  750. if($f->WorkOrder->status == "Completed"){
  751. $doc = Docket::where('work_order_id',$f->WorkOrder->wo)->first();
  752. if(!empty($doc)){
  753. $do = $doc->docket_id;
  754. }
  755. }else{
  756. $wo = $f->WorkOrder->wo;
  757. $do = "null";
  758. }
  759. }else {
  760. $wo = "null";
  761. $do = "null";
  762. }
  763. if($f->type_application == 'B' && $f->type_service != "Rectification"){
  764. $i++;
  765. $n1 = '';
  766. $reg_time = $f->created_at;
  767. $expiry_date = $reg_time->addDays(3);
  768. $expiry_date = $expiry_date->getTimestamp();
  769. if($curr < $expiry_date) {
  770. $n1 = "New/";
  771. }else{
  772. $n1 = "";
  773. }
  774. if(!empty($f->dealer_id)){
  775. $labelD = "D/";
  776. }else {
  777. $labelD = "";
  778. }
  779. if(!empty($f->Subscriber)){
  780. if($f->Subscriber->street != ''){
  781. $street = $f->Subscriber->street;
  782. }
  783. array_push($nested_data, array(
  784. 'formT' => $n1.$i.$f->type_application,
  785. 'submittion' => Carbon::parse($f->created_at)->toDateString(),
  786. 'type' => $f->type_service,
  787. 'name' => $labelD.$f->Subscriber->company_name,
  788. 'phone' => $f->Subscriber->phone1,
  789. 'unit' => $f->Subscriber->unit_no,
  790. 'building' => $f->Subscriber->building_name,
  791. 'street' => $street,
  792. 'postcode' => $f->Subscriber->postcode,
  793. 'city' => $f->Subscriber->city,
  794. 'action1' => $f->type_application.'/'.$f->Subscriber->subscriber_id,
  795. 'action2' => $wo,
  796. 'action3' => $do
  797. ));
  798. }
  799. }
  800. }
  801. }
  802. return \DataTables::of($nested_data)->make(true);
  803. }
  804. public function getCustomerWo()
  805. {
  806. $curr = Carbon::now()->getTimestamp();
  807. $work_detail= WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
  808. $i = 0;
  809. $nested_data = array();
  810. if(!empty($work_detail)){
  811. foreach ($work_detail as $a)
  812. {
  813. $i++; $y = ''; $n1 = '';
  814. $reg_time = $a->created_at;
  815. $expiry_date = $reg_time->addDays(3);
  816. $expiry_date = $expiry_date->getTimestamp();
  817. if($curr < $expiry_date) {
  818. $n1 = "New/";
  819. }
  820. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  821. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  822. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  823. $inst_name = '';
  824. if(!empty($installer)){
  825. $inst_name = $installer->name;
  826. }
  827. array_push($nested_data, array(
  828. 'index' => $i.$n1,
  829. 'nature_work' => $a->nature_work,
  830. 'wo'=>$a->wo,
  831. 'customer_name' => $formDetail->SubscribersLaravel->name,
  832. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  833. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  834. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  835. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  836. 'customer_city' => $formDetail->SubscribersLaravel->city,
  837. 'contractor_id' => $contractor->name,
  838. 'installer_id' => $inst_name,
  839. 'dateTimeEnd' => $a->dateTimeEnd,
  840. 'status' => $a->status,
  841. 'action' => $a->id,
  842. ));
  843. }
  844. }
  845. return \DataTables::of($nested_data)->make(true);
  846. }
  847. public function filterCustomerWo($year, $month, $status)
  848. {
  849. $curr = Carbon::now()->getTimestamp();
  850. if($year == 'null' && $month == 'null' & $status !='null')
  851. {
  852. $nested_data = array();
  853. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->where('status', $status)->get();
  854. $i = 0;
  855. $nested_data = array();
  856. if(!empty($work_detail)){
  857. foreach ($work_detail as $a)
  858. {
  859. $i++; $y = ''; $n1 = '';
  860. $reg_time = $a->created_at;
  861. $expiry_date = $reg_time->addDays(3);
  862. $expiry_date = $expiry_date->getTimestamp();
  863. if($curr < $expiry_date) {
  864. $n1 = "New/";
  865. }else {
  866. $n1 = "";
  867. }
  868. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  869. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  870. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  871. $inst_name = '';
  872. if(!empty($installer)){
  873. $inst_name = $installer->name;
  874. }
  875. array_push($nested_data, array(
  876. 'index' => $i.$n1,
  877. 'nature_work' => $a->nature_work,
  878. 'wo'=>$a->wo,
  879. 'customer_name' => $formDetail->SubscribersLaravel->name,
  880. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  881. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  882. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  883. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  884. 'customer_city' => $formDetail->SubscribersLaravel->city,
  885. 'contractor_id' => $contractor->name,
  886. 'installer_id' => $inst_name,
  887. 'dateTimeEnd' => $a->dateTimeEnd,
  888. 'status' => $a->status,
  889. 'action' => $a->id,
  890. ));
  891. }
  892. }
  893. }
  894. if($year=='null' && $month == 'null' & $status == 'null')
  895. {
  896. $nested_data = array();
  897. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->get();
  898. $i = 0;
  899. $nested_data = array();
  900. if(!empty($work_detail)){
  901. foreach ($work_detail as $a)
  902. {
  903. $i++; $y = ''; $n1 = '';
  904. $reg_time = $a->created_at;
  905. $expiry_date = $reg_time->addDays(3);
  906. $expiry_date = $expiry_date->getTimestamp();
  907. if($curr < $expiry_date) {
  908. $n1 = "New/";
  909. }else {
  910. $n1 = "";
  911. }
  912. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  913. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  914. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  915. $inst_name = '';
  916. if(!empty($installer)){
  917. $inst_name = $installer->name;
  918. }
  919. array_push($nested_data, array(
  920. 'index' => $i.$n1,
  921. 'nature_work' => $a->nature_work,
  922. 'wo'=>$a->wo,
  923. 'customer_name' => $formDetail->SubscribersLaravel->name,
  924. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  925. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  926. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  927. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  928. 'customer_city' => $formDetail->SubscribersLaravel->city,
  929. 'contractor_id' => $contractor->name,
  930. 'installer_id' => $inst_name,
  931. 'dateTimeEnd' => $a->dateTimeEnd,
  932. 'status' => $a->status,
  933. 'action' => $a->id,
  934. ));
  935. }
  936. }
  937. }
  938. if($year!='null' && $month!='nulll' && $status !='null')
  939. {
  940. $nested_data = array();
  941. $start_month = $year."-".$month."-01 00:00:00";
  942. $end_month = $year."-".$month."-32 23:59:59";
  943. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
  944. $i = 0;
  945. $nested_data = array();
  946. if(!empty($work_detail)){
  947. foreach ($work_detail as $a)
  948. {
  949. $i++; $y = ''; $n1 = '';
  950. $reg_time = $a->created_at;
  951. $expiry_date = $reg_time->addDays(3);
  952. $expiry_date = $expiry_date->getTimestamp();
  953. if($curr < $expiry_date) {
  954. $n1 = "New/";
  955. }else {
  956. $n1 = "";
  957. }
  958. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  959. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  960. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  961. $inst_name = '';
  962. if(!empty($installer)){
  963. $inst_name = $installer->name;
  964. }
  965. array_push($nested_data, array(
  966. 'index' => $i.$n1,
  967. 'nature_work' => $a->nature_work,
  968. 'wo'=>$a->wo,
  969. 'customer_name' => $formDetail->SubscribersLaravel->name,
  970. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  971. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  972. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  973. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  974. 'customer_city' => $formDetail->SubscribersLaravel->city,
  975. 'contractor_id' => $contractor->name,
  976. 'installer_id' => $inst_name,
  977. 'dateTimeEnd' => $a->dateTimeEnd,
  978. 'status' => $a->status,
  979. 'action' => $a->id,
  980. ));
  981. }
  982. }
  983. }
  984. if($year!='null' && $month!='null' && $status =='null')
  985. {
  986. $nested_data = array();
  987. $start_month = $year."-".$month."-01 00:00:00";
  988. $end_month = $year."-".$month."-32 23:59:59";
  989. $work_detail = WorkOrderLaravel::with('FormLaravel')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
  990. $i = 0;
  991. $nested_data = array();
  992. if(!empty($work_detail)){
  993. foreach ($work_detail as $a)
  994. {
  995. $i++; $y = ''; $n1 = '';
  996. $reg_time = $a->created_at;
  997. $expiry_date = $reg_time->addDays(3);
  998. $expiry_date = $expiry_date->getTimestamp();
  999. if($curr < $expiry_date) {
  1000. $n1 = "New/";
  1001. }else {
  1002. $n1 = "";
  1003. }
  1004. $formDetail = FormLaravel::with('SubscribersLaravel','PackageDetailLaravel')->first();
  1005. $installer = StaffDetailLaravel::where('_id', $a->installer_id)->where('position','Installer')->first();
  1006. $contractor = CompanyLaravel::where('_id', $a->contractor_id)->first();
  1007. $inst_name = '';
  1008. if(!empty($installer)){
  1009. $inst_name = $installer->name;
  1010. }
  1011. array_push($nested_data, array(
  1012. 'index' => $i.$n1,
  1013. 'nature_work' => $a->nature_work,
  1014. 'wo'=>$a->wo,
  1015. 'customer_name' => $formDetail->SubscribersLaravel->name,
  1016. 'customer_phone' => $formDetail->SubscribersLaravel->phone1,
  1017. 'customer_unit' => $formDetail->SubscribersLaravel->unit_no,
  1018. 'customer_building' => $formDetail->SubscribersLaravel->building_name,
  1019. 'customer_postcode' => $formDetail->SubscribersLaravel->postcode,
  1020. 'customer_city' => $formDetail->SubscribersLaravel->city,
  1021. 'contractor_id' => $contractor->name,
  1022. 'installer_id' => $inst_name,
  1023. 'dateTimeEnd' => $a->dateTimeEnd,
  1024. 'status' => $a->status,
  1025. 'action' => $a->id,
  1026. ));
  1027. }
  1028. }
  1029. }
  1030. return \DataTables::of($nested_data)->make(true);
  1031. }
  1032. public function deleteCustomerWo(Request $request)
  1033. {
  1034. $wo = WorkOrderLaravel::where('_id',$request->id)->first();
  1035. if(!empty($wo)){
  1036. $wo->delete();
  1037. return 'true';
  1038. }else {
  1039. return 'false';
  1040. }
  1041. }
  1042. public function getCountry()
  1043. {
  1044. $jsonString = file_get_contents(base_path('resources/views/customer-service/country.json'));
  1045. $data = json_decode($jsonString, true);
  1046. return $jsonString;
  1047. }
  1048. public function getBuilding()
  1049. {
  1050. $wK = Coverage::all();
  1051. $data = array();
  1052. foreach ($wK as $key=>$w) {
  1053. array_push($data, array(
  1054. 'name' => $w->address,
  1055. ));
  1056. }
  1057. // Read and parse our events JSON file into an array of event data arrays.
  1058. $json = json_encode($data);
  1059. // Send JSON to the client.
  1060. echo $json;
  1061. }
  1062. }