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..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,6 +323,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -334,6 +335,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -344,6 +346,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -354,6 +357,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +306,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -317,6 +318,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -327,6 +329,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -337,6 +340,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..54bda86b207 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,21 @@ 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); + 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. 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..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,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -315,6 +316,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -325,6 +327,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -335,6 +338,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +358,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -369,6 +370,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -379,6 +381,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -389,6 +392,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +298,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -309,6 +310,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -319,6 +321,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -329,6 +332,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..265ef10a025 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,21 @@ 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); + 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. 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..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,6 +300,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -311,6 +312,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -321,6 +323,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -331,6 +334,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..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,6 +319,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -330,6 +331,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -340,6 +342,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -350,6 +353,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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..bf8c034159d 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,21 @@ 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); + 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. 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..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,6 +292,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Amount (LCY)"; Rec."Amount (LCY)") @@ -303,6 +304,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Debit Amount"; Rec."Debit Amount") @@ -313,6 +315,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); end; } field("Credit Amount"; Rec."Credit Amount") @@ -323,6 +326,7 @@ page 256 "Payment Journal" trigger OnValidate() begin CheckAmountMatchedToAppliedLines(); + UpdateBatchTotalAfterAmountChange(); 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,23 @@ page 256 "Payment Journal" if ShowTotalBalance then NumberOfRecords := Rec.Count(); + UpdateBatchTotal(); + OnAfterUpdateBalance(TotalBalanceVisible); end; + local procedure UpdateBatchTotal() + begin + GenJnlManagement.CalcBatchTotal(Rec, BatchTotal, ShowBatchTotal); + BatchTotalVisible := ShowBatchTotal; + end; + + local procedure UpdateBatchTotalAfterAmountChange() + begin + CurrPage.SaveRecord(); + UpdateBatchTotal(); + end; + local procedure EnableApplyEntriesAction() begin ApplyEntriesActionEnabled := 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();