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

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