From 8e1c822134fa0a136f3df30f7add6105ae0c2475 Mon Sep 17 00:00:00 2001 From: Sophie Meynieux Date: Wed, 1 Oct 2014 14:16:48 +0200 Subject: [PATCH] Bug 13018 : Static fine should be charged only once Test plan (see Bug 6858 for using staticfine.pl) : For a user (of a given category and library) with several overdues, launch the script : staticfines.pl --category CAT,AMOUNT --library LIB --delay DELAY Then, check that the user has been charged of AMOUNT if the due date of the most late item plus the delay is *before* today. One day later, re-execute the script with the same parameters and check that the fine has not been charged twice. Without patch, the fine is charged twice, with patch the user already charged is skipped (see output in debug mode) --- C4/Overdues.pm | 11 +++++++++-- misc/cronjobs/staticfines.pl | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 31314d6..185584f 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -655,9 +655,16 @@ sub GetFine { my $dbh = C4::Context->dbh(); my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines where accounttype like 'F%' - AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?|; + AND amountoutstanding > 0 AND borrowernumber=?|; + my @query_param; + push @query_param, $borrowernumber; + if (defined $itemnum ) + { + $query .= " AND itemnumber=?"; + push @query_param, $itemnum; + } my $sth = $dbh->prepare($query); - $sth->execute( $itemnum, $borrowernumber ); + $sth->execute( @query_param ); my $fine = $sth->fetchrow_hashref(); if ($fine->{fineamount}) { return $fine->{fineamount}; diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index 0d819a5..2520fc5 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -196,7 +196,7 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { $amount = $catamounts{$borrower->{'categorycode'}} if (defined $catamounts{$borrower->{'categorycode'}}); # We check if there is already a fine for the given borrower - my $fine = GetFine($data->[$i]->{'borrowernumber'}); + my $fine = GetFine(undef, $data->[$i]->{'borrowernumber'}); if ($fine > 0) { $debug and warn "There is already a fine for borrower " . $data->[$i]->{'borrowernumber'} . ". Nothing to do here. Skipping this borrower"; next; -- 1.9.1