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) ) {
81 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
83 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
85 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
86 if $cgi->param('part1_column_option');
88 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
89 if $cgi->param('part1_row_option');
91 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
94 foreach my $row ( @row_option ) {
96 foreach my $column ( @column_option ) {
98 foreach my $technology ( @technology_option ) {
100 next unless $technology;
101 my @report_option = ();
102 push @report_option, $row if $row;
103 push @report_option, $column if $column;
104 push @report_option, $technology;
105 my $report_option = join(',', @report_option) if @report_option;
107 my $sql_query = FS::cust_pkg->search(
109 ($report_option ? ( 'report_option' => $report_option ) : () ),
112 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
113 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";
114 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
115 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
116 or die "couldn't parse extra_sql";
117 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
118 push @sql_query, $sql_query;
125 my $count_query = 'SELECT count(*) FROM ( ('.
126 join( ') UNION ALL (',
127 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
128 "SELECT censustract from cust_pkg $addl $extra";
133 my $link = 'cust_pkg.cgi?'.
134 join(';', map{ "$_=". $search_hash{$_} } keys %search_hash). ';';
135 my $link_suffix = sub { my $row = shift;
136 my $result = 'censustract='. $row->censustract. ';';
137 $result .= 'report_option='. @row_option[$row->upload - 1]
138 if @row_option[$row->upload - 1];
139 $result .= 'report_option='. @column_option[$row->download - 1]
140 if @column_option[$row->download - 1];