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

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