summaryrefslogtreecommitdiff
path: root/httemplate/browse/inventory_class.html
blob: 8ce131ac293604d7e55bad8beb74aad666845dba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<% include( 'elements/browse.html',
                 'title'       => 'Inventory Classes',
                 'name'        => 'inventory classes',
                 'menubar'     => [ 'Add a new inventory class' =>
                                      $p.'edit/inventory_class.html',
                                  ],
                 'query'       => { 'table' => 'inventory_class', },
                 'count_query' => 'SELECT COUNT(*) FROM inventory_class',
                 'header'      => [ '#', 'Inventory class', 'Inventory' ],
                 'fields'      => [ 'classnum',
                                    'classname',
                                    sub {
                                          #my $inventory_class = shift;
                                          my $i_c = shift;

                                          my $link =
                                            $p. 'search/inventory_item.html?'.
                                            'classnum='. $i_c->classnum;

                                          my %actioncol = ();
                                          foreach ( keys %inv_action_link ) {
                                            my($label, $baseurl, $method) =
                                              @{ $inv_action_link{$_} };
                                            my $url = $baseurl. $i_c->$method();
                                            $actioncol{$_} =
                                              '<FONT SIZE="-1">'.
                                              '('.
                                              '<A HREF="'.$url.'">'.
                                              $label.
                                              '</A>'.
                                              ')'.
                                              '</FONT>';
                                          }

                                          my %num = map { 
                                            $_ => $i_c->$_();
                                          } keys %labels;

                                          [ map {
                                                  [
                                                    {
                                                      'data'  => '<B>'. $num{$_}. '</B>',
                                                      'align' => 'right',
                                                    },
                                                    {
                                                      'data'  => $labels{$_},
                                                      'align' => 'left',
                                                      'link'  => ( $num{$_}
                                                                     ? $link.$link{$_}
                                                                     : ''
                                                                 ),
                                                    },
                                                    { 'data'  => $actioncol{$_},
                                                      'align'  => 'left',
                                                    },
                                                  ]
                                                } keys %labels
                                          ];
                                        },
                                  ],
                 'links'       => [ $link,
                                    $link,
                                    '',
                                  ],
             )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

tie my %labels, 'Tie::IxHash',
  'num_avail' => 'Available', #  <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
  'num_used'  => 'In use', #'Used', #'Allocated',
  'num_total' => 'Total',
;

my %link = (
  'num_avail' => ';avail=1',
  'num_used'  => ';used=1',
  'num_total' => '',
);

my %inv_action_link = (
  'num_avail' => [ 'upload batch',
                   $p.'misc/inventory_item-import.html?classnum=',
                   'classnum'
                 ],
);

my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];

</%init>