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

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