1 <% include( 'elements/search.html',
2 'html_init' => '<H2>Part VI</H2>',
3 'html_foot' => $html_foot,
5 'query' => [ @sql_query ],
6 'count_query' => $count_query,
7 'order_by' => 'ORDER BY censustract',
18 'technology_code_other',
24 'url' => $opt{url} || '',
25 'xml_row_element' => 'Datarow',
26 'really_disable_download' => 1,
31 my $curuser = $FS::CurrentUser::CurrentUser;
34 unless $curuser->access_right('List packages');
39 my %state_pkgcount = ();
44 my $num = ($cgi->param('offset') =~ /^(\d+)$/) ? $1 : 0;
45 unless ( $cgi->param('_type') eq 'xml' ) {
47 push @fields, sub { ++$num };
56 'Technology code other',
58 'Percentage residential',
61 sub { my $row = shift;
62 my $state = substr($row->censustract, 0, 2);
63 $state_hash{$state}++;
64 substr($row->censustract, 2, 3) || 'None';
66 sub { my $row = shift;
67 substr($row->censustract, 5) || 'None';
72 sub { $cgi->param('_type') eq 'xml' ? '0' : '' },#broken
73 sub { my $row = shift;
74 my $state = substr($row->censustract, 0, 2);
75 $state_pkgcount{$state} += $row->quantity;
78 sub { my $row = shift; sprintf "%.2f", $row->residential },
84 for ( qw(agentnum magic) ) {
85 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
87 $search_hash{'classnum'} = [ $cgi->param('classnum') ]
88 if grep { $_ eq 'classnum' } $cgi->param;
90 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
91 if $cgi->param('part1_column_option');
93 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
94 if $cgi->param('part1_row_option');
96 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
99 foreach my $row ( @row_option ) {
101 foreach my $column ( @column_option ) {
103 foreach my $technology ( @technology_option ) {
105 next unless $technology;
106 my @report_option = ();
107 push @report_option, $row if $row;
108 push @report_option, $column if $column;
109 push @report_option, $technology;
110 my $report_option = join(',', @report_option) if @report_option;
112 my $sql_query = FS::cust_pkg->search(
114 ($report_option ? ( 'report_option' => $report_option ) : () ),
117 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
118 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";
119 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
120 $sql_query->{order_by} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
121 or die "couldn't parse order_by";
122 $sql_query->{order_by} = "$1 GROUP BY censustract $3";
123 push @sql_query, $sql_query;
130 my $count_query = 'SELECT count(*) FROM ( ('.
131 join( ') UNION ALL (',
132 map { my $addl_from = $_->{addl_from};
133 my $extra_sql = $_->{extra_sql};
134 my $order_by = $_->{order_by};
135 "SELECT censustract from cust_pkg $addl_from $extra_sql $order_by";
141 my $link = 'cust_pkg.cgi?'. join(';',
143 my @values = ref($search_hash{$_})
144 ? @{ $search_hash{$_} }
146 map { "$key=$_" } @values;
151 my $link_suffix = sub { my $row = shift;
152 my $result = 'censustract='. $row->censustract. ';';
154 @row_option[$row->upload - 1],
155 @column_option[$row->download - 2],
156 @technology_option[$row->technology_code - 1],
158 $result .= 'report_option='. join(',',@ro) if @ro;
162 for (1..8) { push @links, [ $link, $link_suffix ]; }
165 my $html_foot = sub {
166 if (scalar(keys %state_hash) > 1) {
168 my $roa_r = join(',', grep $_, @row_option);
169 $roa_r = ";report_option_any_r=$roa_r" if $roa_r;
171 my $roa_c = join(',', grep $_, @column_option);
172 $roa_c = ";report_option_any_c=$roa_c" if $roa_c;
174 my $roa_t = join(',', grep $_, @technology_option);
175 $roa_t = ";report_option_any_t=$roa_t" if $roa_t;
177 '<BR><B>WARNING: multiple states found</B><BR>'.
178 '<TABLE BORDER=0>'. #nicer formatting someday
179 join('', map { '<TR>'.
181 ( &FS::Report::FCC_477::statenum2state($_) || 'None' ).
184 qq(<A HREF="${link}censustract2=$_$roa_r$roa_c$roa_t">).
187 $state_hash{$_}. ' census tracts'.