[freeside-commits] branch master updated. 86b44a7897af8265bcd87603fbf2632489ca10b8

Jonathan Prykop jonathan at 420.am
Mon Jul 20 17:25:23 PDT 2015


The branch, master has been updated
       via  86b44a7897af8265bcd87603fbf2632489ca10b8 (commit)
      from  f97cd91298d3cbfd380741cf4a64d402d3628ecd (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 86b44a7897af8265bcd87603fbf2632489ca10b8
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Jul 20 19:24:48 2015 -0500

    RT#37125: Include discounts in report: customer accounting summary [some fixes]

diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm
index ffa1172..63e5318 100644
--- a/FS/FS/Report/Table.pm
+++ b/FS/FS/Report/Table.pm
@@ -229,7 +229,8 @@ sub receipts { #net payments
   my $sql = 'SELECT SUM(cust_bill_pay.amount) FROM cust_bill_pay';
   if ( $opt{'setuprecur'} ) {
     $sql = 'SELECT SUM('.
-            FS::cust_bill_pkg->paid_sql($speriod, $eperiod, %opt).
+            #in practice, but not appearance, paid_sql accepts end before start
+            FS::cust_bill_pkg->paid_sql($eperiod, $speriod, %opt).
            ') FROM cust_bill_pkg';
   }
 
@@ -275,6 +276,11 @@ sub discounted {
 
   my $sql = 'SELECT SUM(';
   if ($opt{'setuprecur'}) {
+    # (This isn't exact but it works in most cases.)
+    # When splitting into setup/recur values, 
+    # if the discount is allowed to apply to setup fees (discount.setup = 'Y')
+    # then split it between the "setup" and "recurring" rows in proportion to 
+    # the "unitsetup" and "unitrecur" fields of the line item. 
     $sql .= <<EOF;
 CASE
   WHEN discount.setup = 'Y' 
@@ -291,11 +297,15 @@ EOF
     }
     $sql .= ' / (COALESCE(cust_bill_pkg.unitsetup,0) + COALESCE(cust_bill_pkg.unitrecur,0)))';
     $sql .= " * cust_bill_pkg_discount.amount\n";
-    $sql .= <<EOF;
-  ELSE cust_bill_pkg_discount.amount
-END
-EOF
+    # Otherwise, show it all as "recurring"
+    if ($opt{'setuprecur'} eq 'setup') {
+      $sql .= "  ELSE 0\n";
+    } elsif ($opt{'setuprecur'} eq 'recur') {
+      $sql .= "  ELSE cust_bill_pkg_discount.amount\n";
+    }
+    $sql .= "END\n";
   } else {
+    # simple case, no setuprecur
     $sql .= "cust_bill_pkg_discount.amount\n";
   }
   $sql .= <<EOF;
diff --git a/httemplate/search/report_customer_accounting_summary.html b/httemplate/search/report_customer_accounting_summary.html
index bdcdbcc..cd8622e 100755
--- a/httemplate/search/report_customer_accounting_summary.html
+++ b/httemplate/search/report_customer_accounting_summary.html
@@ -38,9 +38,12 @@
     &>
 
     <& /elements/tr-checkbox.html,
-        'label' => 'Show Gross & Discounted',
-        'field' => 'grossdiscount',
-        'value' => 1,
+        'label'      => 'Show Gross & Discounted',
+        'field'      => 'grossdiscount',
+        'value'      => 1,
+        'curr_value' => defined($cgi->param('grossdiscount'))
+                        ? scalar($cgi->param('grossdiscount'))
+                        : 1, #default to on in v4
     &>
     
   </TABLE>

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

Summary of changes:
 FS/FS/Report/Table.pm                              |   20 +++++++++++++++-----
 .../search/report_customer_accounting_summary.html |    9 ++++++---
 2 files changed, 21 insertions(+), 8 deletions(-)




More information about the freeside-commits mailing list