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

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