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));
}
}
}