Merge branch '428-cmb-new-api-calls' into '424-cmb-release'
Resolve "CMB - new API calls" See merge request jankstudio/resq!494
This commit is contained in:
commit
9728c4cae7
4 changed files with 220 additions and 1 deletions
|
|
@ -129,3 +129,13 @@ cmb_rapi_jo_finish_photos_upload:
|
|||
path: /cmbrapi/uploadfinishphotos
|
||||
controller: App\Controller\CMBRAPIController::uploadFinishPhotos
|
||||
methods: [POST]
|
||||
|
||||
cmb_rapi_status:
|
||||
path: /cmbrapi/status
|
||||
controller: App\Controller\CMBRAPIController::getStatus
|
||||
methods: [GET]
|
||||
|
||||
cmb_rapi_jo_ongoing:
|
||||
path: /cmbrapi/joongoing
|
||||
controller: App\Controller\CMBRAPIController::getOngoingJobOrder
|
||||
methods: [GET]
|
||||
|
|
|
|||
|
|
@ -642,4 +642,53 @@ class CMBRAPIController extends Controller
|
|||
// response
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getStatus(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
||||
{
|
||||
$res = new NewAPIResult();
|
||||
|
||||
$data = $rapi_handler->getStatus($req);
|
||||
|
||||
if (isset($data['error']))
|
||||
{
|
||||
$message = $data['error'];
|
||||
$title = $data['title'];
|
||||
|
||||
$res->setError(true)
|
||||
->setErrorTitle($title)
|
||||
->setErrorMessage($message);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res->setData($data);
|
||||
}
|
||||
|
||||
// response
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getOngoingJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
||||
{
|
||||
$res = new NewAPIResult();
|
||||
|
||||
$data = $rapi_handler->getOngoingJobOrder($req);
|
||||
|
||||
if (isset($data['error']))
|
||||
{
|
||||
$message = $data['error'];
|
||||
$title = $data['title'];
|
||||
|
||||
$res->setError(true)
|
||||
->setErrorTitle($title)
|
||||
->setErrorMessage($message);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res->setData($data);
|
||||
}
|
||||
|
||||
// response
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,6 +347,11 @@ class Rider
|
|||
return $this->job_orders->matching($criteria)[0];
|
||||
}
|
||||
|
||||
public function getRiderActiveJobOrder()
|
||||
{
|
||||
return $this->active_job_order;
|
||||
}
|
||||
|
||||
public function getOpenJobOrders()
|
||||
{
|
||||
$active_status = [
|
||||
|
|
|
|||
|
|
@ -718,6 +718,8 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
return $data;
|
||||
}
|
||||
|
||||
// TODO: put JO in job queue
|
||||
|
||||
// TODO: refactor this into a jo handler class, so we don't have to repeat for control center
|
||||
// TODO: send mqtt event (?)
|
||||
// add event log
|
||||
|
|
@ -1244,6 +1246,9 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
return $data;
|
||||
}
|
||||
|
||||
// set jo status to in progress
|
||||
$jo->setStatus(JOStatus::IN_PROGRESS);
|
||||
|
||||
// add event log
|
||||
$rider = $this->session->getRider();
|
||||
$event = new JOEvent();
|
||||
|
|
@ -1623,6 +1628,156 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
return $data;
|
||||
}
|
||||
|
||||
public function getStatus(Request $req)
|
||||
{
|
||||
$required_params = [];
|
||||
$data = $this->checkParamsAndKey($req, $required_params);
|
||||
if (isset($data['error']))
|
||||
{
|
||||
$data['title'] = 'Failed Get Status';
|
||||
return $data;
|
||||
}
|
||||
|
||||
$rider = $this->session->getRider();
|
||||
|
||||
$rider_status = $rider->isAvailable();
|
||||
|
||||
$status = 'Offline';
|
||||
if ($rider_status)
|
||||
$status = 'Online';
|
||||
|
||||
$data = [
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getOngoingJobOrder(Request $req)
|
||||
{
|
||||
$required_params = [];
|
||||
$data = $this->checkParamsAndKey($req, $required_params);
|
||||
if (isset($data['error']))
|
||||
{
|
||||
$data['title'] = 'Failed Get Ongoing Job Order';
|
||||
return $data;
|
||||
}
|
||||
|
||||
// are we logged in?
|
||||
if (!$this->session->hasRider())
|
||||
{
|
||||
$data = [
|
||||
'title' => 'Failed Get Ongoing Job Order',
|
||||
'error' => 'No logged in rider.'
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
$rider = $this->session->getRider();
|
||||
|
||||
// check if we have an active JO
|
||||
$jo = $rider->getRiderActiveJobOrder();
|
||||
if ($jo == null)
|
||||
{
|
||||
$data = [
|
||||
'title' => 'Failed Get Ongoing Job Order',
|
||||
'error' => 'No active job order.'
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
$coord = $jo->getCoordinates();
|
||||
$cust = $jo->getCustomer();
|
||||
$cv = $jo->getCustomerVehicle();
|
||||
$v = $cv->getVehicle();
|
||||
$inv = $jo->getInvoice();
|
||||
$promo = $inv->getPromo();
|
||||
|
||||
// invoice items
|
||||
$inv_items = [];
|
||||
foreach ($inv->getItems() as $item)
|
||||
{
|
||||
$item_batt = $item->getBattery();
|
||||
if ($item_batt == null)
|
||||
$batt_id = null;
|
||||
else
|
||||
$batt_id = $item_batt->getID();
|
||||
|
||||
$inv_items[] = [
|
||||
'id' => $item->getID(),
|
||||
'title' => $item->getTitle(),
|
||||
'qty' => $item->getQuantity(),
|
||||
'price' => $item->getPrice(),
|
||||
'batt_id' => $batt_id,
|
||||
];
|
||||
}
|
||||
|
||||
// promo
|
||||
if ($promo != null)
|
||||
{
|
||||
$promo_data = [
|
||||
'id' => $promo->getID(),
|
||||
'name' => $promo->getName(),
|
||||
'code' => $promo->getCode(),
|
||||
'discount_rate' => $promo->getDiscountRate(),
|
||||
'discount_apply' => $promo->getDiscountApply(),
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$promo_data = null;
|
||||
}
|
||||
|
||||
$trade_in_type = $jo->getTradeInType();
|
||||
if (empty($trade_in_type))
|
||||
$trade_in_type = 'none';
|
||||
|
||||
$data = [
|
||||
'job_order' => [
|
||||
'id' => $jo->getID(),
|
||||
'service_type' => $jo->getServiceType(),
|
||||
'date_schedule' => $jo->getDateSchedule()->format('Ymd H:i:s'),
|
||||
'longitude' => $coord->getLongitude(),
|
||||
'latitude' => $coord->getLatitude(),
|
||||
'status' => $jo->getStatus(),
|
||||
'customer' => [
|
||||
'title' => $cust->getTitle(),
|
||||
'first_name' => $cust->getFirstName(),
|
||||
'last_name' => $cust->getLastName(),
|
||||
'phone_mobile' => $this->country_code . $cust->getPhoneMobile(),
|
||||
],
|
||||
'vehicle' => [
|
||||
'manufacturer' => $v->getManufacturer()->getName(),
|
||||
'make' => $v->getMake(),
|
||||
'model' => $cv->getModelYear(),
|
||||
'plate_number' => $cv->getPlateNumber(),
|
||||
'color' => $cv->getColor(),
|
||||
],
|
||||
'or_num' => $jo->getORNum(),
|
||||
'or_name' => $jo->getORName(),
|
||||
'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(),
|
||||
'trade_in_type' => $trade_in_type,
|
||||
'promo' => $promo_data,
|
||||
// TODO: load the actual
|
||||
'has_warranty_doc' => false,
|
||||
'flag_coolant' => $jo->hasCoolant(),
|
||||
'has_motolite' => $cv->hasMotoliteBattery(),
|
||||
]
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function checkMissingParameters(Request $req, $params = [])
|
||||
{
|
||||
$missing = [];
|
||||
|
|
@ -1719,7 +1874,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$rider = $this->session->getRider();
|
||||
|
||||
// check if we have an active JO
|
||||
$jo = $rider->getActiveJobOrder();
|
||||
$jo = $rider->getRiderActiveJobOrder();
|
||||
if ($jo == null)
|
||||
{
|
||||
$data = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue