You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkOrderController.php 53KB

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