1 <& 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(),
43 #'svcnum', #XXX proper full service customer link ala svc_acct
44 # "unallocated" ? "available" ?
46 #this could be way more efficient with a mixin
47 # like cust_main_Mixin that let us all all the methods
48 # on data we already have...
49 my $inventory_item = shift;
50 my $cust_svc = $inventory_item->cust_svc;
52 my($label, $value) = $cust_svc->label;
59 \&FS::UI::Web::cust_fields,
63 'align' => 'rll'.FS::UI::Web::cust_aligns(),
68 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
69 FS::UI::Web::cust_header()
76 FS::UI::Web::cust_colors(),
82 FS::UI::Web::cust_styles(),
84 'html_init' => $html_form,
85 'html_foot' => $html_foot,
90 my $curuser = $FS::CurrentUser::CurrentUser;
93 unless $curuser->access_right('Edit inventory')
94 || $curuser->access_right('Edit global inventory')
95 || $curuser->access_right('Configuration');
97 my $classnum = $cgi->param('classnum');
98 $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");
100 my $extra_sql = "WHERE inventory_item.classnum = $classnum ";
102 my $inventory_class = qsearchs( {
103 'table' => 'inventory_class',
104 'hashref' => { 'classnum' => $classnum },
107 my $title = $inventory_class->classname. ' Inventory';
109 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
110 $extra_sql .= " AND inventory_item.agentnum = $1 ";
111 my $agent = qsearchs('agent', { 'agentnum' => $1 }) or die "unknown agentnum";
112 $title = $agent->agent. " $title";
115 #little false laziness with SQL fragments in inventory_class.pm
116 if ( $cgi->param('avail') ) {
117 $extra_sql .= ' AND ( svcnum IS NULL OR svcnum = 0 )';
118 $title .= ' - Available';
119 } elsif ( $cgi->param('used') ) {
120 $extra_sql .= ' AND svcnum IS NOT NULL AND svcnum > 0';
121 $title .= ' - In use';
125 "SELECT COUNT(*) FROM inventory_item $extra_sql";
128 my $inventory_item = shift;
129 if ( $inventory_item->svcnum ) {
131 #[ "${p}view/svc_acct.cgi?", 'svcnum' ];
135 #'svcdb' => $inventory_item->cust_svc->part_svc->svcdb,
136 'svcdb' => $inventory_item->svcdb, #we have it from the joined search
144 my $link_cust = sub {
145 my $inventory_item = shift;
146 if ( $inventory_item->custnum ) {
147 [ "${p}view/cust_main.cgi?", 'custnum' ];
153 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
154 ' LEFT JOIN part_svc USING ( svcpart ) '.
155 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
156 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
158 my $sub_checkbox = sub {
160 my $itemnum = $item->itemnum;
161 return '' if $item->svcnum;
163 return qq!<INPUT NAME="itemnum" TYPE="checkbox" VALUE="$itemnum">!;
167 <FORM NAME="itemForm" ACTION="$p/misc/inventory_item-move.cgi" METHOD="POST">
168 <INPUT TYPE="hidden" NAME="classnum" VALUE="$classnum">
169 <INPUT TYPE="hidden" NAME="avail" VALUE="! .$cgi->param('avail') . '">';
172 my $html_foot = include('elements/checkbox-foot.html',
174 { submit => 'Delete',
175 confirm => 'Delete the selected items?',
178 { submit => 'Move to',
184 $html_foot =~ s[</DIV>][];
186 include('/elements/select-agent.html',
187 'field' => 'move_agentnum',
188 'disable_empty' => 1,