diff options
| -rw-r--r-- | FS/FS/Conf.pm | 4 | ||||
| -rw-r--r-- | FS/FS/tax_rate.pm | 13 | ||||
| -rwxr-xr-x | bin/fetch_and_expand_taxes | 55 | ||||
| -rwxr-xr-x | bin/reassemble_taxes | 35 | 
4 files changed, 100 insertions, 7 deletions
| diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 07c25c46a..47555a348 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1677,8 +1677,8 @@ worry that config_items is freeside-specific and icky.    {      'key'         => 'taxdatadirectdownload',      'section'     => 'billing',  #well -    'description' => 'Enable downloading tax data directly from the vendor site', -    'type'        => 'checkbox', +    'description' => 'Enable downloading tax data directly from the vendor site. at least three lines: URL, username, and password.j', +    'type'        => 'textarea',    },    { diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index 58be8cba6..93550b178 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -1398,11 +1398,14 @@ sub process_download_and_update {      eval "use XBase;";      die $@ if $@; -    my $conffile = '%%%FREESIDE_CONF%%%/cchconf'; -    my $conffh = new IO::File "<$conffile" or die "can't open $conffile: $!\n"; -    my ( $urls, $secret, $states ) = -      map { /^(.*)$/ or die "bad config line in $conffile: $_\n"; $1 } -          <$conffh>; +    my $conf = new FS::Conf; +    die "direct download of tax data not enabled\n"  +      unless $conf->exists('taxdatadirectdownload'); +    my ( $urls, $username, $secret, $states ) = +      $conf->config('taxdatadirectdownload'); +    die "No tax download URL provided.  ". +        "Did you set the taxdatadirectdownload configuration value?\n" +      unless $urls;      $dir .= '/cch'; diff --git a/bin/fetch_and_expand_taxes b/bin/fetch_and_expand_taxes new file mode 100755 index 000000000..186d6df8a --- /dev/null +++ b/bin/fetch_and_expand_taxes @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w + +use strict; +use LWP::UserAgent; +use HTTP::Request; +use HTTP::Response; +use FS::UID qw(adminsuidsetup); +use FS::Conf; + +my $user = shift or die &usage; +my $dir = shift or die &usage; + + +adminsuidsetup $user; + +my $conf = new FS::Conf; + +chdir $dir or die "can't change to $dir: $!\n"; + +die "direct download of tax data not enabled\n" +  unless $conf->exists('taxdatadirectdownload'); +my ( $urls, $username, $secret, $states ) = +  $conf->config('taxdatadirectdownload'); +die "No tax download URL provided.  ". +    "Did you set the taxdatadirectdownload configuration value?\n" +  unless $urls; + +my $ua = new LWP::UserAgent; +  foreach my $url (split ',', $urls) { +  my @name = split '/', $url;  #somewhat restrictive +  my $name = pop @name; +  $name =~ /(.*)/; # untaint that which we trust; +  $name = $1; + +  open my $taxfh, ">$name" or die "Can't open $name: $!\n"; + +  my $res = $ua->request( +    new HTTP::Request( GET => $url), +    sub { #my ($data, $response_object) = @_; +          print $taxfh $_[0] or die "Can't write to $dir.new/$name: $!\n"; +    }, +  ); +  die "download of $url failed: ". $res->status_line +    unless $res->is_success; +  close $taxfh; +  $secret =~ /(.*)/; # untaint that which we trust; +  $secret = $1; +  system('unzip', "-P", $secret, $name) == 0 +    or die "unzip -P $secret $name failed"; +} + +sub usage { +  die "Usage:\n\n  fetch_and_expand_taxes user dir\n"; +} + diff --git a/bin/reassemble_taxes b/bin/reassemble_taxes new file mode 100755 index 000000000..001240ba5 --- /dev/null +++ b/bin/reassemble_taxes @@ -0,0 +1,35 @@ +#!/usr/bin/perl -w + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Conf; + +my $user = shift or die &usage; +my $dir = shift or die &usage; + + +adminsuidsetup $user; + +my $conf = new FS::Conf; + +chdir $dir or die "can't change to $dir: $!\n"; +die "pmzclfull.zip already exists\n" if -f 'pmzclfull.zip'; + +die "direct download of tax data not enabled\n" +  unless $conf->exists('taxdatadirectdownload'); +my ( $urls, $username, $secret, $states ) = +  $conf->config('taxdatadirectdownload'); +die "No tax download URL provided.  ". +    "Did you set the taxdatadirectdownload configuration value?\n" +  unless $urls; + +my @filelist = qw( code.dbf detail.dbf geocode.dbf npanxx.dbf plus4.dbf +  txmatrix.dbf zip.dbf ); + +system('zip', "-P", $secret, 'pmzclfull.zip', @filelist) == 0 +  or die "zip failed\n"; + +sub usage { +  die "Usage:\n\n  reassemble_taxes user dir\n"; +} + | 
