diff options
author | Mitch Jackson <mitch@freeside.biz> | 2019-01-19 07:41:08 -0500 |
---|---|---|
committer | Mitch Jackson <mitch@freeside.biz> | 2019-01-19 08:57:32 -0500 |
commit | 569f676f4a06512a46120e12edc6a6410e93ff93 (patch) | |
tree | fa6d58552c6d34b24cb7daf8a29430b70e8db2a8 /httemplate/misc/xmlhttp-wa_state-find_district_for_address.html | |
parent | 39fe6499bd38e6e7c468f549b1d4919a7cf2c44d (diff) |
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
Diffstat (limited to 'httemplate/misc/xmlhttp-wa_state-find_district_for_address.html')
-rw-r--r-- | httemplate/misc/xmlhttp-wa_state-find_district_for_address.html | 76 |
1 files changed, 76 insertions, 0 deletions
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: + }, +} + +</%doc> +<% 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; +</%init> |