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_main', \%limit ),
27 qsearch( 'cust_location', { disabled => '', %limit } );
29 # breaking the rules somewhat by modifying cust_location records in place
30 # instead of doing a proper package change, but we're not changing the
32 warn scalar(@location)." records found.\n";
33 my $queued = 0; my $updated = 0;
34 foreach my $location (@location) {
36 my $job = FS::queue->new({
37 job => 'FS::geocode_Mixin::process_district_update'
39 my $class = ref($location);
40 my $id = $class eq 'FS::cust_main' ?
42 $location->locationnum;
43 $error = $job->insert($class, $id);
46 die "error queueing update for $class $id\n";
50 warn "Queued $queued tax district lookups.\n";
54 "Usage:\n\n freeside-tax-district-update [ -n ] user\n\n"
59 freeside-tax-district-update - Update tax district codes from a lookup source.
63 freeside-tax-district-update [ -n ] user
67 Updates the 'district' field for all customers and service locations
68 using an online tax information lookup method. Currently the only
69 one supported is the Washington Department of Revenue sales tax table,
70 and looking up the tax district will create a cust_main_county record
71 with the tax rate for that district.
73 The -n option tells the script to ignore customers and locations that
74 already have a district code.
76 The actual lookup operation will run from the job queue.