From 468c9e660eb0edb2033f0f8dbb4458f20280082c Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 6 Nov 2012 12:48:41 -0800 Subject: improved address standardization, #13763 --- httemplate/misc/xmlhttp-address_standardize.html | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 httemplate/misc/xmlhttp-address_standardize.html (limited to 'httemplate/misc/xmlhttp-address_standardize.html') 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; + -- cgit v1.2.1 From 84fa358b56b89205fff99927080d5c28c01d57ff Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 9 Nov 2012 17:03:41 -0800 Subject: various customer location-related fixes, #13763 --- httemplate/misc/xmlhttp-address_standardize.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'httemplate/misc/xmlhttp-address_standardize.html') diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html index f53c35fca..e28c06f3a 100644 --- a/httemplate/misc/xmlhttp-address_standardize.html +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -16,8 +16,15 @@ my %old = %{ decode_json($cgi->param('arg')) } my %new; -foreach my $pre ( '', 'ship_' ) { - next unless ($pre || !$old{onlyship}); +my @prefixes; +if ($old{onlyship}) { + @prefixes = ('ship_'); +} elsif ( $old{same} ) { + @prefixes = (''); +} else { + @prefixes = ('', 'ship_'); +} +foreach my $pre ( @prefixes ) { my $location = { map { $_ => $old{$pre.$_} } -- cgit v1.2.1 From 2bb7db96a07599e980323c1b6b23a8c79cc17a9a Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 13 Nov 2012 15:32:31 -0800 Subject: address standardization/census tract fixes --- httemplate/misc/xmlhttp-address_standardize.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'httemplate/misc/xmlhttp-address_standardize.html') diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html index e28c06f3a..1620642cb 100644 --- a/httemplate/misc/xmlhttp-address_standardize.html +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -20,9 +20,9 @@ my @prefixes; if ($old{onlyship}) { @prefixes = ('ship_'); } elsif ( $old{same} ) { - @prefixes = (''); + @prefixes = ('bill_'); } else { - @prefixes = ('', 'ship_'); + @prefixes = ('bill_', 'ship_'); } foreach my $pre ( @prefixes ) { -- cgit v1.2.1 From 5ad226c0ff7759184ea26d66292ccebd2ec00af7 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 20 Nov 2012 16:11:50 -0800 Subject: fix a confusing standardization behavior, #13763 --- httemplate/misc/xmlhttp-address_standardize.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'httemplate/misc/xmlhttp-address_standardize.html') diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html index 1620642cb..988057163 100644 --- a/httemplate/misc/xmlhttp-address_standardize.html +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -24,6 +24,7 @@ if ($old{onlyship}) { } else { @prefixes = ('bill_', 'ship_'); } +my $all_same = 1; foreach my $pre ( @prefixes ) { my $location = { @@ -38,8 +39,13 @@ foreach my $pre ( @prefixes ) { foreach ( keys(%$cache) ) { $new{$pre.$_} = $cache->get($_); } + + foreach ( qw(address1 address2 city state zip country) ) { + $all_same = 0 if ( $new{$pre.$_} ne $old{$pre.$_} ); + last if !$all_same; + } } -my $return = { old => \%old, new => \%new }; +my $return = { old => \%old, new => \%new, all_same => $all_same }; warn "result:\n".encode_json($return) if $DEBUG; -- cgit v1.2.1 From f88dda7fe57054bd030491a5b9363a1aff601bf2 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sun, 13 Jan 2013 14:22:21 -0800 Subject: fix address standardization when changing package locations, #13763 --- httemplate/misc/xmlhttp-address_standardize.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'httemplate/misc/xmlhttp-address_standardize.html') diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html index 988057163..15f266ab0 100644 --- a/httemplate/misc/xmlhttp-address_standardize.html +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -16,12 +16,10 @@ my %old = %{ decode_json($cgi->param('arg')) } my %new; -my @prefixes; -if ($old{onlyship}) { - @prefixes = ('ship_'); -} elsif ( $old{same} ) { +my @prefixes = (''); +if ( $old{same} ) { @prefixes = ('bill_'); -} else { +} elsif ( $old{billship} ) { @prefixes = ('bill_', 'ship_'); } my $all_same = 1; @@ -44,6 +42,8 @@ foreach my $pre ( @prefixes ) { $all_same = 0 if ( $new{$pre.$_} ne $old{$pre.$_} ); last if !$all_same; } + + $all_same = 0 if $new{$pre.'error'}; } my $return = { old => \%old, new => \%new, all_same => $all_same }; -- cgit v1.2.1 From 54156948ccda87655f9f4bb26a2747ab49b616ce Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 17 Apr 2013 21:09:26 -0700 Subject: move from legacy compat JSON to_json to modern JSON::XS encode_json, RT#22630 --- httemplate/misc/xmlhttp-address_standardize.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'httemplate/misc/xmlhttp-address_standardize.html') diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html index 15f266ab0..618265364 100644 --- a/httemplate/misc/xmlhttp-address_standardize.html +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -1,4 +1,4 @@ -<% encode_json($return) %> +<% encode_json($return) %>\ <%init> local $SIG{__DIE__}; #disable Mason error trap -- cgit v1.2.1