use FS::cust_main;
&untaint_argv; #what it sounds like (eww)
-use vars qw($opt_d $opt_v $opt_p $opt_s $opt_y);
+use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y);
getopts("p:a:d:vsy:");
my $user = shift or die &usage;
0 < ( select count(*) from cust_bill
where cust_main.custnum = cust_bill.custnum
and 0 < charged
- - ( select sum(amount) from cust_bill_pay
- where cust_bill.invnum = cust_bill_pay.invnum )
- - ( select sum(amount) from cust_credit_bill
- where cust_bill.invnum = cust_credit_bill.invnum )
+ - coalesce(
+ ( select sum(amount) from cust_bill_pay
+ where cust_bill.invnum = cust_bill_pay.invnum )
+ ,0
+ )
+ - coalesce(
+ ( select sum(amount) from cust_credit_bill
+ where cust_bill.invnum = cust_credit_bill.invnum )
+ ,0
+ )
and 0 < ( select count(*) from part_bill_event
where payby = cust_main.payby
and ( disabled is null or disabled = '' )
)
END
-my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "$where_pkg OR $where_bill_event";
+my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "( $where_pkg OR $where_bill_event )";
my @cust_main;
if ( @ARGV ) {