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