auto-add service ips to network monitoring, RT#15536
[freeside.git] / FS / FS / svc_dsl.pm
1 package FS::svc_dsl;
2
3 use strict;
4 use vars qw( @ISA $conf $DEBUG $me );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::svc_Common;
7 use FS::dsl_device;
8 use FS::dsl_note;
9 use FS::qual;
10
11 @ISA = qw( FS::svc_Common );
12 $DEBUG = 0;
13 $me = '[FS::svc_dsl]';
14
15 FS::UID->install_callback( sub { 
16   $conf = new FS::Conf;
17 }
18 );
19
20 =head1 NAME
21
22 FS::svc_dsl - Object methods for svc_dsl records
23
24 =head1 SYNOPSIS
25
26   use FS::svc_dsl;
27
28   $record = new FS::svc_dsl \%hash;
29   $record = new FS::svc_dsl { 'column' => 'value' };
30
31   $error = $record->insert;
32
33   $error = $new_record->replace($old_record);
34
35   $error = $record->delete;
36
37   $error = $record->check;
38   
39   $error = $record->suspend;
40
41   $error = $record->unsuspend;
42
43   $error = $record->cancel;
44
45 =head1 DESCRIPTION
46
47 An FS::svc_dsl object represents a DSL service.  FS::svc_dsl inherits from
48 FS::svc_Common.  The following fields are currently supported:
49
50 =over 4
51
52 =item svcnum - Primary key (assigned automatcially for new DSL))
53
54 =item pushed - Time DSL order pushed to vendor/telco, if applicable
55
56 =item desired_due_date - Desired Due Date
57
58 =item due_date - Due Date
59
60 =item vendor_order_id - Vendor/telco DSL order #
61
62 =item vendor_order_type
63
64 Vendor/telco DSL order type (e.g. (M)ove, (A)dd, (C)hange, (D)elete, or similar)
65
66 =item vendor_order_status
67
68 Vendor/telco DSL order status (e.g. (N)ew, (A)ssigned, (R)ejected, (M)revised,
69 (C)ompleted, (X)cancelled, or similar)
70
71 =item first - End-user first name
72
73 =item last - End-user last name
74
75 =item company - End-user company name
76
77 =item phonenum - DSL Telephone Number
78
79 =item gateway_access_number - Gateway access number, if different
80
81 =item loop_type - Loop-type - vendor/telco-specific
82
83 =item local_voice_provider - Local Voice Provider's name
84
85 =item circuitnum - Circuit #
86
87 =item vpi
88
89 =item vci
90
91 =item rate_band - Rate Band
92
93 =item isp_chg
94
95 =item isp_prev
96
97 =item staticips
98
99 =item vendor_qual_id
100
101 Ikano-specific fields, do not use otherwise
102
103 =item username - if outsourced PPPoE/RADIUS, username
104
105 =item password - if outsourced PPPoE/RADIUS, password
106
107 =item monitored - Order is monitored (auto-pull/sync), either Y or blank
108
109 =item last_pull - time of last data pull from vendor/telco
110
111
112 =back
113
114 =head1 METHODS
115
116 =over 4
117
118 =item new HASHREF
119
120 Creates a new DSL.  To add the DSL to the database, see L<"insert">.
121
122 Note that this stores the hash reference, not a distinct copy of the hash it
123 points to.  You can ask the object for a copy with the I<hash> method.
124
125 =cut
126
127 # the new method can be inherited from FS::Record, if a table method is defined
128
129 sub table_info {
130     my %dis1 = ( disable_default=>1, disable_fixed=>1, disable_inventory=>1, disable_select=>1 );
131     my %dis2 = ( disable_inventory=>1, disable_select=>1 );
132
133     {
134         'name' => 'DSL',
135         'name_plural' => 'DSLs',
136         'lcname_plural' => 'DSLs',
137         'sorts' => [ 'phonenum' ],
138         'display_weight' => 55,
139         'cancel_weight' => 75,
140         'ip_field' => 'staticips',
141         'fields' => {
142             'pushed'                => { label => 'Pushed', 
143                                          type  => 'disabled' },
144             'desired_due_date'      => { label => 'Desired Due Date', %dis2, },
145             'due_date'              => { label => 'Due Date', %dis2, },
146             'vendor_order_id'       => { label => 'Vendor Order ID', %dis2, },
147             'vendor_qual_id'        => { label => 'Vendor Qualification ID', 
148                                          type => 'disabled' },
149             'vendor_order_type'     => { label => 'Vendor Order Type',
150                                          disable_inventory => 1, },
151             'vendor_order_status'   => { label => 'Vendor Order Status',
152                                          disable_inventory => 1, },
153             'first'                 => { label => 'First Name', %dis2, },
154             'last'                  => { label => 'Last Name', %dis2, },
155             'company'               => { label => 'Company Name', %dis2, },
156             'phonenum'              => { label => 'Service Telephone Number', },
157             'gateway_access_number' => { label => 'Gateway Access Number'.
158                                                   ' (if different)', },
159             'loop_type'             => { label => 'Loop Type',
160                                          disable_inventory => 1, },
161             'local_voice_provider'  => { label => 'Local Voice Provider',
162                                          disable_inventory => 1, },
163             'circuitnum'            => { label => 'Circuit #',        },
164             'rate_band'             => { label => 'Rate Band',
165                                          disable_inventory => 1, },
166             'vpi'                   => { label => 'VPI',
167                                          disable_inventory => 1 },
168             'vci'                   => { label => 'VCI',
169                                          disable_inventory => 1 },
170             'isp_chg'               => { label => 'ISP Changing?', 
171                                          type  => 'checkbox',
172                                          %dis2, },
173             'isp_prev'              => { label => 'Current or Previous ISP',
174                                          disable_inventory => 1, },
175             'username'              => { label => 'PPPoE Username',
176                                          type  => 'text', },
177             'password'              => { label => 'PPPoE Password', %dis2 },
178             'staticips'             => { label => 'Static IPs', %dis1 },
179             'monitored'             => { label => 'Monitored', 
180                                          type => 'checkbox', %dis2 },
181             'last_pull'             => { label => 'Last Pull',
182                                          type  => 'disabled' },
183         },
184     };
185 }
186
187 sub table { 'svc_dsl'; }
188
189 sub label {
190    my $self = shift;
191    return $self->phonenum if $self->phonenum;
192    return $self->username if $self->username;
193    return $self->vendor_order_id if $self->vendor_order_id;
194    return $self->svcnum;
195 }
196
197 =item notes
198
199 Returns the set of FS::dsl_notes associated with this service
200
201 =cut 
202 sub notes {
203   my $self = shift;
204   qsearch( 'dsl_note', { 'svcnum' => $self->svcnum } );
205 }
206
207 =item insert
208
209 Adds this record to the database.  If there is an error, returns the error,
210 otherwise returns false.
211
212 =cut
213
214 # the insert method can be inherited from FS::Record
215
216 =item delete
217
218 Delete this record from the database.
219
220 =cut
221
222 # the delete method can be inherited from FS::Record
223
224 =item replace OLD_RECORD
225
226 Replaces the OLD_RECORD with this one in the database.  If there is an error,
227 returns the error, otherwise returns false.
228
229 =cut
230
231 # the replace method can be inherited from FS::Record
232
233 =item check
234
235 Checks all fields to make sure this is a valid DSL.  If there is
236 an error, returns the error, otherwise returns false.  Called by the insert
237 and replace methods.
238
239 =cut
240
241 # the check method should currently be supplied - FS::Record contains some
242 # data checking routines
243
244 sub check {
245   my $self = shift;
246
247   my $error = 
248     $self->ut_numbern('svcnum')
249     || $self->ut_numbern('pushed')
250     || $self->ut_numbern('desired_due_date')
251     || $self->ut_numbern('due_date')
252     || $self->ut_textn('vendor_order_id')
253     || $self->ut_textn('vendor_qual_id')
254     || $self->ut_alphan('vendor_order_type')
255     || $self->ut_alphan('vendor_order_status')
256     || $self->ut_textn('first')
257     || $self->ut_textn('last')
258     || $self->ut_textn('company')
259     || $self->ut_numbern('phonenum')
260     || $self->ut_numbern('gateway_access_number')
261     || $self->ut_alphasn('loop_type')
262     || $self->ut_textn('local_voice_provider')
263     || $self->ut_textn('circuitnum')
264     || $self->ut_textn('rate_band')
265     || $self->ut_numbern('vpi')
266     || $self->ut_numbern('vci')
267     || $self->ut_alphan('isp_chg')
268     || $self->ut_textn('isp_prev')
269     || $self->ut_textn('username')
270     || $self->ut_textn('password')
271     || $self->ut_textn('staticips')
272     || $self->ut_enum('monitored',    [ '', 'Y' ])
273     || $self->ut_numbern('last_pull')
274   ;
275   return $error if $error;
276
277   $self->gateway_access_number('')
278     if $self->phonenum && $self->phonenum eq $self->gateway_access_number;
279
280   $self->SUPER::check;
281 }
282
283 =item gateway_access_or_phonenum
284
285 =cut
286
287 sub gateway_access_or_phonenum {
288   my $self = shift;
289   $self->gateway_access_number || $self->phonenum;
290 }
291
292 =item dsl_device
293
294 Returns the MAC addresses associated with this DSL service, as FS::dsl_device
295 objects.
296
297 =cut
298
299 sub dsl_device {
300   my $self = shift;
301   qsearch('dsl_device', { 'svcnum' => $self->svcnum });
302 }
303
304 sub predelete_hook_first {
305     my $self = shift;
306     my @exports = $self->part_svc->part_export_dsl_pull;
307     return 'More than one DSL-pulling export attached' if scalar(@exports) > 1;
308     if ( scalar(@exports) == 1 ) {
309         my $export = $exports[0];
310         return $export->dsl_pull($self);
311     }
312     '';
313 }
314
315 sub predelete_hook {
316     my $self = shift;
317     my @notes = $self->notes;
318     foreach my $note ( @notes ) {
319         my $error = $note->delete;
320         return $error if $error;
321     }
322     '';
323 }
324
325 =back
326
327 =head1 SEE ALSO
328
329 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
330 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
331 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
332 L<freeside-queued>, schema.html from the base documentation.
333
334 =cut
335
336 1;
337