X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Ftax_class.pm;h=04e9d37f95c48995fae5b4aa2ce496b86a49d425;hp=c8fe88968dd86bc8eb80a5bcf335fc3aa64cfba4;hb=60dc4fe638eb9abc5a3ea92d43031dcbfeb71454;hpb=f744f757a01e1750afa55072c7208714f16d1d13 diff --git a/FS/FS/tax_class.pm b/FS/FS/tax_class.pm index c8fe88968..04e9d37f9 100644 --- a/FS/FS/tax_class.pm +++ b/FS/FS/tax_class.pm @@ -5,6 +5,8 @@ use vars qw( @ISA ); 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); @@ -83,20 +85,39 @@ Delete this record from the database. 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 @@ -169,8 +190,7 @@ sub batch_import { $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' && @@ -195,7 +215,6 @@ warn Dumper($hash); ($name eq 'TAXCAT' ? $value : '%')."'", ); foreach (@tax_class) { -warn "deleting ". $_->taxclass. ' '. $_->description. "\n"; my $error = $_->delete; return $error if $error; } @@ -389,9 +408,6 @@ warn "deleting ". $_->taxclass. ' '. $_->description. "\n"; =head1 BUGS - batch_import does not handle mixed I and D records in the same file for - format cch-update - =head1 SEE ALSO L, schema.html from the base documentation.