AX 过账自由文本发票

通过代码产生自由文本发票,并过账该文本发票。

View Code
static void FreeTextInvoicePost(CustAccount _custAccount, LedgerAccount _ledgerAccount)
{
    CustInvoiceTable    custInvoiceTable;
    CustInvoiceLine     custInvoiceLine;
    CustTable           custTable;
    LedgerTable         ledgerTable;
    CustPostInvoice     custPostInvoice;
    LineNum             lineNum;
    int                 i;
    ;

    /// <summary>
    /// The <c>CustInvoiceTable</c> logic is implemented to create single <c>Header</c>.
    /// </summary>
    ttsbegin;
    custTable = CustTable::find(_custAccount);
    custInvoiceTable.initFromCustTable(custTable);
    custInvoiceTable.insert();
    ttscommit;

    /// <summary>
    /// The <c>CustInvoiceLine</c> logic is implemented to create multiple <c>Invoice Lines</c>.
    /// </summary>
    for (i = 1; i <= 100; i++)
    {
        ttsbegin;
        ledgerTable = LedgerTable::find(_ledgerAccount);
        custInvoiceLine.clear();
        custInvoiceLine.initValue();
        custInvoiceLine.LedgerAccount = ledgerTable.AccountNum;
        custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);
        custInvoiceLine.AmountCur = 10.00;
        custInvoiceLine.Description = "Free Text Invoice"+ int2str(i);
        custInvoiceLine.TaxItemGroup = "full";
        custInvoiceLine.ParentRecId = custInvoiceTable.RecId;

        //LINE NUM LOGIC.
        if(!lineNum)
        {
         lineNum = CustInvoiceLine::lastLineNum(custInvoiceLine.ParentRecId);
        }

        lineNum += 1;
        custInvoiceLine.LineNum = lineNum;
        custInvoiceLine.insert();
        ttscommit;
    }

    /// <summary>
    /// The <c>custPostInvoice</c> class is called for posting <c>Free-TextInvoice.</c> records.
    /// </summary>
    custPostInvoice = new CustPostInvoice(custInvoiceTable);
    custPostInvoice.run();
}

运行得到结果

原文地址:https://www.cnblogs.com/dingkui/p/2687093.html