[Koha-patches] [PATCH] bug 2126: reduce round-off errors in fine balance

Galen Charlton galen.charlton at liblime.com
Thu Feb 12 21:20:43 CET 2009


If a patron has a number of fine transactions, the
total could be wrong.  This is particularly noticeable
when a patron has a zero balance, as summing a group
of floating point values derived from decimal(6,2) columns
can result a scalar value that is not zero.

Koha really should be using integral arithmetic
or appropriate accounting modules to do fine and
acquisitions calculations.  Using floating point scalars
for monetary amounts is always a mistake.

This patch also prevents an account maintenance
fee from being applied when renewing a patron if the
amount would be 0.
---
 C4/Members.pm |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/C4/Members.pm b/C4/Members.pm
index 8467813..5dab0c0 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -1180,8 +1180,9 @@ sub GetMemberAccountRecords {
 		$data->{biblionumber} = $biblio->{biblionumber};
         $acctlines[$numlines] = $data;
         $numlines++;
-        $total += $data->{'amountoutstanding'};
+        $total += int(100 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
     }
+    $total /= 100;
     $sth->finish;
     return ( $total, \@acctlines,$numlines);
 }
@@ -1222,8 +1223,9 @@ sub GetBorNotifyAcctRecord {
     while ( my $data = $sth->fetchrow_hashref ) {
         $acctlines[$numlines] = $data;
         $numlines++;
-        $total += $data->{'amountoutstanding'};
+        $total += int(100 * $data->{'amountoutstanding'});
     }
+    $total /= 100;
     $sth->finish;
     return ( $total, \@acctlines, $numlines );
 }
@@ -1742,7 +1744,7 @@ EOF
     $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
     $sth->execute($borrower->{'categorycode'});
     my ($enrolmentfee) = $sth->fetchrow;
-    if ($enrolmentfee) {
+    if ($enrolmentfee && $enrolmentfee > 0) {
         # insert fee in patron debts
         manualinvoice($borrower->{'borrowernumber'}, '', '', 'A', $enrolmentfee);
     }
-- 
1.5.5.GIT




More information about the Koha-patches mailing list