From b9a65e44cc9dd66355351c201617ea24c3225888 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Fri, 17 May 2024 15:50:09 +0200 Subject: [PATCH] Bug 36271: (follow-up) Add switch for join table according to item-level_itypes syspref --- Koha/Booking.pm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index abd006bd86a..c99027cb156 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -91,13 +91,25 @@ sub can_be_booked_in_advance { my $bookings_per_item_count = Koha::Bookings->search( { patron_id => $patron->borrowernumber, item_id => $item->itemnumber } )->count(); return { status => 'tooManyBookings', limit => $bookings_per_item, rule => 'bookings_per_item' } if defined($bookings_per_item) && $bookings_per_item <= $bookings_per_item_count; - my $querycount = q{ - SELECT count(*) AS count - FROM bookings AS b - LEFT JOIN biblioitems AS bi ON (b.biblio_id=bi.biblionumber) - WHERE b.patron_id = ? - AND bi.itemtype = ? - }; + + my $querycount; + if (C4::Context->preference('item-level_itypes')) { + $querycount = q{ + SELECT count(*) AS count + FROM bookings AS b + LEFT JOIN items AS i ON (b.biblio_id=i.biblionumber) + WHERE b.patron_id = ? + AND i.itype = ? + }; + } else { + $querycount = q{ + SELECT count(*) AS count + FROM bookings AS b + LEFT JOIN biblioitems AS bi ON (b.biblio_id=bi.biblionumber) + WHERE b.patron_id = ? + AND bi.itemtype = ? + }; + } my $sthcount = $dbh->prepare($querycount); $sthcount->execute( $patron->borrowernumber, $item->effective_itemtype ); -- 2.30.2