by COBS Tech Support » Mon Apr 03, 2006 11:19 pm
Here it is:
Please note that this script requires CAPITAL 7.41 maintenance release C or higher. The Echo() statement is actually a single line.
* COBS, 10 May 2005, WN
* Prevent negative stock situations
If .Not. ReadTranValue("NEW")
Return TRUE
Endif
Declare nMaxCount Type Number
Declare nCount Type Number
Declare lTranIsOK Type Logical
Declare nQty Type Number
Declare nStockIn Type Number
lTranIsOK := TRUE
nCount := 0
nMaxCount := ReadItemValue("STOCKID", -1)
:Loop
nCount := nCount + 1
If nCount > nMaxCount
Goto End
Endif
If IsEmpty(ReadItemValue("STOCKID", nCount))
Goto Loop
Endif
If .Not. Stock->(Find(ReadItemValue("STOCKID", nCount), 3))
Goto Loop
Endif
nStockIn := StockGetQuantity(FALSE)
nQty := ReadItemValue("QTY", nCount)
If nQty > 0 .And. nQty > nStockIn
Stock->(Find(ReadItemValue("STOCKID", nCount), 3))
Echo("Sorry you are trying to invoice more than is available in stock for stock item " + Alltrim(Stock->Name) + ";;" + "Physical Stock: " + NTrim(nStockIn, 10, 1) + ";To invoice: " + NTrim(nQty, 10, 1),, TRUE)
lTranIsOK := FALSE
Goto End
Endif
Goto Loop
:End
Return lTranIsOK