X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Ftax_rate.pm;h=0d9156b4316d62b7127c296c878872aec4e76afd;hb=399e73ed1e73443523d6889b703d04289ec0e117;hp=ce460e192087fc794dd7e8324ffadc3f2cf7ea09;hpb=c94cc8e588a0888d4b979a10b65f02d07355c4b1;p=freeside.git diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index ce460e192..0d9156b43 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -342,53 +342,78 @@ 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) 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) { @@ -408,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 ); } } @@ -430,10 +454,31 @@ sub taxline { warn "calculated taxes as [ $name, $amount ]\n" if $DEBUG; - return [$name, $amount]; + return { + 'name' => $name, + 'amount' => $amount, + }; } +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_taxes')) { + 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 @@ -515,9 +560,11 @@ sub batch_import { /^(\d{4})(\d{2})(\d{2})$/ && ($r="$1/$2/$3"); $r; }; - $column_callbacks[8] = $date_format; + my $trim = sub { my $r = shift; $r =~ s/^\s*//; $r =~ s/\s*$//; $r }; push @column_lengths, qw( 10 1 1 8 8 5 8 8 8 1 2 2 30 8 8 10 2 8 2 1 2 2 ); push @column_lengths, 1 if $format eq 'cch-update'; + push @column_callbacks, $trim foreach (@column_lengths); # 5, 6, 15, 17 esp + $column_callbacks[8] = $date_format; } my $line; @@ -765,13 +812,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)); @@ -868,10 +915,12 @@ sub process_batch { UNLINK => 0, #meh ) or die "can't open temp file: $!\n"; + my $insert_pattern = ($format eq 'cch-update') ? qr/"I"\s*$/ : qr/I\s*$/; + my $delete_pattern = ($format eq 'cch-update') ? qr/"D"\s*$/ : qr/D\s*$/; while(<$fh>) { my $handle = ''; - $handle = $ifh if $_ =~ /"I"\s*$/; - $handle = $dfh if $_ =~ /"D"\s*$/; + $handle = $ifh if $_ =~ /$insert_pattern/; + $handle = $dfh if $_ =~ /$delete_pattern/; unless ($handle) { $error = "bad input line: $_" unless $handle; last;