Modify location support. #591

This commit is contained in:
Korina Cordero 2021-07-12 09:44:46 +00:00
parent baaa832794
commit bfbd4d4045
3 changed files with 48 additions and 67 deletions

View file

@ -154,3 +154,11 @@ access_keys:
label: Cancel Job Order
- id: mobile_jo.get.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

View file

@ -157,7 +157,7 @@ resqapi_jo_invoice:
resqapi_location_support:
path: /resqapi/location_support
controller: App\Controller\ResqAPI\JobOrderController:locationSupport
methods: [GET]
methods: [POST]
resqapi_nearest_hub_slots:
path: /resqapi/hub_slots

View file

@ -476,93 +476,67 @@ class JobOrderController extends APIController
return new APIResponse(true, 'Job order history found', $data);
}
// TODO: modify for MobileUser
public function getJOInvoice(Request $req, EntityManagerInterface $em)
public function getJOInvoice(Request $req, EntityManagerInterface $em, MobileAPIHandler $mah)
{
$this->denyAccessUnlessGranted('mobile_jo.get.invoice', null, 'No access.');
$required_params = [
'jo_id',
];
$res = $this->checkParamsAndKey($req, $em, $required_params);
if ($res->isError())
return $res->getReturnResponse();
// get job order
$jo_id = $req->query->get('jo_id');
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
if ($jo == null)
{
$res->setError(true)
->setErrorMessage('No job order found');
return $res->getReturnResponse();
}
$msg = $this->checkRequiredParameters($req, $required_params);
if ($msg)
return new APIResponse(false, $msg);
// get customer
$cust = $this->session->getCustomer();
// 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.');
// customer
$cust = $mobile_user->getCustomer();
if ($cust == null)
{
$res->setError(true)
->setErrorMessage('No customer information found');
return $res->getReturnResponse();
}
return new APIResponse(false, 'No customer information found');
// check that the customer owns the job order
$jo_cust = $jo->getCustomer();
if ($jo_cust->getID() != $cust->getID())
{
$res->setError(true)
->setErrorMessage('Job order was not initiated by customer');
return $res->getReturnResponse();
}
return new APIResponse(false, 'Job order was not initiated by customer');
$invoice = $jo->getInvoice();
// make invoice json data
$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,
];
$data = $this->makeInvoiceData($invoice, $mah, $req);
$item_batt = $item->getBattery();
if ($item_batt != null)
{
$my_data['image_url'] = $this->getBatteryImageURL($req, $item_batt);
}
$items_data[] = $my_data;
}
$data['items'] = $items_data;
// set data
$res->setData($data);
return $res->getReturnResponse();
return new APIResponse(true, 'Job order invoice found', $data);
}
public function locationSupport(Request $req, GeofenceTracker $geo, EntityManagerInterface $em)
public function locationSupport(Request $req, GeofenceTracker $geo, EntityManagerInterface $em,
MobileAPIHandler $mah)
{
$required_params = [
'longitude',
'latitude',
];
$res = $this->checkParamsAndKey($req, $em, $required_params);
if ($res->isError())
return $res->getReturnResponse();
$long = $req->query->get('longitude');
$lat = $req->query->get('latitude');
$msg = $this->checkRequiredParameters($req, $required_params);
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
$is_covered = $geo->isCovered($long, $lat);
@ -572,9 +546,8 @@ class JobOrderController extends APIController
'latitude' => $lat,
'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?