Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / deploy_zone.pm
index 227a022..38dd7dc 100644 (file)
@@ -3,6 +3,8 @@ package FS::deploy_zone;
 use strict;
 use base qw( FS::o2m_Common FS::Record );
 use FS::Record qw( qsearch qsearchs dbh );
 use strict;
 use base qw( FS::o2m_Common FS::Record );
 use FS::Record qw( qsearch qsearchs dbh );
+use Storable qw(thaw);
+use MIME::Base64;
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -65,10 +67,6 @@ The FCC technology code for the type of service available.
 
 For mobile service zones, the FCC code for the RF band.
 
 
 For mobile service zones, the FCC code for the RF band.
 
-=item servicetype
-
-"broadband" or "voice"
-
 =item adv_speed_up
 
 For broadband, the advertised upstream bandwidth in the zone.  If multiple
 =item adv_speed_up
 
 For broadband, the advertised upstream bandwidth in the zone.  If multiple
@@ -97,6 +95,14 @@ type of service is sold.
 'Y' if this service is sold to business or institutional use.  Not mutually
 exclusive with is_consumer.
 
 'Y' if this service is sold to business or institutional use.  Not mutually
 exclusive with is_consumer.
 
+=item is_broadband
+
+'Y' if this service includes broadband Internet.
+
+=item is_voice
+
+'Y' if this service includes voice communication.
+
 =item active_date
 
 The date this zone became active.
 =item active_date
 
 The date this zone became active.
@@ -177,28 +183,33 @@ sub check {
 
   my $error = 
     $self->ut_numbern('zonenum')
 
   my $error = 
     $self->ut_numbern('zonenum')
-    || $self->ut_textn('description')
+    || $self->ut_text('description')
     || $self->ut_number('agentnum')
     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
     || $self->ut_number('agentnum')
     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
-    || $self->ut_alphan('dbaname')
+    || $self->ut_textn('dbaname')
     || $self->ut_enum('zonetype', [ 'B', 'P' ])
     || $self->ut_number('technology')
     || $self->ut_numbern('spectrum')
     || $self->ut_enum('zonetype', [ 'B', 'P' ])
     || $self->ut_number('technology')
     || $self->ut_numbern('spectrum')
-    || $self->ut_enum('servicetype', [ 'broadband', 'voice' ])
     || $self->ut_decimaln('adv_speed_up', 3)
     || $self->ut_decimaln('adv_speed_down', 3)
     || $self->ut_decimaln('cir_speed_up', 3)
     || $self->ut_decimaln('cir_speed_down', 3)
     || $self->ut_flag('is_consumer')
     || $self->ut_flag('is_business')
     || $self->ut_decimaln('adv_speed_up', 3)
     || $self->ut_decimaln('adv_speed_down', 3)
     || $self->ut_decimaln('cir_speed_up', 3)
     || $self->ut_decimaln('cir_speed_down', 3)
     || $self->ut_flag('is_consumer')
     || $self->ut_flag('is_business')
+    || $self->ut_flag('is_broadband')
+    || $self->ut_flag('is_voice')
     || $self->ut_numbern('active_date')
     || $self->ut_numbern('expire_date')
   ;
   return $error if $error;
 
   foreach(qw(adv_speed_down adv_speed_up cir_speed_down cir_speed_up)) {
     || $self->ut_numbern('active_date')
     || $self->ut_numbern('expire_date')
   ;
   return $error if $error;
 
   foreach(qw(adv_speed_down adv_speed_up cir_speed_down cir_speed_up)) {
-    if (!$self->get($_)) {
-      $self->set($_, 0);
+    if ($self->get('is_broadband')) {
+      if (!$self->get($_)) {
+        $self->set($_, 0);
+      }
+    } else {
+      $self->set($_, '');
     }
   }
   if (!$self->get('active_date')) {
     }
   }
   if (!$self->get('active_date')) {
@@ -226,8 +237,85 @@ sub element_table {
   }
 }
 
   }
 }
 
+=item deploy_zone_block
+
+Returns the census block records in this zone, in order by census block
+number.  Only appropriate to block-type zones.
+
+=item deploy_zone_vertex
+
+Returns the vertex records for this zone, in order by sequence number.  Only
+appropriate to polygon-type zones.
+
+=cut
+
+sub deploy_zone_block {
+  my $self = shift;
+  qsearch({
+      table     => 'deploy_zone_block',
+      hashref   => { zonenum => $self->zonenum },
+      order_by  => ' ORDER BY censusblock',
+  });
+}
+
+sub deploy_zone_vertex {
+  my $self = shift;
+  qsearch({
+      table     => 'deploy_zone_vertex',
+      hashref   => { zonenum => $self->zonenum },
+      order_by  => ' ORDER BY vertexnum',
+  });
+}
+
 =back
 
 =back
 
+=head2 SUBROUTINES
+
+=over 4
+
+=item process_batch_import JOB, PARAMS
+
+=cut
+
+sub process_batch_import {
+  eval {
+    use FS::deploy_zone_block;
+    use FS::deploy_zone_vertex;
+  };
+  my $job = shift;
+  my $param = shift;
+  if (!ref($param)) {
+    $param = thaw(decode_base64($param));
+  }
+
+  # even if creating a new zone, the deploy_zone object should already
+  # be inserted by this point
+  my $zonenum = $param->{zonenum}
+    or die "zonenum required";
+  my $zone = FS::deploy_zone->by_key($zonenum)
+    or die "deploy_zone #$zonenum not found";
+  my $opt;
+  if ( $zone->zonetype eq 'B' ) {
+    $opt = { 'table'    => 'deploy_zone_block',
+             'params'   => [ 'zonenum', 'censusyear' ],
+             'formats'  => { 'plain' => [ 'censusblock' ] },
+             'default_csv' => 1,
+           };
+    $job->update_statustext('1,Inserting census blocks');
+  } elsif ( $zone->zonetype eq 'P' ) {
+    $opt = { 'table'    => 'deploy_zone_vertex',
+             'params'   => [ 'zonenum' ],
+             'formats'  => { 'plain' => [ 'latitude', 'longitude' ] },
+             'default_csv' => 1,
+           };
+  } else {
+    die "don't know how to import to zonetype ".$zone->zonetype;
+  }
+
+  FS::Record::process_batch_import( $job, $opt, $param );
+
+}
+        
 =head1 BUGS
 
 =head1 SEE ALSO
 =head1 BUGS
 
 =head1 SEE ALSO