Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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