General journal creation and posting

General journal creation
Finantial dimensions merge / combine

protected LedgerJournalTable createLedgerJournalTable(Currency _currency)
{
    LedgerJournalTable ledgerJournalTable;

    ledgerJournalTable.clear();
    ledgerJournalTable.initValue();
    ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
    ledgerJournalTable.initFromLedgerJournalName(_currency.VKDiscrepancyJournalName);
    // journal description, should be after initFromLedgerJournalName
    ledgerJournalTable.Name = strFmt('%1: %2', _currency.CurrencyCode, ledgerJournalTable.Name);
    ledgerJournalTable.CurrencyCode = _currency.CurrencyCode;
    ledgerJournalTable.insert();

    return ledgerJournalTable;
}


protected DimensionDefault getDimensionDefaultValue(DimensionDefault _account, DimensionDefault _defaultDimensions = 0)
{
    container           accPattern;
    MainAccountNum      mainAccountNum;
    DimensionDefault    dimensionDefault;
    Map                 dimSpecifiers;
    MapEnumerator       enumerator;
    DimensionValue      dimValue;
    
    // accPattern = ["420100", "420100", 0];
    // ['acount display value', 'mainAccountId', count of dimensions pairs, dimension name, dimension value, ...]
    // [“131100”,”131100″, 1, “COUNTRY”,”USA”];
    
    mainAccountNum  = DimensionAttributeValueCombination::getMainAccountFromLedgerDimension(_account);
    accPattern      = [MainAccountNum, MainAccountNum];
    
    if (_defaultDimensions)
    {
        dimSpecifiers   = DimensionDefaultingEngine::getDefaultDimensionSpecifiers(_defaultDimensions);
        accPattern      += dimSpecifiers.elements();
    
        if (dimSpecifiers.elements())
        {
            enumerator      = dimSpecifiers.getEnumerator();
            while (enumerator.moveNext())
            {
                dimValue = enumerator.currentValue();
                accPattern += dimensionAttribute::find(enumerator.currentKey()).Name;
                accPattern += dimValue;
            }
        }
    }
    else
    {
        accPattern += 0;
    }
    
    dimensionDefault = AxdDimensionUtil::getLedgerAccountId(accPattern);
    
    return dimensionDefault;
}

protected void createLedgerJournalTrans(
    Currency                _currency,
    LedgerJournalTable      _ledgerJournalTable,
    VKDiscrepancyContainer  _discrepancyContainer)
{
    AxLedgerJournalTrans        axLedgerJournalTrans;
    RetailStoreTenderTypeTable  retailStoreTenderTypeTable = this.getRetailStoreTenderTypeTable(_discrepancyContainer.parmChannel());
    RetailStoreTable            retailStoreTable = this.getRetailStoreTable(_discrepancyContainer.parmChannel());
    ;

    axLedgerJournalTrans = new AxLedgerJournalTrans();

    axLedgerJournalTrans.parmJournalNum(_ledgerJournalTable.JournalNum);
    axLedgerJournalTrans.parmTransDate(systemDateGet());
    axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger);
    //ledgerDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(_currency.VKDiscrepancyLedgerDimension, retailStoreTable.DefaultDimension);
    axLedgerJournalTrans.parmLedgerDimension(this.getDimensionDefaultValue(_currency.VKDiscrepancyLedgerDimension, retailStoreTable.DefaultDimension));

    // axLedgerJournalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger); // if called then parmOffsetLedgerDimension will not set the value
    axLedgerJournalTrans.parmOffsetLedgerDimension(this.getDimensionDefaultValue(retailStoreTenderTypeTable.LedgerDimension, retailStoreTable.DefaultDimension));
    
    if (_discrepancyContainer.parmAmount() > 0)
    {
        axLedgerJournalTrans.parmAmountCurDebit(_discrepancyContainer.parmAmount());
    }
    else
    {
        axLedgerJournalTrans.parmAmountCurCredit(-_discrepancyContainer.parmAmount());
    }
    axLedgerJournalTrans.parmTxt(_discrepancyContainer.parmStore());

    axLedgerJournalTrans.save();
}
Posting:
static void VKPostGeenralJournal(Args _args)
{
    LedgerJournalTable      ledgerJournalTable = LedgerJournalTable::find('VK-000178');
    LedgerJournalCheckPost  ledgerJournalCheckPost;

    ttsBegin;
    ledgerJournalCheckPost  = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
    ledgerJournalCheckPost.run();
    ttsCommit;

    info('done');
}

Links:
Using AX classes
http://axaptacorner.blogspot.com/2012/09/how-to-create-general-journal-in-ax.html
https://dynamicsuser.net/ax/f/developers/91657/create-and-post-general-journal-through-x
Direct to table:
http://msmax2012tech.blogspot.com/2017/07/create-general-journal-from-x-code-in.html

Merging dimensions:
https://axforce.wordpress.com/2015/10/21/merging-financial-dimensions-more-easily-in-x/


Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags