dinsdag 14 september 2010

Post packing slip for a single sales line

public void aduAutoPostPackingSlip(SalesLine            _salesLine,
                                   ADUPostPackingSlip   _aduPostPackingSlip = NoYes::No)
{
    SalesFormLetter salesFormLetter;
    SalesLine       salesLineLocal;
    SalesLine       salesLineUpdate;
    ;

    if (_aduPostPackingSlip == NoYes::Yes && _salesLine)
    {
        ttsbegin;
        salesLineLocal = SalesLine::findRecId(_salesLine.RecId, true);

        if (salesLineLocal)
        {
            //On beforehand (before salesFormLetter.update) set all salesLines of the order, except your line, to sales+inventdelivernow = 0
            //so that you don't accidentally post the delivernow data of another user on you packingslip.
            //this overwrites the existing data of the other users, but this is no problem, since this is data that is usually processed immediately.
            update_recordset salesLineUpdate
                setting      SalesDeliverNow = 0,
                             InventDeliverNow = 0
                where        salesLineUpdate.SalesId == salesLineLocal.SalesId
                          && salesLineUpdate.RecId != salesLineLocal.RecId;

            salesLineLocal.SalesDeliverNow = salesLineLocal.SalesQty;
            salesLineLocal.setInventDeliverNow(); //inventDeliverNow must be filled, otherwise the posting will fail
            salesLineLocal.update();
        }
        ttscommit;

        salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
        salesFormLetter.update(_salesLine.salesTable(),
                               systemdateget(),
                               SalesUpdate::DeliverNow,
                               AccountOrder::None,
                               NoYes::No,
                               NoYes::No);
    }
}


See also http://www.mibuso.com/forum/viewtopic.php?p=98005

Geen opmerkingen:

Een reactie posten