diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 61630861..ca3d271a 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -956,24 +956,38 @@ class JobOrderController extends BaseController if (empty($obj)) throw $this->createNotFoundException('The item does not exist'); + // check if cancelled already + if (!$obj->canDispatch()) + { + throw $this->createNotFoundException('Could not dispatch. Job Order is not pending.'); + // TODO: have this handled better, so UI shows the error + // $error_array['dispatch'] = 'Could not dispatch. Job Order is not pending.'; + } + // check if lat and lng are provided - if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) { + if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) + { $error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.'; } // check if hub is set - if (empty($req->request->get('hub'))) { + if (empty($req->request->get('hub'))) + { $error_array['hub'] = 'No hub selected.'; - } else { + } + else + { // get hub $hub = $em->getRepository(Hub::class)->find($req->request->get('hub')); - if (empty($hub)) { + if (empty($hub)) + { $error_array['hub'] = 'Invalid hub specified.'; } } - if (empty($error_array)) { + if (empty($error_array)) + { // coordinates $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); @@ -1001,7 +1015,8 @@ class JobOrderController extends BaseController } // check if any errors were found - if (!empty($error_array)) { + if (!empty($error_array)) + { // return validation failure response return $this->json([ 'success' => false, diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index cd4f14fb..d4a40373 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -726,4 +726,12 @@ class JobOrder return $this->flag_coolant; } + public function canDispatch() + { + if ($this->status == JOStatus::PENDING) + return true; + + return false; + } + }