X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Ftax_class.pm;h=bfec2c06c27b9d9f4dd26eaf2c7b6b94cefacff1;hb=e513d7cb331d7c7d99d1ea7b5f0a5f8e08e0d725;hp=ed63939f6449ac08ee95fd7be426d222337b9d9c;hpb=6a24254d490f3d023728044daba0765f20f6971e;p=freeside.git diff --git a/FS/FS/tax_class.pm b/FS/FS/tax_class.pm index ed63939f6..bfec2c06c 100644 --- a/FS/FS/tax_class.pm +++ b/FS/FS/tax_class.pm @@ -4,6 +4,7 @@ use strict; use vars qw( @ISA ); use FS::UID qw(dbh); use FS::Record qw( qsearch qsearchs ); +use FS::Misc qw( csv_from_fixed ); @ISA = qw(FS::Record); @@ -147,16 +148,23 @@ sub batch_import { my $imported = 0; my $dbh = dbh; + my @column_lengths = (); + my @column_callbacks = (); + if ( $format eq 'cch-fixed' || $format eq 'cch-fixed-update' ) { + $format =~ s/-fixed//; + push @column_lengths, qw( 8 10 3 2 2 10 100 ); + push @column_lengths, 1 if $format eq 'cch-update'; + } + my $line; my ( $count, $last, $min_sec ) = (0, time, 5); #progressbar - if ( $job ) { - $count++ - while ( defined($line=<$fh>) ); - seek $fh, 0, 0; + if ( $job || scalar(@column_lengths) ) { + my $error = csv_from_fixed(\$fh, \$count, \@column_lengths); + return $error if $error; } if ( $format eq 'cch' || $format eq 'cch-update' ) { - @fields = qw( table name pos number length value description ); + @fields = qw( table name pos length number value description ); push @fields, 'actionflag' if $format eq 'cch-update'; $hook = sub { @@ -195,7 +203,7 @@ sub batch_import { } delete($hash->{$_}) - for qw( data_vendor table name pos number length value description ); + for qw( data_vendor table name pos length number value description ); delete($hash->{actionflag}) if exists($hash->{actionflag}); ''; @@ -238,7 +246,7 @@ sub batch_import { if ( $job ) { # progress bar if ( time - $min_sec > $last ) { my $error = $job->update_statustext( - int( 100 * $imported / $count ) + int( 100 * $imported / $count ). ",Importing tax classes" ); die $error if $error; $last = time; @@ -262,7 +270,7 @@ sub batch_import { if ( $job ) { # progress bar if ( time - $min_sec > $last ) { my $error = $job->update_statustext( - int( 100 * $imported / $count ) + int( 100 * $imported / $count ). ",Importing tax classes" ); die $error if $error; $last = time; @@ -311,7 +319,7 @@ sub batch_import { if ( $job ) { # progress bar if ( time - $min_sec > $last ) { my $error = $job->update_statustext( - int( 100 * $imported / $count ) + int( 100 * $imported / $count ). ",Importing tax classes" ); die $error if $error; $last = time; @@ -331,7 +339,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 tax_class: $line"; } my $error = &{$hook}(\%tax_class); @@ -360,7 +368,7 @@ sub batch_import { $dbh->commit or die $dbh->errstr if $oldAutoCommit; - return "Empty File!" unless $imported; + return "Empty File!" unless ($imported || $format eq 'cch-update'); ''; #no error