TomTom: return a definite error on incomplete matches, #25261
authorMark Wells <mark@freeside.biz>
Wed, 6 Nov 2013 20:14:42 +0000 (12:14 -0800)
committerMark Wells <mark@freeside.biz>
Wed, 6 Nov 2013 20:14:42 +0000 (12:14 -0800)
FS/FS/Misc/Geo.pm
httemplate/misc/confirm-address_standardize.html

index bf4840b..9f6b89b 100644 (file)
@@ -447,6 +447,12 @@ sub standardize_tomtom {
   my ($address1, $address2) = ($location->{address1}, $location->{address2});
   my $subloc = '';
 
+  # trim whitespace
+  $address1 =~ s/^\s+//;
+  $address1 =~ s/\s+$//;
+  $address2 =~ s/^\s+//;
+  $address2 =~ s/\s+$//;
+
   # try to fix some cases of the address fields being switched
   if ( $address2 =~ /^\d/ and $address1 !~ /^\d/ ) {
     $address2 = $address1;
@@ -487,8 +493,8 @@ sub standardize_tomtom {
     }
   }
 
-  if (!$match) {
-    die "Location not found.\n";
+  if ( !$match or !$clean ) { # partial matches are not useful
+    die "Address not found\n";
   }
   my $tract = '';
   if ( defined $match->{censusTract} ) {
@@ -642,6 +648,7 @@ sub subloc_address2 {
     warn "normalizing '$addr2' to '$result'\n" if $DEBUG > 1;
     $addr2 = $result;
   }
+  $addr2 = '' if $addr2 eq $subloc; # if it was entered redundantly
   ($subloc, $addr2);
 }
 
index 33d2219..2eae011 100644 (file)
@@ -19,52 +19,57 @@ Confirm address standardization
 % }
 % for my $pre (@prefixes) {
 %   my $name = $pre eq 'bill_' ? 'billing' : 'service';
-%   if ( $new{$pre.'addr_clean'} ) {
+%   if ( $new{$pre.'error'} ) {
   <TR>
     <TH>Entered <%$name%> address</TH>
-    <TH>Standardized <%$name%> address</TH>
   </TR>
-  <TR>
 %     if ( $old{$pre.'company'} ) {
   <TR>
     <TD><% $old{$pre.'company'} %></TD>
-    <TD><% $new{$pre.'company'} %></TD>
   </TR>
 %     }
   <TR>
     <TD><% $old{$pre.'address1'} %></TD>
-    <TD><% $new{$pre.'address1'} %></TD>
+    <TD ROWSPAN=3><FONT COLOR="#ff0000"><B><% $new{$pre.'error'} %></B></FONT></TD>
   </TR>
   <TR>
     <TD><% $old{$pre.'address2'} %></TD>
-    <TD><% $new{$pre.'address2'} %></TD>
   </TR>
   <TR>
     <TD><% $old{$pre.'city'} %>, <% $old{$pre.'state'} %>  <% $old{$pre.'zip'} %></TD>
-    <TD><% $new{$pre.'city'} %>, <% $new{$pre.'state'} %>  <% $new{$pre.'zip'} %></TD>
   </TR>
-
-%   } # if addr_clean
-%     elsif ( $new{$pre.'error'} ) {
+%   } else { # not an error
   <TR>
     <TH>Entered <%$name%> address</TH>
+    <TH>Standardized <%$name%> address</TH>
+  </TR>
+%   if ( !$new{$pre.'addr_clean'} ) {
+  <TR>
+    <TD></TD>
+    <TH STYLE="font-size:smaller;color:#ff0000">(unverified)</TH>
   </TR>
+%   }
+  <TR>
 %     if ( $old{$pre.'company'} ) {
   <TR>
     <TD><% $old{$pre.'company'} %></TD>
+    <TD><% $new{$pre.'company'} %></TD>
   </TR>
 %     }
   <TR>
     <TD><% $old{$pre.'address1'} %></TD>
-    <TD ROWSPAN=3><FONT COLOR="#ff0000"><B><% $new{$pre.'error'} %></B></FONT></TD>
+    <TD><% $new{$pre.'address1'} %></TD>
   </TR>
   <TR>
     <TD><% $old{$pre.'address2'} %></TD>
+    <TD><% $new{$pre.'address2'} %></TD>
   </TR>
   <TR>
     <TD><% $old{$pre.'city'} %>, <% $old{$pre.'state'} %>  <% $old{$pre.'zip'} %></TD>
+    <TD><% $new{$pre.'city'} %>, <% $new{$pre.'state'} %>  <% $new{$pre.'zip'} %></TD>
   </TR>
-%   } #if error
+
+%   } # if error
 % } # for $pre
 
 %# only do this part if address standardization provided a censustract
@@ -88,7 +93,7 @@ Confirm address standardization
   </TR>
 % } #if censustract
 
-% if ( $new{bill_error} or $new{ship_error} ) {
+% if ( grep {$new{$_.'error'}} @prefixes ) {
   <TR>
     <TD ALIGN="center">
     <BUTTON TYPE="button" STYLE="width:205px" onclick="confirm_manual_address();">
@@ -99,8 +104,7 @@ Confirm address standardization
       <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
     </BUTTON></TD>
   </TR>
-% }
-% else {
+% } else {
   <TR>
     <TD ALIGN="center">
     <BUTTON TYPE="button" STYLE="width:205px" onclick="confirm_manual_address();">