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

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