4 use vars qw($opt_c $opt_p $opt_t $opt_d $opt_z $opt_f);
7 use FS::UID qw(adminsuidsetup);
10 use FS::cust_tax_location;
12 getopts('c:p:t:d:z:f:');
14 my $user = shift or die &usage;
15 my $dbh = adminsuidsetup $user;
17 my ($format) = $opt_f =~ /^([-\w]+)$/;
20 'CODE', $opt_c, \&FS::tax_class::batch_import,
21 'PLUS4', $opt_p, \&FS::cust_tax_location::batch_import,
22 'ZIP', $opt_z, \&FS::cust_tax_location::batch_import,
23 'TXMATRIX', $opt_t, \&FS::part_pkg_taxrate::batch_import,
24 'DETAIL', $opt_d, \&FS::tax_rate::batch_import,
27 my $oldAutoCommit = $FS::UID::AutoCommit;
28 local $FS::UID::AutoCommit = 0;
33 my ($name, $file, $method) = splice(@list, 0, 3);
37 $file =~ /^([\s\d\w.]+)$/ or die "Illegal filename: $file\n";
41 $f .= '-zip' if $name eq 'ZIP';
43 open $fh, '<', $file or die "can't open $name file: $!\n";
44 $error ||= &{$method}( { filehandle => $fh, 'format' => $f, } );
46 die "error while processing $file: $error" if $error;
51 $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
53 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
56 sub usage { die "Usage:\nimport-tax-rates f FORMAT -c CODEFILE -p PLUS4FILE -z ZIPFILE -t TXMATRIXFILE -d DETAILFILE user\n\n"; }