How to using code post packingSlip on Quality Orders Form[AX2009]

For simple user operation posting packing slip with purchase order. we added a function button on Quality Orders Form.

// VAR Changed by Xie Yu Fan.Fandy 谢宇帆
void  YIP_PostPurchPackingSlip()
{
    PurchFormLetter_PackingSlip purchFormLetter;
    SysQueryRun                 chooseLinesQuery;

    PurchParmUpdate         purchParmUpdate;
    PurchLine               purchLine;
    PurchParmTable          purchParmTable;
    PurchParmLine           purchParmLine;
    InventDim               inventDim;
    ;
    ttsbegin;
    chooseLinesQuery = new SysQueryRun(querystr(PurchUpdate));

    chooseLinesQuery.query().dataSourceTable(tablenum(PurchTable)).addRange(fieldnum(PurchTable, PurchId)).value(queryValue(this.InventRefId));
    chooseLinesQuery.query().dataSourceTable(tablenum(PurchLine)).addRange(fieldnum(PurchLine, InventTransId)).value(queryValue(this.InventRefTransId));

    chooseLinesQuery.query().interactive(false);
    chooseLinesQuery.saveUserSetup      (false);

    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);

    purchFormLetter.chooseLinesQuery        (chooseLinesQuery);
    purchFormLetter.purchTable              (PurchTable::find(this.InventRefId));
    purchFormLetter.transDate               (systemdateget());
    purchFormLetter.specQty                 (PurchUpdate::All);
    purchFormLetter.printFormLetter         (NoYes::No);
    purchFormLetter.splitDeliveryInformation(NoYes::No);
    purchFormLetter.sumBy                   (AccountOrder::None);

    purchFormLetter.createParmUpdate(false);
    purchFormLetter.chooseLines();
    purchFormLetter.setForUpdatePurchParmTable();

    purchParmTable      = purchFormLetter.currentPurchParmTable();
    if (!purchParmTable)
        throw Exception::Break;

    purchParmLine       = purchParmLine::findInventTransId(purchParmTable.ParmId,this.InventRefTransId,true);
    if (!purchParmLine)
        throw Exception::Break;

    inventDim                   = this.inventDim();
    purchParmLine.InventDimId   = InventDim::findOrCreate(inventDim).inventDimId;
    purchLine                   = PurchLine::findInventTransId(this.InventRefTransId);
    [purchParmLine.ReceiveNow,  purchParmLine.RemainBefore      , purchParmLine.RemainAfter      ] = purchFormLetter.qtyPurch (purchLine, purchLine.YIP_calcPurchQty(this.Qty));
    [purchParmLine.InventNow,   purchParmLine.RemainBeforeInvent, purchParmLine.RemainAfterInvent] = purchFormLetter.qtyInvent(purchLine, this.Qty);
    purchParmLine.setLineAmount(purchParmLine.ReceiveNow,purchLine);
    purchParmLine.update();

    purchFormLetter.reArrangeNow(true);
    purchFormLetter.YIP_parmFromExternalRun(true);
    purchFormLetter.saveLast();
    ttscommit;
    if (purchFormLetter.prompt())
    {
        try
        {
            ttsbegin;
            purchFormLetter.run();
            this.YIP_QCStatus = YIP_QCStatus::PackingSlip;
            this.doUpdate();
            ttscommit;
        }
        catch(exception::Error)
        {
            ttsabort;
            throw error("Catch an error exception.");
        }
        catch(exception::CLRError)
        {
            ttsabort;
            throw error(AifUtil::getClrErrorMessage());
        }
    }
}
原文地址:https://www.cnblogs.com/Fandyx/p/3620571.html