[freeside-commits] freeside/FS/FS Mason.pm, 1.78.2.9, 1.78.2.10 Schema.pm, 1.317.2.26, 1.317.2.27 cust_main.pm, 1.586.2.11, 1.586.2.12 h_cust_main.pm, NONE, 1.1.2.2

Mark Wells mark at wavetail.420.am
Fri Dec 30 14:11:54 PST 2011


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

Modified Files:
      Tag: FREESIDE_2_3_BRANCH
	Mason.pm Schema.pm cust_main.pm 
Added Files:
      Tag: FREESIDE_2_3_BRANCH
	h_cust_main.pm 
Log Message:
track/update census codes by year, #15381

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.317.2.26
retrieving revision 1.317.2.27
diff -u -w -d -r1.317.2.26 -r1.317.2.27
--- Schema.pm	28 Dec 2011 23:56:19 -0000	1.317.2.26
+++ Schema.pm	30 Dec 2011 22:11:51 -0000	1.317.2.27
@@ -895,6 +895,7 @@
         'payip',    'varchar', 'NULL', 15, '', '', 
         'geocode',  'varchar', 'NULL', 20,  '', '',
         'censustract', 'varchar', 'NULL', 20,  '', '', # 7 to save space?
+        'censusyear', 'char', 'NULL', 4, '', '',
         'tax',      'char', 'NULL', 1, '', '', 
         'otaker',   'varchar', 'NULL',    32, '', '', 
         'usernum',   'int', 'NULL', '', '', '',

--- NEW FILE: h_cust_main.pm ---
package FS::h_cust_main;

use strict;
use base qw( FS::h_Common FS::cust_main );

sub table { 'h_cust_main' };

=head1 NAME

FS::h_cust_main - Historical customer information records.

=head1 DESCRIPTION

An FS::h_cust_main object represents historical changes to a 
customer record (L<FS::cust_main>).

=head1 SEE ALSO

L<FS::cust_main>,  L<FS::h_Common>, L<FS::Record>, schema.html from the base
documentation.

=cut

1;


Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.78.2.9
retrieving revision 1.78.2.10
diff -u -w -d -r1.78.2.9 -r1.78.2.10
--- Mason.pm	13 Dec 2011 19:55:36 -0000	1.78.2.9
+++ Mason.pm	30 Dec 2011 22:11:51 -0000	1.78.2.10
@@ -64,6 +64,7 @@
   use DateTime;
   use DateTime::Format::Strptime;
   use FS::Misc::DateTime qw( parse_datetime );
+  use FS::Misc::Geo qw( get_censustract );
   use Lingua::EN::Inflect qw(PL);
   Lingua::EN::Inflect::classical names=>0; #Categorys
   use Tie::IxHash;

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.586.2.11
retrieving revision 1.586.2.12
diff -u -w -d -r1.586.2.11 -r1.586.2.12
--- cust_main.pm	13 Dec 2011 05:10:21 -0000	1.586.2.11
+++ cust_main.pm	30 Dec 2011 22:11:52 -0000	1.586.2.12
@@ -465,6 +465,8 @@
 
   $self->signupdate(time) unless $self->signupdate;
 
+  $self->censusyear($conf->config('census_year')) if $self->censustract;
+
   $self->auto_agent_custid()
     if $conf->config('cust_main-auto_agent_custid') && ! $self->agent_custid;
 
@@ -1514,6 +1516,12 @@
          || $old->payby  =~ /^(CHEK|DCHK)$/ && $self->payby =~ /^(CHEK|DCHK)$/ )
     && ( $old->payinfo eq $self->payinfo || $old->paymask eq $self->paymask );
 
+  if ( $self->censustract ne '' and $self->censustract ne $old->censustract ) {
+    # update censusyear whenever tract code changes
+    $self->censusyear($conf->config('census_year'));
+  }
+
+
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
@@ -1722,6 +1730,7 @@
     || $self->ut_coordn('latitude')
     || $self->ut_coordn('longitude')
     || $self->ut_enum('coord_auto', [ '', 'Y' ])
+    || $self->ut_numbern('censusyear')
     || $self->ut_anything('comments')
     || $self->ut_numbern('referral_custnum')
     || $self->ut_textn('stateid')
@@ -4919,6 +4928,36 @@
   $cust_main->bill_and_collect( %$param );
 }
 
+=item process_censustract_update CUSTNUM
+
+Queueable function to update the census tract to the current year (as set in 
+the 'census_year' configuration variable) and retrieve the new tract code.
+
+=cut
+
+sub process_censustract_update { 
+  eval "use FS::Misc::Geo qw(get_censustract)";
+  die $@ if $@;
+  my $custnum = shift;
+  my $cust_main = qsearchs( 'cust_main', { custnum => $custnum })
+      or die "custnum '$custnum' not found!\n";
+
+  my $new_year = $conf->config('census_year') or return;
+  my $new_tract = get_censustract({ $cust_main->location_hash }, $new_year);
+  if ( $new_tract =~ /^\d/ ) {
+    # then it's a tract code
+        $cust_main->set('censustract', $new_tract);
+    $cust_main->set('censusyear',  $new_year);
+    my $error = $cust_main->replace;
+    die $error if $error;
+  }
+  else {
+    # it's an error message
+    die $new_tract;
+  }
+  return;
+}
+
 sub _upgrade_data { #class method
   my ($class, %opts) = @_;
 



More information about the freeside-commits mailing list