LP 1198465: Delay creation of bill map for special bill handling
authorDan Wells <dbw2@calvin.edu>
Tue, 1 Apr 2014 19:13:00 +0000 (15:13 -0400)
committerBen Shum <bshum@biblio.org>
Tue, 28 Jul 2015 20:24:49 +0000 (16:24 -0400)
We were making the map, then deciding whether we wanted to void or
adjust.  Since we only want the map if we adjust (and it creates havoc
when voiding), let's just get the bill IDs, then let the adjustment
code create the map it needs.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm

index faa6651..20ff28d 100644 (file)
@@ -142,35 +142,33 @@ sub void_lost {
 sub void_or_zero_bills_of_type {
     my ($class, $e, $circ, $copy, $btype, $for_note) = @_;
 
-    # Get a bill payment map.
-    my $bpmap = $class->bill_payment_map_for_xact($e, $circ);
-    if ($bpmap && @$bpmap) {
-        # Filter out the unvoided bills of the type we're looking for:
-        my @bills = map {$_->{bill}} grep { $_->{bill}->btype() == $btype && $_->{bill_amount} > $_->{void_amount} } @$bpmap;
-        if (@bills) {
-            # settings for lost come from copy circlib.
-            my $prohibit_neg_balance_lost = (
-                $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.prohibit_negative_balance_on_lost')
-                ||
-                $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.prohibit_negative_balance_default')
-            );
-            my $neg_balance_interval_lost = (
-                $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.negative_balance_interval_on_lost')
-                ||
-                $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.negative_balance_interval_default')
-            );
-            my $result;
-            if (
-                $U->is_true($prohibit_neg_balance_lost)
-                and !_has_refundable_payments($e, $circ->id, $neg_balance_interval_lost)
-            ) {
-                $result = $class->adjust_bills_to_zero($e, \@bills, "System: ADJUSTED $for_note");
-            } else {
-                $result = $class->void_bills($e, \@bills, "System: VOIDED $for_note");
-            }
-            if (ref($result)) {
-                return $result;
-            }
+    my $billids = $e->search_money_billing(
+        {xact => $circ->id(), btype => $btype},
+        {idlist=>1}
+    );
+    if ($billids && @$billids) {
+        # settings for lost come from copy circlib.
+        my $prohibit_neg_balance_lost = (
+            $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.prohibit_negative_balance_on_lost')
+            ||
+            $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.prohibit_negative_balance_default')
+        );
+        my $neg_balance_interval_lost = (
+            $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.negative_balance_interval_on_lost')
+            ||
+            $U->ou_ancestor_setting_value($copy->circ_lib(), 'bill.negative_balance_interval_default')
+        );
+        my $result;
+        if (
+            $U->is_true($prohibit_neg_balance_lost)
+            and !_has_refundable_payments($e, $circ->id, $neg_balance_interval_lost)
+        ) {
+            $result = $class->adjust_bills_to_zero($e, $billids, "System: ADJUSTED $for_note");
+        } else {
+            $result = $class->void_bills($e, $billids, "System: VOIDED $for_note");
+        }
+        if (ref($result)) {
+            return $result;
         }
     }