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 $state_hash{substr($row->censustract, 0, 2)}++;
34 substr($row->censustract, 2, 3) || 'None'
36 sub { my $row = shift;
37 substr($row->censustract, 5) || 'None'
42 sub { $cgi->param('_type') eq 'xml' ? '0' : '' },#broken
44 sub { my $row = shift; sprintf "%.2f", $row->residential },
47 [ $link, $link_suffix ],
48 [ $link, $link_suffix ],
49 [ $link, $link_suffix ],
50 [ $link, $link_suffix ],
51 [ $link, $link_suffix ],
52 [ $link, $link_suffix ],
53 [ $link, $link_suffix ],
54 [ $link, $link_suffix ],
56 'url' => $opt{url} || '',
57 'xml_row_element' => 'Datarow',
62 my $curuser = $FS::CurrentUser::CurrentUser;
65 unless $curuser->access_right('List packages');
69 my $html_init = '<H2>Part VI</H2>';
75 for ( qw(agentnum magic) ) {
76 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
78 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
80 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
81 if $cgi->param('part1_column_option');
83 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
84 if $cgi->param('part1_row_option');
86 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
89 foreach my $row ( @row_option ) {
91 foreach my $column ( @column_option ) {
93 foreach my $technology ( @technology_option ) {
95 next unless $technology;
96 my @report_option = ();
97 push @report_option, $row if $row;
98 push @report_option, $column if $column;
99 push @report_option, $technology;
100 my $report_option = join(',', @report_option) if @report_option;
102 my $sql_query = FS::cust_pkg->search(
104 ($report_option ? ( 'report_option' => $report_option ) : () ),
107 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
108 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";
109 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
110 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
111 or die "couldn't parse extra_sql";
112 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
113 push @sql_query, $sql_query;
120 my $count_query = 'SELECT count(*) FROM ( ('.
121 join( ') UNION ALL (',
122 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
123 "SELECT censustract from cust_pkg $addl $extra";
128 my $link = 'cust_pkg.cgi?'. join(';',
130 my @values = ref($search_hash{$_})
131 ? @{ $search_hash{$_} }
133 map { "$key=$_" } @values;
138 my $link_suffix = sub { my $row = shift;
139 my $result = 'censustract='. $row->censustract. ';';
140 $result .= 'report_option='. @row_option[$row->upload - 1]
141 if @row_option[$row->upload - 1];
142 $result .= 'report_option='. @column_option[$row->download - 1]
143 if @column_option[$row->download - 1];
147 my $html_foot = sub {
148 if (scalar(keys %state_hash) > 1) {
149 '<BR><B>WARNING: multiple states found</B><BR>'.
150 '<TABLE BORDER=0>'. #nicer formatting someday
151 join('', map { '<TR>'.
153 ( &FS::Report::FCC_477::statenum2state($_) || 'None' ).
156 qq(<A HREF="${link}censustract2=$_">).
157 $state_hash{$_}. ' census tracts</A>'.