use strict;
use vars qw( @ISA $delete_kludge );
-use FS::Record qw( qsearch dbh );
+use FS::Record qw( qsearch qsearchs dbh );
use Text::CSV_XS;
@ISA = qw(FS::Record);
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';
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;
);
}
- 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++;
}