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(),
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(),
86 <FORM NAME="itemForm" ACTION="$p/misc/inventory_item-move.cgi" METHOD="POST">
87 <INPUT TYPE="hidden" NAME="classnum" VALUE="$classnum">
88 <INPUT TYPE="hidden" NAME="avail" VALUE="! .$cgi->param('avail') . '">', #'
89 'html_foot' => $sub_foot,
94 my $curuser = $FS::CurrentUser::CurrentUser;
97 unless $curuser->access_right('Edit inventory')
98 || $curuser->access_right('Edit global inventory')
99 || $curuser->access_right('Configuration');
101 my $classnum = $cgi->param('classnum');
102 $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");
104 my $extra_sql = "WHERE inventory_item.classnum = $classnum ";
106 my $inventory_class = qsearchs( {
107 'table' => 'inventory_class',
108 'hashref' => { 'classnum' => $classnum },
111 my $title = $inventory_class->classname. ' Inventory';
113 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
114 $extra_sql .= " AND inventory_item.agentnum = $1 ";
115 my $agent = qsearchs('agent', { 'agentnum' => $1 }) or die "unknown agentnum";
116 $title = $agent->agent. " $title";
119 #little false laziness with SQL fragments in inventory_class.pm
120 if ( $cgi->param('avail') ) {
121 $extra_sql .= ' AND ( svcnum IS NULL OR svcnum = 0 )';
122 $title .= ' - Available';
123 } elsif ( $cgi->param('used') ) {
124 $extra_sql .= ' AND svcnum IS NOT NULL AND svcnum > 0';
125 $title .= ' - In use';
129 "SELECT COUNT(*) FROM inventory_item $extra_sql";
132 my $inventory_item = shift;
133 if ( $inventory_item->svcnum ) {
135 #[ "${p}view/svc_acct.cgi?", 'svcnum' ];
139 #'svcdb' => $inventory_item->cust_svc->part_svc->svcdb,
140 'svcdb' => $inventory_item->svcdb, #we have it from the joined search
148 my $link_cust = sub {
149 my $inventory_item = shift;
150 if ( $inventory_item->custnum ) {
151 [ "${p}view/cust_main.cgi?", 'custnum' ];
157 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
158 ' LEFT JOIN part_svc USING ( svcpart ) '.
159 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
160 ' LEFT JOIN cust_main USING ( custnum ) ';
163 my $sub_checkbox = sub {
165 my $itemnum = $item->itemnum;
166 #return '' if $item->svcnum;
168 return qq!<INPUT NAME="itemnum$itemnum" TYPE="checkbox" VALUE="1">!;
172 return if !$areboxes;
174 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
175 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">
176 <BR><INPUT TYPE="submit" NAME="action" VALUE="Move to agent">
177 <SELECT NAME="move_agentnum">';
178 foreach my $agent ($curuser->agents) {
179 $foot .= '<OPTION VALUE="'.$agent->agentnum.'">'.
180 $agent->agent . '</OPTION>
184 <SCRIPT TYPE="text/javascript">
185 function setAll(setTo) {
186 theForm = document.itemForm;
187 for (i=0,n=theForm.elements.length;i<n;i++)
188 if (theForm.elements[i].name.indexOf("itemnum") != -1)
189 theForm.elements[i].checked = setTo;