svc_cable service have a single serial / MAC / model, not one-to-many devices like...
authorIvan Kohler <ivan@freeside.biz>
Tue, 10 Sep 2013 08:33:32 +0000 (01:33 -0700)
committerIvan Kohler <ivan@freeside.biz>
Fri, 27 Sep 2013 00:43:13 +0000 (17:43 -0700)
Conflicts:
FS/FS/Mason.pm
FS/FS/svc_broadband.pm
FS/MANIFEST
httemplate/edit/elements/part_svc_column.html
httemplate/elements/menu.html

FS/FS.pm
FS/FS/Mason.pm
FS/FS/svc_broadband.pm
FS/FS/svc_cable.pm
FS/FS/svc_pbx.pm
FS/MANIFEST
httemplate/edit/svc_Common.html
httemplate/elements/menu.html

index 2dcc796..75656ec 100644 (file)
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -208,6 +208,8 @@ L<FS::svc_dish> - Dish network service class
 
 L<FS::svc_cable> - Cable service class
 
+L<FS::cable_model> - Cable-model model class
+
 L<FS::inventory_class> - Inventory classes
 
 L<FS::inventory_item> - Inventory items
index 6f6b74d..0f8ae87 100644 (file)
@@ -316,7 +316,7 @@ if ( -e $addl_handler_use_file ) {
   use FS::log;
   use FS::log_context;
   use FS::svc_cable;
-  use FS::cable_device;
+  use FS::cable_model;
   # Sammath Naur
 
   if ( $FS::Mason::addl_handler_use ) {
index 83c55b6..5b69127 100755 (executable)
@@ -292,10 +292,14 @@ 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";
   } else {
     '1 = 0'; #false
   }
index f588f43..1980c0e 100644 (file)
@@ -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<hash> 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
index 37ab174..8acd448 100644 (file)
@@ -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::Conf;
 use FS::cust_svc;
@@ -79,6 +80,15 @@ points to.  You can ask the object for a copy with the I<hash> 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',
@@ -87,12 +97,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,
   };
 }
 
index 76171ae..cd3ccd9 100644 (file)
@@ -642,7 +642,7 @@ FS/log_context.pm
 t/log_context.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/cable_model.pm
+t/cable_model.t
index 3da72d2..5949a4d 100644 (file)
@@ -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
+                   ];
+
+
 }
 
 </%init>
index 1c55c14..f9ad579 100644 (file)
@@ -586,6 +586,7 @@ $config_misc{'Hardware types'} = [ $fsurl.'browse/hardware_class.html', 'Set up
 if ( $curuser->access_right('Configuration') ) {
   $config_misc{'RADIUS Groups'} = [ $fsurl.'browse/radius_group.html', 'Manage RADIUS groups' ];
   $config_misc{'RADIUS Clients'} = [ $fsurl.'browse/nas.html', 'Manage RADIUS clients' ];
+  $config_misc{'Cable modem models'} = [ $fsurl.'browse/cable_model.html', '' ];
 }
 
 tie my %config_menu, 'Tie::IxHash';