3 use FS::UID 'adminsuidsetup';
4 use FS::Record qw(qsearch qsearchs dbh);
6 my $user = shift or die "Usage:
7 restore-ship_company username [ max-age ]
11 $FS::UID::AutoCommit = 1;
12 local $FS::cust_main::import = 1;
14 my $days = shift || 30;
15 my $time = time - (86400*$days); # by default, only restore within the last
17 foreach my $cust_main (qsearch('cust_main', { ship_company => '' })) {
18 my $custnum = $cust_main->custnum;
19 my $last_h = qsearchs({
20 table => 'h_cust_main',
21 extra_sql => " WHERE custnum = $custnum".
22 " AND ship_company IS NOT NULL".
23 " AND history_date >= $time",
24 order_by => " ORDER BY history_date DESC LIMIT 1",
27 print "$custnum\t".$last_h->ship_company."\n";
28 $cust_main->set('ship_company' => $last_h->ship_company);
29 my $error = $cust_main->replace;
30 warn "Error setting service company for customer #$custnum:\n $error\n"