[Event Parameter Request] Codeunit "Variable Allocation Mgt." - GetAccountBalance
Describe the request
Please add a new record parameter GenJournalLine to OnGetAccountBalance event in codeunit "Variable Allocation Mgt."
[IntegrationEvent(false, false)]
local procedure OnGetAccountBalance(var AllocAccountDistribution: Record "Alloc. Account Distribution"; StartDate: Date; EndDate: Date; var AccountBalance: Decimal; var ShareDistributions: Dictionary of [Guid, Decimal]; var TotalBalance: Decimal; var GenJournalLine: Record "Gen. Journal Line"; var Handled: Boolean);
begin
end;
The parameter is from the call stack:
GetOrGenerateAllocationLines (Codeunit 2677 "Gen. Journal Alloc. Acc. Mgt." line 18)
AllocationAccountMgt.GenerateAllocationLines() (Codeunit 2675 "Allocation Account Mgt." line 18)
AllocationAccountMgt.GenerateVariableAllocationLines() (Codeunit 2675 "Allocation Account Mgt." line 26)
VariableAllocationMgt.CalculateAmountDistributions() (Codeunit 2670 "Variable Allocation Mgt." line 11)
VariableAllocationMgt.CalculateVariableBalance() (Codeunit 2670 "Variable Allocation Mgt." line 81)
VariableAllocationMgt.GetAccountBalance() (Codeunit 2670 "Variable Allocation Mgt." line 102)
Additional context
It enables to get the account balance by the dimension of the general journal line.
Internal work item: AB#494527
Hello @KennyTangBS variable GenJournalLine is not available in the procedure GetAccountBalance Please review request
Hello @AleksandricMarko
Would it be possible to pass the ExistingDimensionSetId parameter from the procedure of GenerateVariableAllocationLines (Codeunit 2675 "Allocation Account Mgt." line 26) to the below procedures?
VariableAllocationMgt.CalculateAmountDistributions() (Codeunit 2670 "Variable Allocation Mgt." line 11)
internal procedure CalculateAmountDistributions(var AllocationAccount: Record "Allocation Account"; AmountToDistribute: Decimal; var AmountDistributions: Dictionary of [Guid, Decimal]; var ShareDistributions: Dictionary of [Guid, Decimal]; PostingDate: Date; CurrencyCode: Code[10]; ExistingDimensionSetId: Integer)
var
GeneralLedgerSetup: Record "General Ledger Setup";
Currency: Record Currency;
AccountSystemID: Guid;
AccountBalance: Decimal;
TotalBalance: Decimal;
AmountDistribution: Decimal;
TotalDistributedAmount: Decimal;
FixedShareDistributions: Dictionary of [Guid, Decimal];
AmountRoundingPercision: Decimal;
begin
CalculateVariableBalance(AllocationAccount, ShareDistributions, TotalBalance, PostingDate, ExistingDimensionSetId);
FixBalances(ShareDistributions, FixedShareDistributions, TotalBalance);
GeneralLedgerSetup.Get();
AmountRoundingPercision := GeneralLedgerSetup."Amount Rounding Precision";
if CurrencyCode <> '' then
if Currency.Get(CurrencyCode) then
AmountRoundingPercision := Currency."Amount Rounding Precision";
foreach AccountSystemID in FixedShareDistributions.Keys() do begin
FixedShareDistributions.Get(AccountSystemID, AccountBalance);
if TotalBalance <> 0 then
AmountDistribution := Round(AmountToDistribute * AccountBalance / TotalBalance, AmountRoundingPercision);
AmountDistributions.Add(AccountSystemID, AmountDistribution);
TotalDistributedAmount += AmountDistribution;
end;
if TotalDistributedAmount = AmountToDistribute then
exit;
AmountDistributions.Get(AccountSystemID, AccountBalance);
AccountBalance += AmountToDistribute - TotalDistributedAmount;
AmountDistributions.Set(AccountSystemID, AccountBalance);
end;
VariableAllocationMgt.CalculateVariableBalance() (Codeunit 2670 "Variable Allocation Mgt." line 81)
internal procedure CalculateVariableBalance(var AllocationAccount: Record "Allocation Account"; var ShareDistributions: Dictionary of [Guid, Decimal]; var TotalBalance: Decimal; PostingDate: Date; ExistingDimensionSetId: Integer)
var
AllocAccountDistribution: Record "Alloc. Account Distribution";
AccountBalance: Decimal;
StartDate: Date;
EndDate: Date;
begin
Clear(TotalBalance);
Clear(ShareDistributions);
AllocAccountDistribution.SetRange("Allocation Account No.", AllocationAccount."No.");
if not AllocAccountDistribution.FindSet() then
exit;
repeat
CalculateDateFilterForDistributionAccount(AllocAccountDistribution, StartDate, EndDate, PostingDate);
GetAccountBalance(AllocAccountDistribution, StartDate, EndDate, AccountBalance, ShareDistributions, TotalBalance, ExistingDimensionSetId);
ShareDistributions.Add(AllocAccountDistribution.SystemId, AccountBalance);
TotalBalance += AccountBalance;
until AllocAccountDistribution.Next() = 0;
end;
VariableAllocationMgt.GetAccountBalance() (Codeunit 2670 "Variable Allocation Mgt." line 102)
internal procedure GetAccountBalance(var AllocAccountDistribution: Record "Alloc. Account Distribution"; StartDate: Date; EndDate: Date; var AccountBalance: Decimal; var ShareDistributions: Dictionary of [Guid, Decimal]; TotalBalance: Decimal; ExistingDimensionSetId: Integer)
var
BankAccountLedgerEntry: Record "Bank Account Ledger Entry";
GLEntry: Record "G/L Entry";
Handled: Boolean;
begin
OnGetAccountBalance(AllocAccountDistribution, StartDate, EndDate, AccountBalance, ShareDistributions, TotalBalance, Handled, ExistingDimensionSetId);
if Handled then
exit;
case AllocAccountDistribution."Breakdown Account Type" of
AllocAccountDistribution."Breakdown Account Type"::"Bank Account":
begin
BankAccountLedgerEntry.SetRange("Posting Date", StartDate, EndDate);
BankAccountLedgerEntry.SetRange("Bank Account No.", AllocAccountDistribution."Breakdown Account Number");
if AllocAccountDistribution."Dimension 1 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Global Dimension 1 Code", AllocAccountDistribution."Dimension 1 Filter");
if AllocAccountDistribution."Dimension 2 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Global Dimension 2 Code", AllocAccountDistribution."Dimension 2 Filter");
if AllocAccountDistribution."Dimension 3 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Shortcut Dimension 3 Code", AllocAccountDistribution."Dimension 3 Filter");
if AllocAccountDistribution."Dimension 4 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Shortcut Dimension 4 Code", AllocAccountDistribution."Dimension 4 Filter");
if AllocAccountDistribution."Dimension 5 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Shortcut Dimension 5 Code", AllocAccountDistribution."Dimension 5 Filter");
if AllocAccountDistribution."Dimension 6 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Shortcut Dimension 6 Code", AllocAccountDistribution."Dimension 6 Filter");
if AllocAccountDistribution."Dimension 7 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Shortcut Dimension 7 Code", AllocAccountDistribution."Dimension 7 Filter");
if AllocAccountDistribution."Dimension 8 Filter" <> '' then
BankAccountLedgerEntry.SetFilter("Shortcut Dimension 8 Code", AllocAccountDistribution."Dimension 8 Filter");
BankAccountLedgerEntry.ReadIsolation := IsolationLevel::ReadCommitted;
BankAccountLedgerEntry.CalcSums("Amount (LCY)");
AccountBalance := BankAccountLedgerEntry."Amount (LCY)";
end;
AllocAccountDistribution."Breakdown Account Type"::"G/L Account":
begin
GLEntry.SetRange("Posting Date", StartDate, EndDate);
GLEntry.SetRange("G/L Account No.", AllocAccountDistribution."Breakdown Account Number");
if AllocAccountDistribution."Business Unit Code Filter" <> '' then
GLEntry.SetFilter("Business Unit Code", AllocAccountDistribution."Business Unit Code Filter");
if AllocAccountDistribution."Dimension 1 Filter" <> '' then
GLEntry.SetFilter("Global Dimension 1 Code", AllocAccountDistribution."Dimension 1 Filter");
if AllocAccountDistribution."Dimension 2 Filter" <> '' then
GLEntry.SetFilter("Global Dimension 2 Code", AllocAccountDistribution."Dimension 2 Filter");
if AllocAccountDistribution."Dimension 3 Filter" <> '' then
GLEntry.SetFilter("Shortcut Dimension 3 Code", AllocAccountDistribution."Dimension 3 Filter");
if AllocAccountDistribution."Dimension 4 Filter" <> '' then
GLEntry.SetFilter("Shortcut Dimension 4 Code", AllocAccountDistribution."Dimension 4 Filter");
if AllocAccountDistribution."Dimension 5 Filter" <> '' then
GLEntry.SetFilter("Shortcut Dimension 5 Code", AllocAccountDistribution."Dimension 5 Filter");
if AllocAccountDistribution."Dimension 6 Filter" <> '' then
GLEntry.SetFilter("Shortcut Dimension 6 Code", AllocAccountDistribution."Dimension 6 Filter");
if AllocAccountDistribution."Dimension 7 Filter" <> '' then
GLEntry.SetFilter("Shortcut Dimension 7 Code", AllocAccountDistribution."Dimension 7 Filter");
if AllocAccountDistribution."Dimension 8 Filter" <> '' then
GLEntry.SetFilter("Shortcut Dimension 8 Code", AllocAccountDistribution."Dimension 8 Filter");
GLEntry.ReadIsolation := IsolationLevel::ReadCommitted;
GLEntry.CalcSums(Amount);
AccountBalance := GLEntry.Amount;
end;
end;
end;
VariableAllocationMgt.OnGetAccountBalance() (Codeunit 2670 "Variable Allocation Mgt." line 341)
[IntegrationEvent(false, false)]
local procedure OnGetAccountBalance(var AllocAccountDistribution: Record "Alloc. Account Distribution"; StartDate: Date; EndDate: Date; var AccountBalance: Decimal; var ShareDistributions: Dictionary of [Guid, Decimal]; var TotalBalance: Decimal; var Handled: Boolean; ExistingDimensionSetId: Integer);
begin
end;
Hi @KennyTangBS
Unfortunately, we can`t do it like this, at least not as event request. Please try to find some other solution, maybe to create event publisher somewhere else.