Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CustomerController.php 50KB

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