X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=ff8226c8d606b40a45b9ceb708389424f2815c53;hp=175dbe890456a9ce8ed3da946266b9683ca153fd;hb=08b36523ebbf6e2995878f26bfac988f32f7a218;hpb=3eb093c100cd3cd156ae5ddb86180f4a83fc82df diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 175dbe890..ff8226c8d 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -659,17 +659,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 ) ";