package FS::svc_cable;
-use base qw( FS::svc_Common ); #qw( FS::device_Common FS::svc_Common );
+use base qw( FS::MAC_Mixin
+ FS::svc_Common
+ ); #FS::device_Common
use strict;
use Tie::IxHash;
-use FS::Record qw( qsearchs ); # qw( qsearch qsearchs );
-use FS::cable_provider;
-use FS::cable_model;
=head1 NAME
sub table { 'svc_cable'; }
-sub table_dupcheck_fields { ( 'mac_addr' ); }
+sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); }
sub search_sql {
my( $class, $string ) = @_;
type => 'input-mac_addr',
value_callback => sub {
my $svc = shift;
- join(':', $svc->mac_addr =~ /../g);
+ $svc->mac_addr_formatted('U',':');
},
},
;
};
}
+=item label
+
+Returns the MAC address and serial number.
+
+=cut
+
+sub label {
+ my $self = shift;
+ my @label = ();
+ push @label, 'MAC:'. $self->mac_addr_pretty
+ if $self->mac_addr;
+ push @label, 'Serial#'. $self->serialnum
+ if $self->serialnum;
+ return join(', ', @label);
+}
+
=item insert
Adds this record to the database. If there is an error, returns the error,
$self->SUPER::check;
}
-=item cable_provider
+sub _check_duplicate {
+ my $self = shift;
-Returns the cable_provider object for this record.
+ # Not reliable checks because the table isn't locked, but that's why we have
+ # unique indices. These are just to give friendlier error messages.
-=cut
+ my @dup_mac;
+ @dup_mac = $self->find_duplicates('global', 'mac_addr');
+ if ( @dup_mac ) {
+ return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
+ }
-sub cable_provider {
- my $self = shift;
- qsearchs('cable_provider', { 'providernum'=>$self->providernum } );
+ my @dup_serial;
+ @dup_serial = $self->find_duplicates('global', 'serialnum');
+ if ( @dup_serial ) {
+ return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
+ }
+
+ '';
}
-=item cable_model
+=item cable_provider
-Returns the cable_model object for this record.
+Returns the cable_provider object for this record.
-=cut
+=item cable_model
-sub cable_model {
- my $self = shift;
- qsearchs('cable_model', { 'modelnum'=>$self->modelnum } );
-}
+Returns the cable_model object for this record.
=back