X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_refund.pm;h=39603701f215fd428f81859be301f3b3c45f1f40;hb=995a145c931164347683071c95c6754379d36604;hp=e7c5a82154c7ccae6706a038d3fb59e2f8000e45;hpb=624b2d44625f69d71175c3348cae635d580c890b;p=freeside.git diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index e7c5a8215..39603701f 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -343,17 +343,23 @@ Returns an SQL fragment to retreive the unapplied amount. =cut sub unapplied_sql { - #my $class = shift; + my ($class, $start, $end) = @_; + my $credit_start = $start ? "AND cust_credit_refund._date <= $start" : ''; + my $credit_end = $end ? "AND cust_credit_refund._date > $end" : ''; + my $pay_start = $start ? "AND cust_pay_refund._date <= $start" : ''; + my $pay_end = $end ? "AND cust_pay_refund._date > $end" : ''; "refund - COALESCE( ( SELECT SUM(amount) FROM cust_credit_refund - WHERE cust_refund.refundnum = cust_credit_refund.refundnum ) + WHERE cust_refund.refundnum = cust_credit_refund.refundnum + $credit_start $credit_end ) ,0 ) - COALESCE( ( SELECT SUM(amount) FROM cust_pay_refund - WHERE cust_refund.refundnum = cust_pay_refund.refundnum ) + WHERE cust_refund.refundnum = cust_pay_refund.refundnum + $pay_start $pay_end ) ,0 ) ";