1 <% include( 'elements/browse.html',
2 'title' => 'Package Definitions',
3 'html_init' => $html_init,
4 'html_posttotal' => $html_posttotal,
5 'name' => 'package definitions',
7 'disabled_statuspos' => 3,
9 'agent_null_right' => [ $edit, $edit_global ],
10 'agent_null_right_link' => $edit_global,
12 'query' => { 'select' => $select,
13 'table' => 'part_pkg',
15 'extra_sql' => $extra_sql,
16 'order_by' => "ORDER BY $orderby"
18 'count_query' => $count_query,
27 my $curuser = $FS::CurrentUser::CurrentUser;
29 my $edit = 'Edit package definitions';
30 my $edit_global = 'Edit global package definitions';
31 my $acl_edit = $curuser->access_right($edit);
32 my $acl_edit_global = $curuser->access_right($edit_global);
33 my $acl_config = $curuser->access_right('Configuration'); #to edit services
37 unless $acl_edit || $acl_edit_global;
39 my $conf = new FS::Conf;
40 my $taxclasses = $conf->exists('enable_taxclasses');
41 my $money_char = $conf->config('money_char') || '$';
44 my $orderby = 'pkgpart';
48 if ( $cgi->param('active') ) {
49 $orderby = 'num_active DESC';
54 #if ( $cgi->param('activeONLY') ) {
55 # push @where, ' WHERE num_active > 0 '; #XXX doesn't affect count...
58 if ( $cgi->param('recurring') ) {
59 $hash{'freq'} = { op=>'!=', value=>'0' };
60 $extra_count = " freq != '0' ";
64 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
66 push @where, $classnum ? "classnum = $classnum"
69 $cgi->delete('classnum');
71 if ( $cgi->param('missing_recur_fee') ) {
72 push @where, "0 = ( SELECT COUNT(*) FROM part_pkg_option
73 WHERE optionname = 'recur_fee'
74 AND part_pkg_option.pkgpart = part_pkg.pkgpart
75 AND CAST ( optionvalue AS NUMERIC ) > 0
79 push @where, FS::part_pkg->curuser_pkgs_sql
80 unless $acl_edit_global;
82 my $extra_sql = scalar(@where)
83 ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
87 my $agentnums = join(',', $curuser->agentnums);
88 my $count_cust_pkg = "
89 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
90 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
91 AND cust_main.agentnum IN ($agentnums)
99 AND ( cancel IS NULL OR cancel = 0 )
100 AND ( susp IS NULL OR susp = 0 )
104 AND ( cancel IS NULL OR cancel = 0 )
105 AND susp IS NOT NULL AND susp != 0
109 AND cancel IS NOT NULL AND cancel != 0
115 #unless ( $cgi->param('active') ) {
117 One or more service definitions are grouped together into a package
118 definition and given pricing information. Customers purchase packages
119 rather than purchase services directly.<BR><BR>
120 <FORM METHOD="POST" ACTION="${p}edit/part_pkg.cgi">
121 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
123 !.include('/elements/select-part_pkg.html', 'element_name' => 'clone' ). qq!
124 <INPUT TYPE="submit" VALUE="Clone existing package">
130 $cgi->param('dummy', 1);
133 qq(\n<SCRIPT TYPE="text/javascript">\n).
134 "function filter_change() {".
135 " window.location = '". $cgi->self_url.
136 ";classnum=' + document.getElementById('classnum').options[document.getElementById('classnum').selectedIndex].value".
140 #restore this so pagination works
141 $cgi->param('classnum', $classnum) if length($classnum);
144 "$filter_change\n<BR>( show class: ".
145 include('/elements/select-pkg_class.html',
146 #'curr_value' => $classnum,
147 'value' => $classnum, #insist on 0 :/
148 'onchange' => 'filter_change()',
149 'pre_options' => [ '-1' => 'all',
151 'disable_empty' => 1,
155 my $recur_toggle = $cgi->param('recurring') ? 'show' : 'hide';
156 $cgi->param('recurring', $cgi->param('recurring') ^ 1 );
159 '( <A HREF="'. $cgi->self_url.'">'. "$recur_toggle one-time charges</A> )";
161 $cgi->param('recurring', $cgi->param('recurring') ^ 1 ); #put it back
165 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
167 my @header = ( '#', 'Package', 'Comment' );
168 my @fields = ( 'pkgpart', 'pkg', 'comment' );
170 my @links = ( $link, $link, '' );
172 unless ( 0 ) { #already showing only one class or something?
173 push @header, 'Class';
174 push @fields, sub { shift->classname || '(none)'; };
178 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
180 tie my %plan_labels, 'Tie::IxHash',
181 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
184 push @header, 'Pricing';
187 my $part_pkg = shift;
188 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
189 my $is_recur = ( $part_pkg->freq ne '0' );
199 { data =>$money_char.
200 sprintf('%.2f', $part_pkg->option('setup_fee') ),
203 { data => ( $is_recur ? ' setup' : ' one-time' ),
209 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
210 : $part_pkg->freq_pretty
212 align=> ( $is_recur ? 'right' : 'center' ),
213 colspan=> ( $is_recur ? 1 : 2 ),
216 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
223 my $dst_pkg = $_->dst_pkg;
225 { data => 'Add-on: '.$dst_pkg->pkg_comment,
231 $part_pkg->bill_part_pkg_link
235 # $plan_labels{$part_pkg->plan}.'<BR>'.
236 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
237 # ( $part_pkg->freq ne '0'
238 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
241 # $part_pkg->freq_pretty; #.'<BR>'
245 # Agent goes here if displayed
249 if ( $acl_edit_global ) {
250 #really we just want a count, but this is fine unless someone has tons
251 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
252 if ( scalar(@all_agent_types) > 1 ) {
253 push @header, 'Agent types';
254 my $typelink = $p. 'edit/agent_type.cgi?';
255 push @fields, sub { my $part_pkg = shift;
257 map { my $agent_type = $_->agent_type;
259 { 'data' => $agent_type->atype, #escape?
261 'link' => ( $acl_config
276 #if ( $cgi->param('active') ) {
277 push @header, 'Customer<BR>packages';
279 'active' => '00CC00',
280 'suspended' => 'FF9900',
281 'cancelled' => 'FF0000',
282 #'one-time charge' => '000000',
283 'charge' => '000000',
285 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
286 push @fields, sub { my $part_pkg = shift;
291 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
293 #$label = 'one-time charge',
299 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
300 $part_pkg->get("num_$_").
306 ( $part_pkg->get("num_$_") != 1
307 && $label =~ /charge$/
312 'link' => ( $part_pkg->get("num_$_")
320 } (qw( active suspended cancelled ))
326 push @header, 'Taxclass';
327 push @fields, sub { shift->taxclass() || ' '; };
331 push @header, 'Plan options',
333 #'Service', 'Quan', 'Primary';
337 my $part_pkg = shift;
338 if ( $part_pkg->plan ) {
340 my %options = $part_pkg->options;
347 { 'data' => $part_pkg->format($_,$options{$_}),
352 grep { $options{$_} =~ /\S/ }
353 grep { $_ !~ /^(setup|recur)_fee$/ }
364 'data' => $part_pkg->$_(),
377 my $part_pkg = shift;
382 my $part_svc = $pkg_svc->part_svc;
383 my $svc = $part_svc->svc;
384 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
385 $svc = "<B>$svc (PRIMARY)</B>";
387 $svc =~ s/ +/ /g;
391 'data' => '<B>'. $pkg_svc->quantity. '</B>',
397 'link' => ( $acl_config
398 ? $p. 'edit/part_svc.cgi?'.
405 sort { $b->primary_svc =~ /^Y/i
406 <=> $a->primary_svc =~ /^Y/i
408 $part_pkg->pkg_svc('disable_linked'=>1)
411 my $dst_pkg = $_->dst_pkg;
413 { data => 'Add-on: '.$dst_pkg->pkg_comment,
419 $part_pkg->svc_part_pkg_link
425 $align .= 'lrl'; #rr';
429 my $count_extra_sql = $extra_sql;
430 $count_extra_sql =~ s/^\s*AND /WHERE /i;
431 $extra_count = ( $count_extra_sql ? ' AND ' : ' WHERE ' ). $extra_count
433 my $count_query = "SELECT COUNT(*) FROM part_pkg $count_extra_sql $extra_count";