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

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