From fd77f1ef627a0acb8980a6e73463583ab083c882 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 21 Jun 2022 10:08:58 +0000 Subject: [PATCH] Add route for getNearestHubAndSlots. Modify getNearestHubAndSlots. #686 --- config/routes/tapi.yaml | 5 + src/Controller/TAPI/JobOrderController.php | 124 ++++++++++++--------- 2 files changed, 77 insertions(+), 52 deletions(-) diff --git a/config/routes/tapi.yaml b/config/routes/tapi.yaml index 0c3e20c9..afa2f084 100644 --- a/config/routes/tapi.yaml +++ b/config/routes/tapi.yaml @@ -31,6 +31,11 @@ tapi_location_support: controller: App\Controller\TAPI\JobOrderController:locationSupport methods: [POST] +tapi_nearest_hub_slots: + path: /tapi/hub_slots + controller: App\Controller\TAPI\JobOrderController::getNearestHubAndSlots + 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 72ecdac1..4b1e6684 100644 --- a/src/Controller/TAPI/JobOrderController.php +++ b/src/Controller/TAPI/JobOrderController.php @@ -647,57 +647,18 @@ class JobOrderController extends APIController '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); - $coordinates = new Point($req->query->get('longitude'), $req->query->get('latitude')); + $coordinates = new Point($req->request->get('longitude'), $req->request->get('latitude')); - // add checking if customer has a pre-registered hub - // TODO: modify how we get customer - $cust = $this->session->getCustomer(); - if ($cust == null) + $nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools); + + if (empty($nearest_hub_slots['hub'])) { - $res->setError(true) - ->setErrorMessage('No customer information found'); - return $res->getReturnResponse(); - } - - // check if customer has customer tag promo - // TODO: do we still need this? - 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, get the hub where customer is pre-registered - $car_club_cust_hub = $cust->getCarClubCustomerHub(); - if ($car_club_cust_hub != null) - { - // need to get the rider slots for the pre-registered hub - $hub = $car_club_cust_hub->getHub(); - $nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools, $hub); - } - else - { - $nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools); - - if (empty($nearest_hub_slots['hub'])) - { - $res->setError(true) - ->setErrorMessage('Thank you for reaching out to us. Please expect a call from us and we will assist you with your request. Thank you and stay safe!'); - return $res->getReturnResponse(); - } - } - } - else - { - $nearest_hub_slots = $this->findAdvanceNearestHubAndSlots($coordinates, $em, $map_tools); - - if (empty($nearest_hub_slots['hub'])) - { - $res->setError(true) - ->setErrorMessage('Thank you for reaching out to us. Please expect a call from us and we will assist you with your request. Thank you and stay safe!'); - return $res->getReturnResponse(); - } + $message = 'Thank you for reaching out to us. Please expect a call from us and we will assist you with your request. Thank you and stay safe!'; + return new APIResponse (false, $message); } // make hub data @@ -706,9 +667,9 @@ class JobOrderController extends APIController 'hub_slots' => $nearest_hub_slots['slots'], ]; - $res->setData($data); + $message = 'Nearest hub and slots found.'; - return $res->getReturnResponse(); + return new APIResponse(true, $message, $data); } public function scheduleOptionStatus(Request $req, EntityManagerInterface $em) @@ -1146,6 +1107,56 @@ class JobOrderController extends APIController return $hub_slots; } + protected function generateHubSlots($rider_slots, $slots) + { + $data = []; + $total_rslots = 0; + $total_unavailable_rslots = 0; + foreach ($rider_slots as $day_id => $rslot) + { + $data[$day_id] = []; + + foreach ($rslot as $slot_id => $avail_slots) + { + // increment total rider slots + $total_rslots++; + + $slot_data = [ + 'id' => $slot_id, + 'label' => $slots[$slot_id], + 'available' => true, + ]; + + // mark unavailable ones + if ($avail_slots <= 0) + { // increment total number of unavailable slots + $total_unavailable_rslots++; + $slot_data['available'] = false; + } + + // add to day data + $data[$day_id][] = $slot_data; + } + } + + // check if hub has available slots + $hub_available = true; + // error_log('total rider slots ' . $total_rslots); + // error_log('total unavailable slots ' . $total_unavailable_rslots); + if ($total_rslots == $total_unavailable_rslots) + { + // error_log('hub has no available slots'); + $hub_available = false; + } + + $hs_data = [ + 'flag_hub_available' => $hub_available, + 'slot_data' => $data, + ]; + + return $hs_data; + } + protected function getTimeFromSlot($slot_id) { $time_selected = ''; @@ -1264,11 +1275,20 @@ class JobOrderController extends APIController $hub = $em->getRepository(Hub::class)->find($hub_id); $schedule_date = $r->get('date_schedule'); + $slot_id = $r->get('slot_id'); // process the jo date schedule $date_schedule = null; - if (strlen($schedule_date) > 0) - $date_schedule = DateTime::createFromFormat('Y-m-d H:i', $schedule_date); + if ((strlen($schedule_date) > 0) && (strlen($slot_id) > 0)) + { + $time_schedule = $this->getTimeFromSlot($slot_id); + if (!empty($time_schedule)) + { + $s_date = $schedule_date . ' ' . $time_schedule; + $date_schedule = DateTime::createFromFormat('Y-m-d H:i', $s_date); + // error_log($date_schedule->format('Y-m-d H:i')); + } + } // get promo $promo_id = $r->get('promo_id', 0);