RT# 78190 Fix taxes on fees for sectioned invoices
authorMitch Jackson <mitch@freeside.biz>
Sat, 19 May 2018 20:05:15 +0000 (20:05 +0000)
committerMitch Jackson <mitch@freeside.biz>
Sat, 19 May 2018 23:41:32 +0000 (18:41 -0500)
Fix taxes charged on a billing-event fee, such as a late fee,
displayed incorrectly on some sectioned invoices

FS/FS/Template_Mixin.pm
FS/FS/cust_bill_pkg.pm

index edbb4d4..f36fb96 100644 (file)
@@ -3196,6 +3196,7 @@ sub _items_fee {
 
     push @items,
       { feepart     => $cust_bill_pkg->feepart,
+        billpkgnum  => $cust_bill_pkg->billpkgnum,
         amount      => sprintf('%.2f', $cust_bill_pkg->setup + $cust_bill_pkg->recur),
         description => $desc,
         pkg_tax     => \@pkg_tax,
index f6b40f6..1262c38 100644 (file)
@@ -1881,7 +1881,29 @@ sub _pkg_tax_list {
   #   Duplicates can be identified by billpkgtaxlocationnum column.
 
   my $self = shift;
-  return unless $self->pkgnum;
+
+  my $search_selector;
+  if ( $self->pkgnum ) {
+
+    # For taxes applied to normal billing items
+    $search_selector =
+      ' cust_bill_pkg_tax_location.pkgnum = '
+      . dbh->quote( $self->pkgnum );
+
+  } elsif ( $self->feepart ) {
+
+    # For taxes applied to fees, when the fee is not attached to a package
+    # i.e. late fees, billing events fees
+    $search_selector =
+      ' cust_bill_pkg_tax_location.taxable_billpkgnum = '
+      . dbh->quote( $self->billpkgnum );
+
+  } else {
+    warn "_pkg_tax_list() unhandled case breaking taxes into sections";
+    warn "_pkg_tax_list() $_: ".$self->$_
+      for qw(pkgnum billpkgnum feepart);
+    return;
+  }
 
   map +{
       billpkgtaxlocationnum => $_->billpkgtaxlocationnum,
@@ -1907,7 +1929,7 @@ sub _pkg_tax_list {
       ' WHERE '.
       ' cust_bill_pkg.invnum = ' . dbh->quote( $self->invnum ) .
       ' AND '.
-      ' cust_bill_pkg_tax_location.pkgnum = ' . dbh->quote( $self->pkgnum ),
+      $search_selector
   });
 
 }