@@ -, +, @@ --- C4/Reserves.pm | 47 +++++++++++++------- installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 14 ++++++ .../en/modules/admin/preferences/circulation.pref | 10 ++++ 4 files changed, 57 insertions(+), 16 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -868,6 +868,10 @@ sub CancelExpiredReserves { $sth->execute(); while ( my $res = $sth->fetchrow_hashref() ) { + if ( $res->{'found'} eq 'W' && C4::Context->preference("ExpireReservesMaxPickUpDelayCharge") ) { + manualinvoice( $res->{'borrowernumber', undef, "Hold waiting too long Fine", 'F', C4::Context->preference("ExpireReservesMaxPickUpDelayCharge"), undef ); + } + CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} ); } @@ -1137,13 +1141,11 @@ 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 $expire_sql = _GetExpireResevesSQL(); + + my $query = "UPDATE reserves SET found = ?, waitingdate = NOW()$expire_sql WHERE itemnumber = ? AND found IS NULL AND priority = 0"; my $sth_set = $dbh->prepare($query); $sth_set->execute( $newstatus, $itemnumber ); @@ -1196,15 +1198,18 @@ 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 = ? - "; + my $expire_sql = _GetExpireResevesSQL(); + + $query = " + UPDATE reserves + SET priority = 0, + found = 'W', + waitingdate = NOW(), + itemnumber = ? + $expire_sql + WHERE borrowernumber = ? + AND biblionumber = ? + "; } $sth = $dbh->prepare($query); $sth->execute( $itemnumber, $borrowernumber,$biblionumber); @@ -1907,6 +1912,16 @@ sub MergeHolds { } } +sub _GetExpireResevesSQL { + my $sql = ''; + if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) { + my $days_until_expiration = C4::Context->preference("ReservesMaxPickUpDelay"); + $sql = ", expirationdate = DATE( DATE_ADD( NOW(), INTERVAL $days_until_expiration DAY ) )"; + } + + return $sql; +} + =head1 AUTHOR --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -336,3 +336,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('BorrowerRenewalPeriodBase', 'now', 'Set whether the borrower renewal date should be counted from the dateexpiry or from the current date ','dateexpiry|now','Choice'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('AllowItemsOnHoldCheckout',0,'Do not generate RESERVE_WAITING and RESERVED warning when checking out items reserved to someone else. This allows self checkouts for those items.','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacExportOptions','bibtex|dc|marcxml|marc8|utf8|marcstd|mods|ris','Define export options available on OPAC detail page.','','free'); +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') --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -4712,6 +4712,20 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $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)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.07.00.XXX"; +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')"); + print "Upgrade to $DBversion done (Added system preference ExpireReservesMaxPickUpDelayCharge, add reseves.charge_if_expired)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -279,6 +279,16 @@ Circulation: 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: integer + - - Satisfy holds from the libraries - pref: StaticHoldsQueueWeight class: multi --