X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg_taxrate.pm;h=bfb1ea8e27ff45f2e3cb59872f6df4d99d7e0a9b;hp=fb1afce185eec04eaf9f452b527bf3080d75848e;hb=HEAD;hpb=339c9336a908446c63980bff864bdc270c408e23 diff --git a/FS/FS/part_pkg_taxrate.pm b/FS/FS/part_pkg_taxrate.pm index fb1afce18..bfb1ea8e2 100644 --- a/FS/FS/part_pkg_taxrate.pm +++ b/FS/FS/part_pkg_taxrate.pm @@ -5,8 +5,7 @@ use vars qw( @ISA ); use Date::Parse; use DateTime; use DateTime::Format::Strptime; -use FS::UID qw(dbh); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); use FS::part_pkg_taxproduct; use FS::Misc qw(csv_from_fixed); @@ -244,9 +243,12 @@ sub batch_import { ); unless ($part_pkg_taxproduct) { - return "Can't find part_pkg_taxproduct for txmatrix deletion: ". - join(" ", map { "$_ => ". $hash->{$_} } @fields) - if ($hash->{'actionfield'} && $hash->{'actionflag'} eq 'D'); + if (($hash->{'actionfield'} || '') eq 'D') { + warn "WARNING: Can't find part_pkg_taxproduct for txmatrix deletion: ". + join(" ", map { "$_ => ". $hash->{$_} } @fields) . + " (ignored)\n"; + next; + } $part_pkg_taxproduct{'description'} = join(' : ', (map{ $hash->{$_} } qw(groupdesc itemdesc)), @@ -263,6 +265,8 @@ sub batch_import { delete($hash->{$_}) for qw(group groupdesc item itemdesc provider customer rectype ); + + # resolve the taxtype/taxcat fields to taxclassnums my %map = ( 'taxclassnum' => [ 'taxtype', 'taxcat' ], 'taxclassnumtaxed' => [ 'taxtypetaxed', 'taxcattaxed' ], @@ -276,14 +280,13 @@ sub batch_import { 'taxclass' => $class, } ); - $hash->{$item} = $tax_class->taxclassnum - if $tax_class; - - return "Can't find tax class for txmatrix deletion: ". - join(" ", map { "$_ => ". $hash->{$_} } @fields) - if ( $hash->{'actionflag'} && $hash->{'actionflag'} eq 'D' && - !$tax_class && $class ne ':' - ); + if ( $tax_class ) { + $hash->{$item} = $tax_class->taxclassnum; + } elsif ($class ne ':' and ($hash->{actionflag} || '') eq 'D') { + # return "Can't find tax class for txmatrix deletion: ". + warn "WARNING: Can't find tax class $class for txmatrix deletion (ignored)\n"; + return ''; # don't delete the record, then + } delete($hash->{$_}) foreach @{$map{$item}}; } @@ -292,7 +295,9 @@ sub batch_import { time_zone => 'floating', ); my $dt = $parser->parse_datetime( $hash->{'effdate'} ); - $hash->{'effdate'} = $dt ? $dt->epoch : ''; + return "Can't parse effdate ". $hash->{'effdate'}. ': '. $parser->errstr + unless $dt; + $hash->{'effdate'} = $dt->epoch; $hash->{'country'} = 'US'; # CA is available @@ -301,8 +306,15 @@ sub batch_import { if (exists($hash->{actionflag}) && $hash->{actionflag} eq 'D') { delete($hash->{actionflag}); - my $part_pkg_taxrate = qsearchs('part_pkg_taxrate', $hash); - unless ( $part_pkg_taxrate ) { + foreach my $intfield (qw( taxproductnum taxclassnum effdate )) { + if ( $hash->{$intfield} eq '' ) { + return "$intfield is empty in search! -- ". + join(" ", map { "$_ => *". $hash->{$_}. '*' } keys(%$hash) ); + } + } + + my @part_pkg_taxrate = qsearch('part_pkg_taxrate', $hash); + unless ( scalar(@part_pkg_taxrate) || $param->{'delete_only'} ) { if ( $hash->{taxproductnum} ) { my $taxproduct = qsearchs( 'part_pkg_taxproduct', @@ -311,12 +323,14 @@ sub batch_import { $hash->{taxproductnum} .= ' ( '. $taxproduct->taxproduct. ' )' if $taxproduct; } - return "Can't find part_pkg_taxrate to delete: ". + warn "WARNING: Can't find part_pkg_taxrate to delete: ". join(" ", map { "$_ => *". $hash->{$_}. '*' } keys(%$hash) ); } - my $error = $part_pkg_taxrate->delete; - return $error if $error; + foreach my $part_pkg_taxrate (@part_pkg_taxrate) { + my $error = $part_pkg_taxrate->delete; + return $error if $error; + } delete($hash->{$_}) foreach (keys %$hash); } @@ -375,7 +389,7 @@ sub batch_import { } if ( scalar( @columns ) ) { $dbh->rollback if $oldAutoCommit; - return "Unexpected trailing columns in line (wrong format?): $line"; + return "Unexpected trailing columns in line (wrong format?) importing part_pkg_taxrate: $line"; } my $error = &{$hook}(\%part_pkg_taxrate);