Fix problem with payment search in CircCommon::bill_payment_map_for_xact.
authorJason Stephenson <jason@sigio.com>
Sat, 21 Dec 2013 14:21:40 +0000 (09:21 -0500)
committerKathy Lussier <klussier@masslnc.org>
Thu, 13 Feb 2014 05:38:44 +0000 (00:38 -0500)
Also rename some boolean variables so that their meaning is more clear.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm

index 361072e..22c259c 100644 (file)
@@ -367,12 +367,6 @@ sub bill_payment_map_for_xact {
         { order_by => { mb => { billing_ts => { direction => 'asc' } } } },
     ];
 
-    # find all unvoided payments in order
-    my $payment_search = [
-        { xact => $xact->id, voided=>'f' },
-        { order_by => { mp => { payment_ts => { direction => 'asc' } } } },
-    ];
-
     # At some point, we should get rid of the voided column on
     # money.payment and family.  It is not exposed in the client at
     # the moment, and should be replaced with a void_bill type.  The
@@ -401,18 +395,18 @@ sub bill_payment_map_for_xact {
         }
     } @$bills;
 
-    # Retrieve the payments.  Flesh voids do that we don't have to
-    # retrieve them later.
+    # Find all unvoided payments in order.  Flesh voids do that we
+    # don't have to retrieve them later.
     my $payments = $e->search_money_payment(
         [
-            $payment_search,
+            { xact => $xact->id, voided=>'f' },
             {
-                flesh=>1,
-                flesh_fields => {
-                    mp => ['void_payment']
-                }
+                order_by => { mp => { payment_ts => { direction => 'asc' } } },
+                flesh => 1,
+                flesh_fields => { mp => ['void_payment'] }
             }
-        ]);
+        ]
+    );
 
     # If there were no payments, then we just return the bills.
     return \@entries unless ($payments && @$payments);
@@ -551,14 +545,14 @@ sub real_void_bills {
 
         # Retrieve settings based on transaction location and copy
         # location if we have a circulation.
-        my ($neg_balance_default, $neg_balance_overdues,
-            $neg_balance_lost, $neg_balance_interval_default,
+        my ($prohibit_neg_balance_default, $prohibit_neg_balance_overdues,
+            $prohibit_neg_balance_lost, $neg_balance_interval_default,
             $neg_balance_interval_overdues, $neg_balance_interval_lost);
         if ($circ) {
             # defaults and overdue settings come from transaction org unit.
-            $neg_balance_default = $U->ou_ancestor_setting(
+            $prohibit_neg_balance_default = $U->ou_ancestor_setting(
                 $circ->circ_lib(), 'bill.prohibit_negative_balance_default');
-            $neg_balance_overdues = (
+            $prohibit_neg_balance_overdues = (
                 $U->ou_ancestor_setting($circ->circ_lib(), 'bill.prohibit_negative_balance_on_overdues')
                 ||
                 $U->ou_ancestor_setting($circ->circ_lib(), 'bill.prohibit_netgative_balance_default')
@@ -571,7 +565,7 @@ sub real_void_bills {
                 $U->ou_ancestor_setting($circ->circ_lib(), 'bill.negative_balance_interval_default')
             );
             # settings for lost come from copy circlib.
-            $neg_balance_lost = (
+            $prohibit_neg_balance_lost = (
                 $U->ou_ancestor_setting($copy->circ_lib(), 'bill.prohibit_negative_balance_on_lost')
                 ||
                 $U->ou_ancestor_setting($copy->circ_lib(), 'bill.prohibit_negative_balance_default')
@@ -584,7 +578,7 @@ sub real_void_bills {
         } else {
             # We only care about defaults, and they come from the
             # billing location.
-            $neg_balance_default = $U->ou_ancestor_setting(
+            $prohibit_neg_balance_default = $U->ou_ancestor_setting(
                 $grocery->billing_location(), 'bill.prohibit_negative_balance_default');
             $neg_balance_interval_default = $U->ou_ancestor_setting(
             $grocery->billing_location(), 'bill.negative_balance_interval_default');
@@ -631,22 +625,22 @@ sub real_void_bills {
                     if ($btype == 1) {
                         # Overdues
                         $amount_to_void = $xact_total unless(_check_payment_interval($bpentry, $neg_balance_interval_overdues));
-                        $amount_to_void = $xact_total if ($U->is_true($neg_balance_overdues));
+                        $amount_to_void = $xact_total if ($U->is_true($prohibit_neg_balance_overdues));
                     } elsif ($btype == 3 || $btype == 10) {
                         # Lost or Long Overdue
                         $amount_to_void = $xact_total unless(_check_payment_interval($bpentry, $neg_balance_interval_lost));
-                        $amount_to_void = $xact_total if ($U->is_true($neg_balance_lost));
+                        $amount_to_void = $xact_total if ($U->is_true($prohibit_neg_balance_lost));
                     } else {
                         # Any other bill that we're trying to void.
                         $amount_to_void = $xact_total unless(_check_payment_interval($bpentry, $neg_balance_interval_default));
-                        $amount_to_void = $xact_total if ($U->is_true($neg_balance_default));
+                        $amount_to_void = $xact_total if ($U->is_true($prohibit_neg_balance_default));
                     }
                 }
             } else {
                 # Grocery bills are simple by comparison.
                 if ($amount_to_void > $xact_total) {
                     $amount_to_void = $xact_total unless(_check_payment_interval($bpentry, $neg_balance_interval_default));
-                    $amount_to_void = $xact_total if ($U->is_true($neg_balance_default));
+                    $amount_to_void = $xact_total if ($U->is_true($prohibit_neg_balance_default));
                 }
             }