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

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