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:
50 Creates a new record. To add the record to the database, see L<"insert">.
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to. You can ask the object for a copy with the I<hash> method.
57 sub table { 'svc_cable'; }
59 sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); }
62 my( $class, $string ) = @_;
63 if ( $string =~ /^([A-F0-9]{12})$/i ) {
64 $class->search_sql_field('mac_addr', uc($string));
65 } elsif ( $string =~ /^(([A-F0-9]{2}:){5}([A-F0-9]{2}))$/i ) {
67 $class->search_sql_field('mac_addr', uc($string) );
68 } elsif ( $string =~ /^(\w+)$/ ) {
69 $class->search_sql_field('serialnum', $1);
77 tie my %fields, 'Tie::IxHash',
78 'svcnum' => 'Service',
79 'providernum' => { label => 'Provider',
80 type => 'select-cable_provider',
81 disable_inventory => 1,
83 value_callback => sub {
85 my $p = $svc->cable_provider;
86 $p ? $p->provider : '';
89 'ordernum' => 'Order number', #XXX "Circuit ID/Order number"
90 'modelnum' => { label => 'Model',
91 type => 'select-cable_model',
92 disable_inventory => 1,
94 value_callback => sub {
96 $svc->cable_model->model_name;
99 'serialnum' => 'Serial number',
100 'mac_addr' => { label => 'MAC address',
101 type => 'input-mac_addr',
102 value_callback => sub {
104 $svc->mac_addr_formatted('U',':');
110 'name' => 'Cable Subscriber',
111 #'name_plural' => '', #optional,
112 #'longname_plural' => '', #optional
113 'fields' => \%fields,
114 'sorts' => [ 'svcnum', 'serialnum', 'mac_addr', ],
115 'display_weight' => 54,
116 'cancel_weight' => 70, #? no deps, so
122 Returns the MAC address and serial number.
129 push @label, 'MAC:'. $self->mac_addr_pretty
131 push @label, 'Serial#'. $self->serialnum
133 return join(', ', @label);
138 Adds this record to the database. If there is an error, returns the error,
139 otherwise returns false.
143 Delete this record from the database.
145 =item replace OLD_RECORD
147 Replaces the OLD_RECORD with this one in the database. If there is an error,
148 returns the error, otherwise returns false.
152 Checks all fields to make sure this is a valid record. If there is
153 an error, returns the error, otherwise returns false. Called by the insert
162 $self->ut_numbern('svcnum')
163 || $self->ut_foreign_keyn('providernum', 'cable_provider', 'providernum')
164 || $self->ut_alphan('ordernum')
165 || $self->ut_foreign_key('modelnum', 'cable_model', 'modelnum')
166 || $self->ut_alpha('serialnum')
167 || $self->ut_mac_addr('mac_addr')
169 return $error if $error;
174 sub _check_duplicate {
177 # Not reliable checks because the table isn't locked, but that's why we have
178 # unique indices. These are just to give friendlier error messages.
181 @dup_mac = $self->find_duplicates('global', 'mac_addr');
183 return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
187 @dup_serial = $self->find_duplicates('global', 'serialnum');
189 return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
197 Returns the cable_provider object for this record.
203 qsearchs('cable_provider', { 'providernum'=>$self->providernum } );
208 Returns the cable_model object for this record.
214 qsearchs('cable_model', { 'modelnum'=>$self->modelnum } );
223 L<FS::Record>, schema.html from the base documentation.