1 package FS::svc_Domain_Mixin;
5 use FS::Record qw(qsearch qsearchs);
13 FS::svc_Domain_Mixin - Mixin class for svc_classes with a domsvc field
17 package FS::svc_table;
18 use base qw( FS::svc_Domain_Mixin FS::svc_Common );
22 This is a mixin class for svc_ classes that contain a domsvc field linking to
23 a domain (see L<FS::svc_domain>).
29 =item domain [ END_TIMESTAMP [ START_TIMESTAMP ] ]
31 Returns the domain associated with this account.
33 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
40 #die "svc_acct.domsvc is null for svcnum ". $self->svcnum unless $self->domsvc;
41 return '' unless $self->domsvc;
42 my $svc_domain = $self->svc_domain(@_)
43 or die "no svc_domain.svcnum for domsvc ". $self->domsvc;
49 Returns the FS::svc_domain record for this account's domain (see
54 # FS::h_svc_acct has a history-aware svc_domain override
60 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
63 =item domain_select_hash %OPTIONS
65 Object or class method.
67 Returns a hash SVCNUM => DOMAIN ... representing the domains this customer
68 may at present purchase.
70 Currently available options are: I<pkgnum> and I<svcpart>.
74 sub domain_select_hash {
75 my ($self, %options) = @_;
78 my $conf = new FS::Conf;
84 $part_svc = $self->part_svc;
85 $cust_pkg = $self->cust_svc->cust_pkg
89 $part_svc = qsearchs('part_svc', { 'svcpart' => $options{svcpart} })
90 if $options{'svcpart'};
92 $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $options{pkgnum} })
93 if $options{'pkgnum'};
95 if ($part_svc && ( $part_svc->part_svc_column('domsvc')->columnflag eq 'S'
96 || $part_svc->part_svc_column('domsvc')->columnflag eq 'F')) {
97 %domains = map { $_->svcnum => $_->domain }
98 map { qsearchs('svc_domain', { 'svcnum' => $_ }) }
99 split(',', $part_svc->part_svc_column('domsvc')->columnvalue);
100 }elsif ($cust_pkg && !$conf->exists('svc_acct-alldomains') ) {
101 %domains = map { $_->svcnum => $_->domain }
102 map { qsearchs('svc_domain', { 'svcnum' => $_->svcnum }) }
103 map { qsearch('cust_svc', { 'pkgnum' => $_->pkgnum } ) }
104 qsearch('cust_pkg', { 'custnum' => $cust_pkg->custnum });
106 %domains = map { $_->svcnum => $_->domain } qsearch('svc_domain', {} );
109 if ($part_svc && $part_svc->part_svc_column('domsvc')->columnflag eq 'D') {
110 my $svc_domain = qsearchs('svc_domain',
111 { 'svcnum' => $part_svc->part_svc_column('domsvc')->columnvalue } );
113 $domains{$svc_domain->svcnum} = $svc_domain->domain;
115 warn "unknown svc_domain.svcnum for part_svc_column domsvc: ".
116 $part_svc->part_svc_column('domsvc')->columnvalue;
130 L<FS::svc_Common>, L<FS::Record>