[freeside-commits] freeside/FS/FS Misc.pm, 1.32, 1.33 Schema.pm, 1.115, 1.116 cust_main.pm, 1.387, 1.388 cust_tax_location.pm, 1.3, 1.4 part_pkg_taxrate.pm, 1.5, 1.6 tax_class.pm, 1.4, 1.5 tax_rate.pm, 1.11, 1.12
Jeff Finucane,420,,
jeff at wavetail.420.am
Tue Dec 2 17:42:27 PST 2008
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv27042/FS/FS
Modified Files:
Misc.pm Schema.pm cust_main.pm cust_tax_location.pm
part_pkg_taxrate.pm tax_class.pm tax_rate.pm
Log Message:
support zip5 tax lookups, correct errors with fixed format cch import, inital import performance improvements, noise reduction on imports, tool for inital import
Index: cust_tax_location.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_tax_location.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cust_tax_location.pm 19 Nov 2008 14:55:59 -0000 1.3
+++ cust_tax_location.pm 3 Dec 2008 01:42:25 -0000 1.4
@@ -113,15 +113,33 @@
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', [ '', ' ', 'Y' ] ) # wtf?
+ || $self->ut_enum('cityflag', [ '', 'I', 'O', 'B' ] )
+ || $self->ut_alpha('geocode')
;
return $error if $error;
+ #ugh! cch canada weirdness
+ if ($self->state eq 'CN') {
+ $error = "Illegal cch canadian zip"
+ unless $self->zip =~ /^[A-Z]$/;
+ } else {
+ $error = $self->ut_number('zip', $self->state eq 'CN' ? 'CA' : 'US');
+ }
+ return $error if $error;
+
+ #ugh! cch canada weirdness
+ return "must specify either city/county or plus4lo/plus4hi"
+ unless ( $self->plus4lo && $self->plus4hi ||
+ ($self->city || $self->state eq 'CN') && $self->county
+ );
+
$self->SUPER::check;
}
@@ -138,15 +156,24 @@
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;
}
@@ -182,6 +209,38 @@
};
+ } elsif ( $format eq 'cch-zip' || $format eq 'cch-update-zip' ) {
+ @fields = qw( zip city county state postalcity countyfips countydef default geocode cityflag unique );
+ push @fields, 'actionflag' if $format eq 'cch-update';
+
+ $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 );
+
+ 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 'extended' ) {
die "unimplemented\n";
@fields = qw( );
Index: tax_rate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tax_rate.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- tax_rate.pm 19 Nov 2008 14:55:59 -0000 1.11
+++ tax_rate.pm 3 Dec 2008 01:42:25 -0000 1.12
@@ -570,14 +570,22 @@
}
my $actionflag = delete($hash->{'actionflag'});
+
+ $hash->{'taxname'} =~ s/`/'/g;
+ $hash->{'taxname'} =~ s|\\|/|g;
+
+ return '' if $format eq 'cch'; # but not cch-update
+
if ($actionflag eq 'I') {
- $insert{ $hash->{'geocode'}. ':'. $hash->{'taxclassnum'} } = $hash;
+ $insert{ $hash->{'geocode'}. ':'. $hash->{'taxclassnum'} } = { %$hash };
}elsif ($actionflag eq 'D') {
- $delete{ $hash->{'geocode'}. ':'. $hash->{'taxclassnum'} } = $hash;
+ $delete{ $hash->{'geocode'}. ':'. $hash->{'taxclassnum'} } = { %$hash };
}else{
return "Unexpected action flag: ". $hash->{'actionflag'};
}
+ delete($hash->{$_}) for keys %$hash;
+
'';
};
@@ -641,6 +649,18 @@
return $error;
}
+ if (scalar(keys %tax_rate)) { #inserts only, not updates for cch
+
+ my $tax_rate = new FS::tax_rate( \%tax_rate );
+ $error = $tax_rate->insert;
+
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't insert tax_rate for $line: $error";
+ }
+
+ }
+
$imported++;
}
@@ -765,23 +785,30 @@
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
my $error = '';
+ my $have_location = 0;
my @list = ( 'CODE', 'codefile', \&FS::tax_class::batch_import,
'PLUS4', 'plus4file', \&FS::cust_tax_location::batch_import,
+ 'ZIP', 'zipfile', \&FS::cust_tax_location::batch_import,
'TXMATRIX', 'txmatrix', \&FS::part_pkg_taxrate::batch_import,
'DETAIL', 'detail', \&FS::tax_rate::batch_import,
);
while( scalar(@list) ) {
my ($name, $file, $import_sub) = (shift @list, shift @list, shift @list);
unless ($files{$file}) {
+ next if $name eq 'PLUS4';
$error = "No $name supplied";
+ $error = "Neither PLUS4 nor ZIP supplied"
+ if ($name eq 'ZIP' && !$have_location);
next;
}
+ $have_location = 1 if $name eq 'PLUS4';
+ my $fmt = $format. ( $name eq 'ZIP' ? '-zip' : '' );
my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc;
my $filename = "$dir/". $files{$file};
open my $fh, "< $filename" or $error ||= "Can't open $name file: $!";
- $error ||= &{$import_sub}({ 'filehandle' => $fh, 'format' => $format }, $job);
+ $error ||= &{$import_sub}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
close $fh;
unlink $filename or warn "Can't delete $filename: $!";
}
@@ -804,12 +831,23 @@
my @list = ( 'CODE', 'codefile', \&FS::tax_class::batch_import,
'PLUS4', 'plus4file', \&FS::cust_tax_location::batch_import,
+ 'ZIP', 'zipfile', \&FS::cust_tax_location::batch_import,
'TXMATRIX', 'txmatrix', \&FS::part_pkg_taxrate::batch_import,
);
my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc;
while( scalar(@list) ) {
my ($name, $file, $import_sub) = (shift @list, shift @list, shift @list);
unless ($files{$file}) {
+ my $vendor = $name eq 'ZIP' ? 'cch' : 'cch-zip';
+ next # update expected only for previously installed location data
+ if ( ($name eq 'PLUS4' || $name eq 'ZIP')
+ && !scalar( qsearch( { table => 'cust_tax_location',
+ hashref => { data_vendor => $vendor },
+ select => 'DISTINCT data_vendor',
+ } )
+ )
+ );
+
$error = "No $name supplied";
next;
}
@@ -849,9 +887,10 @@
my ($name, $file, $import_sub) =
(shift @insert_list, shift @insert_list, shift @insert_list);
+ my $fmt = $format. ( $name eq 'ZIP' ? '-zip' : '' );
open my $fh, "< $file" or $error ||= "Can't open $name file $file: $!";
$error ||=
- &{$import_sub}({ 'filehandle' => $fh, 'format' => $format }, $job);
+ &{$import_sub}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
close $fh;
unlink $file or warn "Can't delete $file: $!";
}
@@ -871,9 +910,10 @@
my ($name, $file, $import_sub) =
(shift @delete_list, shift @delete_list, shift @delete_list);
+ my $fmt = $format. ( $name eq 'ZIP' ? '-zip' : '' );
open my $fh, "< $file" or $error ||= "Can't open $name file $file: $!";
$error ||=
- &{$import_sub}({ 'filehandle' => $fh, 'format' => $format }, $job);
+ &{$import_sub}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
close $fh;
unlink $file or warn "Can't delete $file: $!";
}
Index: Misc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Misc.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- Misc.pm 19 Nov 2008 14:55:58 -0000 1.32
+++ Misc.pm 3 Dec 2008 01:42:25 -0000 1.33
@@ -799,7 +799,7 @@
my $template = join('', map {$total += $_; "A$_"} @$lengths) if $lengths;
my $dir = "%%%FREESIDE_CACHE%%%/cache.$FS::UID::datasrc";
- my $fh = new File::Temp( TEMPLATE => "CODE.csv.XXXXXXXX",
+ my $fh = new File::Temp( TEMPLATE => "FILE.csv.XXXXXXXX",
DIR => $dir,
UNLINK => 0,
) or return "can't open temp file: $!\n"
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.387
retrieving revision 1.388
diff -u -d -r1.387 -r1.388
--- cust_main.pm 22 Nov 2008 22:17:26 -0000 1.387
+++ cust_main.pm 3 Dec 2008 01:42:25 -0000 1.388
@@ -1262,6 +1262,7 @@
|| $self->ut_textn('stateid')
|| $self->ut_textn('stateid_state')
|| $self->ut_textn('invoice_terms')
+ || $self->ut_alphan('geocode')
;
#barf. need message catalogs. i18n. etc.
@@ -5227,6 +5228,9 @@
sub geocode {
my ($self, $data_vendor) = (shift, shift); #always cch for now
+ my $geocode = $self->get('geocode'); #XXX only one data_vendor for geocode
+ return $geocode if $geocode;
+
my $prefix = ( $conf->exists('tax-ship_address') && length($self->ship_last) )
? 'ship_'
: '';
@@ -5237,7 +5241,6 @@
#CCH specific location stuff
my $extra_sql = "AND plus4lo <= '$plus4' AND plus4hi >= '$plus4'";
- my $geocode = '';
my @cust_tax_location =
qsearch( {
'table' => 'cust_tax_location',
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- Schema.pm 22 Nov 2008 22:17:26 -0000 1.115
+++ Schema.pm 3 Dec 2008 01:42:25 -0000 1.116
@@ -648,6 +648,7 @@
'paystate', 'varchar', 'NULL', $char_d, '', '',
'paytype', 'varchar', 'NULL', $char_d, '', '',
'payip', 'varchar', 'NULL', 15, '', '',
+ 'geocode', 'varchar', 'NULL', 20, '', '',
'tax', 'char', 'NULL', 1, '', '',
'otaker', 'varchar', '', 32, '', '',
'refnum', 'int', '', '', '', '',
@@ -754,11 +755,15 @@
'columns' => [
'custlocationnum', 'serial', '', '', '', '',
'data_vendor', 'varchar', 'NULL', $char_d, '', '', # update source
+ 'city', 'varchar', 'NULL', $char_d, '', '',
+ 'postalcity', 'varchar', 'NULL', $char_d, '', '',
+ 'county', 'varchar', 'NULL', $char_d, '', '',
'zip', 'char', '', 5, '', '',
'state', 'char', '', 2, '', '',
- 'plus4hi', 'char', '', 4, '', '',
- 'plus4lo', 'char', '', 4, '', '',
+ 'plus4hi', 'char', 'NULL', 4, '', '',
+ 'plus4lo', 'char', 'NULL', 4, '', '',
'default_location','char', 'NULL', 1, '', '', # Y = default for zip
+ 'cityflag', 'char', 'NULL', 1, '', '', # I(n)/O(out)/B(oth)/NULL
'geocode', 'varchar', '', 20, '', '',
],
'primary_key' => 'custlocationnum',
Index: tax_class.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tax_class.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- tax_class.pm 19 Nov 2008 14:55:59 -0000 1.4
+++ tax_class.pm 3 Dec 2008 01:42:25 -0000 1.5
@@ -158,7 +158,7 @@
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;
}
Index: part_pkg_taxrate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg_taxrate.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- part_pkg_taxrate.pm 19 Nov 2008 14:55:59 -0000 1.5
+++ part_pkg_taxrate.pm 3 Dec 2008 01:42:25 -0000 1.6
@@ -244,7 +244,7 @@
unless ($part_pkg_taxproduct) {
return "Can't find part_pkg_taxproduct for txmatrix deletion: ".
join(" ", map { "$_ => ". $hash->{$_} } @fields)
- if $hash->{'actionflag'} eq 'D';
+ if ($hash->{'actionfield'} && $hash->{'actionflag'} eq 'D');
$part_pkg_taxproduct{'description'} =
join(' : ', (map{ $hash->{$_} } qw(groupdesc itemdesc)),
@@ -279,7 +279,9 @@
return "Can't find tax class for txmatrix deletion: ".
join(" ", map { "$_ => ". $hash->{$_} } @fields)
- if ($hash->{'actionflag'} eq 'D' && !$tax_class && $class ne ':');
+ if ( $hash->{'actionflag'} && $hash->{'actionflag'} eq 'D' &&
+ !$tax_class && $class ne ':'
+ );
delete($hash->{$_}) foreach @{$map{$item}};
}
More information about the freeside-commits
mailing list