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 my $agentnums = join(',', $curuser->agentnums);
51 unless ( $acl_edit_global ) {
54 agentnum IS NOT NULL OR 0 < (
57 LEFT JOIN agent_type USING ( typenum )
58 LEFT JOIN agent AS typeagent USING ( typenum )
59 WHERE type_pkgs.pkgpart = part_pkg.pkgpart
60 AND typeagent.agentnum IN ($agentnums)
66 my $count_cust_pkg = "
67 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
68 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
69 AND cust_main.agentnum IN ($agentnums)
77 AND ( cancel IS NULL OR cancel = 0 )
78 AND ( susp IS NULL OR susp = 0 )
82 AND ( cancel IS NULL OR cancel = 0 )
83 AND susp IS NOT NULL AND susp != 0
87 AND cancel IS NOT NULL AND cancel != 0
93 #unless ( $cgi->param('active') ) {
95 One or more service definitions are grouped together into a package
96 definition and given pricing information. Customers purchase packages
97 rather than purchase services directly.<BR><BR>
98 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
105 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
107 my @header = ( '#', 'Package', 'Comment' );
108 my @fields = ( 'pkgpart', 'pkg', 'comment' );
110 my @links = ( $link, $link, '' );
112 unless ( 0 ) { #already showing only one class or something?
113 push @header, 'Class';
114 push @fields, sub { shift->classname || '(none)'; };
118 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
120 tie my %plan_labels, 'Tie::IxHash',
121 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
124 push @header, 'Pricing';
127 my $part_pkg = shift;
128 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
129 my $is_recur = ( $part_pkg->freq ne '0' );
139 { data =>$money_char.
140 sprintf('%.2f', $part_pkg->option('setup_fee') ),
143 { data => ( $is_recur ? ' setup' : ' one-time' ),
149 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
150 : $part_pkg->freq_pretty
152 align=> ( $is_recur ? 'right' : 'center' ),
153 colspan=> ( $is_recur ? 1 : 2 ),
156 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
163 my $dst_pkg = $_->dst_pkg;
165 { data => 'Add-on: '.$dst_pkg->pkg_comment,
171 $part_pkg->bill_part_pkg_link
175 # $plan_labels{$part_pkg->plan}.'<BR>'.
176 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
177 # ( $part_pkg->freq ne '0'
178 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
181 # $part_pkg->freq_pretty; #.'<BR>'
184 #if ( $cgi->param('active') ) {
185 push @header, 'Customer<BR>packages';
187 'active' => '00CC00',
188 'suspended' => 'FF9900',
189 'cancelled' => 'FF0000',
190 #'one-time charge' => '000000',
191 'charge' => '000000',
193 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
194 push @fields, sub { my $part_pkg = shift;
199 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
201 #$label = 'one-time charge',
207 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
208 $part_pkg->get("num_$_").
214 ( $part_pkg->get("num_$_") != 1
215 && $label =~ /charge$/
220 'link' => ( $part_pkg->get("num_$_")
228 } (qw( active suspended cancelled ))
234 push @header, 'Taxclass';
235 push @fields, sub { shift->taxclass() || ' '; };
239 push @header, 'Plan options',
241 #'Service', 'Quan', 'Primary';
245 my $part_pkg = shift;
246 if ( $part_pkg->plan ) {
248 my %options = $part_pkg->options;
255 { 'data' => $part_pkg->format($_,$options{$_}),
260 grep { $options{$_} =~ /\S/ }
261 grep { $_ !~ /^(setup|recur)_fee$/ }
272 'data' => $part_pkg->$_(),
285 my $part_pkg = shift;
290 my $part_svc = $pkg_svc->part_svc;
291 my $svc = $part_svc->svc;
292 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
293 $svc = "<B>$svc (PRIMARY)</B>";
295 $svc =~ s/ +/ /g;
299 'data' => '<B>'. $pkg_svc->quantity. '</B>',
305 'link' => ( $acl_config
306 ? $p. 'edit/part_svc.cgi?'.
313 sort { $b->primary_svc =~ /^Y/i
314 <=> $a->primary_svc =~ /^Y/i
316 $part_pkg->pkg_svc('disable_linked'=>1)
319 my $dst_pkg = $_->dst_pkg;
321 { data => 'Add-on: '.$dst_pkg->pkg_comment,
327 $part_pkg->svc_part_pkg_link
333 $align .= 'lrl'; #rr';
337 my $count_query = "SELECT COUNT(*) FROM part_pkg $extra_sql";