10 use FS::UID qw(adminsuidsetup);
11 use FS::Record qw(qsearchs qsearch);
23 my $part_export = qsearchs('part_export' => { exportnum => $exportnum })
24 or die "can't find export $exportnum\n";
26 my $srs = $part_export->get_srs;
28 my $rv = $srs->make_request(
30 action => 'get_domains_by_expiredate',
33 exp_from => time2str('%Y-%m-%d', time() - 4*24*60*60),
34 exp_to => time2str('%Y-%m-%d', time() + 10*366*24*60*60),
40 die $rv->{response_text} unless $rv->{is_success};
42 my %domains = map { $_->{name}, $_ } @{ $rv->{attributes}->{exp_domains} };
46 # 'f_let_expire' => 'N',
47 # 'name' => 'wolfecpa.com',
48 # 'f_auto_renew' => 'N',
49 # 'expiredate' => '2017-09-16 04:00:00'
52 foreach my $svc_domain ( $part_export->svc_x ) {
53 unless ( exists($domains{$svc_domain->domain}) ) {
54 warn $svc_domain->domain. " not at registrar. No action taken.\n";
58 $domains{$svc_domain->domain}{seen} = 1;
60 unless ( $domains{$svc_domain->domain}{expiredate} =~
61 /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/ )
63 warn "Can't parse expiration date for ". $svc_domain->domain. " skipping\n";
67 my ($year,$month,$day,$hour,$minute,$second) = ($1,$2,$3,$4,$5,$6);
68 my $exp = DateTime->new( year => $year,
74 time_zone => 'America/New_York',#timezone of opensrs
76 #my $expiretime = $exp->epoch;
78 #set the bill date early enough to allow a couple chances to pay
84 my $bill = DateTime->new( year => $year,
90 time_zone => 'America/Chicago',#timezone of customer
92 my $expiretime = $bill->epoch;
94 my $error = $part_export->is_supported_domain($svc_domain);
95 warn $error if $error;
99 my $whois = whois($svc_domain->domain);
100 $whois =~ /Record created on (\d{1,2}-\w{3}-\d{4})\./ && ($create = $1);
101 my $createtime = str2time($create);
103 unless ($createtime) {
104 $exp->subtract( 'years' => 1 );
105 $createtime = $exp->epoch;
109 my $cust_svc = $svc_domain->cust_svc;
110 my $cust_pkg = $cust_svc->cust_pkg;
112 warn $svc_domain->domain. " not linked to package. No action taken.\n";
116 foreach my $pkg ( grep { $_->pkgpart == $pkgpart } $cust_pkg->cust_main->ncancelled_pkgs ) {
117 next if $pkg->cust_svc; # only handles simple 1 domain/package case
118 $cust_svc->pkgnum($pkg->pkgnum);
119 $error = $cust_svc->replace;
120 die "error linking to empty package: $error\n" if $error;
125 unless ($cust_pkg->pkgpart == $pkgpart) {
126 $new = new FS::cust_pkg
127 { custnum => $cust_pkg->custnum, pkgpart => $pkgpart };
128 my $error = $new->insert;
129 die "error inserting package: $error\n" if $error;
130 $cust_svc->pkgnum($new->pkgnum);
131 $error = $cust_svc->replace;
132 die "error linking to new package: $error\n" if $error;
136 # set dates on package if it was empty?
137 $cust_pkg->bill($expiretime);
138 $cust_pkg->setup($createtime);
139 $error = $cust_pkg->replace;
140 die $error if $error;