You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkOrderController.php 53KB

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