[freeside-commits] freeside/FS/FS cust_main.pm, 1.505, 1.506 cust_bill.pm, 1.280, 1.281 cust_pay.pm, 1.75, 1.76 cust_credit.pm, 1.41, 1.42 cust_refund.pm, 1.34, 1.35
Mark Wells
mark at wavetail.420.am
Wed May 19 18:33:10 PDT 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv8034/FS/FS
Modified Files:
cust_main.pm cust_bill.pm cust_pay.pm cust_credit.pm
cust_refund.pm
Log Message:
RT#7266: aging report "as of" date now limits applied payments
Index: cust_pay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay.pm,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -w -d -r1.75 -r1.76
--- cust_pay.pm 29 Mar 2010 00:38:04 -0000 1.75
+++ cust_pay.pm 20 May 2010 01:33:07 -0000 1.76
@@ -659,17 +659,23 @@
=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
)
";
Index: cust_refund.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_refund.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -w -d -r1.34 -r1.35
--- cust_refund.pm 29 Mar 2010 00:23:07 -0000 1.34
+++ cust_refund.pm 20 May 2010 01:33:07 -0000 1.35
@@ -343,17 +343,23 @@
=cut
sub unapplied_sql {
- #my $class = shift;
+ my ($class, $start, $end) = shift;
+ 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
)
";
Index: cust_credit.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_credit.pm,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -w -d -r1.41 -r1.42
--- cust_credit.pm 30 Mar 2010 12:07:48 -0000 1.41
+++ cust_credit.pm 20 May 2010 01:33:07 -0000 1.42
@@ -565,17 +565,24 @@
=cut
sub unapplied_sql {
- #my $class = shift;
+ my ($class, $start, $end) = @_;
+
+ my $bill_start = $start ? "AND cust_credit_bill._date <= $start" : '';
+ my $bill_end = $end ? "AND cust_credit_bill._date > $end" : '';
+ my $refund_start = $start ? "AND cust_credit_refund._date <= $start" : '';
+ my $refund_end = $end ? "AND cust_credit_refund._date > $end" : '';
"amount
- COALESCE(
( SELECT SUM(amount) FROM cust_credit_refund
- WHERE cust_credit.crednum = cust_credit_refund.crednum )
+ WHERE cust_credit.crednum = cust_credit_refund.crednum
+ $refund_start $refund_end )
,0
)
- COALESCE(
( SELECT SUM(amount) FROM cust_credit_bill
- WHERE cust_credit.crednum = cust_credit_bill.crednum )
+ WHERE cust_credit.crednum = cust_credit_bill.crednum
+ $bill_start $bill_end )
,0
)
";
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.505
retrieving revision 1.506
diff -u -w -d -r1.505 -r1.506
--- cust_main.pm 13 May 2010 05:16:17 -0000 1.505
+++ cust_main.pm 20 May 2010 01:33:07 -0000 1.506
@@ -7392,6 +7392,12 @@
(unused. obsolete?)
JOIN clause (typically used with the total option)
+=item cutoff
+
+An absolute cutoff time. Payments, credits, and refunds I<applied> after this
+time will be ignored. Note that START_TIME and END_TIME only limit the date
+range for invoices and I<unapplied> payments, credits, and refunds.
+
=back
=cut
@@ -7399,10 +7405,12 @@
sub balance_date_sql {
my( $class, $start, $end, %opt ) = @_;
- my $owed = FS::cust_bill->owed_sql;
- my $unapp_refund = FS::cust_refund->unapplied_sql;
- my $unapp_credit = FS::cust_credit->unapplied_sql;
- my $unapp_pay = FS::cust_pay->unapplied_sql;
+ my $cutoff = $opt{'cutoff'};
+
+ my $owed = FS::cust_bill->owed_sql($cutoff);
+ my $unapp_refund = FS::cust_refund->unapplied_sql($cutoff);
+ my $unapp_credit = FS::cust_credit->unapplied_sql($cutoff);
+ my $unapp_pay = FS::cust_pay->unapplied_sql($cutoff);
my $j = $opt{'join'} || '';
Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -w -d -r1.280 -r1.281
--- cust_bill.pm 9 Apr 2010 08:09:47 -0000 1.280
+++ cust_bill.pm 20 May 2010 01:33:07 -0000 1.281
@@ -4342,7 +4342,10 @@
sub owed_sql {
my $class = shift;
- 'charged - '. $class->paid_sql. ' - '. $class->credited_sql;
+ my ($start, $end) = @_;
+ 'charged - '.
+ $class->paid_sql($start, $end). ' - '.
+ $class->credited_sql($start, $end);
}
=item net_sql
@@ -4353,7 +4356,8 @@
sub net_sql {
my $class = shift;
- 'charged - '. $class->credited_sql;
+ my ($start, $end) = @_;
+ 'charged - '. $class->credited_sql($start, $end);
}
=item paid_sql
@@ -4363,9 +4367,11 @@
=cut
sub paid_sql {
- #my $class = shift;
+ my ($class, $start, $end) = @_;
+ $start &&= "AND cust_bill_pay._date <= $start";
+ $end &&= "AND cust_bill_pay._date > $end";
"( SELECT COALESCE(SUM(amount),0) FROM cust_bill_pay
- WHERE cust_bill.invnum = cust_bill_pay.invnum )";
+ WHERE cust_bill.invnum = cust_bill_pay.invnum $start $end )";
}
=item credited_sql
@@ -4375,9 +4381,11 @@
=cut
sub credited_sql {
- #my $class = shift;
+ my ($class, $start, $end) = shift;
+ $start &&= "AND cust_credit_bill._date <= $start";
+ $end &&= "AND cust_credit_bill._date > $end";
"( SELECT COALESCE(SUM(amount),0) FROM cust_credit_bill
- WHERE cust_bill.invnum = cust_credit_bill.invnum )";
+ WHERE cust_bill.invnum = cust_credit_bill.invnum $start $end )";
}
=item search_sql_where HASHREF
More information about the freeside-commits
mailing list