[freeside-commits] branch FREESIDE_4_BRANCH updated. 060e8d28ba3004b95e39c074285c8d26b70a4432

Christopher Burger burgerc at freeside.biz
Wed Jan 2 09:10:05 PST 2019


The branch, FREESIDE_4_BRANCH has been updated
       via  060e8d28ba3004b95e39c074285c8d26b70a4432 (commit)
       via  69f34bdfd86b949402a7e7520872cbb8f956af57 (commit)
      from  df3d52c35f1f18ffa46c181bc6ed49085082e961 (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 060e8d28ba3004b95e39c074285c8d26b70a4432
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Dec 28 15:52:02 2018 -0500

    RT# 32917 - Added ability for taxes to be charged prior to applying the discount

diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 04b374f88..b9df65062 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2289,6 +2289,7 @@ sub tables_hashref {
         'setuptax',    'char', 'NULL',       1, '', '', # Y = setup tax exempt
         'recurtax',    'char', 'NULL',       1, '', '', # Y = recur tax exempt
         'source',   'varchar', 'NULL', $char_d, '', '',
+        'charge_prediscount', 'char', 'NULL', 1, '', '', # Y = charge this tax pre discount
       ],
       'primary_key' => 'taxnum',
       'unique' => [],
diff --git a/FS/FS/TaxEngine/internal.pm b/FS/FS/TaxEngine/internal.pm
index 5f5d2295a..6fb1ca756 100644
--- a/FS/FS/TaxEngine/internal.pm
+++ b/FS/FS/TaxEngine/internal.pm
@@ -105,6 +105,15 @@ sub taxline {
     my $taxable_charged = $cust_bill_pkg->setup + $cust_bill_pkg->recur
       or next; # don't create zero-amount exemptions
 
+    ## re-add the discounted amount if the tax needs to be charged pre discount
+    if ($tax_object->charge_prediscount) {
+      my $discount_amount = 0;
+      foreach my $discount (@{$cust_bill_pkg->discounts}) {
+        $discount_amount += $discount->amount;
+      }
+      $taxable_charged += $discount_amount;
+    }
+
     # XXX the following procedure should probably be in cust_bill_pkg
 
     if ( $exempt_cust ) {
diff --git a/httemplate/edit/cust_main_county.html b/httemplate/edit/cust_main_county.html
index 9cc5131a2..b0823098f 100644
--- a/httemplate/edit/cust_main_county.html
+++ b/httemplate/edit/cust_main_county.html
@@ -14,6 +14,7 @@
                    'setuptax' => 'This tax not applicable to setup fees',
                    'recurtax' => 'This tax not applicable to recurring fees',
                    'exempt_amount' => 'Monthly exemption per customer ($25 "Texas tax")',
+                   'charge_prediscount' => 'Charge this tax prior to any discounts',
                  },
      'fields' => \@fields,
    )
@@ -60,6 +61,9 @@ push @fields,
   'taxname',
   { field=>'tax',      type=>'percentage', },
 
+  { type=>'tablebreak-tr-title', value=>'Charging options' },
+  { field=>'charge_prediscount', type=>'checkbox', value=>'Y', },
+
   { type=>'tablebreak-tr-title', value=>'Exemptions' },
   { field=>'setuptax', type=>'checkbox', value=>'Y', },
   { field=>'recurtax', type=>'checkbox', value=>'Y', },

commit 69f34bdfd86b949402a7e7520872cbb8f956af57
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Wed Jan 2 11:34:04 2019 -0500

    RT# 32917 - updated tax report to show pre discount estimated tax

diff --git a/FS/FS/Report/Tax/ByName.pm b/FS/FS/Report/Tax/ByName.pm
index 88695b909..7feea10ed 100644
--- a/FS/FS/Report/Tax/ByName.pm
+++ b/FS/FS/Report/Tax/ByName.pm
@@ -215,6 +215,14 @@ sub report {
     WHERE cust_bill._date >= $beginning AND cust_bill._date <= $ending
     GROUP BY cust_credit_bill_pkg.billpkgnum, taxnum
     ";
+
+  # Each row here is the sum of the discounts where taxes were applied pre discount
+  my $discount = "SELECT SUM(cust_bill_pkg_discount.amount) AS discount_amount, cust_bill_pkg_discount.billpkgnum
+                  FROM cust_bill_pkg_discount
+                  LEFT JOIN cust_bill_pkg_tax_location ON (cust_bill_pkg_tax_location.taxable_billpkgnum = cust_bill_pkg_discount.billpkgnum)
+                  LEFT JOIN cust_main_county USING (taxnum)
+                  WHERE cust_main_county.charge_prediscount = 'Y'
+                  GROUP BY cust_bill_pkg_discount.billpkgnum";
   
   if ( $opt{credit_date} eq 'cust_credit_bill' ) {
     $sales_credit =~ s/cust_bill._date/cust_credit_bill._date/g;
@@ -268,6 +276,7 @@ sub report {
       - COALESCE(exempt_charged, 0)
       - COALESCE(credited, 0)
       + COALESCE(exempt_credited, 0)
+      + COALESCE(discount_amount, 0)
     )
     FROM cust_main_county
     JOIN ($pkg_tax) AS pkg_tax USING (taxnum)
@@ -275,6 +284,7 @@ sub report {
     LEFT JOIN ($pkg_tax_exempt) AS pkg_tax_exempt USING (billpkgnum, taxnum)
     LEFT JOIN ($sales_credit) AS sales_credit USING (billpkgnum)
     LEFT JOIN ($exempt_credit) AS exempt_credit USING (billpkgnum, taxnum)
+    LEFT JOIN ($discount) AS pkg_discount USING (billpkgnum)
     $join_cust_pkg $where AND $nottax 
     $group";
 
@@ -283,6 +293,7 @@ sub report {
       - COALESCE(exempt_charged, 0)
       - COALESCE(credited, 0)
       + COALESCE(exempt_credited, 0)
+      + COALESCE(discount_amount, 0)
     )
     FROM cust_main_county
     JOIN ($pkg_tax) AS pkg_tax USING (taxnum)
@@ -290,6 +301,7 @@ sub report {
     LEFT JOIN ($pkg_tax_exempt) AS pkg_tax_exempt USING (billpkgnum, taxnum)
     LEFT JOIN ($sales_credit) AS sales_credit USING (billpkgnum)
     LEFT JOIN ($exempt_credit) AS exempt_credit USING (billpkgnum, taxnum)
+    LEFT JOIN ($discount) AS pkg_discount USING (billpkgnum)
     $join_cust_pkg $where AND $nottax 
     $group_all";
 
@@ -303,6 +315,7 @@ sub report {
       - COALESCE(exempt_charged, 0)
       - COALESCE(credited, 0)
       + COALESCE(exempt_credited, 0)
+      + COALESCE(discount_amount, 0)
       )
     )
     FROM cust_main_county
@@ -311,6 +324,7 @@ sub report {
     LEFT JOIN ($pkg_tax_exempt) AS pkg_tax_exempt USING (billpkgnum, taxnum)
     LEFT JOIN ($sales_credit) AS sales_credit USING (billpkgnum)
     LEFT JOIN ($exempt_credit) AS exempt_credit USING (billpkgnum, taxnum)
+    LEFT JOIN ($discount) AS pkg_discount USING (billpkgnum)
     $join_cust_pkg $where AND $nottax 
     $group";
 
@@ -320,6 +334,7 @@ sub report {
       - COALESCE(exempt_charged, 0)
       - COALESCE(credited, 0)
       + COALESCE(exempt_credited, 0)
+      + COALESCE(discount_amount, 0)
       )
     )
     FROM cust_main_county
@@ -328,6 +343,7 @@ sub report {
     LEFT JOIN ($pkg_tax_exempt) AS pkg_tax_exempt USING (billpkgnum, taxnum)
     LEFT JOIN ($sales_credit) AS sales_credit USING (billpkgnum)
     LEFT JOIN ($exempt_credit) AS exempt_credit USING (billpkgnum, taxnum)
+    LEFT JOIN ($discount) AS pkg_discount USING (billpkgnum)
     $join_cust_pkg $where AND $nottax 
     $group_all";
 

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

Summary of changes:
 FS/FS/Report/Tax/ByName.pm            | 16 ++++++++++++++++
 FS/FS/Schema.pm                       |  1 +
 FS/FS/TaxEngine/internal.pm           |  9 +++++++++
 httemplate/edit/cust_main_county.html |  4 ++++
 4 files changed, 30 insertions(+)




More information about the freeside-commits mailing list