forked from mirrors/easyappointments
Check for other services when calculating multiple attendants number availability (#948).
This commit is contained in:
parent
7bf1d536f3
commit
3381b998a1
2 changed files with 57 additions and 1 deletions
|
@ -388,11 +388,28 @@ class Availability {
|
|||
|
||||
while ($slot_end <= $period['end'])
|
||||
{
|
||||
// Make sure there is no other service appointment for this time slot.
|
||||
$other_service_attendants_number = $this->CI->appointments_model->get_other_service_attendants_number(
|
||||
$slot_start,
|
||||
$slot_end,
|
||||
$service['id'],
|
||||
$provider['id'],
|
||||
$exclude_appointment_id
|
||||
);
|
||||
|
||||
if ($other_service_attendants_number > 0)
|
||||
{
|
||||
$slot_start->add($interval);
|
||||
$slot_end->add($interval);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check reserved attendants for this time slot and see if current attendants fit.
|
||||
$appointment_attendants_number = $this->CI->appointments_model->get_attendants_number_for_period(
|
||||
$slot_start,
|
||||
$slot_end,
|
||||
$service['id'],
|
||||
$provider['id'],
|
||||
$exclude_appointment_id
|
||||
);
|
||||
|
||||
|
|
|
@ -556,11 +556,12 @@ 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 $provider_id Selected provider 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, $exclude_appointment_id = NULL)
|
||||
public function get_attendants_number_for_period(DateTime $slot_start, DateTime $slot_end, $service_id, $provider_id, $exclude_appointment_id = NULL)
|
||||
{
|
||||
if ($exclude_appointment_id)
|
||||
{
|
||||
|
@ -581,6 +582,44 @@ class Appointments_model extends EA_Model {
|
|||
->group_end()
|
||||
->group_end()
|
||||
->where('id_services', $service_id)
|
||||
->where('id_users_provider', $provider_id)
|
||||
->get()
|
||||
->row()
|
||||
->attendants_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the other service attendants number for the provided time slot.
|
||||
*
|
||||
* @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_other_service_attendants_number(DateTime $slot_start, DateTime $slot_end, $service_id, $provider_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')
|
||||
->group_start()
|
||||
->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()
|
||||
->group_end()
|
||||
->where('id_services !=', $service_id)
|
||||
->where('id_users_provider', $provider_id)
|
||||
->get()
|
||||
->row()
|
||||
->attendants_number;
|
||||
|
|
Loading…
Reference in a new issue