I've improved the script to include inline editing of the stock quantity and the re-order levels, as well as making the displayed quantity of any products that are at or below stock appear in RED.
Here's
a screenshot of the output.
It makes it much easier to receive new merchandise into stock as it is delivered, as well as keeping an eye on overall inventory levels.
You just have to change the items in bold, and create a connection string in your global.asa in a separate site that can run ASP.
Example connectionstring in global.asa:
Application("my_ConnectionString") = "Provider=sqloledb;" & _
"Data Source=123.45.67.890,1433;" & _
"Initial Catalog=YOUR_DATABASE_NAME;" & _
"User ID=YOUR_DB_USERNAME;" & _
"Password=YOUR_DB_PASSWORD"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Current Stock Levels as of <%=now()%></title>
</head>
<body link="#0000FF" vlink="#0000FF" alink="#FF0000">
<h2><font face="Tahoma">Current Stock Levels as of <%=now()%></font></h2>
<table width="700" border="1" cellspacing="0" cellpadding="4" bordercolor="#CCCCCC">
<%
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open Application("my_ConnectionString")
SQLStmt = "SELECT [id],[sku],[name],[stockquantity],[NotifyAdminForQuantityBelow] FROM [Product] where [Published] = 'True' AND [Deleted] = 'False' order by [SKU] ASC"
Set RS = Connection.Execute(SQLStmt)
numrecs=-1
If Not rs.EOF Then
theData=rs.GetRows()
numrecs=uBound(theData,2)
Else
' response.write "<p><font color=red face=Tahoma size=2><b><big><i>Strange</i>... no products returned.</font></b>"
' response.end
End If
For i=0 to numrecs
if theData(3,i)=10000 then thestockvalue="----" else thestockvalue=theData(3,i)
%>
<tr>
<th bgcolor="#dadada" align=left colspan=4><font face="Tahoma" size="3"><a name="<%=theData(2,i)%>" href="https://www.mydomain.com/Admin/Product/Edit/<%=theData(0,i)%>" target="_self"><%=theData(2,i)%></a></font></th>
</tr>
<tr>
<td><b><font face="Tahoma" size="2">SKU</font></b></td>
<td><b><font face="Tahoma" size="2">Product Name</font></b></td>
<td align=center><b><font face="Tahoma" size="2">Re-order Level</font></b></td>
<td align=center><b><font face="Tahoma" size="2"># On Hand</font></b></td>
</tr>
<tr>
<td><font face="Tahoma" size="2"><%=theData(1,i)%></font></td>
<td align=left><font face="Tahoma" size="2"><%=theData(2,i)%></font></td>
<td align=center>
<% if thestockvalue="----" then %>
<font face="Tahoma" size="2">----</font>
<% else %>
<form method="POST" action="update_product_reorder_levels.asp" style="line-height: 50%; margin-bottom: 0;">
<input type="text" name="NotifyAdminForQuantityBelow" size="4" value="<%=theData(4,i)%>" style="font-weight: bold;">
<input type="submit" value="Update" name="B1" style="font-size: 8pt; font-weight: bold">
<input type="hidden" name="Id" value="<%=theData(0,i)%>">
<input type="hidden" name="bookmark" value="<%=theData(2,i)%>">
<input type="hidden" name="returnpage" value="stock_levels.asp">
</form>
<% end if %>
</td>
<td align=center>
<% if thestockvalue="----" then %>
<font face="Tahoma" size="2"><%=thestockvalue%></font>
<% else
if theData(3,i) <= theData(4,i) then
stylecolor=" color: red;"
else
stylecolor=" color: black;"
end if
%>
<form method="POST" action="update_product_stock_quantities.asp" style="line-height: 50%; margin-bottom: 0;">
<input type="text" name="stockquantity" size="4" value="<%=thestockvalue%>" style="font-weight: bold;<%=stylecolor%>">
<input type="submit" value="Update" name="B1" style="font-size: 8pt; font-weight: bold">
<input type="hidden" name="Id" value="<%=theData(0,i)%>">
<input type="hidden" name="bookmark" value="<%=theData(2,i)%>">
<input type="hidden" name="returnpage" value="stock_levels.asp">
</form>
<% end if %>
</td>
</tr>
<tr>
<td colspan=4> </td>
</tr>
<%
SQLStmt2 = "SELECT [sku],[ManufacturerPartNumber],[stockquantity],[NotifyAdminForQuantityBelow],[Id] FROM [ProductVariantAttributeCombination] where [productid]=" & theData(0,i) & " order by [ManufacturerPartNumber]; "
Set RS2 = Connection.Execute(SQLStmt2)
numrecs2=-1
If rs2.EOF Then
' skip it
Else
theData2=rs2.GetRows()
numrecs2=uBound(theData2,2)
%>
<tr>
<td bgcolor="#f0f0f0" align=center colspan=4><b><font face="Tahoma" size="1">VARIANTS</font></b></td>
</tr>
<tr>
<td><b><font face="Tahoma" size="2">SKU</font></b></td>
<td><b><font face="Tahoma" size="2">Mfg. Part #</font></b></td>
<td align=center><b><font face="Tahoma" size="2">Re-order Level</font></b></td>
<td align=center><b><font face="Tahoma" size="2"># On Hand</font></b></td>
</tr>
<%
For x=0 to numrecs2
if theData2(2,x) <= theData2(3,x) then
stylecolor=" color: red;"
else
stylecolor=" color: black;"
end if
%>
<tr>
<td><font face="Tahoma" size="2"><%=theData2(0,x)%></font></td>
<td><font face="Tahoma" size="2"><%=theData2(1,x)%></font></td>
<td align=center>
<form method="POST" action="update_attributecombination_reorder_levels.asp" style="line-height: 50%; margin-bottom: 0;">
<input type="text" name="NotifyAdminForQuantityBelow" size="4" value="<%=theData2(3,x)%>" style="font-weight: bold;">
<input type="submit" value="Update" name="B1" style="font-size: 8pt; font-weight: bold">
<input type="hidden" name="Id" value="<%=theData2(4,x)%>">
<input type="hidden" name="bookmark" value="<%=theData(2,i)%>">
<input type="hidden" name="returnpage" value="stock_levels.asp">
</form>
</td>
<td align=center>
<form method="POST" action="update_attributecombination_stock_quantities.asp" style="line-height: 50%; margin-bottom: 0;">
<input type="text" name="stockquantity" size="4" value="<%=theData2(2,x)%>" style="font-weight: bold;<%=stylecolor%>">
<input type="submit" value="Update" name="B2" style="font-size: 8pt; font-weight: bold">
<input type="hidden" name="Id" value="<%=theData2(4,x)%>">
<input type="hidden" name="bookmark" value="<%=theData(2,i)%>">
<input type="hidden" name="returnpage" value="stock_levels.asp">
</form>
</td>
</tr>
<%
Next ' x loop
%>
<tr>
<td colspan=4> </td>
</tr>
<%
End If
Next ' i loop
Set rs=Nothing
Set rs2=Nothing
connection.Close
Set Connection=Nothing
%>
</table>
</body>
</html>
It now includes these two scripts for updating the number of units on hand (stock quantity) and re-order level (NotifyAdminForQuantityBelow):
update_attributecombination_reorder_levels.asp
<%
Id=Request.form("Id")
thereorderlevel=request.form("NotifyAdminForQuantityBelow")
bookmark=request.form("bookmark")
returnpage=request.form("returnpage")
Set rs = Server.CreateObject("ADODB.Recordset")
q = "UPDATE [ProductVariantAttributeCombination] SET [NotifyAdminForQuantityBelow] = " & thereorderlevel
q = q &" WHERE [Id] = " & Id
'response.write q & "<br>"
'response.end
rs.Open q, Application("my_ConnectionString")
response.redirect returnpage & "#" & bookmark
%>
update_attributecombination_stock_quantities.asp
<%
ID=Request.form("Id")
thestockvalue=request.form("stockquantity")
bookmark=request.form("bookmark")
returnpage=request.form("returnpage")
Set rs = Server.CreateObject("ADODB.Recordset")
q = "UPDATE [ProductVariantAttributeCombination] SET [StockQuantity] = " & thestockvalue
q = q &" WHERE [ID] = " & ID
'response.write q & "<br>"
'response.end
rs.Open q, Application("my_ConnectionString")
response.redirect returnpage & "#" & bookmark
%>