From 2fdef2e0c1d5a5f7dd220f8003588a3b43d1ad9b Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Wed, 26 Jun 2024 17:07:00 +0200 Subject: [PATCH] Bug 37201: Allow or not a checkout if a expired booking exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: 1) Apply this patch and run updatedatabase 2) Set a booking on a specific item 3) In database you can update the value to set a past date for booking end for example. 4) Go system preferences and search 'AllowExpiredBookingTransformation' 5) When you "Don\'t allow" normally you will find a pop up to confirm the checkout when you choose to 'Transform to checkout' from bookings list view. Sponsored by: Association de Gestion des Ĺ’uvres Sociales d'Inria (AGOS) --- C4/Circulation.pm | 9 +++++++++ circ/circulation.pl | 1 + ...ug_37201_allow-expired-booking-to-checkout.pl | 16 ++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../modules/admin/preferences/circulation.pref | 6 ++++++ .../prog/en/modules/circ/circulation.tt | 5 +++++ 6 files changed, 38 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/Bug_37201_allow-expired-booking-to-checkout.pl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 70ccd7fb54d..ae0808abe04 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -780,6 +780,7 @@ sub CanBookBeIssued { my $onsite_checkout = $params->{onsite_checkout} || 0; my $override_high_holds = $params->{override_high_holds} || 0; + my $booking_id = $params->{booking_id}; my $item_object = $params->{item} // Koha::Items->find( { barcode => $barcode } ); @@ -1271,6 +1272,14 @@ sub CanBookBeIssued { } } + if ( $booking_id && !(C4::Context->preference('AllowExpiredBookingTransformation')) ) { + my $booking = Koha::Bookings->find( { booking_id => $booking_id } ); + my $booking_end = dt_from_string( $booking->end_date ); + if ( $booking->patron_id == $patron->borrowernumber && $now > $booking_end ) { + $needsconfirmation{'BOOKED_TOO_LATE'} = $booking; + } + } + ## CHECK AGE RESTRICTION my $agerestriction = $biblioitem->agerestriction; my $restriction_age = GetAgeRestriction( $agerestriction ); diff --git a/circ/circulation.pl b/circ/circulation.pl index acabfa4d1db..8a064c66ff4 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -339,6 +339,7 @@ if (@$barcodes && $op eq 'cud-checkout') { { onsite_checkout => $onsite_checkout, override_high_holds => $override_high_holds || $override_high_holds_tmp || 0, + booking_id => $booking_id, } ); } catch { diff --git a/installer/data/mysql/atomicupdate/Bug_37201_allow-expired-booking-to-checkout.pl b/installer/data/mysql/atomicupdate/Bug_37201_allow-expired-booking-to-checkout.pl new file mode 100755 index 00000000000..ca287a79d03 --- /dev/null +++ b/installer/data/mysql/atomicupdate/Bug_37201_allow-expired-booking-to-checkout.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "37201", + description => "Add syspref AllowExpiredBookingTransformation", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('AllowExpiredBookingTransformation', 1, '', 'Prevent transform into checkout a past booking', 'YesNo'); + }); + + say $out "Added new system preference 'AllowExpiredBookingTransformation'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 1a7cd033e90..b4f5780d0b9 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -28,6 +28,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AllFinesNeedOverride','1','0','If on, staff will be asked to override every fine, even if it is below noissuescharge.','YesNo'), ('AllowAllMessageDeletion','0','','Allow any Library to delete any message','YesNo'), ('AllowCheckoutNotes', '0', NULL, 'Allow patrons to submit notes about checked out items.','YesNo'), +('AllowExpiredBookingTransformation','1','','Prevent transform into checkout a past booking','YesNo'), ('AllowFineOverride','0','0','If on, staff will be able to issue books to patrons with fines greater than noissuescharge.','YesNo'), ('AllowHoldDateInFuture','0','','If set a date field is displayed on the Hold screen of the Staff Interface, allowing the hold date to be set in the future.','YesNo'), ('AllowHoldItemTypeSelection','0','','If enabled, patrons and staff will be able to select the itemtype when placing a hold','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 76983576a6a..ee907c26a63 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -622,6 +622,12 @@ Circulation: choices: authval source: LOST - "when the outstanding balance is written off." + - + - pref: AllowExpiredBookingTransformation + choices: + 1: Allow + 0: "Don't allow" + - patrons to transform a past booking into checkout. Checkin policy: - - pref: TrapHoldsOnOrder diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index e596daec917..66f8a40d8bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -274,6 +274,11 @@ Patron has this item booked for checkout on [% BOOKED_EARLY.start_date | $KohaDates %] [% END %] + [% IF ( BOOKED_TOO_LATE ) %] +
  • + Booking ended on [% BOOKED_TOO_LATE.end_date | $KohaDates %] would you force the checkout ? +
  • + [% END %] [% IF CAN_user_circulate_force_checkout or HIGHHOLDS %] -- 2.30.2