From d39262e61d972dfc6bf2fbe3f5d19969e352b34c Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Fri, 7 Oct 2011 13:19:06 +0100 Subject: [PATCH] Bug 6987 Make return from Overdues::GetFine consistent If there is not a fine amount return zero not undefined or other undefined behaviour Use more meaningful var names for readability Signed-off-by: Sophie Meynieux Signed-off-by: Paul Poulain --- C4/Overdues.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 4897b416b1..660e10b830 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -643,13 +643,16 @@ C<$borrowernumber> is the borrowernumber sub GetFine { my ( $itemnum, $borrowernumber ) = @_; my $dbh = C4::Context->dbh(); - my $query = "SELECT sum(amountoutstanding) FROM accountlines - where accounttype like 'F%' - AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?"; + my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines + where accounttype like 'F%' + AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?|; my $sth = $dbh->prepare($query); $sth->execute( $itemnum, $borrowernumber ); - my $data = $sth->fetchrow_hashref(); - return ( $data->{'sum(amountoutstanding)'} ); + my $fine = $sth->fetchrow_hashref(); + if ($fine->{fineamount}) { + return $fine->{fineamount}; + } + return 0; } -- 2.39.5