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

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