new 477 report: deployment info, combined browse-edit UI, #24047
[freeside.git] / httemplate / browse / part_pkg-fcc.html
1 <& elements/browse.html,
2   'title'                 => 'Package Definitions - FCC Options',
3   'menubar'               => \@menubar,
4   'html_init'             => $html_init,
5   'html_form'             => $html_form,
6   'html_posttotal'        => $html_posttotal,
7   'name'                  => 'package definitions',
8   'disableable'           => 1,
9   'disabled_statuspos'    => 4,
10   'agent_virt'            => 1,
11   'agent_null_right'      => [ $edit, $edit_global ],
12   'agent_null_right_link' => $edit_global,
13   'agent_pos'             => 6,
14   'query'                 =>
15                             { 'select'    => $select,
16                               'table'     => 'part_pkg',
17                               'addl_from' => $addl_from,
18                               'hashref'   => \%hash,
19                               'extra_sql' => $extra_sql,
20                               'order_by'  => "ORDER BY $orderby"
21                             },
22   'count_query'           => $count_query,
23   'header'                => \@header,
24   'fields'                => \@fields,
25   'links'                 => \@links,
26   'align'                 => $align,
27   'link_field'            => 'pkgpart',
28   'html_foot'             => $html_foot,
29 &>
30 <%init>
31
32 my $curuser = $FS::CurrentUser::CurrentUser;
33
34 my $edit        = 'Edit package definitions';
35 my $edit_global = 'Edit global package definitions';
36 my $acl_edit        = $curuser->access_right($edit);
37 my $acl_edit_global = $curuser->access_right($edit_global);
38
39 die "access denied"
40   unless $acl_edit || $acl_edit_global;
41
42 my $conf = new FS::Conf;
43
44 my $orderby = 'pkgpart';
45 my %hash = ();
46 my $extra_count = '';
47
48 my @where = ();
49
50 # only ever show recurring packages here
51 $hash{'freq'} = { op=>'!=', value=>'0' };
52 $extra_count = " freq != '0' ";
53
54 # filter by classnum
55 my $classnum = '';
56 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
57   $classnum = $1;
58   push @where, $classnum ? "classnum =  $classnum"
59                          : "classnum IS NULL";
60 }
61 $cgi->delete('classnum');
62
63 # filter by agent permissions
64 push @where, FS::part_pkg->curuser_pkgs_sql
65   unless $acl_edit_global;
66
67 my $extra_sql = scalar(@where)
68                 ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
69                   join( 'AND ', @where)
70                 : '';
71
72 # pull option values into the select
73 my @optionnames = ( qw(
74   media
75   is_consumer
76   is_broadband technology broadband_upstream broadband_downstream
77   is_phone phone_wholesale phone_vges phone_circuits 
78   phone_lines phone_longdistance phone_localloop
79   is_voip voip_lastmile voip_sessions
80 ) );
81
82 my $select = join(',',
83   'part_pkg.*',
84   '(SELECT classname FROM pkg_class WHERE pkg_class.classnum = part_pkg.classnum) AS classname', # grr, disableable...
85   @optionnames
86 );
87
88 my $addl_from = 
89   FS::Report::FCC_477::join_optionnames(@optionnames);
90
91 #restore this so pagination works
92 $cgi->param('classnum', $classnum) if length($classnum);
93
94 #should hide this if there aren't any classes
95 my $html_posttotal =
96   "<BR>( show class: ".
97   include('/elements/select-pkg_class.html',
98             #'curr_value'    => $classnum,
99             'value'         => $classnum, #insist on 0 :/
100             'onchange'      => 'filter_change()',
101             'pre_options'   => [ '-1' => 'all',
102                                  '0'  => '(none)', ],
103             'disable_empty' => 1,
104          ).
105   ' )';
106
107 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
108
109 my @header = ( '#', 'Package', 'Comment' );
110 my @fields = ( 'pkgpart', 'pkg', 'comment' ,);
111 my $align = 'rll';
112 my @links = ( $link, $link, '', );
113
114 unless ( length($classnum) ) {
115   push @header, 'Class';
116   push @fields, 'classname';
117   $align .= 'l';
118 }
119
120 # still include the report_option classes, to help with migration
121 # but not other plan options
122
123 my %report_optionname_name = map { 'report_option_'.$_->num, $_->name }
124   qsearch('part_pkg_report_option', { disabled => '' });
125
126 push @header, 'Report classes';
127
128 push @fields, 
129               sub {
130                     my $part_pkg = shift;
131                     my %options = $part_pkg->options;
132                     # gather any options that are really report options,
133                     # convert them to their user-friendly names,
134                     # and sort them (I think?)
135                     my @report_options =
136                       sort { $a cmp $b }
137                       map { $report_optionname_name{$_} }
138                       grep { $options{$_}
139                              and exists($report_optionname_name{$_}) }
140                       keys %options;
141
142                     my @rows;
143                     foreach (@report_options) {
144                       push @rows, [
145                         { 'data'  => $_,
146                           'align' => 'center',
147                           'colspan' => 2
148                         }
149                       ];
150                     } # foreach @report_options
151                     \@rows;
152                   };
153
154 $align .= 'cr';
155
156 # --------
157 # now the FCC option part
158 # --------
159
160 my @pkgparts;
161 push @header, 'FCC report parameters';
162 push @fields, sub {
163   my $part_pkg = shift;
164   my %hash = $part_pkg->fcc_options;
165   include('/elements/input-fcc_options.html',
166             id          => 'pkgpart'.$part_pkg->pkgpart,
167             curr_value  => encode_json(\%hash),
168             html_only   => 1
169   );
170 };
171 $align .= 'l';
172
173 my $count_extra_sql = $extra_sql;
174 $count_extra_sql =~ s/^\s*AND /WHERE /i;
175 $extra_count = ( $count_extra_sql ? ' AND ' : ' WHERE ' ). $extra_count
176   if $extra_count;
177 my $count_query = "SELECT COUNT(*) FROM part_pkg $count_extra_sql $extra_count";
178
179 my $html_init = 
180   include('/elements/init_overlib.html') .
181   include('/elements/input-fcc_options.html', js_only => 1) .
182   include('.style');
183
184 my $html_form = '';
185 my $html_foot = '';
186 # insert a checkbox column
187 unshift @header, '';
188 unshift @fields, sub {
189   '<INPUT TYPE="checkbox" NAME="pkgpart" VALUE=' . $_[0]->pkgpart .'>';
190 };
191 unshift @links, '';
192 $align = 'c'.$align;
193
194
195 $html_form = qq!<FORM ACTION="${p}edit/process/bulk-part_pkg-fcc.html" METHOD="POST">!;
196 $html_foot = qq!
197   <INPUT TYPE="submit" VALUE="Save changes">
198   </FORM>!;
199
200 my @menubar =
201   ( 'Package definitions' => $p.'browse/part_pkg.cgi' );
202
203 </%init>
204 <%def .style>
205 <style>
206   ul.fcc_options {
207     text-align: left;
208   }
209   ul.fcc_options li {
210   }
211   button.edit_fcc_options {
212     float: right;
213   }
214 </style>
215 </%def>