diff --git a/config/routes/api.yaml b/config/routes/api.yaml index 459cd408..cd710e76 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -79,3 +79,8 @@ api_ongoing: path: /api/job_order/ongoing controller: App\Controller\APIController::getOngoing methods: [GET] + +api_rider_status: + path: /api/rider + controller: App\Controller\APIController::getRiderStatus + methods: [GET] diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index f9696561..a7422e60 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -17,6 +17,7 @@ use App\Ramcar\JOStatus; use App\Ramcar\InvoiceCriteria; use App\Ramcar\ServiceType; use App\Ramcar\WarrantyClass; +use App\Ramcar\APIRiderStatus; use App\Service\InvoiceCreator; @@ -924,6 +925,74 @@ class APIController extends Controller return $res->getReturnResponse(); } + public function getRiderStatus(Request $req) + { + $required_params = []; + $em = $this->getDoctrine()->getManager(); + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get customer + $cust = $this->session->getCustomer(); + if ($cust == null) + { + $res->setError(true) + ->setErrorMessage('No customer information found'); + return $res->getReturnResponse(); + } + + // check if we have an ongoing job order + $ongoing_jos = $em->getRepository(JobOrder::class)->findBy([ + 'customer' => $cust, + 'status' => [JOStatus::PENDING, JOStatus::RIDER_ASSIGN, JOStatus::ASSIGNED, JOStatus::IN_PROGRESS], + ]); + if (count($ongoing_jos) <= 0) + { + $res->setData([ + 'status' => APIRiderStatus::NO_PENDING_JO + ]); + return $res->getReturnResponse(); + } + + // get first jo that's pending + $jo = $ongoing_jos[0]; + switch ($jo->getStatus()) + { + case JOStatus::PENDING: + $res->setData([ + 'status' => APIRiderStatus::OUTLET_ASSIGN, + 'jo_id' => $jo->getID(), + ]); + return $res->getReturnResponse(); + case JOStatus::RIDER_ASSIGN: + $res->setData([ + 'status' => APIRiderStatus::RIDER_ASSIGN, + 'jo_id' => $jo->getID(), + ]); + return $res->getReturnResponse(); + case JOStatus::ASSIGNED: + $coord = $jo->getOutlet()->getCoordinates(); + $res->setData([ + 'status' => APIRiderStatus::RIDER_PICK_UP, + 'jo_id' => $jo->getID(), + // TODO: fix this to actual location of rider + 'lcoation' => [ + 'long' => $coord->getLongitude(), + 'lat' => $coord->getLatitude() + ] + ]); + return $res->getReturnResponse(); + } + + + + $res->setData($data); + + + return $res->getReturnResponse(); + } + public function getOngoing(Request $req) { $required_params = []; diff --git a/src/Ramcar/APIRiderStatus.php b/src/Ramcar/APIRiderStatus.php new file mode 100644 index 00000000..a6f28c27 --- /dev/null +++ b/src/Ramcar/APIRiderStatus.php @@ -0,0 +1,22 @@ + 'No pending job order', + 'outlet_assign' => 'Waiting for outlet assignment', + 'rider_assign' => 'Waiting for rider assignment', + 'rider_pick_up' => 'Rider is picking up item from outlet', + 'rider_otw' => 'Rider is on the way to customer', + 'rider_unavail' => 'No available rider for delivery', + ]; +}