Monday, August 28, 2017

Correct product receipt Purchase order in X++

//Correct product receipt Purchase order in X++
static void CorrectPurchOrderPackingSlip(Args _args)
{
    PurchFormLetter         purchFormLetter;
    PurchFormletterParmData purchFormLetterParmData;
    PurchParmUpdate         purchParmUpdate;
    PurchParmTable          purchParmTable;
    PurchParmLine           purchParmLine;
    PurchTable              purchTable;
    PurchLine               purchLine;
    PurchId                 purchId;
    Num                     packingSlipId;
    VendPackingSlipJour     vendPackingSlipJour;
    VendPackingSlipTrans    vendPackingSlipTrans;
    ;
    purchId       = "CBS-000188";
    packingSlipId = "PS-188-1";
    purchTable = PurchTable::find(purchId);
    select * from vendPackingSlipJour
        where vendPackingSlipJour.PurchId == purchId
            && vendPackingSlipJour.PackingSlipId == packingSlipId;
    ttsBegin;
    purchFormLetterParmData = PurchFormletterParmData::newData(
        DocumentStatus::PackingSlip,
        VersioningUpdateType::Correction);
    purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
    purchFormLetterParmData.createData(false);
    purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
    purchParmTable.clear();
    purchParmTable.TransDate             = SystemDateGet(); //need to mention Required date
    purchParmTable.Ordering              = DocumentStatus::PackingSlip;
    purchParmTable.ParmJobStatus         = ParmJobStatus::Waiting;
    purchParmTable.ParmId                = purchParmUpdate.ParmId;
    purchParmTable.Num                   = packingSlipId;
    purchParmTable.ReCalculate           = true;
    purchParmTable.PurchId               = purchTable.PurchId;
    purchParmTable.PurchName             = purchTable.PurchName;
    purchParmTable.DeliveryName          = purchTable.DeliveryName;
    purchParmTable.OrderAccount          = purchTable.OrderAccount;
    purchParmTable.InvoiceAccount        = purchTable.InvoiceAccount;
    purchParmTable.CurrencyCode          = purchTable.CurrencyCode;
    purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress;
    purchParmTable.VendPackingSlipJour   = vendPackingSlipJour.RecId;
    purchParmTable.insert();
    while select purchLine
        where purchLine.PurchId == purchTable.purchId
    {
        select * from vendPackingSlipTrans
            where vendPackingSlipTrans.OrigPurchid == purchLine.PurchId
                && vendPackingSlipTrans.PurchaseLineLineNumber == purchLine.LineNumber;
        purchParmLine.ParmId = purchParmTable.ParmId;
        purchParmLine.TableRefId = purchParmTable.TableRefId;
        purchParmLine.InitFromPurchLine(purchLine);
        purchParmLine.ReceiveNow = 200; //Qty
        purchParmLine.modifiedReceiveNow();
        purchParmLine.PreviousReceiveNow = vendPackingSlipTrans.Qty;
        purchParmLine.PreviousInventNow = vendPackingSlipTrans.InventQty;
        purchParmLine.setQty(DocumentStatus::PackingSlip, false);
        purchParmLine.setLineAmount();
        purchParmLine.insert();
    }
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
    purchFormLetter.parmVersioningUpdateType(VersioningUpdateType::Correction);
    purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
    purchFormLetter.parmCallerTable(vendPackingSlipJour);
    purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
    purchFormLetter.parmId(purchParmTable.ParmId);
    purchFormLetter.specQty(PurchUpdate::ReceiveNow);
    purchFormLetter.transDate(systemDateGet());
    purchFormLetter.proforma(false);
    purchFormLetter.run();
    ttsCommit;
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...