1 package FS::svc_circuit;
9 use FS::Record qw( dbh qsearch qsearchs );
10 use FS::circuit_provider;
12 use FS::circuit_termination;
16 FS::svc_circuit - Object methods for svc_circuit records
22 $record = new FS::svc_circuit \%hash;
23 $record = new FS::svc_circuit { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::svc_circuit object represents a telecom circuit service (other than
36 an analog phone line, which is svc_phone, or a DSL Internet connection,
37 which is svc_dsl). FS::svc_circuit inherits from FS::svc_IP_Mixin,
38 FS::MAC_Mixin, and FS::svc_Common. The following fields are currently
45 primary key; see also L<FS::cust_svc>
49 circuit type (such as DS1, DS1-PRI, DS3, OC3, etc.); foreign
50 key to L<FS::circuit_type>.
54 circuit provider (telco); foreign key to
55 L<FS::circuit_provider>.
59 circuit termination type; foreign key to
60 L<FS::circuit_termination>
64 provider circuit ID string defined by the provider
66 =item desired_due_date
68 the requested date for completion of the circuit
73 the provider's committed date for completion of the circuit
78 the provider's order number
82 the qualification number, if a qualification was
85 =item vendor_order_type
87 =item vendor_order_status
89 the order status: ACCEPTED, PENDING, COMPLETED,
92 =item endpoint_ip_addr
94 the IP address of the endpoint equipment, if any.
95 This will be validated as an IP address but not assigned from managed address
96 space or checked for uniqueness.
98 =item endpoint_mac_addr
100 the MAC address of the endpoint.
102 =item internal_circuit_id
104 internal circuit ID string
114 Creates a new circuit service. To add the record to the database, see
119 sub table { 'svc_circuit'; }
122 my %dis = ( disable_default => 1, disable_fixed => 1,
123 disabled_inventory => 1, disable_select => 1 );
125 tie my %fields, 'Tie::IxHash', (
126 'svcnum' => 'Service',
130 select_table => 'circuit_provider',
131 select_key => 'providernum',
132 select_label => 'provider',
133 disable_inventory => 1,
136 label => 'Circuit type',
138 select_table => 'circuit_type',
139 select_key => 'typenum',
140 select_label => 'typename',
141 disable_inventory => 1,
144 label => 'Termination type',
146 select_table => 'circuit_termination',
147 select_key => 'termnum',
148 select_label => 'termination',
149 disable_inventory => 1,
151 'circuit_id' => { label => 'Provider Circuit ID', %dis },
152 'desired_due_date' => { label => 'Desired due date',
155 'due_date' => { label => 'Due date',
158 'vendor_order_id' => { label => 'Vendor order ID', %dis },
159 'vendor_qual_id' => { label => 'Vendor qualification ID', %dis },
160 'vendor_order_type' => {
161 label => 'Vendor order type',
162 disable_inventory => 1
163 }, # should be a select?
164 'vendor_order_status' => {
165 label => 'Vendor order status',
166 disable_inventory => 1
167 }, # should also be a select?
168 'endpoint_ip_addr' => {
169 label => 'Endpoint IP address',
171 'endpoint_mac_addr' => {
172 label => 'Endpoint MAC address',
173 type => 'input-mac_addr',
174 disable_inventory => 1,
176 'internal_circuit_id' => { label => 'Internal Circuit ID', %dis },
180 'name_plural' => 'Circuits',
181 'longname_plural' => 'Voice and data circuit services',
182 'display_weight' => 72,
183 'cancel_weight' => 85, # after svc_phone
184 'fields' => \%fields,
190 Adds this record to the database. If there is an error, returns the error,
191 otherwise returns false.
195 Delete this record from the database.
197 =item replace OLD_RECORD
199 Replaces the OLD_RECORD with this one in the database. If there is an error,
200 returns the error, otherwise returns false.
204 Checks all fields to make sure this is a valid service. If there is
205 an error, returns the error, otherwise returns false. Called by the insert
213 my $mac_addr = uc($self->get('endpoint_mac_addr'));
214 $mac_addr =~ s/[\W_]//g;
215 $self->set('endpoint_mac_addr', $mac_addr);
218 $self->ut_numbern('svcnum')
219 || $self->ut_number('typenum')
220 || $self->ut_number('providernum')
221 || $self->ut_text('circuit_id')
222 || $self->ut_numbern('desired_due_date')
223 || $self->ut_numbern('due_date')
224 || $self->ut_textn('vendor_order_id')
225 || $self->ut_textn('vendor_qual_id')
226 || $self->ut_textn('vendor_order_type')
227 || $self->ut_textn('vendor_order_status')
228 || $self->ut_ipn('endpoint_ip_addr')
229 || $self->ut_textn('endpoint_mac_addr')
230 || $self->ut_textn('internal_circuit_id')
233 # no canonical values yet for vendor_order_status or _type
235 return $error if $error;
242 Returns the circuit ID.
248 $self->get('circuit_id');
252 my ($class, $string) = @_;
254 push @where, 'LOWER(svc_circuit.circuit_id) = LOWER(' . dbh->quote($string) . ')';
255 push @where, 'LOWER(circuit_provider.provider) = LOWER(' . dbh->quote($string) . ')';
256 push @where, 'LOWER(circuit_type.typename) = LOWER(' . dbh->quote($string) . ')';
257 '(' . join(' OR ', @where) . ')';
260 sub search_sql_addl_from {
261 'LEFT JOIN circuit_provider USING ( providernum ) '.
262 'LEFT JOIN circuit_type USING ( typenum )';
267 require FS::Misc::FixIPFormat;
268 FS::Misc::FixIPFormat::fix_bad_addresses_in_table(
269 'svc_circuit', 'svcnum', 'endpoint_ip_addr',