1 <% include( 'elements/browse.html',
2 'title' => 'Package Definitions',
3 'menubar' => [ 'Main Menu' => $p ],
4 'html_init' => $html_init,
5 'name' => 'package definitions',
7 'disabled_statuspos' => 3,
9 'agent_null_right' => 'Edit global package definitions',
11 'query' => { 'select' => $select,
12 'table' => 'part_pkg',
14 'extra_sql' => "ORDER BY $orderby",
16 'count_query' => $count_query,
26 unless $FS::CurrentUser::CurrentUser->access_right('Edit package definitions')
27 || $FS::CurrentUser::CurrentUser->access_right('Edit global package definitions');
30 my $orderby = 'pkgpart';
31 if ( $cgi->param('active') ) {
33 $orderby = 'num_active DESC';
39 ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
40 AND ( cancel IS NULL OR cancel = 0 )
41 AND ( susp IS NULL OR susp = 0 )
44 ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
45 AND ( cancel IS NULL OR cancel = 0 )
46 AND susp IS NOT NULL AND susp != 0
49 ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
50 AND cancel IS NOT NULL AND cancel != 0
57 my $conf = new FS::Conf;
58 my $taxclasses = $conf->exists('enable_taxclasses');
61 #unless ( $cgi->param('active') ) {
63 One or more service definitions are grouped together into a package
64 definition and given pricing information. Customers purchase packages
65 rather than purchase services directly.<BR><BR>
66 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
73 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
75 my @header = ( '#', 'Package', 'Comment' );
76 my @fields = ( 'pkgpart', 'pkg', 'comment' );
78 my @links = ( $link, $link, '' );
80 unless ( 0 ) { #already showing only one class or something?
81 push @header, 'Class';
82 push @fields, sub { shift->classname || '(none)'; };
86 #if ( $cgi->param('active') ) {
87 push @header, 'Customer<BR>packages';
90 'suspended' => 'FF9900',
91 'cancelled' => 'FF0000',
92 #'one-time charge' => '000000',
95 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
96 push @fields, sub { my $part_pkg = shift;
101 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
103 #$label = 'one-time charge',
109 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
110 $part_pkg->get("num_$_").
116 ( $part_pkg->get("num_$_") != 1
117 && $label =~ /charge$/
122 'link' => ( $part_pkg->get("num_$_")
130 } (qw( active suspended cancelled ))
135 push @header, 'Frequency';
136 push @fields, sub { shift->freq_pretty; };
140 push @header, 'Taxclass';
141 push @fields, sub { shift->taxclass() || ' '; };
145 push @header, 'Plan',
148 #'Service', 'Quan', 'Primary';
150 push @fields, sub { shift->plan || '(legacy)' },
153 my $part_pkg = shift;
154 if ( $part_pkg->plan ) {
157 /^(\w+)=(.*)$/; #or something;
162 { 'data' => $part_pkg->format($1,$2),
167 split(/\n/, $part_pkg->plandata)
177 'data' => $part_pkg->$_(),
190 my $part_pkg = shift;
194 my $part_svc = $pkg_svc->part_svc;
195 my $svc = $part_svc->svc;
196 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
197 $svc = "<B>$svc (PRIMARY)</B>";
199 $svc =~ s/ +/ /g;
203 'data' => '<B>'. $pkg_svc->quantity. '</B>',
209 'link' => $p. 'edit/part_svc.cgi?'.
214 sort { $b->primary_svc =~ /^Y/i
215 <=> $a->primary_svc =~ /^Y/i
223 $align .= 'lrl'; #rr';
227 my $count_query = 'SELECT COUNT(*) FROM part_pkg WHERE '.
228 $FS::CurrentUser::CurrentUser->agentnums_sql(
229 'null_right' => 'Edit global package definitions',