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

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