add latitude/longitude to prospects, customers and package locations, RT#15539
[freeside.git] / FS / FS / svc_broadband.pm
index 5ffe0e4..678a788 100755 (executable)
@@ -2,14 +2,15 @@ package FS::svc_broadband;
 
 use strict;
 use vars qw(@ISA $conf);
 
 use strict;
 use vars qw(@ISA $conf);
+use NetAddr::IP;
 use FS::Record qw( qsearchs qsearch dbh );
 use FS::svc_Common;
 use FS::cust_svc;
 use FS::addr_block;
 use FS::part_svc_router;
 use FS::Record qw( qsearchs qsearch dbh );
 use FS::svc_Common;
 use FS::cust_svc;
 use FS::addr_block;
 use FS::part_svc_router;
-use NetAddr::IP;
+use FS::tower_sector;
 
 
-@ISA = qw( FS::svc_Common );
+@ISA = qw( FS::svc_Radius_Mixin FS::svc_Common );
 
 $FS::UID::callback{'FS::svc_broadband'} = sub { 
   $conf = new FS::Conf;
 
 $FS::UID::callback{'FS::svc_broadband'} = sub { 
   $conf = new FS::Conf;
@@ -70,6 +71,8 @@ customer's router will have the same address for both its internal and external
 interfaces thus saving address space.  This has been found to work on most NAT
 routers available.
 
 interfaces thus saving address space.  This has been found to work on most NAT
 routers available.
 
+=item plan_id
+
 =back
 
 =head1 METHODS
 =back
 
 =head1 METHODS
@@ -88,16 +91,19 @@ points to.  You can ask the object for a copy with the I<hash> method.
 
 sub table_info {
   {
 
 sub table_info {
   {
-    'name' => 'Broadband',
-    'name_plural' => 'Broadband services',
-    'longname_plural' => 'Fixed (username-less) broadband services',
+    'name' => 'Wireless broadband',
+    'name_plural' => 'Wireless broadband services',
+    'longname_plural' => 'Fixed wireless broadband services',
     'display_weight' => 50,
     'cancel_weight'  => 70,
     'display_weight' => 50,
     'cancel_weight'  => 70,
+    'ip_field' => 'ip_addr',
     'fields' => {
     'fields' => {
-      'description' => 'Descriptive label for this particular device.',
+      'svcnum'      => 'Service',
+      'description' => 'Descriptive label for this particular device',
       'speed_down'  => 'Maximum download speed for this service in Kbps.  0 denotes unlimited.',
       'speed_up'    => 'Maximum upload speed for this service in Kbps.  0 denotes unlimited.',
       'ip_addr'     => 'IP address.  Leave blank for automatic assignment.',
       'speed_down'  => 'Maximum download speed for this service in Kbps.  0 denotes unlimited.',
       'speed_up'    => 'Maximum upload speed for this service in Kbps.  0 denotes unlimited.',
       'ip_addr'     => 'IP address.  Leave blank for automatic assignment.',
+      'sectornum'   => 'Tower sector',
       'blocknum'    => { 'label' => 'Address block',
                          'type'  => 'select',
                          'select_table' => 'addr_block',
       'blocknum'    => { 'label' => 'Address block',
                          'type'  => 'select',
                          'select_table' => 'addr_block',
@@ -105,6 +111,23 @@ sub table_info {
                          'select_label' => 'cidr',
                          'disable_inventory' => 1,
                        },
                          'select_label' => 'cidr',
                          'disable_inventory' => 1,
                        },
+     'plan_id' => 'Service Plan Id',
+     'performance_profile' => 'Peformance Profile',
+     'authkey'      => 'Authentication key',
+     'mac_addr'     => 'MAC address',
+     'latitude'     => 'Latitude',
+     'longitude'    => 'Longitude',
+     'altitude'     => 'Altitude',
+     'vlan_profile' => 'VLAN profile',
+     'usergroup'    => { 
+                         label => 'RADIUS groups',
+                         type  => 'select-radius_group.html',
+                         #select_table => 'radius_group',
+                         #select_key   => 'groupnum',
+                         #select_label => 'groupname',
+                         disable_inventory => 1,
+                         multiple => 1,
+                       },
     },
   };
 }
     },
   };
 }
@@ -158,7 +181,7 @@ sub search {
   
   #agentnum
   if ( $params->{'agentnum'} =~ /^(\d+)$/ and $1 ) {
   
   #agentnum
   if ( $params->{'agentnum'} =~ /^(\d+)$/ and $1 ) {
-    push @where, "agentnum = $1";
+    push @where, "cust_main.agentnum = $1";
   }
   push @where, $FS::CurrentUser::CurrentUser->agentnums_sql(
     'null_right' => 'View/link unlinked services',
   }
   push @where, $FS::CurrentUser::CurrentUser->agentnums_sql(
     'null_right' => 'View/link unlinked services',
@@ -324,19 +347,26 @@ sub check {
 
   return $x unless ref($x);
 
 
   return $x unless ref($x);
 
+  # remove delimiters
+  my $mac_addr = uc($self->get('mac_addr'));
+  $mac_addr =~ s/[-: ]//g;
+  $self->set('mac_addr', $mac_addr);
+
   my $error =
     $self->ut_numbern('svcnum')
     || $self->ut_numbern('blocknum')
   my $error =
     $self->ut_numbern('svcnum')
     || $self->ut_numbern('blocknum')
+    || $self->ut_foreign_keyn('sectornum', 'tower_sector', 'sectornum')
     || $self->ut_textn('description')
     || $self->ut_textn('description')
-    || $self->ut_number('speed_up')
-    || $self->ut_number('speed_down')
+    || $self->ut_numbern('speed_up')
+    || $self->ut_numbern('speed_down')
     || $self->ut_ipn('ip_addr')
     || $self->ut_hexn('mac_addr')
     || $self->ut_hexn('auth_key')
     || $self->ut_ipn('ip_addr')
     || $self->ut_hexn('mac_addr')
     || $self->ut_hexn('auth_key')
-    || $self->ut_coordn('latitude', -90, 90)
-    || $self->ut_coordn('longitude', -180, 180)
+    || $self->ut_coordn('latitude')
+    || $self->ut_coordn('longitude')
     || $self->ut_sfloatn('altitude')
     || $self->ut_textn('vlan_profile')
     || $self->ut_sfloatn('altitude')
     || $self->ut_textn('vlan_profile')
+    || $self->ut_textn('plan_id')
   ;
   return $error if $error;
 
   ;
   return $error if $error;
 
@@ -366,6 +396,17 @@ sub check {
     }
   }
 
     }
   }
 
+  if ( $cust_pkg && ! $self->latitude && ! $self->longitude ) {
+    my $l = $cust_pkg->cust_location_or_main;
+    if ( $l->ship_latitude && $l->ship_longitude ) {
+      $self->latitude  = $l->ship_latitude;
+      $self->longitude = $l->ship_longitude;
+    } elsif ( $l->latitude && $l->longitude ) {
+      $self->latitude  = $l->latitude;
+      $self->longitude = $l->longitude;
+    }
+  }
+
   $error = $self->_check_ip_addr;
   return $error if $error;
 
   $error = $self->_check_ip_addr;
   return $error if $error;
 
@@ -448,6 +489,16 @@ sub NetAddr {
   new NetAddr::IP ($self->ip_addr);
 }
 
   new NetAddr::IP ($self->ip_addr);
 }
 
+=item tower_sector
+
+=cut
+
+sub tower_sector {
+  my $self = shift;
+  return '' unless $self->sectornum;
+  qsearchs('tower_sector', { sectornum => $self->sectornum });
+}
+
 =item addr_block
 
 Returns the FS::addr_block record (i.e. the address block) for this broadband service.
 =item addr_block
 
 Returns the FS::addr_block record (i.e. the address block) for this broadband service.