1 <% include( 'elements/search.html',
2 'html_init' => $html_init,
3 'html_foot' => $html_foot,
5 'query' => [ @sql_query ],
6 'count_query' => $count_query,
7 'order_by' => 'ORDER BY censustract',
17 'Technology code other',
19 'Percentage residential',
27 'technology_code_other',
32 sub { my $row = shift;
33 my $state = substr($row->censustract, 0, 2);
34 $state_hash{$state}++;
35 substr($row->censustract, 2, 3) || 'None';
37 sub { my $row = shift;
38 substr($row->censustract, 5) || 'None';
43 sub { $cgi->param('_type') eq 'xml' ? '0' : '' },#broken
44 sub { my $row = shift;
45 my $state = substr($row->censustract, 0, 2);
46 $state_pkgcount{$state} += $row->quantity;
49 sub { my $row = shift; sprintf "%.2f", $row->residential },
52 [ $link, $link_suffix ],
53 [ $link, $link_suffix ],
54 [ $link, $link_suffix ],
55 [ $link, $link_suffix ],
56 [ $link, $link_suffix ],
57 [ $link, $link_suffix ],
58 [ $link, $link_suffix ],
59 [ $link, $link_suffix ],
61 'url' => $opt{url} || '',
62 'xml_row_element' => 'Datarow',
67 my $curuser = $FS::CurrentUser::CurrentUser;
70 unless $curuser->access_right('List packages');
74 my $html_init = '<H2>Part VI</H2>';
79 my %state_pkgcount = ();
81 for ( qw(agentnum magic) ) {
82 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
84 $search_hash{'classnum'} = [ $cgi->param('classnum') ]
85 if grep { $_ eq 'classnum' } $cgi->param;
87 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
88 if $cgi->param('part1_column_option');
90 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
91 if $cgi->param('part1_row_option');
93 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
96 foreach my $row ( @row_option ) {
98 foreach my $column ( @column_option ) {
100 foreach my $technology ( @technology_option ) {
102 next unless $technology;
103 my @report_option = ();
104 push @report_option, $row if $row;
105 push @report_option, $column if $column;
106 push @report_option, $technology;
107 my $report_option = join(',', @report_option) if @report_option;
109 my $sql_query = FS::cust_pkg->search(
111 ($report_option ? ( 'report_option' => $report_option ) : () ),
114 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
115 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";
116 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
117 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
118 or die "couldn't parse extra_sql";
119 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
120 push @sql_query, $sql_query;
127 my $count_query = 'SELECT count(*) FROM ( ('.
128 join( ') UNION ALL (',
129 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
130 "SELECT censustract from cust_pkg $addl $extra";
135 my $link = 'cust_pkg.cgi?'. join(';',
137 my @values = ref($search_hash{$_})
138 ? @{ $search_hash{$_} }
140 map { "$key=$_" } @values;
145 my $link_suffix = sub { my $row = shift;
146 my $result = 'censustract='. $row->censustract. ';';
148 @row_option[$row->upload - 1],
149 @column_option[$row->download - 2],
150 @technology_option[$row->technology_code - 1],
152 $result .= 'report_option='. join(',',@ro) if @ro;
156 my $html_foot = sub {
157 if (scalar(keys %state_hash) > 1) {
159 my $roa_r = join(',', grep $_, @row_option);
160 $roa_r = ";report_option_any_r=$roa_r" if $roa_r;
162 my $roa_c = join(',', grep $_, @column_option);
163 $roa_c = ";report_option_any_c=$roa_c" if $roa_c;
165 my $roa_t = join(',', grep $_, @technology_option);
166 $roa_t = ";report_option_any_t=$roa_t" if $roa_t;
168 '<BR><B>WARNING: multiple states found</B><BR>'.
169 '<TABLE BORDER=0>'. #nicer formatting someday
170 join('', map { '<TR>'.
172 ( &FS::Report::FCC_477::statenum2state($_) || 'None' ).
175 qq(<A HREF="${link}censustract2=$_$roa_r$row_c$row_t">).
176 $state_pkgcount{$_}. ' packages</A> in '.
177 $state_hash{$_}. ' census tracts'.