[freeside-commits] branch FREESIDE_3_BRANCH updated. 428a33ad6d0e01621717840d2db4861f4bee6c21

Mark Wells mark at 420.am
Thu Feb 19 15:45:43 PST 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  428a33ad6d0e01621717840d2db4861f4bee6c21 (commit)
      from  76a1482705a98e2bbec4ed1e44a50ab01dee8b03 (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 428a33ad6d0e01621717840d2db4861f4bee6c21
Author: Mark Wells <mark at freeside.biz>
Date:   Thu Feb 19 15:45:22 2015 -0800

    fix problems with tax calculation, #33587, from #18509

diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index 13f027b..2aa2a6f 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -954,6 +954,7 @@ sub disintegrate {
 
   my $usage_total;
   foreach my $classnum ($self->usage_classes) {
+    next if $classnum eq ''; # null-class usage is included in 'recur'
     my $amount = $self->usage($classnum);
     next if $amount == 0; # though if so we shouldn't be here
     my $usage_item = FS::cust_bill_pkg->new({
@@ -1013,7 +1014,11 @@ sub usage {
 
     my $sql = 'SELECT SUM(COALESCE(amount,0)) FROM cust_bill_pkg_detail '.
               ' WHERE billpkgnum = '. $self->billpkgnum;
-    $sql .= " AND classnum = $classnum" if defined($classnum);
+    if ($classnum =~ /^(\d+)$/) {
+      $sql .= " AND classnum = $1";
+    } elsif (defined($classnum) and $classnum eq '') {
+      $sql .= " AND classnum IS NULL";
+    }
 
     my $sth = dbh->prepare($sql) or die dbh->errstr;
     $sth->execute or die $sth->errstr;
@@ -1128,7 +1133,7 @@ sub tax_locationnum {
   my $self = shift;
   if ( $self->pkgnum ) { # normal sales
     return $self->cust_pkg->tax_locationnum;
-  } elsif ( $self->feepart ) { # fees
+  } elsif ( $self->feepart and $self->invnum ) { # fees
     return $self->cust_bill->cust_main->ship_locationnum;
   } else { # taxes
     return '';
@@ -1139,7 +1144,7 @@ sub tax_location {
   my $self = shift;
   if ( $self->pkgnum ) { # normal sales
     return $self->cust_pkg->tax_location;
-  } elsif ( $self->feepart ) { # fees
+  } elsif ( $self->feepart and $self->invnum ) { # fees
     return $self->cust_bill->cust_main->ship_location;
   } else { # taxes
     return;
diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm
index d9cd634..6d1ce77 100644
--- a/FS/FS/cust_main_county.pm
+++ b/FS/FS/cust_main_county.pm
@@ -309,8 +309,11 @@ sub taxline {
       # pertain to this tax def
       $taxable_charged -= $_->amount;
     }
- 
-    my $locationnum = $cust_bill_pkg->tax_locationnum;
+
+    # can't determine the tax_locationnum directly for fees; they're not
+    # yet linked to an invoice
+    my $locationnum = $cust_bill_pkg->tax_locationnum
+                   || $cust_main->ship_locationnum;
 
     ### Monthly capped exemptions ### 
     if ( $self->exempt_amount && $self->exempt_amount > 0 
diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm
index ab1a69e..12a3e98 100644
--- a/FS/FS/tax_rate.pm
+++ b/FS/FS/tax_rate.pm
@@ -575,9 +575,11 @@ sub taxline {
 
       } elsif ( $self->unittype == 2 ) {
 
+        my $locationnum = $cust_bill_pkg->tax_locationnum
+                       || $cust_main->ship_locationnum;
         # per account
-        $units = 1 unless $seen{$cust_bill_pkg->tax_locationnum};
-        $seen{$cust_bill_pkg->tax_locationnum} = 1;
+        $units = 1 unless $seen{$locationnum};
+        $seen{$locationnum} = 1;
 
       } else {
         # Unittype 19 is used for prepaid wireless E911 charges in many states.

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

Summary of changes:
 FS/FS/cust_bill_pkg.pm    |   11 ++++++++---
 FS/FS/cust_main_county.pm |    7 +++++--
 FS/FS/tax_rate.pm         |    6 ++++--
 3 files changed, 17 insertions(+), 7 deletions(-)




More information about the freeside-commits mailing list