From 5bb0afe16968492a8a191858639631f32c6d7239 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 (cherry picked from commit d39262e61d972dfc6bf2fbe3f5d19969e352b34c) Signed-off-by: Chris Nighswonger --- C4/Overdues.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 9f4b22f920..898d5385e5 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -644,13 +644,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