X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_cable.pm;h=dde682bc963fdf615dbe2d12373927c84916eb4c;hb=53c235fd67a9ab0022bc8ea0cc35b5a4d02d2e11;hp=672a34d7b71dd08ac35c61ecf71a48e50a33b5e1;hpb=368a5e5e75b2072003641c1938fcb1423a9fb30c;p=freeside.git diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm index 672a34d7b..dde682bc9 100644 --- a/FS/FS/svc_cable.pm +++ b/FS/FS/svc_cable.pm @@ -1,5 +1,7 @@ package FS::svc_cable; -use base qw( FS::svc_Common ); #qw( FS::device_Common FS::svc_Common ); +use base qw( FS::svc_MAC_Mixin + FS::svc_Common + ); #FS::device_Common use strict; use Tie::IxHash; @@ -54,7 +56,7 @@ points to. You can ask the object for a copy with the I method. sub table { 'svc_cable'; } -sub table_dupcheck_fields { ( 'mac_addr' ); } +sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); } sub search_sql { my( $class, $string ) = @_; @@ -99,7 +101,7 @@ sub table_info { type => 'input-mac_addr', value_callback => sub { my $svc = shift; - join(':', $svc->mac_addr =~ /../g); + $svc->mac_addr_formatted('U',':'); }, }, ; @@ -115,6 +117,27 @@ sub table_info { }; } +=item label + +Returns the MAC address and serial number. + +=cut + +sub label { + my $self = shift; + my $part_svc = $self->cust_svc->part_svc; + my @label = (); + push @label, 'MAC:'. $self->mac_addr_pretty + if $self->mac_addr; + if ( $self->serialnum ) { + my $serialnum_label = $part_svc->part_svc_column('serialnum'); + push @label, + ($serialnum_label && $serialnum_label->columnlabel || 'Serial#'). + $self->serialnum; + } + return join(', ', @label); +} + =item insert Adds this record to the database. If there is an error, returns the error, @@ -145,14 +168,39 @@ sub check { || $self->ut_foreign_keyn('providernum', 'cable_provider', 'providernum') || $self->ut_alphan('ordernum') || $self->ut_foreign_key('modelnum', 'cable_model', 'modelnum') - || $self->ut_alpha('serialnum') - || $self->ut_mac_addr('mac_addr') + || $self->ut_alphan('serialnum') + || $self->ut_mac_addrn('mac_addr') ; return $error if $error; $self->SUPER::check; } +sub _check_duplicate { + my $self = shift; + + # 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. + + if ( $self->mac_addr ) { + my @dup_mac; + @dup_mac = $self->find_duplicates('global', 'mac_addr'); + if ( @dup_mac ) { + return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")"; + } + } + + if ( $self->serialnum ) { + 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_provider Returns the cable_provider object for this record.