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

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