3 use FS::UID qw(adminsuidsetup dbh);
4 use FS::Record qw(qsearch);
10 use FS::access_groupagent;
13 # -t passes through the typenum in agent_type
16 adminsuidsetup shift or die &usage;
18 $FS::UID::AutoCommit = 0;
20 my @sales = qsearch('sales', {'disabled'=>''});
22 foreach my $sales (@sales) {
24 my $agent = new FS::agent {
25 'agent' => $sales->salesperson,
26 'agent_custnum' => $sales->sales_custnum,
29 my $error = $agent->insert;
31 dbh->rollback or die dbh->errstr;
35 my $access_group = new FS::access_group {
36 'groupname' => $agent->agent,
38 $error = $access_group->insert;
40 dbh->rollback or die dbh->errstr;
44 my $access_groupagent = new FS::access_groupagent {
45 'groupnum' => $access_group->groupnum,
46 'agentnum' => $agent->agentnum,
48 $error = $access_groupagent->insert;
50 dbh->rollback or die dbh->errstr;
54 foreach my $cust_main (qsearch('cust_main', {'salesnum'=>$sales->salesnum})) {
56 $cust_main->salesnum('');
57 $cust_main->agentnum($agent->agentnum);
58 $error = $cust_main->replace;
60 dbh->rollback or die dbh->errstr;
67 $error = $sales->replace;
69 dbh->rollback or die dbh->errstr;
75 dbh->commit or die dbh->errstr;
80 die "Usage:\n\n sales2agent username\n";