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

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