enable CardFortress in test database, #71513
[freeside.git] / httemplate / elements / standardize_locations.js
index 2d1fc74..ecccd90 100644 (file)
@@ -1,7 +1,7 @@
 function status_message(text, caption) {
   text = '<P STYLE="position:absolute; top:50%; margin-top:-1em; width:100%; text-align:center"><B><FONT SIZE="+1">' + text + '</FONT></B></P>';
   caption = caption || 'Please wait...';
-  overlib(text, WIDTH, 444, HEIGHT, 168, CAPTION, caption, STICKY, AUTOSTATUSCAP, CLOSECLICK, MIDX, 0, MIDY, 0);
+  overlib(text, WIDTH, 444, HEIGHT, 168, CAPTION, caption, STICKY, AUTOSTATUSCAP, CLOSECLICK, NOCLOSE, MIDX, 0, MIDY, 0);
 }
 
 function form_address_info() {
@@ -13,7 +13,7 @@ function form_address_info() {
 % }
 % for my $pre (@prefixes) {
 %   # normal case
-%   for my $field (qw(address1 address2 city state zip country)) {
+%   for my $field (qw(address1 address2 state zip country), ($conf->exists('cust_main-no_city_in_address') ? () : 'city')) {
     returnobj['<% $pre %><% $field %>'] = cf.elements['<% $pre %><% $field %>'].value;
 %   } #for $field
 %   if ( $withcensus ) {
@@ -114,7 +114,12 @@ function confirm_standardize(arg) {
 
     // then all entered address fields are correct
     // but we still need to set the lat/long fields and addr_clean
-    status_message('Verified');
+
+    if ( returned['all_clean'] ) {
+      status_message('Verified');
+    } else {
+      status_message('Unverified');
+    }
     replace_address();
 
   } else {
@@ -129,7 +134,7 @@ function confirm_standardize(arg) {
         function() {
           overlib( OLresponseAJAX, CAPTION, 'Address standardization', STICKY, 
             AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 
-            576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', 
+            650, HEIGHT, 368, BGCOLOR, '#333399', CGCOLOR, '#333399', 
             TEXTSIZE, 3 );
         }, 0);
 
@@ -141,11 +146,16 @@ function replace_address() {
   var newaddr = returned['new'];
 
   var cf = document.<% $formname %>;
+  var crf = document.forms['confirm_replace_form'];
 %  foreach my $pre (@prefixes) {
   var clean = newaddr['<% $pre %>addr_clean'] == 'Y';
+  var replace = true; // auto_standardize_address won't load the form, so just do it
+  if ( crf && crf['<% $pre %>replace'] ) {
+    replace = crf['<% $pre %>replace'].value == 'Y';
+  }
   var error = newaddr['<% $pre %>error'];
-  if ( clean ) {
-%   foreach my $field (qw(address1 address2 city state zip addr_clean )) {
+  if ( clean && replace ) {
+%   foreach my $field (qw(address1 address2 state zip addr_clean ),($conf->exists('cust_main-no_city_in_address') ? () : 'city')) {
     cf.elements['<% $pre %><% $field %>'].value = newaddr['<% $pre %><% $field %>'];
 %   } #foreach $field
 
@@ -154,7 +164,12 @@ function replace_address() {
       cf.elements['<% $pre %>longitude'].value = newaddr['<% $pre %>longitude'];
     }
 %   if ( $withcensus ) {
-    if ( clean && newaddr['<% $pre %>censustract'] ) {
+    var census_replace = true;
+    if ( crf && crf['census_replace'] ) {
+      census_replace = crf['census_replace'].value == 'Y';
+    }
+
+    if ( clean && census_replace && newaddr['<% $pre %>censustract'] ) {
       cf.elements['<% $pre %>censustract'].value = newaddr['<% $pre %>censustract'];
     }
 %   } #if $withcensus
@@ -179,7 +194,7 @@ function confirm_manual_address() {
 
 function post_standardization() {
 
-% if ( $conf->exists('enable_taxproducts') ) {
+% if ( $need_tax_location ) {
 
   var cf = document.<% $formname %>;
 
@@ -204,9 +219,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 +
@@ -252,11 +266,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 %>;
 
@@ -282,10 +294,7 @@ function setselect(el, value) {
 function confirm_censustract() {
 %   if ( FS::Conf->new->exists('cust_main-require_censustract') ) {
   var form = document.<% $formname %>;
-  // this is the existing/confirmed censustract, not the manually entered one
-  if ( form.elements['censustract'].value == '' ||
-       form.elements['censustract'].value != 
-          form.elements['enter_censustract'].value ) {
+  if ( form.elements['censustract'].value == '' ) {
     var address_info = form_address_info();
     address_info['latitude']  = form.elements['latitude'].value;
     address_info['longitude'] = form.elements['longitude'].value;
@@ -293,10 +302,15 @@ function confirm_censustract() {
         '<%$p%>/misc/confirm-censustract.html',
         'q=' + encodeURIComponent(JSON.stringify(address_info)),
         function() {
-          overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
-            AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
-            576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
-            TEXTSIZE, 3 );
+          if ( OLresponseAJAX ) {
+            overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
+              AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
+              576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
+              TEXTSIZE, 3 );
+          } else {
+            // no response
+            <% $post_censustract %>;
+          }
         },
         0);
   } else {
@@ -343,4 +357,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>