default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / browse / cust_class.html
1 <% include( 'elements/browse.html',
2                  'title'       => 'Customer classes',
3                  'html_init'   => $html_init,
4                  'name'        => 'customer classes',
5                  'disableable' => 1,
6                  'disabled_statuspos' => 2,
7                  'query'       => { 'table'     => 'cust_class',
8                                     'hashref'   => {},
9                                     'order_by' => 'ORDER BY classnum',
10                                   },
11                  'count_query' => $count_query,
12                  'header'      => $header,
13                  'fields'      => $fields,
14                  'links'       => $links,
15              )
16 %>
17 <%init>
18
19 die "access denied"
20   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
21
22 my $html_init = 
23   'Customer classes define groups of customer for reporting.<BR><BR>'.
24   qq!<A HREF="${p}edit/cust_class.html"><I>Add a customer class</I></A><BR><BR>!;
25
26 #my $disable_counts = $conf->exists('config-disable_counts');
27 my $disable_counts = 0; 
28
29 my $customers_sub = sub {
30   my $cust_class = shift;
31
32   my $cust_main_link = $p. 'search/cust_main.html?'.
33                        'classnum='. $cust_class->classnum;
34
35   #false laziness w/agent.cgi
36   my $OUT = '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>';
37
38   my @cust_status =
39     qw( prospect inactive ordered active suspended cancelled );
40   my %PL = ( 'prospect' => 'prospects', );
41   #my %link = ( 'cancelled' => 'showcancelledcustomers=1&cancelled' );
42   my $statuscolor = FS::cust_main->statuscolors;
43
44   foreach my $status ( @cust_status ) {
45     my $meth = 'num_'. $status;
46     #my $link = exists($link{$status}) ? $link{$status} : $status;
47
48     $OUT .= '<TR>';
49       my $num = 0;
50       unless ( $disable_counts ) {
51         $num = $cust_class->$meth();
52         $OUT .= '<TH ALIGN="right" WIDTH="40%">'.
53                 '<FONT COLOR="#'. $statuscolor->{$status}. '">'.
54                 $num. '&nbsp;</FONT></TH>';
55       }
56     $OUT .= '<TD>';
57
58     if ( $num || $disable_counts ) { 
59       $OUT .= '<A HREF="'. $cust_main_link. "&status=$status". '">';
60     } 
61     $OUT .= exists($PL{$status}) ? $PL{$status} : $status;
62     if ($num || $disable_counts ) {
63       $OUT .= '</A>';
64     } 
65
66     $OUT .= '</TD></TR>';
67
68   }
69
70   $OUT .= '</TABLE>';
71
72   $OUT;
73
74 };
75
76 my $count_query = 'SELECT COUNT(*) FROM cust_class';
77
78 my $link = [ $p.'edit/cust_class.html?', 'classnum' ];
79 my $header = [ '#', 'Class', 'Customers' ];
80 my $fields = [ 'classnum', 'classname', $customers_sub, ];
81 my $links  = [ $link, $link ];
82
83 my $cat_query = 'SELECT COUNT(*) FROM cust_class where categorynum IS NOT NULL';
84 my $sth = dbh->prepare($cat_query)
85   or die "Error preparing $cat_query: ". dbh->errstr;
86 $sth->execute
87   or die "Error executing $cat_query: ". $sth->errstr;
88 if ($sth->fetchrow_arrayref->[0]) {
89   push @$header, 'Category';
90   push @$fields, 'categoryname';
91   push @$links,  $link;
92 }
93
94 my $conf = new FS::Conf;
95 if ( $conf->exists('cust_class-tax_exempt') ) {
96   push @$header, 'Tax exempt';
97   push @$fields, 'tax';
98   push @$links,  '';
99 }
100
101 </%init>