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 list consisting of:
155 - The name of this service (from part_svc)
156 - A meaningful identifier (username, domain, or mail alias)
157 - The table name (i.e. svc_domain) for this service
163 my($part_svc) = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
164 my($svcdb) = $part_svc->svcdb;
165 my($svc_x) = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } );
166 my($svc) = $part_svc->svc;
168 if ( $svcdb eq 'svc_acct' ) {
169 $tag = $svc_x->getfield('username');
170 } elsif ( $svcdb eq 'svc_acct_sm' ) {
171 my $domuser = $svc_x->domuser eq '*' ? '(anything)' : $svc_x->domuser;
172 my $svc_domain = qsearchs ( 'svc_domain', { 'svcnum' => $svc_x->domsvc } );
173 my $domain = $svc_domain->domain;
174 $tag = "$domuser\@$domain";
175 } elsif ( $svcdb eq 'svc_domain' ) {
176 return $svc, $svc_x->getfield('domain');
178 carp "warning: asked for label of unsupported svcdb; using svcnum";
179 $tag = $svc_x->getfield('svcnum');
188 Behaviour of changing the svcpart of cust_svc records is undefined and should
189 possibly be prohibited, and pkg_svc records are not checked.
191 pkg_svc records are not checked in general (here).
195 L<FS::Record>, L<FS::cust_pkg>, L<FS::part_svc>, L<FS::pkg_svc>,
196 schema.html from the base documentation
200 ivan@voicenet.com 97-jul-10,14
202 no TableUtil, no FS::Lock ivan@sisd.com 98-mar-7
204 pod ivan@sisd.com 98-sep-21
206 $Log: cust_svc.pm,v $
207 Revision 1.4 1998-11-12 07:58:15 ivan
210 Revision 1.3 1998/11/12 03:45:38 ivan
211 use FS::table_name for all tables qsearch()'ed
213 Revision 1.2 1998/11/12 03:32:46 ivan