rename geocode_cache; minor coord_auto bugfix
authorMark Wells <mark@freeside.biz>
Sat, 14 Apr 2012 22:33:39 +0000 (15:33 -0700)
committerMark Wells <mark@freeside.biz>
Sat, 14 Apr 2012 22:33:39 +0000 (15:33 -0700)
FS/FS/Mason.pm
FS/FS/Misc/Geo.pm
FS/FS/geocode_cache.pm [deleted file]
FS/MANIFEST
FS/t/geocode_cache.t [deleted file]
httemplate/elements/order_pkg.js
httemplate/elements/standardize_locations.js
httemplate/misc/xmlhttp-address_standardize.html

index 62568eb..a45be3f 100644 (file)
@@ -304,7 +304,7 @@ if ( -e $addl_handler_use_file ) {
   use FS::tower;
   use FS::tower_sector;
   use FS::contact_class;
-  use FS::geocode_cache;
+  use FS::GeocodeCache;
   # Sammath Naur
 
   if ( $FS::Mason::addl_handler_use ) {
index 174357c..c8290e7 100644 (file)
@@ -354,8 +354,9 @@ sub standardize_teleatlas {
     return $location;
   }
 
-  my $path = $conf->config('teleatlas-path')
-    or die "no teleatlas-path configured";
+  if ( my $path = $conf->config('teleatlas-path') ) {
+    local @INC = (@INC, $path);
+  }
   my $userid = $conf->config('teleatlas-userid')
     or die "no teleatlas-userid configured";
   my $password = $conf->config('teleatlas-password')
diff --git a/FS/FS/geocode_cache.pm b/FS/FS/geocode_cache.pm
deleted file mode 100644 (file)
index 0041e37..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-package FS::geocode_cache;
-
-use strict;
-use vars qw($conf $DEBUG);
-use base qw( FS::geocode_Mixin );
-use FS::Record qw( qsearch qsearchs );
-use FS::Conf;
-use FS::Misc::Geo;
-
-use Data::Dumper;
-
-FS::UID->install_callback( sub { $conf = new FS::Conf; } );
-
-$DEBUG = 0;
-
-=head1 NAME
-
-FS::geocode_cache - An address undergoing the geocode process.
-
-=head1 SYNOPSIS
-
-  use FS::geocode_cache;
-
-  $record = FS::geocode_cache->standardize(%location_hash);
-
-=head1 DESCRIPTION
-
-An FS::geocode_cache object represents a street address in the process of 
-being geocoded.  FS::geocode_cache inherits from FS::geocode_Mixin.
-
-Most methods on this object throw an exception on error.
-
-FS::geocode_cache has the following fields, with the same meaning as in 
-L<FS::cust_location>:
-
-=over 4
-
-All other fields have the same meaning as in L<FS::cust_main> and 
-L<FS::cust_location>:
-
-=item address1
-
-=item address2
-
-=item city
-
-=item county
-
-=item state
-
-=item zip
-
-=item latitude
-
-=item longitude
-
-=item addr_clean
-
-=item country
-
-=item censustract
-
-=item geocode
-
-=item district
-
-=back
-
-=head1 METHODS
-
-=over 4
-
-=item new HASHREF
-
-Creates a new cache object.  For internal use.  See C<standardize>.
-
-=cut
-
-# minimalist constructor
-sub new {
-  my $class = shift;
-  my $self = {
-    company     => '',
-    address1    => '',
-    address2    => '',
-    city        => '',
-    state       => '',
-    zip         => '',
-    country     => '',
-    latitude    => '',
-    longitude   => '',
-    addr_clean  => '',
-    censustract => '',
-    @_
-  };
-  bless $self, $class;
-}
-
-# minimalist accessor, for compatibility with geocode_Mixin
-sub get {
-  $_[0]->{$_[1]}
-}
-
-sub set {
-  $_[0]->{$_[1]} = $_[2];
-}
-
-sub location_hash { %{$_[0]} };
-
-=item set_censustract
-
-Look up the censustract, if it's not already filled in, and return it.
-On error, sets 'error' and returns nothing.
-
-This uses the "get_censustract_*" methods in L<FS::Misc::Geo>; currently
-the only one is 'ffiec'.
-
-=cut
-
-sub set_censustract {
-  my $self = shift;
-
-  if ( $self->get('censustract') =~ /^\d{9}\.\d{2}$/ ) {
-    return $self->get('censustract');
-  }
-  my $censusyear = $conf->config('census_year');
-  return if !$censusyear;
-
-  my $method = 'ffiec';
-  # configurable censustract-only lookup goes here if it's ever needed.
-  $method = "get_censustract_$method";
-  my $censustract = eval { FS::Misc::Geo->$method($self, $censusyear) };
-  $self->set("censustract_error", $@);
-  $self->set("censustract", $censustract);
-}
-
-=item set_coord
-
-Set the latitude and longitude fields if they're not already set.  Returns
-those values, in order.
-
-=cut
-
-sub set_coord { # the one in geocode_Mixin will suffice
-  my $self = shift;
-  if ( !$self->get('latitude') || !$self->get('longitude') ) {
-    $self->SUPER::set_coord;
-    $self->set('coord_error', $@);
-  }
-  return $self->get('latitude'), $self->get('longitude');
-}
-
-=head1 CLASS METHODS
-
-=over 4
-
-=item standardize LOCATION
-
-Given a location hash or L<FS::geocode_Mixin> object, standardize the 
-address using the configured method and return an L<FS::geocode_cache> 
-object.
-
-The methods are the "standardize_*" functions in L<FS::Geo::Misc>.
-
-=cut
-
-sub standardize {
-  my $class = shift;
-  my $location = shift;
-  $location = { $location->location_hash }
-    if UNIVERSAL::can($location, 'location_hash');
-
-  local $Data::Dumper::Terse = 1;
-  warn "standardizing location:\n".Dumper($location) if $DEBUG;
-
-  my $method = $conf->config('address_standardize_method');
-
-  if ( $method ) {
-    $method = "standardize_$method";
-    my $new_location = eval { FS::Misc::Geo->$method( $location ) };
-    if ( $new_location ) {
-      $location = {
-        addr_clean => 'Y',
-        %$new_location
-        # standardize_* can return an address with addr_clean => '' if
-        # the address is somehow questionable
-      }
-    }
-    else {
-      # XXX need an option to decide what to do on error
-      $location->{'addr_clean'} = '';
-      $location->{'error'} = $@;
-    }
-    warn "result:\n".Dumper($location) if $DEBUG;
-  }
-  # else $location = $location
-  my $cache = $class->new(%$location);
-  return $cache;
-}
-
-=back
-
-=head1 BUGS
-
-=head1 SEE ALSO
-
-L<FS::Record>, schema.html from the base documentation.
-
-=cut
-
-1;
-
index 76741ad..e97f870 100644 (file)
@@ -632,5 +632,5 @@ FS/h_svc_cert.pm
 t/h_svc_cert.t
 FS/contact_class.pm
 t/contact_class.t
-FS/geocode_cache.pm
-t/geocode_cache.t
+FS/GeocodeCache.pm
+t/GeocodeCache.t
diff --git a/FS/t/geocode_cache.t b/FS/t/geocode_cache.t
deleted file mode 100644 (file)
index 7cbc58d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-BEGIN { $| = 1; print "1..1\n" }
-END {print "not ok 1\n" unless $loaded;}
-use FS::geocode_cache;
-$loaded=1;
-print "ok 1\n";
index 84c7a82..8c1efd9 100644 (file)
@@ -19,13 +19,10 @@ function pkg_changed () {
       form.start_date_text.disabled = false;
       form.start_date.style.backgroundColor = '#ffffff';
       form.start_date_button.style.display = '';
-      //form.start_date_button_disabled.style.display = 'none';
-      //form.invoice_terms.disabled = true;
     } else {
       form.start_date_text.disabled = true;
       form.start_date.style.backgroundColor = '#dddddd';
       form.start_date_button.style.display = 'none';
-      //form.start_date_button_disabled.style.display = '';
     }
 
   } else {
index 8bec87e..77683b9 100644 (file)
@@ -45,9 +45,10 @@ function standardize_locations() {
   }
 
 %   }
-// unless they're both empty
-  if ( cf.elements['<% $pre %>latitude'] == '' &&
-       cf.elements['<% $pre %>longitude'] == '' ) {
+  // but if the coordinates have been set to null, turn coord_auto on 
+  // and standardize
+  if ( cf.elements['<% $pre %>latitude'].value == '' &&
+       cf.elements['<% $pre %>longitude'].value == '' ) {
     cf.elements['<% $pre %>coord_auto'].value = 'Y';
     changed = true;
   }
index f305a24..c2d6d7a 100644 (file)
@@ -24,7 +24,7 @@ foreach my $pre ( '', 'ship_' ) {
       qw( company address1 address2 city state zip country )
   };
 
-  my $cache = eval { FS::geocode_cache->standardize($location) };
+  my $cache = eval { FS::GeocodeCache->standardize($location) };
   $cache->set_censustract if $pre;
   $cache->set_coord;