From 877dc53206468a62c83a8f57d8932e7943f70ab3 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 12 Feb 2009 14:20:43 -0600 Subject: [PATCH] bug 2126: reduce round-off errors in fine balance 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 file changed, 5 insertions(+), 3 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 54d623c14a..0f6d2e7f4f 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1169,8 +1169,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); } @@ -1211,8 +1212,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 ); } @@ -1732,7 +1734,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); } -- 2.39.5