您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WorkOrderController.php 54KB

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