From eb33863f2f3c710532af1e60a7ab9806c41508d1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sun, 14 Jul 2024 07:39:33 +0100 Subject: [PATCH] Bug 37354: Set maxDate based on issuelength + (renewals * renewalperiod) This patch sets the flatpickr maxDate in the bookings range picker to the startdate selected + issuelength + renewals * renewalperiod circulation rules. Test plan 1) Set an item in a test biblio to 'bookable' from the items tab. 2) Note the itemtype of the above item 3) Add circulation rules for the above item type, in particular the 'Loan period', 'Renewals allowed' and 'Renewal period' options. 4) Go back to your biblio and 'Place booking'. Select a user, pickup location and item. 5) Open the booking dates flatpickr. 6) Select a start date. 7) Note that the date that is 'Loan period' + 'Renewals allowed' * 'Renewal period' is now greyed out and cannot be selected or any date beyond it either. Signed-off-by: Paul Derscheid --- .../prog/js/modals/place_booking.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 4a168d107ba..1ae1f58e5dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -132,8 +132,8 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { // Lead and Trail days syncing let leadDays = 0; let trailDays = 0; + let lengthDays; function getCirculationRules() { - let rules_url = "/api/v1/circulation_rules"; $.ajax({ url: rules_url, type: "GET", @@ -142,10 +142,12 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { patron_category_id: booking_patron.category_id, item_type_id: booking_itemtype_id, library_id: pickup_library_id, - rules: "bookings_lead_period,bookings_trail_period", + rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod" }, success: function (response) { let rules = response[0]; + let renewalLength = rules.renewalsallowed * rules.renewalperiod; + lengthDays = rules.issuelength + renewalLength; leadDays = rules.bookings_lead_period; trailDays = rules.bookings_trail_period; @@ -672,8 +674,17 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { dateStr, instance ) { + // Start date selected + if (selectedDates[0] && !selectedDates[1]) { + // Calculate the maximum date based on the selected start date + const maxDate = new Date(selectedDates[0]); + maxDate.setDate(maxDate.getDate() + lengthDays ); + + // Update the maxDate option of the flatpickr instance + instance.set('maxDate', maxDate); + } // Range set, update hidden fields and set available items - if (selectedDates[0] && selectedDates[1]) { + else if (selectedDates[0] && selectedDates[1]) { // set form fields from picker let picker_start = dayjs(selectedDates[0]); let picker_end = dayjs(selectedDates[1]).endOf( -- 2.47.0