diff options
author | Ivan Kohler <ivan@freeside.biz> | 2013-07-02 21:11:29 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2013-07-02 21:11:29 -0700 |
commit | 3d0a1bb06b895c5be6e3f0517d355442a6b1e125 (patch) | |
tree | 84069ebc3254825b952a482e11cdbbbc69f6fe85 /httemplate/misc/xmlhttp-address_standardize.html | |
parent | f3b99c11d6eed33f467dda360180a698a85c54e8 (diff) | |
parent | d62206a94d9d49ef96640e0a8ec492679f8345e9 (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/misc/xmlhttp-address_standardize.html')
-rw-r--r-- | httemplate/misc/xmlhttp-address_standardize.html | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html new file mode 100644 index 000000000..618265364 --- /dev/null +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -0,0 +1,51 @@ +<% 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; + +my @prefixes = (''); +if ( $old{same} ) { + @prefixes = ('bill_'); +} elsif ( $old{billship} ) { + @prefixes = ('bill_', 'ship_'); +} +my $all_same = 1; +foreach my $pre ( @prefixes ) { + + 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($_); + } + + foreach ( qw(address1 address2 city state zip country) ) { + $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 }; +warn "result:\n".encode_json($return) if $DEBUG; +</%init> |