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

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