1 <% include( 'elements/browse.html',
2 'title' => 'Package Definitions',
3 'html_init' => $html_init,
4 'name' => 'package definitions',
6 'disabled_statuspos' => 3,
8 'agent_null_right' => [ $edit, $edit_global ],
9 'agent_null_right_link' => $edit_global,
11 'query' => { 'select' => $select,
12 'table' => 'part_pkg',
14 'extra_sql' => $extra_sql,
15 'order_by' => "ORDER BY $orderby"
17 'count_query' => $count_query,
26 my $curuser = $FS::CurrentUser::CurrentUser;
28 my $edit = 'Edit package definitions';
29 my $edit_global = 'Edit global package definitions';
30 my $acl_edit = $curuser->access_right($edit);
31 my $acl_edit_global = $curuser->access_right($edit_global);
32 my $acl_config = $curuser->access_right('Configuration'); #to edit services
35 unless $acl_edit || $acl_edit_global;
37 my $conf = new FS::Conf;
38 my $taxclasses = $conf->exists('enable_taxclasses');
39 my $money_char = $conf->config('money_char') || '$';
42 my $orderby = 'pkgpart';
43 if ( $cgi->param('active') ) {
44 $orderby = 'num_active DESC';
49 #false laziness w/elements/select-part_pkg.html
50 my $agentnums = join(',', $curuser->agentnums);
52 unless ( $acl_edit_global ) {
55 agentnum IS NOT NULL OR 0 < (
58 LEFT JOIN agent_type USING ( typenum )
59 LEFT JOIN agent AS typeagent USING ( typenum )
60 WHERE type_pkgs.pkgpart = part_pkg.pkgpart
61 AND typeagent.agentnum IN ($agentnums)
68 my $count_cust_pkg = "
69 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
70 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
71 AND cust_main.agentnum IN ($agentnums)
79 AND ( cancel IS NULL OR cancel = 0 )
80 AND ( susp IS NULL OR susp = 0 )
84 AND ( cancel IS NULL OR cancel = 0 )
85 AND susp IS NOT NULL AND susp != 0
89 AND cancel IS NOT NULL AND cancel != 0
95 #unless ( $cgi->param('active') ) {
97 One or more service definitions are grouped together into a package
98 definition and given pricing information. Customers purchase packages
99 rather than purchase services directly.<BR><BR>
100 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
107 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
109 my @header = ( '#', 'Package', 'Comment' );
110 my @fields = ( 'pkgpart', 'pkg', 'comment' );
112 my @links = ( $link, $link, '' );
114 unless ( 0 ) { #already showing only one class or something?
115 push @header, 'Class';
116 push @fields, sub { shift->classname || '(none)'; };
120 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
122 tie my %plan_labels, 'Tie::IxHash',
123 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
126 push @header, 'Pricing';
129 my $part_pkg = shift;
130 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
131 my $is_recur = ( $part_pkg->freq ne '0' );
141 { data =>$money_char.
142 sprintf('%.2f', $part_pkg->option('setup_fee') ),
145 { data => ( $is_recur ? ' setup' : ' one-time' ),
151 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
152 : $part_pkg->freq_pretty
154 align=> ( $is_recur ? 'right' : 'center' ),
155 colspan=> ( $is_recur ? 1 : 2 ),
158 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
165 my $dst_pkg = $_->dst_pkg;
167 { data => 'Add-on: '.$dst_pkg->pkg_comment,
173 $part_pkg->bill_part_pkg_link
177 # $plan_labels{$part_pkg->plan}.'<BR>'.
178 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
179 # ( $part_pkg->freq ne '0'
180 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
183 # $part_pkg->freq_pretty; #.'<BR>'
186 #if ( $cgi->param('active') ) {
187 push @header, 'Customer<BR>packages';
189 'active' => '00CC00',
190 'suspended' => 'FF9900',
191 'cancelled' => 'FF0000',
192 #'one-time charge' => '000000',
193 'charge' => '000000',
195 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
196 push @fields, sub { my $part_pkg = shift;
201 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
203 #$label = 'one-time charge',
209 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
210 $part_pkg->get("num_$_").
216 ( $part_pkg->get("num_$_") != 1
217 && $label =~ /charge$/
222 'link' => ( $part_pkg->get("num_$_")
230 } (qw( active suspended cancelled ))
236 push @header, 'Taxclass';
237 push @fields, sub { shift->taxclass() || ' '; };
241 push @header, 'Plan options',
243 #'Service', 'Quan', 'Primary';
247 my $part_pkg = shift;
248 if ( $part_pkg->plan ) {
250 my %options = $part_pkg->options;
257 { 'data' => $part_pkg->format($_,$options{$_}),
262 grep { $options{$_} =~ /\S/ }
263 grep { $_ !~ /^(setup|recur)_fee$/ }
274 'data' => $part_pkg->$_(),
287 my $part_pkg = shift;
292 my $part_svc = $pkg_svc->part_svc;
293 my $svc = $part_svc->svc;
294 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
295 $svc = "<B>$svc (PRIMARY)</B>";
297 $svc =~ s/ +/ /g;
301 'data' => '<B>'. $pkg_svc->quantity. '</B>',
307 'link' => ( $acl_config
308 ? $p. 'edit/part_svc.cgi?'.
315 sort { $b->primary_svc =~ /^Y/i
316 <=> $a->primary_svc =~ /^Y/i
318 $part_pkg->pkg_svc('disable_linked'=>1)
321 my $dst_pkg = $_->dst_pkg;
323 { data => 'Add-on: '.$dst_pkg->pkg_comment,
329 $part_pkg->svc_part_pkg_link
335 $align .= 'lrl'; #rr';
339 my $count_query = "SELECT COUNT(*) FROM part_pkg $extra_sql";