From 54b489ada679e84253c8a1b7623b354e334e148f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 23 Feb 2012 14:02:06 -0500 Subject: [PATCH] Bug 7408 - Expire holds that have been waiting too long Modification to cancel_expired_holds.pl. Gives the option to have any waiting holds past ReservesMaxPickupDelay automatically canceled, with the option of charging a fee. --- misc/cronjobs/holds/cancel_expired_holds.pl | 54 ++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 1 deletions(-) diff --git a/misc/cronjobs/holds/cancel_expired_holds.pl b/misc/cronjobs/holds/cancel_expired_holds.pl index 70a2f59..ddb637b 100755 --- a/misc/cronjobs/holds/cancel_expired_holds.pl +++ b/misc/cronjobs/holds/cancel_expired_holds.pl @@ -21,14 +21,66 @@ #use warnings; FIXME - Bug 2505 BEGIN { + # find Koha's Perl modules # test carefully before changing this use FindBin; eval { require "$FindBin::Bin/../kohalib.pl" }; } -# cancel all expired hold requests +use Getopt::Long; +use C4::Context; +use C4::Accounts qw(manualinvoice); use C4::Reserves; +my ( $help, $verbose, $charge, $cancelwaiting ); +my $count = 0; +my $maxdelay = C4::Context->preference("ReservesMaxPickupDelay"); + +GetOptions( + 'h|help' => \$help, + 'v|verbose' => \$verbose, + 'cancelwaiting' => \$cancelwaiting, + 'charge:f' => \$charge, +); + +my $usage = << 'ENDUSAGE'; + +This script cancels expired holds and optionally expires all waiting +holds over ReservesMaxPickupDelay, and can charge the patron a fee +for not picking up the material in time. + +This script has the following parameters : + -h --help: this message + -v --verbose + --cancelwaiting + --charge <>: charge the patron <> for not + picking up the waiting hold on time. + +ENDUSAGE +die $usage if $help; + +print sprintf "Charging patrons \$%.2f for each hold waiting too long...\n", + $charge + if ( defined $verbose ); + +if ( defined $cancelwaiting ) { + my $dbh = C4::Context->dbh; + my $sql = "SELECT * FROM reserves WHERE TO_DAYS( NOW() )-TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0"; + my $sth = $dbh->prepare($sql); + $sth->execute($maxdelay); + + while ( my $row = $sth->fetchrow_hashref ) { + manualinvoice( $row->{'borrowernumber'}, $row->{'itemnumber'}, 'Hold waiting too long', 'F', $charge ) if ($charge); + + CancelReserve( $row->{'biblionumber'}, '', $row->{'borrowernumber'} ); + } + + print "A total of $count waiting holds canceled\n" if ( defined $verbose ); +} + +# cancel all expired hold requests CancelExpiredReserves(); +print "All expired holds canceled\n" if ( defined $verbose ); + -- 1.7.2.5