Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ using Microsoft.Finance.Consolidation;
#endif
using Microsoft.Finance.Dimension;
using Microsoft.Finance.GeneralLedger.Account;
using Microsoft.Finance.GeneralLedger.Ledger;
#if not CLEAN27
using System.Environment.Configuration;
#endif
Expand Down Expand Up @@ -147,18 +146,14 @@ codeunit 4410 "Trial Balance"
local procedure InsertTrialBalanceDataForGLAccountWithFilters(var GLAccount: Record "G/L Account"; Dimension1ValueCode: Code[20]; Dimension2ValueCode: Code[20]; BusinessUnitCode: Code[20]; var TrialBalanceData: Record "EXR Trial Balance Buffer"; var Dimension1Values: Record "Dimension Value" temporary; var Dimension2Values: Record "Dimension Value" temporary)
var
GLAccount2: Record "G/L Account";
GLEntry: Record "G/L Entry";
begin
Clear(TrialBalanceData);
if GLAccount.GetFilter("Date Filter") <> '' then begin
GLEntry.SetFilter("Posting Date", GLAccount.GetFilter("Date Filter"));
if GLEntry.FindFirst() then begin
GLAccount2.Copy(GLAccount);
GLAccount2.SetFilter("Date Filter", '..%1', GLEntry."Posting Date" - 1);
GLAccount2.CalcFields("Balance at Date", "Add.-Currency Balance at Date");
TrialBalanceData.Validate("Starting Balance", GLAccount2."Balance at Date");
TrialBalanceData.Validate("Starting Balance (ACY)", GLAccount2."Add.-Currency Balance at Date");
end;
GLAccount2.Copy(GLAccount);
GLAccount2.SetFilter("Date Filter", '..%1', ClosingDate(GLAccount2.GetRangeMin("Date Filter") - 1));
GLAccount2.CalcFields("Balance at Date", "Add.-Currency Balance at Date");
TrialBalanceData.Validate("Starting Balance", GLAccount2."Balance at Date");
TrialBalanceData.Validate("Starting Balance (ACY)", GLAccount2."Add.-Currency Balance at Date");
end;
GlAccount.CalcFields("Net Change", "Balance at Date", "Additional-Currency Net Change", "Add.-Currency Balance at Date", "Budgeted Amount", "Budget at Date");
TrialBalanceData."G/L Account No." := GlAccount."No.";
Expand Down Expand Up @@ -244,7 +239,7 @@ codeunit 4410 "Trial Balance"
EXRTrialBalanceQuery.Close();

// And now we get the balances at the starting date and modify the ones we have already inserted
EXRTrialBalanceQuery.SetFilter(EXRTrialBalanceQuery.PostingDate, '..%1', StartDate - 1);
EXRTrialBalanceQuery.SetFilter(EXRTrialBalanceQuery.PostingDate, '..%1', ClosingDate(StartDate - 1));
EXRTrialBalanceQuery.Open();
while EXRTrialBalanceQuery.Read() do begin
TrialBalanceData.SetRange("G/L Account No.", EXRTrialBalanceQuery.AccountNumber);
Expand Down Expand Up @@ -296,7 +291,7 @@ codeunit 4410 "Trial Balance"
EXRTrialBalanceBUQuery.Close();

// And now we get the balances at the starting date and modify the ones we have already inserted
EXRTrialBalanceBUQuery.SetFilter(EXRTrialBalanceBUQuery.PostingDate, '..%1', StartDate - 1);
EXRTrialBalanceBUQuery.SetFilter(EXRTrialBalanceBUQuery.PostingDate, '..%1', ClosingDate(StartDate - 1));
EXRTrialBalanceBUQuery.Open();
while EXRTrialBalanceBUQuery.Read() do begin
TrialBalanceData.SetRange("G/L Account No.", EXRTrialBalanceBUQuery.AccountNumber);
Expand Down Expand Up @@ -441,16 +436,11 @@ codeunit 4410 "Trial Balance"

