6 use FS::Record qw( qsearchs );
15 @ISA = qw( FS::Record );
19 my ( $hashref, $cache ) = @_;
20 if ( $hashref->{'username'} ) {
21 $self->{'_svc_acct'} = FS::svc_acct->new($hashref, '');
23 if ( $hashref->{'svc'} ) {
24 $self->{'_svcpart'} = FS::part_svc->new($hashref);
30 FS::cust_svc - Object method for cust_svc objects
36 $record = new FS::cust_svc \%hash
37 $record = new FS::cust_svc { 'column' => 'value' };
39 $error = $record->insert;
41 $error = $new_record->replace($old_record);
43 $error = $record->delete;
45 $error = $record->check;
47 ($label, $value) = $record->label;
51 An FS::cust_svc represents a service. FS::cust_svc inherits from FS::Record.
52 The following fields are currently supported:
56 =item svcnum - primary key (assigned automatically for new services)
58 =item pkgnum - Package (see L<FS::cust_pkg>)
60 =item svcpart - Service definition (see L<FS::part_svc>)
70 Creates a new service. To add the refund to the database, see L<"insert">.
71 Services are normally created by creating FS::svc_ objects (see
72 L<FS::svc_acct>, L<FS::svc_domain>, and L<FS::svc_forward>, among others).
76 sub table { 'cust_svc'; }
80 Adds this service to the database. If there is an error, returns the error,
81 otherwise returns false.
85 Deletes this service from the database. If there is an error, returns the
86 error, otherwise returns false.
88 Called by the cancel method of the package (see L<FS::cust_pkg>).
90 =item replace OLD_RECORD
92 Replaces the OLD_RECORD with this one in the database. If there is an error,
93 returns the error, otherwise returns false.
97 Checks all fields to make sure this is a valid service. If there is an error,
98 returns the error, otehrwise returns false. Called by the insert and
107 $self->ut_numbern('svcnum')
108 || $self->ut_numbern('pkgnum')
109 || $self->ut_number('svcpart')
111 return $error if $error;
113 return "Unknown pkgnum"
114 unless ! $self->pkgnum
115 || qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
117 return "Unknown svcpart" unless
118 qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
125 Returns the definition for this service, as a FS::part_svc object (see
133 ? $self->{'_svcpart'}
134 : qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
139 Returns a list consisting of:
140 - The name of this service (from part_svc)
141 - A meaningful identifier (username, domain, or mail alias)
142 - The table name (i.e. svc_domain) for this service
148 my $svcdb = $self->part_svc->svcdb;
150 if ( $svcdb eq 'svc_acct' && $self->{'_svc_acct'} ) {
151 $svc_x = $self->{'_svc_acct'};
153 $svc_x = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } )
154 or die "can't find $svcdb.svcnum ". $self->svcnum;
157 if ( $svcdb eq 'svc_acct' ) {
158 $tag = $svc_x->email;
159 } elsif ( $svcdb eq 'svc_acct_sm' ) {
160 my $domuser = $svc_x->domuser eq '*' ? '(anything)' : $svc_x->domuser;
161 my $svc_domain = qsearchs ( 'svc_domain', { 'svcnum' => $svc_x->domsvc } );
162 my $domain = $svc_domain->domain;
163 $tag = "$domuser\@$domain";
164 } elsif ( $svcdb eq 'svc_forward' ) {
165 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $svc_x->srcsvc } );
166 $tag = $svc_acct->email. '->';
167 if ( $svc_x->dstsvc ) {
168 $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $svc_x->dstsvc } );
169 $tag .= $svc_acct->email;
173 } elsif ( $svcdb eq 'svc_domain' ) {
174 $tag = $svc_x->getfield('domain');
176 cluck "warning: asked for label of unsupported svcdb; using svcnum";
177 $tag = $svc_x->getfield('svcnum');
179 $self->part_svc->svc, $tag, $svcdb;
186 $Id: cust_svc.pm,v 1.6 2001-11-03 17:49:52 ivan Exp $
190 Behaviour of changing the svcpart of cust_svc records is undefined and should
191 possibly be prohibited, and pkg_svc records are not checked.
193 pkg_svc records are not checked in general (here).
195 Deleting this record doesn't check or delete the svc_* record associated
200 L<FS::Record>, L<FS::cust_pkg>, L<FS::part_svc>, L<FS::pkg_svc>,
201 schema.html from the base documentation