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 @@ -323,6 +323,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("Amount (LCY)"; Rec."Amount (LCY)")
Expand All @@ -334,6 +335,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("Debit Amount"; Rec."Debit Amount")
Expand All @@ -344,6 +346,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("Credit Amount"; Rec."Credit Amount")
Expand All @@ -354,6 +357,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("VAT Amount"; Rec."VAT Amount")
Expand Down Expand Up @@ -728,6 +732,20 @@ page 256 "Payment Journal"
Visible = TotalBalanceVisible;
}
}
group("Batch Total")
{
Caption = 'Batch Total (LCY)';
field(BatchTotal; BatchTotal)
{
ApplicationArea = All;
AutoFormatType = 1;
AutoFormatExpression = '';
Caption = 'Batch Total (LCY)';
Editable = false;
ToolTip = 'Specifies the total amount, in local currency, of the lines that are shown in the journal. Use this to see how much is selected for payment before you post the journal.';
Visible = BatchTotalVisible;
}
}
}
}
}
Expand Down Expand Up @@ -1913,6 +1931,7 @@ page 256 "Payment Journal"
begin
TotalBalanceVisible := true;
BalanceVisible := true;
BatchTotalVisible := true;
AmountVisible := true;
GeneralLedgerSetup.Get();
IsPowerAutomatePrivacyNoticeApproved := PrivacyNotice.GetPrivacyNoticeApprovalState(FlowServiceManagement.GetPowerAutomatePrivacyNoticeId()) = "Privacy Notice Approval State"::Agreed;
Expand Down Expand Up @@ -1995,12 +2014,15 @@ page 256 "Payment Journal"
GenJnlLineApprovalStatus: Text[20];
Balance: Decimal;
TotalBalance: Decimal;
BatchTotal: Decimal;
NumberOfRecords: Integer;
ShowBalance: Boolean;
ShowTotalBalance: Boolean;
ShowBatchTotal: Boolean;
HasPmtFileErr: Boolean;
BalanceVisible: Boolean;
TotalBalanceVisible: Boolean;
BatchTotalVisible: Boolean;
IsPostingGroupEditable: Boolean;
StyleTxt: Text;
OverdueWarningText: Text;
Expand Down Expand Up @@ -2106,9 +2128,23 @@ page 256 "Payment Journal"
if ShowTotalBalance then
NumberOfRecords := Rec.Count();

UpdateBatchTotal();

OnAfterUpdateBalance(TotalBalanceVisible);
end;

local procedure UpdateBatchTotal()
begin
GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal);
BatchTotalVisible := ShowBatchTotal;
end;

local procedure UpdateBatchTotalAfterAmountChange()
begin
CurrPage.SaveRecord();
UpdateBatchTotal();
end;

local procedure EnableApplyEntriesAction()
begin
ApplyEntriesActionEnabled :=
Expand Down
173 changes: 173 additions & 0 deletions src/Layers/APAC/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ codeunit 134920 "ERM General Journal UT"
RecurringFrequencyNotClearedErr: Label 'The recurring frequency should be cleared.';
YearlyRecurringFrequencyTok: Label '1Y', Locked = true;
RecurringFrequencyNotLocalizedErr: Label 'The recurring frequency should be displayed using the localized date formula tokens.';
WrongBatchTotalErr: Label 'Wrong Batch Total on the Payment Journal page.';
BatchTotalNotShownErr: Label 'Batch Total must be shown.';
IsInitialized: Boolean;

[Test]
Expand Down Expand Up @@ -6299,6 +6301,177 @@ codeunit 134920 "ERM General Journal UT"
GenJournalLine.Modify(true);
end;

[Test]
[Scope('OnPrem')]
procedure PaymentJournalBatchTotalShowsSumOfLineAmounts()
var
GenJournalTemplate: Record "Gen. Journal Template";
GenJournalBatch: Record "Gen. Journal Batch";
GeneralJournalBatches: TestPage "General Journal Batches";
PaymentJournal: TestPage "Payment Journal";
ExpectedBatchTotal: Decimal;
begin
// [FEATURE] [Payment] [Batch Total]
// [SCENARIO 425446] Batch Total on the Payment Journal page shows the total amount that is selected for payment in the batch.
Initialize();

