2 use base qw( FS::svc_MAC_Mixin
8 use FS::Record qw( qsearchs ); # qw( qsearch qsearchs );
9 use FS::cable_provider;
14 FS::svc_cable - Object methods for svc_cable records
20 $record = new FS::svc_cable \%hash;
21 $record = new FS::svc_cable { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::svc_cable object represents a cable subscriber. FS::svc_cable inherits
34 from FS::Record. The following fields are currently supported:
44 Provider (see L<FS::cable_provider>)
52 Cable device model (see L<FS::cable_model>)
56 Cable device serial number
60 Cable device MAC address
70 Creates a new record. To add the record to the database, see L<"insert">.
72 Note that this stores the hash reference, not a distinct copy of the hash it
73 points to. You can ask the object for a copy with the I<hash> method.
77 sub table { 'svc_cable'; }
79 sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); }
82 my( $class, $string ) = @_;
83 if ( $string =~ /^([A-F0-9]{12})$/i ) {
84 $class->search_sql_field('mac_addr', uc($string));
85 } elsif ( $string =~ /^(([A-F0-9]{2}:){5}([A-F0-9]{2}))$/i ) {
87 $class->search_sql_field('mac_addr', uc($string) );
88 } elsif ( $string =~ /^(\w+)$/ ) {
89 $class->search_sql_field('serialnum', $1);
97 tie my %fields, 'Tie::IxHash',
98 'svcnum' => 'Service',
99 'providernum' => { label => 'Provider',
100 type => 'select-cable_provider',
101 disable_inventory => 1,
103 value_callback => sub {
105 my $p = $svc->cable_provider;
106 $p ? $p->provider : '';
109 'ordernum' => 'Order number', #XXX "Circuit ID/Order number"
110 'modelnum' => { label => 'Model',
111 type => 'select-cable_model',
112 disable_inventory => 1,
114 value_callback => sub {
116 $svc->cable_model->model_name;
119 'serialnum' => 'Serial number',
120 'mac_addr' => { label => 'MAC address',
121 type => 'input-mac_addr',
122 value_callback => sub {
124 $svc->mac_addr_formatted('U',':');
130 'name' => 'Cable Subscriber',
131 #'name_plural' => '', #optional,
132 #'longname_plural' => '', #optional
133 'fields' => \%fields,
134 'sorts' => [ 'svcnum', 'serialnum', 'mac_addr', ],
135 'display_weight' => 54,
136 'cancel_weight' => 70, #? no deps, so
142 Returns the MAC address and serial number.
148 my $part_svc = $self->cust_svc->part_svc;
150 push @label, 'MAC:'. $self->mac_addr_pretty
152 if ( $self->serialnum ) {
153 my $serialnum_label = $part_svc->part_svc_column('serialnum');
155 ($serialnum_label && $serialnum_label->columnlabel || 'Serial#').
158 return join(', ', @label);
163 Adds this record to the database. If there is an error, returns the error,
164 otherwise returns false.
168 Delete this record from the database.
170 =item replace OLD_RECORD
172 Replaces the OLD_RECORD with this one in the database. If there is an error,
173 returns the error, otherwise returns false.
177 Checks all fields to make sure this is a valid record. If there is
178 an error, returns the error, otherwise returns false. Called by the insert
187 $self->ut_numbern('svcnum')
188 || $self->ut_foreign_keyn('providernum', 'cable_provider', 'providernum')
189 || $self->ut_alphan('ordernum')
190 || $self->ut_foreign_key('modelnum', 'cable_model', 'modelnum')
191 || $self->ut_alphan('serialnum')
192 || $self->ut_mac_addrn('mac_addr')
194 return $error if $error;
199 sub _check_duplicate {
202 # Not reliable checks because the table isn't locked, but that's why we have
203 # unique indices. These are just to give friendlier error messages.
205 if ( $self->mac_addr ) {
207 @dup_mac = $self->find_duplicates('global', 'mac_addr');
209 return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
213 if ( $self->serialnum ) {
215 @dup_serial = $self->find_duplicates('global', 'serialnum');
217 return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
226 Returns the cable_provider object for this record.
232 qsearchs('cable_provider', { 'providernum'=>$self->providernum } );
237 Returns the cable_model object for this record.
243 qsearchs('cable_model', { 'modelnum'=>$self->modelnum } );
252 L<FS::Record>, schema.html from the base documentation.