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 55KB

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