diff --git a/application/libraries/Availability.php b/application/libraries/Availability.php index b7919733..883e91db 100644 --- a/application/libraries/Availability.php +++ b/application/libraries/Availability.php @@ -58,7 +58,7 @@ class Availability { if ($service['attendants_number'] > 1) { - $available_hours = $this->consider_multiple_attendants($date, $service, $provider); + $available_hours = $this->consider_multiple_attendants($date, $service, $provider, $exclude_appointment_id); } return $this->consider_book_advance_timeout($date, $available_hours, $provider); @@ -326,6 +326,7 @@ class Availability { * @param string $date Selected date (Y-m-d). * @param array $service Service record. * @param array $provider Provider record. + * @param int|null $exclude_appointment_id Exclude an appointment from the availability generation. * * @return array Returns the available hours array. * @@ -334,7 +335,8 @@ class Availability { protected function consider_multiple_attendants( $date, $service, - $provider + $provider, + $exclude_appointment_id = NULL ) { $unavailability_events = $this->CI->appointments_model->get_batch([ @@ -390,7 +392,8 @@ class Availability { $appointment_attendants_number = $this->CI->appointments_model->get_attendants_number_for_period( $slot_start, $slot_end, - $service['id'] + $service['id'], + $exclude_appointment_id ); if ($appointment_attendants_number < $service['attendants_number']) diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index bb472bd7..9defb2f4 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -556,11 +556,17 @@ class Appointments_model extends EA_Model { * @param DateTime $slot_start When the slot starts * @param DateTime $slot_end When the slot ends. * @param int $service_id Selected service ID. + * @param int|null $exclude_appointment_id Exclude an appointment from the availability generation. * * @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) + public function get_attendants_number_for_period(DateTime $slot_start, DateTime $slot_end, $service_id, $exclude_appointment_id = NULL) { + if ($exclude_appointment_id) + { + $this->db->where('id !=', $exclude_appointment_id); + } + return (int)$this->db ->select('count(*) AS attendants_number') ->from('appointments')