From 3ad85272d7b0e240ea0a4fb0419810ef39752787 Mon Sep 17 00:00:00 2001 From: v-viditgupta Date: Sun, 23 Aug 2026 11:56:55 +0530 Subject: [PATCH 1/2] [Master]-Slice 425446: Payment Journal Batch Total --- .../Journal/PaymentJournal.Page.al | 42 +++++ .../ERMGeneralJournalUT.Codeunit.al | 173 ++++++++++++++++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../ERMGeneralJournalUT.Codeunit.al | 173 ++++++++++++++++++ .../ERMGeneralJournalUT.Codeunit.al | 173 ++++++++++++++++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../Journal/GenJnlManagement.Codeunit.al | 21 +++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../ERMGeneralJournalUT.Codeunit.al | 173 ++++++++++++++++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../ERMGeneralJournalUT.Codeunit.al | 173 ++++++++++++++++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../Journal/GenJnlManagement.Codeunit.al | 21 +++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../Journal/GenJnlManagement.Codeunit.al | 21 +++ .../Journal/PaymentJournal.Page.al | 42 +++++ .../ERMGeneralJournalUT.Codeunit.al | 173 ++++++++++++++++++ 20 files changed, 1563 insertions(+) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 68c2b49503e..f2dddd73da0 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -323,6 +323,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -334,6 +335,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -344,6 +346,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -354,6 +357,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -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; + } + } } } } @@ -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; @@ -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; @@ -2106,9 +2128,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2428,6 +2465,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/APAC/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al b/src/Layers/APAC/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al index 7bf3ea7144d..707e6a229cd 100644 --- a/src/Layers/APAC/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al +++ b/src/Layers/APAC/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al @@ -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] @@ -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() + 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(); diff --git a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 76354ddc28d..be066213cc7 100644 --- a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -306,6 +306,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -317,6 +318,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -327,6 +329,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -337,6 +340,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -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; + } + } } } } @@ -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; @@ -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; @@ -2206,9 +2228,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2539,6 +2576,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/CH/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al b/src/Layers/CH/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al index 7a652d29ddf..c81c9d60800 100644 --- a/src/Layers/CH/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al +++ b/src/Layers/CH/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al @@ -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] @@ -6102,6 +6104,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() + 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(); diff --git a/src/Layers/CZ/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al b/src/Layers/CZ/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al index cc9099c0250..4ed0a80f174 100644 --- a/src/Layers/CZ/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al +++ b/src/Layers/CZ/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al @@ -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] @@ -6298,6 +6300,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() + 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(); diff --git a/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index b5bdbddca3b..0221c3e3952 100644 --- a/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -663,6 +667,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; + } + } } } } @@ -1762,6 +1780,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; @@ -1846,12 +1865,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; @@ -1957,9 +1979,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2279,6 +2316,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al index 6d8385daa94..f9a33129862 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al @@ -617,6 +617,22 @@ codeunit 230 GenJnlManagement OnAfterCalcBalance(GenJnlLine); end; + procedure CalcBatchTotal(var GenJnlLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var ShowBatchTotal: Boolean) + var + [SecurityFiltering(SecurityFilter::Filtered)] + TotalGenJnlLine: Record "Gen. Journal Line"; + begin + BatchTotal := 0; + ShowBatchTotal := not (CurrentClientType in [CLIENTTYPE::SOAP, CLIENTTYPE::OData, CLIENTTYPE::ODataV4, CLIENTTYPE::Api]); + if not ShowBatchTotal then + exit; + + TotalGenJnlLine.CopyFilters(GenJnlLine); + OnCalcBatchTotalOnAfterCopyFilters(TotalGenJnlLine); + TotalGenJnlLine.CalcSums("Amount (LCY)"); + BatchTotal := TotalGenJnlLine."Amount (LCY)"; + end; + /// /// Generates unique journal template names by checking for conflicts and incrementing names when needed. /// Ensures new template names are unique while maintaining meaningful naming based on template type. @@ -923,6 +939,11 @@ codeunit 230 GenJnlManagement begin end; + [IntegrationEvent(false, false)] + local procedure OnCalcBatchTotalOnAfterCopyFilters(var GenJournalLine: Record "Gen. Journal Line") + begin + end; + /// /// Integration event raised before moving to next record during balance calculation. /// Enables custom record positioning logic during balance calculation. diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 4065a798add..6197fca2324 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -304,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -315,6 +316,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -325,6 +327,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -335,6 +338,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -753,6 +757,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; + } + } } } } @@ -1886,6 +1904,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; @@ -1966,12 +1985,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; @@ -2078,9 +2100,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2400,6 +2437,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/ES/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al b/src/Layers/ES/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al index 99a5a31c45e..0f00c3467cc 100644 --- a/src/Layers/ES/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al +++ b/src/Layers/ES/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al @@ -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] @@ -6327,6 +6329,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() + 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(); diff --git a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 1d6b13fc14c..a3ebb3f3e9f 100644 --- a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -675,6 +679,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; + } + } } } } @@ -1765,6 +1783,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; @@ -1844,12 +1863,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; @@ -1955,9 +1977,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2277,6 +2314,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 690ef07d3b9..ac0d1f714d0 100644 --- a/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -663,6 +667,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; + } + } } } } @@ -1787,6 +1805,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; @@ -1866,12 +1885,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; @@ -1977,9 +1999,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2299,6 +2336,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index ed3ccaed976..a48d9c3c298 100644 --- a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -358,6 +358,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -369,6 +370,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -379,6 +381,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -389,6 +392,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -729,6 +733,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; + } + } } } } @@ -1836,6 +1854,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; @@ -1915,12 +1934,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; @@ -2028,9 +2050,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2350,6 +2387,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/IT/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al b/src/Layers/IT/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al index 26c939c9300..0044783f068 100644 --- a/src/Layers/IT/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al +++ b/src/Layers/IT/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al @@ -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] @@ -6298,6 +6300,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() + 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(); diff --git a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 620bb2cee7f..aab7aaafbb9 100644 --- a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -298,6 +298,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -309,6 +310,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -319,6 +321,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -329,6 +332,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -748,6 +752,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; + } + } } } } @@ -1949,6 +1967,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; @@ -2039,12 +2058,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; @@ -2161,9 +2183,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2578,6 +2615,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al b/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al index 81fdaf2e1bd..9f14f42a732 100644 --- a/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al +++ b/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al @@ -712,6 +712,22 @@ codeunit 230 GenJnlManagement InsertCBGStatement(GenJnlTemplate); end; + procedure CalcBatchTotal(var GenJnlLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var ShowBatchTotal: Boolean) + var + [SecurityFiltering(SecurityFilter::Filtered)] + TotalGenJnlLine: Record "Gen. Journal Line"; + begin + BatchTotal := 0; + ShowBatchTotal := not (CurrentClientType in [CLIENTTYPE::SOAP, CLIENTTYPE::OData, CLIENTTYPE::ODataV4, CLIENTTYPE::Api]); + if not ShowBatchTotal then + exit; + + TotalGenJnlLine.CopyFilters(GenJnlLine); + OnCalcBatchTotalOnAfterCopyFilters(TotalGenJnlLine); + TotalGenJnlLine.CalcSums("Amount (LCY)"); + BatchTotal := TotalGenJnlLine."Amount (LCY)"; + end; + /// /// Generates unique journal template names by checking for conflicts and incrementing names when needed. /// Ensures new template names are unique while maintaining meaningful naming based on template type. @@ -1018,6 +1034,11 @@ codeunit 230 GenJnlManagement begin end; + [IntegrationEvent(false, false)] + local procedure OnCalcBatchTotalOnAfterCopyFilters(var GenJournalLine: Record "Gen. Journal Line") + begin + end; + /// /// Integration event raised before moving to next record during balance calculation. /// Enables custom record positioning logic during balance calculation. diff --git a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index aa9931217b9..55d5e3c3ef5 100644 --- a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -300,6 +300,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -311,6 +312,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -321,6 +323,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -331,6 +334,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -689,6 +693,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; + } + } } } } @@ -1918,6 +1936,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; @@ -1999,12 +2018,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; @@ -2110,9 +2132,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2437,6 +2474,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 3264c32d56d..7e4f5ca06f3 100644 --- a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -319,6 +319,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -330,6 +331,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -340,6 +342,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -350,6 +353,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -700,6 +704,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; + } + } } } } @@ -1900,6 +1918,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; @@ -1979,12 +1998,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; @@ -2090,9 +2112,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2412,6 +2449,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al index c3c99e67a87..5c517f8029b 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al @@ -617,6 +617,22 @@ codeunit 230 GenJnlManagement OnAfterCalcBalance(GenJnlLine); end; + procedure CalcBatchTotal(var GenJnlLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var ShowBatchTotal: Boolean) + var + [SecurityFiltering(SecurityFilter::Filtered)] + TotalGenJnlLine: Record "Gen. Journal Line"; + begin + BatchTotal := 0; + ShowBatchTotal := not (CurrentClientType in [CLIENTTYPE::SOAP, CLIENTTYPE::OData, CLIENTTYPE::ODataV4, CLIENTTYPE::Api]); + if not ShowBatchTotal then + exit; + + TotalGenJnlLine.CopyFilters(GenJnlLine); + OnCalcBatchTotalOnAfterCopyFilters(TotalGenJnlLine); + TotalGenJnlLine.CalcSums("Amount (LCY)"); + BatchTotal := TotalGenJnlLine."Amount (LCY)"; + end; + /// /// Generates unique journal template names by checking for conflicts and incrementing names when needed. /// Ensures new template names are unique while maintaining meaningful naming based on template type. @@ -923,6 +939,11 @@ codeunit 230 GenJnlManagement begin end; + [IntegrationEvent(false, false)] + local procedure OnCalcBatchTotalOnAfterCopyFilters(var GenJournalLine: Record "Gen. Journal Line") + begin + end; + /// /// Integration event raised before moving to next record during balance calculation. /// Enables custom record positioning logic during balance calculation. diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index bc303774a93..ad238e4f9f4 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBalance(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -663,6 +667,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; + } + } } } } @@ -1753,6 +1771,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; @@ -1832,12 +1851,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; @@ -1943,9 +1965,24 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + var + IsHandled: Boolean; + begin + IsHandled := false; + OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); + if IsHandled then + exit; + + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2265,6 +2302,11 @@ page 256 "Payment Journal" begin end; + [IntegrationEvent(true, false)] + local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) + begin + end; + /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/W1/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al b/src/Layers/W1/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al index 37dc949e803..0bffda864c6 100644 --- a/src/Layers/W1/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al +++ b/src/Layers/W1/Tests/General Journal/ERMGeneralJournalUT.Codeunit.al @@ -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] @@ -6298,6 +6300,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() + 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(); From 5101561d1f37efcc74a8e0040d6ba68dc92bde16 Mon Sep 17 00:00:00 2001 From: v-viditgupta Date: Sun, 23 Aug 2026 21:41:35 +0530 Subject: [PATCH 2/2] Comments Fix --- .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/GenJnlManagement.Codeunit.al | 6 ----- .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/GenJnlManagement.Codeunit.al | 6 ----- .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/PaymentJournal.Page.al | 26 +++++++------------ .../Journal/GenJnlManagement.Codeunit.al | 6 ----- .../Journal/PaymentJournal.Page.al | 26 +++++++------------ 14 files changed, 110 insertions(+), 194 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index f2dddd73da0..5533fa1330b 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -323,7 +323,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -335,7 +335,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -346,7 +346,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -357,7 +357,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2134,18 +2134,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2465,11 +2464,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index be066213cc7..3c77f389418 100644 --- a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -306,7 +306,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -318,7 +318,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -329,7 +329,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -340,7 +340,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2234,18 +2234,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2576,11 +2575,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 0221c3e3952..b0676233d1c 100644 --- a/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,7 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -304,7 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -315,7 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -326,7 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -1985,18 +1985,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2316,11 +2315,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al index f9a33129862..54bda86b207 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al @@ -628,7 +628,6 @@ codeunit 230 GenJnlManagement exit; TotalGenJnlLine.CopyFilters(GenJnlLine); - OnCalcBatchTotalOnAfterCopyFilters(TotalGenJnlLine); TotalGenJnlLine.CalcSums("Amount (LCY)"); BatchTotal := TotalGenJnlLine."Amount (LCY)"; end; @@ -939,11 +938,6 @@ codeunit 230 GenJnlManagement begin end; - [IntegrationEvent(false, false)] - local procedure OnCalcBatchTotalOnAfterCopyFilters(var GenJournalLine: Record "Gen. Journal Line") - begin - end; - /// /// Integration event raised before moving to next record during balance calculation. /// Enables custom record positioning logic during balance calculation. diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 6197fca2324..835f22a47ee 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -304,7 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -316,7 +316,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -327,7 +327,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -338,7 +338,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2106,18 +2106,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2437,11 +2436,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index a3ebb3f3e9f..f9fae957789 100644 --- a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,7 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -304,7 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -315,7 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -326,7 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -1983,18 +1983,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2314,11 +2313,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index ac0d1f714d0..1e4fc4aea06 100644 --- a/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,7 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -304,7 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -315,7 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -326,7 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2005,18 +2005,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2336,11 +2335,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index a48d9c3c298..c8fe83b9c2b 100644 --- a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -358,7 +358,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -370,7 +370,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -381,7 +381,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -392,7 +392,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2056,18 +2056,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2387,11 +2386,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index aab7aaafbb9..26013c521ca 100644 --- a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -298,7 +298,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -310,7 +310,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -321,7 +321,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -332,7 +332,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2189,18 +2189,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2615,11 +2614,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al b/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al index 9f14f42a732..265ef10a025 100644 --- a/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al +++ b/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al @@ -723,7 +723,6 @@ codeunit 230 GenJnlManagement exit; TotalGenJnlLine.CopyFilters(GenJnlLine); - OnCalcBatchTotalOnAfterCopyFilters(TotalGenJnlLine); TotalGenJnlLine.CalcSums("Amount (LCY)"); BatchTotal := TotalGenJnlLine."Amount (LCY)"; end; @@ -1034,11 +1033,6 @@ codeunit 230 GenJnlManagement begin end; - [IntegrationEvent(false, false)] - local procedure OnCalcBatchTotalOnAfterCopyFilters(var GenJournalLine: Record "Gen. Journal Line") - begin - end; - /// /// Integration event raised before moving to next record during balance calculation. /// Enables custom record positioning logic during balance calculation. diff --git a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 55d5e3c3ef5..be23a65c56b 100644 --- a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -300,7 +300,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -312,7 +312,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -323,7 +323,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -334,7 +334,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2138,18 +2138,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2474,11 +2473,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index 7e4f5ca06f3..c8439675228 100644 --- a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -319,7 +319,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -331,7 +331,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -342,7 +342,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -353,7 +353,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -2118,18 +2118,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2449,11 +2448,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context. diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al index 5c517f8029b..bf8c034159d 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJnlManagement.Codeunit.al @@ -628,7 +628,6 @@ codeunit 230 GenJnlManagement exit; TotalGenJnlLine.CopyFilters(GenJnlLine); - OnCalcBatchTotalOnAfterCopyFilters(TotalGenJnlLine); TotalGenJnlLine.CalcSums("Amount (LCY)"); BatchTotal := TotalGenJnlLine."Amount (LCY)"; end; @@ -939,11 +938,6 @@ codeunit 230 GenJnlManagement begin end; - [IntegrationEvent(false, false)] - local procedure OnCalcBatchTotalOnAfterCopyFilters(var GenJournalLine: Record "Gen. Journal Line") - begin - end; - /// /// Integration event raised before moving to next record during balance calculation. /// Enables custom record positioning logic during balance calculation. diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al index ad238e4f9f4..5e41851138b 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PaymentJournal.Page.al @@ -292,7 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -304,7 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -315,7 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -326,7 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); - UpdateBalance(); + UpdateBatchTotalAfterAmountChange(); end; } field("VAT Amount"; Rec."VAT Amount") @@ -1971,18 +1971,17 @@ page 256 "Payment Journal" end; local procedure UpdateBatchTotal() - var - IsHandled: Boolean; begin - IsHandled := false; - OnBeforeUpdateBatchTotal(Rec, BatchTotal, BatchTotalVisible, IsHandled); - if IsHandled then - exit; - GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); BatchTotalVisible := ShowBatchTotal; end; + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := @@ -2302,11 +2301,6 @@ page 256 "Payment Journal" begin end; - [IntegrationEvent(true, false)] - local procedure OnBeforeUpdateBatchTotal(var GenJournalLine: Record "Gen. Journal Line"; var BatchTotal: Decimal; var BatchTotalVisible: Boolean; var IsHandled: Boolean) - begin - end; - /// /// Integration event raised after enabling or disabling apply entries action for payment journal. /// Enables custom control of apply entries action availability based on journal line context.