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