Posts Tagged ‘Dynamics’

Introduction

Ledger is the ending point for all financial transactions. Posting to the ledger is the most critical API in any ERP system. Failure to use the APIs properly will lead to inaccurate financial statements. Every subsystem eventually needs to get their base transaction data into the ledger. This document discuss the functionality and APIs for posting to the ledger.

Ledger structure

The Microsoft Dynamics AX ledger is defined in a manner very similar to manual accounting systems. The ledger contains all adjustment amounts, dates, and related information for all ledger accounts. Any transaction that originates in a subledger, such as customer, vendor, bank, or fixed asset transaction, eventually needs to adjust ledger accounts so that the transaction amounts can be reported on financial statements.

The ledger entries are grouped by journal number and further grouped by voucher number. The journal number is a unique number that identifies a group of ledger adjustments generated through one posting. The adjustments within a journal number can be subgrouped by voucher number. The voucher number could represent a single transaction or a group of related transactions, depending on how the customer has set up their journals. While journal numbers must be unique, voucher numbers may permit duplicates if set up to do so. The adjustments must balance against each other on both a per voucher and journal number basis.

 

High-level processes

Ledger posting is never initiated directly by the end user. Instead, it is run by processes initiated by the user. When the user posts a purchase order invoice or performs a task, such as inventory closing, the ledger posting APIs are called to generate the required transaction in General Ledger.

Ledger journal API to LedgerVoucher

Any module that implements a new journal will extend journal classes and forms required for the new journal type. Extending the classes should provide the means to generate LedgerJournalTable and LedgerJournalTrans records. Posting of the new journal type should be handled by the base classes.

The following is an example of the APIs used to post a journal.

Example: LedgerJournalCheckPost.postJournal

ledgerVoucher = LedgerVoucher::newLedgerPost();
 
if a ledgerJournalTable record was read
    validate the ledgerJournalTable record
for each ledgerJournalTrans
    if a new voucher is needed
        LVO = LedgerVoucherObject::newVoucher();
        ledgerVoucher.addVoucher(LVO, ...);
 
for each account and amount to post on the ledgerJournalTrans
    // the method creates the necessary ledgerTrans records to post
    ok = this.postTrans();
// post the vouchers after all ledgerJournalTrans records have been read
ledgerVoucher.end();

 

Non-Ledger journal API to LedgerVoucher

All sub module transactions that post using transaction data from tables other than LedgerJournalTable and LedgerJournalTrans use these APIs to post.

Example: InventoryPostPhysicalPeriodic.postLedgerTrans

ledgerVoucher = LedgerVoucher::newLedgerPost();

transactionTxt = new TransactionTxt();
transactionTxt.setType();
transactionTxt.setVoucher();

// create a new voucher for posting the items together
ledgerVoucherObject = LedgerVoucherObject::newVoucher();

// assign the text to the voucher object and add to the voucher
ledgerVoucherObject.lastTransTxt(transactionTxt.txt());
ledgerVoucher.addVoucher(ledgerVoucherObject);

// if there is a header record to post loop through the lines and add a transaction 
// to the voucher object for each record.

if (inventPostPhysicalTable)
{
    for each inventPOstPhysicalTrans record to post
    {
        // use ledgerVoucher.findLedgerVoucherObject() to retrieve the last voucher object
        // added to the ledgerVoucher. This insures the correct voucher object is used when 
        // creating the LedgerVoucherTransObject
        LVTO = LedgerVoucherTransObject::newCreateTrans(
                                              ledgerVoucher.findLedgerVoucherObject(), ...);
        
        ledgerVoucher.addTrans(LVTO);
    }
}

// this completes the building of the ledgerVoucher.
// the call to end() will initiate the posting of the ledgerVoucher.
ledgerVoucher.end();

 

Multiple entry non-Ledger journal API to LedgerVoucher

All sub module transactions that post using transaction data from tables other than LedgerJournalTable and LedgerJournalTrans use these APIs to post when multiple journal entries are required.

Example: TaxWithhold.posttaxWithhold

ledgerVoucherGroup = LedgerVoucherGroup::construct();

for each record (<multiple posting table>)
    changecompany(<company of transaction>)
    {
        for each record (<table containing records for the transactions>)
        {
            if (<The criteria for a separate journal entry is met>)
            {
                // get the number sequence specified to generate a voucher number.
                numberSeqRef = <where number sequence is specified>
                numberSeq = NumberSeq::newGetVoucher(numberSeqRef);

                // This is the journal entry for the transaction for the current company
                LedgerVoucher = LedgerVoucher::newLedgerPost();

                // add the voucher to the group
                ledgerVoucherGroup.addLedgerVoucher(LedgerVoucher);
            }

            LVO - LedgerVoucherObject::newVoucher();

            // get the next voucher number and add it to the voucher
            LedgerVoucher.addVoucher(LVO, ...);

            taxWithholdTransLedgerVoucher.findLedgerVoucherObject();

            // use ledgerVoucher.findLedgerVoucherObject() to retrieve the last voucher object
            // added to the ledgerVoucher. This insures the correct voucher object is used when 
            // creating the LedgerVoucherTransObject
            LVTO = LedgerVoucherTransObject::newCreateTrans(
                               ledgerVoucher.findLedgerVoucherObject(), ...);

             // add the transaction to the voucher
             ledgerVoucher.addTrans(LVTO);
         }
    }
}

// this completes the building of the ledgerVoucher.
// the call to end() will initiate the posting of the ledgerVoucherGroup.
ledgerVoucherGroup.end();