combine ticket notification scrips, #15353
[freeside.git] / httemplate / search / 477partIA_summary.html
1 <% include( 'elements/search.html',
2                   'html_init'        => $html_init,
3                   'name'             => 'lines',
4                   'query'            => 'SELECT 1',
5                   'count_query'      => 'SELECT 1',
6                   'really_disable_download' => 1,
7                   'disable_download' => 1,
8                   'nohtmlheader'     => 1,
9                   'disable_total'    => 1,
10                   'header'           => [
11                                           'Total Connections',
12                                           '% owned loop',
13                                           '% billed to end users',
14                                           '% residential',
15                                           '% residential &gt; 200kbps',
16                                         ],
17                   'xml_elements'     => [
18                                           $xml_prefix. 'a1',
19                                           $xml_prefix. 'b1',
20                                           $xml_prefix. 'c1',
21                                           $xml_prefix. 'd1',
22                                           $xml_prefix. 'e1',
23                                         ],
24                   'fields'           => [
25                                           sub { $total_count },
26                                           sub { '100.00' },
27                                           sub { '100.00' },
28                                           sub { $total_percentage },
29                                           sub { $above_200_percentage },
30                                         ],
31               )
32 %>
33 <%init>
34
35 my $curuser = $FS::CurrentUser::CurrentUser;
36
37 die "access denied"
38   unless $curuser->access_right('List packages');
39
40 my %opt = @_;
41 my %search_hash = ();
42   
43 for ( qw(agentnum magic) ) {
44   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
45 }
46 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
47
48 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
49   if $cgi->param('part1_column_option');
50
51 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
52   if $cgi->param('part1_row_option');
53
54 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
55
56 my $total_count = 0;
57 my $total_residential = 0;
58 my $above_200 = 0;
59 my $tech_code = $opt{tech_code};
60 my $technology = $FS::Report::FCC_477::technology[$tech_code] || 'unknown';
61 my $html_init = "<H2>Part IA $technology totals</H2>";
62 my $xml_prefix = 'PartIA_'. chr(65 + $tech_code);
63
64 my $not_first_row = 0; # ugh;
65 foreach my $row ( @row_option ) {
66   foreach my $column ( @column_option ) {
67
68     my @report_option = ( $row || '-1', $column || '-1', $technology_option[$tech_code] );
69
70     my ( $count, $residential ) = FS::cust_pkg->fcc_477_count(
71       { %search_hash, 'report_option' => join(',', @report_option) }
72     );
73
74     $total_count += $count;
75     $total_residential += $residential;
76     $above_200 += $residential if $not_first_row;
77   }
78   $not_first_row++;
79 }
80
81 my $total_percentage =
82   sprintf("%.2f", $total_count ? 100*$total_residential/$total_count : 0);
83
84 my $above_200_percentage =
85   sprintf("%.2f", $total_count ? 100*$above_200/$total_count : 0);
86
87
88 </%init>