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

CustomerController.php 51KB

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