tax-pkg_location changes broke new taxation, this should fix
[freeside.git] / FS / FS / tax_rate.pm
index 2837f9c..95d1c60 100644 (file)
@@ -294,6 +294,7 @@ Returns the human understandable value associated with the basetype column
                    '11' => 'gross profits',
                    '12' => 'tariff rate',
                    '14' => 'account',
+                   '15' => 'prior year gross receipts',
 );
 
 sub basetype_name {
@@ -341,26 +342,43 @@ sub passtype_name {
   $tax_passtypes{$self->passtype};
 }
 
-=item taxline CUST_BILL_PKG|AMOUNT, ...
+=item taxline TAXABLES, [ OPTIONSHASH ]
 
 Returns a listref of a name and an amount of tax calculated for the list
-of packages/amounts.  If an error occurs, a message is returned as a scalar.
+of packages/amounts referenced by TAXABLES.  If an error occurs, a message
+is returned as a scalar.
 
 =cut
 
 sub taxline {
   my $self = shift;
 
+  my $taxables;
+  my %opt = ();
+
+  if (ref($_[0]) eq 'ARRAY') {
+    $taxables = shift;
+    %opt = @_;
+  }else{
+    $taxables = [ @_ ];
+    #exemptions would be broken in this case
+  }
+
   my $name = $self->taxname;
   $name = 'Other surcharges'
     if ($self->passtype == 2);
   my $amount = 0;
   
-  return [$name, $amount]  # we always know how to handle disabled taxes
-    if $self->disabled;
+  if ( $self->disabled ) { # we always know how to handle disabled taxes
+    return {
+      'name'   => $name,
+      'amount' => $amount,
+    };
+  }
 
   my $taxable_charged = 0;
-  my @cust_bill_pkg = grep { $taxable_charged += $_ unless ref; ref; } @_;
+  my @cust_bill_pkg = grep { $taxable_charged += $_ unless ref; ref; }
+                      @$taxables;
 
   warn "calculating taxes for ". $self->taxnum. " on ".
     join (",", map { $_->pkgnum } @cust_bill_pkg)
@@ -380,9 +398,11 @@ sub taxline {
       '" threshold';  # "texas" tax
   }
 
+  # we treat gross revenue as gross receipts and expect the tax data
+  # to DTRT (i.e. tax on tax rules)
   if ($self->basetype != 0 && $self->basetype != 1 &&
       $self->basetype != 6 && $self->basetype != 7 &&
-      $self->basetype != 14
+      $self->basetype != 8 && $self->basetype != 14
   ) {
     return qq!fatal: can't (yet) handle tax with "!. $self->basetype_name. 
       '" basis';
@@ -427,7 +447,10 @@ sub taxline {
   warn "calculated taxes as [ $name, $amount ]\n"
     if $DEBUG;
 
-  return [$name, $amount];
+  return {
+    'name'   => $name,
+    'amount' => $amount,
+  };
 
 }
 
@@ -762,13 +785,13 @@ sub batch_import {
 
 }
 
-=item process_batch
+=item process_batch_import
 
 Load a batch import as a queued JSRPC job
 
 =cut
 
-sub process_batch {
+sub process_batch_import {
   my $job = shift;
 
   my $param = thaw(decode_base64(shift));