Collections user balance summary fails on no xacts
authorBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 20:27:37 +0000 (16:27 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 20:27:37 +0000 (16:27 -0400)
If the user has no open transactions, the collections API call
open-ils.collections.user_balance_summary.generate would fail
mid-processing, producing invalid XML output.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm

index 8d61327..550c75d 100644 (file)
@@ -936,19 +936,24 @@ sub user_balance_summary {
             {idlist => 1}
         );
 
-        # get the sum owed an all transactions
-        my $balance = $e->json_query({
-            select => {mbts => [
-                {   column => 'balance_owed',
-                    transform => 'sum',
-                    aggregate => 1
-                }
-            ]},
-            from => 'mbts',
-            where => {id => [@$circ_ids, @$groc_ids, @$res_ids]}
-        })->[0];
+        my $balance = '0';
+
+        if (@$circ_ids or @$groc_ids or @$res_ids) {
 
-        $balance = $balance ? $balance->{balance_owed} : '0';
+            # get the sum owed an all transactions
+            my $balance_obj = $e->json_query({
+                select => {mbts => [
+                    {   column => 'balance_owed',
+                        transform => 'sum',
+                        aggregate => 1
+                    }
+                ]},
+                from => 'mbts',
+                where => {id => [@$circ_ids, @$groc_ids, @$res_ids]}
+            })->[0];
+    
+            $balance = $balance_obj ? $balance_obj->{balance_owed} : '0';
+        }
 
         my $xacts_node = $user_doc->createElement('Transactions');
         my $balance_node = $user_doc->createElement('BalanceOwed');