How to write off quantity programmatically?

SOLVED

Hi all,

My Stock Item is sold by weight quantity in decimal. this situation often left the balance as less than 1 i.e.: 0.002, 0.003 and so on. This happen to a lot of stock items, so I wanted to write off the Actual Quantity and Free Stock Quantity in bulk. I will upload an excel file that contain the Stock Code, and match to the stock item in Sage 200.

For the write off function, I was referring to this page https://my.sage.co.uk/Sage200SDKDocs/html/DOC0077_Overview.html

but unable to find the WriteOff() function under Sage.Accounting.Stock.BinItem binItem class.

So I try to update the quantity as in the code below, but it only change the Free Stock Quantity to 0. The Actual Quantity still have the original value.

 wo.stockItem.UpdateFreeStockAvailable(wo.stockItem.FreeStockQuantity);
wo.stockItem.UpdateQuantityReserved(wo.stockItem.QuantityReserved);
foreach (BinItem bi in wo.stockItem.Locations)
{
    bi.WarehouseItem.QuantityAllocatedBOM = 0;
    bi.WarehouseItem.QuantityAllocatedSOP = 0;
    bi.WarehouseItem.QuantityAllocatedStock = 0;
    bi.WarehouseItem.QuantityReserved = 0;
    bi.WarehouseItem.QuantityOnPOPOrder = 0;
    bi.WarehouseItem.Update();
    bi.QuantityAllocatedBOM = 0;
    bi.QuantityAllocatedSOP = 0;
    bi.QuantityAllocatedStock = 0;
    bi.QuantityReserved = 0;
    bi.Update();
}
wo.stockItem.Update();

Please guide me on how to write off the actual quantity as in the Sage 200 Standard Write off form.

Thank you

  • +1
    verified answer

    The BinItem doesn't have a WriteOff method. You need to use a StockWriteoffMovementActivity.

    Here's an example:

    StockWriteOffMovementActivity writeOffActivity = new StockWriteOffMovementActivity();
    try
    {
        writeOffActivity.StockItem = stockItem;
        writeOffActivity.Location = binItem;
        writeOffActivity.Quantity = quantityThisWriteOff;
        writeOffActivity.ActivityDate = tranDate;
        writeOffActivity.Reference = reference;
        writeOffActivity.SecondReference = secondRef;
        writeOffActivity.GenerateNominalPostings = false;
        writeOffActivity.Recipient = recipientOut;
        writeOffActivity.Update();
    
    }
    catch (Exception ex)
    {
        if (writeOffActivity != null)
        {
            writeOffActivity.DiscardChanges();
        }
        throw;
    }

    Not that the 'RecipientOut' is a WriteOffCategory - you'd have to select the appropriate instance of WriteOffCategory from the collection.

  • 0 in reply to Chris Burke

    thank you that works