local procedure GetRangeDatesForGLAccountFilter(GLAccountDateFilter: Text; var StartDate: Date; var EndDate: Date)
var
GLEntry: Record "G/L Entry";
GLAccount: Record "G/L Account";
begin
GLEntry.SetFilter("Posting Date", GLAccountDateFilter);
GLEntry.SetLoadFields("Posting Date");
GLEntry.SetCurrentKey("Posting Date");
GLEntry.SetAscending("Posting Date", true);
if GLEntry.FindFirst() then
StartDate := GLEntry."Posting Date";
if GLEntry.FindLast() then
EndDate := GLEntry."Posting Date";
GLAccount.SetFilter("Date Filter", GLAccountDateFilter);
StartDate := GLAccount.GetRangeMin("Date Filter");
EndDate := GLAccount.GetRangeMax("Date Filter");
if StartDate = 0D then
StartDate := WorkDate();
if EndDate = 0D then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,42 @@ codeunit 139544 "Trial Balance Excel Reports"
Assert.AreEqual(NonZeroAccount, TrialBalanceData."G/L Account No.", 'The non-zero account should be the one returned');
end;

[Test]
procedure QueryPathStartingBalanceIncludesClosingDateEntries()
var
GLAccount: Record "G/L Account";
TempDimensionValue: Record "Dimension Value" temporary;
TrialBalanceData: Record "EXR Trial Balance Buffer";
TrialBalance: Codeunit "Trial Balance";
PostingAccount: Code[20];
ActivityAmount: Decimal;
PriorYear: Integer;
begin
// [SCENARIO] Starting Balance includes closing date entries from the prior fiscal year, emulating what "Close Income Statement" produces.
// [GIVEN] A posting account with activity during the prior year
Initialize();
CreateGLAccount(GLAccount);
PostingAccount := GLAccount."No.";
PriorYear := Date2DMY(WorkDate(), 3) - 1;
ActivityAmount := 5000;
CreateGLEntryWithAmount(PostingAccount, '', '', '', DMY2Date(15, 6, PriorYear), ActivityAmount);
// [GIVEN] A closing entry on ClosingDate(31/12) that zeroes out the account (emulates Close Income Statement)
CreateGLEntryWithAmount(PostingAccount, '', '', '', ClosingDate(DMY2Date(31, 12, PriorYear)), -ActivityAmount);
// [GIVEN] An entry on the first day of the current year so the old FindFirst logic derives cutoff ..31/12 (normal date), which misses C31/12
CreateGLEntryWithAmount(PostingAccount, '', '', '', DMY2Date(1, 1, Date2DMY(WorkDate(), 3)), 100);

// [WHEN] Running the trial balance for the current year
GLAccount.SetRange("No.", PostingAccount);
GLAccount.SetRange("Date Filter", DMY2Date(1, 1, Date2DMY(WorkDate(), 3)), DMY2Date(31, 12, Date2DMY(WorkDate(), 3)));
TrialBalance.ConfigureTrialBalance(false, false);
TrialBalance.InsertTrialBalanceReportData(GLAccount, TempDimensionValue, TempDimensionValue, TrialBalanceData);

// [THEN] Starting Balance is zero because the closing entry zeroed out the account
TrialBalanceData.SetRange("G/L Account No.", PostingAccount);
TrialBalanceData.FindFirst();
Assert.AreEqual(0, TrialBalanceData."Starting Balance", 'Starting Balance should be zero after closing entries')
end;

local procedure CreateSampleBusinessUnits(HowMany: Integer)
var
BusinessUnit: Record "Business Unit";
Expand Down Expand Up @@ -746,12 +782,14 @@ codeunit 139544 "Trial Balance Excel Reports"
[RequestPageHandler]
procedure EXRTrialBalanceExcelHandler(var EXRTrialBalanceExcel: TestRequestPage "EXR Trial Balance Excel")
begin
EXRTrialBalanceExcel.GLAccounts.SetFilter("Date Filter", Format(DMY2Date(1, 1, Date2DMY(WorkDate(), 3))) + '..' + Format(DMY2Date(31, 12, Date2DMY(WorkDate(), 3))));
EXRTrialBalanceExcel.OK().Invoke();
end;

[RequestPageHandler]
procedure EXRTrialBalanceBudgetExcelHandler(var EXRTrialBalanceBudgetExcel: TestRequestPage "EXR Trial BalanceBudgetExcel")
begin
EXRTrialBalanceBudgetExcel.GLAccounts.SetFilter("Date Filter", Format(DMY2Date(1, 1, Date2DMY(WorkDate(), 3))) + '..' + Format(DMY2Date(31, 12, Date2DMY(WorkDate(), 3))));
EXRTrialBalanceBudgetExcel.OK().Invoke();
end;

Expand Down
Loading