diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 1d1d7336..4a5a7bf3 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -870,11 +870,12 @@ class JobOrderController extends Controller /** * @Menu(selected="jo_onestep_edit_form") */ - public function oneStepEditForm($id, JobOrderHandlerInterface $jo_handler, GISManagerInterface $gis) + public function oneStepEditForm($id, JobOrderHandlerInterface $jo_handler, + GISManagerInterface $gis, MapTools $map_tools) { $this->denyAccessUnlessGranted('jo_onestep.edit', null, 'No access.'); - $params = $jo_handler->initializeOneStepEditForm($id); + $params = $jo_handler->initializeOneStepEditForm($id, $map_tools); $params['submit_url'] = $this->generateUrl('jo_onestep_edit_submit', ['id' => $id]); $params['return_url'] = $this->generateUrl('jo_open'); $params['map_js_file'] = $gis->getJSJOFile(); @@ -885,7 +886,26 @@ class JobOrderController extends Controller return $this->render($template, $params); } - public function oneStepEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler) + public function oneStepEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler, $id) { + $this->denyAccessUnlessGranted('jo_onestep.edit', null, 'No access.'); + + $error_array = []; + $error_array = $jo_handler->generateOneStepJobOrder($req, $id); + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 860058d4..87e1dc9d 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -1267,19 +1267,60 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface return $params; } - public function initializeOneStepEditForm($id) + public function initializeOneStepEditForm($id, $map_tools) { $em = $this->em; - $jo = $em->getRepository(JobOrder::class)->find($id); + $obj = $em->getRepository(JobOrder::class)->find($id); - $params['obj'] = $jo; - $params['mode'] = 'onestep_edit'; - $params['cvid'] = $jo->getCustomerVehicle()->getID(); - $params['vid'] = $jo->getCustomerVehicle()->getVehicle()->getID(); + $params['obj'] = $obj; + $params['mode'] = 'onestep-edit'; + $params['cvid'] = $obj->getCustomerVehicle()->getID(); + $params['vid'] = $obj->getCustomerVehicle()->getVehicle()->getID(); $this->fillDropdownParameters($params); $this->fillFormTags($params); + // get the hubs + // TODO: move this snippet to a function + $hubs = $map_tools->getClosestHubs($obj->getCoordinates(), 50, date("H:i:s")); + + $params['hubs'] = []; + + // format duration and distance into friendly time + foreach ($hubs as $hub) { + // duration + $seconds = $hub['duration']; + + if (!empty($seconds) && $seconds > 0) { + $hours = floor($seconds / 3600); + $minutes = ceil(($seconds / 60) % 60); + + $hub['duration'] = ($hours > 0 ? number_format($hours) . " hr" . ($hours > 1 ? "s" : '') . ($minutes > 0 ? ", " : '') : '') . ($minutes > 0 ? number_format($minutes) . " min" . ($minutes > 1 ? "s" : '') : ''); + } else { + $hub['duration'] = false; + } + + // distance + $meters = $hub['distance']; + + if (!empty($meters) && $meters > 0) { + $hub['distance'] = round($meters / 1000) . " km"; + } else { + $hub['distance'] = false; + } + + // counters + $hub['rider_count'] = count($hub['hub']->getAvailableRiders()); + $hub['jo_count'] = count($hub['hub']->getForAssignmentJobOrders()); + + // check for rejection + $hub['flag_rejected'] = false; + $hub_id = $hub['hub']->getID(); + + $params['hubs'][] = $hub; + } + + // get template to display $params['template'] = $this->getTwigTemplate('jo_onestep_edit_form'); diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index 4a419b60..1da5df4f 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -17,257 +17,270 @@