Modify location support. #591
This commit is contained in:
parent
baaa832794
commit
bfbd4d4045
3 changed files with 48 additions and 67 deletions
|
|
@ -154,3 +154,11 @@ access_keys:
|
||||||
label: Cancel Job Order
|
label: Cancel Job Order
|
||||||
- id: mobile_jo.get.history
|
- id: mobile_jo.get.history
|
||||||
label: Get Job Order History
|
label: Get Job Order History
|
||||||
|
- id: mobile_jo.get.invoice
|
||||||
|
label: Get Job Order Invoice
|
||||||
|
- id: mobile_jo.location.support
|
||||||
|
label: Check Location Support
|
||||||
|
- id: mobile_jo.nearest_hub.get
|
||||||
|
label: Get Nearest Hub and Slots
|
||||||
|
- id: mobile_jo.schedule_option.status
|
||||||
|
label: Schedule Option Status
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ resqapi_jo_invoice:
|
||||||
resqapi_location_support:
|
resqapi_location_support:
|
||||||
path: /resqapi/location_support
|
path: /resqapi/location_support
|
||||||
controller: App\Controller\ResqAPI\JobOrderController:locationSupport
|
controller: App\Controller\ResqAPI\JobOrderController:locationSupport
|
||||||
methods: [GET]
|
methods: [POST]
|
||||||
|
|
||||||
resqapi_nearest_hub_slots:
|
resqapi_nearest_hub_slots:
|
||||||
path: /resqapi/hub_slots
|
path: /resqapi/hub_slots
|
||||||
|
|
|
||||||
|
|
@ -476,93 +476,67 @@ class JobOrderController extends APIController
|
||||||
return new APIResponse(true, 'Job order history found', $data);
|
return new APIResponse(true, 'Job order history found', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: modify for MobileUser
|
public function getJOInvoice(Request $req, EntityManagerInterface $em, MobileAPIHandler $mah)
|
||||||
public function getJOInvoice(Request $req, EntityManagerInterface $em)
|
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('mobile_jo.get.invoice', null, 'No access.');
|
||||||
|
|
||||||
$required_params = [
|
$required_params = [
|
||||||
'jo_id',
|
'jo_id',
|
||||||
];
|
];
|
||||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
|
||||||
if ($res->isError())
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
|
|
||||||
// get job order
|
$msg = $this->checkRequiredParameters($req, $required_params);
|
||||||
$jo_id = $req->query->get('jo_id');
|
if ($msg)
|
||||||
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
return new APIResponse(false, $msg);
|
||||||
if ($jo == null)
|
|
||||||
{
|
|
||||||
$res->setError(true)
|
|
||||||
->setErrorMessage('No job order found');
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// get customer
|
// get capi user to link to mobile user
|
||||||
$cust = $this->session->getCustomer();
|
$user_id = $this->getUser()->getID();
|
||||||
|
|
||||||
|
// get mobile user
|
||||||
|
$mobile_user = $mah->findMobileUser($user_id);
|
||||||
|
|
||||||
|
if ($mobile_user == null)
|
||||||
|
return new APIResponse(false, 'No mobile user found.');
|
||||||
|
|
||||||
|
// customer
|
||||||
|
$cust = $mobile_user->getCustomer();
|
||||||
if ($cust == null)
|
if ($cust == null)
|
||||||
{
|
return new APIResponse(false, 'No customer information found');
|
||||||
$res->setError(true)
|
|
||||||
->setErrorMessage('No customer information found');
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that the customer owns the job order
|
// check that the customer owns the job order
|
||||||
$jo_cust = $jo->getCustomer();
|
$jo_cust = $jo->getCustomer();
|
||||||
if ($jo_cust->getID() != $cust->getID())
|
if ($jo_cust->getID() != $cust->getID())
|
||||||
{
|
return new APIResponse(false, 'Job order was not initiated by customer');
|
||||||
$res->setError(true)
|
|
||||||
->setErrorMessage('Job order was not initiated by customer');
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
$invoice = $jo->getInvoice();
|
$invoice = $jo->getInvoice();
|
||||||
|
|
||||||
// make invoice json data
|
$data = $this->makeInvoiceData($invoice, $mah, $req);
|
||||||
$data = [
|
|
||||||
'total_price' => (float) $invoice->getTotalPrice(),
|
|
||||||
'vat_ex_price' => (float) $invoice->getVATExclusivePrice(),
|
|
||||||
'vat' => (float) $invoice->getVAT(),
|
|
||||||
'discount' => (float) $invoice->getDiscount(),
|
|
||||||
'trade_in' => (float) $invoice->getTradeIn(),
|
|
||||||
];
|
|
||||||
$items = $invoice->getItems();
|
|
||||||
$items_data = [];
|
|
||||||
foreach ($items as $item)
|
|
||||||
{
|
|
||||||
$my_data = [
|
|
||||||
'title' => $item->getTitle(),
|
|
||||||
'qty' => (int) $item->getQuantity() + 0,
|
|
||||||
'price' => (float) $item->getPrice() + 0.0,
|
|
||||||
];
|
|
||||||
|
|
||||||
$item_batt = $item->getBattery();
|
return new APIResponse(true, 'Job order invoice found', $data);
|
||||||
if ($item_batt != null)
|
|
||||||
{
|
|
||||||
$my_data['image_url'] = $this->getBatteryImageURL($req, $item_batt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$items_data[] = $my_data;
|
public function locationSupport(Request $req, GeofenceTracker $geo, EntityManagerInterface $em,
|
||||||
}
|
MobileAPIHandler $mah)
|
||||||
|
|
||||||
$data['items'] = $items_data;
|
|
||||||
|
|
||||||
// set data
|
|
||||||
$res->setData($data);
|
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function locationSupport(Request $req, GeofenceTracker $geo, EntityManagerInterface $em)
|
|
||||||
{
|
{
|
||||||
$required_params = [
|
$required_params = [
|
||||||
'longitude',
|
'longitude',
|
||||||
'latitude',
|
'latitude',
|
||||||
];
|
];
|
||||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
|
||||||
if ($res->isError())
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
|
|
||||||
$long = $req->query->get('longitude');
|
$msg = $this->checkRequiredParameters($req, $required_params);
|
||||||
$lat = $req->query->get('latitude');
|
if ($msg)
|
||||||
|
return new APIResponse(false, $msg);
|
||||||
|
|
||||||
|
// get capi user to link to mobile user
|
||||||
|
$user_id = $this->getUser()->getID();
|
||||||
|
|
||||||
|
// get mobile user
|
||||||
|
$mobile_user = $mah->findMobileUser($user_id);
|
||||||
|
|
||||||
|
if ($mobile_user == null)
|
||||||
|
return new APIResponse(false, 'No mobile user found.');
|
||||||
|
|
||||||
|
$long = $req->request->get('longitude');
|
||||||
|
$lat = $req->request->get('latitude');
|
||||||
|
|
||||||
// geofence
|
// geofence
|
||||||
$is_covered = $geo->isCovered($long, $lat);
|
$is_covered = $geo->isCovered($long, $lat);
|
||||||
|
|
@ -572,9 +546,8 @@ class JobOrderController extends APIController
|
||||||
'latitude' => $lat,
|
'latitude' => $lat,
|
||||||
'supported' => $is_covered,
|
'supported' => $is_covered,
|
||||||
];
|
];
|
||||||
$res->setData($data);
|
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
return new APIResponse(true, 'Location checked', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do we make this use the HubCriteria and HubSelector? YES?
|
// TODO: do we make this use the HubCriteria and HubSelector? YES?
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue