X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Ftax_class.pm;h=d68e7e30c2ca3c370bc0bd7aa3299a713f7ccecd;hb=63973c641c4be00765fa27e55c57cc5b9aa4da19;hp=c8fe88968dd86bc8eb80a5bcf335fc3aa64cfba4;hpb=bee0671782e7a40961cf406cd7a10675fed6b3ba;p=freeside.git diff --git a/FS/FS/tax_class.pm b/FS/FS/tax_class.pm index c8fe88968..d68e7e30c 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,53 @@ 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 overrides!" if qsearch( 'part_pkg_taxoverride', { 'taxclassnum' => $self->taxclassnum } ); - $self->SUPER::delete(@_); - + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $tax_rate ( + qsearch( 'tax_rate', { taxclassnum=>$self->taxclassnum } ) + ) { + my $error = $tax_rate->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + foreach my $part_pkg_taxrate ( + qsearch( 'part_pkg_taxrate', { taxclassnum=>$self->taxclassnum } ) + ) { + my $error = $part_pkg_taxrate->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + my $error = $self->SUPER::delete(@_); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + } =item replace OLD_RECORD @@ -169,8 +204,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 +229,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 +422,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.