1 <% include( 'elements/search.html',
2 'html_init' => $html_init,
5 'count_query' => 'SELECT 11',
6 'really_disable_download' => 1,
7 'disable_download' => 1,
10 'header' => [ @headers ],
11 'xml_elements' => [ @xml_elements ],
12 'fields' => [ @fields ],
17 my $curuser = $FS::CurrentUser::CurrentUser;
20 unless $curuser->access_right('List packages');
22 my $html_init = '<H2>Part IIA</H2>';
25 for ( qw(agentnum magic) ) {
26 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
28 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
30 my @row_option = grep { /^\d+$/ } $cgi->param('part2a_row_option')
31 if $cgi->param('part2a_row_option');
33 # fudge in two rows of LD carrier
34 unshift @row_option, $row_option[0];
36 # fudge in the first pair of rows
37 unshift @row_option, '';
38 unshift @row_option, '';
40 my $query = 'SELECT '. join(' UNION SELECT ', 1..11);
43 my $column_value = sub {
46 my @report_option = ( $row_option[$row - 1] || '' );
48 my $sql_query = FS::cust_pkg->search(
49 { %search_hash, 'report_option' => join(',', @report_option) }
52 my $count_sql = delete($sql_query->{'count_query'});
53 if ( $row == 2 || $row == 4 ) {
54 $count_sql =~ s/COUNT\(\*\) FROM/sum(COALESCE(CASE WHEN cust_main.company IS NULL OR cust_main.company = '' THEN CASE WHEN part_pkg.fcc_ds0s IS NOT NULL AND part_pkg.fcc_ds0s > 0 THEN part_pkg.fcc_ds0s WHEN pkg_class.fcc_ds0s IS NOT NULL AND pkg_class.fcc_ds0s > 0 THEN pkg_class.fcc_ds0s ELSE 0 END ELSE 0 END, 0) ) FROM/
55 or die "couldn't parse count_sql";
57 $count_sql =~ s/COUNT\(\*\) FROM/sum(COALESCE(CASE WHEN part_pkg.fcc_ds0s IS NOT NULL AND part_pkg.fcc_ds0s > 0 THEN part_pkg.fcc_ds0s WHEN pkg_class.fcc_ds0s IS NOT NULL AND pkg_class.fcc_ds0s > 0 THEN pkg_class.fcc_ds0s ELSE 0 END, 0)) FROM/
58 or die "couldn't parse count_sql";
61 my $count_sth = dbh->prepare($count_sql)
62 or die "Error preparing $count_sql: ". dbh->errstr;
64 or die "Error executing $count_sql: ". $count_sth->errstr;
65 my $count_arrayref = $count_sth->fetchrow_arrayref;
66 my $count = $count_arrayref->[0];
68 $total_count = $count if $row == 1;
69 $count = sprintf('%.2f', $total_count ? 100*$count/$total_count : 0)
84 sub { my $row = shift; my $rownum = $row->[0] + 1; "PartII_${rownum}a" },
85 sub { my $row = shift; my $rownum = $row->[0] + 1; "PartII_${rownum}b" },
86 sub { my $row = shift; my $rownum = $row->[0] + 1; "PartII_${rownum}c" },
87 sub { my $row = shift; my $rownum = $row->[0] + 1; "PartII_${rownum}d" },
95 '% residential and LD carrier',
97 '% obtained unswitched UNE loops',
99 '% UNE-P replacement',
106 sub { my $row = shift; $rows[$row->[0] - 1]; },
107 sub { my $row = shift; &{$column_value}($row->[0]); },
113 shift @fields if $cgi->param('_type') eq 'xml';