diff --git a/config/routes/tapi.yaml b/config/routes/tapi.yaml index 3d345d5f..fb343038 100644 --- a/config/routes/tapi.yaml +++ b/config/routes/tapi.yaml @@ -11,6 +11,11 @@ tapi_estimate: controller: App\Controller\TAPI\JobOrderController::getEstimate methods: [POST] +tapi_jo_invoice: + path: /tapi/job_order/invoice/{jo_id} + controller: App\Controller\TAPI\JobOrderController:getJOInvoice + methods: [GET] + # vehicle manufacturer and vehicle tapi_vehicle_mfg_list: path: /tapi/vehicle/mfgs diff --git a/src/Controller/TAPI/JobOrderController.php b/src/Controller/TAPI/JobOrderController.php index e627b15f..3d38efd5 100644 --- a/src/Controller/TAPI/JobOrderController.php +++ b/src/Controller/TAPI/JobOrderController.php @@ -469,44 +469,20 @@ class JobOrderController extends APIController return new APIResponse(true, $message, $data); } - public function getJOInvoice(Request $req, EntityManagerInterface $em) + public function getJOInvoice(Request $req, $jo_id, EntityManagerInterface $em) { $this->denyAccessUnlessGranted('tapi_jo.get.invoice', null, 'No access.'); - $required_params = [ - 'jo_id', - ]; - $res = $this->checkParamsAndKey($req, $em, $required_params); - if ($res->isError()) - return $res->getReturnResponse(); + $required_params = []; + $msg = $this->checkRequiredParameters($req, $required_params); + if ($msg) + return new APIResponse(false, $msg); - // 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 - // TODO: modify to 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(); + $message = 'No job order found'; + return new APIResponse(false, $message); } $invoice = $jo->getInvoice(); @@ -540,10 +516,8 @@ class JobOrderController extends APIController $data['items'] = $items_data; - // set data - $res->setData($data); - - return $res->getReturnResponse(); + $message = 'JO invoice found.'; + return new APIResponse(true, $message, $data); } public function cancelJobOrder(Request $req, MQTTClient $mclient, EntityManagerInterface $em)