From 0717f8300a140789bb86b158966e6dadd6cf9830 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 23 Feb 2012 12:09:06 -0500 Subject: [PATCH] Bug 7408 - Expire holds that have been waiting too long If the new syspref ExpireReservesMaxPickUpDelay is enabled, this will cancel holds that have been waiting for longer than the number of days specified in the syspref ReservesMaxPickupDelay. If ExpireReservesMaxPickUpDelayCharge is set, the borrower charged the fee set therein. Signed-off-by: Ian Walls Altered circulation.pref to include currency class and [% local_currency %] param --- C4/Reserves.pm | 48 ++++++++++++------- installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 8 ++++ .../admin/preferences/circulation.pref | 11 +++++ 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index d2af1c5ac6..44a82bd3b3 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -861,6 +861,7 @@ Cancels all reserves with an expiration date from before today. sub CancelExpiredReserves { + # Cancel reserves that have passed their expiration date. my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( " SELECT * FROM reserves WHERE DATE(expirationdate) < DATE( CURDATE() ) @@ -872,6 +873,24 @@ sub CancelExpiredReserves { CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} ); } + # Cancel reserves that have been waiting too long + if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) { + my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); + my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge"); + + my $query = "SELECT * FROM reserves WHERE TO_DAYS( NOW() ) - TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0"; + $sth = $dbh->prepare( $query ); + $sth->execute( $max_pickup_delay ); + + while (my $res = $sth->fetchrow_hashref ) { + if ( $charge ) { + manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge); + } + + CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} ); + } + } + } =head2 CancelReserve @@ -1138,13 +1157,9 @@ sub ModReserveStatus { #first : check if we have a reservation for this item . my ($itemnumber, $newstatus) = @_; - my $dbh = C4::Context->dbh; - my $query = " UPDATE reserves - SET found=?,waitingdate = now() - WHERE itemnumber=? - AND found IS NULL - AND priority = 0 - "; + my $dbh = C4::Context->dbh; + + my $query = "UPDATE reserves SET found = ?, waitingdate = NOW() WHERE itemnumber = ? AND found IS NULL AND priority = 0"; my $sth_set = $dbh->prepare($query); $sth_set->execute( $newstatus, $itemnumber ); @@ -1197,15 +1212,15 @@ sub ModReserveAffect { } else { # affect the reserve to Waiting as well. - $query = " - UPDATE reserves - SET priority = 0, - found = 'W', - waitingdate=now(), - itemnumber = ? - WHERE borrowernumber = ? - AND biblionumber = ? - "; + $query = " + UPDATE reserves + SET priority = 0, + found = 'W', + waitingdate = NOW(), + itemnumber = ? + WHERE borrowernumber = ? + AND biblionumber = ? + "; } $sth = $dbh->prepare($query); $sth->execute( $itemnumber, $borrowernumber,$biblionumber); @@ -1908,7 +1923,6 @@ sub MergeHolds { } } - =head2 ReserveSlip ReserveSlip($branchcode, $borrowernumber, $biblionumber) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 47b2483575..d16ff81241 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -346,3 +346,5 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerRelink',1,'If ON the authority linker will relink headings that have previously been linked every time it runs.',NULL,'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerKeepStale',0,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.',NULL,'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogModuleRelink',0,'If OFF the linker will never replace the authids that are set in the cataloging module.',NULL,'YesNo'); +INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('ExpireReservesMaxPickUpDelay', '0', '', 'Enabling this allows holds to expire automatically if they have not been picked by within the time period specified in ReservesMaxPickUpDelay', 'YesNo'); +INSERT INTO systempreferences` (variable,value,options,explanation,type) VALUES ('ExpireReservesMaxPickUpDelayCharge', '0', NULL , 'If ExpireReservesMaxPickUpDelay is enabled, and this field has a non-zero value, than a borrower whose waiting hold has expired will be charged this amount.', 'free') diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 06eded1300..2a7a1ac7d1 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4884,6 +4884,14 @@ Date due: <>
SetVersion($DBversion); } +$DBversion = "3.07.00.024"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO systempreferences` (variable,value,options,explanation,type) VALUES ('ExpireReservesMaxPickUpDelayCharge', '0', NULL , 'If ExpireReservesMaxPickUpDelay is enabled, and this field has a non-zero value, than a borrower whose waiting hold has expired will be charged this amount.', 'free')"); + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('ExpireReservesMaxPickUpDelay', '0', '', 'Enabling this allows holds to expire automatically if they have not been picked by within the time period specified in ReservesMaxPickUpDelay', 'YesNo')"); + print "Upgrade to $DBversion done (Added system preference ExpireReservesMaxPickUpDelay, system preference ExpireReservesMaxPickUpDelayCharge, add reseves.charge_if_expired)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) 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 b020a9235a..64fe299d41 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 @@ -283,6 +283,17 @@ Circulation: - pref: ReservesMaxPickUpDelay class: integer - days. + - + - pref: ExpireReservesMaxPickUpDelay + choices: + yes: Allow + no: "Don't allow" + - "holds to expire automatically if they have not been picked by within the time period specified in ReservesMaxPickUpDelay" + - + - If using ExpireReservesMaxPickUpDelay, charge a borrower who allows his or her waiting hold to expire a fee of + - pref: ExpireReservesMaxPickUpDelayCharge + class: currency + - [% local_currency %]. - - Satisfy holds from the libraries - pref: StaticHoldsQueueWeight -- 2.39.5