Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CustomerController.php 53KB

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