Prevent negative stock
  • Nat
    Prevent negative stock

    by Nat » Mon Apr 03, 2006 11:14 pm

    I have a client who would like to be prevented from being able to invoice into negative stock. I believe there is a script available that does this. Can anyone help me?
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    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

Who is online

Users browsing this forum: No registered users and 9 guests