Add rider api get job order call #119
This commit is contained in:
parent
5b94b1a592
commit
d5fb5222ca
3 changed files with 124 additions and 7 deletions
|
|
@ -15,13 +15,27 @@ rapi_logout:
|
|||
controller: App\Controller\RAPIController::logout
|
||||
methods: [POST]
|
||||
|
||||
rapi_get_status:
|
||||
path: /rapi/status
|
||||
controller: App\Controller\RAPIController::getStatus
|
||||
rapi_jo_get:
|
||||
path: /rapi/joborder
|
||||
controller: App\Controller\RAPIController::getJobOrder
|
||||
methods: [GET]
|
||||
|
||||
rapi_set_status:
|
||||
path: /rapi/status
|
||||
controller: App\Controller\RAPIController::setStatus
|
||||
rapi_jo_accept:
|
||||
path: /rapi/accept
|
||||
controller: App\Controller\RAPIController::acceptJobOrder
|
||||
methods: [POST]
|
||||
|
||||
rapi_jo_cancel:
|
||||
path: /rapi/cancel
|
||||
controller: App\Controller\RAPIController::cancelJobOrder
|
||||
methods: [POST]
|
||||
|
||||
rapi_arrive:
|
||||
path: /rapi/arrive
|
||||
controller: App\Controller\RAPIController::cancelJobOrder
|
||||
methods: [POST]
|
||||
|
||||
rapi_payment:
|
||||
path: /rapi/payment
|
||||
controller: App\Controller\RAPIController::cancelJobOrder
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -259,8 +259,94 @@ class RAPIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
public function getJobOrder(Request $req)
|
||||
{
|
||||
// get the job order of the rider assigned to this session
|
||||
$required_params = [];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// are we logged in?
|
||||
if (!$this->session->hasRider())
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('No logged in rider.');
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
$rider = $this->session->getRider();
|
||||
|
||||
// do we have a job order?
|
||||
$jo = $rider->getActiveJobOrder();
|
||||
if ($jo == null)
|
||||
{
|
||||
$data = [
|
||||
'job_order' => null
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$coord = $jo->getCoordinates();
|
||||
$cust = $jo->getCustomer();
|
||||
$cv = $jo->getCustomerVehicle();
|
||||
$v = $cv->getVehicle();
|
||||
$inv = $jo->getInvoice();
|
||||
|
||||
// invoice items
|
||||
$inv_items = [];
|
||||
foreach ($inv->getItems() as $item)
|
||||
{
|
||||
$inv_items[] = [
|
||||
'id' => $item->getID(),
|
||||
'title' => $item->getTitle(),
|
||||
'qty' => $item->getQuantity(),
|
||||
'price' => $item->getPrice(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'job_order' => [
|
||||
'id' => $jo->getID(),
|
||||
'service_type' => $jo->getServiceType(),
|
||||
'date_schedule' => $jo->getDateSchedule()->format('Ymd'),
|
||||
'longitude' => $coord->getLongitude(),
|
||||
'latitude' => $coord->getLatitude(),
|
||||
'status' => $jo->getStatus(),
|
||||
'customer' => [
|
||||
'title' => $cust->getTitle(),
|
||||
'first_name' => $cust->getFirstName(),
|
||||
'last_name' => $cust->getLastName(),
|
||||
'phone_mobile' => $cust->getPhoneMobile(),
|
||||
],
|
||||
'vehicle' => [
|
||||
'manufacturer' => $v->getManufacturer()->getName(),
|
||||
'make' => $v->getMake(),
|
||||
'model' => $cv->getModelYear(),
|
||||
'plate_number' => $cv->getPlateNumber(),
|
||||
'color' => $cv->getColor(),
|
||||
],
|
||||
'delivery_instructions' => $jo->getDeliveryInstructions(),
|
||||
'delivery_address' => $jo->getDeliveryAddress(),
|
||||
'landmark' => $jo->getLandmark(),
|
||||
'invoice' => [
|
||||
'discount' => $inv->getDiscount(),
|
||||
'trade_in' => $inv->getTradeIn(),
|
||||
'total_price' => $inv->getTotalPrice(),
|
||||
'vat' => $inv->getVat(),
|
||||
'items' => $inv_items,
|
||||
],
|
||||
'mode_of_payment' => $jo->getModeOfPayment(),
|
||||
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$res->setData($data);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function setStatus(Request $req)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
|
||||
use App\Ramcar\JOStatus;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="rider")
|
||||
|
|
@ -290,4 +292,19 @@ class Rider
|
|||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getActiveJobOrder()
|
||||
{
|
||||
$active_status = [
|
||||
JOStatus::ASSIGNED,
|
||||
JOStatus::IN_TRANSIT,
|
||||
JOStatus::IN_PROGRESS,
|
||||
];
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->in('status', $active_status))
|
||||
->getFirstResult(1);
|
||||
|
||||
return $this->job_orders->matching($criteria)[0];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue