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

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