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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Microsoft.Bank.Ledger;
using Microsoft.Finance.GeneralLedger.Account;
using Microsoft.Finance.GeneralLedger.Journal;
using Microsoft.Finance.GeneralLedger.Ledger;
using Microsoft.Finance.GeneralLedger.Setup;
using Microsoft.Foundation.AuditCodes;
using Microsoft.Purchases.Payables;
using Microsoft.Purchases.Vendor;
Expand Down Expand Up @@ -44,6 +45,8 @@ codeunit 10826 "Generate File FEC"
SourceCodesDescription: Dictionary of [Code[10], Text[100]];
PayablesAccounts: Dictionary of [Code[20], Code[20]];
ReceivablesAccounts: Dictionary of [Code[20], Code[20]];
PmtDiscountAccounts: Dictionary of [Code[20], Boolean];
PmtDiscountAccountsInitialized: Boolean;
BankAccounts: Dictionary of [Code[20], Text[100]];
BankAccPostingGroups: Dictionary of [Code[20], Code[20]];
ProgressDialog: Dialog;
Expand Down Expand Up @@ -233,6 +236,9 @@ codeunit 10826 "Generate File FEC"
end;

end;
if (PartyNo = '') and IsPaymentDiscountAccount(GLEntry."G/L Account No.") then
GetPartyForPaymentDiscount(GLEntry, PartyNo, PartyName);

AllowMultiplePosting(PartyNo, PartyName, GLEntry, Customer);

FindGLRegister(GLRegister, GLEntry."Entry No.");
Expand Down Expand Up @@ -672,6 +678,83 @@ codeunit 10826 "Generate File FEC"
end;
end;

local procedure IsPaymentDiscountAccount(GLAccountNo: Code[20]): Boolean
begin
if GLAccountNo = '' then
exit(false);

InitPmtDiscountAccountList();
exit(PmtDiscountAccounts.ContainsKey(GLAccountNo));
end;

local procedure InitPmtDiscountAccountList()
var
GeneralPostingSetup: Record "General Posting Setup";
CustomerPostingGroup: Record "Customer Posting Group";
VendorPostingGroup: Record "Vendor Posting Group";
begin
if PmtDiscountAccountsInitialized then
exit;

GeneralPostingSetup.SetLoadFields(
"Sales Pmt. Disc. Debit Acc.", "Sales Pmt. Disc. Credit Acc.",
"Purch. Pmt. Disc. Debit Acc.", "Purch. Pmt. Disc. Credit Acc.");
if GeneralPostingSetup.FindSet() then
repeat
AddPmtDiscountAccount(GeneralPostingSetup."Sales Pmt. Disc. Debit Acc.");
AddPmtDiscountAccount(GeneralPostingSetup."Sales Pmt. Disc. Credit Acc.");
AddPmtDiscountAccount(GeneralPostingSetup."Purch. Pmt. Disc. Debit Acc.");
AddPmtDiscountAccount(GeneralPostingSetup."Purch. Pmt. Disc. Credit Acc.");
until GeneralPostingSetup.Next() = 0;

CustomerPostingGroup.SetLoadFields("Payment Disc. Debit Acc.", "Payment Disc. Credit Acc.");
if CustomerPostingGroup.FindSet() then
repeat
AddPmtDiscountAccount(CustomerPostingGroup."Payment Disc. Debit Acc.");
AddPmtDiscountAccount(CustomerPostingGroup."Payment Disc. Credit Acc.");
until CustomerPostingGroup.Next() = 0;

VendorPostingGroup.SetLoadFields("Payment Disc. Debit Acc.", "Payment Disc. Credit Acc.");
if VendorPostingGroup.FindSet() then
repeat
AddPmtDiscountAccount(VendorPostingGroup."Payment Disc. Debit Acc.");
AddPmtDiscountAccount(VendorPostingGroup."Payment Disc. Credit Acc.");
until VendorPostingGroup.Next() = 0;

PmtDiscountAccountsInitialized := true;
end;

local procedure AddPmtDiscountAccount(GLAccountNo: Code[20])
begin
if (GLAccountNo <> '') and (not PmtDiscountAccounts.ContainsKey(GLAccountNo)) then
PmtDiscountAccounts.Add(GLAccountNo, true);
end;

local procedure GetPartyForPaymentDiscount(GLEntry: Record "G/L Entry"; var PartyNo: Code[20]; var PartyName: Text[100])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$\textbf{🟠\ High\ Severity\ —\ Performance}$

GetPartyForPaymentDiscount() is invoked from inside the G/L Entry export loop for every entry that resolves to a payment-discount account, and performs a fresh Customer.Get()/Vendor.Get() per matching entry. On a ledger with many payment-discount postings for the same customer/vendor this is an N+1 lookup pattern; cache resolved party No./Name per source type + source No. (e.g. in a Dictionary) instead of re-reading the persistent table for every matching row.

