Bug 6987 Make return from Overdues::GetFine consistent
authorColin Campbell <colin.campbell@ptfs-europe.com>
Fri, 7 Oct 2011 12:19:06 +0000 (13:19 +0100)
committerPaul Poulain <paul.poulain@biblibre.com>
Thu, 8 Dec 2011 10:19:10 +0000 (11:19 +0100)
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 <sophie.meynieux@biblibre.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
C4/Overdues.pm

index 4897b41..660e10b 100644 (file)
@@ -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;
 }