You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkOrderController.php 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <?php
  2. namespace App\Http\Controllers\v3\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\v3\Api\BaseController;
  5. use File;
  6. use Carbon\Carbon;
  7. use App\LatestModel\Staff;
  8. use App\LatestModel\StaffDetail;
  9. use App\LatestModel\Module\Form;
  10. use App\LatestModel\Module\FormStatus;
  11. use App\LatestModel\Module\Subscriber;
  12. use App\LatestModel\Module\WorkOrder;
  13. use App\LatestModel\Module\Docket;
  14. use App\LatestModel\Module\PackageDetail;
  15. use App\LatestModel\Module\Company;
  16. use App\LatestModel\Module\Coverage;
  17. use App\LatestModel\Module\Product;
  18. class WorkOrderController extends BaseController
  19. {
  20. /**
  21. * View PDF
  22. *
  23. * @return json
  24. */
  25. public function viewWorkOrderPDF(Request $request){
  26. $wo = WorkOrder::where('wo',$request->id)->first();
  27. if(!empty($wo)){
  28. $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first();
  29. if(!empty($form->Subscriber) && !empty($form->PackageDetail)){
  30. return $this->sendResponse($form, '/v3/main/work-order-pdf/'.$request->id);
  31. }else{
  32. return $this->sendError('Package or subscriber not exist!', '');
  33. }
  34. }else{
  35. return $this->sendError('Work order not exist!', '');
  36. }
  37. }
  38. /**
  39. * Reset Work Order
  40. *
  41. * @return json
  42. */
  43. public function resetWorkOrder(Request $request){
  44. $wo = WorkOrder::where('wo',$request->id)->first();
  45. if(!empty($wo)){
  46. $docket = Docket::where('work_order_id', $request->id)->first();
  47. if(!empty($docket)){
  48. $docket->forceDelete();
  49. $wo->docket_id = '';
  50. $wo->status = 'Pending Contractor';
  51. $wo->save();
  52. $form = Form::where('_id', $wo->_id)->first();
  53. if(!empty($form)){
  54. $formH = new FormStatus;
  55. $formH->form_id = $form->_id;
  56. $formH->status_id = 17;
  57. $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  58. $formH->status = 'Reset Work Order';
  59. $formH->desc = 'This work order has been reset by customer service';
  60. $form->formstatus()->save($formH);
  61. }
  62. return $this->sendResponse($wo, 'Success Reset Work Order. You can check work order under category Pending Contractor');
  63. }else{
  64. return $this->sendError('Docket not exist!', '');
  65. }
  66. }else{
  67. return $this->sendError('Work order not exist!', '');
  68. }
  69. }
  70. /**
  71. * Delete Work Order
  72. *
  73. * @return json
  74. */
  75. public function deleteWorkOrder(Request $request){
  76. $wo = WorkOrder::where('wo',$request->id)->first();
  77. if(!empty($wo)){
  78. $wo->forceDelete();
  79. return $this->sendResponse($wo, 'Success Delete Work Order. You can access the form in customer tab under application form and re-assign work order again');
  80. }else{
  81. return $this->sendError('Work order not exist!', '');
  82. }
  83. }
  84. /**
  85. * Get Work Order Controlelr
  86. *
  87. * @return json
  88. */
  89. public function getWorkOrderData($status,$company_id,$startdate,$enddate,$type_work,$package,$building,$dealer){
  90. if($status == 'pending-contractor'){
  91. $status = 'Pending Contractor';
  92. }else if($status == 'pending-installer'){
  93. $status = 'Pending Installer';
  94. }else if($status == 'pending-non-prelaid'){
  95. $status = 'Pending Non Prelaid';
  96. }else if($status == 'success-non-prelaid'){
  97. $status = 'Success Non Prelaid';
  98. }else if($status == 'reschedule'){
  99. $status = 'Reschedule';
  100. }else if($status == 'suspend'){
  101. $status = 'Suspend';
  102. }else if($status == 'completed'){
  103. $status = 'Completed';
  104. }else if($status == 'cancelled'){
  105. $status = 'Cancelled';
  106. }
  107. if($startdate == '-' && $enddate == '-'){
  108. if($company_id == 'null'){
  109. if($package == 'null' && $dealer == 'null'){
  110. $wo = WorkOrder::with(['Form' => function($q) {
  111. $q->with('Subscriber','PackageDetail')->with('Company');
  112. }])->with('Company','Docket')->with(['Staff' => function($w){
  113. $w->with('StaffDetail');
  114. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  115. }else if($package == 'null' && $dealer != 'null'){
  116. $wo = WorkOrder::with(['Form' => function($q) use($dealer){
  117. $q->with('Subscriber','PackageDetail')->with('Company')->where('company_id', $dealer);
  118. }])->with('Company')->with(['Staff' => function($w){
  119. $w->with('StaffDetail');
  120. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  121. }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
  122. $wo = WorkOrder::with(['Form' => function($q) use($package){
  123. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  124. }])->with('Company')->with(['Staff' => function($w){
  125. $w->with('StaffDetail');
  126. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  127. }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
  128. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  129. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  130. }])->with('Company')->with(['Staff' => function($w){
  131. $w->with('StaffDetail');
  132. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  133. }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
  134. $wo = WorkOrder::with(['Form' => function($q) use($package,$building){
  135. $q->with(['Subscriber' => function($q) use($building) {
  136. $q->where('building_name', $building);
  137. }],'PackageDetail')->with('Company')->where('type_application', $package);
  138. }])->with('Company')->with(['Staff' => function($w){
  139. $w->with('StaffDetail');
  140. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  141. }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
  142. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer,$building){
  143. $q->with(['Subscriber' => function($q) use($building) {
  144. $q->where('building_name', $building);
  145. }],'PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  146. }])->with('Company')->with(['Staff' => function($w){
  147. $w->with('StaffDetail');
  148. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  149. }else if($package == 'B' && $dealer == 'null'){
  150. $wo = WorkOrder::with(['Form' => function($q) use($package){
  151. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  152. }])->with('Company')->with(['Staff' => function($w){
  153. $w->with('StaffDetail');
  154. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  155. }else if($package == 'B' && $dealer != 'null'){
  156. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  157. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  158. }])->with('Company')->with(['Staff' => function($w){
  159. $w->with('StaffDetail');
  160. }])->orderBy('dateTimeStart', 'DESC')->where('status',$status)->get();
  161. }
  162. }
  163. else if($company_id != 'null'){
  164. if($package == 'null' && $dealer == 'null'){
  165. $wo = WorkOrder::with(['Form' => function($q) {
  166. $q->with('Subscriber','PackageDetail')->with('Company');
  167. }])->with('Company')->with(['Staff' => function($w){
  168. $w->with('StaffDetail');
  169. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  170. }else if($package == 'null' && $dealer != 'null'){
  171. $wo = WorkOrder::with(['Form' => function($q) use($dealer){
  172. $q->with('Subscriber','PackageDetail')->with('Company')->where('company_id', $dealer);
  173. }])->with('Company')->with(['Staff' => function($w){
  174. $w->with('StaffDetail');
  175. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  176. }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
  177. $wo = WorkOrder::with(['Form' => function($q) use($package){
  178. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  179. }])->with('Company')->with(['Staff' => function($w){
  180. $w->with('StaffDetail');
  181. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  182. }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
  183. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  184. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  185. }])->with('Company')->with(['Staff' => function($w){
  186. $w->with('StaffDetail');
  187. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  188. }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
  189. $wo = WorkOrder::with(['Form' => function($q) use($package,$building){
  190. $q->with(['Subscriber' => function($q) use($building) {
  191. $q->where('building_name', $building);
  192. }],'PackageDetail')->with('Company')->where('type_application', $package);
  193. }])->with('Company')->with(['Staff' => function($w){
  194. $w->with('StaffDetail');
  195. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  196. }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
  197. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer,$building){
  198. $q->with(['Subscriber' => function($q) use($building) {
  199. $q->where('building_name', $building);
  200. }],'PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  201. }])->with('Company')->with(['Staff' => function($w){
  202. $w->with('StaffDetail');
  203. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  204. }else if($package == 'B' && $dealer == 'null'){
  205. $wo = WorkOrder::with(['Form' => function($q) use($package){
  206. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  207. }])->with('Company')->with(['Staff' => function($w){
  208. $w->with('StaffDetail');
  209. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  210. }else if($package == 'B' && $dealer != 'null'){
  211. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  212. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  213. }])->with('Company')->with(['Staff' => function($w){
  214. $w->with('StaffDetail');
  215. }])->orderBy('dateTimeStart', 'DESC')->where('contractor_id',$company_id)->where('status',$status)->get();
  216. }
  217. }
  218. }else if($startdate != '-'){
  219. $start = $startdate.' 00:00:00';
  220. if($enddate != '-'){
  221. $end = $enddate.' 23:59:59';
  222. }else{
  223. $end = $startdate.' 23:59:59';
  224. }
  225. if($company_id == 'null'){
  226. if($package == 'null' && $dealer == 'null'){
  227. $wo = WorkOrder::with(['Form' => function($q) {
  228. $q->with('Subscriber','PackageDetail')->with('Company');
  229. }])->with('Company')->with(['Staff' => function($w){
  230. $w->with('StaffDetail');
  231. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  232. }else if($package == 'null' && $dealer != 'null'){
  233. $wo = WorkOrder::with(['Form' => function($q) use($dealer){
  234. $q->with('Subscriber','PackageDetail')->with('Company')->where('company_id', $dealer);
  235. }])->with('Company')->with(['Staff' => function($w){
  236. $w->with('StaffDetail');
  237. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  238. }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
  239. $wo = WorkOrder::with(['Form' => function($q) use($package){
  240. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  241. }])->with('Company')->with(['Staff' => function($w){
  242. $w->with('StaffDetail');
  243. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  244. }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
  245. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  246. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  247. }])->with('Company')->with(['Staff' => function($w){
  248. $w->with('StaffDetail');
  249. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  250. }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
  251. $wo = WorkOrder::with(['Form' => function($q) use($package,$building){
  252. $q->with(['Subscriber' => function($q) use($building) {
  253. $q->where('building_name', $building);
  254. }],'PackageDetail')->with('Company')->where('type_application', $package);
  255. }])->with('Company')->with(['Staff' => function($w){
  256. $w->with('StaffDetail');
  257. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  258. }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
  259. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer,$building){
  260. $q->with(['Subscriber' => function($q) use($building) {
  261. $q->where('building_name', $building);
  262. }],'PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  263. }])->with('Company')->with(['Staff' => function($w){
  264. $w->with('StaffDetail');
  265. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  266. }else if($package == 'B' && $dealer == 'null'){
  267. $wo = WorkOrder::with(['Form' => function($q) use($package){
  268. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  269. }])->with('Company')->with(['Staff' => function($w){
  270. $w->with('StaffDetail');
  271. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  272. }else if($package == 'B' && $dealer != 'null'){
  273. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  274. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  275. }])->with('Company')->with(['Staff' => function($w){
  276. $w->with('StaffDetail');
  277. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('status',$status)->get();
  278. }
  279. }
  280. else if($company_id != 'null'){
  281. if($package == 'null' && $dealer == 'null'){
  282. $wo = WorkOrder::with(['Form' => function($q) {
  283. $q->with('Subscriber','PackageDetail')->with('Company');
  284. }])->with('Company')->with(['Staff' => function($w){
  285. $w->with('StaffDetail');
  286. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  287. }else if($package == 'null' && $dealer != 'null'){
  288. $wo = WorkOrder::with(['Form' => function($q) use($dealer){
  289. $q->with('Subscriber','PackageDetail')->with('Company')->where('company_id', $dealer);
  290. }])->with('Company')->with(['Staff' => function($w){
  291. $w->with('StaffDetail');
  292. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  293. }else if($package == 'R' && $building == 'null' && $dealer == 'null'){
  294. $wo = WorkOrder::with(['Form' => function($q) use($package){
  295. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  296. }])->with('Company')->with(['Staff' => function($w){
  297. $w->with('StaffDetail');
  298. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  299. }else if($package == 'R' && $building == 'null' && $dealer != 'null'){
  300. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  301. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  302. }])->with('Company')->with(['Staff' => function($w){
  303. $w->with('StaffDetail');
  304. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  305. }else if($package == 'R' && $building != 'null' && $dealer == 'null'){
  306. $wo = WorkOrder::with(['Form' => function($q) use($package,$building){
  307. $q->with(['Subscriber' => function($q) use($building) {
  308. $q->where('building_name', $building);
  309. }],'PackageDetail')->with('Company')->where('type_application', $package);
  310. }])->with('Company')->with(['Staff' => function($w){
  311. $w->with('StaffDetail');
  312. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  313. }else if($package == 'R' && $building != 'null' && $dealer != 'null'){
  314. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer,$building){
  315. $q->with(['Subscriber' => function($q) use($building) {
  316. $q->where('building_name', $building);
  317. }],'PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  318. }])->with('Company')->with(['Staff' => function($w){
  319. $w->with('StaffDetail');
  320. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  321. }else if($package == 'B' && $dealer == 'null'){
  322. $wo = WorkOrder::with(['Form' => function($q) use($package){
  323. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package);
  324. }])->with('Company')->with(['Staff' => function($w){
  325. $w->with('StaffDetail');
  326. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  327. }else if($package == 'B' && $dealer != 'null'){
  328. $wo = WorkOrder::with(['Form' => function($q) use($package,$dealer){
  329. $q->with('Subscriber','PackageDetail')->with('Company')->where('type_application', $package)->where('company_id', $dealer);
  330. }])->with('Company')->with(['Staff' => function($w){
  331. $w->with('StaffDetail');
  332. }])->orderBy('dateTimeStart', 'DESC')->whereBetween('dateTimeStart', array($start, $end))->where('contractor_id',$company_id)->where('status',$status)->get();
  333. }
  334. }
  335. }
  336. return $wo;
  337. }
  338. public function displayWorkOrder($status,$company_id,$startdate,$enddate,$type_work,$package,$building,$dealer){
  339. $i = 0;
  340. $curr = Carbon::now()->getTimestamp();
  341. $nested_data = array();
  342. $wo = $this->getWorkOrderData($status,$company_id,$startdate,$enddate,$type_work,$package,$building,$dealer);
  343. // return $wo;
  344. if(!empty($wo)){
  345. foreach ($wo as $key => $w) {
  346. $n1 = ''; $do = ''; $labelD = '';
  347. $reg_time = Carbon::createFromFormat('Y-m-d H:i:s', $w->created_at);
  348. $expiry_date = $reg_time->addDays(3);
  349. $expiry_date = $expiry_date->getTimestamp();
  350. if($curr < $expiry_date) { $n1 = 'New/'; }
  351. else{ $n1 = ''; }
  352. if(!empty($w->Form->Subscriber) && !empty($w->Form->PackageDetail)){
  353. if(!empty($w->Form->Company)){
  354. $com = explode(' ',trim($w->Form->Company->name));
  355. $labelD = 'D/'.$com[0].'.';
  356. }else{ $labelD = ''; }
  357. if(!empty($w->Company)){
  358. $company = $w->Company->name;
  359. }
  360. $installer = '';
  361. if(!empty($w->Staff)){
  362. $installer = $w->Staff->StaffDetail->name;
  363. }
  364. $docket = '';
  365. if($status == 'completed' || $status == 'cancelled'){
  366. if(!empty($w->Docket)){
  367. $docket = $w->Docket->docket_id;
  368. }
  369. }
  370. if($w->Form->PackageDetail->name == '1'){
  371. $product = $w->Form->PackageDetail->name .'Gbps';
  372. }else if($w->Form->PackageDetail->name == 'NA'){
  373. $product = $w->Form->PackageDetail->name;
  374. }else {
  375. $product = $w->Form->PackageDetail->name .'Mbps';
  376. }
  377. $unit = ''; $building = ''; $address = '';
  378. if($w->Form->type_application == 'R'){
  379. $building = $w->Form->Subscriber->building_name;
  380. $unit = $w->Form->Subscriber->unit_no;
  381. if($w->Form->Subscriber->street != ''){
  382. $address = $w->Form->Subscriber->street;
  383. }else {
  384. $address = '-';
  385. }
  386. }else if($w->Form->type_application == 'B'){
  387. if($w->Form->Subscriber->unit_no == ''){
  388. $unit = '-';
  389. }else {
  390. $unit = $w->Form->Subscriber->unit_no;
  391. }
  392. $building = $w->Form->Subscriber->company_name;
  393. $address = $w->Form->Subscriber->street;
  394. }
  395. if($w->nature_work == $type_work){
  396. $i++;
  397. array_push($nested_data, array(
  398. 'formT' => $n1.$i.$w->Form->type_application,
  399. 'service' => $w->nature_work,
  400. 'wo' => $w->wo,
  401. 'name' => $labelD.$w->Form->Subscriber->name,
  402. 'phone' => $w->Form->Subscriber->phone1,
  403. 'unit' => $unit,
  404. 'building' => $building,
  405. 'city' => $w->Form->Subscriber->city,
  406. 'package' => $product,
  407. 'contractor' => $company,
  408. 'installer' => $installer,
  409. 'date' => date("d/m/Y", strtotime($w->dateTimeStart)),
  410. 'time' => date("h:i A", strtotime($w->dateTimeStart)),
  411. 'status' => $w->status,
  412. 'docket' => $docket,
  413. 'action' => $w->wo,
  414. ));
  415. }else if($type_work == 'null'){
  416. $i++;
  417. array_push($nested_data, array(
  418. 'formT' => $n1.$i.$w->Form->type_application,
  419. 'service' => $w->nature_work,
  420. 'wo' => $w->wo,
  421. 'name' => $labelD.$w->Form->Subscriber->name,
  422. 'phone' => $w->Form->Subscriber->phone1,
  423. 'unit' => $unit,
  424. 'building' => $building,
  425. 'city' => $w->Form->Subscriber->city,
  426. 'package' => $product,
  427. 'contractor' => $company,
  428. 'installer' => $installer,
  429. 'date' => date("d/m/Y", strtotime($w->dateTimeStart)),
  430. 'time' => date("h:i A", strtotime($w->dateTimeStart)),
  431. 'status' => $w->status,
  432. 'docket' => $docket,
  433. 'action' => $w->wo,
  434. ));
  435. }
  436. }
  437. }
  438. }
  439. return \DataTables::of($nested_data)->make(true);
  440. }
  441. public function updateStatusWorkOrderNonPrelaid(Request $request){
  442. $wod = WorkOrder::where('wo', $request->id)->first();
  443. if(!empty($wod)){
  444. $wod->status = 'Success Non Prelaid';
  445. $wod->save();
  446. $form = Form::where('_id',$wod->_id)->first();
  447. $formH = new FormStatus;
  448. $formH->form_id = $form->_id;
  449. $formH->status_id = 7;
  450. $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
  451. $formH->status = 'Success Non Prelaid';
  452. $formH->desc = 'Prelaid successfully';
  453. $form->formstatus()->save($formH);
  454. return $this->sendResponse($wod, 'Successfully confirm assign/reassign installer');
  455. }else{
  456. return $this->sendError('Work order id cant be found!', '');
  457. }
  458. }
  459. }