1 % if ( $cgi->param('_type') eq 'xml' ) {
2 % my @cols = qw(a b c);
3 % for ( my $row = 0; $row < scalar(@rows); $row++ ) {
5 % if ( exists($data[$col][$row]) ) {
6 <PartII_<% $row + 1 %><% $cols[$col] %>>\
7 <% $data[$col][$row] %>\
8 </PartII_<% $row + 1 %><% $cols[$col] %>>
12 % } else { # HTML mode
13 % # fake up the search-html.html header
16 <TR><TD VALIGN="bottom"><BR></TD></TR>
18 <TABLE CLASS="grid" CELLSPACING=0>
20 % foreach (@headers) {
25 % foreach my $rowhead (@rows) {
26 <TR CLASS="row<% $row % 2 %>">
27 <TD STYLE="text-align: left; font-weight: bold"><% $rowhead %></TD>
28 % for my $col (0..2) {
30 % if ( exists($data[$col][$row]) ) {
31 <% $data[$col][$row] %>
44 my $curuser = $FS::CurrentUser::CurrentUser;
47 unless $curuser->access_right('List packages');
51 $search_hash{'agentnum'} = $cgi->param('agentnum');
52 $search_hash{'state'} = $cgi->param('state');
53 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
54 $search_hash{'status'} = 'active';
57 foreach ($cgi->param('part2b_row_option')) {
58 push @row_option, (/^\d+$/ ? $_ : undef);
61 my $is_residential = "AND COALESCE(cust_main.company, '') = ''";
62 my $has_report_option = sub {
64 defined($row_option[$_]) ?
66 SELECT 1 FROM part_pkg_option
67 WHERE part_pkg_option.pkgpart = part_pkg.pkgpart
68 AND optionname = 'report_option_" . $row_option[$_]."'
74 # an arrayref for each column
76 # get the skeleton of the query
77 my $sql_query = FS::cust_pkg->search(\%search_hash);
78 my $from_where = $sql_query->{'count_query'};
79 $from_where =~ s/^SELECT COUNT\(\*\) //;
81 my $query_ds0 = "SELECT SUM(COALESCE(part_pkg.fcc_ds0s, pkg_class.fcc_ds0s, 0))
84 my $query_custnum = "SELECT COUNT(DISTINCT cust_pkg.custnum) $from_where";
86 my @base_queries = ($query_ds0, $query_ds0, $query_custnum);
92 $has_report_option->(0), # nomadic
98 $has_report_option->(0..5),
107 foreach (@col_conds) {
110 foreach my $cond (@{ $col_conds[$col] }) {
111 # three parts: the select expression, the VoIP class (column selection),
112 # and the row selection
113 my $query = $base_queries[$col] .
114 " AND part_pkg.fcc_voip_class = '".($col+1)."'
116 my $count = FS::Record->scalar_sql($query) || 0;
118 $col_data[$row] = $count; # the raw count
120 if ( $col_data[0] == 0 ) {
121 $col_data[$row] = ''; # show nothing in this row, then
123 $col_data[$row] = sprintf('%.3f', 100 * $count / $col_data[0]) . '%';
128 $data[$col] = \@col_data;