projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
freeside-censustract-update + cust_location, #23422
[freeside.git]
/
FS
/
bin
/
freeside-censustract-update
diff --git
a/FS/bin/freeside-censustract-update
b/FS/bin/freeside-censustract-update
index
8c6721b
..
af9ad74
100644
(file)
--- a/
FS/bin/freeside-censustract-update
+++ b/
FS/bin/freeside-censustract-update
@@
-6,8
+6,8
@@
use Date::Parse 'str2time';
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearch dbh);
use FS::Conf;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearch dbh);
use FS::Conf;
-use FS::cust_
mai
n;
-use FS::h_cust_
mai
n;
+use FS::cust_
locatio
n;
+use FS::h_cust_
locatio
n;
my %opt;
getopts('d:', \%opt);
my %opt;
getopts('d:', \%opt);
@@
-22,40
+22,48
@@
my $current_year = $conf->config('census_year')
or die "No current census year configured.\n";
my $date = str2time($opt{d}) if $opt{d};
$date ||= time;
or die "No current census year configured.\n";
my $date = str2time($opt{d}) if $opt{d};
$date ||= time;
-my %h_cust_main = map { $_->custnum => $_ }
+# 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.
+my %h_cust_location = map { $_->locationnum => $_ }
qsearch(
qsearch(
- 'h_cust_
mai
n',
+ 'h_cust_
locatio
n',
{ censusyear => { op => '!=', value => $current_year } },
{ censusyear => { op => '!=', value => $current_year } },
- FS::h_cust_
mai
n->sql_h_search($date),
- ) ;
#the state of these customers as of $date
+ FS::h_cust_
locatio
n->sql_h_search($date),
+ ) ;
-my @cust_main = qsearch( 'cust_main',
+# 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 } },
{ censusyear => { op => '!=', value => $current_year } },
-);
# all possibly interesting customers
+);
-warn scalar(@cust_
mai
n)." records found.\n";
+warn scalar(@cust_
locatio
n)." records found.\n";
my $queued = 0; my $updated = 0;
my $queued = 0; my $updated = 0;
-foreach my $cust_
main (@cust_mai
n) {
+foreach my $cust_
location (@cust_locatio
n) {
my $error;
my $error;
- my $h = $h_cust_main{$cust_main->custnum};
- if ( defined($h) and $h->censustract eq $cust_main->censustract ) {
- # the tract code hasn't been changed since $date
- # so update it now
+ my $h = $h_cust_location{$cust_location->locationnum};
+ if ( defined($h) and $h->censustract eq $cust_location->censustract ) {
+ # Then the location's censustract hasn't been changed since $date
+ # (or it didn't exist on $date, or $date is now). Queue a censustract
+ # update for it.
my $job = FS::queue->new({
my $job = FS::queue->new({
- job => 'FS::cust_
mai
n::process_censustract_update'
+ job => 'FS::cust_
locatio
n::process_censustract_update'
});
});
- $error = $job->insert($cust_
main->cust
num);
+ $error = $job->insert($cust_
location->location
num);
$queued++;
}
$queued++;
}
- elsif ($cust_main->censusyear eq '') {
- # the tract number is assumed current, so just set the year
- $cust_main->set('censusyear', $current_year);
- $error = $cust_main->replace;
+ elsif ($cust_location->censusyear eq '') {
+ # Then it's been updated since $date, but somehow has a null censusyear.
+ # (Is this still relevant?)
+ $cust_location->set('censusyear', $current_year);
+ $error = $cust_location->replace;
$updated++;
$updated++;
- }
+ }
# Else it's been updated since $date, so leave it alone.
if ( $error ) {
$dbh->rollback;
if ( $error ) {
$dbh->rollback;
- die "error updating ".$cust_
main->cust
num.": $error\n";
+ die "error updating ".$cust_
location->location
num.": $error\n";
}
}
warn "Queued $queued census code lookups, updated year in $updated records.\n";
}
}
warn "Queued $queued census code lookups, updated year in $updated records.\n";