diff options
author | Ivan Kohler <ivan@freeside.biz> | 2013-11-09 12:03:52 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2013-11-09 12:03:52 -0800 |
commit | 0c04fc78f66d17a5736686757cd8f838715c8380 (patch) | |
tree | 582834c1115e6e28c78974a4cd336bed89d23cd9 /bin | |
parent | 9545a93c2cb4ee76c4226e0eacf9a6fb9c169adf (diff) | |
parent | b668e94b7ed814217c9e4a9cfec6ed4df98e023a (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'bin')
-rw-r--r-- | bin/restore-ship_company | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/restore-ship_company b/bin/restore-ship_company new file mode 100644 index 000000000..cee700962 --- /dev/null +++ b/bin/restore-ship_company @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use FS::UID 'adminsuidsetup'; +use FS::Record qw(qsearch qsearchs dbh); +use FS::cust_main; +my $user = shift or die "Usage: + restore-ship_company username [ max-age ] +"; +adminsuidsetup($user); + +$FS::UID::AutoCommit = 1; +local $FS::cust_main::import = 1; + +my $days = shift || 30; +my $time = time - (86400*$days); # by default, only restore within the last + # 30 days +foreach my $cust_main (qsearch('cust_main', { ship_company => '' })) { + my $custnum = $cust_main->custnum; + my $last_h = qsearchs({ + table => 'h_cust_main', + extra_sql => " WHERE custnum = $custnum". + " AND ship_company IS NOT NULL". + " AND history_date >= $time", + order_by => " ORDER BY history_date DESC LIMIT 1", + }); + next if !$last_h; + print "$custnum\t".$last_h->ship_company."\n"; + $cust_main->set('ship_company' => $last_h->ship_company); + my $error = $cust_main->replace; + warn "Error setting service company for customer #$custnum:\n $error\n" + if $error; +} |