{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');