+sub batch_import {
+ my ($param, $job) = @_;
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $fh = $param->{filehandle};
+ my $format = $param->{format};
+ die "unsupported part_pkg_taxproduct format '$format'"
+ unless $format eq 'billsoft';
+
+ # this is slightly silly
+ my @lines = <$fh>;
+ my $lines = scalar @lines;
+ seek($fh, 0, 0);
+
+ my $imported = 0;
+ my $csv = Text::CSV_XS->new;
+ my $error;
+ # for importing the "transervdesc.txt" file
+ while ( my $row = $csv->getline($fh) ) {
+ if (!defined $row) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't parse: ". $csv->error_input();
+ }
+
+ if ( $job ) {
+ $job->update_statustext(
+ int( 100 * $imported / $lines ) . ',Inserting tax product records'
+ );
+ }
+
+ # 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
+ });
+ 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 $taxproduct: $error\n";
+ }
+ $imported++;
+ }
+
+ $dbh->commit if $oldAutoCommit;
+ return '';
+}
+