This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / httemplate / search / inventory_item.html
1 <% include( 'elements/search.html',
2                  'title'       => $title,
3
4                  #less lame to use Lingua:: something to pluralize
5                  'name'        => $inventory_class->classname. 's',
6
7                  'query'       => {
8                                     'table'   => 'inventory_item',
9                                     'hashref' => { 'classnum' => $classnum },
10                                     'select'  => join(', ',
11                                         'inventory_item.*',
12                                         'cust_main.custnum',
13                                         FS::UI::Web::cust_sql_fields(),
14                                       ),
15                                     'extra_sql' => $extra_sql,
16                                     'addl_from' => $addl_from,
17                                   },
18
19                  'count_query' => $count_query,
20
21                  'header'      => [
22                    '#',
23                    $inventory_class->classname,
24                    'Service',
25                    FS::UI::Web::cust_header(),
26                  ],
27
28                  'fields'      => [
29                    'itemnum',
30                    'item',
31                    #'svcnum', #XXX proper full service customer link ala svc_acct
32                              # "unallocated" ?  "available" ?
33                    sub {
34                      #this could be way more efficient with a mixin
35                      # like cust_main_Mixin that let us all all the methods
36                      # on data we already have...
37                      my $inventory_item = shift;
38                      my $cust_svc = $inventory_item->cust_svc;
39                      if ( $cust_svc ) {
40                        my($label, $value) = $cust_svc->label;
41                        "$label: $value";
42                      } else {
43                        '(available)';
44                      }
45                    },
46
47                    \&FS::UI::Web::cust_fields,
48
49                  ],
50                  'align'       => 'rll'.FS::UI::Web::cust_aligns(),
51                  'links'       => [
52                    '',
53                    '',
54                    $link,
55                    ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
56                          FS::UI::Web::cust_header()
57                    ),
58                  ],
59                  'color' => [ 
60                               '',
61                               '',
62                               '',
63                               FS::UI::Web::cust_colors(),
64                             ],
65                  'style' => [ 
66                               '',
67                               '',
68                               '',
69                               FS::UI::Web::cust_styles(),
70                             ],
71
72              )
73 %>
74 <%init>
75
76 die "access denied"
77   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
78
79 my $classnum = $cgi->param('classnum');
80 $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");
81 $classnum = $1;
82
83 my $inventory_class = qsearchs( {
84   'table'     => 'inventory_class',
85   'hashref'   => { 'classnum' => $classnum },
86 } );
87
88 my $title = $inventory_class->classname. ' Inventory';
89
90 #little false laziness with SQL fragments in inventory_class.pm
91 my $extra_sql = '';
92 if ( $cgi->param('avail') ) {
93   $extra_sql = 'AND ( svcnum IS NULL OR svcnum = 0 )';
94   $title .= ' - Available';
95 } elsif ( $cgi->param('used') ) {
96   $extra_sql = 'AND svcnum IS NOT NULL AND svcnum > 0';
97   $title .= ' - In use';
98 }
99
100 my $count_query =
101   "SELECT COUNT(*) FROM inventory_item WHERE classnum = $classnum $extra_sql";
102
103 my $link = sub {
104   my $inventory_item = shift;
105   if ( $inventory_item->svcnum ) {
106     [ "${p}view/svc_acct.cgi?", 'svcnum' ];
107   } else {
108     '';
109   }
110 };
111 my $link_cust = sub {
112   my $inventory_item = shift;
113   if ( $inventory_item->custnum ) {
114     [ "${p}view/cust_main.cgi?", 'custnum' ];
115   } else {
116     '';
117   }
118 };
119
120 my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
121                 ' LEFT JOIN part_svc  USING ( svcpart ) '.
122                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
123                 ' LEFT JOIN cust_main USING ( custnum ) ';
124
125 </%init>