<% '***************************************************************** ' VP-ASP 6.50 ' called by shopthanks to updae Stock Information ' called as a subroutine ' Reads order items and updates product stock levels appropriately ' Sept 22, 2004 fix stock on non existent products '******************************************************************* dim stockconn, dbc Sub UpdateStock (orderid) If getSess(REGISTRANTID)<>"" then exit sub ' dont update stock on giftreg create oid=orderid OpenOrderdb dbc ' Open the database ShopOpendatabaseP stockconn strSQL = "select * FROM oitems where orderid = " & Oid Set Items = dbc.Execute(strSQL) UpdateStockDetails ShopCloseDatabase dbc Shopclosedatabase stockconn end sub Sub UpdateStockDetails dim catalogid dim quantity Do While Not Items.EOF quantity=Items("numitems") catalogid=items("catalogid") UpdateStockLevels catalogid, quantity Items.MoveNext Loop closerecordset items end sub ' Sub UpdateStockLevels (catalogid, quantity) dim rsproduct dim myconn dim stock Set rsproduct = Server.CreateObject ("adodb.recordset") sql ="select cstock, cname from products where catalogid=" & catalogid rsproduct.Open SQL, stockconn, adOpenKeyset, adLockOptimistic , adcmdText if not rsproduct.eof then stock=rsproduct("cstock") stock=stock-quantity rsproduct("cstock")=stock '==================================== 'VP-ASP 600 - Send an email when stock is running low '12/10/2005 '==================================== dim stocklowlevel if getconfig("xstocklowemail") = "Yes" then if (getconfig("xstocklow") > "") then stocklowlevel = getconfig("xstocklow") else stocklowlevel = 0 end if 'VP-ASP 6.09 - added clng() function if clng(stock) <= clng(stocklowlevel) then EmailLowStock rsproduct("cname"), catalogid end if end if '==================================== 'VP-ASP 6.50 - broadened defintion of IF statement to cover cases where xmysql hasn't been set if ucase(xdatabasetype) = "MYSQL" OR ucase(xdatabasetype) = "MYSQL351" OR getconfig("xMYSQL")="Yes" then mysqlupdatestocklevels catalogid, quantity, stockconn exit sub end if 'UPDATE RECORDSET rsproduct.update end if closerecordset rsproduct end sub Sub EmailLowStock (productname,catalogid) dim subject if getconfig("Xemailmerchant")<>"Yes" then exit sub If merchantemailformat<>"" then SetSess "emailformat",merchantemailformat end if subject="Low Stock Warning - " & productname body = "LOW STOCK WARNING" & vbcrlf body = body & "Catalog ID: " & catalogid & vbcrlf body = body & "Product Name: " & productname & vbcrlf ExecuteMail getconfig("xemailtype"),getconfig("xemailname"),getconfig("xemail"),getconfig("xemailname"),getconfig("xemail"),subject,body,Getsess("EmailFormat"),"",0 End Sub %>