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/elements | |
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/elements')
-rw-r--r-- | httemplate/elements/tr-select-cust_location.html | 1 | ||||
-rw-r--r-- | httemplate/elements/wa_state_tax_district.js | 159 |
2 files changed, 160 insertions, 0 deletions
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, &> <SCRIPT TYPE="text/javascript"> diff --git a/httemplate/elements/wa_state_tax_district.js b/httemplate/elements/wa_state_tax_district.js new file mode 100644 index 000000000..03f262b52 --- /dev/null +++ b/httemplate/elements/wa_state_tax_district.js @@ -0,0 +1,159 @@ +<%doc> + +Provide js function in support of a lookup hook for wa_state_tax_districts + +wa_state_tax_district() +* Checks form_address_info() to collect address data +* If any addresses are in Washington State, +* Uses misc/xmlhttp-wa_state-find_district_for_address.html to query + wa state tax districting database +* Displays error, or updates the district input element for the addresses +* Calls submit_continue() upon success +* Calls submit_abort() upon error + +</%doc> + +function wa_state_tax_district() { + // Queries the WA State API to get a Tax District for this address + // upon failure: User can choose to skip or cancel + // upon success: set value of district input box and submit_continue() + + address_info = form_address_info(); + // console.log( address_info ); + + if ( + address_info['state'] != 'WA' + && address_info['state'] != 'wa' + && address_info['bill_state'] != 'WA' + && address_info['bill_state'] != 'wa' + && ( + address_info['same'] + || ( + address_info['ship_state'] != 'WA' + && address_info['ship_state'] != 'wa' + ) + ) + ) { + // nothing to do, not in Washington state + submit_continue(); + return; + } + + wa_state_tax_district_overlib( 'Looking up tax district... please wait...' ); + + $.post({ + url: "<% $fsurl %>misc/xmlhttp-wa_state-find_district_for_address.html", + data: address_info, + success: function(response) { + // console.log(response); + + let error = ''; + if ( response['error'] ) { + error = error + response['error'] + ' '; + } + + // populate Billing Address district into form, or record error + if ( response['bill'] && response['bill']['district'] ) { + $('#bill_district').val( response['bill']['district'] ); + } + else if ( response['bill'] && response['bill']['error'] ) { + error = error + 'Cound not set tax district for billing address. '; + } + + // populate Shipping Address district into form, or record error + if ( + ! address_info['same'] + && response['ship'] + && response['ship']['district'] + ) { + $('#ship_district').val( response['ship']['district'] ); + } + else if ( + ! address_info['same'] + && response['ship'] + && response['ship']['error'] + ) { + error = error + 'Could not set tax district for service address. '; + } + + // populate Plain Address district into form, or record error + if ( + response['address'] + && response['address']['district'] + ) { + $('#district').val( response['address']['district'] ); + } + else if ( + response['address'] + && response['address']['error'] + ) { + error = error + 'Could not set tax district for address. '; + } + + if ( error ) { + wa_state_tax_district_overlib( + 'An error occured determining Washington state tax district:<br>' + + '<br>' + + error + '<br>' + + '<br>' + + 'If you choose to skip this step, taxes will not be calculated ' + + 'for this customer, unless you enter a tax district manually.' + + '<br>' + + '<a href="https://webgis.dor.wa.gov/taxratelookup/SalesTax.aspx" target="_blank">See WA Dept of Revenue</a>' + ); + } + else { + cClick(); + submit_continue(); + return; + } + + } + }) + .fail(function() { + wa_state_tax_district_overlib( + 'A network error occured determining Washington state tax district:<br>' + + '<br>' + + 'If you choose to skip this step, taxes will not be calculated ' + + 'for this customer, unless you enter a tax district manually.' + + '<br>' + + '<a href="https://webgis.dor.wa.gov/taxratelookup/SalesTax.aspx" target="_blank">See WA Dept of Revenue</a>' + ); + }); +} + +function wa_state_tax_district_overlib(html) { + html = + '<div style="text-align: center;">' + + '<h2>Washington State Tax District Lookup</h2>' + + '<p>' + html + '</p>' + + '<a href="#" onclick="wa_state_tax_district_skip()">skip</a>' + + ' | ' + + '<a href="#" onclick="wa_state_tax_district_cancel()">cancel</a>' + + '</div>'; + + overlib( + html, + CAPTION, 'WA State Tax District', + STICKY, + CLOSETEXT, '', + MIDX, 0, + MIDY, 0, + WIDTH, 500, + BGCOLOR, '#339', + CGCOLOR, '#339', + TEXTSIZE, 3 + ); +} + +function wa_state_tax_district_skip() { + // Click target to skip tax district determination + cClick() + submit_continue(); +} + +function wa_state_tax_district_cancel() { + // Click target to cancel submit from tax district determination + cClick() + submit_abort(); +} |