summaryrefslogtreecommitdiff
path: root/httemplate/misc
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-11-06 12:48:41 -0800
committerMark Wells <mark@freeside.biz>2012-11-06 12:49:11 -0800
commit468c9e660eb0edb2033f0f8dbb4458f20280082c (patch)
tree9a87abfbfad9c820598c3a8d773f35c421c2bb38 /httemplate/misc
parent2b2aa5664742a134da11862a7cedb37d25524423 (diff)
improved address standardization, #13763
Diffstat (limited to 'httemplate/misc')
-rwxr-xr-xhttemplate/misc/change_pkg.cgi1
-rw-r--r--httemplate/misc/confirm-address_standardize.html123
-rw-r--r--httemplate/misc/confirm-censustract.html78
-rw-r--r--httemplate/misc/order_pkg.html1
-rw-r--r--httemplate/misc/xmlhttp-address_standardize.html38
-rw-r--r--httemplate/misc/xmlhttp-cust_main-address_standardize.html93
6 files changed, 241 insertions, 93 deletions
diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi
index 2ab9329a1..7b08f7b10 100755
--- a/httemplate/misc/change_pkg.cgi
+++ b/httemplate/misc/change_pkg.cgi
@@ -34,6 +34,7 @@
'form' => "OrderPkgForm",
'onlyship' => 1,
'no_company' => 1,
+ 'no_census' => 1,
'callback' => 'document.OrderPkgForm.submit();',
&>
diff --git a/httemplate/misc/confirm-address_standardize.html b/httemplate/misc/confirm-address_standardize.html
new file mode 100644
index 000000000..3603b95d9
--- /dev/null
+++ b/httemplate/misc/confirm-address_standardize.html
@@ -0,0 +1,123 @@
+<STYLE type="text/css">
+th { line-height: 150% }
+</STYLE>
+<CENTER><BR><B>
+% if ( $new{error} or $new{ship_error} ) {
+Address standardization error
+% }
+% else {
+Confirm address standardization
+% }
+
+</B><BR><BR>
+<TABLE WIDTH="100%">
+% for my $pre ('', 'ship_') {
+% next if !$pre and $old{onlyship};
+% my $name = $pre eq 'ship_' ? 'service' : 'billing';
+% if ( $new{$pre.'addr_clean'} ) {
+ <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>
+ </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'} ) {
+ <TR>
+ <TH>Entered <%$name%> address</TH>
+ </TR>
+% if ( $old{$pre.'company'} ) {
+ <TR>
+ <TD><% $old{$pre.'company'} %></TD>
+ </TR>
+% }
+ <TR>
+ <TD><% $old{$pre.'address1'} %></TD>
+ <TD ROWSPAN=3><FONT COLOR="#ff0000"><B><% $new{$pre.'error'} %></B></FONT></TD>
+ </TR>
+ <TR>
+ <TD><% $old{$pre.'address2'} %></TD>
+ </TR>
+ <TR>
+ <TD><% $old{$pre.'city'} %>, <% $old{$pre.'state'} %> <% $old{$pre.'zip'} %></TD>
+ </TR>
+% } #if error
+% } # for $pre
+
+%# only do this part if address standardization provided a censustract
+% if ( $new{'ship_censustract'} ) {
+ <TR>
+ <TH>Entered census tract</TH>
+ <TH>Calculated census tract</TH>
+ </TR>
+ <TR>
+ <TD><% $old{'ship_censustract'} %></TD>
+ <TD>
+% if ( $new{'ship_census_error'} ) {
+ <FONT COLOR="#ff0000"><% $new{'ship_census_error'} %></FONT>
+% } else {
+ <% $new{'ship_censustract'} %>
+% }
+ </TD>
+ </TR>
+% } #if censustract
+
+% if ( $new{error} or $new{ship_error} ) {
+ <TR>
+ <TD ALIGN="center">
+ <BUTTON TYPE="button" STYLE="width:205px" onclick="confirm_manual_address();">
+ <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered <%$addresses%>
+ </BUTTON></TD>
+ <TD ALIGN="center">
+ <BUTTON TYPE="button" STYLE="width:205px" onclick="submit_abort();">
+ <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
+ </BUTTON></TD>
+ </TR>
+% }
+% else {
+ <TR>
+ <TD ALIGN="center">
+ <BUTTON TYPE="button" STYLE="width:205px" onclick="confirm_manual_address()();">
+ <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered <%$addresses%>
+ </BUTTON></TD>
+ <TD ALIGN="center">
+ <BUTTON TYPE="button" STYLE="width:205px" onclick="replace_address();">
+ <IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized <%$addresses%>
+ </BUTTON></TD>
+ </TR>
+ <TR ALIGN="center"><TD COLSPAN=2>
+ <BUTTON TYPE="button" STYLE="width:205px" onclick="submit_abort();">
+ <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
+ </BUTTON>
+ </TD></TR>
+</TABLE>
+% } # !error
+<%init>
+
+# slightly weird interface...
+my $q = decode_json($cgi->param('q'));
+#warn Dumper($q);
+my %old = %{ $q->{old} };
+my %new = %{ $q->{new} };
+
+my $addresses = $old{onlyship} ? 'address' : 'addresses';
+
+</%init>
diff --git a/httemplate/misc/confirm-censustract.html b/httemplate/misc/confirm-censustract.html
new file mode 100644
index 000000000..ae0ae3a6a
--- /dev/null
+++ b/httemplate/misc/confirm-censustract.html
@@ -0,0 +1,78 @@
+<CENTER><BR><B>
+% if ( $error ) {
+Census tract error
+% }
+% else {
+Confirm census tract
+% }
+</B><BR>
+% my $querystring = "census_year=$year&latitude=".$cache->get('latitude').'&longitude='.$cache->get('longitude');
+<A HREF="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?<% $querystring %>"
+ TARGET="_blank">Map service module location</A><BR>
+% $querystring = "census_year=$year&zip_code=".$cache->get('zip');
+<A HREF="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?<% $querystring %>"
+ TARGET="_blank">Map zip code center</A><BR>
+<BR>
+<TABLE>
+ <TR>
+ <TH style="width:50%">Entered census tract</TH>
+ <TH style="width:50%">Calculated census tract</TH>
+ </TR>
+ <TR>
+ <TD><% $old_tract %></TD>
+% if ( $error ) {
+ <TD><FONT COLOR="#ff0000"><% $error %></FONT></TD>
+% } else {
+ <TD><% $new_tract %></TD>
+% }
+ </TR>
+ <TR>
+ <TD ALIGN="center">
+ <BUTTON TYPE="button"
+ onclick="set_censustract('<% $old_tract %>', '<% $year %>')">
+ <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract
+ </BUTTON>
+ </TD>
+ <TD ALIGN="center">
+ <BUTTON TYPE="button"
+ onclick="set_censustract('<% $new_tract %>', '<% $year %>')">
+ <IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract
+ </BUTTON>
+ </TD>
+ </TR>
+ <TR>
+ <TD COLSPAN=2 ALIGN="center">
+ <BUTTON TYPE="button" onclick="submit_abort()">
+ <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
+ </BUTTON>
+ </TD>
+ </TR>
+</TABLE></CENTER>
+<%init>
+
+local $SIG{__DIE__}; #disable Mason error trap
+
+my $DEBUG = 0;
+
+my $conf = new FS::Conf;
+
+warn $cgi->param('q') if $DEBUG;
+
+my $q = decode_json($cgi->param('q'))
+ or die "bad argument '".$cgi->param('q')."'";
+
+my %location = (
+ map { $_ => $q->{'ship_'.$_} }
+ qw( company address1 address2 city state zip country latitude longitude )
+);
+
+my $old_tract = $q->{'ship_censustract'};
+my $cache = eval { FS::GeocodeCache->new(%location) };
+$cache->set_censustract;
+my $year = FS::Conf->new->config('census_year');
+my $new_tract = $cache->get('censustract');
+my $error = $cache->get('censustract_error');
+
+warn Dumper($cache) if $DEBUG;
+
+</%init>
diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html
index c5f4509ab..bfc7b6903 100644
--- a/httemplate/misc/order_pkg.html
+++ b/httemplate/misc/order_pkg.html
@@ -131,6 +131,7 @@
'form' => "OrderPkgForm",
'onlyship' => 1,
'no_company' => 1,
+ 'no_census' => 1,
'callback' => 'document.OrderPkgForm.submit();',
&>
diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html
new file mode 100644
index 000000000..f53c35fca
--- /dev/null
+++ b/httemplate/misc/xmlhttp-address_standardize.html
@@ -0,0 +1,38 @@
+<% encode_json($return) %>
+<%init>
+
+local $SIG{__DIE__}; #disable Mason error trap
+
+my $DEBUG = 0;
+
+my $conf = new FS::Conf;
+
+my $sub = $cgi->param('sub');
+
+warn $cgi->param('arg') if $DEBUG;
+
+my %old = %{ decode_json($cgi->param('arg')) }
+ or die "bad argument '".$cgi->param('arg')."'";
+
+my %new;
+
+foreach my $pre ( '', 'ship_' ) {
+ next unless ($pre || !$old{onlyship});
+
+ my $location = {
+ map { $_ => $old{$pre.$_} }
+ qw( company address1 address2 city state zip country )
+ };
+
+ my $cache = eval { FS::GeocodeCache->standardize($location) };
+ $cache->set_coord;
+ # don't do set_censustract here, though censustract may be set by now
+
+ foreach ( keys(%$cache) ) {
+ $new{$pre.$_} = $cache->get($_);
+ }
+}
+
+my $return = { old => \%old, new => \%new };
+warn "result:\n".encode_json($return) if $DEBUG;
+</%init>
diff --git a/httemplate/misc/xmlhttp-cust_main-address_standardize.html b/httemplate/misc/xmlhttp-cust_main-address_standardize.html
deleted file mode 100644
index d0627cd59..000000000
--- a/httemplate/misc/xmlhttp-cust_main-address_standardize.html
+++ /dev/null
@@ -1,93 +0,0 @@
-<% objToJson($return) %>
-<%init>
-
-my $DEBUG = 0;
-
-my $conf = new FS::Conf;
-
-my $sub = $cgi->param('sub');
-
-my $return = {};
-
-if ( $sub eq 'address_standardize' ) {
-
- my %arg = $cgi->param('arg');
- $return = \%arg;
- warn join('', map "$_: $arg{$_}\n", keys %arg )
- if $DEBUG;
-
- my $userid = $conf->config('usps_webtools-userid');
- my $password = $conf->config('usps_webtools-password');
-
- if ( length($userid) && length($password) ) {
-
- my $verifier = Business::US::USPS::WebTools::AddressStandardization->new( {
- UserID => $userid, #$ENV{USPS_WEBTOOLS_USERID},
- Password => $password, #$ENV{USPS_WEBTOOLS_PASSWORD},
- #Testing => 1,
- } );
-
- foreach my $pre ( '', 'ship_' ) {
- next unless ($pre || !$arg{onlyship});
-
- my($zip5, $zip4) = split('-',$arg{$pre.'zip'});
-
- my %usps_args = (
- FirmName => $arg{$pre.'company'},
- Address2 => $arg{$pre.'address1'},
- Address1 => $arg{$pre.'address2'},
- City => $arg{$pre.'city'},
- State => $arg{$pre.'state'},
- Zip5 => $zip5,
- Zip4 => $zip4,
- );
- warn join('', map "$_: $usps_args{$_}\n", keys %usps_args )
- if $DEBUG;
-
- my $hash = $verifier->verify_address( %usps_args );
-
- warn $verifier->response
- if $DEBUG;
-
- unless ( $verifier->is_error ) {
-
- my $zip = $hash->{Zip5};
- $zip .= '-'. $hash->{Zip4} if $hash->{Zip4} =~ /\d/;
-
- $return = {
- %$return,
- "new_$pre".'company' => $hash->{FirmName},
- "new_$pre".'address1' => $hash->{Address2},
- "new_$pre".'address2' => $hash->{Address1},
- "new_$pre".'city' => $hash->{City},
- "new_$pre".'state' => $hash->{State},
- "new_$pre".'zip' => $zip,
- };
-
- my @fields = (qw( company address1 address2 city state zip )); #hmm
-
- my $changed =
- scalar( grep { $return->{$pre.$_} ne $return->{"new_$pre$_"} }
- @fields
- )
- ? 1 : 0;
-
- $return->{$pre.'address_standardized'} = $changed;
-
- } else {
-
- $return->{$pre.'error'} = "USPS WebTools error: ".
- $verifier->{error}{description};
-
-
- }
-
- }
-
- }
-
- $return;
-
-}
-
-</%init>