update warnings re: census tract length so real errors are easier to spot, RT#86245
[freeside.git] / FS / FS / Report / FCC_477.pm
index 75ddee0..29505f8 100644 (file)
@@ -320,7 +320,7 @@ sub report {
   my $num_errors = 0;
   foreach my $row (@$data) {
     if ( $class->can($check_method) ) { # they don't all have these
-      my $eh = $class->$check_method( $row );
+      my $eh = $class->$check_method( $row, 'date'=>$opt{'date'} );
       $num_errors++ if keys(%$eh);
       push @$error, $eh
     }
@@ -365,10 +365,12 @@ sub fbd_sql {
     'adv_speed_down',
     'adv_speed_up',
     'CASE WHEN is_business IS NOT NULL THEN 1 ELSE 0 END',
-    'cir_speed_down',
-    'cir_speed_up',
   );
-  push @select, 'blocknum' if $opt{detail};
+  push @select, 'cir_speed_down', 'cir_speed_up'
+    if $opt{date} < 1569826800; #9/30/2019, halfway between the two filing
+                                # "as of" dates when it changed
+  push @select, 'blocknum'
+    if $opt{detail};
 
   my $from = 'deploy_zone_block
     JOIN deploy_zone USING (zonenum)
@@ -382,7 +384,7 @@ sub fbd_sql {
 
   my $order_by = 'censusblock, agentnum, technology, is_consumer, is_business';
 
-  "SELECT ".join(', ', @select) . "
+  "SELECT DISTINCT ".join(', ', @select) . "
   FROM $from
   WHERE ".join(' AND ', @where)."
   ORDER BY $order_by
@@ -440,12 +442,19 @@ sub fbs_sql {
 sub fbs_check {
   my $class = shift;
   my $row = shift;
+
+  my %opt = @_;
+  my $date = $opt{date} || time;
+  my $census_digits = ($date < 1601449200) ? 11 : 15; # 9/30/2020, halfway
+                                                      # between the two filing
+                                                      # dates when it changed
+
   my %e;
   #censustract
   if ( length($row->[0]) == 0 ) {
     $e{'censustract_null'} = 'The package location has no census tract.';
-  } elsif ($row->[0] !~ /^\d{11}$/) {
-    $e{'censustract_bad'} = 'The census tract must be exactly 11 digits.';
+  } elsif ($row->[0] !~ /^\d{$census_digits}$/) {
+    $e{'censustract_bad'} = "The census tract must be exactly $census_digits digits.";
   }
 
   #technology
@@ -513,12 +522,18 @@ sub fvs_sql {
 sub fvs_check {
   my $class = shift;
   my $row = shift;
+  my %opt = @_;
+  my $date = $opt{date} || time;
+  my $census_digits = ($date < 1601449200) ? 11 : 15; # 9/30/2020, halfway
+                                                      # between the two filing
+                                                      # dates when it changed
+
   my %e;
   #censustract
   if ( length($row->[0]) == 0 ) {
     $e{'censustract_null'} = 'The package location has no census tract.';
-  } elsif ($row->[0] !~ /^\d{11}$/) {
-    $e{'censustract_bad'} = 'The census tract must be exactly 11 digits.';
+  } elsif ($row->[0] !~ /^\d{$census_digits}$/) {
+    $e{'censustract_bad'} = "The census tract must be exactly $census_digits digits.";
   }
   return \%e;
 }