Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

How to get Closing balance for offsetaccount in general journal

Posted on by 15
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));
            }
        }
    }
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,584 Super User on at
    How to get Closing balance for offsetaccount in general journal
    Hi,
     
    Can you tell me what is the exact requirement? What do you mean by bringing the closing balance? What is the exact functional requirement about? The warning in the coding also gives a hint about a credit limit, but I don't have any idea what business problem you are trying to solve.
     
    What is the current behavior of the code you shared and what is your expectation? Or do you get errors? 

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans