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
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();
{
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerTrialBalanceTmp trialBalanceTmp;
LedgerTrialBalanceDP trialBalanceDP = new LedgerTrialBalanceDP();
List selected = new List(Types::Enum);
MainAccount mainAccount;
MainAccount mainAccountOffset;
date fromDate = mkDate(1, 1, 2024); // Start date (adjust as needed)
date toDate = mkDate(31, 12, 2024); // End date (adjust as needed)
mainAccount = MainAccount::findByLedgerDimension(ledgerJournalTrans.LedgerDimension);
mainAccountOffset = MainAccount::findByLedgerDimension(ledgerJournalTrans.OffsetLedgerDimension);
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()
);
trialBalanceTmp = trialBalanceDP.getLedgerTrialBalanceTmp();
{
AmountCur closingBalance = trialBalanceTmp.EndingBalance;
{
// Display a warning message
info(strFmt("Warning: The ending balance for %1 exceeds the credit limit. Balance: %2",
DimensionAttributeValueCombination::find(trialBalanceTmp.LedgerDimension).DisplayValue,
closingBalance));
}
}
}