Add jo invoice user api call #162
This commit is contained in:
parent
5b323e155b
commit
bbc6989a66
2 changed files with 80 additions and 0 deletions
|
|
@ -100,6 +100,11 @@ api_jo_history:
|
|||
controller: App\Controller\APIController:getJOHistory
|
||||
methods: [GET]
|
||||
|
||||
api_jo_invoice:
|
||||
path: /api/job_order/invoice
|
||||
controller: App\Controller\APIController:getJOInvoice
|
||||
methods: [GET]
|
||||
|
||||
api_device_id:
|
||||
path: /api/device_id
|
||||
controller: App\Controller\APIController:updateDeviceID
|
||||
|
|
|
|||
|
|
@ -1278,6 +1278,81 @@ class APIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getJOInvoice(Request $req)
|
||||
{
|
||||
$required_params = [
|
||||
'jo_id',
|
||||
];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$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();
|
||||
}
|
||||
|
||||
// get customer
|
||||
$cust = $this->session->getCustomer();
|
||||
if ($cust == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('No customer information found');
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
$inv = $jo->getInvoice();
|
||||
|
||||
// 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,
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'invoice' => [
|
||||
'discount' => $inv->getDiscount(),
|
||||
'trade_in' => $inv->getTradeIn(),
|
||||
'total_price' => $inv->getTotalPrice(),
|
||||
'vat' => $inv->getVat(),
|
||||
'items' => $inv_items,
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$res->setData($data);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function cancelJobOrder(Request $req, MQTTClient $mclient)
|
||||
{
|
||||
$required_params = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue