X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_tax_location.pm;h=161a6547b14d5b24ad95fe82265ba63237bb249f;hp=cd24cc8a83378422cdc06e7da3bace6d9487fc7d;hb=f9a181e4c2e505df84de16190ee3b75011326f3f;hpb=f32fab28c5cea2b5619c9b1d5cc6e3fe7beef126 diff --git a/FS/FS/cust_tax_location.pm b/FS/FS/cust_tax_location.pm index cd24cc8a8..161a6547b 100644 --- a/FS/FS/cust_tax_location.pm +++ b/FS/FS/cust_tax_location.pm @@ -113,15 +113,39 @@ sub check { my $error = $self->ut_numbern('custlocationnum') || $self->ut_text('data_vendor') - || $self->ut_number('zip') + || $self->ut_textn('city') + || $self->ut_textn('postalcity') + || $self->ut_textn('county') || $self->ut_text('state') - || $self->ut_number('plus4hi') - || $self->ut_number('plus4lo') - || $self->ut_enum('default', [ '', ' ', 'Y' ] ) - || $self->ut_number('geocode') + || $self->ut_numbern('plus4hi') + || $self->ut_numbern('plus4lo') + || $self->ut_enum('default_location', [ '', 'Y' ] ) + || $self->ut_enum('cityflag', [ '', 'I', 'O', 'B' ] ) + || $self->ut_alpha('geocode') ; return $error if $error; + #ugh! cch canada weirdness and more + if ($self->state eq 'CN' && $self->data_vendor eq 'cch-zip' ) { + $error = "Illegal cch canadian zip" + unless $self->zip =~ /^[A-Z]$/; + } elsif ($self->state =~ /^E([B-DFGILNPR-UW])$/ && $self->data_vendor eq 'cch-zip' ) { + $error = "Illegal cch european zip" + unless $self->zip =~ /^E$1$/; + } else { + $error = $self->ut_number('zip', $self->state eq 'CN' ? 'CA' : 'US'); + } + return $error if $error; + + #ugh! cch canada weirdness and more + return "must specify either city/county or plus4lo/plus4hi" + unless ( $self->plus4lo && $self->plus4hi || + ( $self->city || + $self->state eq 'CN' || + $self->state =~ /^E([B-DFGILNPR-UW])$/ + ) && $self->county + ); + $self->SUPER::check; } @@ -138,21 +162,30 @@ sub batch_import { my @column_lengths = (); my @column_callbacks = (); - if ( $format eq 'cch-fixed' || $format eq 'cch-fixed-update' ) { + if ( $format =~ /^cch-fixed/ ) { $format =~ s/-fixed//; - push @column_lengths, qw( 5 2 4 4 10 1 ); - push @column_lengths, 1 if $format eq 'cch-update'; + my $f = $format; + my $update = 0; + $f =~ s/-update// && ($update = 1); + if ($f eq 'cch') { + push @column_lengths, qw( 5 2 4 4 10 1 ); + } elsif ( $f eq 'cch-zip' ) { + push @column_lengths, qw( 5 28 25 2 28 5 1 1 10 1 2 ); + } else { + return "Unknown format: $format"; + } + push @column_lengths, 1 if $update; } my $line; my ( $count, $last, $min_sec ) = (0, time, 5); #progressbar - if ( $job || scalar(@column_callbacks) ) { + 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( zip state plus4lo plus4hi geocode default ); + @fields = qw( zip state plus4lo plus4hi geocode default_location ); push @fields, 'actionflag' if $format eq 'cch-update'; $imported++ if $format eq 'cch-update'; #empty file ok @@ -161,6 +194,42 @@ sub batch_import { my $hash = shift; $hash->{'data_vendor'} = 'cch'; + $hash->{'default_location'} =~ s/ //g; + + if (exists($hash->{actionflag}) && $hash->{actionflag} eq 'D') { + delete($hash->{actionflag}); + + my $cust_tax_location = qsearchs('cust_tax_location', $hash); + return "Can't find cust_tax_location to delete: ". + join(" ", map { "$_ => ". $hash->{$_} } @fields) + unless $cust_tax_location; + + my $error = $cust_tax_location->delete; + return $error if $error; + + delete($hash->{$_}) foreach (keys %$hash); + } + + delete($hash->{'actionflag'}); + + ''; + + }; + + } elsif ( $format eq 'cch-zip' || $format eq 'cch-update-zip' ) { + @fields = qw( zip city county state postalcity countyfips countydef default_location geocode cityflag unique ); + push @fields, 'actionflag' if $format eq 'cch-update-zip'; + + $imported++ if $format eq 'cch-update'; #empty file ok + + $hook = sub { + my $hash = shift; + + $hash->{'data_vendor'} = 'cch-zip'; + delete($hash->{$_}) foreach qw( countyfips countydef unique ); + + $hash->{'cityflag'} =~ s/ //g; + $hash->{'default_location'} =~ s/ //g; if (exists($hash->{actionflag}) && $hash->{actionflag} eq 'D') { delete($hash->{actionflag}); @@ -214,7 +283,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 locations" ); die $error if $error; $last = time; @@ -253,7 +322,7 @@ sub batch_import { $dbh->commit or die $dbh->errstr if $oldAutoCommit; - return "Empty file!" unless $imported; + return "Empty file!" unless ( $imported || $format =~ /^cch-update/ ); ''; #no error