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' => 4,
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
38 unless $acl_edit || $acl_edit_global;
40 my $conf = new FS::Conf;
41 my $taxclasses = $conf->exists('enable_taxclasses');
42 my $money_char = $conf->config('money_char') || '$';
45 my $orderby = 'pkgpart';
50 if ( $cgi->param('active') ) {
51 $orderby = 'num_active DESC';
56 #if ( $cgi->param('activeONLY') ) {
57 # push @where, ' WHERE num_active > 0 '; #XXX doesn't affect count...
60 if ( $cgi->param('recurring') ) {
61 $hash{'freq'} = { op=>'!=', value=>'0' };
62 $extra_count = " freq != '0' ";
66 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
68 push @where, $classnum ? "classnum = $classnum"
71 $cgi->delete('classnum');
73 if ( $cgi->param('missing_recur_fee') ) {
74 push @where, "0 = ( SELECT COUNT(*) FROM part_pkg_option
75 WHERE optionname = 'recur_fee'
76 AND part_pkg_option.pkgpart = part_pkg.pkgpart
77 AND CAST( optionvalue AS NUMERIC ) > 0
81 if ( $cgi->param('family') =~ /^(\d+)$/ ) {
83 push @where, "family_pkgpart = $1";
84 # Hiding disabled or one-time charges and limiting by classnum aren't
85 # very useful in this mode, so all links should still refer back to the
86 # non-family-limited display.
87 $cgi->param('showdisabled', 1);
88 $cgi->delete('family');
91 push @where, FS::part_pkg->curuser_pkgs_sql
92 unless $acl_edit_global;
94 my $extra_sql = scalar(@where)
95 ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
99 my $agentnums_sql = $curuser->agentnums_sql( 'table'=>'cust_main' );
100 my $count_cust_pkg = "
101 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
102 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
111 AND ( setup IS NULL OR setup = 0 )
112 AND ( cancel IS NULL OR cancel = 0 )
113 AND ( susp IS NULL OR susp = 0 )
114 ) AS num_not_yet_billed,
117 AND setup IS NOT NULL AND setup != 0
118 AND ( cancel IS NULL OR cancel = 0 )
119 AND ( susp IS NULL OR susp = 0 )
123 AND ( cancel IS NULL OR cancel = 0 )
124 AND susp IS NOT NULL AND susp != 0
128 AND cancel IS NOT NULL AND cancel != 0
134 #unless ( $cgi->param('active') ) {
136 One or more service definitions are grouped together into a package
137 definition and given pricing information. Customers purchase packages
138 rather than purchase services directly.<BR><BR>
139 <FORM METHOD="GET" ACTION="${p}edit/part_pkg.cgi">
140 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
142 !.include('/elements/select-part_pkg.html', 'element_name' => 'clone' ). qq!
143 <INPUT TYPE="submit" VALUE="Clone existing package">
149 $cgi->param('dummy', 1);
152 qq(\n<SCRIPT TYPE="text/javascript">\n).
153 "function filter_change() {".
154 " window.location = '". $cgi->self_url.
155 ";classnum=' + document.getElementById('classnum').options[document.getElementById('classnum').selectedIndex].value".
159 #restore this so pagination works
160 $cgi->param('classnum', $classnum) if length($classnum);
162 #should hide this if there aren't any classes
164 "$filter_change\n<BR>( show class: ".
165 include('/elements/select-pkg_class.html',
166 #'curr_value' => $classnum,
167 'value' => $classnum, #insist on 0 :/
168 'onchange' => 'filter_change()',
169 'pre_options' => [ '-1' => 'all',
171 'disable_empty' => 1,
175 my $recur_toggle = $cgi->param('recurring') ? 'show' : 'hide';
176 $cgi->param('recurring', $cgi->param('recurring') ^ 1 );
179 '( <A HREF="'. $cgi->self_url.'">'. "$recur_toggle one-time charges</A> )";
181 $cgi->param('recurring', $cgi->param('recurring') ^ 1 ); #put it back
185 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
187 my @header = ( '#', 'Package', 'Comment', 'Custom' );
188 my @fields = ( 'pkgpart', 'pkg', 'comment',
189 sub{ '<B><FONT COLOR="#0000CC">'.$_[0]->custom.'</FONT></B>' }
192 my @links = ( $link, $link, '', '' );
194 unless ( 0 ) { #already showing only one class or something?
195 push @header, 'Class';
196 push @fields, sub { shift->classname || '(none)'; };
200 if ( $conf->exists('pkg-addon_classnum') ) {
201 push @header, "Add'l order class";
202 push @fields, sub { shift->addon_classname || '(none)'; };
206 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
208 tie my %plan_labels, 'Tie::IxHash',
209 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
212 push @header, 'Pricing';
215 my $part_pkg = shift;
216 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
217 my $is_recur = ( $part_pkg->freq ne '0' );
218 my @discounts = sort { $a->months <=> $b->months }
220 $part_pkg->part_pkg_discount;
223 ( !$family_pkgpart &&
224 $part_pkg->pkgpart == $part_pkg->family_pkgpart ? () : [
229 'data' => '<b>Show all versions</b>',
230 'link' => $p.'browse/part_pkg.cgi?family='.$part_pkg->family_pkgpart,
240 { data =>$money_char.
241 sprintf('%.2f', $part_pkg->option('setup_fee') ),
244 { data => ( ( $is_recur ? ' setup' : ' one-time' ).
245 ( $part_pkg->option('recur_fee') == 0
246 && $part_pkg->setup_show_zero
247 ? ' (printed on invoices)'
257 ? $money_char. sprintf('%.2f ', $part_pkg->option('recur_fee'))
258 : $part_pkg->freq_pretty
260 align=> ( $is_recur ? 'right' : 'center' ),
261 colspan=> ( $is_recur ? 1 : 2 ),
264 ? { data => ( $is_recur
265 ? $part_pkg->freq_pretty.
266 ( $part_pkg->option('recur_fee') == 0
267 && $part_pkg->recur_show_zero
268 ? ' (printed on invoices)'
278 my $dst_pkg = $_->dst_pkg;
280 { data => 'Add-on: '.$dst_pkg->pkg_comment,
286 $part_pkg->bill_part_pkg_link
290 { data => '<b>Discounts</b>',
300 { data => $_->months. ':',
303 { data => $_->amount ? '$'. $_->amount : $_->percent. '%'
312 # $plan_labels{$part_pkg->plan}.'<BR>'.
313 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
314 # ( $part_pkg->freq ne '0'
315 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
318 # $part_pkg->freq_pretty; #.'<BR>'
322 # Agent goes here if displayed
326 if ( $acl_edit_global ) {
327 #really we just want a count, but this is fine unless someone has tons
328 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
329 if ( scalar(@all_agent_types) > 1 ) {
330 push @header, 'Agent types';
331 my $typelink = $p. 'edit/agent_type.cgi?';
332 push @fields, sub { my $part_pkg = shift;
334 map { my $agent_type = $_->agent_type;
336 { 'data' => $agent_type->atype, #escape?
338 'link' => ( $acl_config
353 #if ( $cgi->param('active') ) {
354 push @header, 'Customer<BR>packages';
356 'not yet billed' => '009999', #teal? cyan?
357 'active' => '00CC00',
358 'suspended' => 'FF9900',
359 'cancelled' => 'FF0000',
360 #'one-time charge' => '000000',
361 'charge' => '000000',
363 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
364 push @fields, sub { my $part_pkg = shift;
369 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
371 #$label = 'one-time charge',
374 $label= 'not yet billed' if $magic eq 'not_yet_billed';
378 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
379 $part_pkg->get("num_$_").
385 ( $part_pkg->get("num_$_") != 1
386 && $label =~ /charge$/
391 'link' => ( $part_pkg->get("num_$_")
399 } (qw( not_yet_billed active suspended cancelled ))
403 { 'data' => '<FONT SIZE="-1">[ '.
404 include('/elements/popup_link.html',
406 'action' => "${p}edit/bulk-cust_pkg.html?".
407 'pkgpart='.$part_pkg->pkgpart,
408 'actionlabel' => 'Change Packages',
421 push @header, 'Taxclass';
422 push @fields, sub { shift->taxclass() || ' '; };
426 push @header, 'Plan options',
428 #'Service', 'Quan', 'Primary';
432 my $part_pkg = shift;
433 if ( $part_pkg->plan ) {
435 my %options = $part_pkg->options;
442 { 'data' => $part_pkg->format($_,$options{$_}),
447 grep { $options{$_} =~ /\S/ }
448 grep { $_ !~ /^(setup|recur)_fee$/ }
459 'data' => $part_pkg->$_(),
472 my $part_pkg = shift;
477 my $part_svc = $pkg_svc->part_svc;
478 my $svc = $part_svc->svc;
479 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
480 $svc = "<B>$svc (PRIMARY)</B>";
482 $svc =~ s/ +/ /g;
486 'data' => '<B>'. $pkg_svc->quantity. '</B>',
492 'link' => ( $acl_config
493 ? $p. 'edit/part_svc.cgi?'.
500 sort { $b->primary_svc =~ /^Y/i
501 <=> $a->primary_svc =~ /^Y/i
503 $part_pkg->pkg_svc('disable_linked'=>1)
506 my $dst_pkg = $_->dst_pkg;
508 { data => 'Add-on: '.$dst_pkg->pkg_comment,
514 $part_pkg->svc_part_pkg_link
520 $align .= 'lrl'; #rr';
524 my $count_extra_sql = $extra_sql;
525 $count_extra_sql =~ s/^\s*AND /WHERE /i;
526 $extra_count = ( $count_extra_sql ? ' AND ' : ' WHERE ' ). $extra_count
528 my $count_query = "SELECT COUNT(*) FROM part_pkg $count_extra_sql $extra_count";