From 33541201a5c0b477c52bee5e3fc62bcbbd6f59eb Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 6 Aug 2013 16:27:37 -0400 Subject: [PATCH] Collections user balance summary fails on no xacts 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 --- .../lib/OpenILS/Application/Collections.pm | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm index 8d61327174..550c75da56 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm @@ -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'); -- 2.11.0