Ensure that multiple attendant services can be modified with proper availability.

This commit is contained in:
Alex Tselegidis 2020-12-09 15:32:39 +02:00
parent 75905752f7
commit bde91f5a14
2 changed files with 13 additions and 4 deletions

View file

@ -58,7 +58,7 @@ class Availability {
if ($service['attendants_number'] > 1) 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); 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 string $date Selected date (Y-m-d).
* @param array $service Service record. * @param array $service Service record.
* @param array $provider Provider 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. * @return array Returns the available hours array.
* *
@ -334,7 +335,8 @@ class Availability {
protected function consider_multiple_attendants( protected function consider_multiple_attendants(
$date, $date,
$service, $service,
$provider $provider,
$exclude_appointment_id = NULL
) )
{ {
$unavailability_events = $this->CI->appointments_model->get_batch([ $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( $appointment_attendants_number = $this->CI->appointments_model->get_attendants_number_for_period(
$slot_start, $slot_start,
$slot_end, $slot_end,
$service['id'] $service['id'],
$exclude_appointment_id
); );
if ($appointment_attendants_number < $service['attendants_number']) if ($appointment_attendants_number < $service['attendants_number'])

View file

@ -556,11 +556,17 @@ class Appointments_model extends EA_Model {
* @param DateTime $slot_start When the slot starts * @param DateTime $slot_start When the slot starts
* @param DateTime $slot_end When the slot ends. * @param DateTime $slot_end When the slot ends.
* @param int $service_id Selected service ID. * @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. * @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 return (int)$this->db
->select('count(*) AS attendants_number') ->select('count(*) AS attendants_number')
->from('appointments') ->from('appointments')