|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2012 Ian Walls & ByWater Solutions |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 8 |
# terms of the GNU General Public License as published by the Free Software |
| 9 |
# Foundation; either version 2 of the License, or (at your option) any later |
| 10 |
# version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
|
| 20 |
#use strict; |
| 21 |
#use warnings; FIXME - Bug 2505 |
| 22 |
|
| 23 |
BEGIN { |
| 24 |
# find Koha's Perl modules |
| 25 |
# test carefully before changing this |
| 26 |
use FindBin; |
| 27 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
| 28 |
} |
| 29 |
|
| 30 |
use Getopt::Long; |
| 31 |
use C4::Context; |
| 32 |
use C4::Accounts qw(manualinvoice); |
| 33 |
|
| 34 |
my ($help, $verbose, $charge); |
| 35 |
my $count = 0; |
| 36 |
my $maxdelay = C4::Context->preference("ReservesMaxPickupDelay"); |
| 37 |
|
| 38 |
GetOptions( 'h|help' => \$help, |
| 39 |
'v|verbose' => \$verbose, |
| 40 |
'charge:f' => \$charge |
| 41 |
); |
| 42 |
my $usage = << 'ENDUSAGE'; |
| 43 |
|
| 44 |
This script expires all holds over ReservesMaxPickupDelay, and |
| 45 |
can charge the patron a fee for not picking up the material in |
| 46 |
time. |
| 47 |
|
| 48 |
This script has the following parameters : |
| 49 |
-h --help: this message |
| 50 |
-v --verbose |
| 51 |
-charge <<amount>>: charge the patron <<amount>> for not |
| 52 |
picking up the hold |
| 53 |
|
| 54 |
ENDUSAGE |
| 55 |
die $usage if $help; |
| 56 |
|
| 57 |
print sprintf "Charging patrons \$%.2f for each hold waiting too long...\n",$charge if (defined $verbose); |
| 58 |
|
| 59 |
my $dbh = C4::Context->dbh; |
| 60 |
my $sth = $dbh->prepare("SELECT * FROM reserves WHERE TO_DAYS( NOW() )-TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0"); |
| 61 |
$sth->execute($maxdelay); |
| 62 |
my $sth_update = $dbh->prepare("UPDATE reserves SET expirationdate = NOW() WHERE borrowernumber = ? and itemnumber = ?"); |
| 63 |
while (my $row = $sth->fetchrow_hashref ) { |
| 64 |
if ($charge) { |
| 65 |
manualinvoice($row->{'borrowernumber'}, $row->{'itemnumber'}, 'Hold waiting too long', 'F', $charge); |
| 66 |
} |
| 67 |
$sth_update->execute($row->{'borrowernumber'}, $row->{'itemnumber'}); |
| 68 |
$count++; |
| 69 |
} |
| 70 |
|
| 71 |
print "A total of $count holds expired\n" if (defined $verbose); |