Knowledge:

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

var
Customer: Record Customer;
Vendor: Record Vendor;
begin
case GLEntry."Source Type" of
GLEntry."Source Type"::Customer:
begin
Customer.SetLoadFields(Name);
if Customer.Get(GLEntry."Source No.") then begin
PartyNo := Customer."No.";
PartyName := Customer.Name;
end;
end;
GLEntry."Source Type"::Vendor:
begin
Vendor.SetLoadFields(Name);
if Vendor.Get(GLEntry."Source No.") then begin
PartyNo := Vendor."No.";
PartyName := Vendor.Name;
end;
end;
end;
end;

local procedure ResetTransactionData()
begin
CustVendLedgEntryPartyNo := '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,62 @@ codeunit 148017 "FEC Audit File Export Tests"
VerifyExportGLEntriesReport(GLRegister, AuditFile, '', BankAccount."No.", BankAccount.Name);
end;

[Test]
[HandlerFunctions('ConfirmHandlerYes')]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$\textbf{🔴\ Critical\ Severity\ —\ Testing}$

The new test PaymentDiscountLineHasCustomerInfo lists [HandlerFunctions('ConfirmHandlerYes')] but never enqueues/verifies the expected confirm text via LibraryVariableStorage, and does not call AssertEmpty(). ConfirmHandlerYes hardcodes its answer, so nothing proves the correct dialog fired the expected number of times; the scenario can pass even if the wrong confirm appears or an extra confirm is introduced. Follow the enqueue/dequeue pattern (Enqueue expected text before acting, Dequeue and Assert.ExpectedConfirm in the handler, AssertEmpty() at the end) instead of a hardcoded-answer handler.

Knowledge:

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

procedure PaymentDiscountLineHasCustomerInfo()
var
Customer: Record Customer;
CustomerPostingGroup: Record "Customer Posting Group";
CustLedgerEntry: Record "Cust. Ledger Entry";
GenJournalBatch: Record "Gen. Journal Batch";
AuditFile: Record "Audit File";
iStream: InStream;
StartingDate: Date;
InvoiceDocNo: Code[20];
PaymentDocNo: Code[20];
InvoiceAmount: Decimal;
DiscountAmount: Decimal;
PmtDiscAccountNo: Code[20];
LineToRead: Text;
begin
// [SCENARIO 639574] CompAuxNum and CompAuxLib are informed for Payment Discount lines in the French Audit File
Initialize();
StartingDate := GetStartingDate();

// [GIVEN] Customer with a payment-discount payment term whose posting group has a Payment Disc. Debit Acc.
CreateCustomer(Customer);
CustomerPostingGroup.Get(Customer."Customer Posting Group");
if CustomerPostingGroup."Payment Disc. Debit Acc." = '' then begin
CustomerPostingGroup.Validate("Payment Disc. Debit Acc.", LibraryERM.CreateGLAccountNo());
CustomerPostingGroup.Modify(true);
end;
PmtDiscAccountNo := CustomerPostingGroup."Payment Disc. Debit Acc.";

// [GIVEN] A posted sales invoice with a possible payment discount
CreateGenJournalBatch(GenJournalBatch);
InvoiceAmount := LibraryRandom.RandDecInRange(1000, 2000, 2);
InvoiceDocNo :=
CreateGenJournalLine(GenJournalBatch, "Gen. Journal Document Type"::Invoice, "Gen. Journal Account Type"::Customer,
Customer."No.", StartingDate, InvoiceAmount);
LibraryERM.FindCustomerLedgerEntry(CustLedgerEntry, "Gen. Journal Document Type"::Invoice, InvoiceDocNo);
DiscountAmount := CustLedgerEntry."Original Pmt. Disc. Possible";
Assert.IsTrue(DiscountAmount > 0, 'The posted invoice should have a possible payment discount.');

// [GIVEN] A payment for (invoice amount - discount) applied to the invoice within the discount date, so the discount is granted
PaymentDocNo :=
CreateGenJournalLine(GenJournalBatch, "Gen. Journal Document Type"::Payment, "Gen. Journal Account Type"::Customer,
Customer."No.", StartingDate, -(InvoiceAmount - DiscountAmount));
ApplyAndPostGenJournalLine(PaymentDocNo, "Gen. Journal Document Type"::Invoice, InvoiceDocNo);

// [WHEN] Export Audit File in FEC format for the Payment Disc. Debit Acc. only
RunFECExport(AuditFile, PmtDiscAccountNo, StartingDate, StartingDate, false);

// [THEN] The exported Payment Discount line has CompAuxNum = Customer No. and CompAuxLib = Customer Name
CreateReadStream(iStream, AuditFile);
iStream.ReadText(LineToRead); // header
VerifyFilePartyNoAndName(iStream, Customer."No.", Customer.Name);
end;

local procedure Initialize()
begin
LibrarySetupStorage.Restore();
Expand Down
Loading