// [GIVEN] Payment journal batch with three payment lines
CreateGenJournalTemplateBatchPayment(GenJournalTemplate, GenJournalBatch);
ExpectedBatchTotal := CreatePaymentJournalLines(GenJournalTemplate, GenJournalBatch, 3);
PrepareGeneralJournalBatchesPage(GeneralJournalBatches, GenJournalBatch);

// [WHEN] Payment Journal page is opened on the batch
RunEditJournalActionOnPaymentJournalPage(PaymentJournal, GeneralJournalBatches);

// [THEN] Batch Total is the sum of "Amount (LCY)" of the three lines
Assert.AreEqual(ExpectedBatchTotal, PaymentJournal.BatchTotal.AsDecimal(), WrongBatchTotalErr);

PaymentJournal.Close();
GeneralJournalBatches.Close();
end;

[Test]
[Scope('OnPrem')]
procedure PaymentJournalBatchTotalIsZeroForEmptyBatch()
var
GenJournalTemplate: Record "Gen. Journal Template";
GenJournalBatch: Record "Gen. Journal Batch";
GeneralJournalBatches: TestPage "General Journal Batches";
PaymentJournal: TestPage "Payment Journal";
begin
// [FEATURE] [Payment] [Batch Total]
// [SCENARIO 425446] Batch Total on the Payment Journal page is zero when the batch has no lines.
Initialize();

// [GIVEN] Payment journal batch without lines
CreateGenJournalTemplateBatchPayment(GenJournalTemplate, GenJournalBatch);
PrepareGeneralJournalBatchesPage(GeneralJournalBatches, GenJournalBatch);

// [WHEN] Payment Journal page is opened on the batch
RunEditJournalActionOnPaymentJournalPage(PaymentJournal, GeneralJournalBatches);

// [THEN] Batch Total is 0
Assert.AreEqual(0, PaymentJournal.BatchTotal.AsDecimal(), WrongBatchTotalErr);

PaymentJournal.Close();
GeneralJournalBatches.Close();
end;

[Test]
[Scope('OnPrem')]
procedure PaymentJournalBatchTotalUpdatedWhenLineAmountIsValidated()
var
GenJournalTemplate: Record "Gen. Journal Template";
GenJournalBatch: Record "Gen. Journal Batch";
GeneralJournalBatches: TestPage "General Journal Batches";
PaymentJournal: TestPage "Payment Journal";
InitialBatchTotal: Decimal;
OldAmount: Decimal;
NewAmount: Decimal;
begin
// [FEATURE] [Payment] [Batch Total]
// [SCENARIO 425446] Batch Total on the Payment Journal page is recalculated when the Amount of a line is changed.
Initialize();

// [GIVEN] Payment Journal page opened on a batch with two payment lines
CreateGenJournalTemplateBatchPayment(GenJournalTemplate, GenJournalBatch);
InitialBatchTotal := CreatePaymentJournalLines(GenJournalTemplate, GenJournalBatch, 2);
PrepareGeneralJournalBatchesPage(GeneralJournalBatches, GenJournalBatch);
RunEditJournalActionOnPaymentJournalPage(PaymentJournal, GeneralJournalBatches);
PaymentJournal.First();
OldAmount := PaymentJournal.Amount.AsDecimal();
NewAmount := OldAmount - LibraryRandom.RandDecInRange(100, 1000, 2);

// [WHEN] Amount is changed on the first line
PaymentJournal.Amount.SetValue(NewAmount);

// [THEN] Batch Total is updated without leaving the line
Assert.AreEqual(
InitialBatchTotal - OldAmount + NewAmount, PaymentJournal.BatchTotal.AsDecimal(), WrongBatchTotalErr);

