From 0e6ce42764f9ebe7a89de54f71dd17249fd65c0d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 14 May 2025 14:18:47 +0100 Subject: [PATCH] Bug 39584: Include trailDays when calculating maxDate When enforcing the max booking period from the circulation rules, we should not include booking post processing days. Our pre and post processing days handling looks for 'flatpickr-disabled' and ensure processing days cannot overlap. When setting maxDate, flatpickr will apply the flatpickr-disabled class to the next day to prevent selection past the max date and as such our post-processing acts in an inclusive manor. This patch updates our maxDate handler to increase then maximum target by the trailDays setting to allow a full loan period and includes styling to match flatpickr-disabled for the exclusive trailDays. To test: 1. Set up two days of post-processing time in the circ rules for an item type. 2. Make that item type bookable. 3. Place a booking for an item from that item type. Note that the 2-days of post-processing time are factored into the total number of days allowed for the booking. For a 7-day circ period, the booking cannot be set for 7 days; it is enforced to end at 5. 4. APPLY PATCH 5. Try the booking again, this time you should be able to select the full loan period for that item. --- .../prog/css/src/staff-global.scss | 7 ++++++ .../prog/js/modals/place_booking.js | 23 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index 5798abfd153..aeb523696f1 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -899,6 +899,13 @@ $dayTrailBackground: #fcdcb3 !default; } } + &.booking-grey { + color: rgba(0, 0, 0, 0.3); + background: transparent; + border-color: transparent; + cursor: default; + } + &.trailRange { box-shadow: -2.5 * $dayMargin 0 0 $dayTrailBackground, 2.5 * $dayMargin 0 0 $dayTrailBackground; background: $dayTrailBackground; diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js index 634cce0c36e..4e8d2e83fa9 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -132,6 +132,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { // Circulation rules update let leadDays = 0; let trailDays = 0; + let greyDates = []; let boldDates = []; let issueLength; let renewalLength; @@ -767,9 +768,20 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { const maxDate = new Date(startDate.getTime()); maxDate.setDate( - maxDate.getDate() + totalIssueLength + maxDate.getDate() + + totalIssueLength + + parseInt(trailDays) ); + // Apply disabled style to inclusive trailDays in maxDate + for (let i = 0; i < trailDays; i++) { + const greyDate = new Date( + maxDate.getTime() + ); + greyDate.setDate(greyDate.getDate() - i); + greyDates.unshift(greyDate); + } + // Update the maxDate option of the flatpickr instance instance.set("maxDate", maxDate); } @@ -844,6 +856,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { // Range not set, reset field options and flatPickr state else { boldDates = []; + greyDates = []; instance.set("maxDate", null); $("#booking_item_id > option").each( function () { @@ -907,6 +920,14 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { dayElem.classList.add("title"); } + const isGreyed = greyDates.some( + greyDate => + greyDate.getTime() === currentDate.getTime() + ); + if (isGreyed) { + dayElem.classList.add("booking-grey"); + } + if (bookingsByDate[dateString]) { const dots = document.createElement("span"); dots.className = "event-dots"; -- 2.49.0