[freeside-commits] branch FREESIDE_3_BRANCH updated. d81ba2cb27849831d3946d408e9f39697f66702b

Mark Wells mark at 420.am
Tue May 20 09:39:25 PDT 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  d81ba2cb27849831d3946d408e9f39697f66702b (commit)
      from  5ca63867625f4158166d7c8444617676e6ad7abd (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 d81ba2cb27849831d3946d408e9f39697f66702b
Author: Mark Wells <mark at freeside.biz>
Date:   Mon May 19 22:12:14 2014 -0700

    option to handle credited tax date range differently, #28497

diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi
index 6cda34a..6bb09d7 100644
--- a/httemplate/search/cust_bill_pkg.cgi
+++ b/httemplate/search/cust_bill_pkg.cgi
@@ -241,8 +241,7 @@ if ( $cgi->param('distribute') == 1 ) {
   push @where, "sdate <= $ending",
                "edate >  $beginning",
   ;
-}
-else {
+} else {
   push @where, "cust_bill._date >= $beginning",
                "cust_bill._date <= $ending";
 }
@@ -602,6 +601,12 @@ push @select, "($pay_sub) AS pay_amount";
 # credit
 if ( $cgi->param('credit') ) {
 
+  my $credit_where;
+
+  my($cr_begin, $cr_end) = FS::UI::Web::parse_beginning_ending($cgi, 'credit');
+  $credit_where = "WHERE cust_credit_bill._date >= $cr_begin " .
+                  "AND cust_credit_bill._date <= $cr_end";
+
   my $credit_sub;
 
   if ( $cgi->param('istax') ) {
@@ -615,6 +620,7 @@ if ( $cgi->param('credit') ) {
       JOIN cust_credit USING (crednum)
       LEFT JOIN reason USING (reasonnum)
       LEFT JOIN access_user USING (usernum)
+    $credit_where
     GROUP BY billpkgnum, billpkgtaxlocationnum, reason.reason, 
       access_user.username";
 
@@ -645,6 +651,7 @@ if ( $cgi->param('credit') ) {
       JOIN cust_credit USING (crednum)
       LEFT JOIN reason USING (reasonnum)
       LEFT JOIN access_user USING (usernum)
+    $credit_where
     GROUP BY billpkgnum, reason.reason, access_user.username";
     $join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit USING (billpkgnum)";
   }
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index 1841903..9926133 100755
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -324,7 +324,7 @@ my $pkg_tax = "SELECT SUM(amount) as tax_amount, taxnum, ".
 my $pkg_tax_exempt = "SELECT SUM(amount) AS exempt_charged, billpkgnum, taxnum ".
   "FROM cust_tax_exempt_pkg EXEMPT_WHERE GROUP BY billpkgnum, taxnum";
 
-my $where = "WHERE _date >= $beginning AND _date <= $ending ";
+my $where = "WHERE cust_bill._date >= $beginning AND cust_bill._date <= $ending ";
 # SELECT/GROUP clauses for first-level queries
 # classnum is a placeholder; they all go in one class in this case.
 my $select = "SELECT NULL AS classnum, cust_main_county.taxnum, ";
@@ -470,9 +470,18 @@ $all_sql{tax} = "$select_all SUM(cust_bill_pkg.setup)
 # ($creditfrom includes join of taxable item to part_pkg if with_pkgclass
 # is on)
 my $creditfrom = $taxfrom .
-   ' JOIN cust_credit_bill_pkg USING (billpkgtaxlocationnum)';
+  ' JOIN cust_credit_bill_pkg USING (billpkgtaxlocationnum)' .
+  ' JOIN cust_credit_bill     USING (creditbillnum)';
 my $creditwhere = $where . 
-   ' AND billpkgtaxratelocationnum IS NULL';
+  ' AND billpkgtaxratelocationnum IS NULL';
+my $creditwhere_all = $where;
+
+# if the credit_date option is set to application date, change
+# $creditwhere accordingly
+if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
+  $creditwhere     =~ s/cust_bill._date/cust_credit_bill._date/g;
+  $creditwhere_all =~ s/cust_bill._date/cust_credit_bill._date/g;
+}
 
 $sql{credit} = "$select SUM(cust_credit_bill_pkg.amount)
                 $creditfrom
@@ -483,9 +492,10 @@ $all_sql{credit} = "$select_all SUM(cust_credit_bill_pkg.amount)
                 FROM cust_credit_bill_pkg
                 JOIN cust_bill_pkg USING (billpkgnum)
                 $join_cust
-                $where AND $istax
+                JOIN cust_credit_bill USING (creditbillnum)
+                $creditwhere_all AND $istax
                 $group_all";
-
+warn "\n\n$all_sql{credit}\n\n";
 if ( $with_pkgclass ) {
   # the slightly more complicated version, with lots of joins that are 
   # unnecessary if you're not breaking down by package class
@@ -496,7 +506,7 @@ if ( $with_pkgclass ) {
 
   $all_sql{credit} = "$select_all SUM(cust_credit_bill_pkg.amount)
                       $creditfrom
-                      $creditwhere AND $istax
+                      $creditwhere_all AND $istax
                       $group_all";
 }
 
@@ -795,6 +805,13 @@ $dateagentlink .= ';agentnum='. $cgi->param('agentnum')
   if length($agentname);
 my $baselink   = $p. "search/cust_bill_pkg.cgi?$dateagentlink";
 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
-my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1";
+
+my $creditlink = $baselink . ";credit=1";
+if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
+  $creditlink =~ s/begin/credit_begin/;
+  $creditlink =~ s/end/credit_end/;
+}
+warn $creditlink;
+
 
 </%init>
diff --git a/httemplate/search/report_tax.html b/httemplate/search/report_tax.html
index 8a207aa..00cb3e8 100755
--- a/httemplate/search/report_tax.html
+++ b/httemplate/search/report_tax.html
@@ -65,6 +65,15 @@
      <TD>Show package classes</TD>
    </TR>
 % } 
+  <TR>
+    <TD></TD>
+    <TD>Deduct credited tax if it was 
+      <SELECT NAME="credit_date">
+        <OPTION VALUE="cust_bill" SELECTED>invoiced in this period</OPTION>
+        <OPTION VALUE="cust_credit_bill">credited in this period</OPTION>
+      </SELECT>
+    </TD>
+  </TR>
 
 </TABLE>
 

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

Summary of changes:
 httemplate/search/cust_bill_pkg.cgi |   11 +++++++++--
 httemplate/search/report_tax.cgi    |   31 ++++++++++++++++++++++++-------
 httemplate/search/report_tax.html   |    9 +++++++++
 3 files changed, 42 insertions(+), 9 deletions(-)




More information about the freeside-commits mailing list