1 <% include( 'elements/search.html',
2 'html_init' => $html_init,
3 'html_foot' => sub { if (scalar(keys %state_hash) > 1) {
5 'WARNING: multiple states found'.
12 'query' => [ @sql_query ],
13 'count_query' => $count_query,
14 'order_by' => 'ORDER BY censustract',
24 'Technology code other',
26 'Percentage residential',
34 'technology_code_other',
39 sub { my $row = shift;
40 $state_hash{substr($row->censustract, 0, 2)} = 1;
41 substr($row->censustract, 2, 3)
43 sub { my $row = shift; substr($row->censustract, 5) },
47 sub { $cgi->param('_type') eq 'xml' ? '0' : '' }, # doesn't really work
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>';
80 for ( qw(agentnum magic classnum) ) {
81 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
84 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
85 if $cgi->param('part1_column_option');
87 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
88 if $cgi->param('part1_row_option');
90 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
93 foreach my $row ( @row_option ) {
95 foreach my $column ( @column_option ) {
97 foreach my $technology ( @technology_option ) {
99 next unless $technology;
100 my @report_option = ();
101 push @report_option, $row if $row;
102 push @report_option, $column if $column;
103 push @report_option, $technology;
104 my $report_option = join(',', @report_option) if @report_option;
106 my $sql_query = FS::cust_pkg->search(
108 ($report_option ? ( 'report_option' => $report_option ) : () ),
111 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
112 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";
113 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
114 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
115 or die "couldn't parse extra_sql";
116 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
117 push @sql_query, $sql_query;
124 my $count_query = 'SELECT count(*) FROM ( ('.
125 join( ') UNION ALL (',
126 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
127 "SELECT censustract from cust_pkg $addl $extra";
132 my $link = 'cust_pkg.cgi?'.
133 join(';', map{ "$_=". $search_hash{$_} } keys %search_hash). ';';
134 my $link_suffix = sub { my $row = shift;
135 my $result = 'censustract='. $row->censustract. ';';
136 $result .= 'report_option='. @row_option[$row->upload - 1]
137 if @row_option[$row->upload - 1];
138 $result .= 'report_option='. @column_option[$row->download - 1]
139 if @column_option[$row->download - 1];