Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

WorkOrderController.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. namespace App\Http\Controllers\Contractor;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use Validator;
  8. use PDF;
  9. use App\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\Form;
  12. use App\Model\Subscriber;
  13. use App\Model\WorkOrder;
  14. use App\Model\PackageDetail;
  15. use App\Model\Company;
  16. use App\Model\Coverage;
  17. use App\Model\Product;
  18. use App\Model\Docket;
  19. use App\Model\FormStatus;
  20. class WorkOrderController extends Controller
  21. {
  22. function random_code($limit) {
  23. return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
  24. }
  25. function createWorkID($limit){
  26. $allowedNumbers = range(0, 9);
  27. shuffle($allowedNumbers);
  28. $digits = array_rand($allowedNumbers, $limit);
  29. $number = '';
  30. foreach($digits as $d){
  31. $number .= $allowedNumbers[$d];
  32. }
  33. $unique_id = $number;
  34. return $unique_id;
  35. }
  36. public function viewContractorWork()
  37. {
  38. $id = Auth::guard('contractor')->id();
  39. $user = Staff::with('StaffDetail')->find($id);
  40. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  41. $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  42. $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
  43. $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
  44. $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
  45. $pc = count(WorkOrder::where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->get());
  46. $pi = count(WorkOrder::where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->get());
  47. return view('contractor.view_wo', compact('user','pp','sp','rs','ss','cm','pc','pi'));
  48. }
  49. public function editContractorWork($wo)
  50. {
  51. $id = Auth::guard('contractor')->id();
  52. $user = Staff::with('StaffDetail')->find($id);
  53. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  54. $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  55. $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
  56. $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
  57. $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
  58. $w = WorkOrder::where('wo',$wo)->first();
  59. $form = Form::with('Subscriber','WorkOrder')->where('_id',$w->_id)->first();
  60. $coverage = Coverage::all();
  61. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  62. if(empty($installer)){
  63. $installer = '';
  64. }else {
  65. $installer = $installer->StaffDetail->name;
  66. }
  67. $company = Company::where('_id',$w->contractor_id)->first();
  68. return view('contractor.edit_wo', compact('user','pp','sp','rs','ss','cm','pc','pi','form','coverage','installer','company'));
  69. }
  70. public function updateCustomerDetail(Request $request){
  71. $form = Subscriber::with('Form')->where('subscriber_id',$request->subscriber_id)->first();
  72. $phone = ''; $street = ''; $fax = '';
  73. if($request->phone2 != null){
  74. $phone = $request->phone2;
  75. }
  76. if($form->Form->type_application == 'R'){
  77. if($request->street != null){
  78. $street = $request->street;
  79. }
  80. $cov = Coverage::where('building_name',$request->building)->first();
  81. $form->name = $request->name;
  82. $form->ic = $request->ic;
  83. $form->email = $request->email;
  84. $form->phone1 = $request->phone1;
  85. $form->phone2 = $phone;
  86. $form->unit_no = $request->unit_no;
  87. $form->building_name = $cov->building_name;
  88. $form->street = $street;
  89. $form->city = $cov->city;
  90. $form->postcode = $cov->postcode;
  91. $form->state = $cov->state;
  92. $form->save();
  93. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  94. }else if($form->Form->type_application == 'B'){
  95. if($request->company_fax != null){
  96. $fax = $request->company_fax;
  97. }
  98. $form->company_reg = $request->company_reg;
  99. $form->company_num = $request->company_num;
  100. $form->company_fax = $fax;
  101. $form->company_name = $request->company_name;
  102. $form->unit_no = $request->unit_no;
  103. $form->street = $request->address;
  104. $form->city = $request->city;
  105. $form->postcode = $request->postcode;
  106. $form->state = $request->state;
  107. $form->name = $request->name;
  108. $form->ic = $request->ic;
  109. $form->designation = $request->designation;
  110. $form->email = $request->email;
  111. $form->phone1 = $request->phone1;
  112. $form->phone2 = $phone;
  113. $form->save();
  114. return redirect()->back()->with('success_msg', 'Success! Update customer '.$request->get('name'));
  115. }
  116. }
  117. public function viewRescheduleCalendar($wo){
  118. $id = Auth::guard('contractor')->id();
  119. $user = Staff::with('StaffDetail')->find($id);
  120. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  121. $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  122. $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
  123. $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
  124. $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
  125. $installer = StaffDetail::where('company_id',$user->StaffDetail->company_id)->where('position','Installer')->get();
  126. $today = Carbon::today();
  127. return view('contractor.reschedule_work_order', compact('user','pp','sp','rs','ss','cm','company','wo','today','installer'));
  128. }
  129. public function getAllPendingContractor($year,$month,$day){
  130. $id = Auth::guard('contractor')->id();
  131. $user = Staff::with('StaffDetail')->find($id);
  132. $i = 0; $n1 = '';
  133. $curr = Carbon::now()->getTimestamp();
  134. $nested_data = array();
  135. if($month == 'null' && $day == 'null'){
  136. $wo = WorkOrder::with('Form')->where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->get();
  137. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  138. $timestamp = $year."-01-01 00:00:00.000Z";
  139. $masa = strtotime($timestamp);
  140. $go = Carbon::createFromTimestamp($masa);
  141. $go2 = Carbon::createFromTimestamp($masa);
  142. $end_year = $go2->endOfYear();
  143. $wo = WorkOrder::with('Form')->where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  144. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  145. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  146. $masa = strtotime($timestamp);
  147. $go = Carbon::createFromTimestamp($masa);
  148. $go2 = Carbon::createFromTimestamp($masa);
  149. $end_year = $go2->endOfMonth();
  150. $wo = WorkOrder::with('Form')->where('status','Pending Contractor')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  151. }
  152. if(!empty($wo)){
  153. foreach ($wo as $key => $w) {
  154. $i++;
  155. $n1 = '';
  156. $reg_time = $w->updated_at;
  157. $expiry_date = $reg_time->addDays(3);
  158. $expiry_date = $expiry_date->getTimestamp();
  159. if($curr < $expiry_date) {
  160. $n1 = "New/";
  161. }
  162. $installer = '';
  163. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  164. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  165. $company = Company::where('_id',$w->contractor_id)->first();
  166. $building = ''; $unit = '-'; $name = '';
  167. if($form->type_application == 'R'){
  168. $building = $form->Subscriber->building_name;
  169. $unit = $form->Subscriber->unit_no;
  170. $name = $form->Subscriber->name;
  171. }else if($form->type_application == 'B'){
  172. if($form->Subscriber->unit_no != ''){
  173. $unit = '-';
  174. }else {
  175. $unit = $form->Subscriber->unit_no;
  176. }
  177. $building = '-';
  178. $name = $form->Subscriber->company_name;
  179. }
  180. if($w->installer_id != ''){
  181. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  182. $installer = $installer->StaffDetail->name;
  183. }
  184. if(empty($product)){
  185. $product = 'R Mbps';
  186. }else {
  187. $product = $product->package_name;
  188. }
  189. array_push($nested_data, array(
  190. 'formT' => $n1.$i.$w->Form->type_application,
  191. 'service' => $w->nature_work,
  192. 'wo' => $w->wo,
  193. 'name' => $name,
  194. 'phone' => $form->Subscriber->phone1,
  195. 'unit' => $unit,
  196. 'building' => $building,
  197. 'city' => $form->Subscriber->city,
  198. 'package' => $product,
  199. 'contractor' => $company->name,
  200. 'installer' => $installer,
  201. 'date' => date("d/m/Y", strtotime($w->dateTimeStart)),
  202. 'time' => date("h:i A", strtotime($w->dateTimeStart)),
  203. 'status' => $w->status,
  204. 'action' => $w->wo,
  205. ));
  206. }
  207. }
  208. return \DataTables::of($nested_data)->make(true);
  209. }
  210. public function getAllPendingNonPrelaid($year,$month,$day){
  211. $id = Auth::guard('contractor')->id();
  212. $user = Staff::with('StaffDetail')->find($id);
  213. $i = 0; $n1 = '';
  214. $curr = Carbon::now()->getTimestamp();
  215. $nested_data = array();
  216. if($year == 'null' && $month == 'null' && $day == 'null'){
  217. $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->get();
  218. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  219. $timestamp = $year."-01-01 00:00:00.000Z";
  220. $masa = strtotime($timestamp);
  221. $go = Carbon::createFromTimestamp($masa);
  222. $go2 = Carbon::createFromTimestamp($masa);
  223. $end_year = $go2->endOfYear();
  224. $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  225. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  226. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  227. $masa = strtotime($timestamp);
  228. $go = Carbon::createFromTimestamp($masa);
  229. $go2 = Carbon::createFromTimestamp($masa);
  230. $end_year = $go2->endOfMonth();
  231. $wo = WorkOrder::with('Form')->where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  232. }
  233. if(!empty($wo)){
  234. foreach ($wo as $key => $w) {
  235. $i++;
  236. $n1 = '';
  237. $reg_time = $w->updated_at;
  238. $expiry_date = $reg_time->addDays(3);
  239. $expiry_date = $expiry_date->getTimestamp();
  240. if($curr < $expiry_date) {
  241. $n1 = "New/";
  242. }
  243. $installer = '';
  244. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  245. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  246. $company = Company::where('_id',$w->contractor_id)->first();
  247. if($w->installer_id != ''){
  248. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  249. if(!empty($installer)){
  250. $installer = $installer->StaffDetail->name;
  251. }
  252. }
  253. $building = ''; $unit = '-'; $name = '';
  254. if($form->type_application == 'R'){
  255. $building = $form->Subscriber->building_name;
  256. $unit = $form->Subscriber->unit_no;
  257. $name = $form->Subscriber->name;
  258. }else if($form->type_application == 'B'){
  259. if($form->Subscriber->unit_no != ''){
  260. $unit = '-';
  261. }else {
  262. $unit = $form->Subscriber->unit_no;
  263. }
  264. $building = '-';
  265. $name = $form->Subscriber->company_name;
  266. }
  267. if(empty($product)){
  268. $product = 'R Mbps';
  269. }else {
  270. $product = $product->package_name;
  271. }
  272. $date = ''; $time = '';
  273. if($w->dateTimeStart == ''){
  274. $date = '';
  275. $time = '';
  276. }else {
  277. $date = date("d/m/Y", strtotime($w->dateTimeStart));
  278. $time = date("h:i A", strtotime($w->dateTimeStart));
  279. }
  280. array_push($nested_data, array(
  281. 'formT' => $n1.$i.$w->Form->type_application,
  282. 'service' => $w->nature_work,
  283. 'wo' => $w->wo,
  284. 'name' => $name,
  285. 'phone' => $form->Subscriber->phone1,
  286. 'unit' => $unit,
  287. 'building' => $building,
  288. 'city' => $form->Subscriber->city,
  289. 'package' => $product,
  290. 'contractor' => $company->name,
  291. 'installer' => $installer,
  292. 'date' => $date,
  293. 'time' => $time,
  294. 'status' => $w->status,
  295. 'action' => $w->wo,
  296. ));
  297. }
  298. }
  299. return \DataTables::of($nested_data)->make(true);
  300. }
  301. public function getAllPendingInstaller($year,$month,$day){
  302. $id = Auth::guard('contractor')->id();
  303. $user = Staff::with('StaffDetail')->find($id);
  304. $i = 0; $n1 = '';
  305. $curr = Carbon::now()->getTimestamp();
  306. $nested_data = array();
  307. if($year == 'null' && $month == 'null' && $day == 'null'){
  308. $wo = WorkOrder::with('Form')->where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->get();
  309. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  310. $timestamp = $year."-01-01 00:00:00.000Z";
  311. $masa = strtotime($timestamp);
  312. $go = Carbon::createFromTimestamp($masa);
  313. $go2 = Carbon::createFromTimestamp($masa);
  314. $end_year = $go2->endOfYear();
  315. $wo = WorkOrder::with('Form')->where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  316. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  317. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  318. $masa = strtotime($timestamp);
  319. $go = Carbon::createFromTimestamp($masa);
  320. $go2 = Carbon::createFromTimestamp($masa);
  321. $end_year = $go2->endOfMonth();
  322. $wo = WorkOrder::with('Form')->where('status','Pending Installer')->where('contractor_id',$user->StaffDetail->company_id)->orderBy('updated_at', 'desc')->whereBetween('created_at', [$go, $end_year])->get();
  323. }
  324. if(!empty($wo)){
  325. foreach ($wo as $key => $w) {
  326. $i++;
  327. $n1 = '';
  328. $reg_time = $w->updated_at;
  329. $expiry_date = $reg_time->addDays(3);
  330. $expiry_date = $expiry_date->getTimestamp();
  331. if($curr < $expiry_date) {
  332. $n1 = "New/";
  333. }
  334. $installer = '';
  335. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->Form->_id)->first();
  336. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$w->Form->type_application)->first();
  337. $company = Company::where('_id',$w->contractor_id)->first();
  338. if($w->installer_id != ''){
  339. $installer = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  340. if(!empty($installer)){
  341. $installer = $installer->StaffDetail->name;
  342. }
  343. }
  344. $building = ''; $unit = '-'; $name = '';
  345. if($form->type_application == 'R'){
  346. $building = $form->Subscriber->building_name;
  347. $unit = $form->Subscriber->unit_no;
  348. $name = $form->Subscriber->name;
  349. }else if($form->type_application == 'B'){
  350. if($form->Subscriber->unit_no != ''){
  351. $unit = '-';
  352. }else {
  353. $unit = $form->Subscriber->unit_no;
  354. }
  355. $building = '-';
  356. $name = $form->Subscriber->company_name;
  357. }
  358. if(empty($product)){
  359. $product = 'R Mbps';
  360. }else {
  361. $product = $product->package_name;
  362. }
  363. array_push($nested_data, array(
  364. 'formT' => $n1.$i.$w->Form->type_application,
  365. 'service' => $w->nature_work,
  366. 'wo' => $w->wo,
  367. 'name' => $name,
  368. 'phone' => $form->Subscriber->phone1,
  369. 'unit' => $unit,
  370. 'building' => $building,
  371. 'city' => $form->Subscriber->city,
  372. 'package' => $product,
  373. 'contractor' => $company->name,
  374. 'installer' => $installer,
  375. 'date' => date("d/m/Y", strtotime($w->dateTimeStart)),
  376. 'time' => date("h:i A", strtotime($w->dateTimeStart)),
  377. 'status' => $w->status,
  378. 'action' => $w->wo,
  379. ));
  380. }
  381. }
  382. return \DataTables::of($nested_data)->make(true);
  383. }
  384. public function getAllCompleted($year,$month,$day){
  385. $id = Auth::guard('contractor')->id();
  386. $user = Staff::with('StaffDetail')->find($id);
  387. $i = 0; $n1 = '';
  388. $curr = Carbon::now()->getTimestamp();
  389. $nested_data = array();
  390. if($year == 'null' && $month == 'null' && $day == 'null'){
  391. $doc = Docket::with('WorkOrder')->orderBy('updated_at', 'desc')->get();
  392. }else if($year != 'null' && $month == 'null' && $day == 'null'){
  393. $timestamp = $year."-01-01 00:00:00.000Z";
  394. $masa = strtotime($timestamp);
  395. $go = Carbon::createFromTimestamp($masa);
  396. $go2 = Carbon::createFromTimestamp($masa);
  397. $end_year = $go2->endOfYear();
  398. $doc = Docket::with('WorkOrder')->orderBy('updated_at', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
  399. }else if($year != 'null' && $month != 'null' && $day == 'null'){
  400. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  401. $masa = strtotime($timestamp);
  402. $go = Carbon::createFromTimestamp($masa);
  403. $go2 = Carbon::createFromTimestamp($masa);
  404. $end_year = $go2->endOfMonth();
  405. $doc = Docket::with('WorkOrder')->orderBy('updated_at', 'desc')->whereBetween('dateTimeStart', [$go, $end_year])->get();
  406. }
  407. if(!empty($doc)){
  408. foreach ($doc as $key => $w) {
  409. $i++;
  410. $n1 = '';
  411. if(!empty($w->updated_at)) {
  412. $reg_time = $w->updated_at;
  413. $expiry_date = $reg_time->addDays(3);
  414. $expiry_date = $expiry_date->getTimestamp();
  415. if($curr < $expiry_date) {
  416. $n1 = "New/";
  417. }
  418. }else {
  419. $n1 = '';
  420. }
  421. $installer = '';
  422. if(!empty($w->WorkOrder->_id)){
  423. $form = Form::with('Subscriber','PackageDetail')->where('_id',$w->WorkOrder->_id)->first();
  424. $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
  425. $company = Company::where('_id',$w->WorkOrder->contractor_id)->first();
  426. if($w->WorkOrder->installer_id != ''){
  427. $installer = Staff::with('StaffDetail')->withTrashed()->where('_id',$w->WorkOrder->installer_id)->first();
  428. $installer = $installer->StaffDetail->name;
  429. }
  430. if(empty($product)){
  431. $product = 'R Mbps';
  432. }else {
  433. $product = $product->package_name;
  434. }
  435. $building = ''; $unit = '-'; $name = '';
  436. if($form->type_application == 'R'){
  437. $building = $form->Subscriber->building_name;
  438. $unit = $form->Subscriber->unit_no;
  439. $name = $form->Subscriber->name;
  440. }else if($form->type_application == 'B'){
  441. if($form->Subscriber->unit_no != ''){
  442. $unit = '-';
  443. }else {
  444. $unit = $form->Subscriber->unit_no;
  445. }
  446. $building = '-';
  447. $name = $form->Subscriber->company_name;
  448. }
  449. if($w->WorkOrder->contractor_id == $user->StaffDetail->company_id){
  450. array_push($nested_data, array(
  451. 'formT' => $n1.$i.$form->type_application,
  452. 'service' => $w->nature_work,
  453. 'wo' => $w->WorkOrder->wo,
  454. 'name' => $name,
  455. 'phone' => $form->Subscriber->phone1,
  456. 'unit' => $unit,
  457. 'building' => $building,
  458. 'city' => $form->Subscriber->city,
  459. 'package' => $product,
  460. 'contractor' => $company->name,
  461. 'installer' => $installer,
  462. 'date' => date("d/m/Y", strtotime($w->end_job)),
  463. 'time' => date("h:i A", strtotime($w->end_job)),
  464. 'status' => $w->WorkOrder->status,
  465. 'docket' => $w->docket_id,
  466. 'action' => $w->WorkOrder->wo,
  467. ));
  468. }
  469. }
  470. }
  471. }
  472. return \DataTables::of($nested_data)->make(true);
  473. }
  474. public function generateWorkOrderPDF($wo){
  475. $id = Auth::guard('contractor')->id();
  476. $user = Staff::with('StaffDetail')->find($id);
  477. $wo = WorkOrder::where('wo',$wo)->first();
  478. $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first();
  479. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  480. if(empty($product)){
  481. if($form->PackageDetail->name == "30"){
  482. $product = '30Mbps';
  483. }else{
  484. $product = 'RMbps';
  485. }
  486. }else {
  487. $product = $product->package_name;
  488. }
  489. $created_by = Staff::with('StaffDetail')->find($wo->created_by)->first();
  490. if(empty($created_by)){
  491. $created_by = '';
  492. }
  493. $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
  494. $address = '';
  495. if($form->type_application == 'R'){
  496. if($form->Subscriber->street != ''){
  497. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  498. }else {
  499. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  500. }
  501. }else if($form->type_application == 'B'){
  502. if($form->Subscriber->unit_no != ''){
  503. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  504. }else {
  505. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  506. }
  507. }
  508. $pdf = PDF::loadView('pdf.workorder-pdf',compact('wo','form','product','created_at','created_by','address'));
  509. $pdf->setPaper('A4', 'potrait');
  510. return $pdf->stream();
  511. }
  512. public function updateWorkOrder(Request $request){
  513. $id = Auth::guard('contractor')->id();
  514. $user = Staff::with('StaffDetail')->find($id);
  515. $wo = WorkOrder::where('wo',$request->work_order)->first();
  516. if(!empty($wo)){
  517. $wo->nature_work = $request->task;
  518. $wo->pppoe_username = $request->pppoe_username;
  519. $wo->onu = $request->onu_ont;
  520. $wo->router = $request->router;
  521. $wo->n_phone = $request->n_phone;
  522. $wo->no_phone = $request->no_phone;
  523. $wo->remarks_custservice = $request->remark;
  524. $wo->created_by = $user->_id;
  525. $wo->save();
  526. return redirect('/contractor/work-order/list');
  527. // return redirect()->back()->with('success_msg', 'Success! Update work order '.$request->get('work_order'));
  528. }else {
  529. return redirect()->back()->with('error_msg', 'Cant update work order '.$request->get('work_order'));
  530. }
  531. }
  532. public function rescheduleWorkOrder(Request $request){
  533. $wod = WorkOrder::where('wo',$request->wo)->first();
  534. if(!empty($wod)){
  535. $wod->dateTimeStart = $request->start;
  536. $wod->dateTimeEnd = $request->end;
  537. $wod->installer_id = $request->installer;
  538. $wod->status = $request->type_work;
  539. $wod->save();
  540. return 'success';
  541. }else{
  542. return 'false';
  543. }
  544. }
  545. public function cancelCreateWorkOrder(Request $request){
  546. $wod = WorkOrder::where('wo',$request->wo)->first();
  547. if(!empty($wod)){
  548. $wod->delete();
  549. return 'true';
  550. }else{
  551. return 'false';
  552. }
  553. }
  554. public function updateWorkOrderReschedule(Request $request)
  555. {
  556. $data = array();
  557. $wod = WorkOrder::where('wo',$request->wo)->first();
  558. $form = Form::where('_id',$wod->_id)->first();
  559. $installer = Staff::with('StaffDetail')->where('_id',$wod->installer_id)->first();
  560. if(!empty($wod)){
  561. if($wod->status == 'Pending Contractor'){
  562. $wod->status = $request->type_work;
  563. $wod->installer_id = $request->installer;
  564. $wod->save();
  565. $formH = new FormStatus;
  566. $formH->form_id = $form->_id;
  567. $formH->status_id = 6;
  568. $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  569. $formH->status = 'Pending Installer';
  570. $formH->desc = 'This work order been assigned to particular installer ('.$installer->name.')';
  571. $form->formstatus()->save($formH);
  572. array_push($data, array(
  573. 'result' => 'yes',
  574. ));
  575. }else {
  576. $wod->status = $request->type_work;
  577. $wod->installer_id = $request->installer;
  578. $wod->save();
  579. array_push($data, array(
  580. 'result' => 'yes',
  581. ));
  582. }
  583. }else{
  584. array_push($data, array(
  585. 'result' => 'no',
  586. ));
  587. }
  588. return response()->json($data);
  589. }
  590. public function updateStatusWorkOrder($wo){
  591. $wod = WorkOrder::where('wo',$wo)->first();
  592. if(!empty($wod)){
  593. $wod->status = 'Success Non Prelaid';
  594. $wod->save();
  595. $form = Form::where('_id',$wod->_id)->first();
  596. $formH = new FormStatus;
  597. $formH->form_id = $form->_id;
  598. $formH->status_id = 7;
  599. $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  600. $formH->status = 'Success Prelaid';
  601. $formH->desc = 'Prelaid successfully';
  602. $form->formstatus()->save($formH);
  603. return redirect('/contractor/work-order/list');
  604. }
  605. }
  606. }