Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WorkOrderController.php 55KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  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::all();
  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::all();
  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')->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. $category = $form->customer_category;
  239. if(empty($category)){
  240. $category = '';
  241. }else {
  242. $category = $form->customer_category;
  243. }
  244. if(empty($product)){
  245. $product = 'R Mbps';
  246. }else {
  247. $product = $product->package_name;
  248. }
  249. if(empty($company)){
  250. $company = ' ';
  251. }else {
  252. $company = $company->name;
  253. }
  254. if(empty($w->dateTimeStart)){
  255. $date = '';
  256. $time = '';
  257. } else {
  258. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  259. $time = date("h:i A", strtotime($w->dateTimeStart));
  260. }
  261. array_push($nested_data, array(
  262. 'formT' => $n1.$i.$w->Form->type_application,
  263. 'service' => $w->nature_work,
  264. 'wo' => $w->wo,
  265. 'category' => $category,
  266. 'name' => $name,
  267. 'phone' => $form->Subscriber->phone1,
  268. 'unit' => $unit,
  269. 'building' => $building,
  270. 'city' => $form->Subscriber->city,
  271. 'package' => $product,
  272. 'contractor' => $company,
  273. 'installer' => $installer,
  274. 'date' => $date,
  275. 'time' => $time,
  276. 'status' => $w->status,
  277. 'action' => $w->wo,
  278. ));
  279. }
  280. }
  281. return \DataTables::of($nested_data)->make(true);
  282. }
  283. public function getAllPendingNonPrelaid($year,$month,$day){
  284. $id = Auth::guard('cs')->id();
  285. $user = Staff::with('StaffDetail')->find($id);
  286. $i = 0; $n1 = '';
  287. $curr = Carbon::now()->getTimestamp();
  288. $nested_data = array();
  289. if($year == 'null' && $month == 'null' && $day == 'null'){
  290. $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->orderBy('created_at', 'desc')->get();
  291. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  292. $timestamp = $year."-01-01 00:00:00.000Z";
  293. $masa = strtotime($timestamp);
  294. $go = Carbon::createFromTimestamp($masa);
  295. $go2 = Carbon::createFromTimestamp($masa);
  296. $end_year = $go2->endOfYear();
  297. $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  298. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  299. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  300. $masa = strtotime($timestamp);
  301. $go = Carbon::createFromTimestamp($masa);
  302. $go2 = Carbon::createFromTimestamp($masa);
  303. $end_year = $go2->endOfMonth();
  304. $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  305. }
  306. if(!empty($wo)){
  307. foreach ($wo as $key => $w) {
  308. $i++;
  309. $n1 = '';
  310. $reg_time = $w->created_at;
  311. $expiry_date = $reg_time->addDays(3);
  312. $expiry_date = $expiry_date->getTimestamp();
  313. if($curr < $expiry_date) {
  314. $n1 = "New/";
  315. }
  316. $installer = '';
  317. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  318. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  319. $company = Company::where('_id',$w->contractor_id)->first();
  320. if($w->installer_id != ''){
  321. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  322. $installer = $installer->StaffDetail->name;
  323. }
  324. $building = ''; $unit = '-'; $name = '';
  325. $building = $form->Subscriber->building_name;
  326. $unit = $form->Subscriber->unit_no;
  327. if($form->type_application == 'R'){
  328. $name = $form->Subscriber->name;
  329. }else if($form->type_application == 'B'){
  330. $name = $form->Subscriber->company_name;
  331. }
  332. $category = $form->customer_category;
  333. if(empty($category)){
  334. $category = '';
  335. }else {
  336. $category = $form->customer_category;
  337. }
  338. if(empty($product)){
  339. $product = 'R Mbps';
  340. }else {
  341. $product = $product->package_name;
  342. }
  343. if(empty($company)){
  344. $company = ' ';
  345. }else {
  346. $company = $company->name;
  347. }
  348. if(empty($w->dateTimeStart)){
  349. $date = '';
  350. $time = '';
  351. } else {
  352. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  353. $time = date("h:i A", strtotime($w->dateTimeStart));
  354. }
  355. array_push($nested_data, array(
  356. 'formT' => $n1.$i.$w->Form->type_application,
  357. 'service' => $w->nature_work,
  358. 'wo' => $w->wo,
  359. 'category' => $category,
  360. 'name' => $name,
  361. 'phone' => $form->Subscriber->phone1,
  362. 'unit' => $unit,
  363. 'building' => $building,
  364. 'city' => $form->Subscriber->city,
  365. 'package' => $product,
  366. 'contractor' => $company,
  367. 'installer' => $installer,
  368. 'date' => $date,
  369. 'time' => $time,
  370. 'status' => $w->status,
  371. 'action' => $w->wo,
  372. ));
  373. }
  374. }
  375. return \DataTables::of($nested_data)->make(true);
  376. }
  377. public function getAllSuccessNonPrelaid($year,$month,$day){
  378. $id = Auth::guard('cs')->id();
  379. $user = Staff::with('StaffDetail')->find($id);
  380. $i = 0; $n1 = '';
  381. $curr = Carbon::now()->getTimestamp();
  382. $nested_data = array();
  383. if($year == 'null' && $month == 'null' && $day == 'null'){
  384. $wo = WorkOrder::with('Form')->where('status','Success Non Prelaid')->orderBy('created_at', 'desc')->get();
  385. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  386. $timestamp = $year."-01-01 00:00:00.000Z";
  387. $masa = strtotime($timestamp);
  388. $go = Carbon::createFromTimestamp($masa);
  389. $go2 = Carbon::createFromTimestamp($masa);
  390. $end_year = $go2->endOfYear();
  391. $wo = WorkOrder::with('Form')->where('status','Success Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  392. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  393. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  394. $masa = strtotime($timestamp);
  395. $go = Carbon::createFromTimestamp($masa);
  396. $go2 = Carbon::createFromTimestamp($masa);
  397. $end_year = $go2->endOfMonth();
  398. $wo = WorkOrder::with('Form')->where('status','Success Non Prelaid')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  399. }
  400. if(!empty($wo)){
  401. foreach ($wo as $key => $w) {
  402. $i++;
  403. $n1 = '';
  404. $reg_time = $w->created_at;
  405. $expiry_date = $reg_time->addDays(3);
  406. $expiry_date = $expiry_date->getTimestamp();
  407. if($curr < $expiry_date) {
  408. $n1 = "New/";
  409. }
  410. $installer = '';
  411. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  412. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  413. $company = Company::where('_id',$w->contractor_id)->first();
  414. if($w->installer_id != ''){
  415. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->withTrashed()->first();
  416. $installer = $installer->StaffDetail->name;
  417. }
  418. $building = ''; $unit = '-'; $name = '';
  419. $building = $form->Subscriber->building_name;
  420. $unit = $form->Subscriber->unit_no;
  421. if($form->type_application == 'R'){
  422. $name = $form->Subscriber->name;
  423. }else if($form->type_application == 'B'){
  424. $name = $form->Subscriber->company_name;
  425. }
  426. $category = $form->customer_category;
  427. if(empty($category)){
  428. $category = '';
  429. }else {
  430. $category = $form->customer_category;
  431. }
  432. if(empty($product)){
  433. $product = 'R Mbps';
  434. }else {
  435. $product = $product->package_name;
  436. }
  437. if(empty($company)){
  438. $company = ' ';
  439. }else {
  440. $company = $company->name;
  441. }
  442. if(empty($w->dateTimeStart)){
  443. $date = '';
  444. $time = '';
  445. } else {
  446. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  447. $time = date("h:i A", strtotime($w->dateTimeStart));
  448. }
  449. array_push($nested_data, array(
  450. 'formT' => $n1.$i.$w->Form->type_application,
  451. 'service' => $w->nature_work,
  452. 'wo' => $w->wo,
  453. 'category' => $category,
  454. 'name' => $name,
  455. 'phone' => $form->Subscriber->phone1,
  456. 'unit' => $unit,
  457. 'building' => $building,
  458. 'city' => $form->Subscriber->city,
  459. 'package' => $product,
  460. 'contractor' => $company,
  461. 'installer' => $installer,
  462. 'date' => $date,
  463. 'time' => $time,
  464. 'status' => $w->status,
  465. 'action' => $w->wo,
  466. ));
  467. }
  468. }
  469. return \DataTables::of($nested_data)->make(true);
  470. }
  471. public function getAllPendingInstaller($year,$month,$day){
  472. $id = Auth::guard('cs')->id();
  473. $user = Staff::with('StaffDetail')->find($id);
  474. $i = 0; $n1 = '';
  475. $curr = Carbon::now()->getTimestamp();
  476. $nested_data = array();
  477. if($year == 'null' && $month == 'null' && $day == 'null'){
  478. $wo = WorkOrder::with('Form')->where('status','Pending Installer')->orderBy('created_at', 'desc')->get();
  479. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  480. $timestamp = $year."-01-01 00:00:00.000Z";
  481. $masa = strtotime($timestamp);
  482. $go = Carbon::createFromTimestamp($masa);
  483. $go2 = Carbon::createFromTimestamp($masa);
  484. $end_year = $go2->endOfYear();
  485. $wo = WorkOrder::with('Form')->where('status','Pending Installer')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  486. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  487. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  488. $masa = strtotime($timestamp);
  489. $go = Carbon::createFromTimestamp($masa);
  490. $go2 = Carbon::createFromTimestamp($masa);
  491. $end_year = $go2->endOfMonth();
  492. $wo = WorkOrder::with('Form')->where('status','Pending Installer')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  493. }
  494. if(!empty($wo)){
  495. foreach ($wo as $key => $w) {
  496. $i++;
  497. $n1 = '';
  498. $reg_time = $w->created_at;
  499. $expiry_date = $reg_time->addDays(3);
  500. $expiry_date = $expiry_date->getTimestamp();
  501. if($curr < $expiry_date) {
  502. $n1 = "New/";
  503. }
  504. $installer = '';
  505. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  506. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  507. $company = Company::where('_id',$w->contractor_id)->first();
  508. if($w->installer_id != ''){
  509. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  510. if(!empty($installer)){
  511. $installer = $installer->StaffDetail->name;
  512. }
  513. }
  514. $building = ''; $unit = '-'; $name = '';
  515. $building = $form->Subscriber->building_name;
  516. $unit = $form->Subscriber->unit_no;
  517. if($form->type_application == 'R'){
  518. $name = $form->Subscriber->name;
  519. }else if($form->type_application == 'B'){
  520. $name = $form->Subscriber->company_name;
  521. }
  522. $category = $form->customer_category;
  523. if(empty($category)){
  524. $category = '';
  525. }else {
  526. $category = $form->customer_category;
  527. }
  528. if(empty($product)){
  529. $product = 'R Mbps';
  530. }else {
  531. $product = $product->package_name;
  532. }
  533. if(empty($company)){
  534. $company = ' ';
  535. }else {
  536. $company = $company->name;
  537. }
  538. if(empty($w->dateTimeStart)){
  539. $date = '';
  540. $time = '';
  541. } else {
  542. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  543. $time = date("h:i A", strtotime($w->dateTimeStart));
  544. }
  545. array_push($nested_data, array(
  546. 'formT' => $n1.$i.$w->Form->type_application,
  547. 'service' => $w->nature_work,
  548. 'wo' => $w->wo,
  549. 'category' => $category,
  550. 'name' => $name,
  551. 'phone' => $form->Subscriber->phone1,
  552. 'unit' => $unit,
  553. 'building' => $building,
  554. 'city' => $form->Subscriber->city,
  555. 'package' => $product,
  556. 'contractor' => $company,
  557. 'installer' => $installer,
  558. 'date' => $date,
  559. 'time' => $time,
  560. 'status' => $w->status,
  561. 'action' => $w->wo,
  562. ));
  563. }
  564. }
  565. return \DataTables::of($nested_data)->make(true);
  566. }
  567. public function getAllReschedule($year,$month,$day){
  568. $id = Auth::guard('cs')->id();
  569. $user = Staff::with('StaffDetail')->find($id);
  570. $i = 0; $n1 = '';
  571. $curr = Carbon::now()->getTimestamp();
  572. $nested_data = array();
  573. if($year == 'null' && $month == 'null' && $day == 'null'){
  574. $wo = WorkOrder::with('Form')->where('status','Reschedule')->orderBy('created_at', 'desc')->get();
  575. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  576. $timestamp = $year."-01-01 00:00:00.000Z";
  577. $masa = strtotime($timestamp);
  578. $go = Carbon::createFromTimestamp($masa);
  579. $go2 = Carbon::createFromTimestamp($masa);
  580. $end_year = $go2->endOfYear();
  581. $wo = WorkOrder::with('Form')->where('status','Reschedule')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  582. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  583. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  584. $masa = strtotime($timestamp);
  585. $go = Carbon::createFromTimestamp($masa);
  586. $go2 = Carbon::createFromTimestamp($masa);
  587. $end_year = $go2->endOfMonth();
  588. $wo = WorkOrder::with('Form')->where('status','Reschedule')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  589. }
  590. if(!empty($wo)){
  591. foreach ($wo as $key => $w) {
  592. $i++;
  593. $n1 = '';
  594. $reg_time = $w->created_at;
  595. $expiry_date = $reg_time->addDays(3);
  596. $expiry_date = $expiry_date->getTimestamp();
  597. if($curr < $expiry_date) {
  598. $n1 = "New/";
  599. }
  600. $installer = '';
  601. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  602. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  603. $company = Company::where('_id',$w->contractor_id)->first();
  604. if($w->installer_id != ''){
  605. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->withTrashed()->first();
  606. $installer = $installer->StaffDetail->name;
  607. }
  608. $building = ''; $unit = '-'; $name = '';
  609. $building = $form->Subscriber->building_name;
  610. $unit = $form->Subscriber->unit_no;
  611. if($form->type_application == 'R'){
  612. $name = $form->Subscriber->name;
  613. }else if($form->type_application == 'B'){
  614. $name = $form->Subscriber->company_name;
  615. }
  616. $category = $form->customer_category;
  617. if(empty($category)){
  618. $category = '';
  619. }else {
  620. $category = $form->customer_category;
  621. }
  622. if(empty($product)){
  623. $product = 'R Mbps';
  624. }else {
  625. $product = $product->package_name;
  626. }
  627. if(empty($company)){
  628. $company = ' ';
  629. }else {
  630. $company = $company->name;
  631. }
  632. if(empty($w->dateTimeStart)){
  633. $date = '';
  634. $time = '';
  635. } else {
  636. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  637. $time = date("h:i A", strtotime($w->dateTimeStart));
  638. }
  639. array_push($nested_data, array(
  640. 'formT' => $n1.$i.$w->Form->type_application,
  641. 'service' => $w->nature_work,
  642. 'wo' => $w->wo,
  643. 'category' => $category,
  644. 'name' => $name,
  645. 'phone' => $form->Subscriber->phone1,
  646. 'unit' => $unit,
  647. 'building' => $building,
  648. 'city' => $form->Subscriber->city,
  649. 'package' => $product,
  650. 'contractor' => $company,
  651. 'installer' => $installer,
  652. 'date' => $date,
  653. 'time' => $time,
  654. 'status' => $w->status." (".$w->remarks_installer.")",
  655. 'action' => $w->wo,
  656. ));
  657. }
  658. }
  659. return \DataTables::of($nested_data)->make(true);
  660. }
  661. public function getAllSuspend($year,$month,$day){
  662. $id = Auth::guard('cs')->id();
  663. $user = Staff::with('StaffDetail')->find($id);
  664. $i = 0; $n1 = '';
  665. $curr = Carbon::now()->getTimestamp();
  666. $nested_data = array();
  667. if($year == 'null' && $month == 'null' && $day == 'null'){
  668. $wo = WorkOrder::with('Form')->where('status','Suspend')->orderBy('created_at', 'desc')->get();
  669. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  670. $timestamp = $year."-01-01 00:00:00.000Z";
  671. $masa = strtotime($timestamp);
  672. $go = Carbon::createFromTimestamp($masa);
  673. $go2 = Carbon::createFromTimestamp($masa);
  674. $end_year = $go2->endOfYear();
  675. $wo = WorkOrder::with('Form')->where('status','Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  676. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  677. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  678. $masa = strtotime($timestamp);
  679. $go = Carbon::createFromTimestamp($masa);
  680. $go2 = Carbon::createFromTimestamp($masa);
  681. $end_year = $go2->endOfMonth();
  682. $wo = WorkOrder::with('Form')->where('status','Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  683. }
  684. if(!empty($wo)){
  685. foreach ($wo as $key => $w) {
  686. $i++;
  687. $n1 = '';
  688. $reg_time = $w->created_at;
  689. $expiry_date = $reg_time->addDays(3);
  690. $expiry_date = $expiry_date->getTimestamp();
  691. if($curr < $expiry_date) {
  692. $n1 = "New/";
  693. }
  694. $installer = '';
  695. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  696. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  697. $company = Company::where('_id',$w->contractor_id)->first();
  698. if($w->installer_id != ''){
  699. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id',$w->installer_id)->first();
  700. $installer = $installer->StaffDetail->name;
  701. }
  702. $building = ''; $unit = '-'; $name = '';
  703. $building = $form->Subscriber->building_name;
  704. $unit = $form->Subscriber->unit_no;
  705. if($form->type_application == 'R'){
  706. $name = $form->Subscriber->name;
  707. }else if($form->type_application == 'B'){
  708. $name = $form->Subscriber->company_name;
  709. }
  710. $category = $form->customer_category;
  711. if(empty($category)){
  712. $category = '';
  713. }else {
  714. $category = $form->customer_category;
  715. }
  716. if(empty($product)){
  717. $product = 'R Mbps';
  718. }else {
  719. $product = $product->package_name;
  720. }
  721. if(empty($company)){
  722. $company = ' ';
  723. }else {
  724. $company = $company->name;
  725. }
  726. if(empty($w->dateTimeStart)){
  727. $date = '';
  728. $time = '';
  729. } else {
  730. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  731. $time = date("h:i A", strtotime($w->dateTimeStart));
  732. }
  733. array_push($nested_data, array(
  734. 'formT' => $n1.$i.$w->Form->type_application,
  735. 'service' => $w->nature_work,
  736. 'wo' => $w->wo,
  737. 'category' => $category,
  738. 'name' => $name,
  739. 'phone' => $form->Subscriber->phone1,
  740. 'unit' => $unit,
  741. 'building' => $building,
  742. 'city' => $form->Subscriber->city,
  743. 'package' => $product,
  744. 'contractor' => $company,
  745. 'installer' => $installer,
  746. 'date' => $date,
  747. 'time' => $time,
  748. 'status' => $w->status." (".$w->remarks_installer.")",
  749. 'action' => $w->wo,
  750. ));
  751. }
  752. }
  753. return \DataTables::of($nested_data)->make(true);
  754. }
  755. public function getAllCancelled($year,$month,$day){
  756. $id = Auth::guard('cs')->id();
  757. $user = Staff::with('StaffDetail')->find($id);
  758. $i = 0; $n1 = '';
  759. $curr = Carbon::now()->getTimestamp();
  760. $nested_data = array();
  761. if($year == 'null' && $month == 'null' && $day == 'null'){
  762. $wo = WorkOrder::with('Form')->where('status','Cancelled')->orderBy('created_at', 'desc')->get();
  763. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  764. $timestamp = $year."-01-01 00:00:00.000Z";
  765. $masa = strtotime($timestamp);
  766. $go = Carbon::createFromTimestamp($masa);
  767. $go2 = Carbon::createFromTimestamp($masa);
  768. $end_year = $go2->endOfYear();
  769. $wo = WorkOrder::with('Form')->where('status','Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  770. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  771. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  772. $masa = strtotime($timestamp);
  773. $go = Carbon::createFromTimestamp($masa);
  774. $go2 = Carbon::createFromTimestamp($masa);
  775. $end_year = $go2->endOfMonth();
  776. $wo = WorkOrder::with('Form')->where('status','Suspend')->orderBy('created_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  777. }
  778. if(!empty($wo)){
  779. foreach ($wo as $key => $w) {
  780. $i++;
  781. $n1 = '';
  782. $reg_time = $w->created_at;
  783. $expiry_date = $reg_time->addDays(3);
  784. $expiry_date = $expiry_date->getTimestamp();
  785. if($curr < $expiry_date) {
  786. $n1 = "New/";
  787. }
  788. $installer = '';
  789. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  790. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  791. $company = Company::where('_id',$w->contractor_id)->first();
  792. if($w->installer_id != ''){
  793. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id',$w->installer_id)->first();
  794. $installer = $installer->StaffDetail->name;
  795. }
  796. $building = ''; $unit = '-'; $name = '';
  797. $building = $form->Subscriber->building_name;
  798. $unit = $form->Subscriber->unit_no;
  799. if($form->type_application == 'R'){
  800. $name = $form->Subscriber->name;
  801. }else if($form->type_application == 'B'){
  802. $name = $form->Subscriber->company_name;
  803. }
  804. $category = $form->customer_category;
  805. if(empty($category)){
  806. $category = '';
  807. }else {
  808. $category = $form->customer_category;
  809. }
  810. if(empty($product)){
  811. $product = 'R Mbps';
  812. }else {
  813. $product = $product->package_name;
  814. }
  815. if(empty($company)){
  816. $company = ' ';
  817. }else {
  818. $company = $company->name;
  819. }
  820. if(empty($w->dateTimeStart)){
  821. $date = '';
  822. $time = '';
  823. } else {
  824. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  825. $time = date("h:i A", strtotime($w->dateTimeStart));
  826. }
  827. array_push($nested_data, array(
  828. 'formT' => $n1.$i.$w->Form->type_application,
  829. 'service' => $w->nature_work,
  830. 'wo' => $w->wo,
  831. 'category' => $category,
  832. 'name' => $name,
  833. 'phone' => $form->Subscriber->phone1,
  834. 'unit' => $unit,
  835. 'building' => $building,
  836. 'city' => $form->Subscriber->city,
  837. 'package' => $product,
  838. 'contractor' => $company,
  839. 'installer' => $installer,
  840. 'date' => $date,
  841. 'time' => $time,
  842. 'status' => $w->status,
  843. 'action' => $w->wo,
  844. ));
  845. }
  846. }
  847. return \DataTables::of($nested_data)->make(true);
  848. }
  849. public function getAllCompleted($year,$month,$day){
  850. $id = Auth::guard('cs')->id();
  851. $user = Staff::with('StaffDetail')->find($id);
  852. $i = 0; $n1 = '';
  853. $curr = Carbon::now()->getTimestamp();
  854. $nested_data = array();
  855. if($year == 'null' && $month == 'null' && $day == 'null'){
  856. $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->get();
  857. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  858. $timestamp = $year."-01-01 00:00:00.000Z";
  859. $masa = strtotime($timestamp);
  860. $go = Carbon::createFromTimestamp($masa);
  861. $go2 = Carbon::createFromTimestamp($masa);
  862. $end_year = $go2->endOfYear();
  863. $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
  864. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  865. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  866. $masa = strtotime($timestamp);
  867. $go = Carbon::createFromTimestamp($masa);
  868. $go2 = Carbon::createFromTimestamp($masa);
  869. $end_year = $go2->endOfMonth();
  870. $doc = Docket::with('WorkOrder')->orderBy('end_job', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
  871. }
  872. if(!empty($doc)){
  873. foreach ($doc as $key => $w) {
  874. $i++;
  875. $n1 = '';
  876. $reg_time = $w->created_at;
  877. $expiry_date = $reg_time->addDays(3);
  878. $expiry_date = $expiry_date->getTimestamp();
  879. if($curr < $expiry_date) {
  880. $n1 = "New/";
  881. }
  882. $installer = '';
  883. if(!empty($w->WorkOrder->_id)){
  884. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->WorkOrder->_id)->first();
  885. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
  886. $company = Company::where('_id',$w->WorkOrder->contractor_id)->first();
  887. if($w->WorkOrder->installer_id != ''){
  888. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id',$w->WorkOrder->installer_id)->first();
  889. $installer = $installer->StaffDetail->name;
  890. }
  891. $building = ''; $unit = '-'; $name = '';
  892. $building = $form->Subscriber->building_name;
  893. $unit = $form->Subscriber->unit_no;
  894. if($form->type_application == 'R'){
  895. $name = $form->Subscriber->name;
  896. }else if($form->type_application == 'B'){
  897. $name = $form->Subscriber->company_name;
  898. }
  899. if(empty($product)){
  900. $product = 'R Mbps';
  901. }else {
  902. $product = $product->package_name;
  903. }
  904. if(empty($company)){
  905. $company = ' ';
  906. }else {
  907. $company = $company->name;
  908. }
  909. array_push($nested_data, array(
  910. 'formT' => $n1.$i.$form->type_application,
  911. 'service' => $w->nature_work,
  912. 'wo' => $w->WorkOrder->wo,
  913. 'name' => $name,
  914. 'phone' => $form->Subscriber->phone1,
  915. 'unit' => $unit,
  916. 'building' => $building,
  917. 'city' => $form->Subscriber->city,
  918. 'package' => $product,
  919. 'contractor' => $company,
  920. 'installer' => $installer,
  921. 'date' => date("d/m/Y", strtotime($w->end_job)),
  922. 'time' => date("h:i A", strtotime($w->end_job)),
  923. 'status' => $w->WorkOrder->status,
  924. 'docket' => $w->docket_id,
  925. 'action' => $w->WorkOrder->wo,
  926. ));
  927. }
  928. }
  929. }
  930. return \DataTables::of($nested_data)->make(true);
  931. }
  932. public function generateWorkOrderPDF($wo){
  933. $id = Auth::guard('cs')->id();
  934. $user = Staff::with('StaffDetail')->find($id);
  935. $wo = WorkOrder::where('wo',$wo)->first();
  936. $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first();
  937. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  938. if(empty($form->customer_category)){
  939. $category = '';
  940. }else {
  941. $category = $form->customer_category;
  942. }
  943. if(empty($product)){
  944. if($form->PackageDetail->name == "30"){
  945. $product = '30Mbps';
  946. }else{
  947. $product = 'RMbps';
  948. }
  949. }else {
  950. $product = $product->package_name;
  951. }
  952. $created_by = Staff::with('StaffDetail')->where("_id",$wo->created_by)->first();
  953. if(empty($created_by)){
  954. $created_by = '';
  955. }
  956. $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
  957. $address = '';
  958. if($form->type_application == 'R'){
  959. if($form->Subscriber->street != ''){
  960. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  961. }else {
  962. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  963. }
  964. }else if($form->type_application == 'B'){
  965. if($form->Subscriber->unit_no != ''){
  966. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  967. }else {
  968. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  969. }
  970. }
  971. $pdf = PDF::loadView('pdf.workorder-pdf',compact('wo','form','product','created_at','created_by','address', 'category'));
  972. $pdf->setPaper('A4', 'potrait');
  973. return $pdf->stream();
  974. }
  975. public function sendWorkOrders($work_order_id) {
  976. $work_order = WorkOrder::where('wo',$work_order_id)->first();
  977. $s = StaffDetail::where('company_id',$work_order->contractor_id)->where('position','Contractor')->get();
  978. $customer = Subscriber::where('_id',$work_order->_id)->first();
  979. if($work_order->contractor_id == '5b42b935ee0dc2b707473b76'){
  980. $company = Company::where('_id',$work_order->contractor_id)->first();
  981. $staff = StaffDetail::where('company_id',$work_order->contractor_id)->where('email','mimi@jitech.com.my')->first();
  982. SendWorkOrder::dispatch($work_order,$staff,'cbbinstallation@jitech.com.my',$customer,$company);
  983. }else {
  984. $company = Company::where('_id',$work_order->contractor_id)->first();
  985. foreach($s as $staff){
  986. SendWorkOrder::dispatch($work_order,$staff,$staff->email,$customer,$company);
  987. }
  988. }
  989. }
  990. public function updateWorkOrder(Request $request){
  991. $id = Auth::guard('cs')->id();
  992. $user = Staff::with('StaffDetail')->find($id);
  993. $wo = WorkOrder::where('wo',$request->work_order)->first();
  994. if(!empty($wo)){
  995. $number_phone = '';
  996. if($request->n_phone == 'Yes'){
  997. $number_phone = $request->no_phone;
  998. }
  999. $wo->nature_work = $request->task;
  1000. $wo->pppoe_username = $request->pppoe_username;
  1001. $wo->onu = $request->onu_ont;
  1002. $wo->router = $request->router;
  1003. $wo->need_phone = $request->n_phone;
  1004. $wo->no_phone = $number_phone;
  1005. $wo->remarks_custservice = $request->remark;
  1006. $wo->created_by = $user->_id;
  1007. $wo->save();
  1008. $form = Form::where('_id',$wo->_id)->first();
  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('_id',$request->buildingsss)->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 = $request->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. $coverage = Coverage::where('_id',$request->buildingssss,'Type','R')->first();
  1340. if(!empty($coverage)){
  1341. $building = $coverage->building_name;
  1342. $postcode = $coverage->postcode;
  1343. $city = $coverage->city;
  1344. $state = $coverage->state;
  1345. }else {
  1346. $building = $request->buildingssss;
  1347. $postcode = '-';
  1348. $city = '-';
  1349. $state = '-';
  1350. }
  1351. $sdl = new Subscriber();
  1352. $sdl->subscriber_id = $su_id;
  1353. $sdl->name = $request->name;
  1354. $sdl->ic = '<b>Package Development</b>';
  1355. $sdl->citizen = $request->citizensss;
  1356. $sdl->gender = $request->gender;
  1357. $sdl->race = $request->race;
  1358. $sdl->email = '<b>Package Development</b>';
  1359. $sdl->phone1 = $request->phone1;
  1360. $sdl->phone2 = $request->phone2;
  1361. $sdl->unit_no = $request->unit_no;
  1362. $sdl->building_name = $building;
  1363. $sdl->street = $request->street;
  1364. $sdl->postcode = $postcode;
  1365. $sdl->city = $city;
  1366. $sdl->state = $state;
  1367. $sdl->front_ic = '';
  1368. $sdl->back_ic = '';
  1369. $sdl->signature = '';
  1370. $packageD = new PackageDetail();
  1371. $packageD->contract = '24';
  1372. $packageD->name = $request->package;
  1373. $packageD->montly_fee = '';
  1374. $packageD->voice_fee = 'No';
  1375. $packageD->deposit = '';
  1376. $packageD->upfront_payment = '';
  1377. $packageD->rfs = '';
  1378. $sl->subscriber()->save($sdl);
  1379. $sl->packagedetail()->save($packageD);
  1380. $subs = Subscriber::where('subscriber_id',$su_id)->first();
  1381. $form = Form::where('_id',$subs->_id)->first();
  1382. $formH = new FormStatus;
  1383. $formH->form_id = $form->_id;
  1384. $formH->status_id = 13;
  1385. $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  1386. $formH->status = 'Secured Development';
  1387. $formH->desc = 'Secured development form been submitted';
  1388. $form->formstatus()->save($formH);
  1389. do {
  1390. $woID = 'WO-'.$this->createWorkID();
  1391. } while (WorkOrder::where("wo", "=", $woID)->first() instanceof WorkOrder);
  1392. $work_order = new WorkOrder;
  1393. $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
  1394. $work_order->wo = $woID;
  1395. $work_order->nature_work = '';
  1396. $work_order->sub_category = '';
  1397. $work_order->dateTimeStart = '';
  1398. $work_order->dateTimeEnd = '';
  1399. $work_order->contractor_id = '';
  1400. $work_order->installer_id = '';
  1401. $work_order->onu = '';
  1402. $work_order->router = '';
  1403. $work_order->need_phone = '';
  1404. $work_order->no_phone = '';
  1405. $work_order->pppoe_username = '';
  1406. $work_order->pppoe_password = '';
  1407. $work_order->docket_id = '';
  1408. $work_order->remarks_custservice = '';
  1409. $work_order->remarks_installer = '';
  1410. $work_order->status = 'Pending Contractor';
  1411. $work_order->created_by = '';
  1412. $form->workorder()->save($work_order);
  1413. return redirect()->to('/customer-service/work-order/add/schedule/secured/'.$woID.'/'. $su_id);
  1414. }
  1415. }