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.

WorkOrderController.php 54KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  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 App\Mail\AssignWorkOrder;
  7. use App\Jobs\SendWorkOrder;
  8. use Carbon\Carbon;
  9. use Validator;
  10. use PDF;
  11. use App\Staff;
  12. use App\Model\StaffDetail;
  13. use App\Model\Form;
  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. use App\Model\FormStatus;
  22. class WorkOrderController extends Controller
  23. {
  24. function random_code($limit)
  25. {
  26. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  27. }
  28. function createWorkID()
  29. {
  30. $number = WorkOrder::select('id', 'wo')->orderBy('created_at', 'DESC')->first();
  31. $numberOnly = str_replace('WO-', '', $number->wo);
  32. info('before WO' . $numberOnly);
  33. $numberOnly++;
  34. info('after WO' . $numberOnly);
  35. return $numberOnly;
  36. }
  37. public function viewWorkOrder()
  38. {
  39. $id = Auth::guard('cs')->id();
  40. $user = Staff::with('StaffDetail')->find($id);
  41. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  42. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  43. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  44. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  45. $cm = count(WorkOrder::where('status', 'Completed')->get());
  46. $pc = count(WorkOrder::where('status', 'Pending Contractor')->get());
  47. $pi = count(WorkOrder::where('status', 'Pending Installer')->get());
  48. $cance = count(WorkOrder::where('status', 'Cancelled')->get());
  49. return view('customer-service.view_wo', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'cance'));
  50. }
  51. public function viewEditWorkOrder($wo)
  52. {
  53. $id = Auth::guard('cs')->id();
  54. $user = Staff::with('StaffDetail')->find($id);
  55. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  56. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  57. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  58. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  59. $cm = count(WorkOrder::where('status', 'Completed')->get());
  60. $w = WorkOrder::where('wo', $wo)->first();
  61. $form = Form::with('Subscriber', 'WorkOrder')->where('_id', $w->_id)->first();
  62. $coverage = Coverage::groupBy('building_name')->orderBy('building_name')->get();
  63. if ($w->contractor_id != '') {
  64. $company = Company::where('_id', $w->contractor_id)->first();
  65. } else {
  66. $company = '';
  67. }
  68. return view('customer-service.edit_work_order', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'form', 'coverage', 'company'));
  69. }
  70. public function viewAddNewSchedule($status, $wo, $subscriber_id)
  71. {
  72. $id = Auth::guard('cs')->id();
  73. $user = Staff::with('StaffDetail')->find($id);
  74. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  75. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  76. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  77. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  78. $cm = count(WorkOrder::where('status', 'Completed')->get());
  79. $company = Company::where('team', 'CBB')->get();
  80. $today = Carbon::today();
  81. $wo_status = '';
  82. if ($status == "non-prelaid") {
  83. $wo_status = 'Pending Non Prelaid';
  84. } else {
  85. $wo_status = 'Pending Contractor';
  86. }
  87. $subscriber = Subscriber::where('subscriber_id', $subscriber_id)->first();
  88. if (!empty($subscriber)) {
  89. $form = Form::with('WorkOrder')->where('_id', $subscriber->_id)->first();
  90. if (empty($form->WorkOrder)) {
  91. do {
  92. $woID = 'WO-' . $this->createWorkID();
  93. } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
  94. $work_order = new WorkOrder;
  95. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  96. $work_order->wo = $woID;
  97. $work_order->nature_work = '';
  98. $work_order->sub_category = '';
  99. $work_order->dateTimeStart = '';
  100. $work_order->dateTimeEnd = '';
  101. $work_order->contractor_id = '';
  102. $work_order->installer_id = '';
  103. $work_order->onu = '';
  104. $work_order->router = '';
  105. $work_order->need_phone = '';
  106. $work_order->no_phone = '';
  107. $work_order->pppoe_username = '';
  108. $work_order->pppoe_password = '';
  109. $work_order->docket_id = '';
  110. $work_order->remarks_custservice = '';
  111. $work_order->remarks_installer = '';
  112. $work_order->status = $wo_status;
  113. $work_order->created_by = '';
  114. $form->workorder()->save($work_order);
  115. } else {
  116. $work_order = WorkOrder::where('wo', $form->WorkOrder->wo)->first();
  117. $work_order->nature_work = '';
  118. $work_order->sub_category = '';
  119. $work_order->dateTimeStart = '';
  120. $work_order->dateTimeEnd = '';
  121. $work_order->contractor_id = '';
  122. $work_order->installer_id = '';
  123. $work_order->onu = '';
  124. $work_order->router = '';
  125. $work_order->need_phone = '';
  126. $work_order->no_phone = '';
  127. $work_order->pppoe_username = '';
  128. $work_order->pppoe_password = '';
  129. $work_order->docket_id = '';
  130. $work_order->remarks_custservice = '';
  131. $work_order->remarks_installer = '';
  132. $work_order->status = $wo_status;
  133. $work_order->created_by = '';
  134. $work_order->save();
  135. }
  136. }
  137. return view('customer-service.view_add_new_schedule', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'company', 'wo', 'today', 'subscriber_id', 'status'));
  138. }
  139. public function viewRescheduleCalendar($wo)
  140. {
  141. $id = Auth::guard('cs')->id();
  142. $user = Staff::with('StaffDetail')->find($id);
  143. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  144. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  145. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  146. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  147. $cm = count(WorkOrder::where('status', 'Completed')->get());
  148. $company = Company::where('team', 'CBB')->get();
  149. $today = Carbon::today();
  150. return view('customer-service.view_reschedule-work-order', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'company', 'wo', 'today'));
  151. }
  152. public function confirmWorkOrder($wo)
  153. {
  154. $id = Auth::guard('cs')->id();
  155. $user = Staff::with('StaffDetail')->find($id);
  156. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  157. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  158. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  159. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  160. $cm = count(WorkOrder::where('status', 'Completed')->get());
  161. $w = WorkOrder::where('wo', $wo)->first();
  162. $form = Form::with('Subscriber', 'WorkOrder')->where('_id', $w->_id)->first();
  163. $coverage = Coverage::groupBy('building_name')->orderBy('building_name')->get();
  164. $company = Company::where('_id', $w->contractor_id)->first();
  165. return view('customer-service.confirm_work_order', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'form', 'coverage', 'wo', 'company'));
  166. }
  167. public function viewCreateWorkOrderR()
  168. {
  169. $id = Auth::guard('cs')->id();
  170. $user = Staff::with('StaffDetail')->find($id);
  171. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  172. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  173. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  174. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  175. $cm = count(WorkOrder::where('status', 'Completed')->get());
  176. $coverage = Coverage::where('Type', 'R')->groupBy('building_name')->orderBy('building_name')->get();
  177. $product = Product::where('formT', 'R')->get();
  178. return view('customer-service.view_wo_formR', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'coverage', 'product'));
  179. }
  180. public function viewCreateWorkOrderB()
  181. {
  182. $id = Auth::guard('cs')->id();
  183. $user = Staff::with('StaffDetail')->find($id);
  184. $pp = count(WorkOrder::where('status', 'Pending Non Prelaid')->get());
  185. $sp = count(WorkOrder::where('status', 'Success Non Prelaid')->get());
  186. $rs = count(WorkOrder::where('status', 'Reschedule')->get());
  187. $ss = count(WorkOrder::where('status', 'Suspend')->get());
  188. $cm = count(WorkOrder::where('status', 'Completed')->get());
  189. $coverage = Coverage::where('Type', 'B')->get();
  190. $product = Product::where('formT', 'B')->get();
  191. return view('customer-service.view_wo_formB', compact('user', 'pp', 'sp', 'rs', 'ss', 'cm', 'pc', 'pi', 'coverage', 'product'));
  192. }
  193. public function getAllPendingContractor($year, $month, $day)
  194. {
  195. $id = Auth::guard('cs')->id();
  196. $user = Staff::with('StaffDetail')->find($id);
  197. $i = 0;
  198. $n1 = '';
  199. $curr = Carbon::now()->getTimestamp();
  200. $nested_data = array();
  201. if ($month == 'null' && $day == 'null') {
  202. $wo = WorkOrder::with('Form')->where('status', 'Pending Contractor')->orderBy('created_at', 'desc')->get();
  203. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  204. $timestamp = $year . "-01-01 00:00:00.000Z";
  205. $masa = strtotime($timestamp);
  206. $go = Carbon::createFromTimestamp($masa);
  207. $go2 = Carbon::createFromTimestamp($masa);
  208. $end_year = $go2->endOfYear();
  209. $wo = WorkOrder::with('Form')->where('status', 'Pending Contractor')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  210. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  211. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  212. $masa = strtotime($timestamp);
  213. $go = Carbon::createFromTimestamp($masa);
  214. $go2 = Carbon::createFromTimestamp($masa);
  215. $end_year = $go2->endOfMonth();
  216. $wo = WorkOrder::with('Form')->where('status', 'Pending Contractor')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  217. }
  218. if (!empty($wo)) {
  219. foreach ($wo as $key => $w) {
  220. $i++;
  221. $n1 = '';
  222. $reg_time = $w->created_at;
  223. $expiry_date = $reg_time->addDays(3);
  224. $expiry_date = $expiry_date->getTimestamp();
  225. if ($curr < $expiry_date) {
  226. $n1 = "New/";
  227. }
  228. $installer = '';
  229. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  230. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  231. $company = Company::where('_id', $w->contractor_id)->first();
  232. // info($w->installer_id);
  233. if ($w->installer_id != '') {
  234. $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->first();
  235. $installer = $installer->StaffDetail->name;
  236. }
  237. $building = '';
  238. $unit = '-';
  239. $name = '';
  240. $building = $form->Subscriber->building_name;
  241. $unit = $form->Subscriber->unit_no;
  242. if ($form->type_application == 'R') {
  243. $name = $form->Subscriber->name;
  244. } else if ($form->type_application == 'B') {
  245. $name = $form->Subscriber->company_name;
  246. }
  247. if (empty($form->customer_category)) {
  248. $category = '';
  249. } else {
  250. $category = $form->customer_category;
  251. }
  252. if (empty($product)) {
  253. $product = 'R Mbps';
  254. } else {
  255. $product = $product->package_name;
  256. }
  257. if (empty($company)) {
  258. $company = ' ';
  259. } else {
  260. $company = $company->name;
  261. }
  262. if (empty($w->dateTimeStart)) {
  263. $date = '';
  264. $time = '';
  265. } else {
  266. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  267. $time = date("h:i A", strtotime($w->dateTimeStart));
  268. }
  269. array_push($nested_data, array(
  270. 'formT' => $n1 . $i . $w->Form->type_application,
  271. 'service' => $w->nature_work,
  272. 'wo' => $w->wo,
  273. 'category' => $category,
  274. 'name' => $name,
  275. 'phone' => $form->Subscriber->phone1,
  276. 'unit' => $unit,
  277. 'building' => $building,
  278. 'city' => $form->Subscriber->city,
  279. 'package' => $product,
  280. 'contractor' => $company,
  281. 'installer' => $installer,
  282. 'date' => $date,
  283. 'time' => $time,
  284. 'status' => $w->status,
  285. 'action' => $w->wo,
  286. ));
  287. }
  288. }
  289. return \DataTables::of($nested_data)->make(true);
  290. }
  291. public function getAllPendingNonPrelaid($year, $month, $day)
  292. {
  293. $id = Auth::guard('cs')->id();
  294. $user = Staff::with('StaffDetail')->find($id);
  295. $i = 0;
  296. $n1 = '';
  297. $curr = Carbon::now()->getTimestamp();
  298. $nested_data = array();
  299. if ($year == 'null' && $month == 'null' && $day == 'null') {
  300. $wo = WorkOrder::with('Form')->where('status', 'Pending Non Prelaid')->orderBy('created_at', 'desc')->get();
  301. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  302. $timestamp = $year . "-01-01 00:00:00.000Z";
  303. $masa = strtotime($timestamp);
  304. $go = Carbon::createFromTimestamp($masa);
  305. $go2 = Carbon::createFromTimestamp($masa);
  306. $end_year = $go2->endOfYear();
  307. $wo = WorkOrder::with('Form')->where('status', 'Pending Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  308. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  309. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  310. $masa = strtotime($timestamp);
  311. $go = Carbon::createFromTimestamp($masa);
  312. $go2 = Carbon::createFromTimestamp($masa);
  313. $end_year = $go2->endOfMonth();
  314. $wo = WorkOrder::with('Form')->where('status', 'Pending Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  315. }
  316. if (!empty($wo)) {
  317. foreach ($wo as $key => $w) {
  318. $i++;
  319. $n1 = '';
  320. $reg_time = $w->created_at;
  321. $expiry_date = $reg_time->addDays(3);
  322. $expiry_date = $expiry_date->getTimestamp();
  323. if ($curr < $expiry_date) {
  324. $n1 = "New/";
  325. }
  326. $installer = '';
  327. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  328. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  329. $company = Company::where('_id', $w->contractor_id)->first();
  330. if ($w->installer_id != '') {
  331. $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->first();
  332. $installer = $installer->StaffDetail->name;
  333. }
  334. $building = '';
  335. $unit = '-';
  336. $name = '';
  337. $building = $form->Subscriber->building_name;
  338. $unit = $form->Subscriber->unit_no;
  339. if ($form->type_application == 'R') {
  340. $name = $form->Subscriber->name;
  341. } else if ($form->type_application == 'B') {
  342. $name = $form->Subscriber->company_name;
  343. }
  344. if (empty($form->customer_category)) {
  345. $category = '';
  346. } else {
  347. $category = $form->customer_category;
  348. }
  349. if (empty($product)) {
  350. $product = 'R Mbps';
  351. } else {
  352. $product = $product->package_name;
  353. }
  354. if (empty($company)) {
  355. $company = ' ';
  356. } else {
  357. $company = $company->name;
  358. }
  359. if (empty($w->dateTimeStart)) {
  360. $date = '';
  361. $time = '';
  362. } else {
  363. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  364. $time = date("h:i A", strtotime($w->dateTimeStart));
  365. }
  366. array_push($nested_data, array(
  367. 'formT' => $n1 . $i . $w->Form->type_application,
  368. 'service' => $w->nature_work,
  369. 'wo' => $w->wo,
  370. 'category' => $category,
  371. 'name' => $name,
  372. 'phone' => $form->Subscriber->phone1,
  373. 'unit' => $unit,
  374. 'building' => $building,
  375. 'city' => $form->Subscriber->city,
  376. 'package' => $product,
  377. 'contractor' => $company,
  378. 'installer' => $installer,
  379. 'date' => $date,
  380. 'time' => $time,
  381. 'status' => $w->status,
  382. 'action' => $w->wo,
  383. ));
  384. }
  385. }
  386. return \DataTables::of($nested_data)->make(true);
  387. }
  388. public function getAllSuccessNonPrelaid($year, $month, $day)
  389. {
  390. $id = Auth::guard('cs')->id();
  391. $user = Staff::with('StaffDetail')->find($id);
  392. $i = 0;
  393. $n1 = '';
  394. $curr = Carbon::now()->getTimestamp();
  395. $nested_data = array();
  396. if ($year == 'null' && $month == 'null' && $day == 'null') {
  397. $wo = WorkOrder::with('Form')->where('status', 'Success Non Prelaid')->orderBy('created_at', 'desc')->get();
  398. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  399. $timestamp = $year . "-01-01 00:00:00.000Z";
  400. $masa = strtotime($timestamp);
  401. $go = Carbon::createFromTimestamp($masa);
  402. $go2 = Carbon::createFromTimestamp($masa);
  403. $end_year = $go2->endOfYear();
  404. $wo = WorkOrder::with('Form')->where('status', 'Success Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  405. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  406. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  407. $masa = strtotime($timestamp);
  408. $go = Carbon::createFromTimestamp($masa);
  409. $go2 = Carbon::createFromTimestamp($masa);
  410. $end_year = $go2->endOfMonth();
  411. $wo = WorkOrder::with('Form')->where('status', 'Success Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  412. }
  413. if (!empty($wo)) {
  414. foreach ($wo as $key => $w) {
  415. $i++;
  416. $n1 = '';
  417. $reg_time = $w->created_at;
  418. $expiry_date = $reg_time->addDays(3);
  419. $expiry_date = $expiry_date->getTimestamp();
  420. if ($curr < $expiry_date) {
  421. $n1 = "New/";
  422. }
  423. $installer = '';
  424. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  425. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  426. $company = Company::where('_id', $w->contractor_id)->first();
  427. if ($w->installer_id != '') {
  428. $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->withTrashed()->first();
  429. $installer = $installer->StaffDetail->name;
  430. }
  431. $building = '';
  432. $unit = '-';
  433. $name = '';
  434. $building = $form->Subscriber->building_name;
  435. $unit = $form->Subscriber->unit_no;
  436. if ($form->type_application == 'R') {
  437. $name = $form->Subscriber->name;
  438. } else if ($form->type_application == 'B') {
  439. $name = $form->Subscriber->company_name;
  440. }
  441. if (empty($form->customer_category)) {
  442. $category = '';
  443. } else {
  444. $category = $form->customer_category;
  445. }
  446. if (empty($product)) {
  447. $product = 'R Mbps';
  448. } else {
  449. $product = $product->package_name;
  450. }
  451. if (empty($company)) {
  452. $company = ' ';
  453. } else {
  454. $company = $company->name;
  455. }
  456. if (empty($w->dateTimeStart)) {
  457. $date = '';
  458. $time = '';
  459. } else {
  460. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  461. $time = date("h:i A", strtotime($w->dateTimeStart));
  462. }
  463. array_push($nested_data, array(
  464. 'formT' => $n1 . $i . $w->Form->type_application,
  465. 'service' => $w->nature_work,
  466. 'wo' => $w->wo,
  467. 'category' => $category,
  468. 'name' => $name,
  469. 'phone' => $form->Subscriber->phone1,
  470. 'unit' => $unit,
  471. 'building' => $building,
  472. 'city' => $form->Subscriber->city,
  473. 'package' => $product,
  474. 'contractor' => $company,
  475. 'installer' => $installer,
  476. 'date' => $date,
  477. 'time' => $time,
  478. 'status' => $w->status,
  479. 'action' => $w->wo,
  480. ));
  481. }
  482. }
  483. return \DataTables::of($nested_data)->make(true);
  484. }
  485. public function getAllPendingInstaller($year, $month, $day)
  486. {
  487. $id = Auth::guard('cs')->id();
  488. $user = Staff::with('StaffDetail')->find($id);
  489. $i = 0;
  490. $n1 = '';
  491. $curr = Carbon::now()->getTimestamp();
  492. $nested_data = array();
  493. if ($year == 'null' && $month == 'null' && $day == 'null') {
  494. $wo = WorkOrder::with('Form')->where('status', 'Pending Installer')->orderBy('created_at', 'desc')->get();
  495. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  496. $timestamp = $year . "-01-01 00:00:00.000Z";
  497. $masa = strtotime($timestamp);
  498. $go = Carbon::createFromTimestamp($masa);
  499. $go2 = Carbon::createFromTimestamp($masa);
  500. $end_year = $go2->endOfYear();
  501. $wo = WorkOrder::with('Form')->where('status', 'Pending Installer')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  502. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  503. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  504. $masa = strtotime($timestamp);
  505. $go = Carbon::createFromTimestamp($masa);
  506. $go2 = Carbon::createFromTimestamp($masa);
  507. $end_year = $go2->endOfMonth();
  508. $wo = WorkOrder::with('Form')->where('status', 'Pending Installer')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  509. }
  510. if (!empty($wo)) {
  511. foreach ($wo as $key => $w) {
  512. $i++;
  513. $n1 = '';
  514. $reg_time = $w->created_at;
  515. $expiry_date = $reg_time->addDays(3);
  516. $expiry_date = $expiry_date->getTimestamp();
  517. if ($curr < $expiry_date) {
  518. $n1 = "New/";
  519. }
  520. $installer = '';
  521. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  522. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  523. $company = Company::where('_id', $w->contractor_id)->first();
  524. if ($w->installer_id != '') {
  525. $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->first();
  526. if (!empty($installer)) {
  527. $installer = $installer->StaffDetail->name;
  528. }
  529. }
  530. $building = '';
  531. $unit = '-';
  532. $name = '';
  533. $building = $form->Subscriber->building_name;
  534. $unit = $form->Subscriber->unit_no;
  535. if ($form->type_application == 'R') {
  536. $name = $form->Subscriber->name;
  537. } else if ($form->type_application == 'B') {
  538. $name = $form->Subscriber->company_name;
  539. }
  540. if (empty($form->customer_category)) {
  541. $category = '';
  542. } else {
  543. $category = $form->customer_category;
  544. }
  545. if (empty($product)) {
  546. $product = 'R Mbps';
  547. } else {
  548. $product = $product->package_name;
  549. }
  550. if (empty($company)) {
  551. $company = ' ';
  552. } else {
  553. $company = $company->name;
  554. }
  555. if (empty($w->dateTimeStart)) {
  556. $date = '';
  557. $time = '';
  558. } else {
  559. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  560. $time = date("h:i A", strtotime($w->dateTimeStart));
  561. }
  562. array_push($nested_data, array(
  563. 'formT' => $n1 . $i . $w->Form->type_application,
  564. 'service' => $w->nature_work,
  565. 'wo' => $w->wo,
  566. 'category' => $category,
  567. 'name' => $name,
  568. 'phone' => $form->Subscriber->phone1,
  569. 'unit' => $unit,
  570. 'building' => $building,
  571. 'city' => $form->Subscriber->city,
  572. 'package' => $product,
  573. 'contractor' => $company,
  574. 'installer' => $installer,
  575. 'date' => $date,
  576. 'time' => $time,
  577. 'status' => $w->status,
  578. 'action' => $w->wo,
  579. ));
  580. }
  581. }
  582. return \DataTables::of($nested_data)->make(true);
  583. }
  584. public function getAllReschedule($year, $month, $day)
  585. {
  586. $id = Auth::guard('cs')->id();
  587. $user = Staff::with('StaffDetail')->find($id);
  588. $i = 0;
  589. $n1 = '';
  590. $curr = Carbon::now()->getTimestamp();
  591. $nested_data = array();
  592. if ($year == 'null' && $month == 'null' && $day == 'null') {
  593. $wo = WorkOrder::with('Form')->where('status', 'Reschedule')->orderBy('created_at', 'desc')->get();
  594. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  595. $timestamp = $year . "-01-01 00:00:00.000Z";
  596. $masa = strtotime($timestamp);
  597. $go = Carbon::createFromTimestamp($masa);
  598. $go2 = Carbon::createFromTimestamp($masa);
  599. $end_year = $go2->endOfYear();
  600. $wo = WorkOrder::with('Form')->where('status', 'Reschedule')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  601. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  602. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  603. $masa = strtotime($timestamp);
  604. $go = Carbon::createFromTimestamp($masa);
  605. $go2 = Carbon::createFromTimestamp($masa);
  606. $end_year = $go2->endOfMonth();
  607. $wo = WorkOrder::with('Form')->where('status', 'Reschedule')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  608. }
  609. if (!empty($wo)) {
  610. foreach ($wo as $key => $w) {
  611. $i++;
  612. $n1 = '';
  613. $reg_time = $w->created_at;
  614. $expiry_date = $reg_time->addDays(3);
  615. $expiry_date = $expiry_date->getTimestamp();
  616. if ($curr < $expiry_date) {
  617. $n1 = "New/";
  618. }
  619. $installer = '';
  620. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  621. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  622. $company = Company::where('_id', $w->contractor_id)->first();
  623. if ($w->installer_id != '') {
  624. $installer = Staff::with('StaffDetail')->where('_id', $w->installer_id)->withTrashed()->first();
  625. $installer = $installer->StaffDetail->name;
  626. }
  627. $building = '';
  628. $unit = '-';
  629. $name = '';
  630. $building = $form->Subscriber->building_name;
  631. $unit = $form->Subscriber->unit_no;
  632. if ($form->type_application == 'R') {
  633. $name = $form->Subscriber->name;
  634. } else if ($form->type_application == 'B') {
  635. $name = $form->Subscriber->company_name;
  636. }
  637. if (empty($form->customer_category)) {
  638. $category = '';
  639. } else {
  640. $category = $form->customer_category;
  641. }
  642. if (empty($product)) {
  643. $product = 'R Mbps';
  644. } else {
  645. $product = $product->package_name;
  646. }
  647. if (empty($company)) {
  648. $company = ' ';
  649. } else {
  650. $company = $company->name;
  651. }
  652. if (empty($w->dateTimeStart)) {
  653. $date = '';
  654. $time = '';
  655. } else {
  656. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  657. $time = date("h:i A", strtotime($w->dateTimeStart));
  658. }
  659. array_push($nested_data, array(
  660. 'formT' => $n1 . $i . $w->Form->type_application,
  661. 'service' => $w->nature_work,
  662. 'wo' => $w->wo,
  663. 'category' => $category,
  664. 'name' => $name,
  665. 'phone' => $form->Subscriber->phone1,
  666. 'unit' => $unit,
  667. 'building' => $building,
  668. 'city' => $form->Subscriber->city,
  669. 'package' => $product,
  670. 'contractor' => $company,
  671. 'installer' => $installer,
  672. 'date' => $date,
  673. 'time' => $time,
  674. 'status' => $w->status . " (" . $w->remarks_installer . ")",
  675. 'action' => $w->wo,
  676. ));
  677. }
  678. }
  679. return \DataTables::of($nested_data)->make(true);
  680. }
  681. public function getAllSuspend($year, $month, $day)
  682. {
  683. $id = Auth::guard('cs')->id();
  684. $user = Staff::with('StaffDetail')->find($id);
  685. $i = 0;
  686. $n1 = '';
  687. $curr = Carbon::now()->getTimestamp();
  688. $nested_data = array();
  689. if ($year == 'null' && $month == 'null' && $day == 'null') {
  690. $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->get();
  691. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  692. $timestamp = $year . "-01-01 00:00:00.000Z";
  693. $masa = strtotime($timestamp);
  694. $go = Carbon::createFromTimestamp($masa);
  695. $go2 = Carbon::createFromTimestamp($masa);
  696. $end_year = $go2->endOfYear();
  697. $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  698. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  699. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  700. $masa = strtotime($timestamp);
  701. $go = Carbon::createFromTimestamp($masa);
  702. $go2 = Carbon::createFromTimestamp($masa);
  703. $end_year = $go2->endOfMonth();
  704. $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  705. }
  706. if (!empty($wo)) {
  707. foreach ($wo as $key => $w) {
  708. $i++;
  709. $n1 = '';
  710. $reg_time = $w->created_at;
  711. $expiry_date = $reg_time->addDays(3);
  712. $expiry_date = $expiry_date->getTimestamp();
  713. if ($curr < $expiry_date) {
  714. $n1 = "New/";
  715. }
  716. $installer = '';
  717. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  718. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  719. $company = Company::where('_id', $w->contractor_id)->first();
  720. if ($w->installer_id != '') {
  721. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $w->installer_id)->first();
  722. $installer = $installer->StaffDetail->name;
  723. }
  724. $building = '';
  725. $unit = '-';
  726. $name = '';
  727. $building = $form->Subscriber->building_name;
  728. $unit = $form->Subscriber->unit_no;
  729. if ($form->type_application == 'R') {
  730. $name = $form->Subscriber->name;
  731. } else if ($form->type_application == 'B') {
  732. $name = $form->Subscriber->company_name;
  733. }
  734. if (empty($form->customer_category)) {
  735. $category = '';
  736. } else {
  737. $category = $form->customer_category;
  738. }
  739. if (empty($product)) {
  740. $product = 'R Mbps';
  741. } else {
  742. $product = $product->package_name;
  743. }
  744. if (empty($company)) {
  745. $company = ' ';
  746. } else {
  747. $company = $company->name;
  748. }
  749. if (empty($w->dateTimeStart)) {
  750. $date = '';
  751. $time = '';
  752. } else {
  753. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  754. $time = date("h:i A", strtotime($w->dateTimeStart));
  755. }
  756. array_push($nested_data, array(
  757. 'formT' => $n1 . $i . $w->Form->type_application,
  758. 'service' => $w->nature_work,
  759. 'wo' => $w->wo,
  760. 'category' => $category,
  761. 'name' => $name,
  762. 'phone' => $form->Subscriber->phone1,
  763. 'unit' => $unit,
  764. 'building' => $building,
  765. 'city' => $form->Subscriber->city,
  766. 'package' => $product,
  767. 'contractor' => $company,
  768. 'installer' => $installer,
  769. 'date' => $date,
  770. 'time' => $time,
  771. 'status' => $w->status . " (" . $w->remarks_installer . ")",
  772. 'action' => $w->wo,
  773. ));
  774. }
  775. }
  776. return \DataTables::of($nested_data)->make(true);
  777. }
  778. public function getAllCancelled($year, $month, $day)
  779. {
  780. $id = Auth::guard('cs')->id();
  781. $user = Staff::with('StaffDetail')->find($id);
  782. $i = 0;
  783. $n1 = '';
  784. $curr = Carbon::now()->getTimestamp();
  785. $nested_data = array();
  786. if ($year == 'null' && $month == 'null' && $day == 'null') {
  787. $wo = WorkOrder::with('Form')->where('status', 'Cancelled')->orderBy('created_at', 'desc')->get();
  788. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  789. $timestamp = $year . "-01-01 00:00:00.000Z";
  790. $masa = strtotime($timestamp);
  791. $go = Carbon::createFromTimestamp($masa);
  792. $go2 = Carbon::createFromTimestamp($masa);
  793. $end_year = $go2->endOfYear();
  794. $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  795. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  796. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  797. $masa = strtotime($timestamp);
  798. $go = Carbon::createFromTimestamp($masa);
  799. $go2 = Carbon::createFromTimestamp($masa);
  800. $end_year = $go2->endOfMonth();
  801. $wo = WorkOrder::with('Form')->where('status', 'Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  802. }
  803. if (!empty($wo)) {
  804. foreach ($wo as $key => $w) {
  805. $i++;
  806. $n1 = '';
  807. $reg_time = $w->created_at;
  808. $expiry_date = $reg_time->addDays(3);
  809. $expiry_date = $expiry_date->getTimestamp();
  810. if ($curr < $expiry_date) {
  811. $n1 = "New/";
  812. }
  813. $installer = '';
  814. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->Form->_id)->first();
  815. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $w->Form->type_application)->first();
  816. $company = Company::where('_id', $w->contractor_id)->first();
  817. if ($w->installer_id != '') {
  818. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $w->installer_id)->first();
  819. $installer = $installer->StaffDetail->name;
  820. }
  821. $building = '';
  822. $unit = '-';
  823. $name = '';
  824. $building = $form->Subscriber->building_name;
  825. $unit = $form->Subscriber->unit_no;
  826. if ($form->type_application == 'R') {
  827. $name = $form->Subscriber->name;
  828. } else if ($form->type_application == 'B') {
  829. $name = $form->Subscriber->company_name;
  830. }
  831. if (empty($form->customer_category)) {
  832. $category = '';
  833. } else {
  834. $category = $form->customer_category;
  835. }
  836. if (empty($product)) {
  837. $product = 'R Mbps';
  838. } else {
  839. $product = $product->package_name;
  840. }
  841. if (empty($company)) {
  842. $company = ' ';
  843. } else {
  844. $company = $company->name;
  845. }
  846. if (empty($w->dateTimeStart)) {
  847. $date = '';
  848. $time = '';
  849. } else {
  850. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  851. $time = date("h:i A", strtotime($w->dateTimeStart));
  852. }
  853. array_push($nested_data, array(
  854. 'formT' => $n1 . $i . $w->Form->type_application,
  855. 'service' => $w->nature_work,
  856. 'wo' => $w->wo,
  857. 'category' => $category,
  858. 'name' => $name,
  859. 'phone' => $form->Subscriber->phone1,
  860. 'unit' => $unit,
  861. 'building' => $building,
  862. 'city' => $form->Subscriber->city,
  863. 'package' => $product,
  864. 'contractor' => $company,
  865. 'installer' => $installer,
  866. 'date' => $date,
  867. 'time' => $time,
  868. 'status' => $w->status,
  869. 'action' => $w->wo,
  870. ));
  871. }
  872. }
  873. return \DataTables::of($nested_data)->make(true);
  874. }
  875. public function getAllCompleted($year, $month, $day)
  876. {
  877. $id = Auth::guard('cs')->id();
  878. $user = Staff::with('StaffDetail')->find($id);
  879. $i = 0;
  880. $n1 = '';
  881. $curr = Carbon::now()->getTimestamp();
  882. $nested_data = array();
  883. if ($year == 'null' && $month == 'null' && $day == 'null') {
  884. $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->get();
  885. } else if ($year != 'null' && $month == 'null' && $day == 'null') {
  886. $timestamp = $year . "-01-01 00:00:00.000Z";
  887. $masa = strtotime($timestamp);
  888. $go = Carbon::createFromTimestamp($masa);
  889. $go2 = Carbon::createFromTimestamp($masa);
  890. $end_year = $go2->endOfYear();
  891. $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
  892. } else if ($year != 'null' && $month != 'null' && $day == 'null') {
  893. $timestamp = $year . "-" . $month . "-01 00:00:00.000Z";
  894. $masa = strtotime($timestamp);
  895. $go = Carbon::createFromTimestamp($masa);
  896. $go2 = Carbon::createFromTimestamp($masa);
  897. $end_year = $go2->endOfMonth();
  898. $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
  899. }
  900. if (!empty($doc)) {
  901. foreach ($doc as $key => $w) {
  902. $i++;
  903. $n1 = '';
  904. $reg_time = $w->created_at;
  905. $expiry_date = $reg_time->addDays(3);
  906. $expiry_date = $expiry_date->getTimestamp();
  907. if ($curr < $expiry_date) {
  908. $n1 = "New/";
  909. }
  910. $installer = '';
  911. if (!empty($w->WorkOrder->_id)) {
  912. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $w->WorkOrder->_id)->first();
  913. $product = Product::where('speed', $form->PackageDetail->name)->where('formT', $form->type_application)->first();
  914. $company = Company::where('_id', $w->WorkOrder->contractor_id)->first();
  915. if ($w->WorkOrder->installer_id != '') {
  916. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id', $w->WorkOrder->installer_id)->first();
  917. $installer = $installer->StaffDetail->name;
  918. }
  919. $building = '';
  920. $unit = '-';
  921. $name = '';
  922. $building = $form->Subscriber->building_name;
  923. $unit = $form->Subscriber->unit_no;
  924. if ($form->type_application == 'R') {
  925. $name = $form->Subscriber->name;
  926. } else if ($form->type_application == 'B') {
  927. $name = $form->Subscriber->company_name;
  928. }
  929. if (empty($product)) {
  930. $product = 'R Mbps';
  931. } else {
  932. $product = $product->package_name;
  933. }
  934. if (empty($company)) {
  935. $company = ' ';
  936. } else {
  937. $company = $company->name;
  938. }
  939. if (empty($form->customer_category)) {
  940. $category = '';
  941. } else {
  942. $category = $form->customer_category;
  943. }
  944. array_push($nested_data, array(
  945. 'formT' => $n1 . $i . $form->type_application,
  946. 'service' => $w->nature_work,
  947. 'wo' => $w->WorkOrder->wo,
  948. 'category' => $category,
  949. 'name' => $name,
  950. 'phone' => $form->Subscriber->phone1,
  951. 'unit' => $unit,
  952. 'building' => $building,
  953. 'city' => $form->Subscriber->city,
  954. 'package' => $product,
  955. 'contractor' => $company,
  956. 'installer' => $installer,
  957. 'date' => date("d/m/Y", strtotime($w->end_job)),
  958. 'time' => date("h:i A", strtotime($w->end_job)),
  959. 'status' => $w->WorkOrder->status,
  960. 'docket' => $w->docket_id,
  961. 'action' => $w->WorkOrder->wo,
  962. ));
  963. }
  964. }
  965. }
  966. return \DataTables::of($nested_data)->make(true);
  967. }
  968. public function generateWorkOrderPDF($wo)
  969. {
  970. $id = Auth::guard('cs')->id();
  971. $user = Staff::with('StaffDetail')->find($id);
  972. $wo = WorkOrder::where('wo', $wo)->first();
  973. $form = Form::with('PackageDetail', 'Subscriber')->where('_id', $wo->_id)->first();
  974. $product = Product::where('formT', $form->type_application)->where('speed', $form->PackageDetail->name)->first();
  975. if (empty($form->customer_category)) {
  976. $category = '';
  977. } else {
  978. $category = $form->customer_category;
  979. }
  980. if (empty($product)) {
  981. if ($form->PackageDetail->name == "30") {
  982. $product = '30Mbps';
  983. } else {
  984. $product = 'RMbps';
  985. }
  986. } else {
  987. $product = $product->package_name;
  988. }
  989. $created_by = Staff::with('StaffDetail')->where("_id", $wo->created_by)->first();
  990. if (empty($created_by)) {
  991. $created_by = '';
  992. }
  993. $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
  994. $address = '';
  995. if ($form->type_application == 'R') {
  996. if ($form->Subscriber->street != '') {
  997. $address = $form->Subscriber->unit_no . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  998. } else {
  999. $address = $form->Subscriber->unit_no . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1000. }
  1001. } else if ($form->type_application == 'B') {
  1002. if ($form->Subscriber->unit_no != '') {
  1003. $unit = $form->Subscriber->unit_no;
  1004. } else {
  1005. $unit = ' ';
  1006. }
  1007. if ($form->Subscriber->building_name == null) {
  1008. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1009. } else {
  1010. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1011. }
  1012. }
  1013. $pdf = PDF::loadView('pdf.workorder-pdf', compact('wo', 'form', 'product', 'created_at', 'created_by', 'address', 'category'));
  1014. $pdf->setPaper('A4', 'potrait');
  1015. return $pdf->stream();
  1016. }
  1017. public function sendWorkOrders($work_order_id)
  1018. {
  1019. $work_order = WorkOrder::where('wo', $work_order_id)->first();
  1020. $s = StaffDetail::where('company_id', $work_order->contractor_id)->where('position', 'Contractor')->get();
  1021. $customer = Subscriber::where('_id', $work_order->_id)->first();
  1022. if ($work_order->contractor_id == '5b42b935ee0dc2b707473b76') {
  1023. $company = Company::where('_id', $work_order->contractor_id)->first();
  1024. $staff = StaffDetail::where('company_id', $work_order->contractor_id)->where('email', 'mimi@jitech.com.my')->first();
  1025. SendWorkOrder::dispatch($work_order, $staff, 'cbbinstallation@jitech.com.my', $customer, $company);
  1026. } else {
  1027. $company = Company::where('_id', $work_order->contractor_id)->first();
  1028. foreach ($s as $staff) {
  1029. SendWorkOrder::dispatch($work_order, $staff, $staff->email, $customer, $company);
  1030. }
  1031. }
  1032. }
  1033. public function updateWorkOrder(Request $request)
  1034. {
  1035. $id = Auth::guard('cs')->id();
  1036. $user = Staff::with('StaffDetail')->find($id);
  1037. $wo = WorkOrder::where('wo', $request->work_order)->first();
  1038. if (!empty($wo)) {
  1039. $number_phone = '';
  1040. if ($request->n_phone == 'Yes') {
  1041. $number_phone = $request->no_phone;
  1042. }
  1043. $wo->nature_work = $request->task;
  1044. $wo->pppoe_username = $request->pppoe_username;
  1045. $wo->onu = $request->onu_ont;
  1046. $wo->router = $request->router;
  1047. $wo->need_phone = $request->n_phone;
  1048. $wo->no_phone = $number_phone;
  1049. $wo->remarks_custservice = $request->remark;
  1050. $wo->created_by = $user->_id;
  1051. $wo->save();
  1052. $form = Form::where('_id', $wo->_id)->first();
  1053. $form->customer_category = $request->cust_category;
  1054. $form->save();
  1055. $contractor = Company::where('_id', $wo->contractor_id)->first();
  1056. $status = '';
  1057. $st_id = '';
  1058. if ($wo->status == 'Pending Contractor') {
  1059. $st_id = 4;
  1060. $status = 'Pending Contractor';
  1061. } else if ($wo->status == 'Pending Non Prelaid') {
  1062. $st_id = 5;
  1063. $status = 'Pending Non Prelaid';
  1064. }
  1065. $formH = new FormStatus;
  1066. $formH->form_id = $form->_id;
  1067. $formH->status_id = $st_id;
  1068. $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
  1069. $formH->status = $status;
  1070. $formH->desc = 'This work order been assigned to particular contractor (' . $contractor->name . ')';
  1071. $form->formstatus()->save($formH);
  1072. $this->sendWorkOrders($request->work_order);
  1073. return redirect('/customer-service/work-order/list');
  1074. // return redirect()->back()->with('success_msg', 'Success! Update work order '.$request->get('work_order'));
  1075. } else {
  1076. return redirect()->back()->with('error_msg', 'Cant update work order ' . $request->get('work_order'));
  1077. }
  1078. }
  1079. public function addSchedule(Request $request)
  1080. {
  1081. $subscriber = Subscriber::where('subscriber_id', $request->subscriber_id)->first();
  1082. if (!empty($subscriber)) {
  1083. $wod = WorkOrder::where('wo', $request->wo)->first();
  1084. if (empty($wod)) {
  1085. $status = '';
  1086. if ($request->status == 'non-prelaid') {
  1087. $status = 'Pending Non Prelaid';
  1088. } else {
  1089. $status = 'Pending Contractor';
  1090. }
  1091. $form = Form::where('_id', $subscriber->_id)->first();
  1092. $work_order = new WorkOrder;
  1093. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  1094. $work_order->wo = $request->wo;
  1095. $work_order->nature_work = '';
  1096. $work_order->sub_category = '';
  1097. $work_order->dateTimeStart = $request->start;
  1098. $work_order->dateTimeEnd = $request->end;
  1099. $work_order->contractor_id = $request->vendor;
  1100. $work_order->installer_id = '';
  1101. $work_order->onu = '';
  1102. $work_order->router = '';
  1103. $work_order->need_phone = '';
  1104. $work_order->no_phone = '';
  1105. $work_order->pppoe_username = '';
  1106. $work_order->pppoe_password = '';
  1107. $work_order->docket_id = '';
  1108. $work_order->remarks_custservice = '';
  1109. $work_order->remarks_installer = '';
  1110. $work_order->status = $status;
  1111. $work_order->created_by = $request->created_by;
  1112. $form->workorder()->save($work_order);
  1113. return 'success';
  1114. } else {
  1115. $wod->dateTimeStart = $request->start;
  1116. $wod->dateTimeEnd = $request->end;
  1117. $wod->contractor_id = $request->vendor;
  1118. $wod->save();
  1119. }
  1120. } else {
  1121. return 'false';
  1122. }
  1123. }
  1124. public function rescheduleWorkOrder(Request $request)
  1125. {
  1126. $wod = WorkOrder::where('wo', $request->wo)->first();
  1127. if (!empty($wod)) {
  1128. $wod->dateTimeStart = $request->start;
  1129. $wod->dateTimeEnd = $request->end;
  1130. $wod->contractor_id = $request->vendor;
  1131. $wod->status = 'Pending Contractor';
  1132. $wod->save();
  1133. return 'success';
  1134. } else {
  1135. return 'false';
  1136. }
  1137. }
  1138. public function cancelCreateWorkOrder(Request $request)
  1139. {
  1140. $wod = WorkOrder::where('wo', $request->wo)->first();
  1141. if (!empty($wod)) {
  1142. $wod->delete();
  1143. return 'true';
  1144. } else {
  1145. return 'false';
  1146. }
  1147. }
  1148. public function deleteWorkOrder(Request $request)
  1149. {
  1150. $wod = WorkOrder::where('wo', $request->id)->first();
  1151. if (!empty($wod)) {
  1152. $wod->delete();
  1153. $form = Form::where('_id', $wod->_id)->first();
  1154. $formH = new FormStatus;
  1155. $formH->form_id = $form->_id;
  1156. $formH->status_id = 9;
  1157. $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
  1158. $formH->status = 'Delete Work Order';
  1159. $formH->desc = 'This work order for this customer already been deleted!';
  1160. $form->formstatus()->save($formH);
  1161. return 'true';
  1162. } else {
  1163. return 'false';
  1164. }
  1165. }
  1166. public function checkExistingWorkOrder(Request $request)
  1167. {
  1168. $data = array();
  1169. $wod = WorkOrder::where('wo', $request->wo)->first();
  1170. if (($wod->status == 'Pending Contractor' || $wod->status == '')) {
  1171. array_push($data, array(
  1172. 'result' => 'yes',
  1173. ));
  1174. } else {
  1175. $wod->img_url = '/assets/img/activation_icon_nRead1.png';
  1176. $wod->wo = $request->wo;
  1177. $wod->nature_work = '';
  1178. $wod->sub_category = '';
  1179. $wod->dateTimeStart = '';
  1180. $wod->dateTimeEnd = '';
  1181. $wod->contractor_id = $request->vendor;
  1182. $wod->installer_id = '';
  1183. $wod->onu = '';
  1184. $wod->router = '';
  1185. $wod->need_phone = '';
  1186. $wod->no_phone = '';
  1187. $wod->pppoe_username = '';
  1188. $wod->pppoe_password = '';
  1189. $wod->docket_id = '';
  1190. $wod->remarks_custservice = '';
  1191. $wod->remarks_installer = '';
  1192. $wod->status = 'Pending Non Prelaid';
  1193. $wod->save();
  1194. array_push($data, array(
  1195. 'result' => 'yes',
  1196. ));
  1197. }
  1198. return response()->json($data);
  1199. }
  1200. public function updateWorkOrderReschedule(Request $request)
  1201. {
  1202. $data = array();
  1203. $wod = WorkOrder::where('wo', $request->wo)->first();
  1204. $form = Form::where('_id', $wod->_id)->first();
  1205. $contractor = Company::where('_id', $wod->contractor_id)->first();
  1206. if (!empty($wod)) {
  1207. $formH = new FormStatus;
  1208. $formH->form_id = $form->_id;
  1209. $formH->status_id = 4;
  1210. $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
  1211. $formH->status = 'Pending Contractor';
  1212. $formH->desc = 'This work order been reassigned to particular contractor (' . $contractor->name . ')';
  1213. $form->formstatus()->save($formH);
  1214. $this->sendWorkOrders($request->wo);
  1215. array_push($data, array(
  1216. 'result' => 'yes',
  1217. ));
  1218. } else {
  1219. array_push($data, array(
  1220. 'result' => 'no',
  1221. ));
  1222. }
  1223. return response()->json($data);
  1224. }
  1225. public function createRectification(Request $request)
  1226. {
  1227. $su_id = '';
  1228. $pathIconF = '';
  1229. $pathIconB = '';
  1230. $sl = Form::create([
  1231. 'type_service' => 'Rectification',
  1232. 'type_application' => $request->formT,
  1233. 'customer_category' => $request->cust_category,
  1234. 'status_payment' => 'paid',
  1235. 'status_email' => 'verified',
  1236. 'remark_form' => ''
  1237. ]);
  1238. if ($request->formT == 'R') {
  1239. do {
  1240. $su_id = strtoupper('CBB-' . $this->random_code(6) . 'R');
  1241. } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
  1242. $coverage = Coverage::where('building_name', $request->buildingsss)->where('street', $request->street)->first();
  1243. $sdl = new Subscriber();
  1244. $sdl->subscriber_id = $su_id;
  1245. $sdl->name = $request->name;
  1246. $sdl->ic = '';
  1247. $sdl->citizen = '';
  1248. $sdl->gender = '';
  1249. $sdl->race = '';
  1250. $sdl->email = '';
  1251. $sdl->phone1 = $request->phone1;
  1252. $sdl->phone2 = $request->phone2;
  1253. $sdl->unit_no = $request->unit_no;
  1254. $sdl->building_name = $coverage->building_name;
  1255. $sdl->street = $coverage->street;
  1256. $sdl->postcode = $coverage->postcode;
  1257. $sdl->city = $coverage->city;
  1258. $sdl->state = $coverage->state;
  1259. $sdl->front_ic = '';
  1260. $sdl->back_ic = '';
  1261. $sdl->signature = '';
  1262. $packageD = new PackageDetail();
  1263. $packageD->contract = '';
  1264. $packageD->name = $request->package;
  1265. $packageD->montly_fee = '';
  1266. $packageD->voice_fee = '';
  1267. $packageD->deposit = '';
  1268. $packageD->upfront_payment = '';
  1269. $packageD->rfs = '';
  1270. $sl->subscriber()->save($sdl);
  1271. $sl->packagedetail()->save($packageD);
  1272. $subs = Subscriber::where('subscriber_id', $su_id)->first();
  1273. $form = Form::where('_id', $subs->_id)->first();
  1274. $formH = new FormStatus;
  1275. $formH->form_id = $form->_id;
  1276. $formH->status_id = 12;
  1277. $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
  1278. $formH->status = 'New Rectification';
  1279. $formH->desc = 'Rectification form been submitted';
  1280. $form->formstatus()->save($formH);
  1281. do {
  1282. $woID = 'WO-' . $this->createWorkID();
  1283. } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
  1284. $work_order = new WorkOrder;
  1285. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  1286. $work_order->wo = $woID;
  1287. $work_order->nature_work = '';
  1288. $work_order->sub_category = '';
  1289. $work_order->dateTimeStart = '';
  1290. $work_order->dateTimeEnd = '';
  1291. $work_order->contractor_id = '';
  1292. $work_order->installer_id = '';
  1293. $work_order->onu = '';
  1294. $work_order->router = '';
  1295. $work_order->need_phone = '';
  1296. $work_order->no_phone = '';
  1297. $work_order->pppoe_username = '';
  1298. $work_order->pppoe_password = '';
  1299. $work_order->docket_id = '';
  1300. $work_order->remarks_custservice = '';
  1301. $work_order->remarks_installer = '';
  1302. $work_order->status = 'Pending Contractor';
  1303. $work_order->created_by = '';
  1304. $form->workorder()->save($work_order);
  1305. return redirect()->to('/customer-service/work-order/add/schedule/rectification/' . $woID . '/' . $su_id);
  1306. } else if ($request->formT == 'B') {
  1307. do {
  1308. $su_id = strtoupper('CBB-' . $this->random_code(6) . 'B');
  1309. } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
  1310. $sdl = new Subscriber();
  1311. $sdl->subscriber_id = $su_id;
  1312. $sdl->company_name = $request->cname;
  1313. $sdl->company_reg = '';
  1314. $sdl->company_num = '';
  1315. $sdl->company_fax = '';
  1316. $sdl->name = $request->name;
  1317. $sdl->ic = '';
  1318. $sdl->designation = '';
  1319. $sdl->email = '';
  1320. $sdl->phone1 = $request->phone1;
  1321. $sdl->phone2 = '';
  1322. $sdl->unit_no = $request->unit_no;
  1323. $sdl->street = $request->caddress;
  1324. $sdl->postcode = '';
  1325. $sdl->city = '';
  1326. $sdl->state = '';
  1327. $sdl->front_ic = '';
  1328. $sdl->back_ic = '';
  1329. $sdl->form24_49 = '';
  1330. $sdl->form9_44 = '';
  1331. $packageD = new PackageDetail();
  1332. $packageD->contract = '';
  1333. $packageD->name = $request->package;
  1334. $packageD->montly_fee = '';
  1335. $packageD->voice_fee = 'No';
  1336. $packageD->deposit = '';
  1337. $packageD->upfront_payment = '';
  1338. $packageD->rfs = '';
  1339. $sl->subscriber()->save($sdl);
  1340. $sl->packagedetail()->save($packageD);
  1341. $subs = Subscriber::where('subscriber_id', $su_id)->first();
  1342. $form = Form::where('_id', $subs->_id)->first();
  1343. $formH = new FormStatus;
  1344. $formH->form_id = $form->_id;
  1345. $formH->status_id = 12;
  1346. $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
  1347. $formH->status = 'New Rectification';
  1348. $formH->desc = 'Rectification form been submitted';
  1349. $form->formstatus()->save($formH);
  1350. do {
  1351. $woID = 'WO-' . $this->createWorkID();
  1352. } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
  1353. $work_order = new WorkOrder;
  1354. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  1355. $work_order->wo = $woID;
  1356. $work_order->nature_work = '';
  1357. $work_order->sub_category = '';
  1358. $work_order->dateTimeStart = '';
  1359. $work_order->dateTimeEnd = '';
  1360. $work_order->contractor_id = '';
  1361. $work_order->installer_id = '';
  1362. $work_order->onu = '';
  1363. $work_order->router = '';
  1364. $work_order->need_phone = '';
  1365. $work_order->no_phone = '';
  1366. $work_order->pppoe_username = '';
  1367. $work_order->pppoe_password = '';
  1368. $work_order->docket_id = '';
  1369. $work_order->remarks_custservice = '';
  1370. $work_order->remarks_installer = '';
  1371. $work_order->status = 'Pending Contractor';
  1372. $work_order->created_by = '';
  1373. $form->workorder()->save($work_order);
  1374. return redirect()->to('/customer-service/work-order/add/schedule/rectification/' . $woID . '/' . $su_id);
  1375. }
  1376. }
  1377. public function createSecuredDevelopement(Request $request)
  1378. {
  1379. $su_id = '';
  1380. $pathIconF = '';
  1381. $pathIconB = '';
  1382. do {
  1383. $su_id = strtoupper('CBB-' . $this->random_code(6) . 'R');
  1384. } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
  1385. if ($request->has('cust_category1')) {
  1386. $category = $request->cust_category1;
  1387. } else if ($request->has('cust_category2')) {
  1388. $category = $request->cust_category2;
  1389. }
  1390. $sl = Form::create([
  1391. 'type_service' => $request->app,
  1392. 'customer_category' => $category,
  1393. 'type_application' => 'R',
  1394. 'status_payment' => 'paid',
  1395. 'status_email' => 'verified',
  1396. 'remark_form' => ''
  1397. ]);
  1398. $building = '-';
  1399. $postcode = '-';
  1400. $city = '-';
  1401. $state = '-';
  1402. if ($request->has('buildingsss')) {
  1403. $coverage = Coverage::where('building_name', $request->buildingssss)->first(); $street = $request->streets;
  1404. } else if ($request->has('buildingssss')) {
  1405. $coverage = Coverage::where('building_name', $request->buildingsssss)->first();
  1406. $street = $request->streetss;
  1407. }
  1408. dd($coverage);
  1409. if (!empty($coverage)) {
  1410. $building = $coverage->building_name;
  1411. $street = $street;
  1412. $postcode = $coverage->postcode;
  1413. $city = $coverage->city;
  1414. $state = $coverage->state;
  1415. } else {
  1416. $building = $request->buildingssss;
  1417. $street = '-';
  1418. $postcode = '-';
  1419. $city = '-';
  1420. $state = '-';
  1421. }
  1422. $sdl = new Subscriber();
  1423. $sdl->subscriber_id = $su_id;
  1424. $sdl->name = $request->name;
  1425. $sdl->ic = '<b>Package Development</b>';
  1426. $sdl->citizen = $request->citizensss;
  1427. $sdl->gender = $request->gender;
  1428. $sdl->race = $request->race;
  1429. $sdl->email = '<b>Package Development</b>';
  1430. $sdl->phone1 = $request->phone1;
  1431. $sdl->phone2 = $request->phone2;
  1432. $sdl->unit_no = $request->unit_no;
  1433. $sdl->building_name = $building;
  1434. $sdl->street = $street;
  1435. $sdl->postcode = $postcode;
  1436. $sdl->city = $city;
  1437. $sdl->state = $state;
  1438. $sdl->front_ic = '';
  1439. $sdl->back_ic = '';
  1440. $sdl->signature = '';
  1441. $packageD = new PackageDetail();
  1442. $packageD->contract = '24';
  1443. $packageD->name = $request->package;
  1444. $packageD->montly_fee = '';
  1445. $packageD->voice_fee = 'No';
  1446. $packageD->deposit = '';
  1447. $packageD->upfront_payment = '';
  1448. $packageD->rfs = '';
  1449. $sl->subscriber()->save($sdl);
  1450. $sl->packagedetail()->save($packageD);
  1451. $subs = Subscriber::where('subscriber_id', $su_id)->first();
  1452. $form = Form::where('_id', $subs->_id)->first();
  1453. $formH = new FormStatus;
  1454. $formH->form_id = $form->_id;
  1455. $formH->status_id = 13;
  1456. $formH->date = new \MongoDB\BSON\UTCDateTime(time() * 1000);
  1457. $formH->status = 'Secured Development';
  1458. $formH->desc = 'Secured development form been submitted';
  1459. $form->formstatus()->save($formH);
  1460. do {
  1461. $woID = 'WO-' . $this->createWorkID();
  1462. } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
  1463. $work_order = new WorkOrder;
  1464. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  1465. $work_order->wo = $woID;
  1466. $work_order->nature_work = '';
  1467. $work_order->sub_category = '';
  1468. $work_order->dateTimeStart = '';
  1469. $work_order->dateTimeEnd = '';
  1470. $work_order->contractor_id = '';
  1471. $work_order->installer_id = '';
  1472. $work_order->onu = '';
  1473. $work_order->router = '';
  1474. $work_order->need_phone = '';
  1475. $work_order->no_phone = '';
  1476. $work_order->pppoe_username = '';
  1477. $work_order->pppoe_password = '';
  1478. $work_order->docket_id = '';
  1479. $work_order->remarks_custservice = '';
  1480. $work_order->remarks_installer = '';
  1481. $work_order->status = 'Pending Contractor';
  1482. $work_order->created_by = '';
  1483. $form->workorder()->save($work_order);
  1484. return redirect()->to('/customer-service/work-order/add/schedule/secured/' . $woID . '/' . $su_id);
  1485. }
  1486. }