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
36 unless $acl_edit || $acl_edit_global;
38 my $conf = new FS::Conf;
39 my $taxclasses = $conf->exists('enable_taxclasses');
40 my $money_char = $conf->config('money_char') || '$';
43 my $orderby = 'pkgpart';
44 if ( $cgi->param('active') ) {
45 $orderby = 'num_active DESC';
50 unless ( $acl_edit_global ) {
51 $extra_sql .= ' WHERE '. FS::part_pkg->curuser_pkgs_sql;
54 my $agentnums = join(',', $curuser->agentnums);
55 my $count_cust_pkg = "
56 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
57 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
58 AND cust_main.agentnum IN ($agentnums)
66 AND ( cancel IS NULL OR cancel = 0 )
67 AND ( susp IS NULL OR susp = 0 )
71 AND ( cancel IS NULL OR cancel = 0 )
72 AND susp IS NOT NULL AND susp != 0
76 AND cancel IS NOT NULL AND cancel != 0
82 #unless ( $cgi->param('active') ) {
84 One or more service definitions are grouped together into a package
85 definition and given pricing information. Customers purchase packages
86 rather than purchase services directly.<BR><BR>
87 <FORM METHOD="POST" ACTION="${p}edit/part_pkg.cgi">
88 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
90 !.include('/elements/select-part_pkg.html', 'element_name' => 'clone' ). qq!
91 <INPUT TYPE="submit" VALUE="Clone existing package">
99 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
101 my @header = ( '#', 'Package', 'Comment' );
102 my @fields = ( 'pkgpart', 'pkg', 'comment' );
104 my @links = ( $link, $link, '' );
106 unless ( 0 ) { #already showing only one class or something?
107 push @header, 'Class';
108 push @fields, sub { shift->classname || '(none)'; };
112 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
114 tie my %plan_labels, 'Tie::IxHash',
115 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
118 push @header, 'Pricing';
121 my $part_pkg = shift;
122 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
123 my $is_recur = ( $part_pkg->freq ne '0' );
133 { data =>$money_char.
134 sprintf('%.2f', $part_pkg->option('setup_fee') ),
137 { data => ( $is_recur ? ' setup' : ' one-time' ),
143 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
144 : $part_pkg->freq_pretty
146 align=> ( $is_recur ? 'right' : 'center' ),
147 colspan=> ( $is_recur ? 1 : 2 ),
150 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
157 my $dst_pkg = $_->dst_pkg;
159 { data => 'Add-on: '.$dst_pkg->pkg_comment,
165 $part_pkg->bill_part_pkg_link
169 # $plan_labels{$part_pkg->plan}.'<BR>'.
170 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
171 # ( $part_pkg->freq ne '0'
172 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
175 # $part_pkg->freq_pretty; #.'<BR>'
179 # Agent goes here if displayed
183 if ( $acl_edit_global ) {
184 #really we just want a count, but this is fine unless someone has tons
185 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
186 if ( scalar(@all_agent_types) > 1 ) {
187 push @header, 'Agent types';
188 my $typelink = $p. 'edit/agent_type.cgi?';
189 push @fields, sub { my $part_pkg = shift;
192 my $agent_type = $_->agent_type;
195 { 'data' => $agent_type->atype, #escape?
197 'link' => ( $acl_config
212 #if ( $cgi->param('active') ) {
213 push @header, 'Customer<BR>packages';
215 'active' => '00CC00',
216 'suspended' => 'FF9900',
217 'cancelled' => 'FF0000',
218 #'one-time charge' => '000000',
219 'charge' => '000000',
221 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
222 push @fields, sub { my $part_pkg = shift;
227 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
229 #$label = 'one-time charge',
235 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
236 $part_pkg->get("num_$_").
242 ( $part_pkg->get("num_$_") != 1
243 && $label =~ /charge$/
248 'link' => ( $part_pkg->get("num_$_")
256 } (qw( active suspended cancelled ))
262 push @header, 'Taxclass';
263 push @fields, sub { shift->taxclass() || ' '; };
267 push @header, 'Plan options',
269 #'Service', 'Quan', 'Primary';
273 my $part_pkg = shift;
274 if ( $part_pkg->plan ) {
276 my %options = $part_pkg->options;
283 { 'data' => $part_pkg->format($_,$options{$_}),
288 grep { $options{$_} =~ /\S/ }
289 grep { $_ !~ /^(setup|recur)_fee$/ }
300 'data' => $part_pkg->$_(),
313 my $part_pkg = shift;
318 my $part_svc = $pkg_svc->part_svc;
319 my $svc = $part_svc->svc;
320 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
321 $svc = "<B>$svc (PRIMARY)</B>";
323 $svc =~ s/ +/ /g;
327 'data' => '<B>'. $pkg_svc->quantity. '</B>',
333 'link' => ( $acl_config
334 ? $p. 'edit/part_svc.cgi?'.
341 sort { $b->primary_svc =~ /^Y/i
342 <=> $a->primary_svc =~ /^Y/i
344 $part_pkg->pkg_svc('disable_linked'=>1)
347 my $dst_pkg = $_->dst_pkg;
349 { data => 'Add-on: '.$dst_pkg->pkg_comment,
355 $part_pkg->svc_part_pkg_link
361 $align .= 'lrl'; #rr';
365 my $count_query = "SELECT COUNT(*) FROM part_pkg $extra_sql";