Lines 21-34
Link Here
|
21 |
#use warnings; FIXME - Bug 2505 |
21 |
#use warnings; FIXME - Bug 2505 |
22 |
|
22 |
|
23 |
BEGIN { |
23 |
BEGIN { |
|
|
24 |
|
24 |
# find Koha's Perl modules |
25 |
# find Koha's Perl modules |
25 |
# test carefully before changing this |
26 |
# test carefully before changing this |
26 |
use FindBin; |
27 |
use FindBin; |
27 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
28 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
28 |
} |
29 |
} |
29 |
|
30 |
|
30 |
# cancel all expired hold requests |
31 |
use Getopt::Long; |
31 |
|
32 |
|
|
|
33 |
use C4::Context; |
34 |
use C4::Accounts qw(manualinvoice); |
32 |
use C4::Reserves; |
35 |
use C4::Reserves; |
33 |
|
36 |
|
|
|
37 |
my ( $help, $verbose, $charge, $cancelwaiting ); |
38 |
my $count = 0; |
39 |
my $maxdelay = C4::Context->preference("ReservesMaxPickupDelay"); |
40 |
|
41 |
GetOptions( |
42 |
'h|help' => \$help, |
43 |
'v|verbose' => \$verbose, |
44 |
'cancelwaiting' => \$cancelwaiting, |
45 |
'charge:f' => \$charge, |
46 |
); |
47 |
|
48 |
my $usage = << 'ENDUSAGE'; |
49 |
|
50 |
This script cancels expired holds and optionally expires all waiting |
51 |
holds over ReservesMaxPickupDelay, and can charge the patron a fee |
52 |
for not picking up the material in time. |
53 |
|
54 |
This script has the following parameters : |
55 |
-h --help: this message |
56 |
-v --verbose |
57 |
--cancelwaiting |
58 |
--charge <<amount>>: charge the patron <<amount>> for not |
59 |
picking up the waiting hold on time. |
60 |
|
61 |
ENDUSAGE |
62 |
die $usage if $help; |
63 |
|
64 |
print sprintf "Charging patrons \$%.2f for each hold waiting too long...\n", |
65 |
$charge |
66 |
if ( defined $verbose ); |
67 |
|
68 |
if ( defined $cancelwaiting ) { |
69 |
my $dbh = C4::Context->dbh; |
70 |
my $sql = "SELECT * FROM reserves WHERE TO_DAYS( NOW() )-TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0"; |
71 |
my $sth = $dbh->prepare($sql); |
72 |
$sth->execute($maxdelay); |
73 |
|
74 |
while ( my $row = $sth->fetchrow_hashref ) { |
75 |
manualinvoice( $row->{'borrowernumber'}, $row->{'itemnumber'}, 'Hold waiting too long', 'F', $charge ) if ($charge); |
76 |
|
77 |
CancelReserve( $row->{'biblionumber'}, '', $row->{'borrowernumber'} ); |
78 |
} |
79 |
|
80 |
print "A total of $count waiting holds canceled\n" if ( defined $verbose ); |
81 |
} |
82 |
|
83 |
# cancel all expired hold requests |
34 |
CancelExpiredReserves(); |
84 |
CancelExpiredReserves(); |
35 |
- |
85 |
print "All expired holds canceled\n" if ( defined $verbose ); |
|
|
86 |
|