diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al index d975f90883..8ce4f57ff7 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al @@ -6,6 +6,7 @@ namespace Microsoft.eServices.EDocument; using System.Telemetry; using System.Utilities; +using Microsoft.Foundation.Attachment; using Microsoft.eServices.EDocument.Integration.Send; using Microsoft.eServices.EDocument.Integration.Receive; using Microsoft.Bank.Reconciliation; @@ -185,6 +186,16 @@ page 6121 "E-Document" } #endif } + area(factboxes) + { + part("Attached Documents List"; "Doc. Attachment List Factbox") + { + Caption = 'Documents'; + UpdatePropagation = Both; + SubPageLink = "E-Document Entry No." = field("Entry No"), + "E-Document Attachment" = const(true); + } + } } actions { diff --git a/Apps/W1/EDocument/app/src/Document/EDocuments.Page.al b/Apps/W1/EDocument/app/src/Document/EDocuments.Page.al index f54f4880a6..c512fcdd34 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocuments.Page.al +++ b/Apps/W1/EDocument/app/src/Document/EDocuments.Page.al @@ -3,6 +3,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // ------------------------------------------------------------------------------------------------ namespace Microsoft.eServices.EDocument; +using Microsoft.Foundation.Attachment; page 6122 "E-Documents" { @@ -55,6 +56,16 @@ page 6122 "E-Documents" } } } + area(factboxes) + { + part(DocumentListFactBox; "Doc. Attachment List Factbox") + { + Caption = 'Documents'; + UpdatePropagation = Both; + SubPageLink = "E-Document Entry No." = field("Entry No"), + "E-Document Attachment" = const(true); + } + } } actions { diff --git a/Apps/W1/EDocument/app/src/Processing/EDocAttachmentProcessor.Codeunit.al b/Apps/W1/EDocument/app/src/Processing/EDocAttachmentProcessor.Codeunit.al index b1e6db8471..64364397aa 100644 --- a/Apps/W1/EDocument/app/src/Processing/EDocAttachmentProcessor.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Processing/EDocAttachmentProcessor.Codeunit.al @@ -126,6 +126,36 @@ codeunit 6169 "E-Doc. Attachment Processor" end; end; + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Document Attachment Mgmt", OnAfterGetRefTable, '', false, false)] + local procedure OnAfterGetRefTableForEDocs(var RecRef: RecordRef; DocumentAttachment: Record "Document Attachment") + var + EDocument: Record "E-Document"; + begin + case DocumentAttachment."Table ID" of + Database::"E-Document": + begin + RecRef.Open(Database::"E-Document"); + if EDocument.Get(DocumentAttachment."No.") then + RecRef.GetTable(EDocument); + end; + end; + end; + + [EventSubscriber(ObjectType::Page, Page::"Doc. Attachment List FactBox", OnBeforeDocumentAttachmentDetailsRunModal, '', false, false)] + local procedure FilterEDocumentAttachmentsOnBeforeDocumentAttachmentDetailsRunModal(var DocumentAttachment: Record "Document Attachment"; var DocumentAttachmentDetails: Page "Document Attachment Details") + var + EDocumentEntryNo: Integer; + EDocumentEntryNoText: Text; + begin + DocumentAttachment.FilterGroup(4); + EDocumentEntryNoText := DocumentAttachment.GetFilter("E-Document Entry No."); + if EDocumentEntryNoText <> '' then begin + Evaluate(EDocumentEntryNo, EDocumentEntryNoText); + DocumentAttachmentDetails.FilterForEDocuments(EDocumentEntryNo); + end; + DocumentAttachment.FilterGroup(0); + end; + var MissingEDocumentTypeErr: Label 'E-Document type %1 is not supported for attachments', Comment = '%1 - E-Document document type'; diff --git a/Apps/W1/EDocument/app/src/Processing/EDocDocumentAttachmentDetails.PageExt.al b/Apps/W1/EDocument/app/src/Processing/EDocDocumentAttachmentDetails.PageExt.al new file mode 100644 index 0000000000..dd1c95de87 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Processing/EDocDocumentAttachmentDetails.PageExt.al @@ -0,0 +1,11 @@ +namespace Microsoft.eServices.EDocument; +using Microsoft.Foundation.Attachment; + +pageextension 6102 EDocDocumentAttachmentDetails extends "Document Attachment Details" +{ + internal procedure FilterForEDocuments(EDocumentEntryNo: Integer) + begin + Rec.SetRange("E-Document Attachment", true); + Rec.SetRange("E-Document Entry No.", EDocumentEntryNo); + end; +} diff --git a/Apps/W1/EDocument/test/src/Receive/EDocReceiveTest.Codeunit.al b/Apps/W1/EDocument/test/src/Receive/EDocReceiveTest.Codeunit.al index 98a2793f6b..f1678b62b2 100644 --- a/Apps/W1/EDocument/test/src/Receive/EDocReceiveTest.Codeunit.al +++ b/Apps/W1/EDocument/test/src/Receive/EDocReceiveTest.Codeunit.al @@ -1342,6 +1342,45 @@ codeunit 139628 "E-Doc. Receive Test" PurchaseHeader.Delete(true); end; + [Test] + [HandlerFunctions('SelectPOHandlerCancel,ConfirmHandler')] + procedure ReceiveSinglePurchaseInvoice_PEPPOL_WithAttachment_WithoutLinkedOrder() + var + EDocService: Record "E-Document Service"; + EDocument: Record "E-Document"; + Item: Record Item; + DocumentAttachment: Record "Document Attachment"; + VATPostingSetup: Record "VAT Posting Setup"; + DocumentVendor: Record Vendor; + begin + // [FEATURE] [E-Document] [Receive] + // [SCENARIO] Receive single e-document with two attachments without linking to purchase order + Initialize(); + BindSubscription(EDocImplState); + + // [GIVEN] e-Document service to receive one single purchase order + CreateEDocServiceToReceivePurchaseOrder(EDocService); + // [GIVEN] Vendor with VAT Posting Setup + CreateVendorWithVatPostingSetup(DocumentVendor, VATPostingSetup); + // [GIVEN] Item with item reference + CreateItemWithReference(Item, VATPostingSetup); + // [GIVEN] Incoming PEPPOL file + CreateIncomingPEPPOL(DocumentVendor); + // [GIVEN] Purchase order created for vendor + CreatePurchaseOrder(Item, DocumentVendor); + + // [WHEN] Running Receive + InvokeReceive(EDocService); + + // [THEN] Attachments are imported and linked with e-Document + EDocument.FindLast(); + DocumentAttachment.SetRange("No.", Format(EDocument."Entry No")); + DocumentAttachment.SetRange("Table ID", Database::"E-Document"); + DocumentAttachment.SetRange("E-Document Entry No.", EDocument."Entry No"); + DocumentAttachment.SetRange("E-Document Attachment", true); + Assert.RecordCount(DocumentAttachment, 2); + end; + [ModalPageHandler] procedure SelectPOHandler(var POList: TestPage "Purchase Order List") var @@ -1437,6 +1476,93 @@ codeunit 139628 "E-Doc. Receive Test" Assert.AreEqual(PurchHeader."Amount Including VAT", Abs(GenJnlLine.Amount), ''); end; + local procedure CreateEDocServiceToReceivePurchaseOrder(var EDocService: Record "E-Document Service") + begin + LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::Mock); + SetDefaultEDocServiceValues(EDocService); + end; + + local procedure CreateVendorWithVatPostingSetup(var DocumentVendor: Record Vendor; var VATPostingSetup: Record "VAT Posting Setup") + begin + LibraryPurchase.CreateVendorWithVATRegNo(DocumentVendor); + LibraryERM.CreateVATPostingSetupWithAccounts(VATPostingSetup, Enum::"Tax Calculation Type"::"Normal VAT", 1); + DocumentVendor."VAT Bus. Posting Group" := VATPostingSetup."VAT Bus. Posting Group"; + DocumentVendor."Receive E-Document To" := Enum::"E-Document Type"::"Purchase Order"; + DocumentVendor.Modify(false); + end; + + local procedure CreateItemWithReference(var Item: Record Item; var VATPostingSetup: Record "VAT Posting Setup") + var + ItemReference: Record "Item Reference"; + begin + Item.FindFirst(); + Item."VAT Prod. Posting Group" := VATPostingSetup."VAT Prod. Posting Group"; + Item.Modify(false); + ItemReference.DeleteAll(false); + ItemReference."Item No." := Item."No."; + ItemReference."Reference No." := '1000'; + ItemReference.Insert(false); + end; + + local procedure CreateIncomingPEPPOL(var DocumentVendor: Record Vendor) + var + TempXMLBuffer: Record "XML Buffer" temporary; + TempBlob: Codeunit "Temp Blob"; + Document: Text; + XMLInstream: InStream; + begin + TempXMLBuffer.LoadFromText(EDocReceiveFiles.GetDocument1()); + TempXMLBuffer.Reset(); + TempXMLBuffer.SetRange(Type, TempXMLBuffer.Type::Element); + TempXMLBuffer.SetRange(Path, '/Invoice/cac:AccountingSupplierParty/cac:Party/cbc:EndpointID'); + TempXMLBuffer.FindFirst(); + TempXMLBuffer.Value := DocumentVendor."VAT Registration No."; + TempXMLBuffer.Modify(); + + TempXMLBuffer.Reset(); + TempXMLBuffer.FindFirst(); + TempXMLBuffer.Save(TempBlob); + + TempBlob.CreateInStream(XMLInstream, TextEncoding::UTF8); + XMLInstream.Read(Document); + + LibraryVariableStorage.Clear(); + LibraryVariableStorage.Enqueue(Document); + LibraryVariableStorage.Enqueue(1); + EDocImplState.SetVariableStorage(LibraryVariableStorage); + end; + + local procedure CreatePurchaseOrder(var Item: Record Item; var DocumentVendor: Record Vendor) + begin + LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Order, DocumentVendor."No."); + LibraryPurchase.CreatePurchaseLine(PurchaseLine, PurchaseHeader, PurchaseLine.Type::Item, Item."No.", 10); + PurchaseLine.Validate("Direct Unit Cost", 100); + PurchaseLine.Modify(true); + end; + + local procedure InvokeReceive(var EDocService: Record "E-Document Service") + var + EDocServicePage: TestPage "E-Document Service"; + begin + EDocServicePage.OpenView(); + EDocServicePage.Filter.SetFilter(Code, EDocService.Code); + EDocServicePage.Receive.Invoke(); + end; + + local procedure SetDefaultEDocServiceValues(var EDocService: Record "E-Document Service") + begin + EDocService."Document Format" := "E-Document Format"::"PEPPOL BIS 3.0"; + EDocService."Lookup Account Mapping" := false; + EDocService."Lookup Item GTIN" := false; + EDocService."Lookup Item Reference" := false; + EDocService."Resolve Unit Of Measure" := false; + EDocService."Validate Line Discount" := false; + EDocService."Verify Totals" := false; + EDocService."Use Batch Processing" := false; + EDocService."Validate Receiving Company" := false; + EDocService.Modify(false); + end; + [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Document Create Purch. Doc.", 'OnBeforeProcessHeaderFieldsAssignment', '', false, false)] local procedure OnBeforeProcessHeaderFieldsAssignment(var DocumentHeader: RecordRef; var PurchaseField: Record Field); begin