Add route for getNearestHubAndSlots. Modify getNearestHubAndSlots. #686
This commit is contained in:
parent
2112edd4f0
commit
fd77f1ef62
2 changed files with 77 additions and 52 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
$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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue