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';
49 if ( $cgi->param('active') ) {
50 $orderby = 'num_active DESC';
55 #if ( $cgi->param('activeONLY') ) {
56 # push @where, ' WHERE num_active > 0 '; #XXX doesn't affect count...
59 if ( $cgi->param('recurring') ) {
60 $hash{'freq'} = { op=>'!=', value=>'0' };
61 $extra_count = " freq != '0' ";
65 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
67 push @where, $classnum ? "classnum = $classnum"
70 $cgi->delete('classnum');
72 if ( $cgi->param('missing_recur_fee') ) {
73 push @where, "0 = ( SELECT COUNT(*) FROM part_pkg_option
74 WHERE optionname = 'recur_fee'
75 AND part_pkg_option.pkgpart = part_pkg.pkgpart
76 AND CAST ( optionvalue AS NUMERIC ) > 0
80 push @where, FS::part_pkg->curuser_pkgs_sql
81 unless $acl_edit_global;
83 my $extra_sql = scalar(@where)
84 ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
88 my $agentnums_sql = $curuser->agentnums_sql( 'table'=>'cust_main' );
89 my $count_cust_pkg = "
90 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
91 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
100 AND ( setup IS NULL OR setup = 0 )
101 AND ( cancel IS NULL OR cancel = 0 )
102 AND ( susp IS NULL OR susp = 0 )
103 ) AS num_not_yet_billed,
106 AND setup IS NOT NULL AND setup != 0
107 AND ( cancel IS NULL OR cancel = 0 )
108 AND ( susp IS NULL OR susp = 0 )
112 AND ( cancel IS NULL OR cancel = 0 )
113 AND susp IS NOT NULL AND susp != 0
117 AND cancel IS NOT NULL AND cancel != 0
123 #unless ( $cgi->param('active') ) {
125 One or more service definitions are grouped together into a package
126 definition and given pricing information. Customers purchase packages
127 rather than purchase services directly.<BR><BR>
128 <FORM METHOD="POST" ACTION="${p}edit/part_pkg.cgi">
129 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
131 !.include('/elements/select-part_pkg.html', 'element_name' => 'clone' ). qq!
132 <INPUT TYPE="submit" VALUE="Clone existing package">
138 $cgi->param('dummy', 1);
141 qq(\n<SCRIPT TYPE="text/javascript">\n).
142 "function filter_change() {".
143 " window.location = '". $cgi->self_url.
144 ";classnum=' + document.getElementById('classnum').options[document.getElementById('classnum').selectedIndex].value".
148 #restore this so pagination works
149 $cgi->param('classnum', $classnum) if length($classnum);
152 "$filter_change\n<BR>( show class: ".
153 include('/elements/select-pkg_class.html',
154 #'curr_value' => $classnum,
155 'value' => $classnum, #insist on 0 :/
156 'onchange' => 'filter_change()',
157 'pre_options' => [ '-1' => 'all',
159 'disable_empty' => 1,
163 my $recur_toggle = $cgi->param('recurring') ? 'show' : 'hide';
164 $cgi->param('recurring', $cgi->param('recurring') ^ 1 );
167 '( <A HREF="'. $cgi->self_url.'">'. "$recur_toggle one-time charges</A> )";
169 $cgi->param('recurring', $cgi->param('recurring') ^ 1 ); #put it back
173 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
175 my @header = ( '#', 'Package', 'Comment', 'Custom' );
176 my @fields = ( 'pkgpart', 'pkg', 'comment',
177 sub{ '<B><FONT COLOR="#0000CC">'.$_[0]->custom.'</FONT></B>' }
180 my @links = ( $link, $link, '', '' );
182 unless ( 0 ) { #already showing only one class or something?
183 push @header, 'Class';
184 push @fields, sub { shift->classname || '(none)'; };
188 if ( $conf->exists('pkg-addon_classnum') ) {
189 push @header, "Add'l order class";
190 push @fields, sub { shift->addon_classname || '(none)'; };
194 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
196 tie my %plan_labels, 'Tie::IxHash',
197 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
200 push @header, 'Pricing';
203 my $part_pkg = shift;
204 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
205 my $is_recur = ( $part_pkg->freq ne '0' );
206 my @discounts = sort { $a->months <=> $b->months }
208 $part_pkg->part_pkg_discount;
218 { data =>$money_char.
219 sprintf('%.2f', $part_pkg->option('setup_fee') ),
222 { data => ( $is_recur ? ' setup' : ' one-time' ),
228 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
229 : $part_pkg->freq_pretty
231 align=> ( $is_recur ? 'right' : 'center' ),
232 colspan=> ( $is_recur ? 1 : 2 ),
235 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
242 my $dst_pkg = $_->dst_pkg;
244 { data => 'Add-on: '.$dst_pkg->pkg_comment,
250 $part_pkg->bill_part_pkg_link
254 { data => '<b>Discounts</b>',
264 { data => $_->months. ':',
267 { data => $_->amount ? '$'. $_->amount : $_->percent. '%'
276 # $plan_labels{$part_pkg->plan}.'<BR>'.
277 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
278 # ( $part_pkg->freq ne '0'
279 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
282 # $part_pkg->freq_pretty; #.'<BR>'
286 # Agent goes here if displayed
290 if ( $acl_edit_global ) {
291 #really we just want a count, but this is fine unless someone has tons
292 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
293 if ( scalar(@all_agent_types) > 1 ) {
294 push @header, 'Agent types';
295 my $typelink = $p. 'edit/agent_type.cgi?';
296 push @fields, sub { my $part_pkg = shift;
298 map { my $agent_type = $_->agent_type;
300 { 'data' => $agent_type->atype, #escape?
302 'link' => ( $acl_config
317 #if ( $cgi->param('active') ) {
318 push @header, 'Customer<BR>packages';
320 'not yet billed' => '009999', #teal? cyan?
321 'active' => '00CC00',
322 'suspended' => 'FF9900',
323 'cancelled' => 'FF0000',
324 #'one-time charge' => '000000',
325 'charge' => '000000',
327 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
328 push @fields, sub { my $part_pkg = shift;
333 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
335 #$label = 'one-time charge',
338 $label= 'not yet billed' if $magic eq 'not_yet_billed';
342 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
343 $part_pkg->get("num_$_").
349 ( $part_pkg->get("num_$_") != 1
350 && $label =~ /charge$/
355 'link' => ( $part_pkg->get("num_$_")
363 } (qw( not_yet_billed active suspended cancelled ))
367 { 'data' => '<FONT SIZE="-1">[ '.
368 include('/elements/popup_link.html',
370 'action' => "${p}edit/bulk-cust_pkg.html?".
371 'pkgpart='.$part_pkg->pkgpart,
372 'actionlabel' => 'Change Packages',
385 push @header, 'Taxclass';
386 push @fields, sub { shift->taxclass() || ' '; };
390 push @header, 'Plan options',
392 #'Service', 'Quan', 'Primary';
396 my $part_pkg = shift;
397 if ( $part_pkg->plan ) {
399 my %options = $part_pkg->options;
406 { 'data' => $part_pkg->format($_,$options{$_}),
411 grep { $options{$_} =~ /\S/ }
412 grep { $_ !~ /^(setup|recur)_fee$/ }
423 'data' => $part_pkg->$_(),
436 my $part_pkg = shift;
441 my $part_svc = $pkg_svc->part_svc;
442 my $svc = $part_svc->svc;
443 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
444 $svc = "<B>$svc (PRIMARY)</B>";
446 $svc =~ s/ +/ /g;
450 'data' => '<B>'. $pkg_svc->quantity. '</B>',
456 'link' => ( $acl_config
457 ? $p. 'edit/part_svc.cgi?'.
464 sort { $b->primary_svc =~ /^Y/i
465 <=> $a->primary_svc =~ /^Y/i
467 $part_pkg->pkg_svc('disable_linked'=>1)
470 my $dst_pkg = $_->dst_pkg;
472 { data => 'Add-on: '.$dst_pkg->pkg_comment,
478 $part_pkg->svc_part_pkg_link
484 $align .= 'lrl'; #rr';
488 my $count_extra_sql = $extra_sql;
489 $count_extra_sql =~ s/^\s*AND /WHERE /i;
490 $extra_count = ( $count_extra_sql ? ' AND ' : ' WHERE ' ). $extra_count
492 my $count_query = "SELECT COUNT(*) FROM part_pkg $count_extra_sql $extra_count";