[freeside-commits] freeside/FS/FS cust_main.pm, 1.464.2.28, 1.464.2.29 cust_bill.pm, 1.263.2.16, 1.263.2.17 cust_pay.pm, 1.74, 1.74.2.1 cust_credit.pm, 1.38.2.1, 1.38.2.2 cust_refund.pm, 1.33, 1.33.4.1
Mark Wells
mark at wavetail.420.am
Wed May 19 18:34:22 PDT 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv8112/FS/FS
Modified Files:
Tag: FREESIDE_1_9_BRANCH
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.74
retrieving revision 1.74.2.1
diff -u -w -d -r1.74 -r1.74.2.1
--- cust_pay.pm 21 Sep 2009 02:41:43 -0000 1.74
+++ cust_pay.pm 20 May 2010 01:34:20 -0000 1.74.2.1
@@ -657,17 +657,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.33
retrieving revision 1.33.4.1
diff -u -w -d -r1.33 -r1.33.4.1
--- cust_refund.pm 1 Jun 2008 22:48:14 -0000 1.33
+++ cust_refund.pm 20 May 2010 01:34:20 -0000 1.33.4.1
@@ -321,17 +321,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.38.2.1
retrieving revision 1.38.2.2
diff -u -w -d -r1.38.2.1 -r1.38.2.2
--- cust_credit.pm 30 Mar 2010 12:09:21 -0000 1.38.2.1
+++ cust_credit.pm 20 May 2010 01:34:20 -0000 1.38.2.2
@@ -557,17 +557,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.464.2.28
retrieving revision 1.464.2.29
diff -u -w -d -r1.464.2.28 -r1.464.2.29
--- cust_main.pm 30 Mar 2010 12:09:15 -0000 1.464.2.28
+++ cust_main.pm 20 May 2010 01:34:19 -0000 1.464.2.29
@@ -7392,6 +7392,12 @@
}
=item charge HASHREF || AMOUNT [ PKG [ COMMENT [ TAXCLASS ] ] ]
+=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.
+
Creates a one-time charge for this customer. If there is an error, returns
the error, otherwise returns false.
@@ -8257,10 +8263,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.263.2.16
retrieving revision 1.263.2.17
diff -u -w -d -r1.263.2.16 -r1.263.2.17
--- cust_bill.pm 9 Apr 2010 08:09:04 -0000 1.263.2.16
+++ cust_bill.pm 20 May 2010 01:34:20 -0000 1.263.2.17
@@ -4321,7 +4321,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
@@ -4332,7 +4335,8 @@
sub net_sql {
my $class = shift;
- 'charged - '. $class->credited_sql;
+ my ($start, $end) = @_;
+ 'charged - '. $class->credited_sql($start, $end);
}
=item paid_sql
@@ -4342,9 +4346,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
@@ -4354,9 +4360,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