summaryrefslogtreecommitdiff
path: root/FS/FS/tax_rate.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-08-07 23:08:53 -0700
committerIvan Kohler <ivan@freeside.biz>2012-08-07 23:08:53 -0700
commit94c1d035193d1eabb1820e62bce96438f11f870a (patch)
treeb811fb38f7f310733ab63dcbf6c790ca575a8b09 /FS/FS/tax_rate.pm
parent21254f0e0062b92c19530c49c6eacc9ce3e93827 (diff)
ignore extra columns in CCH diff (bad data from last update?), RT#18817
Diffstat (limited to 'FS/FS/tax_rate.pm')
-rw-r--r--FS/FS/tax_rate.pm40
1 files changed, 26 insertions, 14 deletions
diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm
index 3fdaa1e..a5a623d 100644
--- a/FS/FS/tax_rate.pm
+++ b/FS/FS/tax_rate.pm
@@ -10,6 +10,7 @@ use DateTime::Format::Strptime;
use Storable qw( thaw nfreeze );
use IO::File;
use File::Temp;
+use Text::CSV_XS;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
@@ -637,6 +638,7 @@ sub batch_import {
$count *=2;
if ( $format eq 'cch' || $format eq 'cch-update' ) {
+ #false laziness w/below (sub _perform_cch_diff)
@fields = qw( geocode inoutcity inoutlocal tax location taxbase taxmax
excessrate effective_date taxauth taxtype taxcat taxname
usetax useexcessrate fee unittype feemax maxtype passflag
@@ -715,9 +717,6 @@ sub batch_import {
die "unknown format $format";
}
- eval "use Text::CSV_XS;";
- die $@ if $@;
-
my $csv = new Text::CSV_XS;
my $imported = 0;
@@ -759,12 +758,10 @@ sub batch_import {
$tax_rate{$field} = shift @columns;
}
- #ignoring extra columns (bad data from last update?) and seeing if that
- # allows the upgrade to proceed
- #if ( scalar( @columns ) ) {
- # $dbh->rollback if $oldAutoCommit;
- # return "Unexpected trailing columns in line (wrong format?) importing tax_rate: $line";
- #}
+ if ( scalar( @columns ) ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Unexpected trailing columns in line (wrong format?) importing tax_rate: $line";
+ }
my $error = &{$hook}(\%tax_rate);
if ( $error ) {
@@ -1118,8 +1115,26 @@ sub _perform_cch_diff {
}
close $newcsvfh;
- for (keys %oldlines) {
- print $dfh $_, ',"D"', "\n" if $oldlines{$_};
+ #false laziness w/above (sub batch_import)
+ my @fields = qw( geocode inoutcity inoutlocal tax location taxbase taxmax
+ excessrate effective_date taxauth taxtype taxcat taxname
+ usetax useexcessrate fee unittype feemax maxtype passflag
+ passtype basetype );
+ my $numfields = scalar(@fields);
+
+ my $csv = new Text::CSV_XS { 'always_quote' => 1 };
+
+ for my $line (grep $oldlines{$_}, keys %oldlines) {
+
+ $csv->parse($line) or do {
+ #$dbh->rollback if $oldAutoCommit;
+ die "can't parse: ". $csv->error_input();
+ };
+ my @columns = $csv->fields();
+
+ $csv->combine( splice(@columns, 0, $numfields) );
+
+ print $dfh $csv->string, ',"D"', "\n";
}
close $dfh;
@@ -1173,9 +1188,6 @@ sub _cch_fetch_and_unzip {
sub _cch_extract_csv_from_dbf {
my ( $job, $dir, $name ) = @_;
- eval "use Text::CSV_XS;";
- die $@ if $@;
-
eval "use XBase;";
die $@ if $@;