Move outstanding_bills_for_circ to AppUtils
authorJeff Godin <jgodin@tadl.org>
Tue, 12 Jun 2012 15:38:07 +0000 (11:38 -0400)
committerJeff Godin <jgodin@tadl.org>
Tue, 12 Jun 2012 15:38:07 +0000 (11:38 -0400)
Move the outstanding_bills_for_circ sub to
OpenILS::Application::Apputils, since we intend to call it from at
least two different packages.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm

index a866508..70f9616 100644 (file)
@@ -1798,5 +1798,57 @@ sub create_circ_chain_summary {
     return $obj;
 }
 
+# -----------------------------------------------------------------
+# Given an editor and a circ, return a reference to an array of
+# billing objects which are outstanding (unpaid, not voided).
+# If a bill is partially paid, change the amount of the bill
+# to reflect the unpaid amount, not the original amount.
+# -----------------------------------------------------------------
+sub outstanding_bills_for_circ {
+    my ($self, $e, $circ) = @_;
+
+    # find all unvoided bills in order
+    my $bill_search = [
+        { xact => $circ->id, voided=>'f' },
+        { order_by => { mb => { billing_ts => { direction => 'asc' } } } },
+    ];
+
+    # find all unvoided payments in order
+    my $payment_search = [
+        { xact => $circ->id, voided=>'f' },
+        { order_by => { mp => { payment_ts => { direction => 'asc' } } } },
+    ];
+
+    my $bills = $e->search_money_billing($bill_search);
+
+    my $payments = $e->search_money_payment($payment_search);
+
+    # "Pay" the bills, removing fully paid bills and
+    # adjusting the amount for partially paid bills
+    map {
+            my $payment = $_;
+            my $paybal = $payment->amount;
+
+            while ($paybal > 0) {
+                    # get next billing
+                    my $bill = shift @{$bills};
+                    my $newbal = (($paybal*100) - ($bill->amount*100))/100;
+                    if ($newbal < 0) {
+                            $newbal = 0;
+                            my $new_bill_amount = (($bill->amount*100) - ($paybal*100))/100;
+                            $bill->amount($new_bill_amount);
+                            unshift(@{$bills}, $bill); # put the partially-paid bill back on top of the stack
+                    }
+
+                    $paybal = $newbal;
+
+            }
+
+    } @$payments;
+
+    return $bills;
+
+}
+
 1;
 
index f65f36f..2ffaa14 100644 (file)
@@ -31,7 +31,7 @@ sub forgive_overdues {
     $logger->info("attempting to forgive overdues on circ " . $circ->id . " with note " . $note);
 
     # get outstanding bills for the circ in question
-    my $bills = _outstanding_bills_for_circ($e, $circ);
+    my $bills = $U->outstanding_bills_for_circ($e, $circ);
  
     # Sum any outstanding overdue billings, stopping at the first non-overdue billing
 
@@ -163,56 +163,4 @@ sub create_bill {
        return undef;
 }
 
-# -----------------------------------------------------------------
-# Given an editor and a circ, return a reference to an array of
-# billing objects which are outstanding (unpaid, not voided).
-# If a bill is partially paid, change the amount of the bill
-# to reflect the unpaid amount, not the original amount.
-# -----------------------------------------------------------------
-sub _outstanding_bills_for_circ {
-    my ($e, $circ) = @_;
-
-    # find all unvoided bills in order
-    my $bill_search = [
-        { xact => $circ->id, voided=>'f' },
-        { order_by => { mb => { billing_ts => { direction => 'asc' } } } },
-    ];
-
-    # find all unvoided payments in order
-    my $payment_search = [
-        { xact => $circ->id, voided=>'f' },
-        { order_by => { mp => { payment_ts => { direction => 'asc' } } } },
-    ];
-
-    my $bills = $e->search_money_billing($bill_search);
-
-    my $payments = $e->search_money_payment($payment_search);
-
-    # "Pay" the bills, removing fully paid bills and
-    # adjusting the amount for partially paid bills
-    map {
-            my $payment = $_;
-            my $paybal = $payment->amount;
-
-            while ($paybal > 0) {
-                    # get next billing
-                    my $bill = shift @{$bills};
-                    my $newbal = (($paybal*100) - ($bill->amount*100))/100;
-                    if ($newbal < 0) {
-                            $newbal = 0;
-                            my $new_bill_amount = (($bill->amount*100) - ($paybal*100))/100;
-                            $bill->amount($new_bill_amount);
-                            unshift(@{$bills}, $bill); # put the partially-paid bill back on top of the stack
-                    }
-
-                    $paybal = $newbal;
-
-            }
-
-    } @$payments;
-
-    return $bills;
-
-}
-
 1;