X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Ftax_class.pm;h=d68e7e30c2ca3c370bc0bd7aa3299a713f7ccecd;hb=13f21e01ac9faa50c07f64c20cbceae0ae50790c;hp=bfec2c06c27b9d9f4dd26eaf2c7b6b94cefacff1;hpb=7792fb0d3dfa4e77f41b8055e96a8938153a7677;p=freeside.git diff --git a/FS/FS/tax_class.pm b/FS/FS/tax_class.pm index bfec2c06c..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 @@ -253,14 +288,23 @@ sub batch_import { } } - my $tax_class = - new FS::tax_class( { 'data_vendor' => 'cch', - 'taxclass' => $type->[0].':'.$cat->[0], - 'description' => $type->[1].':'.$cat->[1], - } ); - my $error = $tax_class->insert; - return $error if $error; + my %hash = ( 'data_vendor' => 'cch', + 'taxclass' => $type->[0].':'.$cat->[0], + 'description' => $type->[1].':'.$cat->[1], + ); + unless ( qsearchs('tax_class', \%hash) ) { + my $tax_class = new FS::tax_class \%hash; + my $error = $tax_class->insert; + + return "can't insert tax_class for ". + " old TAXTYPE ". $type->[0].':'.$type->[1]. + " and new TAXCAT ". $cat->[0].':'. $cat->[1]. + " : $error" + if $error; + } + $imported++; + } } @@ -283,7 +327,7 @@ sub batch_import { 'description' => $type->[1].':'.$cat->[1], } ); my $error = $tax_class->insert; - return $error if $error; + return "can't insert tax_class for new TAXTYPE $type and TAXCAT $cat: $error" if $error; $imported++; } } @@ -363,7 +407,7 @@ sub batch_import { my $error = &{$endhook}(); if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "can't insert tax_class for $line: $error"; + return "can't run end hook: $error"; } $dbh->commit or die $dbh->errstr if $oldAutoCommit; @@ -378,9 +422,6 @@ sub batch_import { =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.