feat(appointment): enhance booking window functionality with day/week/month options and update defaults
This commit is contained in:
@@ -27,9 +27,12 @@ class WeeklySchedule
|
||||
public const MODE_SLOT = 'slot'; // نوبتدهی اسلاتی (رفتار پیشفرض)
|
||||
public const MODE_SERVICE = 'service'; // نوبتدهی بر اساس مدت سرویس
|
||||
|
||||
/** واحدهای مجاز بازهٔ رزرو آنلاین؛ همان کلیدواژههای strtotime. */
|
||||
public const BOOKING_WINDOW_UNITS = ['day', 'week', 'month'];
|
||||
|
||||
public const DEFAULT_META = [
|
||||
'online_booking_enabled' => true,
|
||||
'booking_window_value' => 1,
|
||||
'booking_window_value' => 3,
|
||||
'booking_window_unit' => 'month',
|
||||
'booking_mode' => self::MODE_SLOT,
|
||||
'buffer_minutes' => 0,
|
||||
@@ -128,7 +131,7 @@ class WeeklySchedule
|
||||
$this->setting[self::META_KEY] = [
|
||||
'online_booking_enabled' => (bool)($meta['online_booking_enabled'] ?? $current['online_booking_enabled']),
|
||||
'booking_window_value' => max(1, (int)($meta['booking_window_value'] ?? $current['booking_window_value'])),
|
||||
'booking_window_unit' => in_array($meta['booking_window_unit'] ?? null, ['week', 'month'], true)
|
||||
'booking_window_unit' => in_array($meta['booking_window_unit'] ?? null, self::BOOKING_WINDOW_UNITS, true)
|
||||
? $meta['booking_window_unit']
|
||||
: $current['booking_window_unit'],
|
||||
'booking_mode' => in_array($meta['booking_mode'] ?? null, [self::MODE_SLOT, self::MODE_SERVICE], true)
|
||||
|
||||
@@ -263,10 +263,13 @@ class SlotCalculatorService
|
||||
return false;
|
||||
}
|
||||
|
||||
/** آخرین روزی که رزرو عمومی روی آن مجاز است (شروعِ آن روز، 00:00). */
|
||||
private function bookingWindowEnd(array $meta): int
|
||||
{
|
||||
$value = max(1, (int) ($meta['booking_window_value'] ?? 1));
|
||||
$unit = ($meta['booking_window_unit'] ?? 'month') === 'week' ? 'week' : 'month';
|
||||
$value = max(1, (int) ($meta['booking_window_value'] ?? WeeklySchedule::DEFAULT_META['booking_window_value']));
|
||||
$unit = in_array($meta['booking_window_unit'] ?? null, WeeklySchedule::BOOKING_WINDOW_UNITS, true)
|
||||
? $meta['booking_window_unit']
|
||||
: WeeklySchedule::DEFAULT_META['booking_window_unit'];
|
||||
|
||||
return (int) strtotime("today +{$value} {$unit} 00:00:00");
|
||||
}
|
||||
@@ -309,11 +312,7 @@ class SlotCalculatorService
|
||||
return false;
|
||||
}
|
||||
|
||||
$value = max(1, (int)($meta['booking_window_value'] ?? 1));
|
||||
$unit = ($meta['booking_window_unit'] ?? 'month') === 'week' ? 'week' : 'month';
|
||||
$maxStart = (int) strtotime("today +{$value} {$unit} 00:00:00");
|
||||
|
||||
return $dayStart <= $maxStart;
|
||||
return $dayStart <= $this->bookingWindowEnd($meta);
|
||||
}
|
||||
|
||||
private function getBookingMeta(Doctor $doctor, ?Clinic $clinic): array
|
||||
|
||||
Reference in New Issue
Block a user