summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorjeff <jeff>2009-07-13 16:02:32 +0000
committerjeff <jeff>2009-07-13 16:02:32 +0000
commitb6a644c59f47d0a890c2f3122d362a72958fbc58 (patch)
tree6e3df8a3f468b636fa73a058890734ff8f303b0d /FS
parent3cb93a3aa0af9f004b7ee122bdf5c1daf5f1289c (diff)
correct ordering and other bugs in tax updates
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/tax_rate.pm45
-rw-r--r--FS/FS/tax_rate_location.pm21
2 files changed, 55 insertions, 11 deletions
diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm
index 9a25f947b..d55b09b22 100644
--- a/FS/FS/tax_rate.pm
+++ b/FS/FS/tax_rate.pm
@@ -917,6 +917,7 @@ sub process_batch_import {
my $error = '';
my @insert_list = ();
my @delete_list = ();
+ my @predelete_list = ();
my @list = ( 'GEOCODE', 'geofile', \&FS::tax_rate_location::batch_import,
'CODE', 'codefile', \&FS::tax_class::batch_import,
@@ -972,9 +973,26 @@ sub process_batch_import {
close $dfh;
push @insert_list, $name, $ifh->filename, $import_sub;
- unshift @delete_list, $name, $dfh->filename, $import_sub;
+ if ( $name eq 'GEOCODE' ) { #handle this whole ordering issue better
+ unshift @predelete_list, $name, $dfh->filename, $import_sub;
+ } else {
+ unshift @delete_list, $name, $dfh->filename, $import_sub;
+ }
}
+
+ while( scalar(@predelete_list) ) {
+ my ($name, $file, $import_sub) =
+ (shift @predelete_list, shift @predelete_list, shift @predelete_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' => $fmt }, $job);
+ close $fh;
+ unlink $file or warn "Can't delete $file: $!";
+ }
+
while( scalar(@insert_list) ) {
my ($name, $file, $import_sub) =
(shift @insert_list, shift @insert_list, shift @insert_list);
@@ -1316,7 +1334,7 @@ sub process_download_and_update {
if (-d $dir) {
if (-d "$dir.4") {
- opendir(my $dirh, $dir) or die "failed to open $dir.4: $!\n";
+ opendir(my $dirh, "$dir.4") or die "failed to open $dir.4: $!\n";
foreach my $file (readdir($dirh)) {
unlink "$dir.4/$file" if (-f "$dir.4/$file");
}
@@ -1426,6 +1444,7 @@ sub process_download_and_update {
my @insert_list = ();
my @delete_list = ();
+ my @predelete_list = ();
my @list = (
'geocode', \&FS::tax_rate_location::batch_import,
@@ -1491,13 +1510,31 @@ sub process_download_and_update {
%oldlines = ();
push @insert_list, $name, $ifh->filename, $method;
- unshift @delete_list, $name, $dfh->filename, $method
- unless $name eq 'detail';
+ if ( $name eq 'geocode' ) {
+ unshift @predelete_list, $name, $dfh->filename, $method
+ unless $name eq 'detail';
+ } else {
+ unshift @delete_list, $name, $dfh->filename, $method
+ unless $name eq 'detail';
+ }
close $dfh;
close $ifh;
}
+ while( scalar(@predelete_list) ) {
+ my ($name, $file, $method) =
+ (shift @predelete_list, shift @predelete_list, shift @predelete_list);
+
+ my $fmt = "$format-update";
+ $fmt = $fmt. ( $name eq 'zip' ? '-zip' : '' );
+ open my $fh, "< $file" or $error ||= "Can't open $name file $file: $!";
+ $error ||=
+ &{$method}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
+ close $fh;
+ #unlink $file or warn "Can't delete $file: $!";
+ }
+
while( scalar(@insert_list) ) {
my ($name, $file, $method) =
(shift @insert_list, shift @insert_list, shift @insert_list);
diff --git a/FS/FS/tax_rate_location.pm b/FS/FS/tax_rate_location.pm
index 0e0dafebb..218ed977b 100644
--- a/FS/FS/tax_rate_location.pm
+++ b/FS/FS/tax_rate_location.pm
@@ -125,11 +125,18 @@ sub check {
;
return $error if $error;
- my $t = qsearchs( 'tax_rate_location',
- { map { $_ => $self->$_ } qw( data_vendor geocode ) },
- );
-
- return "geocode already in use for this vendor"
+ my $t;
+ $t = qsearchs( 'tax_rate_location',
+ { disabled => '',
+ ( map { $_ => $self->$_ } qw( data_vendor geocode ) ),
+ },
+ )
+ unless $self->disabled;
+
+ $t = $self->by_key( $self->taxratelocationnum )
+ if ( !$t && $self->taxratelocationnum );
+
+ return "geocode ". $self->geocode. " already in use for this vendor"
if ( $t && $t->taxratelocationnum != $self->taxratelocationnum );
return "may only be disabled"
@@ -194,7 +201,7 @@ sub batch_import {
if (exists($hash->{'actionflag'}) && $hash->{'actionflag'} eq 'D') {
delete($hash->{actionflag});
- $hash->{deleted} = '';
+ $hash->{disabled} = '';
my $tax_rate_location = qsearchs('tax_rate_location', $hash);
return "Can't find tax_rate_location to delete: ".
join(" ", map { "$_ => ". $hash->{$_} } @fields)
@@ -279,7 +286,7 @@ sub batch_import {
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "can't insert tax_rate for $line: $error";
+ return "can't insert tax_rate_location for $line: $error";
}
}