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

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