Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / browse / pkg_class.html
1 <% include( 'elements/browse.html',
2                  'title'       => 'Package classes',
3                  'html_init'   => $html_init,
4                  'name'        => 'package classes',
5                  'disableable' => 1,
6                  'disabled_statuspos' => 2,
7                  'query'       => { 'table'     => 'pkg_class',
8                                     'addl_from' => ' LEFT JOIN pkg_category USING (categorynum)',
9                                     'hashref'   => {},
10                                     'order_by' => 'ORDER BY classnum',
11                                   },
12                  'count_query' => $count_query,
13                  'header'      => $header,
14                  'fields'      => $fields,
15                  'links'       => $links,
16              )
17 %>
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
22
23 my $conf = new FS::Conf;
24
25 my $html_init = 
26   'Package classes define groups of packages, for taxation, ordering '.
27   'convenience and reporting.<BR><BR>'.
28   qq!<A HREF="${p}edit/pkg_class.html"><I>Add a package class</I></A><BR><BR>!;
29
30 my $count_query = 'SELECT COUNT(*) FROM pkg_class';
31
32 my $link = [ $p.'edit/pkg_class.html?', 'classnum' ];
33
34 my $header = [ '#', 'Class' ];
35 my $fields = [ 'classnum', 'classname' ];
36 my $links  = [ $link, $link ];
37
38 my $cat_query = 'SELECT COUNT(*) FROM pkg_class where categorynum IS NOT NULL';
39 my $sth = dbh->prepare($cat_query)
40   or die "Error preparing $cat_query: ". dbh->errstr;
41 $sth->execute
42   or die "Error executing $cat_query: ". $sth->errstr;
43 if ($sth->fetchrow_arrayref->[0]) {
44   push @$header, 'Category';
45   push @$fields, 'categoryname';
46   push @$links,  [ $p.'edit/pkg_category.html?', 'categorynum' ]
47 }
48
49 </%init>