Showing posts with label posting. Show all posts
Showing posts with label posting. Show all posts

Sunday, November 16, 2008

Financial posting in dynamics ax

Question: How to use the exisitng posting to ledger API. Is there any documentation available.

Answer: The API documentation can be found at http://download.microsoft.com/download/d/b/a/dba4455a-25c1-495c-bad2-3b316e0e2434/PostToLedger.pdf . Also I have written a blog entry for this you can check that out as well.

Friday, April 4, 2008

Posting in the General Ledger (GL)


Question:
How to create a posting entry in General Ledger (GL) module of Dynamics AX?

Answer:
There are many ways to create posting entries in to General Ledger module. In my experience the simplest way is to use the Journal classes. There are two parts of posting create a heade entry and then create the add lines to it. To create a header entry use the LedgerJournalTable table and use the LedgerJournalTrans table. Finally use the ledgerJournalCheckPost class object to post these entries into the system.
Below is a job explaing the Posting process in a simple way.
static void postVoucherThroughJournal(Args _args)
{
Dialog dialog = new Dialog("Ledger Posting Example");
DialogField ledgerAccountField;
DialogField offsetAccountField;
DialogField ledgerJournalDescription;
DialogField ledgerAmount;
DialogField ledgerTransDescription;

LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberSeq;
;
dialog.addGroup("Post Ledger Voucher");
//Add Fields
ledgerAccountField = dialog.addField(typeid(LedgerAccount), "Ledger Account");
offsetAccountField = dialog.addField(typeid(LedgerAccount), "Offset Account");
ledgerJournalDescription = dialog.addField(typeid(Name), "Journal Name");
ledgerAmount = dialog.addField(typeid(AmountCurDebit), "Debit Amount");
ledgerTransDescription = dialog.addField(typeid(Name), "Transaction Text");

if(dialog.run())
{
ttsbegin;
//STEP1: INSERT Journal Header
ledgerJournalTable.JournalName = 'Day1'; /This is the journal name.
ledgerJournalTable.initFromLedgerJournalName();
ledgerJournalTable.Name = ledgerJournalDescription.value();
ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
ledgerJournalTable.insert();

//STEP2: INSERT Journal Details
numberSeq = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find(ledgerJournalTable.JournalName).VoucherSeries);
ledgerJournalTrans.Voucher = numberSeq.voucher();
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.CurrencyCode = CompanyInfo::standardCurrency();
ledgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.CurrencyCode);
ledgerJournalTrans.AccountNum = ledgerAccountField.value();
ledgerJournalTrans.AmountCurDebit = ledgerAmount.value();
ledgerJournalTrans.TransDate = Today();
ledgerJournalTrans.OffsetAccount = offsetAccountField.value();
ledgerJournalTrans.Txt = ledgerTransDescription.value();
ledgerJournalTrans.insert();
//Post Journal into Ledger Accounts
ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
ledgerJournalCheckPost.run();
ttscommit;
Info(StrFmt("Journal %1 is posted", ledgerJournalTable.JournalNum));
}
}