All i want, to calculate time-slots-list according to my business-hours and block or disable those time-slots which booked by appointments.
I have done these things with my problem, stuck on last task, mention below.
My Service Duration = 60min.
My Today Busines Hours:
start time - 10:00 AM
end time - 3:00 PM
I have generated 15min time slot-list according to my today business hours:
$start = strtotime('10:00 AM');
$end = strtotime('3:00 PM');
for( $i = $start; $i <= $end; $i += (60*15))
{
$slotlist[] = date('g:iA', $i);
}
//output
10:00AM
10:15AM
10:30AM
10:45AM
11:00AM
11:15AM
11:30AM
11:45AM
12:00PM
12:15PM
12:30PM
12:45PM
1:00PM
1:15PM
1:30PM
1:45PM
2:00PM
2:15PM
2:30PM
2:45PM
3:00PM
now i have booked 3 appointments
Appointments | start-time to end-times
Appointment-1 : 10:00AM to 11:00AM (according to my service duration 60min)
Appointment-2 : 11:15AM to 12:15PM
Appointment-3 : 1:00PM to 2:00PM
//array of all appointment start_time
$appointment_start_time = array('10:00AM','11:15AM','1:00PM');
Now disable those time-slots which are already booked in appointments
foreach($slotlist as $single)
{
if(in_array($single, $appointment_start_time))
{
echo "<input name=start_time type='radio' disabled value='$single' />".$single; echo "<br>";
$time = $single;
$event_length = 60-15; // 60 is time duration
$timestamp = strtotime("$time");
$endtime = strtotime("+$event_length minutes", $timestamp);
$next_time = date('g:i A', $endtime);
//calculate between slots (start-end time)
$start = strtotime($single);
$end = strtotime($next_time);
for( $i = $start; $i <= $end; $i += (60*15))
{
$list2[] = date('g:iA', $i);
}
}
else
{
if(in_array($single, $list2))
{
echo "<input name=start_time type='radio' disabled value='$single' />".$single; echo "<br>";
}
else
{
echo "<input name=start_time type='radio' value='$single' />".$single; echo "<br>";
}
}
}
//output
10:00AM -disabled
10:15AM -disabled
10:30AM -disabled
10:45AM -disabled
11:00AM
11:15AM -disabled
11:30AM -disabled
11:45AM -disabled
12:00PM -disabled
12:15PM
12:30PM
12:45PM
1:00PM -disabled
1:15PM -disabled
1:30PM -disabled
1:45PM -disabled
2:00PM
2:15PM
2:30PM
2:45PM
3:00PM
Now last task to do, how to remove those time slot which are not qualify service duration time like as:
11:00AM (single slot b/w 2 appointment, cover only 15min)
12:15PM -
12:30PM -(3 slot b/w 2 appointment, cover only 45min)
12:45PM -