fix 477 reporting w/multiple classnums, RT#13922
[freeside.git] / httemplate / search / 477partVI_census.html
index fc260be..15d2b81 100755 (executable)
@@ -1,6 +1,6 @@
 <% include( 'elements/search.html',
                   'html_init'     => $html_init,
-                  'html_foot'     => $html_foot,,
+                  'html_foot'     => $html_foot,
                   'name'          => 'regions',
                   'query'         => [ @sql_query ],
                   'count_query'   =>  $count_query,
                                      ],
                   'fields'        => [
                     sub { my $row = shift; 
-                          $state_hash{substr($row->censustract, 0, 2)}++;
-                          substr($row->censustract, 2, 3) || 'None'
+                          my $state = substr($row->censustract, 0, 2);
+                          $state_hash{$state}++;
+                          substr($row->censustract, 2, 3) || 'None';
                         },
                     sub { my $row = shift;
-                          substr($row->censustract, 5) || 'None'
+                          substr($row->censustract, 5) || 'None';
                         },
                     'upload',
                     'download',
                     'technology_code',
                     sub { $cgi->param('_type') eq 'xml' ? '0' : '' },#broken
-                    'quantity',
+                    sub { my $row = shift;
+                          my $state = substr($row->censustract, 0, 2);
+                          $state_pkgcount{$state} += $row->quantity;
+                          $row->quantity;
+                        },
                     sub { my $row = shift; sprintf "%.2f", $row->residential },
                   ],
                   'links'        => [
@@ -71,11 +76,13 @@ my $html_init = '<H2>Part VI</H2>';
 my %search_hash = ();
 my @sql_query = ();
 my %state_hash = ();
+my %state_pkgcount = ();
   
 for ( qw(agentnum magic) ) {
   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
 }
-$search_hash{'classnum'} = [ $cgi->param('classnum') ];
+$search_hash{'classnum'} = [ $cgi->param('classnum') ]
+  if grep { $_ eq 'classnum' } $cgi->param;
 
 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
   if $cgi->param('part1_column_option');
@@ -154,7 +161,8 @@ my $html_foot = sub {
                      '</TD>'.
                      '<TD>'.
                        qq(<A HREF="${link}censustract2=$_">).
-                       $state_hash{$_}. ' census tracts</A>'.
+                       $state_pkgcount{$_}. ' packages</A> in '.
+                       $state_hash{$_}. ' census tracts'.
                      '</TD>'.
                    '</TR>';
                  }