From 61d51fe08fe18ca886018a16b2be67c91bacd5c3 Mon Sep 17 00:00:00 2001
From: Kilian Seizinger <56249171+pri-kise@users.noreply.github.com>
Date: Mon, 22 Dec 2025 12:21:50 +0100
Subject: [PATCH 1/3] Simplify Integration
---
.../ZUGFeRD/ExportZUGFeRDDocument.Codeunit.al | 54 +++++++++++++++++++
.../ZUGFeRD/PostedSalesCrMemo.ReportExt.al | 36 ++-----------
.../ZUGFeRD/PostedSalesInvoice.ReportExt.al | 36 ++-----------
.../src/ZUGFeRDCustomSalesInvoice.Report.al | 31 +----------
4 files changed, 63 insertions(+), 94 deletions(-)
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..201c22be5b 100644
--- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
+++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
@@ -3,9 +3,8 @@
// 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"
{
@@ -14,8 +13,6 @@ reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Me
ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
begin
CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess();
- Clear(PDFDocument);
- PDFDocument.Initialize();
end;
trigger OnPreRendering(var RenderingPayload: JsonObject)
@@ -26,41 +23,15 @@ reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Me
[NonDebuggable]
local procedure OnRenderingCompleteJson(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
exit;
if not CreateZUGFeRDXML 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
@@ -74,7 +45,6 @@ reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Me
#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..44642ed53a 100644
--- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
+++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
@@ -3,9 +3,9 @@
// 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()
@@ -13,8 +13,6 @@ reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice"
ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
begin
CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess();
- Clear(PDFDocument);
- PDFDocument.Initialize();
end;
trigger OnPreRendering(var RenderingPayload: JsonObject)
@@ -25,40 +23,15 @@ reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice"
[NonDebuggable]
local procedure OnRenderingCompleteJson(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
exit;
if not CreateZUGFeRDXML 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
@@ -72,6 +45,5 @@ reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice"
#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..674e5ac104 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"
{
@@ -42,8 +40,6 @@ report 13918 "ZUGFeRD Custom Sales Invoice"
ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
begin
CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess();
- Clear(PDFDocument);
- PDFDocument.Initialize();
end;
trigger OnPreRendering(var RenderingPayload: JsonObject)
@@ -53,40 +49,17 @@ report 13918 "ZUGFeRD Custom Sales Invoice"
local procedure OnRenderingCompleteJson(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
exit;
if not CreateZUGFeRDXML 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);
- 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;
var
- PDFDocument: Codeunit "PDF Document";
CreateZUGFeRDXML: Boolean;
}
\ No newline at end of file
From ba196bbe40d362094637ff63f638c0f264196b1f Mon Sep 17 00:00:00 2001
From: Kilian Seizinger <56249171+pri-kise@users.noreply.github.com>
Date: Mon, 22 Dec 2025 12:24:30 +0100
Subject: [PATCH 2/3] Remove NonDebuggable
---
.../EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al | 1 -
.../EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al | 1 -
2 files changed, 2 deletions(-)
diff --git a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
index 201c22be5b..5040b33d70 100644
--- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
+++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
@@ -20,7 +20,6 @@ reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Me
this.OnRenderingCompleteJson(RenderingPayload);
end;
- [NonDebuggable]
local procedure OnRenderingCompleteJson(var RenderingPayload: JsonObject)
var
ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
diff --git a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
index 44642ed53a..2821888f6d 100644
--- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
+++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
@@ -20,7 +20,6 @@ reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice"
this.OnRenderingCompleteJson(RenderingPayload);
end;
- [NonDebuggable]
local procedure OnRenderingCompleteJson(var RenderingPayload: JsonObject)
var
ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
From 8990101bb714b721f44844061e2aa0266cec79cf Mon Sep 17 00:00:00 2001
From: Kilian Seizinger <56249171+pri-kise@users.noreply.github.com>
Date: Mon, 22 Dec 2025 16:31:01 +0100
Subject: [PATCH 3/3] Simplify Report Integration
---
.../src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al | 17 ++++-------------
.../src/ZUGFeRD/PostedSalesInvoice.ReportExt.al | 17 ++++-------------
.../src/ZUGFeRDCustomSalesInvoice.Report.al | 16 ++++------------
3 files changed, 12 insertions(+), 38 deletions(-)
diff --git a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
index 5040b33d70..7c49851e9f 100644
--- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
+++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesCrMemo.ReportExt.al
@@ -8,26 +8,20 @@ using Microsoft.Sales.History;
reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Memo"
{
- trigger OnPreReport()
- var
- ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
- begin
- CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess();
- 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
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;
ExportZUGFeRDDocument.CreateAndAddXMLAttachmentToRenderingPayload(Header, RenderingPayload);
@@ -43,7 +37,4 @@ reportextension 13919 "Posted Sales Cr.Memo" extends "Standard Sales - Credit Me
#endif
#pragma warning restore AS0072
- var
- 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 2821888f6d..a2a27eaef7 100644
--- a/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
+++ b/Apps/DE/EDocumentDE/app/src/ZUGFeRD/PostedSalesInvoice.ReportExt.al
@@ -8,26 +8,19 @@ using Microsoft.Sales.History;
reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice"
{
- trigger OnPreReport()
- var
- ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
- begin
- CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess();
- 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
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;
ExportZUGFeRDDocument.CreateAndAddXMLAttachmentToRenderingPayload(Header, RenderingPayload);
@@ -43,6 +36,4 @@ reportextension 13918 "Posted Sales Invoice" extends "Standard Sales - Invoice"
#endif
#pragma warning restore AS0072
- var
- 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 674e5ac104..bd95edcc5e 100644
--- a/Apps/DE/EDocumentDE/test/src/ZUGFeRDCustomSalesInvoice.Report.al
+++ b/Apps/DE/EDocumentDE/test/src/ZUGFeRDCustomSalesInvoice.Report.al
@@ -35,31 +35,23 @@ report 13918 "ZUGFeRD Custom Sales Invoice"
Type = Word;
}
}
- trigger OnPreReport()
- var
- ExportZUGFeRDDocument: Codeunit "Export ZUGFeRD Document";
- begin
- CreateZUGFeRDXML := ExportZUGFeRDDocument.IsZUGFeRDPrintProcess();
- 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
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;
ExportZUGFeRDDocument.CreateAndAddXMLAttachmentToRenderingPayload(Header, RenderingPayload);
end;
- var
- CreateZUGFeRDXML: Boolean;
}
\ No newline at end of file