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);