Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

WorkOrderController.php 55KB

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