PaymentJournal.Close();
GeneralJournalBatches.Close();
end;

[Test]
[Scope('OnPrem')]
procedure PaymentJournalBatchTotalUpdatedWhenBatchIsChanged()
var
GenJournalTemplate: Record "Gen. Journal Template";
GenJournalBatch: Record "Gen. Journal Batch";
GenJournalBatch2: Record "Gen. Journal Batch";
GeneralJournalBatches: TestPage "General Journal Batches";
PaymentJournal: TestPage "Payment Journal";
SecondBatchTotal: Decimal;
begin
// [FEATURE] [Payment] [Batch Total]
// [SCENARIO 425446] Batch Total on the Payment Journal page only covers the lines of the selected batch.
Initialize();

// [GIVEN] Two payment journal batches with lines, in the same template
CreateGenJournalTemplateBatchPayment(GenJournalTemplate, GenJournalBatch);
CreatePaymentJournalLines(GenJournalTemplate, GenJournalBatch, 2);
LibraryERM.CreateGenJournalBatch(GenJournalBatch2, GenJournalTemplate.Name);
SecondBatchTotal := CreatePaymentJournalLines(GenJournalTemplate, GenJournalBatch2, 3);

// [GIVEN] Payment Journal page opened on the first batch
PrepareGeneralJournalBatchesPage(GeneralJournalBatches, GenJournalBatch);
RunEditJournalActionOnPaymentJournalPage(PaymentJournal, GeneralJournalBatches);

// [WHEN] Batch Name is changed to the second batch
PaymentJournal.CurrentJnlBatchName.SetValue(GenJournalBatch2.Name);

// [THEN] Batch Total is the total of the second batch only
Assert.AreEqual(SecondBatchTotal, PaymentJournal.BatchTotal.AsDecimal(), WrongBatchTotalErr);

PaymentJournal.Close();
GeneralJournalBatches.Close();
end;

[Test]
[Scope('OnPrem')]
procedure CalcBatchTotalReturnsSumOfAmountLCYOfFilteredLines()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Testing}$

The new CalcBatchTotal unit test only exercises the visible branch (ShowBatchTotal = true). GenJnlManagement.CalcBatchTotal now suppresses Batch Total for ClientType::SOAP, OData, ODataV4, and Api, but this codeunit never binds Test Client Type Subscriber to verify that ShowBatchTotal becomes false and BatchTotal stays 0 for those clients. Add a negative client-type test so the suppression branch cannot regress silently.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.35.4

var
GenJournalTemplate: Record "Gen. Journal Template";
GenJournalBatch: Record "Gen. Journal Batch";
GenJournalLine: Record "Gen. Journal Line";
ExpectedBatchTotal: Decimal;
BatchTotal: Decimal;
ShowBatchTotal: Boolean;
begin
// [FEATURE] [Payment] [Batch Total] [UT]
// [SCENARIO 425446] CalcBatchTotal returns the sum of "Amount (LCY)" of the lines that the filters apply to.
Initialize();

// [GIVEN] Payment journal batch with three payment lines
CreateGenJournalTemplateBatchPayment(GenJournalTemplate, GenJournalBatch);
ExpectedBatchTotal := CreatePaymentJournalLines(GenJournalTemplate, GenJournalBatch, 3);
GenJournalLine.SetRange("Journal Template Name", GenJournalBatch."Journal Template Name");
GenJournalLine.SetRange("Journal Batch Name", GenJournalBatch.Name);

// [WHEN] CalcBatchTotal is called for the filtered lines
GenJnlManagement.CalcBatchTotal(GenJournalLine, BatchTotal, ShowBatchTotal);

// [THEN] The total of the batch is returned and can be shown
Assert.IsTrue(ShowBatchTotal, BatchTotalNotShownErr);
Assert.AreEqual(ExpectedBatchTotal, BatchTotal, WrongBatchTotalErr);
end;

