1 <% include( 'elements/search.html',
2 'html_init' => $html_init,
4 'query' => [ @sql_query ],
5 'count_query' => $count_query,
6 'order_by' => 'ORDER BY censustract',
16 'Technology code other',
18 'Percentage residential',
26 'technology_code_other',
31 sub { my $row = shift; substr($row->censustract, 2, 3) },
32 sub { my $row = shift; substr($row->censustract, 5) },
36 sub { '' }, # doesn't really work
38 sub { my $row = shift; sprintf "%.2f", $row->residential },
41 [ $link, $link_suffix ],
42 [ $link, $link_suffix ],
43 [ $link, $link_suffix ],
44 [ $link, $link_suffix ],
45 [ $link, $link_suffix ],
46 [ $link, $link_suffix ],
47 [ $link, $link_suffix ],
48 [ $link, $link_suffix ],
50 'url' => $opt{url} || '',
51 'xml_row_element' => 'Datarow',
56 my $curuser = $FS::CurrentUser::CurrentUser;
59 unless $curuser->access_right('List packages');
63 my $html_init = '<H2>Part VI</H2>';
68 for ( qw(agentnum magic classnum) ) {
69 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
72 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
73 if $cgi->param('part1_column_option');
75 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
76 if $cgi->param('part1_row_option');
78 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
81 foreach my $row ( @row_option ) {
83 foreach my $column ( @column_option ) {
85 foreach my $technology ( @technology_option ) {
87 next unless $technology;
88 my @report_option = ();
89 push @report_option, $row if $row;
90 push @report_option, $column if $column;
91 push @report_option, $technology;
92 my $report_option = join(',', @report_option) if @report_option;
94 my $sql_query = FS::cust_pkg->search(
96 ($report_option ? ( 'report_option' => $report_option ) : () ),
99 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
100 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";
101 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
102 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
103 or die "couldn't parse extra_sql";
104 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
105 push @sql_query, $sql_query;
112 my $count_query = 'SELECT count(*) FROM ( ('.
113 join( ') UNION ALL (',
114 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
115 "SELECT censustract from cust_pkg $addl $extra";
120 my $link = 'cust_pkg.cgi?'.
121 join(';', map{ "$_=". $search_hash{$_} } keys %search_hash). ';';
122 my $link_suffix = sub { my $row = shift;
123 my $result = 'censustract='. $row->censustract. ';';
124 $result .= 'report_option='. @row_option[$row->upload - 1]
125 if @row_option[$row->upload - 1];
126 $result .= 'report_option='. @column_option[$row->download - 1]
127 if @column_option[$row->download - 1];