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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Layers/APAC/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2510,12 +2511,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/BE/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2464,12 +2465,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/ES/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2502,12 +2503,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/FR/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2508,12 +2509,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/GB/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2501,12 +2502,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/IT/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2592,12 +2593,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/NA/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2609,12 +2610,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/NL/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2454,12 +2455,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/NO/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2470,12 +2471,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/RU/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2584,12 +2585,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
8 changes: 5 additions & 3 deletions src/Layers/W1/BaseApp/Sales/Customer/CustomerCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,7 @@ page 21 "Customer Card"
CRMCouplingManagement: Codeunit "CRM Coupling Management";
WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";
begin
Rec.SetRange("Date Filter", 0D, WorkDate());
if NewMode then
CreateCustomerFromTemplate()
else
Expand Down Expand Up @@ -2440,12 +2441,13 @@ page 21 "Customer Card"
begin
OnBeforeOnOpenPage(Rec);

if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
if GuiAllowed() then
OnOpenPageFunc()
else
else begin
if Rec.GetFilter("Date Filter") = '' then
Rec.SetRange("Date Filter", 0D, WorkDate());
OnOpenBackground();
end;
OnAfterOnOpenPage(Rec, xRec);
end;

Expand Down
83 changes: 79 additions & 4 deletions src/Layers/W1/Tests/ERM/ERMCustomerStatistics.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ codeunit 134389 "ERM Customer Statistics"
PaymentsLCYAndAmountLCYMustMatchErr: Label 'Payemnts (LCY) and Amount (LCY) must match.';
CustomerCardFactboxTotalErr: Label 'Customer card factbox total is not Correct';
LotNoErr: Label 'Lot No. should have value.';
DateFilterNotResetErr: Label 'Date Filter upper bound on the Customer Card should be reset to WORKDATE() before StartBackgroundCalculations captures Rec.GetView().';
DateFilterLeakedErr: Label 'Date Filter on the Customer Card should no longer contain the leaked wider upper bound.';
BalanceLCYShouldIncludeBothInvoicesErr: Label 'Balance (LCY) should include both invoices.';

[Test]
[Scope('OnPrem')]
Expand Down Expand Up @@ -491,20 +494,21 @@ codeunit 134389 "ERM Customer Statistics"
// [SCENARIO 258948] When Drill Down on Balance Due (LCY) is called from Customer Card, Due Date filter on opened Customer Ledger Entries Page = Date Filter.
Initialize();

// [GIVEN] Setup new Customer with a customer ledger entry
// [GIVEN] Setup new Customer with a customer ledger entry due on or before the work date
LibrarySales.CreateCustomer(Customer);
CreateBasicCustLedgerEntry(CustLedgerEntry, Customer."No.");
CustLedgerEntry.Validate("Due Date", LibraryRandom.RandDate(100));
CustLedgerEntry.Validate("Due Date", CalcDate('<-1M>', WorkDate()));
CustLedgerEntry.Modify(true);

// [WHEN] The user drills down on Balance Due (LCY) field from Customer Card
CustomerCard.OpenView();
CustomerLedgerEntries.Trap();
CustomerCard.FILTER.SetFilter("Date Filter", Format(CustLedgerEntry."Due Date"));
// [WHEN] A wider Date Filter is inherited on the Customer Card (document/journal path)
CustomerCard.FILTER.SetFilter("Date Filter", StrSubstNo('..%1', CalcDate('<1M>', WorkDate())));
CustomerCard.GotoRecord(Customer);
CustomerCard."Balance Due (LCY)".DrillDown();

// [THEN] Customer Ledger Entries window opens, Due Date filter = Date Filter from Customer List.
// [THEN] The Customer Card normalizes the Date Filter to 0D..WORKDATE (Bug 640988), and the opened Customer Ledger Entries Page Due Date filter = that Date Filter.
Assert.AreEqual(CustomerCard.FILTER.GetFilter("Date Filter"), CustomerLedgerEntries.FILTER.GetFilter("Due Date"), '');

// [THEN] Customer Ledger Entries window opens, showing the ledger entries for the selected customer
Expand Down Expand Up @@ -1119,6 +1123,62 @@ codeunit 134389 "ERM Customer Statistics"
Assert.AreEqual(CustomerStatistics.GetTotalAmountLCY.AsDecimal(), Customer.GetTotalAmountLCY(), CustomerCardFactboxTotalErr);
end;


[Test]
procedure OverdueBalanceIsolatedFromLeakedWideDateFilterOnCustomer()
var
Customer: Record Customer;
CustomerForBackgroundTask: Record Customer;
CustomerCard: TestPage "Customer Card";
EarliestDate: Date;
LatestDate: Date;
OverdueAmount: Decimal;
NotOverdueAmount: Decimal;
begin
// [FEATURE] [Overdue Balance] [Cue]
// [SCENARIO 640988] The "Balance Due" overdue payments cue on the Customer Card (page variable OverdueBalance, filled by the "Customer Card Calculations" background task from Rec.GetView) and the "Balance Due (LCY)" FlowField both return only overdue amounts, even when a wider "Date Filter" is inherited on the Customer record from a document or journal.
Initialize();

