[freeside-commits] freeside/httemplate/misc xmlhttp-cust_main-address_standardize.html, NONE, 1.1 xmlhttp-cust_main-search.cgi, 1.3, 1.4

Ivan,,, ivan at wavetail.420.am
Thu May 8 05:46:01 PDT 2008


Update of /home/cvs/cvsroot/freeside/httemplate/misc
In directory wavetail.420.am:/tmp/cvs-serv738/httemplate/misc

Modified Files:
	xmlhttp-cust_main-search.cgi 
Added Files:
	xmlhttp-cust_main-address_standardize.html 
Log Message:
address standardization part one, finally checked in from here

--- NEW FILE: xmlhttp-cust_main-address_standardize.html ---
<% to_json($return) %>
<%init>

my $DEBUG = 1;

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_' ) {

      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 ) {

        $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'      => $hash->{Zip5}. '-'. $hash->{Zip4},
        };

        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 {

        warn "USPS WebTools error: ". $verifier->response. "\n";

      }

    }

  }

  $return;

}

</%init>

Index: xmlhttp-cust_main-search.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/xmlhttp-cust_main-search.cgi,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- xmlhttp-cust_main-search.cgi	6 May 2008 01:14:55 -0000	1.3
+++ xmlhttp-cust_main-search.cgi	8 May 2008 12:45:59 -0000	1.4
@@ -15,7 +15,7 @@
 %   my @cust_main = smart_search( 'search' => $string );
 %   my $return = [ map [ $_->custnum, $_->name ], @cust_main ];
 %     
-<% objToJson($return) %>
+<% to_json($return) %>
 % } 
 <%init>
 



More information about the freeside-commits mailing list