1 <% include( 'elements/search.html',
4 #less lame to use Lingua:: something to pluralize
5 'name' => $inventory_class->classname. 's',
8 'table' => 'inventory_item',
10 'select' => join(', ',
14 FS::UI::Web::cust_sql_fields(),
16 'extra_sql' => $extra_sql,
17 'addl_from' => $addl_from,
20 'count_query' => $count_query,
24 $inventory_class->classname,
26 FS::UI::Web::cust_header(),
32 #'svcnum', #XXX proper full service customer link ala svc_acct
33 # "unallocated" ? "available" ?
35 #this could be way more efficient with a mixin
36 # like cust_main_Mixin that let us all all the methods
37 # on data we already have...
38 my $inventory_item = shift;
39 my $cust_svc = $inventory_item->cust_svc;
41 my($label, $value) = $cust_svc->label;
48 \&FS::UI::Web::cust_fields,
51 'align' => 'rll'.FS::UI::Web::cust_aligns(),
56 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
57 FS::UI::Web::cust_header()
64 FS::UI::Web::cust_colors(),
70 FS::UI::Web::cust_styles(),
78 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
80 my $classnum = $cgi->param('classnum');
81 $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");
83 my $extra_sql = "WHERE inventory_item.classnum = $classnum ";
85 my $inventory_class = qsearchs( {
86 'table' => 'inventory_class',
87 'hashref' => { 'classnum' => $classnum },
90 my $title = $inventory_class->classname. ' Inventory';
92 #little false laziness with SQL fragments in inventory_class.pm
93 if ( $cgi->param('avail') ) {
94 $extra_sql .= ' AND ( svcnum IS NULL OR svcnum = 0 )';
95 $title .= ' - Available';
96 } elsif ( $cgi->param('used') ) {
97 $extra_sql .= ' AND svcnum IS NOT NULL AND svcnum > 0';
98 $title .= ' - In use';
102 "SELECT COUNT(*) FROM inventory_item $extra_sql";
105 my $inventory_item = shift;
106 if ( $inventory_item->svcnum ) {
108 #[ "${p}view/svc_acct.cgi?", 'svcnum' ];
112 #'svcdb' => $inventory_item->cust_svc->part_svc->svcdb,
113 'svcdb' => $inventory_item->svcdb, #we have it from the joined search
121 my $link_cust = sub {
122 my $inventory_item = shift;
123 if ( $inventory_item->custnum ) {
124 [ "${p}view/cust_main.cgi?", 'custnum' ];
130 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
131 ' LEFT JOIN part_svc USING ( svcpart ) '.
132 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
133 ' LEFT JOIN cust_main USING ( custnum ) ';