X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fsvc_cable.pm;h=01c5de760420721107731465b27064e1f44bcfe7;hp=6575a0bec98acd2371fadfd55ca8d1a3be47a058;hb=ff27c3f36240aee48ed50153dd5d8fe3ac3f2443;hpb=b198322c5f3c1d26674ff12f93abf0d55e09f731 diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm index 6575a0bec..01c5de760 100644 --- a/FS/FS/svc_cable.pm +++ b/FS/FS/svc_cable.pm @@ -1,11 +1,10 @@ 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 @@ -54,7 +53,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 +98,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 +114,22 @@ sub table_info { }; } +=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, @@ -142,38 +157,49 @@ sub check { my $error = $self->ut_numbern('svcnum') - || $self->ut_foreign_key('providernum', 'cable_provider', 'providernum') + || $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; } -=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 + 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.")"; + } + } -sub cable_provider { - my $self = shift; - qsearchs('cable_provider', { 'providernum'=>$self->providernum } ); + 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_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