add a config flag to ignore new style taxes instead of throwing fatal errors
authorjeff <jeff>
Thu, 5 Feb 2009 16:57:34 +0000 (16:57 +0000)
committerjeff <jeff>
Thu, 5 Feb 2009 16:57:34 +0000 (16:57 +0000)
FS/FS/Conf.pm
FS/FS/tax_rate.pm

index 72fb98c..eb20590 100644 (file)
@@ -1468,6 +1468,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'ignore_incalculable_taxes',
+    'section'     => 'billing',
+    'description' => 'Prefer to invoice without tax over not billing at all',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'welcome_email',
     'section'     => '',
     'description' => 'Template file for welcome email.  Welcome emails are sent to the customer email invoice destination(s) each time a svc_acct record is created.  See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code></ul>',
index 95d1c60..021bce3 100644 (file)
@@ -385,27 +385,35 @@ sub taxline {
     if $DEBUG;
 
   if ($self->passflag eq 'N') {
-    return "fatal: can't (yet) handle taxes not passed to the customer";
+    # return "fatal: can't (yet) handle taxes not passed to the customer";
+    # until someone needs to track these in freeside
+    return {
+      'name'   => $name,
+      'amount' => 0,
+    };
   }
 
   if ($self->maxtype != 0 && $self->maxtype != 9) {
-    return qq!fatal: can't (yet) handle tax with "!. $self->maxtype_name. 
-      '" threshold';
+    return $self->_fatal_or_null( 'tax with "'.
+                                    $self->maxtype_name. '" threshold'
+                                );
   }
 
   if ($self->maxtype == 9) {
-    return qq!fatal: can't (yet) handle tax with "!. $self->maxtype_name. 
-      '" threshold';  # "texas" tax
+    return
+      $self->_fatal_or_null( 'tax with "'. $self->maxtype_name. '" 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 != 8 && $self->basetype != 14
+      $self->basetype != 5 && $self->basetype != 6 &&
+      $self->basetype != 7 && $self->basetype != 8 &&
+      $self->basetype != 14
   ) {
-    return qq!fatal: can't (yet) handle tax with "!. $self->basetype_name. 
-      '" basis';
+    return
+      $self->_fatal_or_null( 'tax with "'. $self->basetype_name. '" basis' );
   }
 
   unless ($self->setuptax =~ /^Y$/i) {
@@ -425,12 +433,11 @@ sub taxline {
         $seen{$_->pkgnum}++;
       }
     }elsif ($self->unittype == 1) {
-      return qq!fatal: can't (yet) handle fee with minute unit type!;
+      return $self->_fatal_or_null( 'fee with minute unit type' );
     }elsif ($self->unittype == 2) {
       $taxable_units = 1;
     }else {
-      return qq!fatal: can't (yet) handle unknown unit type in tax!.
-        $self->taxnum;
+      return $self->_fatal_or_null( 'unknown unit type in tax'. $self->taxnum );
     }
   }
 
@@ -454,6 +461,24 @@ sub taxline {
 
 }
 
+sub _fatal_or_null {
+  my ($self, $error) = @_;
+
+  my $conf = new FS::Conf;
+
+  $error = "fatal: can't yet handle ". $error;
+  my $name = $self->taxname;
+  $name = 'Other surcharges'
+    if ($self->passtype == 2);
+
+  if ($conf->exists('ignore_incalculable_tax')) {
+    warn $error;
+    return { name => $name, amount => 0 };
+  } else {
+    return $error;
+  }
+}
+
 =item tax_on_tax CUST_MAIN
 
 Returns a list of taxes which are candidates for taxing taxes for the