您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WorkOrderController.php 53KB

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