diff --git a/config/api_acl.yaml b/config/api_acl.yaml index b235ff81..c1c1067f 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -101,8 +101,6 @@ access_keys: label: Third Party Get Ongoing Job Order - id: tapi_jo.cancel label: Third Party Cancel Job Order - - id: tapi_jo.get.history - label: Third Party Get Job Order History - id: tapi_jo.get.invoice label: Third Party Get Job Order Invoice - id: tapi_jo.location.support diff --git a/config/routes/tapi.yaml b/config/routes/tapi.yaml index 59ec7a80..0c3e20c9 100644 --- a/config/routes/tapi.yaml +++ b/config/routes/tapi.yaml @@ -22,10 +22,15 @@ tapi_jo_cancel: methods: [POST] tapi_jo_info: - path: /tapi/job_order/{id}/info + path: /tapi/job_order/{jo_id}/info controller: App\Controller\TAPI\JobOrderController::getJobOrderInfo methods: [GET] +tapi_location_support: + path: /tapi/location_support + controller: App\Controller\TAPI\JobOrderController:locationSupport + methods: [POST] + # 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 b5c9418c..72ecdac1 100644 --- a/src/Controller/TAPI/JobOrderController.php +++ b/src/Controller/TAPI/JobOrderController.php @@ -601,130 +601,6 @@ class JobOrderController extends APIController return new APIResponse(true, $message, $data); } - public function getJOHistory(Request $req, EntityManagerInterface $em) - { - $this->denyAccessUnlessGranted('tapi_jo.get.history', null, 'No access.'); - - $res = $this->checkParamsAndKey($req, $em, []); - if ($res->isError()) - return $res->getReturnResponse(); - - // get customer - // TODO: modify to find customer - $cust = $this->session->getCustomer(); - if ($cust == null) - { - $res->setError(true) - ->setErrorMessage('No customer information found'); - return $res->getReturnResponse(); - } - - // get job orders - $all_jo_data = []; - // get the fulfilled and cancelled job orders, since ongoing jos are not yet part of history - $jos = $em->getRepository(JobOrder::class)->findBy([ - 'customer' => $cust, - 'status' => [JOStatus::CANCELLED, JOStatus::FULFILLED] - ], ['date_schedule' => 'DESC']); - foreach ($jos as $jo) - { - // NOTE: use generateJobOrderData method, maybe? - $status = $jo->getStatus(); - - $jo_data = [ - 'id' => $jo->getID(), - 'date_create' => $jo->getDateCreate()->format('M d, Y'), - 'service_type' => $jo->getServiceType(), - 'status' => $status, - ]; - - // customer vehicle and warranty - $cv = $jo->getCustomerVehicle(); - - // get latest warranty using plate number - $warranty = $this->findWarranty($cv->getPlateNumber(), $em); - - $jo_data['customer_vehicle'] = [ - 'id' => $cv->getID(), - 'plate_number' => $cv->getPlateNumber(), - 'warranty' => $warranty, - ]; - - // rider - $rider = $jo->getRider(); - - // check if jo has rider rating set to true - $has_rider_rating = $jo->hasRiderRating(); - $rating = 0; - $comment = ''; - if ($rider != null) - { - $jo_data['rider'] = $rider->getFullName(); - - // find the rider rating if any - if ($has_rider_rating) - { - $jo_rating = $jo->getRating(); - if ($jo_rating != null) - { - $rating = $jo_rating->getRating(); - - // get comment - $comment = $jo_rating->getComment(); - } - } - } - - // rider rating for jo - $jo_data['has_rider_rating'] = $has_rider_rating; - $jo_data['rider_rating'] = $rating; - $jo_data['comment'] = $comment; - - // invoice items - $items = []; - $jo_items = $jo->getInvoice()->getItems(); - foreach ($jo_items as $item) - { - $items[] = [ - 'id' => $item->getID(), - 'title' => $item->getTitle(), - 'qty' => $item->getQuantity(), - 'price' => $item->getPrice(), - ]; - } - - $jo_data['items'] = $items; - - // dates depending on status - switch ($status) - { - case JOStatus::FULFILLED: - if ($jo->getDateFulfill() == null) - $jo_data['date_fulfilled'] = ''; - else - $jo_data['date_fulfilled'] = $jo->getDateFulfill()->format('M d, Y'); - break; - case JOStatus::CANCELLED: - $date_cancel = $jo->getDateCancel(); - if ($date_cancel == null) - $date_cancel = new DateTime(); - $jo_data['date_cancelled'] = $date_cancel->format('M d, Y'); - break; - } - - $all_jo_data[] = $jo_data; - } - - // return data - $data = [ - 'job_orders' => $all_jo_data - ]; - $res->setData($data); - - // response - return $res->getReturnResponse(); - } - public function locationSupport(Request $req, GeofenceTracker $geo, EntityManagerInterface $em) { $this->denyAccessUnlessGranted('tapi_jo.location.support', null, 'No access.'); @@ -733,52 +609,31 @@ class JobOrderController extends APIController 'longitude', 'latitude', ]; - $res = $this->checkParamsAndKey($req, $em, $required_params); - if ($res->isError()) - return $res->getReturnResponse(); + $msg = $this->checkRequiredParameters($req, $required_params); + if ($msg) + return new APIResponse(false, $msg); - $long = $req->query->get('longitude'); - $lat = $req->query->get('latitude'); - - // NOTE: had to add this for promo tag - // TODO: modify to find customer if we still need this - $cust = $this->session->getCustomer(); - if ($cust == null) - { - $res->setError(true) - ->setErrorMessage('No customer information found'); - return $res->getReturnResponse(); - } + $long = $req->request->get('longitude'); + $lat = $req->request->get('latitude'); $is_covered = false; - // check if customer still has promo - if (($cust->getCustomerTag('TAG_CAR_CLUB_OFFICER_PROMO')) || - ($cust->getCustomerTag('TAG_CAR_CLUB_MEMBER_PROMO'))) - { - // if has customer tag, customer has not availed of promo - $is_covered = true; - } - else - { - // geofence - $is_covered = $geo->isCovered($long, $lat); - } + // geofence + $is_covered = $geo->isCovered($long, $lat); $data = [ 'longitude' => $long, 'latitude' => $lat, 'supported' => $is_covered, ]; - $res->setData($data); - // check if is_covered is false. If so, we need to set the error part in the response + // check if is_covered is false. If so, we need to modify the message + $message = 'Location is supported.'; if (!$is_covered) { - $res->setError(true) - ->setErrorMessage('Oops! Our service is limited to some areas in Metro Manila, Laguna, and Baguio only. We will update you as soon as we are able to cover your area'); + $message = 'Oops! Our service is limited to some areas in Metro Manila, Laguna, and Baguio only. We will update you as soon as we are able to cover your area'; } - return $res->getReturnResponse(); + return new APIResponse(true, $message, $data); } // TODO: should we change to the HubSelector?