477 report, XML adjustments, #28020
authorMark Wells <mark@freeside.biz>
Fri, 11 Apr 2014 22:12:07 +0000 (15:12 -0700)
committerMark Wells <mark@freeside.biz>
Fri, 11 Apr 2014 22:12:07 +0000 (15:12 -0700)
httemplate/search/477.html
httemplate/search/477partIA.html
httemplate/search/477partIIA.html
httemplate/search/477partIIB.html
httemplate/search/477partV.html
httemplate/search/477partVI_census.html
httemplate/search/elements/search-xml.html

index 3e7888c..ecf21cf 100755 (executable)
@@ -1,4 +1,7 @@
 % if ( $type eq 'xml' ) {
+% $filename = "fcc_477_$state" . '_' . time2str('%Y%m%d', $date) . '.xml';
+% http_header('Content-Type' => 'application/XML' ); # So saith RFC 4180
+% http_header('Content-Disposition' => 'attachment;filename="'.$filename.'"');
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <Form_477_submission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://specialreports.fcc.gov/wcb/Form477/XMLSchema-instance/form_477_upload_Schema.xsd" >
 % } else { #html
@@ -64,6 +67,7 @@
 <& "477part${part}.html",
     'url' => $url,
     'date' => $date,
+    'filename' => $filename,
 &>
 %       if ( $type eq 'xml' ) {
 </<% 'Part_'. $part %>>
@@ -92,7 +96,7 @@ $state =~ /^[A-Z]{2}$/ or die "illegal state: $state";
 
 my %part = map { $_ => 1 } grep { /^\w+$/ } $cgi->param('part');
 my $type = $cgi->param('_type') || 'html';
-my $xlsname = '477report';
+my $filename;
 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi,1);
 
 # save upload and download mappings
index aa73811..97f8ac0 100755 (executable)
@@ -118,7 +118,6 @@ my $percentages = ($technology eq 'Terrestrial Mobile Wireless');
 # So we count packages that were in active status as of the specified date,
 # not over any sort of range.
 $search_hash{'active'} = [ $opt{date}, $opt{date} ];
-warn Dumper \%search_hash;
 
 my $query = FS::cust_pkg->search(\%search_hash);
 my $count_query = $query->{'count_query'};
index 467b19c..7ccee69 100755 (executable)
@@ -2,11 +2,9 @@
 %   my @cols = qw(a b c d);
 %   for ( my $row = 0; $row < scalar(@rows); $row++ ) {
 %     for my $col (0..3) {
-%       if ( exists($data[$col][$row]) and $data[$col][$row] > 0 ) {
 <PartII_<% $row + 1 %><% $cols[$col] %>>\
-<% $data[$col][$row] %>\
+<% $data[$col][$row] || 0 %>\
 </PartII_<% $row + 1 %><% $cols[$col] %>>
-%       }
 %     } #for $col
 %   } #for $row
 % } else { # HTML mode
index ce1ac03..bd56ecc 100755 (executable)
@@ -118,11 +118,14 @@ foreach (@col_conds) {
     if ( $row == 0 ) {
       $col_data[$row] = $count; # the raw count
     } else {
+      # the rows that are percentages of the raw count
       if ( $col_data[0] == 0 ) {
-        $col_data[$row] = ''; # show nothing in this row, then
+        # 0 out of 0 is not 0%, but supposedly this works
+        $col_data[$row] = '0.000';
       } else {
-        $col_data[$row] = sprintf('%.3f', 100 * $count / $col_data[0]) . '%';
+        $col_data[$row] = sprintf('%.3f', 100 * $count / $col_data[0]);
       }
+      $col_data[$row] .= '%' unless $cgi->param('_type') eq 'xml';
     } #if $row == 0
     $row++;
   }
index 5f77081..2ffad2a 100755 (executable)
@@ -1,5 +1,5 @@
 % if ( $cgi->param('_type') =~ /^xml$/ ) {
-<zip_code>
+<zip_codes>
 % }
 <& elements/search.html,
                   'html_init'         => $html_init,
@@ -18,7 +18,7 @@
               
 &>
 % if ( $cgi->param('_type') =~ /^xml$/ ) {
-</zip_code>
+</zip_codes>
 % }
 <%init>
 
index b4f6ddc..2f3cf41 100755 (executable)
@@ -24,7 +24,7 @@
                   'url'             => $opt{url} || '',
                   'xml_row_element' => 'Datarow',
                   'really_disable_download' => 1,
-              
+                  'filename'        => $opt{filename},
 &>
 <%init>
 
@@ -117,7 +117,6 @@ foreach my $row ( @row_option ) {
           ($report_option ? ( 'report_option' => $report_option ) : () ),
         }
       );
-warn Dumper($sql_query) if $rowcount==1 and $columncount==3;
       my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
       my $percent = "CASE WHEN count(*) > 0 THEN 100-100*cast(count(cust_main.company) as numeric)/cast(count(*) as numeric) ELSE cast(0 as numeric) END AS residential";
       $sql_query->{select} = "count(*) AS quantity, $extracolumns, cust_location.censustract, $percent";
index 50b1916..18bfe8d 100644 (file)
@@ -32,9 +32,11 @@ my $header = $args{'header'};
 my $rows   = $args{'rows'};
 my %opt    = %{ $args{'opt'} };
 
+my $filename = $opt{'filename'} ||
+                ($opt{'name'} || PL($opt{'name_singular'}) . 'xml');
+
 http_header('Content-Type' => 'application/XML' ); # So saith RFC 4180
-http_header('Content-Disposition' => 
-  'attachment;filename="'.($opt{'name'} || PL($opt{'name_singular'}) ).'.xml"');
+http_header('Content-Disposition' => 'attachment;filename="'.$filename.'"');
 
 unless ( $opt{'fields'} ) {
   foreach my $i ( 0 .. ( $#{ @$rows[0] } ) ) {