X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-censustract-update;h=f9b6d119705322fb70a75c9b464ed1ea2ccbbc2d;hp=af9ad749b6219591d16fe07f6cfb1556eef4f67a;hb=HEAD;hpb=1271e8451691de07d167402e93ebde8efd902c84 diff --git a/FS/bin/freeside-censustract-update b/FS/bin/freeside-censustract-update old mode 100644 new mode 100755 index af9ad749b..49505ee81 --- a/FS/bin/freeside-censustract-update +++ b/FS/bin/freeside-censustract-update @@ -18,14 +18,14 @@ $FS::UID::AutoCommit = 0; my $dbh = dbh; my $conf = FS::Conf->new; -my $current_year = $conf->config('census_year') - or die "No current census year configured.\n"; +my $current_year = $conf->config('census_legacy') || '2020'; my $date = str2time($opt{d}) if $opt{d}; $date ||= time; # This now operates on cust_location, not cust_main. # Find all locations that, as of $date, did not have # censusyear = the current year. This includes those # that have no censusyear. +local($FS::Record::qsearch_qualify_columns) = 0; my %h_cust_location = map { $_->locationnum => $_ } qsearch( 'h_cust_location', @@ -35,9 +35,14 @@ my %h_cust_location = map { $_->locationnum => $_ } # Find all locations that don't have censusyear = the current # year as of now. -my @cust_location = qsearch( 'cust_location', - { censusyear => { op => '!=', value => $current_year } }, -); +my @cust_location = qsearch({ + 'table' => 'cust_location', + 'hashref' => { 'country' => 'US', }, + 'extra_sql' => " AND ( censusyear != '$current_year' + OR censustract IS NULL + ) + ", +}); warn scalar(@cust_location)." records found.\n"; my $queued = 0; my $updated = 0; @@ -84,8 +89,8 @@ freeside-censustract-update - Update census tract codes to the current year. =head1 DESCRIPTION Finds all customers whose census tract codes don't appear to be current -and updates them to the current year. The "current year" is defined by -the I configuration variable, not the calendar year. +and updates them to the current year. The "current year" is 2020, unless the +I configuration variable is set. The -d option tells the script to assume that tract codes last modified after some date are already current. Those customers will just have