6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearchs);
12 $FS::svc_Common::noexport_hack = 1;
17 or die 'Usage:\n\n artera.import user <artera_active_orders.csv';
22 my $csv = new Text::CSV_XS;
24 my $header = scalar(<>);
26 my( $num, $linked ) = ( 0, 0 );
29 my $status = $csv->parse($_)
30 or die $csv->error_input;
31 my($serial, $keycode, $name, $ordernum, $email) = $csv->fields();
32 #warn join(" - ", $serial, $keycode, $name, $ordernum, $email ). "\n";
34 $email =~ /^([^@]+)\@([^@]+)$/
36 my($username, $domain) = ( $1, $2 );
37 my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } );
40 my $svc_acct = qsearchs('svc_acct', {
41 'username' => $username,
42 'domsvc' => $svc_domain->svcnum,
44 $cust_svc = $svc_acct->cust_svc
47 # warn "can't find domain $domain\n";
50 my $exist = qsearchs('svc_external', { 'id' => $serial } );
53 my $svc_external = new FS::svc_external {
54 'svcpart' => $svcpart,
55 'pkgnum' => ( $cust_svc ? $cust_svc->pkgnum : '' ),
59 #my $error = $svc_external->check;
60 my $error = $svc_external->insert;
61 if ( $cust_svc && $error =~ /^Already/ ) {
63 $svc_external->pkgnum('');
64 $error = $svc_external->insert;
66 warn $error if $error;
69 $linked++ if $cust_svc;
70 #print "$num imported, $linked linked\n";
74 print "$num imported, $linked linked\n";