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