From 40ece625bba3ac1733bef69ac33871d16aa5834a 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) Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer Without the patch, the fine will be applied every time the script is run. With the patch the fine will only be applied once. Passes tests and QA script. Signed-off-by: Tomas Cohen Arazi --- 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 31314d6849..185584fa80 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 0d819a591c..2520fc5841 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; -- 2.39.5