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

WorkOrderController.php 48KB

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