link new tax report to cust_credit_bill_pkg for credits, RT#12332
[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 classnum) ) {
44   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
45 }
46
47 my @column_option = grep { /^\d+$/ } $cgi->param('part1_column_option')
48   if $cgi->param('part1_column_option');
49
50 my @row_option = grep { /^\d+$/ } $cgi->param('part1_row_option')
51   if $cgi->param('part1_row_option');
52
53 my @technology_option = &FS::Report::FCC_477::parse_technology_option($cgi);
54
55 my $total_count = 0;
56 my $total_residential = 0;
57 my $above_200 = 0;
58 my $tech_code = $opt{tech_code};
59 my $technology = $FS::Report::FCC_477::technology[$tech_code] || 'unknown';
60 my $html_init = "<H2>Part IA $technology totals</H2>";
61 my $xml_prefix = 'PartIA_'. chr(65 + $tech_code);
62
63 my $not_first_row = 0; # ugh;
64 foreach my $row ( @row_option ) {
65   foreach my $column ( @column_option ) {
66
67     my @report_option = ( $row || '-1', $column || '-1', $technology_option[$tech_code] );
68
69     my ( $count, $residential ) = FS::cust_pkg->fcc_477_count(
70       { %search_hash, 'report_option' => join(',', @report_option) }
71     );
72
73     $total_count += $count;
74     $total_residential += $residential;
75     $above_200 += $residential if $not_first_row;
76   }
77   $not_first_row++;
78 }
79
80 my $total_percentage =
81   sprintf("%.2f", $total_count ? 100*$total_residential/$total_count : 0);
82
83 my $above_200_percentage =
84   sprintf("%.2f", $total_count ? 100*$above_200/$total_count : 0);
85
86
87 </%init>