3 Provide js function in support of a lookup hook for wa_state_tax_districts
5 wa_state_tax_district()
6 * Checks form_address_info() to collect address data
7 * If any addresses are in Washington State,
8 * Uses misc/xmlhttp-wa_state-find_district_for_address.html to query
9 wa state tax districting database
10 * Displays error, or updates the district input element for the addresses
11 * Calls submit_continue() upon success
12 * Calls submit_abort() upon error
16 function wa_state_tax_district() {
17 // Queries the WA State API to get a Tax District for this address
18 // upon failure: User can choose to skip or cancel
19 // upon success: set value of district input box and submit_continue()
21 address_info = form_address_info();
22 // console.log( address_info );
25 address_info['state'] != 'WA'
26 && address_info['state'] != 'wa'
27 && address_info['bill_state'] != 'WA'
28 && address_info['bill_state'] != 'wa'
32 address_info['ship_state'] != 'WA'
33 && address_info['ship_state'] != 'wa'
37 // nothing to do, not in Washington state
42 wa_state_tax_district_overlib( 'Looking up tax district... please wait...' );
45 url: "<% $fsurl %>misc/xmlhttp-wa_state-find_district_for_address.html",
47 success: function(response) {
48 // console.log(response);
51 if ( response['error'] ) {
52 error = error + response['error'] + ' ';
55 // populate Billing Address district into form, or record error
56 if ( response['bill'] && response['bill']['district'] ) {
57 $('#bill_district').val( response['bill']['district'] );
59 else if ( response['bill'] && response['bill']['error'] ) {
60 error = error + 'Cound not set tax district for billing address. ';
63 // populate Shipping Address district into form, or record error
65 ! address_info['same']
67 && response['ship']['district']
69 $('#ship_district').val( response['ship']['district'] );
72 ! address_info['same']
74 && response['ship']['error']
76 error = error + 'Could not set tax district for service address. ';
79 // populate Plain Address district into form, or record error
82 && response['address']['district']
84 $('#district').val( response['address']['district'] );
88 && response['address']['error']
90 error = error + 'Could not set tax district for address. ';
94 wa_state_tax_district_overlib(
95 'An error occured determining Washington state tax district:<br>'
99 + 'If you choose to skip this step, taxes will not be calculated '
100 + 'for this customer, unless you enter a tax district manually.'
102 + '<a href="https://webgis.dor.wa.gov/taxratelookup/SalesTax.aspx" target="_blank">See WA Dept of Revenue</a>'
114 wa_state_tax_district_overlib(
115 'A network error occured determining Washington state tax district:<br>'
117 + 'If you choose to skip this step, taxes will not be calculated '
118 + 'for this customer, unless you enter a tax district manually.'
120 + '<a href="https://webgis.dor.wa.gov/taxratelookup/SalesTax.aspx" target="_blank">See WA Dept of Revenue</a>'
125 function wa_state_tax_district_overlib(html) {
127 '<div style="text-align: center;">'
128 + '<h2>Washington State Tax District Lookup</h2>'
129 + '<p>' + html + '</p>'
130 + '<a href="#" onclick="wa_state_tax_district_skip()">skip</a>'
132 + '<a href="#" onclick="wa_state_tax_district_cancel()">cancel</a>'
137 CAPTION, 'WA State Tax District',
149 function wa_state_tax_district_skip() {
150 // Click target to skip tax district determination
155 function wa_state_tax_district_cancel() {
156 // Click target to cancel submit from tax district determination