blob: c3d79e22c8870cbf088ed910b6218ebd56dcfa29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<%
my $DEBUG = 0;
$cgi->param('pkgnum') =~ /^(\d+)$/;
my $pkgnum = $1;
$cgi->param('svcpart') =~ /^(\d+)$/;
my $svcpart = $1;
$cgi->param('svcnum') =~ /^(\d*)$/;
my $svcnum = $1;
unless ( $svcnum ) {
my $part_svc = qsearchs('part_svc',{'svcpart'=>$svcpart});
my $svcdb = $part_svc->getfield('svcdb');
$cgi->param('link_field') =~ /^(\w+)$/;
my $link_field = $1;
my %search = ( $link_field => $cgi->param('link_value') );
if ( $cgi->param('link_field2') =~ /^(\w+)$/ ) {
$search{$1} = $cgi->param('link_value2');
}
my @svc_x = ( sort { ($a->cust_svc->pkgnum > 0) <=> ($b->cust_svc->pkgnum > 0)
or ($b->cust_svc->svcpart == $svcpart)
<=> ($a->cust_svc->svcpart == $svcpart)
}
qsearch( $svcdb, \%search )
);
if ( $DEBUG ) {
warn scalar(@svc_x). " candidate accounts found for linking ".
"(svcpart $svcpart):\n";
foreach my $svc_x ( @svc_x ) {
warn " ". $svc_x->email.
" (svcnum ". $svc_x->svcnum. ",".
" pkgnum ". $svc_x->cust_svc->pkgnum. ",".
" svcpart ". $svc_x->cust_svc->svcpart. ")\n";
}
}
my $svc_x = $svc_x[0];
eidiot("$link_field not found!") unless $svc_x;
$svcnum = $svc_x->svcnum;
}
my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum});
die "svcnum not found!" unless $old;
my $conf = new FS::Conf;
my($error, $new);
if ( $old->pkgnum && ! $conf->exists('legacy_link-steal') ) {
$error = "svcnum $svcnum already linked to package ". $old->pkgnum;
} else {
$new = new FS::cust_svc ({
'svcnum' => $svcnum,
'pkgnum' => $pkgnum,
'svcpart' => $svcpart,
});
$error = $new->replace($old);
}
unless ($error) {
#no errors, so let's view this customer.
my $custnum = $new->cust_pkg->custnum;
print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum".
"#cust_pkg$pkgnum" );
} else {
%>
<!-- mason kludge -->
<%
idiot($error);
}
%>
|