// [GIVEN] Reference dates that bracket both WORKDATE and Today so the fixture is deterministic regardless of their relative order.
if WorkDate() < Today() then begin
EarliestDate := WorkDate();
LatestDate := Today();
end else begin
EarliestDate := Today();
LatestDate := WorkDate();
end;

// [GIVEN] Create customer with two posted sales invoices.
LibrarySales.CreateCustomer(Customer);
// [GIVEN] Invoice "A" is overdue against both WORKDATE and Today: Due Date < min(WORKDATE, Today), Amount = "X".
OverdueAmount := CreateAndPostInvoiceWithDueDate(Customer."No.", CalcDate('<-2M>', EarliestDate), CalcDate('<-1M>', EarliestDate));
// [GIVEN] Invoice "B" is not yet due against either WORKDATE or Today: Due Date > max(WORKDATE, Today), Amount = "Y".
NotOverdueAmount := CreateAndPostInvoiceWithDueDate(Customer."No.", WorkDate(), CalcDate('<2M>', LatestDate));

// [WHEN] The Customer Card is opened for the customer with a leaked wider "Date Filter" applied by the caller (document/journal path).
CustomerCard.OpenView();
CustomerCard.FILTER.SetFilter("Date Filter", StrSubstNo('..%1', CalcDate('<3M>', LatestDate)));
CustomerCard.FILTER.SetFilter("No.", Customer."No.");

// [THEN] OnAfterGetCurrRecordFunc resets the "Date Filter" on the Card record to 0D..WORKDATE before StartBackgroundCalculations captures the view, so the leaked upper bound past WORKDATE no longer applies on the page.
Assert.IsTrue(StrPos(CustomerCard.FILTER.GetFilter("Date Filter"), Format(WorkDate())) > 0, DateFilterNotResetErr);
Assert.IsTrue(StrPos(CustomerCard.FILTER.GetFilter("Date Filter"), Format(CalcDate('<3M>', LatestDate))) = 0, DateFilterLeakedErr);

// [THEN] "Balance Due (LCY)" FlowField shown on the Customer Card reflects only the overdue invoice amount.
Assert.AreEqual(OverdueAmount, CustomerCard."Balance Due (LCY)".AsDecimal(), OverDueBalanceErr);
// [THEN] "Balance Due" cue (OverdueBalance page variable, populated by the background task) also reflects only the overdue invoice amount.
Assert.AreEqual(OverdueAmount, CustomerCard."Balance Due".AsDecimal(), OverDueBalanceErr);
// [THEN] "Balance (LCY)" on the Customer Card still sums both invoices.
Assert.AreEqual(OverdueAmount + NotOverdueAmount, CustomerCard."Balance (LCY)".AsDecimal(), BalanceLCYShouldIncludeBothInvoicesErr);

// [THEN] The "Balance Due" overdue payments cue (OverdueBalance page variable) is populated by the "Customer Card Calculations" background task which does Customer.SetView(<Rec.GetView from the Card>) and then Customer.CalcOverdueBalance(). Replaying that exact call path with the Date Filter now captured on the Card returns only the overdue amount, proving the cue value is isolated from the leaked wider Date Filter.
CustomerForBackgroundTask.Get(Customer."No.");
CustomerForBackgroundTask.SetFilter("Date Filter", CustomerCard.FILTER.GetFilter("Date Filter"));
Assert.AreEqual(Round(OverdueAmount), CustomerForBackgroundTask.CalcOverdueBalance(), OverDueBalanceErr);

CustomerCard.Close();
end;

local procedure Initialize()
var
Currency: Record Currency;
Expand Down Expand Up @@ -1242,6 +1302,21 @@ codeunit 134389 "ERM Customer Statistics"
exit(SalesHeader."Amount Including VAT");
end;

local procedure CreateAndPostInvoiceWithDueDate(CustomerNo: Code[20]; PostingDate: Date; DueDate: Date) AmountInclVAT: Decimal
var
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
begin
CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Invoice, CustomerNo, PostingDate);
SalesHeader.Validate("Due Date", DueDate);
SalesHeader.Modify(true);
LibrarySales.CreateSalesLine(
SalesLine, SalesHeader, SalesLine.Type::Item, CreateItemWithUnitPrice(), LibraryRandom.RandDec(10, 2));
SalesHeader.CalcFields("Amount Including VAT");
AmountInclVAT := SalesHeader."Amount Including VAT";
LibrarySales.PostSalesDocument(SalesHeader, true, true);
end;

local procedure CreateAndPostSalesDocument(CustomerNo: Code[20]; CurrencyCode: Code[10]): Decimal
var
SalesHeader: Record "Sales Header";
Expand Down
Loading