1 <% include( 'elements/search.html',
2 'title' => 'FCC Form 477 Results',
3 'html_init' => $html_init,
5 'query' => [ @sql_query ],
6 'count_query' => $count_query,
7 'order_by' => 'ORDER BY censustract',
14 'Technology code other',
16 'Percentage residential',
19 sub { my $row = shift; substr($row->censustract, 2, 3) },
20 sub { my $row = shift; substr($row->censustract, 5) },
26 sub { my $row = shift; sprintf "%.2f", $row->residential },
29 [ $link, $link_suffix ],
30 [ $link, $link_suffix ],
31 [ $link, $link_suffix ],
32 [ $link, $link_suffix ],
33 [ $link, $link_suffix ],
34 [ $link, $link_suffix ],
35 [ $link, $link_suffix ],
36 [ $link, $link_suffix ],
42 my $curuser = $FS::CurrentUser::CurrentUser;
45 unless $curuser->access_right('List packages');
50 for ( qw(agentnum magic classnum) ) {
51 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
54 my @column_option = $cgi->param('column_option')
55 if $cgi->param('column_option');
57 my @row_option = $cgi->param('row_option')
58 if $cgi->param('row_option');
60 my $where = join(' OR ', map { "num = $_" } grep { /^\d+$/ } @column_option );
61 my %column_option_name = $where ?
62 ( map { $_->name => $_->num }
63 qsearch({ 'table' => 'part_pkg_report_option',
65 'extra_sql' => "WHERE $where",
68 ( 'all packages' => '' );
70 $where = join(' OR ', map { "num = $_" } grep { /^\d+$/ } @row_option );
71 my %row_option_name = $where ?
72 ( map { $_->name => $_->num }
73 qsearch({ 'table' => 'part_pkg_report_option',
75 'extra_sql' => "WHERE $where",
78 ( 'all packages' => '' );
80 @row_option = map { $row_option_name{$_} } sort keys %row_option_name;
81 @column_option = map { $column_option_name{$_} } sort keys %column_option_name;
83 #$search_hash{row_option} = join(',', @row_option) if @row_option;
84 my $html_init = '<H2>Summary</H2>'. include('/elements/table.html');
85 $html_init .= '<TR><TH></TH>';
86 foreach my $column ( sort keys %column_option_name ) {
87 $html_init .= "<TH>$column</TH>";
89 $html_init .= "</TR>";
92 foreach my $row ( sort keys %row_option_name ) {
94 $html_init .= "<TR><TH>$row</TH>";
97 foreach my $column ( sort keys %column_option_name ) {
98 my @report_option = ();
99 push @report_option, $row_option_name{$row}
100 if $row_option_name{$row};
101 push @report_option, $column_option_name{$column}
102 if $column_option_name{$column};
103 my $report_option = join(',', @report_option) if @report_option;
105 my $sql_query = FS::cust_pkg->search_sql(
107 ($report_option ? ( 'report_option' => $report_option ) : () ),
110 my $extracolumns = "$rowcount AS upload, $columncount AS download";
111 my $percent = "100-100*cast(count(cust_main.company) as numeric)/cast(count(*) as numeric) AS residential";
112 $sql_query->{select} = "count(*) AS quantity, $extracolumns, censustract, $percent";
113 $sql_query->{extra_sql} =~ /^(.*)(ORDER BY pkgnum)(.*)$/s
114 or die "couldn't parse extra_sql";
115 $sql_query->{extra_sql} = "$1 GROUP BY censustract $3";
117 my $count_sql = delete($sql_query->{'count_query'});
119 my $count_sth = dbh->prepare($count_sql)
120 or die "Error preparing $count_sql: ". dbh->errstr;
122 or die "Error executing $count_sql: ". $count_sth->errstr;
123 my $count_arrayref = $count_sth->fetchrow_arrayref;
124 my $count = $count_arrayref->[0];
126 $html_init .= "<TD>$count</TD>";
127 push @sql_query, $sql_query;
131 $html_init .= "</TR>";
135 $html_init .= "</TABLE><BR><H2>Details</H2>";
137 my $count_query = 'SELECT count(*) FROM ( ('.
139 map { my $extra = $_->{extra_sql}; my $addl = $_->{addl_from};
140 "SELECT censustract from cust_pkg $addl $extra";
145 my $link = 'cust_pkg.cgi?'.
146 join(';', map{ "$_=". $search_hash{$_} } keys %search_hash). ';';
147 my $link_suffix = sub { my $row = shift;
148 my $result = 'censustract='. $row->censustract. ';';
149 $result .= 'report_option='. @row_option[$row->upload - 1]
150 if @row_option[$row->upload - 1];
151 $result .= 'report_option='. @column_option[$row->download - 1]
152 if @column_option[$row->download - 1];