您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WorkOrderController.php 53KB

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