2 use base qw( FS::MAC_Mixin
11 FS::svc_cable - Object methods for svc_cable records
17 $record = new FS::svc_cable \%hash;
18 $record = new FS::svc_cable { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::svc_cable object represents a cable subscriber. FS::svc_cable inherits
31 from FS::Record. The following fields are currently supported:
41 Provider (see L<FS::cable_provider>)
49 Cable device model (see L<FS::cable_model>)
53 Cable device serial number
57 Cable device MAC address
67 Creates a new record. To add the record to the database, see L<"insert">.
69 Note that this stores the hash reference, not a distinct copy of the hash it
70 points to. You can ask the object for a copy with the I<hash> method.
74 sub table { 'svc_cable'; }
76 sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); }
79 my( $class, $string ) = @_;
80 if ( $string =~ /^([A-F0-9]{12})$/i ) {
81 $class->search_sql_field('mac_addr', uc($string));
82 } elsif ( $string =~ /^(([A-F0-9]{2}:){5}([A-F0-9]{2}))$/i ) {
84 $class->search_sql_field('mac_addr', uc($string) );
85 } elsif ( $string =~ /^(\w+)$/ ) {
86 $class->search_sql_field('serialnum', $1);
94 tie my %fields, 'Tie::IxHash',
95 'svcnum' => 'Service',
96 'providernum' => { label => 'Provider',
97 type => 'select-cable_provider',
98 disable_inventory => 1,
100 value_callback => sub {
102 my $p = $svc->cable_provider;
103 $p ? $p->provider : '';
106 'ordernum' => 'Order number', #XXX "Circuit ID/Order number"
107 'modelnum' => { label => 'Model',
108 type => 'select-cable_model',
109 disable_inventory => 1,
111 value_callback => sub {
113 $svc->cable_model->model_name;
116 'serialnum' => 'Serial number',
117 'mac_addr' => { label => 'MAC address',
118 type => 'input-mac_addr',
119 value_callback => sub {
121 $svc->mac_addr_formatted('U',':');
127 'name' => 'Cable Subscriber',
128 #'name_plural' => '', #optional,
129 #'longname_plural' => '', #optional
130 'fields' => \%fields,
131 'sorts' => [ 'svcnum', 'serialnum', 'mac_addr', ],
132 'display_weight' => 54,
133 'cancel_weight' => 70, #? no deps, so
139 Returns the MAC address and serial number.
145 my $part_svc = $self->cust_svc->part_svc;
147 push @label, 'MAC:'. $self->mac_addr_pretty
149 if ( $self->serialnum ) {
150 my $serialnum_label = $part_svc->part_svc_column('serialnum');
152 ($serialnum_label && $serialnum_label->columnlabel || 'Serial#').
155 return join(', ', @label);
160 Adds this record to the database. If there is an error, returns the error,
161 otherwise returns false.
165 Delete this record from the database.
167 =item replace OLD_RECORD
169 Replaces the OLD_RECORD with this one in the database. If there is an error,
170 returns the error, otherwise returns false.
174 Checks all fields to make sure this is a valid record. If there is
175 an error, returns the error, otherwise returns false. Called by the insert
184 $self->ut_numbern('svcnum')
185 || $self->ut_foreign_keyn('providernum', 'cable_provider', 'providernum')
186 || $self->ut_alphan('ordernum')
187 || $self->ut_foreign_key('modelnum', 'cable_model', 'modelnum')
188 || $self->ut_alphan('serialnum')
189 || $self->ut_mac_addrn('mac_addr')
191 return $error if $error;
196 sub _check_duplicate {
199 # Not reliable checks because the table isn't locked, but that's why we have
200 # unique indices. These are just to give friendlier error messages.
202 if ( $self->mac_addr ) {
204 @dup_mac = $self->find_duplicates('global', 'mac_addr');
206 return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
210 if ( $self->serialnum ) {
212 @dup_serial = $self->find_duplicates('global', 'modelnum', 'serialnum');
214 return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
223 Returns the cable_provider object for this record.
227 Returns the cable_model object for this record.
235 L<FS::Record>, schema.html from the base documentation.