From: Mitch Jackson Date: Sat, 19 Jan 2019 12:41:08 +0000 (-0500) Subject: RT# 80488 Live look up of WA state tax district X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=569f676f4a06512a46120e12edc6a6410e93ff93 RT# 80488 Live look up of WA state tax district When conf flag 'tax_district_method' is set, tax district is queried for address before form is submitted Affected Pages: * New Customer * Edit Customer * Order Package * Change Package * Edit Package Location --- diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index fee77a8b1..63492dd33 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -265,8 +265,15 @@ sub insert { return $error; } - #false laziness with cust_main, will go away eventually - if ( !$import and $conf->config('tax_district_method') ) { + # If using tax_district_method, for rows in state of Washington, + # without a tax district already specified, queue a job to find + # the tax district + if ( + !$import + && !$self->district + && lc $self->state eq 'wa' + && $conf->config('tax_district_method') + ) { my $queue = new FS::queue { 'job' => 'FS::geocode_Mixin::process_district_update' @@ -990,7 +997,11 @@ sub _upgrade_data { die "$error (fixing whitespace in $field, locationnum ".$location->locationnum.')' if $error; - if ( $use_districts ) { + if ( + $use_districts + && !$location->district + && lc $location->state eq 'wa' + ) { my $queue = new FS::queue { 'job' => 'FS::geocode_Mixin::process_district_update' }; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index cc0e83f23..920f4d413 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -743,20 +743,6 @@ sub insert { } } - # FS::geocode_Mixin::after_insert or something? - if ( $conf->config('tax_district_method') and !$import ) { - # if anything non-empty, try to look it up - my $queue = new FS::queue { - 'job' => 'FS::geocode_Mixin::process_district_update', - 'custnum' => $self->custnum, - }; - my $error = $queue->insert( ref($self), $self->custnum ); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "queueing tax district update: $error"; - } - } - # cust_main exports! warn " exporting\n" if $DEBUG > 1; diff --git a/httemplate/edit/cust_location.cgi b/httemplate/edit/cust_location.cgi index 38816db7a..93311c5c3 100755 --- a/httemplate/edit/cust_location.cgi +++ b/httemplate/edit/cust_location.cgi @@ -17,10 +17,21 @@ ACTION="<% $p %>edit/process/cust_location.cgi" METHOD=POST> &> <& /elements/standardize_locations.html, 'form' => 'EditLocationForm', - 'callback' => 'document.EditLocationForm.submit();', + 'callback' => $conf->exists('tax_district_method') + ? 'wa_state_tax_district()' + : 'submit_continue()', 'with_census' => 1, 'with_census_functions' => 1, &> +
diff --git a/httemplate/edit/cust_main/bottomfixup.js b/httemplate/edit/cust_main/bottomfixup.js index 97816aad7..d2a277b2f 100644 --- a/httemplate/edit/cust_main/bottomfixup.js +++ b/httemplate/edit/cust_main/bottomfixup.js @@ -7,6 +7,9 @@ my $company_longitude = $conf->config('company_longitude'); my @fixups = ('standardize_locations'); +push @fixups, 'wa_state_tax_district' + if $conf->exists('tax_district_method'); + push @fixups, 'confirm_censustract_bill', 'confirm_censustract_ship' if $conf->exists('cust_main-require_censustract'); @@ -57,6 +60,8 @@ function do_submit() { 'with_census' => 1, # no with_firm, apparently &> +<& /elements/wa_state_tax_district.js &> + % # the value in pre+'censustract' is the confirmed censustract (either from % # the previous saved record, or from address standardization (if the backend % # supports it), or from an aborted previous submit. only need to reconfirm diff --git a/httemplate/elements/tr-select-cust_location.html b/httemplate/elements/tr-select-cust_location.html index 7a2d886d3..1e6cf5b7f 100644 --- a/httemplate/elements/tr-select-cust_location.html +++ b/httemplate/elements/tr-select-cust_location.html @@ -202,6 +202,7 @@ Example: 'alt_format' => $opt{'alt_format'}, 'enable_coords' => 1, 'enable_censustract' => 1, + 'enable_district' => $conf->exists('tax_district_method') ? 1 : 0, &> + " diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html index 1efe7456e..7a63b5c2b 100644 --- a/httemplate/misc/order_pkg.html +++ b/httemplate/misc/order_pkg.html @@ -188,11 +188,23 @@ <& /elements/standardize_locations.html, 'form' => "OrderPkgForm", - 'callback' => 'document.OrderPkgForm.submit()', + 'callback' => $conf->exists('tax_district_method') + ? 'wa_state_tax_district()' + : 'submit_continue()', 'with_census' => 1, 'with_census_functions' => 1, &> + + % } % if ($quotationnum) { diff --git a/httemplate/misc/xmlhttp-wa_state-find_district_for_address.html b/httemplate/misc/xmlhttp-wa_state-find_district_for_address.html new file mode 100644 index 000000000..e59789bd1 --- /dev/null +++ b/httemplate/misc/xmlhttp-wa_state-find_district_for_address.html @@ -0,0 +1,76 @@ +<%doc> + +Expects POST keys: +* address1 +* address2 +* city +* state +* zip +* country + +Also accepts all the above keys with the prefixes bill_ and ship_ + +Returns json with a key for each given address, e.g., whose value is +the tax district number. e.g. +{ + address: { + district: 1234 + tax: 7.9 + exempt_amount: 0 + city: MOXEE CITY + state: WA + }, + bill: { + error: district not found + district: + }, +} + + +<% encode_json($return) %> +<%init> +use Data::Dumper; +use FS::Misc::Geo; + +http_header('Content-Type' => 'application/json'); + +my $DEBUG = 0; +my %param = ( $cgi->Vars ); +my $return = {}; + +warn '$param: '.Dumper( \%param )."\n" + if $DEBUG; + +my %address; +for my $prefix ( '', 'bill', 'ship' ) { + my $addr_key = $prefix || 'address'; + $address{$addr_key} = {}; + $address{$addr_key}->{$_} = $param{ $prefix ? "${prefix}_${_}" : $_ } + for qw/ address1 address2 city state zip country /; + delete $address{$addr_key} + unless $address{$addr_key}->{address1} + && $address{$addr_key}->{city}; +} +warn Dumper( \%address ) + if $DEBUG; + +for my $k ( keys %address ) { + next unless lc $address{$k}->{state} eq 'wa'; + my $response = FS::Misc::Geo::wa_sales( $address{$k} ); + warn Dumper( $response ) + if $DEBUG; + + if ( ref $response ) { + $return->{$k} = $response; + } else { + $return->{$k} = { error => 'Lookup Failed' }; + } +} + +unless ( keys %$return ) { + $return->{error} = 'No WA addresses passed for lookup - nothing to do'; +} + +warn '$return: '.Dumper( $return )."\n" + if $DEBUG; +