summaryrefslogtreecommitdiff
path: root/httemplate/misc
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2019-01-19 07:41:08 -0500
committerMitch Jackson <mitch@freeside.biz>2019-01-19 08:57:32 -0500
commit569f676f4a06512a46120e12edc6a6410e93ff93 (patch)
treefa6d58552c6d34b24cb7daf8a29430b70e8db2a8 /httemplate/misc
parent39fe6499bd38e6e7c468f549b1d4919a7cf2c44d (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')
-rwxr-xr-xhttemplate/misc/change_pkg.cgi14
-rw-r--r--httemplate/misc/order_pkg.html14
-rw-r--r--httemplate/misc/xmlhttp-wa_state-find_district_for_address.html76
3 files changed, 102 insertions, 2 deletions
diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi
index c588c9e6c..9729c6b5f 100755
--- a/httemplate/misc/change_pkg.cgi
+++ b/httemplate/misc/change_pkg.cgi
@@ -119,9 +119,21 @@
'form' => "OrderPkgForm",
'with_census' => 1,
'with_census_functions' => 1,
- 'callback' => 'document.OrderPkgForm.submit()',
+ 'callback' => $conf->exists('tax_district_method')
+ ? 'wa_state_tax_district()'
+ : 'submit_continue()',
&>
+<script>
+ <& /elements/wa_state_tax_district.js &>
+
+ // wa_sate_tax_district() will call submit_continue() upon success,
+ // or submit_abort() upon error
+ function submit_continue() {
+ document.OrderPkgForm.submit();
+ }
+</script>
+
<INPUT NAME = "submitButton"
TYPE = "button"
VALUE = "<% mt("Change package") |h %>"
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,
&>
+ <script>
+ <& /elements/wa_state_tax_district.js &>
+
+ // wa_sate_tax_district() will call submit_continue() upon success,
+ // or submit_abort() upon error
+ function submit_continue() {
+ document.OrderPkgForm.submit();
+ }
+ </script>
+
% }
% 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:
+ },
+}
+
+</%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>