use FS::UID qw(dbh);
use FS::Record qw( qsearch qsearchs );
use FS::Misc qw( csv_from_fixed );
+use FS::part_pkg_taxrate;
+use FS::part_pkg_taxoverride;
@ISA = qw(FS::Record);
=head1 DESCRIPTION
-An FS::tax_class object represents a tax class. FS::tax_class
-inherits from FS::Record. The following fields are currently supported:
+An FS::tax_class object represents a class of tax definitions. FS::tax_class
+inherits from FS::Record.
-=over 4
-
-=item taxclassnum
+This should not be confused with L<FS::part_pkg_taxclass>, which defines tax
+classes for I<package> definitions. The two kinds of tax classes are
+completely unrelated.
-Primary key
+The following fields are currently supported:
-=item data_vendor
-
-Vendor of the tax data
+=over 4
-=item taxclass
+=item taxclassnum - Primary key
-Tax class
+=item data_vendor - Vendor of the tax data ('cch' or 'billsoft')
-=item description
+=item taxclass - The identifier used in the tax tables for this class.
-Human readable description of the tax class
+=item description - Human readable description of the tax class.
=back
sub delete {
my $self = shift;
- return "Can't delete a tax class which has tax rates!"
- if qsearch( 'tax_rate', { 'taxclassnum' => $self->taxclassnum } );
-
- return "Can't delete a tax class which has package tax rates!"
- if qsearch( 'part_pkg_taxrate', { 'taxclassnum' => $self->taxclassnum } );
-
- return "Can't delete a tax class which has package tax rates!"
- if qsearch( 'part_pkg_taxrate', { 'taxclassnumtaxed' => $self->taxclassnum } );
+ #return "Can't delete a tax class which has package tax rates!"
+ #if qsearch( 'part_pkg_taxrate', { 'taxclassnumtaxed' => $self->taxclassnum
+ # If this tax class is manually assigned to a package,
+ # then return a useful error message instead of just having a conniption.
+ my @overrides = qsearch( 'part_pkg_taxoverride', {
+ 'taxclassnum' => $self->taxclassnum
+ } );
+ if (@overrides) {
+ return "Tried to delete tax class " . $self->taxclass .
+ ", which is assigned to package definition " .
+ join(', ', map { '#'.$_->pkgpart} @overrides) .
+ ".";
+ }
- return "Can't delete a tax class which has package tax overrides!"
- if qsearch( 'part_pkg_taxoverride', { 'taxclassnum' => $self->taxclassnum } );
+ # part_pkg_taxrate.taxclass identifies taxes belonging to this taxclass.
+ # part_pkg_taxrate.taxclassnumtaxed identifies taxes applying to this
+ # taxclass.
+ # If this taxclass goes away, remove all of them. (CCH upgrade CAN'T
+ # remove them, because it removes the tax_class first and then doesn't
+ # know what the taxclassnum was. Yeah, I know. So it will just skip
+ # over them at the TXMATRIX stage.)
+ my @part_pkg_taxrate = (
+ qsearch('part_pkg_taxrate', { 'taxclassnum' => $self->taxclassnum }),
+ qsearch('part_pkg_taxrate', { 'taxclassnumtaxed' => $self->taxclassnum })
+ );
+ foreach (@part_pkg_taxrate) {
+ my $error = $_->delete;
+ return "when deleting taxclass ".$self->taxclass.": $error"
+ if $error;
+ }
$self->SUPER::delete(@_);
-
+
}
=item replace OLD_RECORD
$hook = sub {
my $hash = shift;
-use Data::Dumper;
-warn Dumper($hash);
+
if ($hash->{'table'} eq 'DETAIL') {
push @{$data->{'taxcat'}}, [ $hash->{'value'}, $hash->{'description'} ]
if ($hash->{'name'} eq 'TAXCAT' &&
($name eq 'TAXCAT' ? $value : '%')."'",
);
foreach (@tax_class) {
-warn "deleting ". $_->taxclass. ' '. $_->description. "\n";
my $error = $_->delete;
return $error if $error;
}
'';
};
+ } elsif ( $format eq 'billsoft' ) {
+ # Billsoft doesn't actually have a format for this; it's just my own
+ # invention to have a way to load the list of tax classes from the
+ # documentation.
+ @fields = qw( taxclass description );
+ $endhook = $hook = sub {};
+
} elsif ( $format eq 'extended' ) {
die "unimplemented\n";
@fields = qw( );
=head1 BUGS
- batch_import does not handle mixed I and D records in the same file for
- format cch-update
-
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.