Refactor scheduling for advance order #403
This commit is contained in:
parent
dd7771b5ce
commit
60846e17d6
1 changed files with 75 additions and 1 deletions
|
|
@ -3022,6 +3022,19 @@ class APIController extends Controller implements LoggedController
|
||||||
->getResult();
|
->getResult();
|
||||||
// check request_time
|
// check request_time
|
||||||
|
|
||||||
|
// define slots
|
||||||
|
$slots = [
|
||||||
|
'08_09' => '8:00 AM',
|
||||||
|
'09_10' => '9:00 AM',
|
||||||
|
'10_11' => '10:00 AM',
|
||||||
|
'11_12' => '11:00 AM',
|
||||||
|
'12_13' => '12:00 PM',
|
||||||
|
'13_14' => '1:00 PM',
|
||||||
|
'14_15' => '2:00 PM',
|
||||||
|
'15_16' => '3:00 PM',
|
||||||
|
'16_17' => '4:00 PM',
|
||||||
|
];
|
||||||
|
|
||||||
// check each JO's date_schedule, decrement rider_slots if date schedule falls in that slot
|
// check each JO's date_schedule, decrement rider_slots if date schedule falls in that slot
|
||||||
// index - equivalent time
|
// index - equivalent time
|
||||||
// 0 - 8-9
|
// 0 - 8-9
|
||||||
|
|
@ -3033,7 +3046,6 @@ class APIController extends Controller implements LoggedController
|
||||||
// 6 - 14-15
|
// 6 - 14-15
|
||||||
// 7 - 15-16
|
// 7 - 15-16
|
||||||
// 8 - 16-17
|
// 8 - 16-17
|
||||||
$hub_slots = [];
|
|
||||||
|
|
||||||
// get the dates for the next three days
|
// get the dates for the next three days
|
||||||
$first_date = $start_date->format('Y-m-d');
|
$first_date = $start_date->format('Y-m-d');
|
||||||
|
|
@ -3045,9 +3057,41 @@ class APIController extends Controller implements LoggedController
|
||||||
// third day
|
// third day
|
||||||
$third_date = $end_date->format('Y-m-d');
|
$third_date = $end_date->format('Y-m-d');
|
||||||
|
|
||||||
|
// define days
|
||||||
|
$days = [
|
||||||
|
$first_date => $first_date,
|
||||||
|
$sec_date => $sec_date,
|
||||||
|
$third_date => $third_date,
|
||||||
|
];
|
||||||
|
|
||||||
|
// initialize hub slots
|
||||||
|
$hub_rider_slots = [];
|
||||||
|
foreach ($days as $day)
|
||||||
|
{
|
||||||
|
foreach ($slots as $slot_key => $slot)
|
||||||
|
{
|
||||||
|
$hub_rider_slots[$day][$slot_key] = $hub->getRiderSlots();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// array of # of riders that can handle JOs in a timeslot
|
// array of # of riders that can handle JOs in a timeslot
|
||||||
$hub_rider_slots = [];
|
$hub_rider_slots = [];
|
||||||
|
|
||||||
|
foreach ($jos_advance_order as $jo)
|
||||||
|
{
|
||||||
|
// get date key
|
||||||
|
$date_sched = $jo->getDateSchedule();
|
||||||
|
$date_string = $date_sched->format('Y-m-d');
|
||||||
|
$hour = $date_sched->format('H');
|
||||||
|
$slot_id = sprintf('%02d_%02d', $hour, $hour + 1);
|
||||||
|
|
||||||
|
// decrement rider slot
|
||||||
|
$hub_rider_slots[$date_string][$slot_id]--;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hub_slots = $this->generateHubSlots($hub_rider_slots, $slots);
|
||||||
|
|
||||||
|
/*
|
||||||
// populate the array with the hub's rider slots per day
|
// populate the array with the hub's rider slots per day
|
||||||
for ($i = 0; $i <= self::RIDER_SLOT_ARRAY_LENGTH; $i++)
|
for ($i = 0; $i <= self::RIDER_SLOT_ARRAY_LENGTH; $i++)
|
||||||
{
|
{
|
||||||
|
|
@ -3061,7 +3105,9 @@ class APIController extends Controller implements LoggedController
|
||||||
{
|
{
|
||||||
$hub_rider_slots[$third_date][$i] = $hub->getRiderSlots();
|
$hub_rider_slots[$third_date][$i] = $hub->getRiderSlots();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
// no advance orders
|
// no advance orders
|
||||||
if (empty($jos_advance_orders))
|
if (empty($jos_advance_orders))
|
||||||
{
|
{
|
||||||
|
|
@ -3115,10 +3161,38 @@ class APIController extends Controller implements LoggedController
|
||||||
$hub_slots[$third_date] = $this->setHubSlots($hub_rider_slots, $third_date);
|
$hub_slots[$third_date] = $this->setHubSlots($hub_rider_slots, $third_date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return $hub_slots;
|
return $hub_slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function generateHubSlots($rider_slots, $slots)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
foreach ($rider_slots as $day_id => $rslot)
|
||||||
|
{
|
||||||
|
$data[$day_id] = [];
|
||||||
|
|
||||||
|
foreach ($rslot as $slot_id => $avail_slots)
|
||||||
|
{
|
||||||
|
$slot_data = [
|
||||||
|
'id' => $slot_id,
|
||||||
|
'label' => $slots[$slot_id],
|
||||||
|
'available' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
// mark unavailable ones
|
||||||
|
if ($avail_slots <= 0)
|
||||||
|
$slot_data['available'] = false;
|
||||||
|
|
||||||
|
// add to day data
|
||||||
|
$data[$day_id][] = $slot_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
protected function setAllHubSlots($status)
|
protected function setAllHubSlots($status)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue