How to create payment in Dynamics AX 2012 Through X++


How to create payment in Dynamics AX 2012 Through X++

static void createPayment(Args _args)
{
    AxLedgerJournalTable                journalTable;
    AxLedgerJournalTrans                journalTrans;
 
    LedgerJournalTable                  ledgerJournalTable;
    LedgerJournalTrans                  ledgerJournalTrans;
    NumberSeq                               numberseq;
    MainAccountNum                    offsetAccount;
 
 
    // create journal table
    journalTable = new AxLedgerJournalTable();
    journalTable.parmJournalName('Payment Journal Name');
    journalTable.parmJournalType(LedgerJournalType::CustPayment);
    journalTable.save();

    ledgerJournalTable = journalTable.ledgerJournalTable();

    //create journal line
    journalTrans = AxLedgerJournalTrans::construct();
    journalTrans.parmJournalNum(ledgerJournalTable.JournalNum);


    numberseq = NumberSeq::NewGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalTable.ledgerJournalName().NumberSequenceTable).NumberSequence);
    journalTrans.parmVoucher(numberseq.voucher());
    journalTrans.parmTransDate(systemDateGet());
    journalTrans.parmCurrencyCode(Ledger::accountingCurrency());
    journalTrans.parmApproved(NoYes::Yes);

    journalTrans.parmAccountType(LedgerJournalACType::Cust);

    journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount('Customer account',LedgerJournalACType::Cust)) ;
    journalTrans.parmDefaultDimension(CustTable::find('Customer account').DefaultDimension);

    journalTrans.parmAmountCurDebit(0);
    journalTrans.parmAmountCurCredit(1000);
    journalTrans.parmTxt(strFmt('paymenet description'));
    journalTrans.parmPaymMode('Method of payment');


    JournalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
    journalTrans.clearField(fieldNum(LedgerJournalTrans,OffsetLedgerDimension),false);

    offsetAccount = '1000000';
    journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId([offsetAccount,offsetAccount,0])) ;


    journalTrans.save();
    ledgerJournalTrans = journalTrans.ledgerJournalTrans();
}

Comments

Popular posts from this blog

How to loop through enum in dynamics ax 2012 using x++

How to read from csv file in Dynamics AX 2012 Through X++

How to Create Transfer Journal in Dynamics AX 2012 Through X++