Add rider status API call
This commit is contained in:
parent
ed75a3936a
commit
21b7727278
3 changed files with 96 additions and 0 deletions
|
|
@ -79,3 +79,8 @@ api_ongoing:
|
||||||
path: /api/job_order/ongoing
|
path: /api/job_order/ongoing
|
||||||
controller: App\Controller\APIController::getOngoing
|
controller: App\Controller\APIController::getOngoing
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
api_rider_status:
|
||||||
|
path: /api/rider
|
||||||
|
controller: App\Controller\APIController::getRiderStatus
|
||||||
|
methods: [GET]
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use App\Ramcar\JOStatus;
|
||||||
use App\Ramcar\InvoiceCriteria;
|
use App\Ramcar\InvoiceCriteria;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
use App\Ramcar\WarrantyClass;
|
use App\Ramcar\WarrantyClass;
|
||||||
|
use App\Ramcar\APIRiderStatus;
|
||||||
|
|
||||||
use App\Service\InvoiceCreator;
|
use App\Service\InvoiceCreator;
|
||||||
|
|
||||||
|
|
@ -924,6 +925,74 @@ class APIController extends Controller
|
||||||
return $res->getReturnResponse();
|
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)
|
public function getOngoing(Request $req)
|
||||||
{
|
{
|
||||||
$required_params = [];
|
$required_params = [];
|
||||||
|
|
|
||||||
22
src/Ramcar/APIRiderStatus.php
Normal file
22
src/Ramcar/APIRiderStatus.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ramcar;
|
||||||
|
|
||||||
|
class APIRiderStatus extends NameValue
|
||||||
|
{
|
||||||
|
const NO_PENDING_JO = 'no_pending_jo';
|
||||||
|
const OUTLET_ASSIGN = 'outlet_assign';
|
||||||
|
const RIDER_ASSIGN = 'rider_assign';
|
||||||
|
const RIDER_PICK_UP = 'rider_pick_up';
|
||||||
|
const RIDER_OTW = 'rider_otw';
|
||||||
|
const RIDER_UNAVAIL = 'rider_unavail';
|
||||||
|
|
||||||
|
const COLLECTION = [
|
||||||
|
'no_pending_jo' => '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',
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue