[open-ils-commits] [GIT] Evergreen ILS branch rel_2_10 updated. 1421e7dc15ebdf946006bfadc924efb125a0d60b

Evergreen Git git at git.evergreen-ils.org
Tue Oct 25 16:29:06 EDT 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_10 has been updated
       via  1421e7dc15ebdf946006bfadc924efb125a0d60b (commit)
      from  17ddf95b1736f708bbf2bf1c4c50911142fbc151 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1421e7dc15ebdf946006bfadc924efb125a0d60b
Author: Bill Erickson <berickxx at gmail.com>
Date:   Thu Sep 15 15:13:47 2016 -0400

    LP#1282751 Credit card payment balance owed rounding fix
    
    Avoid using Perl's int() when summing owed/paid totals for display in
    the TPAC credit card payment form, since this can lead to rounding
    errors.
    
    A simple example of why we should not use int() when summing floating
    point numbers:
    
    perl -e 'print "no match\n" unless ((8.29 * 100) == int(8.29 * 100))';
    
    Furthermore, use the relatively new fpsum() utility function for summing
    floating point numbers so we can avoid having multiple versions of the
    summing logic floating (*cough*) around (*cough cough*).
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
index d2be12d..9896ff2 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
@@ -1947,8 +1947,8 @@ sub prepare_fines {
         }
     );
 
-    my @total_keys = qw/total_paid total_owed balance_owed/;
-    $self->ctx->{"fines"}->{@total_keys} = (0, 0, 0);
+    # Collect $$ amounts from each transaction for summing below.
+    my (@paid_amounts, @owed_amounts, @balance_amounts);
 
     while(my $resp = $req->recv) {
         my $mobts = $resp->content;
@@ -1960,10 +1960,9 @@ sub prepare_fines {
             $last_billing = pop(@billings);
         }
 
-        # XXX TODO confirm that the following, and the later division by 100.0
-        # to get a floating point representation once again, is sufficiently
-        # "money-safe" math.
-        $self->ctx->{"fines"}->{$_} += int($mobts->$_ * 100) for (@total_keys);
+        push(@paid_amounts, $mobts->total_paid);
+        push(@owed_amounts, $mobts->total_owed);
+        push(@balance_amounts, $mobts->balance_owed);
 
         my $marc_xml = undef;
         if ($mobts->xact_type eq 'reservation' and
@@ -1990,7 +1989,10 @@ sub prepare_fines {
 
     $cstore->kill_me;
 
-    $self->ctx->{"fines"}->{$_} /= 100.0 for (@total_keys);
+    $self->ctx->{"fines"}->{total_paid}   = $U->fpsum(@paid_amounts);
+    $self->ctx->{"fines"}->{total_owed}   = $U->fpsum(@owed_amounts);
+    $self->ctx->{"fines"}->{balance_owed} = $U->fpsum(@balance_amounts);
+
     return;
 }
 

-----------------------------------------------------------------------

Summary of changes:
 .../lib/OpenILS/WWW/EGCatLoader/Account.pm         |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list