X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg_taxproduct.pm;h=51bc37f9c437d4eed03c9d52a2ba3ff8671aef29;hb=09af85fc0e7a48392c930c9672a99448cf9630d4;hp=c12a432a3737674cdfb4f9f3168623ed1852fbdc;hpb=7516e3da0f17eeecba27219ef96a8b5f46af2083;p=freeside.git diff --git a/FS/FS/part_pkg_taxproduct.pm b/FS/FS/part_pkg_taxproduct.pm index c12a432a3..51bc37f9c 100644 --- a/FS/FS/part_pkg_taxproduct.pm +++ b/FS/FS/part_pkg_taxproduct.pm @@ -153,7 +153,11 @@ sub part_pkg_taxrate { map { $_->taxproductnum } $self->expand_cch_taxproduct ); - $extra_sql .= "AND taxproductnum IN($tpnums)"; + + # if there are no taxproductnums, there are no matching tax classes + return if length($tpnums) == 0; + + $extra_sql .= " AND taxproductnum IN($tpnums)"; my $addl_from = 'LEFT JOIN part_pkg_taxproduct USING ( taxproductnum )'; my $order_by = 'ORDER BY taxclassnum, length(geocode) desc, length(taxproduct) desc'; @@ -219,7 +223,8 @@ sub batch_import { my $imported = 0; my $csv = Text::CSV_XS->new; - # fields: taxproduct, description + my $error; + # for importing the "transervdesc.txt" file while ( my $row = $csv->getline($fh) ) { if (!defined $row) { $dbh->rollback if $oldAutoCommit; @@ -232,15 +237,32 @@ sub batch_import { ); } - my $new = FS::part_pkg_taxproduct->new({ - 'data_vendor' => 'billsoft', - 'taxproduct' => $row->[0], - 'description' => $row->[1], + # columns 0-2: irrelevant here + my $taxproduct = $row->[3] . ':' . $row->[5]; + my $description = $row->[4]; + $description =~ s/\s+$//; + $description .= ':' . $row->[6]; + $description =~ s/\s+$//; + my $ppt = qsearchs('part_pkg_taxproduct', { + 'data_vendor' => 'billsoft', + 'taxproduct' => $taxproduct }); - my $error = $new->insert; + if ( $ppt ) { + $ppt->set('description', $description); + $ppt->set('note', $row->[7]); + $error = $ppt->replace; + } else { + $ppt = FS::part_pkg_taxproduct->new({ + 'data_vendor' => 'billsoft', + 'taxproduct' => $taxproduct, + 'description' => $description, + 'note' => $row->[7], + }); + $error = $ppt->insert; + } if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "error inserting part_pkg_taxproduct: $error\n"; + return "error inserting part_pkg_taxproduct $taxproduct: $error\n"; } $imported++; }