diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 8b60e412..7a506492 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -571,8 +571,9 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface public function getJobOrder(Request $req) { - // get the job order of the rider assigned to this session - $required_params = []; + $required_params = [ + 'jo_id' + ]; $data = $this->checkParamsAndKey($req, $required_params); if (isset($data['error'])) return $data; @@ -588,8 +589,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $rider = $this->session->getRider(); - // do we have a job order? - $jo = $rider->getActiveJobOrder(); + // get jo + $jo_id = $req->query->get('jo_id'); + + $jo = $this->em->getRepository(JobOrder::class)->find($jo_id); if ($jo == null) { $data = [ @@ -598,6 +601,23 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface } else { + if ($jo->getRider() == null) + { + $data = [ + 'error' => 'Job order selected has no rider assigned.' + ]; + return $data; + } + + // check if rider is assigned to JO + if ($rider->getID() != $jo->getRider()->getID()) + { + $data = [ + 'error' => 'Job order selected is not assigned to rider' + ]; + return $data; + } + $coord = $jo->getCoordinates(); $cust = $jo->getCustomer(); $cv = $jo->getCustomerVehicle(); @@ -615,7 +635,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface else $batt_id = $item_batt->getID(); - $inv_items[] = [ + $inv_items[] = [ 'id' => $item->getID(), 'title' => $item->getTitle(), 'qty' => $item->getQuantity(),