local procedure CreatePaymentJournalLines(GenJournalTemplate: Record "Gen. Journal Template"; GenJournalBatch: Record "Gen. Journal Batch"; NoOfLines: Integer) TotalAmountLCY: Decimal
var
GenJournalLine: Record "Gen. Journal Line";
VendorNo: Code[20];
i: Integer;
begin
VendorNo := LibraryPurchase.CreateVendorNo();
for i := 1 to NoOfLines do begin
LibraryERM.CreateGeneralJnlLine2(
GenJournalLine, GenJournalTemplate.Name, GenJournalBatch.Name, GenJournalLine."Document Type"::Payment,
GenJournalLine."Account Type"::Vendor, VendorNo, -LibraryRandom.RandDecInRange(100, 1000, 2));
TotalAmountLCY += GenJournalLine."Amount (LCY)";
end;
end;

local procedure Initialize()
begin
LibrarySetupStorage.Restore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("Amount (LCY)"; Rec."Amount (LCY)")
Expand All @@ -317,6 +318,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("Debit Amount"; Rec."Debit Amount")
Expand All @@ -327,6 +329,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("Credit Amount"; Rec."Credit Amount")
Expand All @@ -337,6 +340,7 @@ page 256 "Payment Journal"
trigger OnValidate()
begin
CheckAmountMatchedToAppliedLines();
UpdateBatchTotalAfterAmountChange();
end;
}
field("VAT Amount"; Rec."VAT Amount")
Expand Down Expand Up @@ -682,6 +686,20 @@ page 256 "Payment Journal"
Visible = TotalBalanceVisible;
}
}
group("Batch Total")
{
Caption = 'Batch Total (LCY)';
field(BatchTotal; BatchTotal)
{
ApplicationArea = All;
AutoFormatType = 1;
AutoFormatExpression = '';
Caption = 'Batch Total (LCY)';
Editable = false;
ToolTip = 'Specifies the total amount, in local currency, of the lines that are shown in the journal. Use this to see how much is selected for payment before you post the journal.';
Visible = BatchTotalVisible;
}
}
}
}
}
Expand Down Expand Up @@ -2003,6 +2021,7 @@ page 256 "Payment Journal"
begin
TotalBalanceVisible := true;
BalanceVisible := true;
BatchTotalVisible := true;
AmountVisible := true;
GeneralLedgerSetup.Get();
IsPowerAutomatePrivacyNoticeApproved := PrivacyNotice.GetPrivacyNoticeApprovalState(FlowServiceManagement.GetPowerAutomatePrivacyNoticeId()) = "Privacy Notice Approval State"::Agreed;
Expand Down Expand Up @@ -2091,12 +2110,15 @@ page 256 "Payment Journal"
GenJnlLineApprovalStatus: Text[20];
Balance: Decimal;
TotalBalance: Decimal;
BatchTotal: Decimal;
NumberOfRecords: Integer;
ShowBalance: Boolean;
ShowTotalBalance: Boolean;
ShowBatchTotal: Boolean;
HasPmtFileErr: Boolean;
BalanceVisible: Boolean;
TotalBalanceVisible: Boolean;
BatchTotalVisible: Boolean;
IsPostingGroupEditable: Boolean;
StyleTxt: Text;
OverdueWarningText: Text;
Expand Down Expand Up @@ -2206,9 +2228,23 @@ page 256 "Payment Journal"
if ShowTotalBalance then
NumberOfRecords := Rec.Count();

UpdateBatchTotal();

OnAfterUpdateBalance(TotalBalanceVisible);
end;

local procedure UpdateBatchTotal()
begin
GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal);
BatchTotalVisible := ShowBatchTotal;
end;

local procedure UpdateBatchTotalAfterAmountChange()
begin
CurrPage.SaveRecord();
UpdateBatchTotal();
end;

local procedure EnableApplyEntriesAction()
begin
ApplyEntriesActionEnabled :=
Expand Down
Loading
Loading