tax engine refactoring for Avalara and Billsoft tax vendors, #25718
[freeside.git] / httemplate / elements / standardize_locations.js
index cea59b8..817a2e3 100644 (file)
@@ -11,26 +11,14 @@ function form_address_info() {
 % if ( $billship ) {
   returnobj['same'] = cf.elements['same'].checked;
 % }
-% if ( $withcensus ) {
-% # "entered" censustract always goes with the ship_ address if there is one
-%   if ( $billship ) {
-    returnobj['ship_censustract'] = cf.elements['enter_censustract'].value;
-%   } else { # there's only a package address, so it's just "censustract"
-    returnobj['censustract'] = cf.elements['enter_censustract'].value;
-%   }
-% }
 % for my $pre (@prefixes) {
-  if ( <% $pre eq 'ship_' ? 1 : 0 %> && returnobj['same'] ) {
-%   # special case: don't include any ship_ fields, and move the entered
-%   # censustract over to bill_.
-    returnobj['bill_censustract'] = returnobj['ship_censustract'];
-    delete returnobj['ship_censustract'];
-  } else {
 %   # normal case
 %   for my $field (qw(address1 address2 city state zip country)) {
     returnobj['<% $pre %><% $field %>'] = cf.elements['<% $pre %><% $field %>'].value;
 %   } #for $field
-  } // if returnobj['same']
+%   if ( $withcensus ) {
+    returnobj['<% $pre %>censustract'] = cf.elements['<% $pre %>enter_censustract'].value;
+%   }
 % } #foreach $pre
 
   return returnobj;
@@ -181,24 +169,17 @@ function confirm_manual_address() {
 %# not much to do in this case, just confirm the censustract
 % if ( $withcensus ) {
   var cf = document.<% $formname %>;
-%   if ( $billship ) {
-  if ( cf.elements['same'] && cf.elements['same'].checked ) {
-    cf.elements['bill_censustract'].value =
-      cf.elements['enter_censustract'].value;
-  } else {
-    cf.elements['ship_censustract'].value =
-      cf.elements['enter_censustract'].value;
-  }
-%   } else {
-  cf.elements['censustract'].value = cf.elements['enter_censustract'].value;
+%   foreach my $pre (@prefixes) {
+  cf.elements['<% $pre %>censustract'].value =
+    cf.elements['<% $pre %>enter_censustract'].value;
 %   }
-% }
+% } # $withcensus
   post_standardization();
 }
 
 function post_standardization() {
 
-% if ( $conf->exists('enable_taxproducts') ) {
+% if ( $need_tax_location ) {
 
   var cf = document.<% $formname %>;
 
@@ -223,9 +204,8 @@ function post_standardization() {
       var state_el = cf.elements[prefix + 'state'];
       var state = state_el.options[ state_el.selectedIndex ].value;
 
-      var url = "<% $p %>/misc/choose_tax_location.html" +
-                  "?data_vendor=cch-zip" + 
-                  ";city="     + cf.elements[prefix + 'city'].value +
+      var url = "<% $p %>/misc/choose_tax_location.html?" +
+                  "city="     + cf.elements[prefix + 'city'].value +
                   ";state="    + state + 
                   ";zip="      + cf.elements[prefix + 'zip'].value +
                   ";country="  + country +
@@ -271,11 +251,9 @@ function update_geocode() {
       prefix = 'bill_';
     }
 
-    //alert(what.options[what.selectedIndex].value);
-    var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
-    cf.elements[prefix + 'city'].value     = argsHash['city'];
-    setselect(cf.elements[prefix + 'state'], argsHash['state']);
-    cf.elements[prefix + 'zip'].value      = argsHash['zip'];
+%# this used to set the city/state/zip to the selected value; I think
+%# that's wrong.
+    var argsHash = JSON.parse(what.value);
     cf.elements[prefix + 'geocode'].value  = argsHash['geocode'];
     <% $post_geocode %>;
 
@@ -362,4 +340,7 @@ if ( $census_functions ) {
   $post_geocode = 'confirm_censustract()';
 }
 
+my $tax_engine = FS::TaxEngine->new;
+my $need_tax_location = $tax_engine->info->{manual_tax_location} ? 1 : 0;
+
 </%init>