% include( 'elements/search.html',
'html_init' => $html_init,
'name' => 'lines',
'query' => $query,
'count_query' => $count_query,
'really_disable_download' => 1,
'disable_download' => 1,
'nohtmlheader' => 1,
'disable_total' => 1,
'header' => [ '', @column_option_name ],
'xml_elements' => [ @xml_elements ],
'xml_omit_empty' => 1,
'fields' => [ @fields ],
)
%>
<%init>
my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
unless $curuser->access_right('List packages');
my %opt = @_;
my %search_hash = ();
for ( qw(agentnum magic) ) {
$search_hash{$_} = $cgi->param($_) if $cgi->param($_);
}
$search_hash{'classnum'} = [ $cgi->param('classnum') ];
my @column_option = grep { /^\d+/ } $cgi->param('part1_column_option')
if $cgi->param('part1_column_option');
my @row_option = grep { /^\d+/ } $cgi->param('part1_row_option')
if $cgi->param('part1_row_option');
my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
my @column_option_name = scalar(@column_option)
? ( map { my $part_pkg_report_option =
qsearchs({ 'table' => 'part_pkg_report_option',
'hashref' => { num => $_ },
});
$part_pkg_report_option ? $part_pkg_report_option->name
: 'no such report option';
} @column_option
)
: ( 'all packages' );
my $where = join(' OR ', map { "num = $_" } @row_option );
my %row_option_name = $where ?
( map { $_->num => $_->name }
qsearch({ 'table' => 'part_pkg_report_option',
'hashref' => {},
'extra_sql' => "WHERE $where",
})
) :
();
my $tech_code = $opt{tech_code};
my $technology = $FS::Report::FCC_477::technology[$tech_code] || 'unknown';
my $html_init = "
Part IA $technology breakdown by speeds
";
my $xml_prefix = 'PartIA_'. chr(65 + $tech_code);
if ($cgi->param('_type') eq 'xml') {
#rotate data pi/2
my @temp = @column_option;
@column_option = @row_option;
@row_option = @temp;
}
my $query = 'SELECT '. join(' UNION ALL SELECT ',@row_option);
my $count_query = 'SELECT '. scalar(@row_option);
my $xml_element = 'OOPS, I was never set';
my $rowchar = 101; # 'e' -- rows are columns! (pi/2)
my $value = sub {
my ($rowref, $column) = (shift, shift);
my $row = $rowref->[0];
if ($column eq 'name') {
return $row_option_name{$row} || 'no such report option';
} elsif ( $column =~ /^(\d+)$/ ) {
my @report_option = ( $row || '',
$column_option[$column] || '',
$technology_option[$tech_code] || '',
);
my ( $count, $residential ) = FS::cust_pkg->fcc_477_count(
{ %search_hash, 'report_option' => join(',', @report_option) }
);
my $percentage = sprintf('%.2f', $count ? 100 * $residential / $count : 0);
my $return = $count;
if ($cgi->param('_type') eq 'xml') {
$rowchar++ if $column == 0;
$xml_element = $xml_prefix. chr($rowchar). ($column+1);
$return = '' if $count == 0 and $cgi->param('_type') eq 'xml';
} else {
$return .= "
$percentage% residential";
}
return $return;
} else {
return 'Bad call to column_value';
}
};
my @fields = map { my $ci = $_; sub { &{$value}(shift, $ci); } }
( 'name', (0 .. $#column_option) );
shift @fields if $cgi->param('_type') eq 'xml';
my @xml_elements = ( # -- columns are rows! (pi/2)
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
sub { return $xml_element; },
);
%init>