5 use Date::Parse 'str2time';
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch dbh);
15 my $user = shift or die &usage;
16 adminsuidsetup($user);
17 $FS::UID::AutoCommit = 0;
20 my $conf = FS::Conf->new;
21 my $method = $conf->config('tax_district_method')
22 or die "no tax district lookup method configured.\n";
25 %limit = ( district => '' ) if $opt{'n'};
26 my @location = qsearch( 'cust_location', { disabled => '', %limit } );
28 # breaking the rules somewhat by modifying cust_location records in place
29 # instead of doing a proper package change, but we're not changing the
31 warn scalar(@location)." records found.\n";
32 my $queued = 0; my $updated = 0;
33 foreach my $location (@location) {
35 my $job = FS::queue->new({
36 job => 'FS::geocode_Mixin::process_district_update'
38 my $class = 'FS::cust_location';
39 my $id = $location->locationnum;
40 $error = $job->insert($class, $id);
43 die "error queueing update for $class $id\n";
47 warn "Queued $queued tax district lookups.\n";
51 "Usage:\n\n freeside-tax-district-update [ -n ] user\n\n"
56 freeside-tax-district-update - Update tax district codes from a lookup source.
60 freeside-tax-district-update [ -n ] user
64 Updates the 'district' field for all customers and service locations
65 using an online tax information lookup method. Currently the only
66 one supported is the Washington Department of Revenue sales tax table,
67 and looking up the tax district will create a cust_main_county record
68 with the tax rate for that district.
70 The -n option tells the script to ignore customers and locations that
71 already have a district code.
73 The actual lookup operation will run from the job queue.