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 unless ( $acl_edit_global ) {
50 $extra_sql .= ' WHERE '. FS::part_pkg->curuser_pkgs_sql;
53 my $agentnums = join(',', $curuser->agentnums);
54 my $count_cust_pkg = "
55 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
56 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
57 AND cust_main.agentnum IN ($agentnums)
65 AND ( cancel IS NULL OR cancel = 0 )
66 AND ( susp IS NULL OR susp = 0 )
70 AND ( cancel IS NULL OR cancel = 0 )
71 AND susp IS NOT NULL AND susp != 0
75 AND cancel IS NOT NULL AND cancel != 0
81 #unless ( $cgi->param('active') ) {
83 One or more service definitions are grouped together into a package
84 definition and given pricing information. Customers purchase packages
85 rather than purchase services directly.<BR><BR>
86 <FORM METHOD="POST" ACTION="${p}edit/part_pkg.cgi">
87 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
89 !.include('/elements/select-part_pkg.html', 'element_name' => 'clone' ). qq!
90 <INPUT TYPE="submit" VALUE="Clone existing package">
98 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
100 my @header = ( '#', 'Package', 'Comment' );
101 my @fields = ( 'pkgpart', 'pkg', 'comment' );
103 my @links = ( $link, $link, '' );
105 unless ( 0 ) { #already showing only one class or something?
106 push @header, 'Class';
107 push @fields, sub { shift->classname || '(none)'; };
111 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
113 tie my %plan_labels, 'Tie::IxHash',
114 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
117 push @header, 'Pricing';
120 my $part_pkg = shift;
121 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
122 my $is_recur = ( $part_pkg->freq ne '0' );
132 { data =>$money_char.
133 sprintf('%.2f', $part_pkg->option('setup_fee') ),
136 { data => ( $is_recur ? ' setup' : ' one-time' ),
142 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
143 : $part_pkg->freq_pretty
145 align=> ( $is_recur ? 'right' : 'center' ),
146 colspan=> ( $is_recur ? 1 : 2 ),
149 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
156 my $dst_pkg = $_->dst_pkg;
158 { data => 'Add-on: '.$dst_pkg->pkg_comment,
164 $part_pkg->bill_part_pkg_link
168 # $plan_labels{$part_pkg->plan}.'<BR>'.
169 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
170 # ( $part_pkg->freq ne '0'
171 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
174 # $part_pkg->freq_pretty; #.'<BR>'
177 #if ( $cgi->param('active') ) {
178 push @header, 'Customer<BR>packages';
180 'active' => '00CC00',
181 'suspended' => 'FF9900',
182 'cancelled' => 'FF0000',
183 #'one-time charge' => '000000',
184 'charge' => '000000',
186 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
187 push @fields, sub { my $part_pkg = shift;
192 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
194 #$label = 'one-time charge',
200 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
201 $part_pkg->get("num_$_").
207 ( $part_pkg->get("num_$_") != 1
208 && $label =~ /charge$/
213 'link' => ( $part_pkg->get("num_$_")
221 } (qw( active suspended cancelled ))
227 push @header, 'Taxclass';
228 push @fields, sub { shift->taxclass() || ' '; };
232 push @header, 'Plan options',
234 #'Service', 'Quan', 'Primary';
238 my $part_pkg = shift;
239 if ( $part_pkg->plan ) {
241 my %options = $part_pkg->options;
248 { 'data' => $part_pkg->format($_,$options{$_}),
253 grep { $options{$_} =~ /\S/ }
254 grep { $_ !~ /^(setup|recur)_fee$/ }
265 'data' => $part_pkg->$_(),
278 my $part_pkg = shift;
283 my $part_svc = $pkg_svc->part_svc;
284 my $svc = $part_svc->svc;
285 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
286 $svc = "<B>$svc (PRIMARY)</B>";
288 $svc =~ s/ +/ /g;
292 'data' => '<B>'. $pkg_svc->quantity. '</B>',
298 'link' => ( $acl_config
299 ? $p. 'edit/part_svc.cgi?'.
306 sort { $b->primary_svc =~ /^Y/i
307 <=> $a->primary_svc =~ /^Y/i
309 $part_pkg->pkg_svc('disable_linked'=>1)
312 my $dst_pkg = $_->dst_pkg;
314 { data => 'Add-on: '.$dst_pkg->pkg_comment,
320 $part_pkg->svc_part_pkg_link
326 $align .= 'lrl'; #rr';
330 my $count_query = "SELECT COUNT(*) FROM part_pkg $extra_sql";