Addition to bugfix 1666: correcting rounding errors for negative values
authorG. Richardson <information@lx-office-hosting.de>
Fri, 27 May 2011 11:10:35 +0000 (13:10 +0200)
committerG. Richardson <information@lx-office-hosting.de>
Fri, 27 May 2011 11:10:35 +0000 (13:10 +0200)
make sure rounding error is caught if invoicediff and expensediff both have negative values

see also commit cc47124952e133ee4edbc116d927b90040dc8a05

SL/IR.pm

index 602ffc3..86b1323 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -400,12 +400,10 @@ sub post_invoice {
     # shall receive the total rounding error, and the next time it is rounded
     # the 1 cent correction will be introduced.
 
-    my $total_rounding_diff = $invoicediff+$expensediff;
-
     $form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $invoicediff if $lastinventoryaccno;
     $form->{amount}{ $form->{id} }{$lastexpenseaccno}   -= $expensediff if $lastexpenseaccno;
 
-    if ( ($expensediff+$invoicediff) >= 0.005 and $expensediff < 0.005 and $invoicediff < 0.005 ) {
+    if ( (abs($expensediff)+abs($invoicediff)) >= 0.005 and abs($expensediff) < 0.005 and abs($invoicediff) < 0.005 ) {
 
       # in total the rounding error adds up to 1 cent effectively, correct the
       # larger of the two numbers