From 323533c588ccb0a685a8266acd6214dfa1cfadaf Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Mon, 12 Jun 2023 17:58:15 +0000 Subject: [PATCH] Bug 33887: Add the ability to optionally fill the next hold when an item is automatically checked in. When an item is automatically checked in, Koha should be able to trap that item for the next patron and send a notification to that patron that a hold is waiting for them. --- Koha/Checkouts.pm | 17 ++++++++++++++--- installer/data/mysql/atomicupdate/skeleton.pl | 18 +++++------------- installer/data/mysql/mandatory/sysprefs.sql | 1 + .../modules/admin/preferences/circulation.pref | 7 +++++++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Koha/Checkouts.pm b/Koha/Checkouts.pm index 76a3b9e686..c6db4562d0 100644 --- a/Koha/Checkouts.pm +++ b/Koha/Checkouts.pm @@ -28,6 +28,7 @@ use Koha::DateUtils qw( dt_from_string ); use base qw(Koha::Objects); + =head1 NAME Koha::Checkouts - Koha Checkout object set class @@ -66,7 +67,7 @@ sub calculate_dropbox_date { my $automatic_checkins = Koha::Checkouts->automatic_checkin() -Checks in every due issue which itemtype has automatic_checkin enabled +Checks in every due issue which itemtype has automatic_checkin enabled. Also if the AutoCheckinAutoFill sys. pref. is enabled, the item is trapped for the next patron. =cut @@ -81,10 +82,20 @@ sub automatic_checkin { { prefetch => 'item'} ); + my $autofill_next = C4::Context->preference('AutoCheckinAutoFill'); + while ( my $checkout = $due_checkouts->next ) { if ( $checkout->item->itemtype->automatic_checkin ) { - C4::Circulation::AddReturn( $checkout->item->barcode, - $checkout->branchcode, undef, dt_from_string($checkout->date_due) ); + my ( undef, $messages) = C4::Circulation::AddReturn($checkout->item->barcode, $checkout->branchcode, undef, dt_from_string($checkout->date_due) ); + my $is_transfer = $checkout->branchcode ne $messages->{ResFound}->{branchcode}; + if ( $autofill_next ){ + if ( $messages->{ResFound} ){ + C4::Reserves::ModReserveAffect($checkout->item->itemnumber, $checkout->borrowernumber, $is_transfer, $messages->{ResFound}->{reserve_id}, $checkout->{desk_id}, 0); + if( $is_transfer ){ + C4::Items::ModItemTransfer($checkout->item->itemnumber,$checkout->branchcode, $messages->{ResFound}->{branchcode},"Reserve"); + } + } + } } } } diff --git a/installer/data/mysql/atomicupdate/skeleton.pl b/installer/data/mysql/atomicupdate/skeleton.pl index c253039c5c..a420b537f2 100755 --- a/installer/data/mysql/atomicupdate/skeleton.pl +++ b/installer/data/mysql/atomicupdate/skeleton.pl @@ -1,24 +1,16 @@ use Modern::Perl; return { - bug_number => "BUG_NUMBER", - description => "A single line description", + bug_number => "33887", + description => "Automatically fill the next hold with a automatic check in.", up => sub { my ($args) = @_; my ($dbh, $out) = @$args{qw(dbh out)}; # Do you stuffs here - $dbh->do(q{}); + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('AutoCheckinAutoFill', '0', NULL,'Automatically fill the next hold with an automatic checkin cronjob.', 'YesNo'}); # Print useful stuff here - # tables - say $out "Added new table 'XXX'"; - say $out "Added column 'XXX.YYY'"; # sysprefs - say $out "Added new system preference 'XXX'"; - say $out "Updated system preference 'XXX'"; - say $out "Removed system preference 'XXX'"; - # permissions - say $out "Added new permission 'XXX'"; - # letters - say $out "Added new letter 'XXX' (TRANSPORT)"; + say $out "Added new system preference 'AutoCheckinAutoFill'"; }, }; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index db1dcabd01..2aae161c4b 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -77,6 +77,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AuthorityXSLTResultsDisplay','','','Enable XSL stylesheet control over authority results page display on intranet','Free'), ('AuthSuccessLog','0',NULL,'If enabled, log successful authentications','YesNo'), ('autoBarcode','OFF','incremental|annual|hbyymmincr|EAN13|OFF','Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB=Home Branch','Choice'), +('AutoCheckinAutoFill','0',NULL,'Automatically fill the next hold with an automatic check in.','YesNo'), ('autoControlNumber','OFF','biblionumber|OFF','Used to autogenerate a Control Number: biblionumber will be as biblionumber, OFF will leave the field as it is;','Choice'), ('AutoCreateAuthorities','0',NULL,'Automatically create authorities that do not exist when cataloging records.','YesNo'), ('AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice'), 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 c5308a8506..46d68ed50e 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 @@ -977,6 +977,12 @@ Circulation: homebranch: "item's home library" holdingbranch: "item's holding library" - "." + - + - pref: AutoCheckinAutoFill + choices: + 1: "Do" + 0: "Don't" + - allow holds to be automatically filled after being automatically checked in. Patron restrictions: - - pref: PatronRestrictionTypes @@ -1364,3 +1370,4 @@ Circulation: 1: Enable 0: Disable - "the curbside pickup module." + -- 2.30.2