[freeside-commits] branch FREESIDE_3_BRANCH updated. 2feef99c412039a2b718e5f3889f2c25dc1bcf73

Mark Wells mark at 420.am
Fri Aug 9 12:05:57 PDT 2013


The branch, FREESIDE_3_BRANCH has been updated
       via  2feef99c412039a2b718e5f3889f2c25dc1bcf73 (commit)
      from  7d8eccbe9fe50eb5f69ed9bf426623110d2cf960 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2feef99c412039a2b718e5f3889f2c25dc1bcf73
Author: Mark Wells <mark at freeside.biz>
Date:   Thu Aug 8 18:42:57 2013 -0700

    unearned revenue report: consider primary object dates, not application dates, #13289

diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index 0c8c0bb..acbaded 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -949,8 +949,8 @@ Returns an SQL expression for the sum of payments applied to this item.
 
 sub paid_sql {
   my ($class, $start, $end, %opt) = @_;
-  my $s = $start ? "AND cust_bill_pay._date <= $start" : '';
-  my $e = $end   ? "AND cust_bill_pay._date >  $end"   : '';
+  my $s = $start ? "AND cust_pay._date <= $start" : '';
+  my $e = $end   ? "AND cust_pay._date >  $end"   : '';
   my $setuprecur = 
     $opt{setuprecur} =~ /^s/ ? 'setup' :
     $opt{setuprecur} =~ /^r/ ? 'recur' :
@@ -959,6 +959,7 @@ sub paid_sql {
 
   my $paid = "( SELECT COALESCE(SUM(cust_bill_pay_pkg.amount),0)
      FROM cust_bill_pay_pkg JOIN cust_bill_pay USING (billpaynum)
+                            JOIN cust_pay      USING (paynum)
      WHERE cust_bill_pay_pkg.billpkgnum = cust_bill_pkg.billpkgnum
            $s $e $setuprecur )";
 
@@ -977,8 +978,8 @@ sub paid_sql {
 
 sub credited_sql {
   my ($class, $start, $end, %opt) = @_;
-  my $s = $start ? "AND cust_credit_bill._date <= $start" : '';
-  my $e = $end   ? "AND cust_credit_bill._date >  $end"   : '';
+  my $s = $start ? "AND cust_credit._date <= $start" : '';
+  my $e = $end   ? "AND cust_credit._date >  $end"   : '';
   my $setuprecur = 
     $opt{setuprecur} =~ /^s/ ? 'setup' :
     $opt{setuprecur} =~ /^r/ ? 'recur' :
@@ -987,6 +988,7 @@ sub credited_sql {
 
   my $credited = "( SELECT COALESCE(SUM(cust_credit_bill_pkg.amount),0)
      FROM cust_credit_bill_pkg JOIN cust_credit_bill USING (creditbillnum)
+                               JOIN cust_credit      USING (crednum)
      WHERE cust_credit_bill_pkg.billpkgnum = cust_bill_pkg.billpkgnum
            $s $e $setuprecur )";
 
diff --git a/httemplate/search/unearned_detail.html b/httemplate/search/unearned_detail.html
index 285fb50..b87a747 100644
--- a/httemplate/search/unearned_detail.html
+++ b/httemplate/search/unearned_detail.html
@@ -105,6 +105,10 @@ my $agentnums_sql =
 
 my @where = ( $agentnums_sql );
 
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+  push @where, "cust_main.agentnum = $1";
+}
+
 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
 
 if ( $cgi->param('status') =~ /^([a-z]+)$/ ) {
@@ -191,12 +195,16 @@ push @select, "$unearned_sql AS unearned_revenue";
 # last payment/credit date
 my %t = (pay => 'cust_bill_pay', credit => 'cust_credit_bill');
 foreach my $x (qw(pay credit)) {
-  my $table = $t{$x};
-  my $link = $table.'_pkg';
-  my $pkey = dbdef->table($table)->primary_key;
-  my $last_date_sql = "SELECT MAX(_date) 
-  FROM $table JOIN $link USING ($pkey)
-  WHERE $link.billpkgnum = cust_bill_pkg.billpkgnum 
+  my $table     = "cust_$x";
+  my $link_bill = $t{$x};
+  my $link_pkg  = $link_bill.'_pkg';
+  my %pkey = map { $_ => dbdef->table($_)->primary_key }
+    ( $table, $link_bill );
+
+  my $last_date_sql = "SELECT MAX($table._date) 
+  FROM $table JOIN $link_bill USING ($pkey{$table})
+              JOIN $link_pkg  USING ($pkey{$link_bill})
+  WHERE $link_pkg.billpkgnum = cust_bill_pkg.billpkgnum 
   AND $table._date <= $unearned";
   push @select, "($last_date_sql) AS last_$x";
 }

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_bill_pkg.pm                 |   10 ++++++----
 httemplate/search/unearned_detail.html |   20 ++++++++++++++------
 2 files changed, 20 insertions(+), 10 deletions(-)




More information about the freeside-commits mailing list