its all about control
[freeside.git] / httemplate / browse / inventory_class.html
1 <% include( 'elements/browse.html',
2                  'title'       => 'Inventory Classes',
3                  'name'        => 'inventory classes',
4                  'menubar'     => [ 'Add a new inventory class' =>
5                                       $p.'edit/inventory_class.html',
6                                   ],
7                  'query'       => { 'table' => 'inventory_class', },
8                  'count_query' => 'SELECT COUNT(*) FROM inventory_class',
9                  'header'      => [ '#', 'Inventory class', 'Inventory' ],
10                  'fields'      => [ 'classnum',
11                                     'classname',
12                                     sub {
13                                           #my $inventory_class = shift;
14                                           my $i_c = shift;
15
16                                           my $link =
17                                             $p. 'search/inventory_item.html?'.
18                                             'classnum='. $i_c->classnum;
19
20                                           my %actioncol = ();
21                                           foreach ( keys %inv_action_link ) {
22                                             my($label, $baseurl, $method) =
23                                               @{ $inv_action_link{$_} };
24                                             my $url = $baseurl. $i_c->$method();
25                                             $actioncol{$_} =
26                                               '<FONT SIZE="-1">'.
27                                               '('.
28                                               '<A HREF="'.$url.'">'.
29                                               $label.
30                                               '</A>'.
31                                               ')'.
32                                               '</FONT>';
33                                           }
34
35                                           my %num = map { 
36                                             $_ => $i_c->$_();
37                                           } keys %labels;
38
39                                           [ map {
40                                                   [
41                                                     {
42                                                       'data'  => '<B>'. $num{$_}. '</B>',
43                                                       'align' => 'right',
44                                                     },
45                                                     {
46                                                       'data'  => $labels{$_},
47                                                       'align' => 'left',
48                                                       'link'  => ( $num{$_}
49                                                                      ? $link.$link{$_}
50                                                                      : ''
51                                                                  ),
52                                                     },
53                                                     { 'data'  => $actioncol{$_},
54                                                       'align'  => 'left',
55                                                     },
56                                                   ]
57                                                 } keys %labels
58                                           ];
59                                         },
60                                   ],
61                  'links'       => [ $link,
62                                     $link,
63                                     '',
64                                   ],
65              )
66 %>
67 <%init>
68
69 die "access denied"
70   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
71
72 tie my %labels, 'Tie::IxHash',
73   'num_avail' => 'Available', #  <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
74   'num_used'  => 'In use', #'Used', #'Allocated',
75   'num_total' => 'Total',
76 ;
77
78 my %link = (
79   'num_avail' => ';avail=1',
80   'num_used'  => ';used=1',
81   'num_total' => '',
82 );
83
84 my %inv_action_link = (
85   'num_avail' => [ 'upload batch',
86                    $p.'misc/inventory_item-import.html?classnum=',
87                    'classnum'
88                  ],
89 );
90
91 my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];
92
93 </%init>