From ebe087553ee8d0cbbbcfe4fd0279245c2b358891 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Tue, 11 Jul 2023 08:11:19 +0200 Subject: [PATCH] Automatically select the next available date in the booking page or display a message if this month is unavailable (#1075) (#1204) --- application/controllers/Booking.php | 9 +++++++++ assets/js/http/booking_http_client.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/application/controllers/Booking.php b/application/controllers/Booking.php index 72398059..e460b581 100755 --- a/application/controllers/Booking.php +++ b/application/controllers/Booking.php @@ -708,6 +708,15 @@ class Booking extends EA_Controller { $unavailable_dates[] = $current_date->format('Y-m-d'); } } + + if (count($unavailable_dates) === $number_of_days_in_month) + { + json_response([ + 'is_month_unavailable' => TRUE, + ]); + + return; + } json_response($unavailable_dates); } diff --git a/assets/js/http/booking_http_client.js b/assets/js/http/booking_http_client.js index 6a408719..0f9ceb8f 100755 --- a/assets/js/http/booking_http_client.js +++ b/assets/js/http/booking_http_client.js @@ -28,6 +28,7 @@ App.Http.Booking = (function () { let unavailableDatesBackup; let selectedDateStringBackup; let processingUnavailableDates = false; + let searchedMonthCounter = 0; /** * Get Available Hours @@ -260,6 +261,20 @@ App.Http.Booking = (function () { data: data, dataType: 'json' }).done((response) => { + if (response.is_month_unavailable) { + if (searchedMonthCounter >= 3) { + searchedMonthCounter = 0; + return; // Stop searching + } + + searchedMonthCounter++; + const selectedDateMoment = moment(selectedDateString); + selectedDateMoment.add(1, 'month'); + const nextSelectedDate = selectedDateMoment.format('YYYY-MM-DD'); + getUnavailableDates(providerId, serviceId, nextSelectedDate); + return; + } + unavailableDatesBackup = response; selectedDateStringBackup = selectedDateString; applyUnavailableDates(response, selectedDateString, true);