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
43 =item svcnum - primary key; see also L<FS::cust_svc>
45 =item typenum - circuit type (such as DS1, DS1-PRI, DS3, OC3, etc.); foreign
46 key to L<FS::circuit_type>.
48 =item providernum - circuit provider (telco); foreign key to
49 L<FS::circuit_provider>.
51 =item termnum - circuit termination type; foreign key to
52 L<FS::circuit_termination>
54 =item circuit_id - provider circuit ID string defined by the provider
56 =item desired_due_date - the requested date for completion of the circuit
59 =item due_date - the provider's committed date for completion of the circuit
62 =item vendor_order_id - the provider's order number
64 =item vendor_qual_id - the qualification number, if a qualification was
67 =item vendor_order_type -
69 =item vendor_order_status - the order status: ACCEPTED, PENDING, COMPLETED,
72 =item endpoint_ip_addr - the IP address of the endpoint equipment, if any.
73 This will be validated as an IP address but not assigned from managed address
74 space or checked for uniqueness.
76 =item endpoint_mac_addr - the MAC address of the endpoint.
78 =item internal_circuit_id - internal circuit ID string
88 Creates a new circuit service. To add the record to the database, see
93 sub table { 'svc_circuit'; }
96 my %dis = ( disable_default => 1, disable_fixed => 1,
97 disabled_inventory => 1, disable_select => 1 );
99 tie my %fields, 'Tie::IxHash', (
100 'svcnum' => 'Service',
104 select_table => 'circuit_provider',
105 select_key => 'providernum',
106 select_label => 'provider',
107 disable_inventory => 1,
110 label => 'Circuit type',
112 select_table => 'circuit_type',
113 select_key => 'typenum',
114 select_label => 'typename',
115 disable_inventory => 1,
118 label => 'Termination type',
120 select_table => 'circuit_termination',
121 select_key => 'termnum',
122 select_label => 'termination',
123 disable_inventory => 1,
125 'circuit_id' => { label => 'Provider Circuit ID', %dis },
126 'desired_due_date' => { label => 'Desired due date',
129 'due_date' => { label => 'Due date',
132 'vendor_order_id' => { label => 'Vendor order ID', %dis },
133 'vendor_qual_id' => { label => 'Vendor qualification ID', %dis },
134 'vendor_order_type' => {
135 label => 'Vendor order type',
136 disable_inventory => 1
137 }, # should be a select?
138 'vendor_order_status' => {
139 label => 'Vendor order status',
140 disable_inventory => 1
141 }, # should also be a select?
142 'endpoint_ip_addr' => {
143 label => 'Endpoint IP address',
145 'endpoint_mac_addr' => {
146 label => 'Endpoint MAC address',
147 type => 'input-mac_addr',
148 disable_inventory => 1,
150 'internal_circuit_id' => { label => 'Internal Circuit ID', %dis },
154 'name_plural' => 'Circuits',
155 'longname_plural' => 'Voice and data circuit services',
156 'display_weight' => 72,
157 'cancel_weight' => 85, # after svc_phone
158 'fields' => \%fields,
164 Adds this record to the database. If there is an error, returns the error,
165 otherwise returns false.
169 Delete this record from the database.
171 =item replace OLD_RECORD
173 Replaces the OLD_RECORD with this one in the database. If there is an error,
174 returns the error, otherwise returns false.
178 Checks all fields to make sure this is a valid service. If there is
179 an error, returns the error, otherwise returns false. Called by the insert
187 my $mac_addr = uc($self->get('endpoint_mac_addr'));
188 $mac_addr =~ s/[\W_]//g;
189 $self->set('endpoint_mac_addr', $mac_addr);
192 $self->ut_numbern('svcnum')
193 || $self->ut_number('typenum')
194 || $self->ut_number('providernum')
195 || $self->ut_text('circuit_id')
196 || $self->ut_numbern('desired_due_date')
197 || $self->ut_numbern('due_date')
198 || $self->ut_textn('vendor_order_id')
199 || $self->ut_textn('vendor_qual_id')
200 || $self->ut_textn('vendor_order_type')
201 || $self->ut_textn('vendor_order_status')
202 || $self->ut_ipn('endpoint_ip_addr')
203 || $self->ut_textn('endpoint_mac_addr')
204 || $self->ut_textn('internal_circuit_id')
207 # no canonical values yet for vendor_order_status or _type
209 return $error if $error;
216 Returns the circuit ID.
222 $self->get('circuit_id');
226 my ($class, $string) = @_;
228 push @where, 'LOWER(svc_circuit.circuit_id) = LOWER(' . dbh->quote($string) . ')';
229 push @where, 'LOWER(circuit_provider.provider) = LOWER(' . dbh->quote($string) . ')';
230 push @where, 'LOWER(circuit_type.typename) = LOWER(' . dbh->quote($string) . ')';
231 '(' . join(' OR ', @where) . ')';
234 sub search_sql_addl_from {
235 'LEFT JOIN circuit_provider USING ( providernum ) '.
236 'LEFT JOIN circuit_type USING ( typenum )';
241 require FS::Misc::FixIPFormat;
242 FS::Misc::FixIPFormat::fix_bad_addresses_in_table(
243 'svc_circuit', 'svcnum', 'endpoint_ip_addr',