Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

WorkOrderController.php 48KB

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