From 05864978c5ca3495db386c3ea6527b11d96ef25e 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. Signed-off-by: Galen Charlton --- C4/Members.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 8467813cf4..5dab0c0a38 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); } -- 2.11.0