Tuesday, January 13, 2009

Auto Posting of Ledger Journal in AX

The tables used are LedgerJournalName, LedgerJournalTable, and LedgerJournalTrans.
The steps are:
• Create a journal table record {Table\LedgerJournalTable}
• Create lines for each transaction to be posted {Table\LedgerJournalTrans}.
• Post the journal. {Classes\LedgerJournalCheckPost}

Sample Code:



class Raj_LedgerJournal
{
LedgerJournalName ledgerJournalName;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberSeq;

LedgerJournalType journalType;

}

void JournalParameters()
{
str retStr;
;

retStr = this.PostingJournal("Cust_Daily","INR","900120",5000,"900110");
}

str PostingJournal(JournalNameId _JournalName, str _CurrencyCode, str _AccountNum, AmountMST _amount, str _offset)
{
#AviFiles
SysOperationProgress _progress;
str returnStr;
int i;
LineNum lineNum;
Amount amountMST;
;

amountMST = _amount;

/******** Progress Bar ********************************/

_progress = new SysOperationProgress();
_progress.setCaption("Posting");

_progress.setTotal(2);
_progress.setAnimation(#AviTransfer);

/******************** End Progress Bar ***********************/

/*********************** Creating Journal ************************/

ttsbegin;
select firstonly ledgerjournalName where ledgerJournalName.JournalName == _JournalName;
ledgerJournalTable.JournalName = LedgerJournalName.JournalName;
ledgerJournalTable.initFromLedgerJournalName();
// ledgerJournalTable.Name = "Rajdip Journal Description";
ledgerJournalTable.insert();

info(ledgerJournalTable.JournalNum);

/************************ End Creating Journal ****************************/




/************************* Creating Lines for Journal *************************/

numberSeq = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
ledgerJournalTrans.voucher = numberSeq.voucher();

++lineNum;

ledgerJournalTrans.LineNum = lineNum;
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.currencyCode = _CurrencyCode;
ledgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.currencyCode);
ledgerJournalTrans.AccountNum = _AccountNum;
ledgerJournalTrans.Dimension[1]= "Kolkata";
ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;

if(amountMST > 0)
ledgerJournalTrans.AmountCurDebit = amountMST;
else
ledgerJournalTrans.AmountCurCredit = -(amountMST);

ledgerJournalTrans.TransDate = today();
ledgerJOurnalTrans.Txt = 'Rajdip Das Ledger Post Demo';

ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerJournalTrans.OffsetAccount = _offset;
ledgerJournalTrans.insert();
returnStr = ledgerJournalTable.JournalNum;

/************************* End Creating Lines for Journal *************************/


ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);

_progress.setText(ledgerJournalTrans.voucher);

ledgerJournalCheckPost.run();
returnStr += ' please verify from AX.';
ttscommit;

return returnStr;
}


Static void main(Args a)
{
Raj_LedgerJournal ledgerJournal;
;

ledgerJournal = new Raj_LedgerJournal();

ledgerJournal.JournalParameters();
}

1 comment:

Dhruv Thakar said...

What is about LedgerDimension and OffsetLedgerDimension fields ?