Fixes for SIP2 Fee Payment.
authorJason Stephenson <jstephenson@mvlc.org>
Thu, 22 Sep 2011 16:52:08 +0000 (12:52 -0400)
committerDan Scott <dscott@laurentian.ca>
Fri, 14 Oct 2011 01:01:45 +0000 (21:01 -0400)
Skip negative or zero bill balance when paying multiple bills.

Log amount paid, bill id, balance, and amount remaining when paying
multiple bills.

Use sprintf("%.2f") to avoid floating point errors.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/FeePayment.pm

index 28de0dc..d0b3fa4 100644 (file)
@@ -126,6 +126,9 @@ sub do_fee_payment {
             foreach my $bill (@{$results}) {
                 my $payment;
                 syslog('LOG_INFO', 'OILS: bill '. $bill->id . ' amount ' . $bill->balance_owed);
+                # Skip negative or zero-balance bills. (Not that I've
+                # ever seen any.)
+                next if ($bill->balance_owed <= 0);
                 if ($bill->balance_owed >= $amount_paid) {
                     # We owe as much as or more than we have money
                     # left, so pay what we have left.
@@ -139,10 +142,13 @@ sub do_fee_payment {
                 }
                 # Add the payment to our array.
                 push(@payments, [$bill->id, $payment]);
+                # Attempt to round $amount_paid to avoid floating point error.
+                $amount_paid = sprintf("%.2f", $amount_paid);
+                syslog('LOG_INFO', "OILS: paid $payment on " . $bill->id . " with balance " . $bill->balance_owed . " and $amount_paid remaining");
                 # Leave if we ran out of money.
-                last if ($amount_paid == 0);
+                last if ($amount_paid == 0.00);
             }
-            if (@payments && $amount_paid == 0) {
+            if (@payments && $amount_paid == 0.00) {
                 # pay the bills with a reference to our payments
                 # array.
                 my $resp = $self->pay_bills(\@payments);