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 my $state = substr($row->censustract, 0, 2);
34 $state_hash{$state}++;
35 substr($row->censustract, 2, 3) || 'None'
37 sub { my $row = shift;
38 substr($row->censustract, 5) || 'None'
43 sub { $cgi->param('_type') eq 'xml' ? '0' : '' },#broken
44 sub { my $row = shift;
45 my $state = substr($row->censustract, 0, 2);
46 $state_pkgcount{$state} += $row->quantity;
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>';
79 my %state_pkgcount = ();
81 for ( qw(agentnum magic) ) {
82 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
84 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
86 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
87 if $cgi->param('part1_column_option');
89 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
90 if $cgi->param('part1_row_option');
92 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
95 foreach my $row ( @row_option ) {
97 foreach my $column ( @column_option ) {
99 foreach my $technology ( @technology_option ) {
101 next unless $technology;
102 my @report_option = ();
103 push @report_option, $row if $row;
104 push @report_option, $column if $column;
105 push @report_option, $technology;
106 my $report_option = join(',', @report_option) if @report_option;
108 my $sql_query = FS::cust_pkg->search(
110 ($report_option ? ( 'report_option' => $report_option ) : () ),
113 my $extracolumns = "$rowcount AS upload, $columncount AS download, $tech_code as technology_code";
114 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";
115 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
116 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
117 or die "couldn't parse extra_sql";
118 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
119 push @sql_query, $sql_query;
126 my $count_query = 'SELECT count(*) FROM ( ('.
127 join( ') UNION ALL (',
128 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
129 "SELECT censustract from cust_pkg $addl $extra";
134 my $link = 'cust_pkg.cgi?'. join(';',
136 my @values = ref($search_hash{$_})
137 ? @{ $search_hash{$_} }
139 map { "$key=$_" } @values;
144 my $link_suffix = sub { my $row = shift;
145 my $result = 'censustract='. $row->censustract. ';';
146 $result .= 'report_option='. @row_option[$row->upload - 1]
147 if @row_option[$row->upload - 1];
148 $result .= 'report_option='. @column_option[$row->download - 1]
149 if @column_option[$row->download - 1];
153 my $html_foot = sub {
154 if (scalar(keys %state_hash) > 1) {
155 '<BR><B>WARNING: multiple states found</B><BR>'.
156 '<TABLE BORDER=0>'. #nicer formatting someday
157 join('', map { '<TR>'.
159 ( &FS::Report::FCC_477::statenum2state($_) || 'None' ).
162 qq(<A HREF="${link}censustract2=$_">).
163 $state_pkgcount{$_}. ' packages</A> in '.
164 $state_hash{$_}. ' census tracts'.