diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index b05ffa60306..cd0571446e5 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7663,6 +7663,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7679,6 +7681,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/APAC/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al b/src/Layers/APAC/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al index 71c5cdb23b1..7919566f421 100644 --- a/src/Layers/APAC/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al +++ b/src/Layers/APAC/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al @@ -10,18 +10,19 @@ codeunit 134333 "ERM Purchase Prepayments" end; var - LibraryRandom: Codeunit "Library - Random"; - LibraryPurchase: Codeunit "Library - Purchase"; - LibraryERM: Codeunit "Library - ERM"; - LibraryUtility: Codeunit "Library - Utility"; - PurchasePostPrepayments: Codeunit "Purchase-Post Prepayments"; Assert: Codeunit Assert; - LibraryTestInitialize: Codeunit "Library - Test Initialize"; + LibraryERM: Codeunit "Library - ERM"; LibraryInventory: Codeunit "Library - Inventory"; + LibraryPurchase: Codeunit "Library - Purchase"; + LibraryRandom: Codeunit "Library - Random"; + LibraryTestInitialize: Codeunit "Library - Test Initialize"; + LibraryUtility: Codeunit "Library - Utility"; LibraryVariableStorage: Codeunit "Library - Variable Storage"; + PurchasePostPrepayments: Codeunit "Purchase-Post Prepayments"; IsInitialized: Boolean; LCYCode: Code[10]; NoAmtFoundToBePostedErr: Label 'No amount found to be posted.'; + PaymentReferenceNotTransferredErr: Label '%1 was not transferred to the %2.', Comment = '%1 Field Caption,%2 Table Caption'; local procedure Initialize() var @@ -427,6 +428,49 @@ codeunit 134333 "ERM Purchase Prepayments" Assert.AreEqual(PurchaseLine[1]."Line No.", PurchRcptLine."Order Line No.", ''); end; + [Test] + [HandlerFunctions('ConfirmHandler')] + procedure PaymentReferenceTransferredToVLEOnPurchasePrepaymentInvoice() + var + GLAccount: Record "G/L Account"; + Item: Record Item; + PurchaseHeader: Record "Purchase Header"; + Vendor: Record Vendor; + VendorLedgerEntry: Record "Vendor Ledger Entry"; + PurchaseOrder: TestPage "Purchase Order"; + begin + // [SCENARIO 643383] Payment Reference from the Purchase Order is transferred to the Vendor Ledger Entry when posting a prepayment invoice. + Initialize(); + + // [GIVEN] Prepayment posting setup, an item and a vendor with a prepayment %. + PreparePrepaymentsPostingSetup(GLAccount); + PrepareItemAccordingToSetup(Item, GLAccount); + PrepareVendorAccordingToSetup(Vendor, GLAccount, LibraryRandom.RandInt(100)); + + // [GIVEN] A Purchase Order with a Payment Reference specified. + CreatePurchOrder(PurchaseHeader, Vendor, Item, LCYCode); + + PurchaseHeader.Validate("Payment Reference", LibraryUtility.GenerateRandomCode(PurchaseHeader.FieldNo("Payment Reference"), Database::"Purchase Header")); + PurchaseHeader.Modify(true); + + // [WHEN] Post the prepayment invoice via Purchase order page. + PurchaseOrder.OpenEdit(); + PurchaseOrder.GoToRecord(PurchaseHeader); + PurchaseOrder.PostPrepaymentInvoice.Invoke(); + Commit(); + PurchaseOrder.Close(); + + // [THEN] The Vendor Ledger Entry created for the prepayment carries the Payment Reference from the Purchase Order. + CheckNumOfVendorLedgerEntries(VendorLedgerEntry, Vendor, 1); + VendorLedgerEntry.FindFirst(); + + // [THEN] The Payment Reference from the Purchase Header should be transferred to the Vendor Ledger Entry table. + Assert.AreEqual( + PurchaseHeader."Payment Reference", VendorLedgerEntry."Payment Reference", + StrSubstNo( + PaymentReferenceNotTransferredErr, PurchaseHeader.FieldCaption("Payment Reference"), VendorLedgerEntry.TableCaption())); + end; + local procedure PreparePrepaymentsPostingSetup(var GLAccount: Record "G/L Account") var PrepmtGLAccount: Record "G/L Account"; diff --git a/src/Layers/BE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/BE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 85d7d6614ba..05a9cd5d8e1 100644 --- a/src/Layers/BE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/BE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7285,6 +7285,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7301,6 +7303,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 7e7a13a8c0d..9eb7337c73e 100644 --- a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7386,6 +7386,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7402,6 +7404,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 1896513ef6d..28c295c3833 100644 --- a/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/DACH/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7277,6 +7277,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7293,6 +7295,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 69ebf919521..c69c6103347 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7434,6 +7434,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7451,6 +7453,13 @@ table 81 "Gen. Journal Line" "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; "Recipient Bank Account" := PurchHeader."Vendor Bank Acc. Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index a8ca79cd724..98b7467395b 100644 --- a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7318,6 +7318,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7334,6 +7336,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/FR/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/FR/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 282be3f97af..23c49f101e1 100644 --- a/src/Layers/FR/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/FR/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7298,6 +7298,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7314,6 +7316,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 0cfde9ca3b8..6ef0666858e 100644 --- a/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/GB/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7254,6 +7254,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7270,6 +7272,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index c2e3072ca35..b5d11e82fd4 100644 --- a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7934,6 +7934,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7950,6 +7952,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 4ca5163551a..90a27cef024 100644 --- a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7401,6 +7401,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7417,6 +7419,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index f5bc2f1f0b1..ed1ff8733b4 100644 --- a/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/NL/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7294,6 +7294,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7310,6 +7312,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 9542c800353..6167bcd4673 100644 --- a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7518,6 +7518,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7534,6 +7536,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index d63a7113d64..294de8032e2 100644 --- a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -8438,6 +8438,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -8454,6 +8456,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/SE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/SE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index eaa007377ef..ea17c40685f 100644 --- a/src/Layers/SE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/SE/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7265,6 +7265,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7281,6 +7283,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al index 282a375b0d1..c6d568df999 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/GenJournalLine.Table.al @@ -7245,6 +7245,8 @@ table 81 "Gen. Journal Line" end; procedure CopyFromPurchHeaderPrepmtPost(PurchHeader: Record "Purchase Header"; UsePmtDisc: Boolean) + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; begin "Account Type" := "Account Type"::Vendor; "Account No." := PurchHeader."Pay-to Vendor No."; @@ -7261,6 +7263,13 @@ table 81 "Gen. Journal Line" "Due Date" := PurchHeader."Prepayment Due Date"; "Payment Terms Code" := PurchHeader."Payment Terms Code"; "Payment Method Code" := PurchHeader."Payment Method Code"; + if PurchHeader."Payment Reference" <> '' then + "Payment Reference" := PurchHeader."Payment Reference" + else begin + PurchasesPayablesSetup.Get(); + if PurchasesPayablesSetup."Copy Inv. No. To Pmt. Ref." then + "Payment Reference" := PurchHeader."Vendor Invoice No."; + end; if UsePmtDisc then begin "Pmt. Discount Date" := PurchHeader."Prepmt. Pmt. Discount Date"; "Payment Discount %" := PurchHeader."Prepmt. Payment Discount %"; diff --git a/src/Layers/W1/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al b/src/Layers/W1/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al index 6108583e29b..686dd0824ba 100644 --- a/src/Layers/W1/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al +++ b/src/Layers/W1/Tests/Prepayment/ERMPurchasePrepayments.Codeunit.al @@ -10,18 +10,19 @@ codeunit 134333 "ERM Purchase Prepayments" end; var - LibraryRandom: Codeunit "Library - Random"; - LibraryPurchase: Codeunit "Library - Purchase"; - LibraryERM: Codeunit "Library - ERM"; - LibraryUtility: Codeunit "Library - Utility"; - PurchasePostPrepayments: Codeunit "Purchase-Post Prepayments"; Assert: Codeunit Assert; - LibraryTestInitialize: Codeunit "Library - Test Initialize"; + LibraryERM: Codeunit "Library - ERM"; LibraryInventory: Codeunit "Library - Inventory"; + LibraryPurchase: Codeunit "Library - Purchase"; + LibraryRandom: Codeunit "Library - Random"; + LibraryTestInitialize: Codeunit "Library - Test Initialize"; + LibraryUtility: Codeunit "Library - Utility"; LibraryVariableStorage: Codeunit "Library - Variable Storage"; + PurchasePostPrepayments: Codeunit "Purchase-Post Prepayments"; IsInitialized: Boolean; LCYCode: Code[10]; NoAmtFoundToBePostedErr: Label 'No amount found to be posted.'; + PaymentReferenceNotTransferredErr: Label '%1 was not transferred to the %2.', Comment = '%1 Field Caption,%2 Table Caption'; local procedure Initialize() var @@ -426,6 +427,49 @@ codeunit 134333 "ERM Purchase Prepayments" Assert.AreEqual(PurchaseLine[1]."Line No.", PurchRcptLine."Order Line No.", ''); end; + [Test] + [HandlerFunctions('ConfirmHandler')] + procedure PaymentReferenceTransferredToVLEOnPurchasePrepaymentInvoice() + var + GLAccount: Record "G/L Account"; + Item: Record Item; + PurchaseHeader: Record "Purchase Header"; + Vendor: Record Vendor; + VendorLedgerEntry: Record "Vendor Ledger Entry"; + PurchaseOrder: TestPage "Purchase Order"; + begin + // [SCENARIO 643383] Payment Reference from the Purchase Order is transferred to the Vendor Ledger Entry when posting a prepayment invoice. + Initialize(); + + // [GIVEN] Prepayment posting setup, an item and a vendor with a prepayment %. + PreparePrepaymentsPostingSetup(GLAccount); + PrepareItemAccordingToSetup(Item, GLAccount); + PrepareVendorAccordingToSetup(Vendor, GLAccount, LibraryRandom.RandInt(100)); + + // [GIVEN] A Purchase Order with a Payment Reference specified. + CreatePurchOrder(PurchaseHeader, Vendor, Item, LCYCode); + + PurchaseHeader.Validate("Payment Reference", LibraryUtility.GenerateRandomCode(PurchaseHeader.FieldNo("Payment Reference"), Database::"Purchase Header")); + PurchaseHeader.Modify(true); + + // [WHEN] Post the prepayment invoice via Purchase order page. + PurchaseOrder.OpenEdit(); + PurchaseOrder.GoToRecord(PurchaseHeader); + PurchaseOrder.PostPrepaymentInvoice.Invoke(); + Commit(); + PurchaseOrder.Close(); + + // [THEN] The Vendor Ledger Entry created for the prepayment carries the Payment Reference from the Purchase Order. + CheckNumOfVendorLedgerEntries(VendorLedgerEntry, Vendor, 1); + VendorLedgerEntry.FindFirst(); + + // [THEN] The Payment Reference from the Purchase Header should be transferred to the Vendor Ledger Entry table. + Assert.AreEqual( + PurchaseHeader."Payment Reference", VendorLedgerEntry."Payment Reference", + StrSubstNo( + PaymentReferenceNotTransferredErr, PurchaseHeader.FieldCaption("Payment Reference"), VendorLedgerEntry.TableCaption())); + end; + local procedure PreparePrepaymentsPostingSetup(var GLAccount: Record "G/L Account") var PrepmtGLAccount: Record "G/L Account";