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