1 <% include( 'elements/search.html',
4 'menubar' => [ 'View inventory classes' =>
5 $p.'browse/inventory_class.html',
6 'Upload '. PL($inventory_class->classname)=>
7 $p.'misc/inventory_item-import.html?'.
11 'name' => PL($inventory_class->classname),
14 'table' => 'inventory_item',
16 'select' => join(', ',
20 FS::UI::Web::cust_sql_fields(),
22 'extra_sql' => $extra_sql,
23 'addl_from' => $addl_from,
26 'count_query' => $count_query,
34 $inventory_class->classname,
36 FS::UI::Web::cust_header(),
42 #'svcnum', #XXX proper full service customer link ala svc_acct
43 # "unallocated" ? "available" ?
45 #this could be way more efficient with a mixin
46 # like cust_main_Mixin that let us all all the methods
47 # on data we already have...
48 my $inventory_item = shift;
49 my $cust_svc = $inventory_item->cust_svc;
51 my($label, $value) = $cust_svc->label;
58 \&FS::UI::Web::cust_fields,
61 'align' => 'rll'.FS::UI::Web::cust_aligns(),
66 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
67 FS::UI::Web::cust_header()
74 FS::UI::Web::cust_colors(),
80 FS::UI::Web::cust_styles(),
87 my $curuser = $FS::CurrentUser::CurrentUser;
90 unless $curuser->access_right('Edit inventory')
91 || $curuser->access_right('Edit global inventory')
92 || $curuser->access_right('Configuration');
94 my $classnum = $cgi->param('classnum');
95 $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");
97 my $extra_sql = "WHERE inventory_item.classnum = $classnum ";
99 my $inventory_class = qsearchs( {
100 'table' => 'inventory_class',
101 'hashref' => { 'classnum' => $classnum },
104 my $title = $inventory_class->classname. ' Inventory';
106 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
107 $extra_sql .= " AND inventory_item.agentnum = $1 ";
108 my $agent = qsearchs('agent', { 'agentnum' => $1 }) or die "unknown agentnum";
109 $title = $agent->agent. " $title";
112 #little false laziness with SQL fragments in inventory_class.pm
113 if ( $cgi->param('avail') ) {
114 $extra_sql .= ' AND ( svcnum IS NULL OR svcnum = 0 )';
115 $title .= ' - Available';
116 } elsif ( $cgi->param('used') ) {
117 $extra_sql .= ' AND svcnum IS NOT NULL AND svcnum > 0';
118 $title .= ' - In use';
122 "SELECT COUNT(*) FROM inventory_item $extra_sql";
125 my $inventory_item = shift;
126 if ( $inventory_item->svcnum ) {
128 #[ "${p}view/svc_acct.cgi?", 'svcnum' ];
132 #'svcdb' => $inventory_item->cust_svc->part_svc->svcdb,
133 'svcdb' => $inventory_item->svcdb, #we have it from the joined search
141 my $link_cust = sub {
142 my $inventory_item = shift;
143 if ( $inventory_item->custnum ) {
144 [ "${p}view/cust_main.cgi?", 'custnum' ];
150 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
151 ' LEFT JOIN part_svc USING ( svcpart ) '.
152 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
153 ' LEFT JOIN cust_main USING ( custnum ) ';