*** empty log message ***
[freeside.git] / site_perl / cust_svc.pm
1 package FS::cust_svc;
2
3 use strict;
4 use vars qw( @ISA );
5 use Carp qw( cluck );
6 use FS::Record qw( qsearchs );
7 use FS::cust_pkg;
8 use FS::part_pkg;
9 use FS::part_svc;
10 use FS::svc_acct;
11 use FS::svc_acct_sm;
12 use FS::svc_domain;
13
14 @ISA = qw( FS::Record );
15
16 =head1 NAME
17
18 FS::cust_svc - Object method for cust_svc objects
19
20 =head1 SYNOPSIS
21
22   use FS::cust_svc;
23
24   $record = new FS::cust_svc \%hash
25   $record = new FS::cust_svc { 'column' => 'value' };
26
27   $error = $record->insert;
28
29   $error = $new_record->replace($old_record);
30
31   $error = $record->delete;
32
33   $error = $record->check;
34
35   ($label, $value) = $record->label;
36
37 =head1 DESCRIPTION
38
39 An FS::cust_svc represents a service.  FS::cust_svc inherits from FS::Record.
40 The following fields are currently supported:
41
42 =over 4
43
44 =item svcnum - primary key (assigned automatically for new services)
45
46 =item pkgnum - Package (see L<FS::cust_pkg>)
47
48 =item svcpart - Service definition (see L<FS::part_svc>)
49
50 =back
51
52 =head1 METHODS
53
54 =over 4
55
56 =item new HASHREF
57
58 Creates a new service.  To add the refund to the database, see L<"insert">.
59 Services are normally created by creating FS::svc_ objects (see
60 L<FS::svc_acct>, L<FS::svc_domain>, and L<FS::svc_acct_sm>, among others).
61
62 =cut
63
64 sub table { 'cust_svc'; }
65
66 =item insert
67
68 Adds this service to the database.  If there is an error, returns the error,
69 otherwise returns false.
70
71 =item delete
72
73 Deletes this service from the database.  If there is an error, returns the
74 error, otherwise returns false.
75
76 Called by the cancel method of the package (see L<FS::cust_pkg>).
77
78 =item replace OLD_RECORD
79
80 Replaces the OLD_RECORD with this one in the database.  If there is an error,
81 returns the error, otherwise returns false.
82
83 =item check
84
85 Checks all fields to make sure this is a valid service.  If there is an error,
86 returns the error, otehrwise returns false.  Called by the insert and
87 replace methods.
88
89 =cut
90
91 sub check {
92   my $self = shift;
93
94   my $error =
95     $self->ut_numbern('svcnum')
96     || $self->ut_numbern('pkgnum')
97     || $self->ut_number('svcpart')
98   ;
99   return $error if $error;
100
101   return "Unknown pkgnum"
102     unless ! $self->pkgnum
103       || qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
104
105   return "Unknown svcpart" unless
106     qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
107
108   ''; #no error
109 }
110
111 =item label
112
113 Returns a list consisting of:
114 - The name of this service (from part_svc)
115 - A meaningful identifier (username, domain, or mail alias)
116 - The table name (i.e. svc_domain) for this service
117
118 =cut
119
120 sub label {
121   my $self = shift;
122   my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
123   my $svcdb = $part_svc->svcdb;
124   my $svc_x = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } );
125   my $svc = $part_svc->svc;
126   my $tag;
127   if ( $svcdb eq 'svc_acct' ) {
128     $tag = $svc_x->getfield('username');
129   } elsif ( $svcdb eq 'svc_acct_sm' ) {
130     my $domuser = $svc_x->domuser eq '*' ? '(anything)' : $svc_x->domuser;
131     my $svc_domain = qsearchs ( 'svc_domain', { 'svcnum' => $svc_x->domsvc } );
132     my $domain = $svc_domain->domain;
133     $tag = "$domuser\@$domain";
134   } elsif ( $svcdb eq 'svc_domain' ) {
135     $tag = $svc_x->getfield('domain');
136   } else {
137     cluck "warning: asked for label of unsupported svcdb; using svcnum";
138     $tag = $svc_x->getfield('svcnum');
139   }
140   $svc, $tag, $svcdb;
141 }
142
143 =back
144
145 =head1 VERSION
146
147 $Id: cust_svc.pm,v 1.5 1998-12-29 11:59:47 ivan Exp $
148
149 =head1 BUGS
150
151 Behaviour of changing the svcpart of cust_svc records is undefined and should
152 possibly be prohibited, and pkg_svc records are not checked.
153
154 pkg_svc records are not checked in general (here).
155
156 Deleting this record doesn't check or delete the svc_* record associated
157 with this record.
158
159 =head1 SEE ALSO
160
161 L<FS::Record>, L<FS::cust_pkg>, L<FS::part_svc>, L<FS::pkg_svc>, 
162 schema.html from the base documentation
163
164 =head1 HISTORY
165
166 ivan@voicenet.com 97-jul-10,14
167
168 no TableUtil, no FS::Lock ivan@sisd.com 98-mar-7
169
170 pod ivan@sisd.com 98-sep-21
171
172 $Log: cust_svc.pm,v $
173 Revision 1.5  1998-12-29 11:59:47  ivan
174 mostly properly OO, some work still to be done with svc_ stuff
175
176 Revision 1.4  1998/11/12 07:58:15  ivan
177 added svcdb to label
178
179 Revision 1.3  1998/11/12 03:45:38  ivan
180 use FS::table_name for all tables qsearch()'ed
181
182 Revision 1.2  1998/11/12 03:32:46  ivan
183 added label method
184
185
186 =cut
187
188 1;
189