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

WorkOrderController.php 53KB

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