web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

How to get Closing balance for offsetaccount in general journal

Posted on by
this my Hello dev,

I'm working on a business requirement, in general journals whenever general journal is posted I need to bring the closing balance of particular main account, that closing balance should come from the Trial Balance, I'm not able to figure it out! can somebody please suggest me how to bring the closing balance


Thanks in advance,


This is my code
 
[ExtensionOf(classStr(LedgerJournalPost))]
final class ADCG_LedgerJournalPost_Class_Extension
{
    public static void post(
        Common  _record,
        TableId _tableId,
        NoYes _transferErrors,
        boolean _splitLargeJournal,
        boolean _suppressClientMessages,
        str _callingFormName,
        LedgerJournalEngine _ledgerJournalEngine,
        boolean _skipIL_RU,
        LedgerJournalCheckPostResults _results_R,
        boolean _progressBarHide)
    {
        next post(_record,_tableId,_transferErrors,true,false,'',null,false,null,false);
      
        LedgerJournalPost::getClosingBalanceForMainAccount();
    }
    static void getClosingBalanceForMainAccount()
    {
        LedgerJournalTable ledgerJournalTable;
        LedgerJournalTrans ledgerJournalTrans;
        LedgerTrialBalanceTmp trialBalanceTmp;
        LedgerTrialBalanceDP trialBalanceDP = new LedgerTrialBalanceDP();
        List selected = new List(Types::Enum);
        MainAccount mainAccount;
        MainAccount mainAccountOffset;
        // Specify the date range for the trial balance
        date fromDate = mkDate(1, 1, 2024); // Start date (adjust as needed)
        date toDate = mkDate(31, 12, 2024); // End date (adjust as needed)
        // Get the main account and offset account
        mainAccount = MainAccount::findByLedgerDimension(ledgerJournalTrans.LedgerDimension);
        mainAccountOffset = MainAccount::findByLedgerDimension(ledgerJournalTrans.OffsetLedgerDimension);
        // Calculate balances for the main account
        LedgerTrialBalanceTmp::calculateBalances(
            trialBalanceTmp,
            mainAccount.MainAccountId, // Use the current main account number
        fromDate,
            toDate,
            false, // Opening balances
        false, // Closing balances
        false, // Include transactions
        selected,
            true, // Include financial dimensions
        true, // Include balances
        Ledger::current()
        );
        // Retrieve the calculated balance
        trialBalanceTmp = trialBalanceDP.getLedgerTrialBalanceTmp();
        if (trialBalanceTmp)
        {
            AmountCur closingBalance = trialBalanceTmp.EndingBalance;
            if (mainAccountOffset && closingBalance < mainAccountOffset.ADCG_CreditLimitReal)
            {
                // Display a warning message
                info(strFmt("Warning: The ending balance for %1 exceeds the credit limit. Balance: %2",
                        DimensionAttributeValueCombination::find(trialBalanceTmp.LedgerDimension).DisplayValue,
                        closingBalance));
            }
        }
    }

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans