5 use FS::UID qw( adminsuidsetup dbh );
6 use FS::Record qw( qsearch );
7 use FS::cust_main_county;
9 adminsuidsetup shift or die "Usage: copy-cust_main_county username\n";
11 my $from_state = 'XX'; #XXX
13 $FS::UID::AutoCommit = 0;
15 my @from_cust_main_county = qsearch({
16 'table' => 'cust_main_county',
17 'hashref' => { 'state' => $from_state,
20 'extra_sql' => "AND taxname LIKE 'FED%'",
23 #select distinct state from cust_main_county where country = 'US'
24 #and then exclude the one other state?
26 #no, just find the target records directly. there should be one per state?
27 my @to_cust_main_county = qsearchs({
28 'table' => 'cust_main_county',
29 'hashref' => { 'taxclass' => '',
36 foreach my $to_cust_main_county (@to_cust_main_county) {
38 foreach my $from_cust_main_county (@from_cust_main_county) {
40 my $new = new FS::cust_main_county {
41 'state' => $to_cust_main_county->state,
43 map { $_ => $from_cust_main_county->$_ }
44 qw( tax taxclass taxname setuptax recurtax ),
47 my $error = $new->insert;
55 my $error = $to_cust_main_county->delete;
63 dbh->rollback or die dbh->errstr;
64 #dbh->commit or die dbh->errstr;