7 use FS::Record qw(fields qsearchs);
9 @ISA = qw(FS::Record Exporter);
13 FS::cust_svc - Object method for cust_svc objects
19 $record = create FS::cust_svc \%hash
20 $record = create FS::cust_svc { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
30 ($label, $value) = $record->label;
34 An FS::cust_svc represents a service. FS::cust_svc inherits from FS::Record.
35 The following fields are currently supported:
39 =item svcnum - primary key (assigned automatically for new services)
41 =item pkgnum - Package (see L<FS::cust_pkg>)
43 =item svcpart - Service definition (see L<FS::part_svc>)
53 Creates a new service. To add the refund to the database, see L<"insert">.
54 Services are normally created by creating FS::svc_ objects (see
55 L<FS::svc_acct>, L<FS::svc_domain>, and L<FS::svc_acct_sm>, among others).
60 my($proto,$hashref)=@_;
62 #now in FS::Record::new
64 #foreach $field (fields('cust_svc')) {
65 # $hashref->{$field}='' unless defined $hashref->{$field};
68 $proto->new('cust_svc',$hashref);
73 Adds this service to the database. If there is an error, returns the error,
74 otherwise returns false.
87 Deletes this service from the database. If there is an error, returns the
88 error, otherwise returns false.
90 Called by the cancel method of the package (see L<FS::cust_pkg>).
100 =item replace OLD_RECORD
102 Replaces the OLD_RECORD with this one in the database. If there is an error,
103 returns the error, otherwise returns false.
109 return "(Old) Not a cust_svc record!" unless $old->table eq "cust_svc";
110 return "Can't change svcnum!"
111 unless $old->getfield('svcnum') eq $new->getfield('svcnum');
118 Checks all fields to make sure this is a valid service. If there is an error,
119 returns the error, otehrwise returns false. Called by the insert and
126 return "Not a cust_svc record!" unless $self->table eq "cust_svc";
127 my($recref) = $self->hashref;
129 $recref->{svcnum} =~ /^(\d*)$/ or return "Illegal svcnum";
130 $recref->{svcnum}=$1;
132 $recref->{pkgnum} =~ /^(\d*)$/ or return "Illegal pkgnum";
133 $recref->{pkgnum}=$1;
134 return "Unknown pkgnum" unless
135 ! $recref->{pkgnum} ||
136 qsearchs('cust_pkg',{'pkgnum'=>$recref->{pkgnum}});
138 $recref->{svcpart} =~ /^(\d+)$/ or return "Illegal svcpart";
139 $recref->{svcpart}=$1;
140 return "Unknown svcpart" unless
141 qsearchs('part_svc',{'svcpart'=>$recref->{svcpart}});
148 Returns a pretty-printed label and value for this service, i.e. `username' and
149 `foobar' or `domain' and `foo.bar'.
155 my($part_svc) = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
156 my($svcdb) = $part_svc->svcdb;
157 my($svc) = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } );
158 if ( $svcdb eq 'svc_acct' ) {
159 return 'username', $svc->getfield('username');
160 } elsif ( $svcdb eq 'svc_acct_sm' ) {
161 my $domuser = $svc->domuser eq '*' ? '(anything)' : $svc->domuser;
162 my $svc_domain = qsearchs ( 'svc_domain', { 'svcnum' => $svc->domsvc } );
163 my $domain = $svc_domain->domain;
164 return 'email', "$domuser\@$domain";
165 } elsif ( $svcdb eq 'svc_domain' ) {
166 return 'domain', $svc->getfield('domain');
168 carp "warning: asked for label of unsupported svcdb; using svcnum";
169 return 'svcnum', $svc->getfield('svcnum');
178 Behaviour of changing the svcpart of cust_svc records is undefined and should
179 possibly be prohibited, and pkg_svc records are not checked.
181 pkg_svc records are not checked in general (here).
185 L<FS::Record>, L<FS::cust_pkg>, L<FS::part_svc>, L<FS::pkg_svc>,
186 schema.html from the base documentation
190 ivan@voicenet.com 97-jul-10,14
192 no TableUtil, no FS::Lock ivan@sisd.com 98-mar-7
194 pod ivan@sisd.com 98-sep-21
196 $Log: cust_svc.pm,v $
197 Revision 1.2 1998-11-12 03:32:46 ivan