diff --git a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/ExportZUGFeRDDocument.Codeunit.al b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/ExportZUGFeRDDocument.Codeunit.al index d4c39ccdf1..ff4f250318 100644 --- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/ExportZUGFeRDDocument.Codeunit.al +++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/ExportZUGFeRDDocument.Codeunit.al @@ -67,6 +67,60 @@ codeunit 13917 "Export ZUGFeRD Document" begin end; + /// + /// Creates a ZUGFeRD XML document from the sales invoice and adds it as an attachment to the rendering payload. + /// + /// The sales invoice header record to export. + /// The JSON object to add the XML attachment to. + procedure CreateAndAddXMLAttachmentToRenderingPayload(var SalesInvoiceHeader: Record "Sales Invoice Header"; var RenderingPayload: JsonObject) + var + TempBlob: Codeunit "Temp Blob"; + XmlOutStream: OutStream; + begin + TempBlob.CreateOutStream(XmlOutStream, TextEncoding::UTF8); + CreateXML(SalesInvoiceHeader, XmlOutStream); + + AddXMLAttachmentToRenderingPayload(TempBlob, RenderingPayload); + end; + + /// + /// Creates a ZUGFeRD XML document from the sales credit memo and adds it as an attachment to the rendering payload. + /// + /// The sales credit memo header record to export. + /// The JSON object to add the XML attachment to. + procedure CreateAndAddXMLAttachmentToRenderingPayload(var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var RenderingPayload: JsonObject) + var + TempBlob: Codeunit "Temp Blob"; + XmlOutStream: OutStream; + begin + TempBlob.CreateOutStream(XmlOutStream, TextEncoding::UTF8); + CreateXML(SalesCrMemoHeader, XmlOutStream); + + AddXMLAttachmentToRenderingPayload(TempBlob, RenderingPayload); + end; + + local procedure AddXMLAttachmentToRenderingPayload(var XmlAttachmentTempBlob: Codeunit "Temp Blob"; var RenderingPayload: JsonObject) + var + XmlInStream: InStream; + XmlOutStream: OutStream; + Name: Text; + MimeType: Text; + Description: Text; + DataType: Enum "PDF Attach. Data Relationship"; + PDFDocument: Codeunit "PDF Document"; + begin + PDFDocument.Initialize(); + Name := 'factur-x.xml'; + DataType := Enum::"PDF Attach. Data Relationship"::Alternative; + MimeType := 'text/xml'; + Description := 'This is the e-invoicing xml document'; + + XmlAttachmentTempBlob.CreateInStream(XmlInStream, TextEncoding::UTF8); + PDFDocument.AddAttachment(Name, DataType, MimeType, XmlInStream, Description, true); + + RenderingPayload := PDFDocument.ToJson(RenderingPayload); + end; + procedure ExportSalesDocument(var RecordExportBuffer: Record "Record Export Buffer") var SalesInvoiceHeader: Record "Sales Invoice Header"; diff --git a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al index abae143ea2..7c49851e9f 100644 --- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al +++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al @@ -3,64 +3,28 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // ------------------------------------------------------------------------------------------------ namespace Microsoft.eServices.EDocument.Formats; + using Microsoft.Sales.History; -using System.IO; -using System.Utilities; reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Memo" { - trigger OnPreReport() - var - ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; - begin - CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess(); - Clear(PDFDocument); - PDFDocument.Initialize(); - end; trigger OnPreRendering(var RenderingPayload: JsonObject) begin - this.OnRenderingCompleteJson(RenderingPayload); + AddXMLAttachmentforZUGFeRDExport(RenderingPayload); end; - [NonDebuggable] - local procedure OnRenderingCompleteJson(var RenderingPayload: JsonObject) + local procedure AddXMLAttachmentforZUGFeRDExport(var RenderingPayload: JsonObject) var - TempBlob: Codeunit "Temp Blob"; - XmlInStream: InStream; - UserCode: SecretText; - AdminCode: SecretText; - Name: Text; - MimeType: Text; - Description: Text; - DataType: Enum "PDF Attach. Data Relationship"; + ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; begin - if CurrReport.TargetFormat <> ReportFormat::PDF then + if CurrReport.TargetFormat() <> ReportFormat::PDF then exit; - if not CreateZUGFeRDXML then + if not ExportZUGFeRDDocument.IsZUGFeRDPrintProcess() then exit; - Name := 'factur-x.xml'; - CreateXmlFile(TempBlob); - DataType := "PDF Attach. Data Relationship"::Alternative; - MimeType := 'text/xml'; - Description := 'This is the e-invoicing xml document'; - TempBlob.CreateInStream(XmlInStream, TextEncoding::UTF8); - PDFDocument.AddAttachment(Name, DataType, MimeType, XmlInStream, Description, true); - - RenderingPayload := PDFDocument.ToJson(RenderingPayload); - PDFDocument.ProtectDocument(UserCode, AdminCode); - end; - - - local procedure CreateXmlFile(var TempBlob: Codeunit "Temp Blob") - var - ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; - OutStream: OutStream; - begin - TempBlob.CreateOutStream(OutStream, TextEncoding::UTF8); - ExportZUGFeRDDocument.CreateXML(Header, OutStream); + ExportZUGFeRDDocument.CreateAndAddXMLAttachmentToRenderingPayload(Header, RenderingPayload); end; #pragma warning disable AS0072 @@ -73,8 +37,4 @@ reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Me #endif #pragma warning restore AS0072 - var - PDFDocument: Codeunit "PDF Document"; - CreateZUGFeRDXML: Boolean; - } \ No newline at end of file diff --git a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al index a1f0ba6ed2..a2a27eaef7 100644 --- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al +++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al @@ -3,62 +3,27 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // ------------------------------------------------------------------------------------------------ namespace Microsoft.eServices.EDocument.Formats; -using System.Utilities; + using Microsoft.Sales.History; -using System.IO; + reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice" { - trigger OnPreReport() - var - ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; - begin - CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess(); - Clear(PDFDocument); - PDFDocument.Initialize(); - end; - trigger OnPreRendering(var RenderingPayload: JsonObject) begin - this.OnRenderingCompleteJson(RenderingPayload); + AddXMLAttachmentforZUGFeRDExport(RenderingPayload); end; - [NonDebuggable] - local procedure OnRenderingCompleteJson(var RenderingPayload: JsonObject) + local procedure AddXMLAttachmentforZUGFeRDExport(var RenderingPayload: JsonObject) var - TempBlob: Codeunit "Temp Blob"; - XmlInStream: InStream; - UserCode: SecretText; - AdminCode: SecretText; - Name: Text; - MimeType: Text; - Description: Text; - DataType: Enum "PDF Attach. Data Relationship"; + ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; begin - if CurrReport.TargetFormat <> ReportFormat::PDF then + if CurrReport.TargetFormat() <> ReportFormat::PDF then exit; - if not CreateZUGFeRDXML then + if not ExportZUGFeRDDocument.IsZUGFeRDPrintProcess() then exit; - Name := 'factur-x.xml'; - CreateXmlFile(TempBlob); - DataType := "PDF Attach. Data Relationship"::Alternative; - MimeType := 'text/xml'; - Description := 'This is the e-invoicing xml document'; - TempBlob.CreateInStream(XmlInStream, TextEncoding::UTF8); - PDFDocument.AddAttachment(Name, DataType, MimeType, XmlInStream, Description, true); - - RenderingPayload := PDFDocument.ToJson(RenderingPayload); - PDFDocument.ProtectDocument(UserCode, AdminCode); - end; - - local procedure CreateXmlFile(var TempBlob: Codeunit "Temp Blob") - var - ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; - OutStream: OutStream; - begin - TempBlob.CreateOutStream(OutStream, TextEncoding::UTF8); - ExportZUGFeRDDocument.CreateXML(Header, OutStream); + ExportZUGFeRDDocument.CreateAndAddXMLAttachmentToRenderingPayload(Header, RenderingPayload); end; #pragma warning disable AS0072 @@ -71,7 +36,4 @@ reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice" #endif #pragma warning restore AS0072 - var - PDFDocument: Codeunit "PDF Document"; - CreateZUGFeRDXML: Boolean; } \ No newline at end of file diff --git a/Apps/DE/EDocumentDE/test/src/ZUGFeRDCustomSalesInvoice.Report.al b/Apps/DE/EDocumentDE/test/src/ZUGFeRDCustomSalesInvoice.Report.al index 7086d86cc5..bd95edcc5e 100644 --- a/Apps/DE/EDocumentDE/test/src/ZUGFeRDCustomSalesInvoice.Report.al +++ b/Apps/DE/EDocumentDE/test/src/ZUGFeRDCustomSalesInvoice.Report.al @@ -1,8 +1,6 @@ namespace Microsoft.eServices.EDocument.Formats; using Microsoft.Sales.History; -using System.IO; -using System.Utilities; report 13918 "ZUGFeRD Custom Sales Invoice" { @@ -37,56 +35,23 @@ report 13918 "ZUGFeRD Custom Sales Invoice" Type = Word; } } - trigger OnPreReport() - var - ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; - begin - CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess(); - Clear(PDFDocument); - PDFDocument.Initialize(); - end; trigger OnPreRendering(var RenderingPayload: JsonObject) begin - this.OnRenderingCompleteJson(RenderingPayload); + AddXMLAttachmentforZUGFeRDExport(RenderingPayload); end; - local procedure OnRenderingCompleteJson(var RenderingPayload: JsonObject) + local procedure AddXMLAttachmentforZUGFeRDExport(var RenderingPayload: JsonObject) var - TempBlob: Codeunit "Temp Blob"; - XmlInStream: InStream; - Name: Text; - MimeType: Text; - Description: Text; - DataType: Enum "PDF Attach. Data Relationship"; + ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; begin - if CurrReport.TargetFormat <> ReportFormat::PDF then + if CurrReport.TargetFormat() <> ReportFormat::PDF then exit; - if not CreateZUGFeRDXML then + if not ExportZUGFeRDDocument.IsZUGFeRDPrintProcess() then exit; - Name := 'factur-x.xml'; - CreateXmlFile(TempBlob); - DataType := DataType::Alternative; - MimeType := 'text/xml'; - Description := 'This is the e-invoicing xml document'; - - TempBlob.CreateInStream(XmlInStream, TextEncoding::UTF8); - PDFDocument.AddAttachment(Name, DataType, MimeType, XmlInStream, Description, true); - RenderingPayload := PDFDocument.ToJson(RenderingPayload); + ExportZUGFeRDDocument.CreateAndAddXMLAttachmentToRenderingPayload(Header, RenderingPayload); end; - local procedure CreateXmlFile(var TempBlob: Codeunit "Temp Blob") - var - ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document"; - OutStream: OutStream; - begin - TempBlob.CreateOutStream(OutStream, TextEncoding::UTF8); - ExportZUGFeRDDocument.CreateXML(Header, OutStream); - end; - - var - PDFDocument: Codeunit "PDF Document"; - CreateZUGFeRDXML: Boolean; } \ No newline at end of file