[freeside-commits] branch master updated. f539cfd607d3812b189e3473a15d4f55bb91844c

Mark Wells mark at 420.am
Mon Mar 9 23:13:42 PDT 2015


The branch, master has been updated
       via  f539cfd607d3812b189e3473a15d4f55bb91844c (commit)
      from  cd7cfb165d6d843671ec11022f38ecd484812f9f (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 f539cfd607d3812b189e3473a15d4f55bb91844c
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Mar 9 23:13:35 2015 -0700

    more accurate charge type detail searches from sales report, #33257

diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi
index fa6dabc..91fe4e0 100644
--- a/httemplate/search/cust_bill_pkg.cgi
+++ b/httemplate/search/cust_bill_pkg.cgi
@@ -106,11 +106,7 @@ Output control parameters:
   range of the report.  Line items will be limited to those for which this 
   portion is > 0.  This disables filtering on invoice date.
 
-- usage: Separate usage (cust_bill_pkg_detail records) from
-  recurring charges.  If set to "usage", will show usage instead of 
-  recurring charges.  If set to "recurring", will deduct usage and only
-  show the flat rate charge.  If not passed, the "recurring charge" column
-  will include usage charges also.
+- charges: 'S'etup, 'R'ecur, 'U'sage, or any string combination of those.
 
 Filtering parameters:
 - begin, end: Date range.  Applies to invoice date, not necessarily package
@@ -201,7 +197,7 @@ my @total = ( 'COUNT(*)', 'SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)');
 my @total_desc = ( $money_char.'%.2f total' ); # sprintf strings
 
 my @peritem = ( 'setup', 'recur' );
-my @peritem_desc = ( 'Setup charge', 'Recurring charge' );
+my @peritem_desc = ( 'Setup charges', 'Recurring charges' );
 
 my @currency_desc = ();
 my @currency_sub = ();
@@ -517,16 +513,32 @@ if ( $cgi->param('nottax') ) {
 
   } # handle all joins to cust_main_county
 
-  # recur/usage separation
-  if ( $cgi->param('usage') eq 'recurring' ) {
+  # setup/recur/usage separation
+  my %charges = map { $_ => 1 } split('', $cgi->param('charges') || 'SRU');
 
-    my $recur_no_usage = FS::cust_bill_pkg->charged_sql('', '', no_usage => 1);
+  if ( $charges{R} and $charges{U} ) {
+
+    # default, don't change @peritem or @total
+    if ( !$charges{S} ) {
+      push @where, 'cust_bill_pkg.recur > 0';
+      $total[1] = "SUM(cust_bill_pkg.recur)";
+      $total_desc[0] = "$money_char%.2f recurring";
+    }
+
+  } elsif ( $charges{R} and !$charges{U} ) {
+
+    my $recur_no_usage = FS::cust_bill_pkg->charged_sql('', '', 
+      setuprecur => 'recur', no_usage => 1);
     push @select, "($recur_no_usage) AS recur_no_usage";
     $peritem[1] = 'recur_no_usage';
-    $total[1] = "SUM(cust_bill_pkg.setup + $recur_no_usage)";
-    $total_desc[0] .= ' (excluding usage)';
+    $peritem_desc[1] = 'Recurring charges (excluding usage)';
+    $total[1] = "SUM($recur_no_usage)";
+    $total_desc[0] = "$money_char%.2f recurring";
+    if ( !$charges{S} ) {
+      push @where, "($recur_no_usage) > 0";
+    }
 
-  } elsif ( $cgi->param('usage') eq 'usage' ) {
+  } elsif ( !$charges{R} and $charges{U} ) {
 
     my $usage = FS::cust_bill_pkg->usage_sql();
     push @select, "($usage) AS _usage";
@@ -534,8 +546,18 @@ if ( $cgi->param('nottax') ) {
     $peritem[1] = '_usage';
     $peritem_desc[1] = 'Usage charge';
     $total[1] = "SUM($usage)";
-    $total_desc[0] .= ' usage charges';
-  }
+    $total_desc[0] = "$money_char%.2f usage charges";
+    if ( !$charges{S} ) {
+      push @where, "($usage) > 0";
+    }
+
+  } elsif ( $charges{S} ) {
+
+    push @where, "cust_bill_pkg.setup > 0";
+    $total[1] = "SUM(cust_bill_pkg.setup)";
+    $total_desc[0] = "$money_char%.2f setup";
+
+  } # else huh? you have to have SOME charges
 
 } elsif ( $cgi->param('istax') ) {
 

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

Summary of changes:
 httemplate/search/cust_bill_pkg.cgi |   50 +++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 14 deletions(-)




More information about the freeside-commits mailing list