Full day appointment with multiple attendants are now being taken into
concern while generating availabilities. (fixes #337 and #315).
This commit is contained in:
parent
3a9ae7f4a3
commit
85dec33466
3 changed files with 203 additions and 196 deletions
|
@ -271,7 +271,7 @@ class Appointments extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function book_success($appointment_id)
|
public function book_success($appointment_id)
|
||||||
{
|
{
|
||||||
//if the appointment id doesn't exist or zero redirect to index
|
// If the appointment id doesn't exist or zero redirect to index.
|
||||||
if ( ! $appointment_id)
|
if ( ! $appointment_id)
|
||||||
{
|
{
|
||||||
redirect('appointments');
|
redirect('appointments');
|
||||||
|
@ -357,31 +357,49 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$availabilities_type = $this->services_model->get_value('availabilities_type',
|
$service = $this->services_model->get_row($this->input->post('service_id'));
|
||||||
$this->input->post('service_id'));
|
$provider = $this->providers_model->get_row($_POST['provider_id']);
|
||||||
$attendants_number = $this->services_model->get_value('attendants_number',
|
|
||||||
$this->input->post('service_id'));
|
|
||||||
|
|
||||||
$empty_periods = $this->_get_provider_available_time_periods($this->input->post('provider_id'),
|
$empty_periods = $this->_get_provider_available_time_periods($this->input->post('provider_id'),
|
||||||
|
$this->input->post('service_id'),
|
||||||
$this->input->post('selected_date'), $exclude_appointments);
|
$this->input->post('selected_date'), $exclude_appointments);
|
||||||
|
|
||||||
$available_hours = $this->_calculate_available_hours($empty_periods, $this->input->post('selected_date'),
|
$available_hours = $this->_calculate_available_hours($empty_periods, $this->input->post('selected_date'),
|
||||||
$this->input->post('service_duration'),
|
$this->input->post('service_duration'),
|
||||||
filter_var($this->input->post('manage_mode'), FILTER_VALIDATE_BOOLEAN),
|
filter_var($this->input->post('manage_mode'), FILTER_VALIDATE_BOOLEAN),
|
||||||
$availabilities_type);
|
$service['availabilities_type']);
|
||||||
|
|
||||||
if ($attendants_number > 1)
|
if ($service['attendants_number'] > 1)
|
||||||
{
|
{
|
||||||
$this->_get_multiple_attendants_hours($this->input->post('select_date'), $availabilities_type,
|
$available_hours = $this->_get_multiple_attendants_hours($this->input->post('selected_date'), $service,
|
||||||
$attendants_number,
|
$provider);
|
||||||
$this->input->post('service_id'),
|
|
||||||
$this->input->post('provider_id'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the selected date is today, remove past hours. It is important include the timeout before
|
||||||
|
// booking that is set in the back-office the system. Normally we might want the customer to book
|
||||||
|
// an appointment that is at least half or one hour from now. The setting is stored in minutes.
|
||||||
|
if (date('Y-m-d', strtotime($this->input->post('selected_date'))) === date('Y-m-d'))
|
||||||
|
{
|
||||||
|
$book_advance_timeout = $this->settings_model->get_setting('book_advance_timeout');
|
||||||
|
|
||||||
|
foreach ($available_hours as $index => $value)
|
||||||
|
{
|
||||||
|
$available_hour = strtotime($value);
|
||||||
|
$current_hour = strtotime('+' . $book_advance_timeout . ' minutes', strtotime('now'));
|
||||||
|
if ($available_hour <= $current_hour)
|
||||||
|
{
|
||||||
|
unset($available_hours[$index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$available_hours = array_values($available_hours);
|
||||||
|
sort($available_hours, SORT_STRING);
|
||||||
|
$available_hours = array_values($available_hours);
|
||||||
|
|
||||||
$this->output
|
$this->output
|
||||||
->set_content_type('application/json')
|
->set_content_type('application/json')
|
||||||
->set_output(json_encode($available_hours));
|
->set_output(json_encode($available_hours));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception $exc)
|
catch (Exception $exc)
|
||||||
{
|
{
|
||||||
|
@ -580,56 +598,63 @@ class Appointments extends CI_Controller {
|
||||||
{
|
{
|
||||||
$provider_id = $this->input->get('provider_id');
|
$provider_id = $this->input->get('provider_id');
|
||||||
$service_id = $this->input->get('service_id');
|
$service_id = $this->input->get('service_id');
|
||||||
$selected_date = new DateTime($this->input->get('selected_date'));
|
$selected_date_string = $this->input->get('selected_date');
|
||||||
$number_of_days = (int)$selected_date->format('t');
|
$selected_date = new DateTime($selected_date_string);
|
||||||
|
$number_of_days_in_month = (int)$selected_date->format('t');
|
||||||
$unavailable_dates = [];
|
$unavailable_dates = [];
|
||||||
|
|
||||||
// Handle the "Any Provider" case.
|
// Handle the "Any Provider" case.
|
||||||
if ($provider_id === ANY_PROVIDER)
|
if ($provider_id === ANY_PROVIDER)
|
||||||
{
|
{
|
||||||
$provider_id = $this->_search_any_provider($service_id, $this->input->get('selected_date'));
|
$provider_id = $this->_search_any_provider($service_id, $selected_date_string);
|
||||||
|
|
||||||
if ($provider_id === NULL)
|
if ($provider_id === NULL)
|
||||||
{ // No provider is available in the selected date.
|
{
|
||||||
for ($i = 1; $i <= $number_of_days; $i++)
|
// No provider is available in the selected date.
|
||||||
|
for ($i = 1; $i <= $number_of_days_in_month; $i++)
|
||||||
{
|
{
|
||||||
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
||||||
$unavailable_dates[] = $current_date->format('Y-m-d');
|
$unavailable_dates[] = $current_date->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->output
|
$this->output
|
||||||
->set_content_type('application/json')
|
->set_content_type('application/json')
|
||||||
->set_output(json_encode($unavailable_dates));
|
->set_output(json_encode($unavailable_dates));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the available time periods for every day of this month.
|
// Get the provider record.
|
||||||
$this->load->model('services_model');
|
$this->load->model('providers_model');
|
||||||
$service_duration = (int)$this->services_model->get_value('duration', $service_id);
|
$provider = $this->providers_model->get_row($provider_id);
|
||||||
$availabilities_type = (int)$this->services_model->get_value('availabilities_type', $service_id);
|
|
||||||
$attendants_number = (int)$this->services_model->get_value('attendants_number', $service_id);
|
|
||||||
|
|
||||||
for ($i = 1; $i <= $number_of_days; $i++)
|
// Get the service record.
|
||||||
|
$this->load->model('services_model');
|
||||||
|
$service = $this->services_model->get_row($service_id);
|
||||||
|
|
||||||
|
for ($i = 1; $i <= $number_of_days_in_month; $i++)
|
||||||
{
|
{
|
||||||
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
|
||||||
|
|
||||||
if ($current_date < new DateTime(date('Y-m-d 00:00:00')))
|
if ($current_date < new DateTime(date('Y-m-d 00:00:00')))
|
||||||
{ // Past dates become immediately unavailable.
|
{
|
||||||
|
// Past dates become immediately unavailable.
|
||||||
$unavailable_dates[] = $current_date->format('Y-m-d');
|
$unavailable_dates[] = $current_date->format('Y-m-d');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$empty_periods = $this->_get_provider_available_time_periods($provider_id,
|
$empty_periods = $this->_get_provider_available_time_periods($provider_id,
|
||||||
|
$service_id,
|
||||||
$current_date->format('Y-m-d'));
|
$current_date->format('Y-m-d'));
|
||||||
|
|
||||||
$available_hours = $this->_calculate_available_hours($empty_periods, $current_date->format('Y-m-d'),
|
$available_hours = $this->_calculate_available_hours($empty_periods, $current_date->format('Y-m-d'),
|
||||||
$service_duration, FALSE, $availabilities_type);
|
$service['duration'], FALSE, $service['availabilities_type']);
|
||||||
|
|
||||||
if ($attendants_number > 1)
|
if ($service['attendants_number'] > 1)
|
||||||
{
|
{
|
||||||
$this->_get_multiple_attendants_hours($current_date->format('Y-m-d'), $availabilities_type,
|
$available_hours = $this->_get_multiple_attendants_hours($current_date->format('Y-m-d'), $service,
|
||||||
$attendants_number,
|
$provider);
|
||||||
$service_id,
|
|
||||||
$provider_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($available_hours))
|
if (empty($available_hours))
|
||||||
|
@ -702,7 +727,8 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$available_periods = $this->_get_provider_available_time_periods(
|
$available_periods = $this->_get_provider_available_time_periods(
|
||||||
$appointment['id_users_provider'], date('Y-m-d', strtotime($appointment['start_datetime'])),
|
$appointment['id_users_provider'], $appointment['id_services'],
|
||||||
|
date('Y-m-d', strtotime($appointment['start_datetime'])),
|
||||||
$exclude_appointments);
|
$exclude_appointments);
|
||||||
|
|
||||||
$is_still_available = FALSE;
|
$is_still_available = FALSE;
|
||||||
|
@ -737,71 +763,76 @@ class Appointments extends CI_Controller {
|
||||||
* values that have the start and the end time of an available time period.
|
* values that have the start and the end time of an available time period.
|
||||||
*
|
*
|
||||||
* @param int $provider_id Provider record ID.
|
* @param int $provider_id Provider record ID.
|
||||||
|
* @param int $service_id Service record ID.
|
||||||
* @param string $selected_date Date to be checked (MySQL formatted string).
|
* @param string $selected_date Date to be checked (MySQL formatted string).
|
||||||
* @param array $exclude_appointments Array containing the IDs of the appointments that will not be taken into
|
* @param array $excluded_appointment_ids Array containing the IDs of the appointments that will not be taken into
|
||||||
* consideration when the available time periods are calculated.
|
* consideration when the available time periods are calculated.
|
||||||
*
|
*
|
||||||
* @return array Returns an array with the available time periods of the provider.
|
* @return array Returns an array with the available time periods of the provider.
|
||||||
*/
|
*/
|
||||||
protected function _get_provider_available_time_periods(
|
protected function _get_provider_available_time_periods(
|
||||||
$provider_id,
|
$provider_id,
|
||||||
|
$service_id,
|
||||||
$selected_date,
|
$selected_date,
|
||||||
$exclude_appointments = []
|
$excluded_appointment_ids = []
|
||||||
) {
|
) {
|
||||||
$this->load->model('appointments_model');
|
$this->load->model('appointments_model');
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
$this->load->model('services_model');
|
||||||
|
|
||||||
// Get the provider's working plan and reserved appointments.
|
// Get the service, provider's working plan and provider appointments.
|
||||||
$working_plan = json_decode($this->providers_model->get_setting('working_plan', $provider_id), TRUE);
|
$working_plan = json_decode($this->providers_model->get_setting('working_plan', $provider_id), TRUE);
|
||||||
|
|
||||||
$where_clause = [
|
$provider_appointments = $this->appointments_model->get_batch([
|
||||||
'id_users_provider' => $provider_id
|
'id_users_provider' => $provider_id,
|
||||||
];
|
'DATE(start_datetime)' => $selected_date
|
||||||
|
]);
|
||||||
|
|
||||||
$reserved_appointments = $this->appointments_model->get_batch($where_clause);
|
$service = $this->services_model->get_row($service_id);
|
||||||
|
|
||||||
// Sometimes it might be necessary to not take into account some appointment records
|
// Sometimes it might be necessary to not take into account some appointment records in order to display what
|
||||||
// in order to display what the providers' available time periods would be without them.
|
// the providers' available time periods would be without them.
|
||||||
foreach ($exclude_appointments as $excluded_id)
|
foreach ($excluded_appointment_ids as $excluded_appointment_id)
|
||||||
{
|
{
|
||||||
foreach ($reserved_appointments as $index => $reserved)
|
foreach ($provider_appointments as $index => $reserved)
|
||||||
{
|
{
|
||||||
if ($reserved['id'] == $excluded_id)
|
if ($reserved['id'] == $excluded_appointment_id)
|
||||||
{
|
{
|
||||||
unset($reserved_appointments[$index]);
|
unset($provider_appointments[$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the empty spaces on the plan. The first split between the plan is due to
|
// Find the empty spaces on the plan. The first split between the plan is due to a break (if any). After that
|
||||||
// a break (if exist). After that every reserved appointment is considered to be
|
// every reserved appointment is considered to be a taken space in the plan.
|
||||||
// a taken space in the plan.
|
|
||||||
$selected_date_working_plan = $working_plan[strtolower(date('l', strtotime($selected_date)))];
|
$selected_date_working_plan = $working_plan[strtolower(date('l', strtotime($selected_date)))];
|
||||||
$available_periods_with_breaks = [];
|
|
||||||
|
$periods = [];
|
||||||
|
|
||||||
if (isset($selected_date_working_plan['breaks']))
|
if (isset($selected_date_working_plan['breaks']))
|
||||||
{
|
{
|
||||||
$start = new DateTime($selected_date_working_plan['start']);
|
$periods[] = [
|
||||||
$end = new DateTime($selected_date_working_plan['end']);
|
|
||||||
$available_periods_with_breaks[] = [
|
|
||||||
'start' => $selected_date_working_plan['start'],
|
'start' => $selected_date_working_plan['start'],
|
||||||
'end' => $selected_date_working_plan['end']
|
'end' => $selected_date_working_plan['end']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$day_start = new DateTime($selected_date_working_plan['start']);
|
||||||
|
$day_end = new DateTime($selected_date_working_plan['end']);
|
||||||
|
|
||||||
// Split the working plan to available time periods that do not contain the breaks in them.
|
// Split the working plan to available time periods that do not contain the breaks in them.
|
||||||
foreach ($selected_date_working_plan['breaks'] as $index => $break)
|
foreach ($selected_date_working_plan['breaks'] as $index => $break)
|
||||||
{
|
{
|
||||||
$break_start = new DateTime($break['start']);
|
$break_start = new DateTime($break['start']);
|
||||||
$break_end = new DateTime($break['end']);
|
$break_end = new DateTime($break['end']);
|
||||||
|
|
||||||
if ($break_start < $start)
|
if ($break_start < $day_start)
|
||||||
{
|
{
|
||||||
$break_start = $start;
|
$break_start = $day_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($break_end > $end)
|
if ($break_end > $day_end)
|
||||||
{
|
{
|
||||||
$break_end = $end;
|
$break_end = $day_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($break_start >= $break_end)
|
if ($break_start >= $break_end)
|
||||||
|
@ -809,106 +840,101 @@ class Appointments extends CI_Controller {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($available_periods_with_breaks as $key => $open_period)
|
foreach ($periods as $key => $period)
|
||||||
{
|
{
|
||||||
$s = new DateTime($open_period['start']);
|
$period_start = new DateTime($period['start']);
|
||||||
$e = new DateTime($open_period['end']);
|
$period_end = new DateTime($period['end']);
|
||||||
|
|
||||||
if ($s < $break_end && $break_start < $e)
|
$remove_current_period = FALSE;
|
||||||
{ // check for overlap
|
|
||||||
$changed = FALSE;
|
|
||||||
if ($s < $break_start)
|
|
||||||
{
|
|
||||||
$open_start = $s;
|
|
||||||
$open_end = $break_start;
|
|
||||||
$available_periods_with_breaks[] = [
|
|
||||||
'start' => $open_start->format("H:i"),
|
|
||||||
'end' => $open_end->format("H:i")
|
|
||||||
];
|
|
||||||
$changed = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($break_end < $e)
|
if ($break_start > $period_start && $break_start < $period_end && $break_end > $period_start)
|
||||||
{
|
{
|
||||||
$open_start = $break_end;
|
$periods[] = [
|
||||||
$open_end = $e;
|
'start' => $period_start->format('H:i'),
|
||||||
$available_periods_with_breaks[] = [
|
'end' => $break_start->format('H:i')
|
||||||
'start' => $open_start->format("H:i"),
|
];
|
||||||
'end' => $open_end->format("H:i")
|
|
||||||
];
|
|
||||||
$changed = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($changed)
|
$remove_current_period = TRUE;
|
||||||
{
|
}
|
||||||
unset($available_periods_with_breaks[$key]);
|
|
||||||
}
|
if ($break_start < $period_end && $break_end > $period_start && $break_end < $period_end)
|
||||||
|
{
|
||||||
|
$periods[] = [
|
||||||
|
'start' => $break_end->format('H:i'),
|
||||||
|
'end' => $period_end->format('H:i')
|
||||||
|
];
|
||||||
|
|
||||||
|
$remove_current_period = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($remove_current_period)
|
||||||
|
{
|
||||||
|
unset($periods[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break the empty periods with the reserved appointments.
|
// Break the empty periods with the reserved appointments.
|
||||||
$available_periods_with_appointments = $available_periods_with_breaks;
|
foreach ($provider_appointments as $provider_appointment)
|
||||||
|
|
||||||
foreach ($reserved_appointments as $appointment)
|
|
||||||
{
|
{
|
||||||
foreach ($available_periods_with_appointments as $index => &$period)
|
foreach ($periods as $index => &$period)
|
||||||
{
|
{
|
||||||
$a_start = strtotime($appointment['start_datetime']);
|
$appointment_start = new DateTime($provider_appointment['start_datetime']);
|
||||||
$a_end = strtotime($appointment['end_datetime']);
|
$appointment_end = new DateTime($provider_appointment['end_datetime']);
|
||||||
$p_start = strtotime($selected_date . ' ' . $period['start']);
|
$period_start = new DateTime($selected_date . ' ' . $period['start']);
|
||||||
$p_end = strtotime($selected_date . ' ' . $period['end']);
|
$period_end = new DateTime($selected_date . ' ' . $period['end']);
|
||||||
|
|
||||||
if ($a_start <= $p_start && $a_end <= $p_end && $a_end <= $p_start)
|
if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end <= $period_start)
|
||||||
{
|
{
|
||||||
// The appointment does not belong in this time period, so we
|
// The appointment does not belong in this time period, so we will not change anything.
|
||||||
// will not change anything.
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($a_start <= $p_start && $a_end <= $p_end && $a_end >= $p_start)
|
if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end >= $period_start)
|
||||||
{
|
{
|
||||||
// The appointment starts before the period and finishes somewhere inside.
|
// The appointment starts before the period and finishes somewhere inside. We will need to break
|
||||||
// We will need to break this period and leave the available part.
|
// this period and leave the available part.
|
||||||
$period['start'] = date('H:i', $a_end);
|
$period['start'] = $appointment_end->format('H:i');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($a_start >= $p_start && $a_end <= $p_end)
|
if ($appointment_start >= $period_start && $appointment_end <= $period_end)
|
||||||
{
|
{
|
||||||
// The appointment is inside the time period, so we will split the period
|
// The appointment is inside the time period, so we will split the period into two new
|
||||||
// into two new others.
|
// others.
|
||||||
unset($available_periods_with_appointments[$index]);
|
unset($periods[$index]);
|
||||||
$available_periods_with_appointments[] = [
|
|
||||||
'start' => date('H:i', $p_start),
|
$periods[] = [
|
||||||
'end' => date('H:i', $a_start)
|
'start' => $period_start->format('H:i'),
|
||||||
|
'end' => $appointment_start->format('H:i')
|
||||||
];
|
];
|
||||||
$available_periods_with_appointments[] = [
|
|
||||||
'start' => date('H:i', $a_end),
|
$periods[] = [
|
||||||
'end' => date('H:i', $p_end)
|
'start' => $appointment_end->format('H:i'),
|
||||||
|
'end' => $appointment_end->format('H:i')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($a_start >= $p_start && $a_end >= $p_start && $a_start <= $p_end)
|
if ($appointment_start >= $period_start && $appointment_end >= $period_start && $appointment_start <= $period_end)
|
||||||
{
|
{
|
||||||
// The appointment starts in the period and finishes out of it. We will
|
// The appointment starts in the period and finishes out of it. We will need to remove
|
||||||
// need to remove the time that is taken from the appointment.
|
// the time that is taken from the appointment.
|
||||||
$period['end'] = date('H:i', $a_start);
|
$period['end'] = $appointment_start->format('H:i');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($a_start >= $p_start && $a_end >= $p_end && $a_start >= $p_end)
|
if ($appointment_start >= $period_start && $appointment_end >= $period_end && $appointment_start >= $period_end)
|
||||||
{
|
{
|
||||||
// The appointment does not belong in the period so do not change anything.
|
// The appointment does not belong in the period so do not change anything.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($a_start <= $p_start && $a_end >= $p_end && $a_start <= $p_end)
|
if ($appointment_start <= $period_start && $appointment_end >= $period_end && $appointment_start <= $period_end)
|
||||||
{
|
{
|
||||||
// The appointment is bigger than the period, so this period needs to be removed.
|
// The appointment is bigger than the period, so this period needs to be removed.
|
||||||
unset($available_periods_with_appointments[$index]);
|
unset($periods[$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -918,7 +944,7 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_values($available_periods_with_appointments);
|
return array_values($periods);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -946,7 +972,8 @@ class Appointments extends CI_Controller {
|
||||||
{
|
{
|
||||||
if ($provider_service_id == $service_id)
|
if ($provider_service_id == $service_id)
|
||||||
{ // Check if the provider is available for the requested date.
|
{ // Check if the provider is available for the requested date.
|
||||||
$empty_periods = $this->_get_provider_available_time_periods($provider['id'], $selected_date);
|
$empty_periods = $this->_get_provider_available_time_periods($provider['id'], $service_id,
|
||||||
|
$selected_date);
|
||||||
$available_hours = $this->_calculate_available_hours($empty_periods, $selected_date,
|
$available_hours = $this->_calculate_available_hours($empty_periods, $selected_date,
|
||||||
$service['duration'], FALSE, $service['availabilities_type']);
|
$service['duration'], FALSE, $service['availabilities_type']);
|
||||||
if (count($available_hours) > $max_hours_count)
|
if (count($available_hours) > $max_hours_count)
|
||||||
|
@ -1005,28 +1032,6 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the selected date is today, remove past hours. It is important include the timeout before
|
|
||||||
// booking that is set in the back-office the system. Normally we might want the customer to book
|
|
||||||
// an appointment that is at least half or one hour from now. The setting is stored in minutes.
|
|
||||||
if (date('m/d/Y', strtotime($selected_date)) === date('m/d/Y'))
|
|
||||||
{
|
|
||||||
$book_advance_timeout = $this->settings_model->get_setting('book_advance_timeout');
|
|
||||||
|
|
||||||
foreach ($available_hours as $index => $value)
|
|
||||||
{
|
|
||||||
$available_hour = strtotime($value);
|
|
||||||
$current_hour = strtotime('+' . $book_advance_timeout . ' minutes', strtotime('now'));
|
|
||||||
if ($available_hour <= $current_hour)
|
|
||||||
{
|
|
||||||
unset($available_hours[$index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$available_hours = array_values($available_hours);
|
|
||||||
sort($available_hours, SORT_STRING);
|
|
||||||
$available_hours = array_values($available_hours);
|
|
||||||
|
|
||||||
return $available_hours;
|
return $available_hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1035,38 +1040,25 @@ class Appointments extends CI_Controller {
|
||||||
*
|
*
|
||||||
* This method will add the extra appointment hours whenever a service accepts multiple attendants.
|
* This method will add the extra appointment hours whenever a service accepts multiple attendants.
|
||||||
*
|
*
|
||||||
* @param array $available_hours The previously calculated appointment hours.
|
|
||||||
* @param int $availabilities_type
|
|
||||||
* @param int $attendants_number Service attendants number.
|
|
||||||
* @param int $service_id Selected service ID.
|
|
||||||
* @param string $selected_date The selected appointment date.
|
* @param string $selected_date The selected appointment date.
|
||||||
|
* @param array $service Selected service data.
|
||||||
|
* @param array $provider Selected provider data.
|
||||||
|
*
|
||||||
|
* @return array Returns the available hours array.
|
||||||
*/
|
*/
|
||||||
protected function _get_multiple_attendants_hours(
|
protected function _get_multiple_attendants_hours(
|
||||||
$selected_date,
|
$selected_date,
|
||||||
$availabilities_type,
|
$service,
|
||||||
$attendants_number,
|
$provider
|
||||||
$service_id,
|
|
||||||
$provider_id
|
|
||||||
) {
|
) {
|
||||||
/*
|
|
||||||
* Multiple availabilities should allow two appointments to reserve the same time.
|
|
||||||
*
|
|
||||||
* The current system does not check the time correctly cause an appointment that is bigger than the
|
|
||||||
* original service duration will not be taken into concern.
|
|
||||||
*
|
|
||||||
* Recreate this method logic from scratch.
|
|
||||||
*/
|
|
||||||
|
|
||||||
$this->load->model('appointments_model');
|
$this->load->model('appointments_model');
|
||||||
$this->load->model('services_model');
|
$this->load->model('services_model');
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
|
||||||
$service = $this->services_model->get_row($service_id);
|
|
||||||
$provider = $this->providers_model->get_row($provider_id);
|
|
||||||
$unavailabilities = $this->appointments_model->get_batch([
|
$unavailabilities = $this->appointments_model->get_batch([
|
||||||
'is_unavailable' => TRUE,
|
'is_unavailable' => TRUE,
|
||||||
'DATE(start_datetime)' => $selected_date,
|
'DATE(start_datetime)' => $selected_date,
|
||||||
'id_users_provider' => $provider_id
|
'id_users_provider' => $provider['id']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$working_plan = json_decode($provider['settings']['working_plan'], TRUE);
|
$working_plan = json_decode($provider['settings']['working_plan'], TRUE);
|
||||||
|
@ -1085,7 +1077,7 @@ class Appointments extends CI_Controller {
|
||||||
|
|
||||||
$hours = [];
|
$hours = [];
|
||||||
|
|
||||||
$interval_value = $availabilities_type == AVAILABILITIES_TYPE_FIXED ? $service['duration'] : '15';
|
$interval_value = $service['availabilities_type'] == AVAILABILITIES_TYPE_FIXED ? $service['duration'] : '15';
|
||||||
$interval = new DateInterval('PT' . (int)$interval_value . 'M');
|
$interval = new DateInterval('PT' . (int)$interval_value . 'M');
|
||||||
$duration = new DateInterval('PT' . (int)$service['duration'] . 'M');
|
$duration = new DateInterval('PT' . (int)$service['duration'] . 'M');
|
||||||
|
|
||||||
|
@ -1097,20 +1089,11 @@ class Appointments extends CI_Controller {
|
||||||
|
|
||||||
while ($slot_end <= $period['end'])
|
while ($slot_end <= $period['end'])
|
||||||
{
|
{
|
||||||
//$appointment_attendants_number = $this->appointments_model->get_attendants_number_for_period($start_start, )
|
|
||||||
|
|
||||||
// Check reserved attendants for this time slot and see if current attendants fit.
|
// Check reserved attendants for this time slot and see if current attendants fit.
|
||||||
$appointment_attendants_number = (int)$this->db
|
$appointment_attendants_number = $this->appointments_model->get_attendants_number_for_period($slot_start,
|
||||||
->select('count(*) AS attendants_number')
|
$slot_end, $service['id']);
|
||||||
->from('ea_appointments')
|
|
||||||
->where('start_datetime <= ', $slot_start->format('Y-m-d H:i:s'))
|
|
||||||
->where('end_datetime >=', $slot_start->format('Y-m-d H:i:s'))
|
|
||||||
->where('id_services', $service['id'])
|
|
||||||
->get()
|
|
||||||
->row()
|
|
||||||
->attendants_number;
|
|
||||||
|
|
||||||
if ($appointment_attendants_number <= $service['attendants_number'])
|
if ($appointment_attendants_number < $service['attendants_number'])
|
||||||
{
|
{
|
||||||
$hours[] = $slot_start->format('H:i');
|
$hours[] = $slot_start->format('H:i');
|
||||||
}
|
}
|
||||||
|
@ -1121,28 +1104,17 @@ class Appointments extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
return $hours;
|
return $hours;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//foreach ($appointments as $appointment)
|
|
||||||
//{
|
|
||||||
// $hour = date('H:i', strtotime($appointment['start_datetime']));
|
|
||||||
// $current_attendants_number = $this->appointments_model->appointment_count_for_hour($service_id,
|
|
||||||
// $selected_date, $hour);
|
|
||||||
// if ($current_attendants_number < $attendants_number && ! in_array($hour, $available_hours))
|
|
||||||
// {
|
|
||||||
// $available_hours[] = $hour;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//$available_hours = array_values($available_hours);
|
|
||||||
//sort($available_hours, SORT_STRING);
|
|
||||||
//$available_hours = array_values($available_hours);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove breaks from available time periods.
|
||||||
|
*
|
||||||
|
* @param string $selected_date Selected data (Y-m-d format).
|
||||||
|
* @param array $periods Time periods of the current date.
|
||||||
|
* @param array $breaks Breaks array for the current date.
|
||||||
|
*
|
||||||
|
* @return array Returns the available time periods without the breaks.
|
||||||
|
*/
|
||||||
public function remove_breaks($selected_date, $periods, $breaks)
|
public function remove_breaks($selected_date, $periods, $breaks)
|
||||||
{
|
{
|
||||||
if ( ! $breaks)
|
if ( ! $breaks)
|
||||||
|
@ -1197,6 +1169,14 @@ class Appointments extends CI_Controller {
|
||||||
return $periods;
|
return $periods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the unavailabilities from the available time periods of the selected date.
|
||||||
|
*
|
||||||
|
* @param array $periods Available time periods.
|
||||||
|
* @param array $unavailabilities Unavailabilities of the current date.
|
||||||
|
*
|
||||||
|
* @return array Returns the available time periods without the unavailabilities.
|
||||||
|
*/
|
||||||
public function remove_unavailabilities($periods, $unavailabilities)
|
public function remove_unavailabilities($periods, $unavailabilities)
|
||||||
{
|
{
|
||||||
foreach ($unavailabilities as $unavailability)
|
foreach ($unavailabilities as $unavailability)
|
||||||
|
@ -1236,7 +1216,7 @@ class Appointments extends CI_Controller {
|
||||||
|
|
||||||
if ($unavailability_start <= $period_start && $unavailability_end >= $period_end)
|
if ($unavailability_start <= $period_start && $unavailability_end >= $period_end)
|
||||||
{
|
{
|
||||||
// unavaibility contains period
|
// Unavaibility contains period
|
||||||
$period['start'] = $unavailability_end;
|
$period['start'] = $unavailability_end;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,6 +481,33 @@ class Appointments_Model extends CI_Model {
|
||||||
])->num_rows();
|
])->num_rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the attendants number for selection period.
|
||||||
|
*
|
||||||
|
* @param DateTime $slot_start When the slot starts
|
||||||
|
* @param DateTime $slot_end When the slot ends.
|
||||||
|
* @param int $service_id Selected service ID.
|
||||||
|
*
|
||||||
|
* @return int Returns the number of attendants for selected time period.
|
||||||
|
*/
|
||||||
|
public function get_attendants_number_for_period(DateTime $slot_start, DateTime $slot_end, $service_id) {
|
||||||
|
return(int)$this->db
|
||||||
|
->select('count(*) AS attendants_number')
|
||||||
|
->from('ea_appointments')
|
||||||
|
->group_start()
|
||||||
|
->where('start_datetime <=', $slot_start->format('Y-m-d H:i:s'))
|
||||||
|
->where('end_datetime >', $slot_start->format('Y-m-d H:i:s'))
|
||||||
|
->group_end()
|
||||||
|
->or_group_start()
|
||||||
|
->where('start_datetime <', $slot_end->format('Y-m-d H:i:s'))
|
||||||
|
->where('end_datetime >=', $slot_end->format('Y-m-d H:i:s'))
|
||||||
|
->group_end()
|
||||||
|
->where('id_services', $service_id)
|
||||||
|
->get()
|
||||||
|
->row()
|
||||||
|
->attendants_number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the aggregates of an appointment.
|
* Get the aggregates of an appointment.
|
||||||
*
|
*
|
||||||
|
|
|
@ -86,7 +86,7 @@ window.FrontendBook = window.FrontendBook || {};
|
||||||
closeText: EALang.close,
|
closeText: EALang.close,
|
||||||
|
|
||||||
onSelect: function(dateText, instance) {
|
onSelect: function(dateText, instance) {
|
||||||
FrontendBookApi.getAvailableHours(dateText);
|
FrontendBookApi.getAvailableHours($(this).datepicker('getDate').toString('yyyy-MM-dd'));
|
||||||
FrontendBook.updateConfirmFrame();
|
FrontendBook.updateConfirmFrame();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue