[freeside-commits] freeside/FS/FS geocode_Mixin.pm, 1.4, 1.5 qual.pm, 1.10, 1.11

Ivan,,, ivan at wavetail.420.am
Sun Mar 13 11:56:05 PDT 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv3526/FS/FS

Modified Files:
	geocode_Mixin.pm qual.pm 
Log Message:
qualification address handling changes, RT#7111

Index: qual.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/qual.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -d -r1.10 -r1.11
--- qual.pm	12 Mar 2011 21:30:57 -0000	1.10
+++ qual.pm	13 Mar 2011 18:56:03 -0000	1.11
@@ -91,7 +91,8 @@
 
   if ( $options{'cust_location'} ) {
     my $cust_location = $options{'cust_location'};
-    my $error = $cust_location->insert;
+    my $method = $cust_location->locationnum ? 'replace' : 'insert';
+    my $error = $cust_location->$method();
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return $error;
@@ -186,7 +187,6 @@
 
 sub location_hash {
     my $self = shift;
-    use Data::Dumper; warn Dumper($self);
     if ( $self->locationnum ) {
 	my $l = qsearchs( 'cust_location', 
 		    { 'locationnum' => $self->locationnum });

Index: geocode_Mixin.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/geocode_Mixin.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- geocode_Mixin.pm	7 Dec 2010 19:04:42 -0000	1.4
+++ geocode_Mixin.pm	13 Mar 2011 18:56:03 -0000	1.5
@@ -38,7 +38,8 @@
 =item location_hash
 
 Returns a list of key/value pairs, with the following keys: address1, address2,
-city, county, state, zip, country.  The shipping address is used if present.
+city, county, state, zip, country, geocode, location_type, location_number,
+location_kind.  The shipping address is used if present.
 
 =cut
 
@@ -88,12 +89,29 @@
   my $prefix = $self->has_ship_address ? 'ship_' : '';
 
   my $notfirst = 0;
-  foreach (qw ( address1 address2 location_type location_number ) ) {
+  foreach (qw ( address1 address2 ) ) {
     my $method = "$prefix$_";
     $line .= ($notfirst ? $separator : ''). &$escape($self->$method)
       if $self->$method;
     $notfirst++;
   }
+
+  my %location_type;
+  if ( 1 ) { #ikano, switch on via config
+    { no warnings 'void';
+      eval { 'use FS::part_export::ikano;' };
+      die $@ if $@;
+    }
+    %location_type = FS::part_export::ikano->location_types;
+  } else {
+    %location_type = (); #?
+  }
+
+  $line .= ' '. &$escape( $location_type{ $self->get($prefix.'location_type') })
+    if $self->get($prefix.'location_type');
+  $line .= ' '. &$escape($self->get($prefix.'location_number'))
+    if $self->get($prefix.'location_number');
+
   $notfirst = 0;
   foreach (qw ( city county state zip ) ) {
     my $method = "$prefix$_";
@@ -150,6 +168,49 @@
   $geocode;
 }
 
+=item alternize
+
+Attempts to parse data for location_type and location_number from address1
+and address2.
+
+=cut
+
+sub alternize {
+  my $self = shift;
+  my $prefix = $self->has_ship_address ? 'ship_' : '';
+
+  return '' if $self->get($prefix.'location_type')
+            || $self->get($prefix.'location_number');
+
+  my %parse;
+  if ( 1 ) { #ikano, switch on via config
+    { no warnings 'void';
+      eval { 'use FS::part_export::ikano;' };
+      die $@ if $@;
+    }
+    %parse = FS::part_export::ikano->location_types_parse;
+  } else {
+    %parse = (); #?
+  }
+
+  foreach my $from ('address1', 'address2') {
+    foreach my $parse ( keys %parse ) {
+      my $value = $self->get($prefix.$from);
+      if ( $value =~ s/(^|\W+)$parse\W+(\w+)\W*$//i ) {
+        $self->set($prefix.'location_type', $parse{$parse});
+        $self->set($prefix.'location_number', $2);
+        $self->set($prefix.$from, $value);
+        return '';
+      }
+    }
+  }
+
+  #nothing matched, no changes
+  $self->get($prefix.'address2')
+    ? "Can't parse unit type and number from ${prefix}address2"
+    : '';
+}
+
 =back
 
 =head1 BUGS



More information about the freeside-commits mailing list