X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Ftax_rate.pm;h=50279172df02e2aedd9c9093852dd735659ceb3a;hb=75ba02c6ef43d30a6382cdb3ce82db8c7c05f6a7;hp=9e458e27f76934cc1efbba043a44a12e7cff5a27;hpb=dbd79d059c9353da8d521fce4ee2ce8cc3349a54;p=freeside.git diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index 9e458e27f..50279172d 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -286,16 +286,25 @@ sub unittype_name { =item maxtype_name -Returns the human understandable value associated with the maxtype column +Returns the human understandable value associated with the maxtype column. =cut +# XXX these are non-functional, and most of them are horrible to implement +# in our current model + %tax_maxtypes = ( '0' => 'receipts per invoice', '1' => 'receipts per item', '2' => 'total utility charges per utility tax year', '3' => 'total charges per utility tax year', '4' => 'receipts per access line', + '7' => 'total utility charges per calendar year', '9' => 'monthly receipts per location', + '10' => 'monthly receipts exceeds taxbase and total tax per month does not exceed maxtax', # wtf? + '11' => 'receipts/units per access line', + '14' => 'units per invoice', + '15' => 'units per month', + '18' => 'units per account', ); sub maxtype_name { @@ -423,17 +432,12 @@ sub taxline { } my $maxtype = $self->maxtype || 0; - if ($maxtype != 0 && $maxtype != 1 && $maxtype != 9) { + if ($maxtype != 0 && $maxtype != 1 + && $maxtype != 14 && $maxtype != 15) { return $self->_fatal_or_null( 'tax with "'. $self->maxtype_name. '" threshold' ); - } - - if ($maxtype == 9) { - return - $self->_fatal_or_null( 'tax with "'. $self->maxtype_name. '" threshold' ); - # "texas" tax - } + } # I don't know why, it's not like there are maxtypes that we DO support # we treat gross revenue as gross receipts and expect the tax data # to DTRT (i.e. tax on tax rules) @@ -493,6 +497,15 @@ sub taxline { # the tax or fee is applied to taxbase or feebase and then # the excessrate or excess fee is applied to taxmax or feemax + if ( ($self->taxmax > 0 and $taxable_charged > $self->taxmax) or + ($self->feemax > 0 and $taxable_units > $self->feemax) ) { + # throw an error + # (why not just cap taxable_charged/units at the taxmax/feemax? because + # it's way more complicated than that. this won't even catch every case + # where a bracket maximum should apply.) + return $self->_fatal_or_null( 'tax base > taxmax/feemax for tax'.$self->taxnum ); + } + $amount += $taxable_charged * $self->tax; $amount += $taxable_units * $self->fee; @@ -509,6 +522,8 @@ sub taxline { sub _fatal_or_null { my ($self, $error) = @_; + $DB::single = 1; # not a mistake + my $conf = new FS::Conf; $error = "can't yet handle ". $error; @@ -880,20 +895,22 @@ sub batch_import { } my $tax_rate = qsearchs( 'tax_rate', $delete{$_} ); - unless ($tax_rate) { + if (!$tax_rate) { $dbh->rollback if $oldAutoCommit; $tax_rate = $delete{$_}; - return "can't find tax_rate to delete for: ". - #join(" ", map { "$_ => ". $tax_rate->{$_} } @fields); - join(" ", map { "$_ => ". $tax_rate->{$_} } keys(%$tax_rate) ); - } - my $error = $tax_rate->delete; + warn "WARNING: can't find tax_rate to delete for: ". + join(" ", map { "$_ => ". $tax_rate->{$_} } keys(%$tax_rate) ). + " (ignoring)\n"; + } else { + my $error = $tax_rate->delete; # XXX we really should not do this + # (it orphans CBPTRL records) - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - my $hashref = $delete{$_}; - $line = join(", ", map { "$_ => ". $hashref->{$_} } keys(%$hashref) ); - return "can't delete tax_rate for $line: $error"; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + my $hashref = $delete{$_}; + $line = join(", ", map { "$_ => ". $hashref->{$_} } keys(%$hashref) ); + return "can't delete tax_rate for $line: $error"; + } } $imported++;