Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CustomerController.php 50KB

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