1 <% include( 'elements/browse.html',
2 'title' => 'Package Definitions',
3 'html_init' => $html_init,
4 'name' => 'package definitions',
5 'html_posttotal' => $posttotal,
6 'query' => { 'select' => $select,
9 'extra_sql' => "ORDER BY $orderby",
11 'count_query' => $count_query,
22 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
24 #false laziness w/access_user.html
27 unless ( $cgi->param('showdisabled') ) {
28 %search = ( 'disabled' => '' );
29 $search = "( disabled = '' OR disabled IS NULL )";
33 my $orderby = 'pkgpart';
34 if ( $cgi->param('active') ) {
36 $orderby = 'num_active DESC';
42 ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
43 AND ( cancel IS NULL OR cancel = 0 )
44 AND ( susp IS NULL OR susp = 0 )
47 ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
48 AND ( cancel IS NULL OR cancel = 0 )
49 AND susp IS NOT NULL AND susp != 0
52 ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
53 AND cancel IS NOT NULL AND cancel != 0
60 my $conf = new FS::Conf;
61 my $taxclasses = $conf->exists('enable_taxclasses');
64 #unless ( $cgi->param('active') ) {
66 One or more service definitions are grouped together into a package
67 definition and given pricing information. Customers purchase packages
68 rather than purchase services directly.<BR><BR>
69 <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
75 if ( $cgi->param('showdisabled') ) {
76 $cgi->param('showdisabled', 0);
77 $posttotal = '( <a href="'. $cgi->self_url. '">hide disabled packages</a> )';
78 $cgi->param('showdisabled', 1);
80 $cgi->param('showdisabled', 1);
81 $posttotal = '( <a href="'. $cgi->self_url. '">show disabled packages</a> )';
82 $cgi->param('showdisabled', 0);
88 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
90 my @header = ( '#', 'Package', 'Comment' );
91 my @fields = ( 'pkgpart', 'pkg', 'comment' );
93 my @links = ( $link, $link, '' );
94 my @style = ( '', '', '' );
96 #false laziness w/access_user.html
97 #unless ( $cgi->param('showdisabled') ) { #its been reversed already
98 if ( $cgi->param('showdisabled') ) { #its been reversed already
99 push @header, 'Status';
100 push @fields, sub { shift->disabled
101 ? '<FONT COLOR="#FF0000">DISABLED</FONT>'
102 : '<FONT COLOR="#00CC00">Active</FONT>'
109 unless ( 0 ) { #already showing only one class or something?
110 push @header, 'Class';
111 push @fields, sub { shift->classname || '(none)'; };
115 #if ( $cgi->param('active') ) {
116 push @header, 'Customer<BR>packages';
118 'active' => '00CC00',
119 'suspended' => 'FF9900',
120 'cancelled' => 'FF0000',
121 #'one-time charge' => '000000',
122 'charge' => '000000',
124 my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
125 push @fields, sub { my $part_pkg = shift;
130 if ( $magic eq 'active' && $part_pkg->freq == 0 ) {
132 #$label = 'one-time charge',
138 'data' => '<B><FONT COLOR="#'. $col{$label}. '">'.
139 $part_pkg->get("num_$_").
145 ( $part_pkg->get("num_$_") != 1
146 && $label =~ /charge$/
151 'link' => ( $part_pkg->get("num_$_")
159 } (qw( active suspended cancelled ))
164 push @header, 'Frequency';
165 push @fields, sub { shift->freq_pretty; };
169 push @header, 'Taxclass';
170 push @fields, sub { shift->taxclass() || ' '; };
174 push @header, 'Plan',
177 #'Service', 'Quan', 'Primary';
179 push @fields, sub { shift->plan || '(legacy)' },
182 my $part_pkg = shift;
183 if ( $part_pkg->plan ) {
186 /^(\w+)=(.*)$/; #or something;
191 { 'data' => $part_pkg->format($1,$2),
196 split(/\n/, $part_pkg->plandata)
206 'data' => $part_pkg->$_(),
219 my $part_pkg = shift;
223 my $part_svc = $pkg_svc->part_svc;
224 my $svc = $part_svc->svc;
225 if ( $pkg_svc->primary_svc =~ /^Y/i ) {
226 $svc = "<B>$svc (PRIMARY)</B>";
228 $svc =~ s/ +/ /g;
232 'data' => '<B>'. $pkg_svc->quantity. '</B>',
238 'link' => $p. 'edit/part_svc.cgi?'.
243 sort { $b->primary_svc =~ /^Y/i
244 <=> $a->primary_svc =~ /^Y/i
252 $align .= 'lrl'; #rr';
256 my $count_query = 'SELECT COUNT(*) FROM part_pkg';
257 $count_query .= " WHERE $search"