From ec9b0f903dfa57efc0c82791b9efa74f0c746bc0 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 10 Sep 2013 01:33:25 -0700 Subject: [PATCH] svc_cable service have a single serial / MAC / model, not one-to-many devices like svc_phone and svc_dsl, RT#22009 --- FS/FS.pm | 2 + FS/FS/Mason.pm | 2 +- FS/FS/svc_broadband.pm | 7 +-- FS/FS/svc_cable.pm | 76 ++++++++++++++++++++++----- FS/FS/svc_pbx.pm | 19 ++++--- FS/MANIFEST | 4 +- httemplate/edit/elements/part_svc_column.html | 4 +- httemplate/edit/svc_Common.html | 12 +++++ httemplate/elements/menu.html | 6 +++ 9 files changed, 104 insertions(+), 28 deletions(-) diff --git a/FS/FS.pm b/FS/FS.pm index 348444431..b3ebf3050 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -210,6 +210,8 @@ L - Dish network service class L - Cable service class +L - Cable-model model class + L - Inventory classes L - Inventory items diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 08cce1666..780e3ffaf 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -341,7 +341,6 @@ if ( -e $addl_handler_use_file ) { use FS::cdr_cust_pkg_usage; use FS::part_pkg_msgcat; use FS::svc_cable; - use FS::cable_device; use FS::agent_currency; use FS::currency_exchange; use FS::part_pkg_currency; @@ -353,6 +352,7 @@ if ( -e $addl_handler_use_file ) { use FS::vend_bill_pay; use FS::sales_pkg_class; use FS::svc_alarm; + use FS::cable_model; # Sammath Naur if ( $FS::Mason::addl_handler_use ) { diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm index b5012caa3..6073902e8 100755 --- a/FS/FS/svc_broadband.pm +++ b/FS/FS/svc_broadband.pm @@ -234,10 +234,11 @@ sub search_sql { my( $class, $string ) = @_; if ( $string =~ /^(\d{1,3}\.){3}\d{1,3}$/ ) { $class->search_sql_field('ip_addr', $string ); - } elsif ( $string =~ /^([a-fA-F0-9]{12})$/ ) { + } elsif ( $string =~ /^([A-F0-9]{12})$/i ) { $class->search_sql_field('mac_addr', uc($string)); - } elsif ( $string =~ /^(([a-fA-F0-9]{1,2}:){5}([a-fA-F0-9]{1,2}))$/ ) { - $class->search_sql_field('mac_addr', uc("$2$3$4$5$6$7") ); + } 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 =~ /^(\d+)$/ ) { my $table = $class->table; "$table.svcnum = $1"; diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm index f588f43c3..1980c0ee9 100644 --- a/FS/FS/svc_cable.pm +++ b/FS/FS/svc_cable.pm @@ -1,9 +1,10 @@ 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_model; =head1 NAME @@ -52,18 +53,53 @@ 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', + '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 +129,27 @@ sub check { my $self = shift; my $error = - $self->ut_numbern('svcnum') + $self->ut_numbern('svcnum') + || $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_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 diff --git a/FS/FS/svc_pbx.pm b/FS/FS/svc_pbx.pm index 66e51da71..7c228f8b5 100644 --- a/FS/FS/svc_pbx.pm +++ b/FS/FS/svc_pbx.pm @@ -1,7 +1,8 @@ package FS::svc_pbx; +use base qw( FS::svc_External_Common ); use strict; -use base qw( FS::svc_External_Common ); +use Tie::IxHash; use FS::Record qw( qsearch qsearchs dbh ); use FS::PagedSearch qw( psearch ); use FS::Conf; @@ -80,6 +81,15 @@ points to. You can ask the object for a copy with the I method. sub table { 'svc_pbx'; } sub table_info { + + tie my %fields, 'Tie::IxHash', + 'svcnum' => 'PBX', + 'id' => 'PBX/Tenant ID', + 'title' => 'Name', + 'max_extensions' => 'Maximum number of User Extensions', + 'max_simultaneous' => 'Maximum number of simultaneous users', + ; + { 'name' => 'PBX', 'name_plural' => 'PBXs', @@ -88,12 +98,7 @@ sub table_info { 'sorts' => 'svcnum', # optional sort field (or arrayref of sort fields, main first) 'display_weight' => 70, 'cancel_weight' => 90, - 'fields' => { - 'id' => 'ID', - 'title' => 'Name', - 'max_extensions' => 'Maximum number of User Extensions', - 'max_simultaneous' => 'Maximum number of simultaneous users', - }, + 'fields' => \%fields, }; } diff --git a/FS/MANIFEST b/FS/MANIFEST index eb237c3bb..a3b11f717 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -694,8 +694,6 @@ FS/access_user_session.pm t/access_user_session.t FS/svc_cable.pm t/svc_cable.t -FS/cable_device.pm -t/cable_device.t FS/h_svc_cable.pm t/h_svc_cable.t FS/agent_currency.pm @@ -720,3 +718,5 @@ FS/sales_pkg_class.pm t/sales_pkg_class.t FS/svc_alarm.pm t/svc_alarm.t +FS/cable_model.pm +t/cable_model.t diff --git a/httemplate/edit/elements/part_svc_column.html b/httemplate/edit/elements/part_svc_column.html index ddfc85cfc..64901a80f 100644 --- a/httemplate/edit/elements/part_svc_column.html +++ b/httemplate/edit/elements/part_svc_column.html @@ -183,8 +183,8 @@ that field. 'curr_value' => $value, &> % } -% } elsif ( $def->{'type'} =~ /select-(.*?).html/ ) { - <& '/elements/'.$def->{'type'}, +% } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) { + <& "/elements/select-$1.html", 'field' => $name, 'id' => $name.'_select', 'multiple' => $def->{'multiple'}, diff --git a/httemplate/edit/svc_Common.html b/httemplate/edit/svc_Common.html index 3da72d2e8..5949a4dc0 100644 --- a/httemplate/edit/svc_Common.html +++ b/httemplate/edit/svc_Common.html @@ -20,6 +20,7 @@ if ( UNIVERSAL::can("FS::$table", 'table_info') ) { $opt{'name'} = "FS::$table"->table_info->{'name'}; my $fields = "FS::$table"->table_info->{'fields'}; + my %labels = map { $_ => ( ref($fields->{$_}) ? $fields->{$_}{'label'} : $fields->{$_} @@ -28,6 +29,17 @@ if ( UNIVERSAL::can("FS::$table", 'table_info') ) { keys %$fields; $opt{'labels'} = \%labels; + #transform FS::svc_* table_info's structure into one edit.html likes + delete $fields->{svcnum}; + $opt{'fields'} = [ map { ref $fields->{$_} + ? { field => $_, + %{ $fields->{$_} } + } + : $_ + } keys %$fields + ]; + + } diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index b619aba30..8cbbd1742 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -516,6 +516,10 @@ tie my %config_radius, 'Tie::IxHash', 'RADIUS Clients' => [ $fsurl.'browse/nas.html', 'Manage RADIUS clients' ], ; +tie my %config_cable, 'Tie::IxHash', + 'Cable modem models' => [ $fsurl.'browse/cable_model.html', '' ], +; + tie my %config_export_svc, 'Tie::IxHash', (); if ( $curuser->access_right('Configuration') ) { $config_export_svc{'Service definitions'} = [ $fsurl.'browse/part_svc.cgi', 'Services are items you offer to your customers' ]; @@ -530,6 +534,8 @@ $config_export_svc{'Phone'} = [ \%config_phone, '' ] if $curuser->access_right('Configuration'); $config_export_svc{'RADIUS'} = [ \%config_radius, '' ] if $curuser->access_right('Configuration'); +$config_export_svc{'Cable'} = [ \%config_cable, '' ] + if $curuser->access_right('Configuration'); $config_export_svc{'Hardware types'} = [ $fsurl.'browse/hardware_class.html', 'Set up hardware type catalog' ] if $curuser->access_right('Configuration'); -- 2.11.0