X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_cable.pm;h=6575a0bec98acd2371fadfd55ca8d1a3be47a058;hb=b198322c5f3c1d26674ff12f93abf0d55e09f731;hp=f588f43c343d69eb947da83cacb162f820c9c273;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;p=freeside.git diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm index f588f43c3..6575a0bec 100644 --- a/FS/FS/svc_cable.pm +++ b/FS/FS/svc_cable.pm @@ -1,9 +1,11 @@ package FS::svc_cable; -use base qw( FS::device_Common FS::svc_Common ); +use base qw( FS::svc_Common ); #qw( FS::device_Common FS::svc_Common ); use strict; -use base qw( FS::Record ); -use FS::Record; # qw( qsearch qsearchs ); +use Tie::IxHash; +use FS::Record qw( qsearchs ); # qw( qsearch qsearchs ); +use FS::cable_provider; +use FS::cable_model; =head1 NAME @@ -52,18 +54,64 @@ 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 search_sql { + my( $class, $string ) = @_; + if ( $string =~ /^([A-F0-9]{12})$/i ) { + $class->search_sql_field('mac_addr', uc($string)); + } elsif ( $string =~ /^(([A-F0-9]{2}:){5}([A-F0-9]{2}))$/i ) { + $string =~ s/://g; + $class->search_sql_field('mac_addr', uc($string) ); + } elsif ( $string =~ /^(\w+)$/ ) { + $class->search_sql_field('serialnum', $1); + } else { + '1 = 0'; #false + } +} + sub table_info { + + tie my %fields, 'Tie::IxHash', + 'svcnum' => 'Service', + 'providernum' => { label => 'Provider', + type => 'select-cable_provider', + disable_inventory => 1, + disable_select => 1, + value_callback => sub { + my $svc = shift; + my $p = $svc->cable_provider; + $p ? $p->provider : ''; + }, + }, + 'ordernum' => 'Order number', #XXX "Circuit ID/Order number" + 'modelnum' => { label => 'Model', + type => 'select-cable_model', + disable_inventory => 1, + disable_select => 1, + value_callback => sub { + my $svc = shift; + $svc->cable_model->model_name; + }, + }, + 'serialnum' => 'Serial number', + 'mac_addr' => { label => 'MAC address', + type => 'input-mac_addr', + value_callback => sub { + my $svc = shift; + join(':', $svc->mac_addr =~ /../g); + }, + }, + ; + { - 'name' => 'Cable Subscriber', - #'name_plural' => '', #optional, + 'name' => 'Cable Subscriber', + #'name_plural' => '', #optional, #'longname_plural' => '', #optional - 'sorts' => [ 'svcnum', ], #, 'serviceid' ], # optional sort field (or arrayref of sort fields, main first) - 'display_weight' => 54, - 'cancel_weight' => 70, #? no deps, so - 'fields' => { - 'svcnum' => 'Service', - 'identifier' => 'Identifier', - }, + 'fields' => \%fields, + 'sorts' => [ 'svcnum', 'serialnum', 'mac_addr', ], + 'display_weight' => 54, + 'cancel_weight' => 70, #? no deps, so }; } @@ -93,13 +141,40 @@ sub check { my $self = shift; my $error = - $self->ut_numbern('svcnum') + $self->ut_numbern('svcnum') + || $self->ut_foreign_key('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') ; return $error if $error; $self->SUPER::check; } +=item cable_provider + +Returns the cable_provider object for this record. + +=cut + +sub cable_provider { + my $self = shift; + qsearchs('cable_provider', { 'providernum'=>$self->providernum } ); +} + +=item cable_model + +Returns the cable_model object for this record. + +=cut + +sub cable_model { + my $self = shift; + qsearchs('cable_model', { 'modelnum'=>$self->modelnum } ); +} + =back =head1 BUGS