Skip to content
Draft
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 @@ -67,6 +67,60 @@ codeunit 13917 "Export ZUGFeRD Document"
begin
end;

/// <summary>
/// Creates a ZUGFeRD XML document from the sales invoice and adds it as an attachment to the rendering payload.
/// </summary>
/// <param name="SalesInvoiceHeader">The sales invoice header record to export.</param>
/// <param name="RenderingPayload">The JSON object to add the XML attachment to.</param>
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;

/// <summary>
/// Creates a ZUGFeRD XML document from the sales credit memo and adds it as an attachment to the rendering payload.
/// </summary>
/// <param name="SalesCrMemoHeader">The sales credit memo header record to export.</param>
/// <param name="RenderingPayload">The JSON object to add the XML attachment to.</param>
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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"
{
Expand Down Expand Up @@ -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;
}
Loading