summaryrefslogtreecommitdiff
path: root/FS/FS/svc_fiber.pm
blob: 00b4e0e8a50b16e12680e455adbb66afc14e39d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package FS::svc_fiber;

use strict;
use base qw( FS::svc_Common );
use FS::cust_svc;
use FS::hardware_type;
use FS::fiber_olt;
use FS::Record 'dbh';

=head1 NAME

FS::svc_fiber - Object methods for svc_fiber records

=head1 SYNOPSIS

  use FS::table_name;

  $record = new FS::table_name \%hash;
  $record = new FS::table_name { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

  $error = $record->suspend;

  $error = $record->unsuspend;

  $error = $record->cancel;

=head1 DESCRIPTION

An FS::svc_fiber object represents a fiber-to-the-premises service.  
FS::svc_fiber inherits from FS::svc_Common.  The following fields are
currently supported:

=over 4

=item svcnum - Primary key

=item oltnum - The Optical Line Terminal this service connects to (see
L<FS::fiber_olt>).

=item shelf - The shelf number on the OLT.

=item card - The card number on the OLT shelf.

=item olt_port - The port number on that card.

=item vlan - The VLAN number.

=item signal - Measured signal strength in dB.

=item speed_up - Measured uplink speed in Mbps.

=item speed_down - Measured downlink speed in Mbps.

=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new fiber service record.  To add it to the database, see L<"insert">.

=cut

sub table { 'svc_fiber'; }

sub table_info {
  {
    'name' => 'Fiber',
    'name_plural' => 'Fiber', # really the name of the ACL
    'longname_plural' => 'Fiber services',
    'sorts' => [ 'oltnum', ],
    'display_weight' => 74,
    'cancel_weight'  => 74,
    'fields' => {
      'oltnum'        => {
                          'label'        => 'OLT',
                          'type'         => 'select',
                          'select_table' => 'fiber_olt',
                          'select_key'   => 'oltnum',
                          'select_label' => 'oltname',
                          'disable_inventory' => 1,
                         },
      'shelf'         => {
                          'label' => 'Shelf',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'card'          => {
                          'label' => 'Card',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'olt_port'      => {
                          'label' => 'GPON port',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      # ODN circuit
      'circuit_id'    => {
                          'label' => 'ODN circuit',
                          'type'  => 'input-fiber_circuit',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      # ONT stuff
      'ont_id'        => {
                          'label' => 'ONT #',
                          'disable_select'    => 1,
                         },
      'ont_typenum'   => {
                          'label' => 'Device type',
                          'type'  => 'select-hardware',
                          'disable_select'    => 1,
                          'disable_default'   => 1,
                          'disable_inventory' => 1,
                         },
      'ont_serial'    => {
                          'label' => 'Serial number',
                          'disable_select'    => 1,
                         },
      'ont_port'      => {
                          'label' => 'GE port',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'vlan'          => {
                          'label' => 'VLAN #',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'signal'        => {
                          'label' => 'Signal strength (dB)',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'speed_down'    => {
                          'label' => 'Download speed (Mbps)',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'speed_up'      => {
                          'label' => 'Upload speed (Mbps)',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
      'ont_install'   => {
                          'label' => 'ONT install location',
                          'type'  => 'text',
                          'disable_inventory' => 1,
                          'disable_select'    => 1,
                         },
    },
  };
}

=item search_sql STRING

Class method which returns an SQL fragment to search for the given string.
For svc_fiber, STRING can be a full or partial ONT serial number.

=cut

#or something more complicated if necessary
sub search_sql {
  my($class, $string) = @_;
  $string = dbh->quote('%' . $string . '%');
  "LOWER(svc_fiber.ont_serial) LIKE LOWER($string)";
}

=item label

Returns a description of this fiber service containing the ONT serial number
and the OLT name and port location.

=cut

sub label {
  my $self = shift;
  $self->ont_serial . ' @ ' . $self->fiber_olt->description . ' ' .
  join('-', $self->shelf, $self->card, $self->olt_port);
}

# nothing special for insert, delete, or replace

=item insert

Adds this record to the database.  If there is an error, returns the error,
otherwise returns false.

The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
defined.  An FS::cust_svc record will be created and inserted.

=item delete

Delete this record from the database.

=item replace OLD_RECORD

Replaces the OLD_RECORD with this one in the database.  If there is an error,
returns the error, otherwise returns false.

=item suspend

Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).

=item unsuspend

Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).

=item cancel

Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).

=item check

Checks all fields to make sure this is a valid example.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and repalce methods.

=cut

sub check {
  my $self = shift;

  my $x = $self->setfixed;
  return $x unless ref($x);
  my $part_svc = $x;

  my $error =
       $self->ut_number('oltnum')
    || $self->ut_numbern('shelf')
    || $self->ut_numbern('card')
    || $self->ut_numbern('olt_port')
    || $self->ut_number('ont_id')
    || $self->ut_number('ont_typenum')
    || $self->ut_alphan('ont_serial')
    || $self->ut_alphan('ont_port')
    || $self->ut_numbern('vlan')
    || $self->ut_sfloatn('signal')
    || $self->ut_numbern('speed_up')
    || $self->ut_numbern('speed_down')
    || $self->ut_textn('ont_install')
  ;
  return $error if $error;

  $self->set('signal', sprintf('%.2f', $self->get('signal')));

  $self->SUPER::check;
}

=item ont_description

Returns the description of the ONT hardware, if there is one.

=cut

sub ont_description {
  my $self = shift;
  $self->ont_typenum ? $self->hardware_type->description : '';
}

=item search HASHREF

Returns a qsearch hash expression to search for parameters specified in
HASHREF.

Parameters are those in L<FS::svc_Common/search>, plus:

ont_typenum - the ONT L<FS::hardware_type> key

oltnum - the OLT L<FS::fiber_olt> key

shelf, card, olt_port - the OLT port location fields

vlan - the VLAN number

ont_serial - the ONT serial number

=cut

sub _search_svc {
  my ($class, $params, $from, $where) = @_;

  # make this simple: all of these are numeric fields, except that 0 means null
  foreach my $field (qw(ont_typenum oltnum shelf olt_port card vlan)) {
    if ( $params->{$field} =~ /^(\d+)$/ ) {
      push @$where, "COALESCE($field,0) = $1";
    }
  }
  if ( length($params->{ont_serial}) ) {
    my $string = dbh->quote('%'.$params->{ont_serial}.'%');
    push @$where, "LOWER(ont_serial) LIKE LOWER($string)";
  }

}

#stub still needed under 4.x+

sub hardware_type {
  my $self = shift;
  $self->ont_typenum ? FS::hardware_type->by_key($self->ont_typenum) : '';
}

=back

=head1 SEE ALSO

L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
L<FS::cust_pkg>, schema.html from the base documentation.

=cut

1;