summaryrefslogtreecommitdiff
path: root/httemplate/search/477partIA_detail.html
blob: 546d56c7f02760308eaaae746334dc3608ded8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<% 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 ],
                  '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 classnum) ) {
  $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
}

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 = "<H2>Part IA $technology breakdown by speeds</H2>";
my $xml_prefix = 'PartIA_'. chr(65 + $tech_code);

my $query = 'SELECT '. join(' UNION ALL SELECT ',@row_option);
my $count_query = 'SELECT '. scalar(@row_option);

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[$1 - 2] || '',
                          $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;
    $return .= "<BR>$percentage% residential"
      unless $cgi->param('_type') eq 'xml';
    return $return;
  } else {
    return '<FONT SIZE="+1" COLOR="#ff0000">Bad call to column_value</FONT>';
  }
};

my @fields = (
  sub { &{$value}(shift, 'name');},
  sub { &{$value}(shift, 2);},
  sub { &{$value}(shift, 3);},
  sub { &{$value}(shift, 4);},
  sub { &{$value}(shift, 5);},
  sub { &{$value}(shift, 6);},
  sub { &{$value}(shift, 7);},
  sub { &{$value}(shift, 8);},
  sub { &{$value}(shift, 9);},
 );
shift @fields if $cgi->param('_type') eq 'xml';

my $xml_element = sub {
  my ($rowref, $column) = (shift, shift);
  my $row = $rowref->[0];

  $row++;
  $xml_prefix. $column. $row;

};

my @xml_elements = (
  sub { &{$xml_element}(shift, 'f') },
  sub { &{$xml_element}(shift, 'g') },
  sub { &{$xml_element}(shift, 'h') },
  sub { &{$xml_element}(shift, 'i') },
  sub { &{$xml_element}(shift, 'j') },
  sub { &{$xml_element}(shift, 'k') },
  sub { &{$xml_element}(shift, 'l') },
  sub { &{$xml_element}(shift, 'm') },
);

</%init>