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';
47 if ( $cgi->param('active') ) {
48 $orderby = 'num_active DESC';
53 #if ( $cgi->param('activeONLY') ) {
54 # $extra_sql = ' WHERE num_active > 0 '; #XXX doesn't affect count...
57 if ( $cgi->param('recurring') ) {
58 $hash{'freq'} = { op=>'!=', value=>'0' };
59 $extra_count = ' freq != 0 ';
62 if ( $cgi->param('missing_recur_fee') ) {
63 my $missing = "0 = ( SELECT COUNT(*) FROM part_pkg_option
64 WHERE optionname = 'recur_fee'
65 AND part_pkg_option.pkgpart = part_pkg.pkgpart
66 AND CAST ( optionvalue AS NUMERIC ) > 0
68 $extra_sql .= ( ( scalar(keys %hash) || $extra_sql ) ? ' AND ' : ' WHERE ' ).
72 unless ( $acl_edit_global ) {
73 $extra_sql .= ( ( scalar(keys %hash) || $extra_sql ) ? ' AND ' : ' WHERE ' ).
74 FS::part_pkg->curuser_pkgs_sql;
77 my $agentnums = join(',', $curuser->agentnums);
78 my $count_cust_pkg = "
79 SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
80 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
81 AND cust_main.agentnum IN ($agentnums)
89 AND ( cancel IS NULL OR cancel = 0 )
90 AND ( susp IS NULL OR susp = 0 )
94 AND ( cancel IS NULL OR cancel = 0 )
95 AND susp IS NOT NULL AND susp != 0
99 AND cancel IS NOT NULL AND cancel != 0
105 #unless ( $cgi->param('active') ) {
107 One or more service definitions are grouped together into a package
108 definition and given pricing information. Customers purchase packages
109 rather than purchase services directly.<BR><BR>
110 <FORM METHOD="POST" ACTION="${p}edit/part_pkg.cgi">
111 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
113 !.include('/elements/select-part_pkg.html', 'element_name' => 'clone' ). qq!
114 <INPUT TYPE="submit" VALUE="Clone existing package">
122 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
124 my @header = ( '#', 'Package', 'Comment' );
125 my @fields = ( 'pkgpart', 'pkg', 'comment' );
127 my @links = ( $link, $link, '' );
129 unless ( 0 ) { #already showing only one class or something?
130 push @header, 'Class';
131 push @fields, sub { shift->classname || '(none)'; };
135 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
137 tie my %plan_labels, 'Tie::IxHash',
138 map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
141 push @header, 'Pricing';
144 my $part_pkg = shift;
145 (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
146 my $is_recur = ( $part_pkg->freq ne '0' );
156 { data =>$money_char.
157 sprintf('%.2f', $part_pkg->option('setup_fee') ),
160 { data => ( $is_recur ? ' setup' : ' one-time' ),
166 ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
167 : $part_pkg->freq_pretty
169 align=> ( $is_recur ? 'right' : 'center' ),
170 colspan=> ( $is_recur ? 1 : 2 ),
173 ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
180 my $dst_pkg = $_->dst_pkg;
182 { data => 'Add-on: '.$dst_pkg->pkg_comment,
188 $part_pkg->bill_part_pkg_link
192 # $plan_labels{$part_pkg->plan}.'<BR>'.
193 # $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
194 # ( $part_pkg->freq ne '0'
195 # ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
198 # $part_pkg->freq_pretty; #.'<BR>'
202 # Agent goes here if displayed
206 if ( $acl_edit_global ) {
207 #really we just want a count, but this is fine unless someone has tons
208 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
209 if ( scalar(@all_agent_types) > 1 ) {
210 push @header, 'Agent types';
211 my $typelink = $p. 'edit/agent_type.cgi?';
212 push @fields, sub { my $part_pkg = shift;
214 map { my $agent_type = $_->agent_type;
216 { 'data' => $agent_type->atype, #escape?
218 'link' => ( $acl_config
233 #if ( $cgi->param('active') ) {
234 push @header, 'Customer<BR>packages';
236 'active' => '00CC00',
237 'suspended' => 'FF9900',
238 'cancelled' => 'FF0000',
239 #'one-time charge' => '000000',
240 'charge' => '000000',
242 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
243 push @fields, sub { my $part_pkg = shift;
248 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
250 #$label = 'one-time charge',
256 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
257 $part_pkg->get("num_$_").
263 ( $part_pkg->get("num_$_") != 1
264 && $label =~ /charge$/
269 'link' => ( $part_pkg->get("num_$_")
277 } (qw( active suspended cancelled ))
283 push @header, 'Taxclass';
284 push @fields, sub { shift->taxclass() || ' '; };
288 push @header, 'Plan options',
290 #'Service', 'Quan', 'Primary';
294 my $part_pkg = shift;
295 if ( $part_pkg->plan ) {
297 my %options = $part_pkg->options;
304 { 'data' => $part_pkg->format($_,$options{$_}),
309 grep { $options{$_} =~ /\S/ }
310 grep { $_ !~ /^(setup|recur)_fee$/ }
321 'data' => $part_pkg->$_(),
334 my $part_pkg = shift;
339 my $part_svc = $pkg_svc->part_svc;
340 my $svc = $part_svc->svc;
341 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
342 $svc = "<B>$svc (PRIMARY)</B>";
344 $svc =~ s/ +/ /g;
348 'data' => '<B>'. $pkg_svc->quantity. '</B>',
354 'link' => ( $acl_config
355 ? $p. 'edit/part_svc.cgi?'.
362 sort { $b->primary_svc =~ /^Y/i
363 <=> $a->primary_svc =~ /^Y/i
365 $part_pkg->pkg_svc('disable_linked'=>1)
368 my $dst_pkg = $_->dst_pkg;
370 { data => 'Add-on: '.$dst_pkg->pkg_comment,
376 $part_pkg->svc_part_pkg_link
382 $align .= 'lrl'; #rr';
386 my $count_extra_sql = $extra_sql;
387 $count_extra_sql =~ s/^\s*AND /WHERE /i;
388 $extra_count = ( $count_extra_sql ? ' AND ' : ' WHERE ' ). $extra_count
390 my $count_query = "SELECT COUNT(*) FROM part_pkg $count_extra_sql $extra_count";