X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=f9185cc4bb6ee2099e0c0372479d326bf28a3045;hb=81ffc8da62da1cc5a01ad92c7c4489e37b35f088;hp=69bcd87176c916d5f83264f648277bcd0e9cab0c;hpb=b7a86943a8af02f06ffb6ae9f05fb12bbb8afe85;p=freeside.git diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 69bcd8717..f9185cc4b 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -657,17 +657,23 @@ Returns an SQL fragment to retreive the unapplied amount. =cut sub unapplied_sql { - #my $class = shift; + my ($class, $start, $end) = shift; + my $bill_start = $start ? "AND cust_bill_pay._date <= $start" : ''; + my $bill_end = $end ? "AND cust_bill_pay._date > $end" : ''; + my $refund_start = $start ? "AND cust_pay_refund._date <= $start" : ''; + my $refund_end = $end ? "AND cust_pay_refund._date > $end" : ''; "paid - COALESCE( ( SELECT SUM(amount) FROM cust_bill_pay - WHERE cust_pay.paynum = cust_bill_pay.paynum ) + WHERE cust_pay.paynum = cust_bill_pay.paynum + $bill_start $bill_end ) ,0 ) - COALESCE( ( SELECT SUM(amount) FROM cust_pay_refund - WHERE cust_pay.paynum = cust_pay_refund.paynum ) + WHERE cust_pay.paynum = cust_pay_refund.paynum + $refund_start $refund_end ) ,0 ) ";