7 use FS::Record qw(fields qsearchs);
15 @ISA = qw(FS::Record Exporter);
19 FS::cust_svc - Object method for cust_svc objects
25 $record = create FS::cust_svc \%hash
26 $record = create FS::cust_svc { 'column' => 'value' };
28 $error = $record->insert;
30 $error = $new_record->replace($old_record);
32 $error = $record->delete;
34 $error = $record->check;
36 ($label, $value) = $record->label;
40 An FS::cust_svc represents a service. FS::cust_svc inherits from FS::Record.
41 The following fields are currently supported:
45 =item svcnum - primary key (assigned automatically for new services)
47 =item pkgnum - Package (see L<FS::cust_pkg>)
49 =item svcpart - Service definition (see L<FS::part_svc>)
59 Creates a new service. To add the refund to the database, see L<"insert">.
60 Services are normally created by creating FS::svc_ objects (see
61 L<FS::svc_acct>, L<FS::svc_domain>, and L<FS::svc_acct_sm>, among others).
66 my($proto,$hashref)=@_;
68 #now in FS::Record::new
70 #foreach $field (fields('cust_svc')) {
71 # $hashref->{$field}='' unless defined $hashref->{$field};
74 $proto->new('cust_svc',$hashref);
79 Adds this service to the database. If there is an error, returns the error,
80 otherwise returns false.
93 Deletes this service from the database. If there is an error, returns the
94 error, otherwise returns false.
96 Called by the cancel method of the package (see L<FS::cust_pkg>).
102 # anything else here?
106 =item replace OLD_RECORD
108 Replaces the OLD_RECORD with this one in the database. If there is an error,
109 returns the error, otherwise returns false.
115 return "(Old) Not a cust_svc record!" unless $old->table eq "cust_svc";
116 return "Can't change svcnum!"
117 unless $old->getfield('svcnum') eq $new->getfield('svcnum');
124 Checks all fields to make sure this is a valid service. If there is an error,
125 returns the error, otehrwise returns false. Called by the insert and
132 return "Not a cust_svc record!" unless $self->table eq "cust_svc";
133 my($recref) = $self->hashref;
135 $recref->{svcnum} =~ /^(\d*)$/ or return "Illegal svcnum";
136 $recref->{svcnum}=$1;
138 $recref->{pkgnum} =~ /^(\d*)$/ or return "Illegal pkgnum";
139 $recref->{pkgnum}=$1;
140 return "Unknown pkgnum" unless
141 ! $recref->{pkgnum} ||
142 qsearchs('cust_pkg',{'pkgnum'=>$recref->{pkgnum}});
144 $recref->{svcpart} =~ /^(\d+)$/ or return "Illegal svcpart";
145 $recref->{svcpart}=$1;
146 return "Unknown svcpart" unless
147 qsearchs('part_svc',{'svcpart'=>$recref->{svcpart}});
154 Returns a pretty-printed label and value for this service, i.e. `username' and
155 `foobar' or `domain' and `foo.bar'.
161 my($part_svc) = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
162 my($svcdb) = $part_svc->svcdb;
163 my($svc) = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } );
164 if ( $svcdb eq 'svc_acct' ) {
165 return 'username', $svc->getfield('username');
166 } elsif ( $svcdb eq 'svc_acct_sm' ) {
167 my $domuser = $svc->domuser eq '*' ? '(anything)' : $svc->domuser;
168 my $svc_domain = qsearchs ( 'svc_domain', { 'svcnum' => $svc->domsvc } );
169 my $domain = $svc_domain->domain;
170 return 'email', "$domuser\@$domain";
171 } elsif ( $svcdb eq 'svc_domain' ) {
172 return 'domain', $svc->getfield('domain');
174 carp "warning: asked for label of unsupported svcdb; using svcnum";
175 return 'svcnum', $svc->getfield('svcnum');
184 Behaviour of changing the svcpart of cust_svc records is undefined and should
185 possibly be prohibited, and pkg_svc records are not checked.
187 pkg_svc records are not checked in general (here).
191 L<FS::Record>, L<FS::cust_pkg>, L<FS::part_svc>, L<FS::pkg_svc>,
192 schema.html from the base documentation
196 ivan@voicenet.com 97-jul-10,14
198 no TableUtil, no FS::Lock ivan@sisd.com 98-mar-7
200 pod ivan@sisd.com 98-sep-21
202 $Log: cust_svc.pm,v $
203 Revision 1.3 1998-11-12 03:45:38 ivan
204 use FS::table_name for all tables qsearch()'ed
206 Revision 1.2 1998/11/12 03:32:46 ivan