Friday, 2 September 2016

Creation and posting of Payment Journal through X++

Payment journal creation and Posting through code in AX 2012

class T_VendPaym
{
    public static void Main(Args _args)
    {
        Ledgerjournalname           ledgerjournalname;
        LedgerJournalTable          jourTable;
        LedgerJournalTrans          jourTrans;
        LedgerJournalCheckPost      jourPost;
        AccountNum                  accountNum;
        NumberSeq                   voucherNumSeq;
        NumberSequenceTable         numberSequenceTable;
        DimensionCombinationBase    dimensionCombinationBase;

        select ledgerjournalname where ledgerjournalname.JournalName == "VendPay";
        ttsbegin;
        jourTable.JournalName = ledgerjournalname.JournalName;
        jourTable.JournalNum  = JournalTableData::newTable(jourTable).nextJournalId();
        accountNum            = jourTable.JournalNum;
        jourTable.JournalType = LedgerJournalType::Payment;
        jourTable.insert();
       
        jourTrans.JournalNum = jourTable.JournalNum;
        numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(jourTable.JournalName).NumberSequenceTable);
        voucherNumSeq = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence);
        jourTrans.Voucher = voucherNumSeq.voucher();
        jourTrans.AccountType = LedgerJournalACType::Vend;
        jourTrans.CurrencyCode = "USD";
        jourTrans.initValue();
        jourTrans.TransDate = systemDateGet();
        dimensionCombinationBase = DimensionAttributeValueCombination::getDynamicDisplayValue("1003").RecId;
        jourTrans.LedgerDimension = DimensionAttributeValueCombination::find(dimensionCombinationBase,true,true).RecId;
        jourTrans.Txt = DimensionAttributeValueCombination::find(dimensionCombinationBase,true,true).DisplayValue;
        jourTrans.offsetAccountType = LedgerJournalACType::Bank;
        jourTrans.OffsetLedgerDimension = DimensionAttributeValueCombination::getDynamicDisplayValue("USMF EUR").RecId;
        jourTrans.AmountCurDebit =2000;
        jourTrans.PaymMode = "ELECTRONIC";
        jourTrans.BankTransType = "01";
        jourTrans.insert();
        ttscommit;
        
        info(strFmt("Journal '%1 %2' has been created", jourTable.JournalNum,jourTrans.Voucher));
        jourTable = LedgerJournalTable::find(accountNum);
        jourPost = LedgerJournalCheckPost::newLedgerJournalTable(jourTable,NoYes::Yes);
        jourPost.run();
    }

}

No comments:

Post a Comment