blob: be58618d091c13271f5b70dd778126815ad5ff17 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 | <% 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;
my $all_clean = 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 ( length( $old{$pre.'censustract'} ) > 0 &&
                     length( $new{$pre.'censustract'} ) > 0 &&
                     $old{$pre.'censustract'} ne $new{$pre.'censustract'} );
  $all_same = 0 if $new{$pre.'error'};
  $all_clean = 0 if !$new{$pre.'addr_clean'};
}
my $return = { old => \%old,
               new => \%new,
               all_same => $all_same,
               all_clean => $all_clean };
warn "result:\n".encode_json($return) if $DEBUG;
</%init>
 |