Skip to content
Open
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 @@ -39,11 +39,13 @@ codeunit 13916 "Export XRechnung Document"
EDocumentService: Record "E-Document Service";
FeatureTelemetry: Codeunit "Feature Telemetry";
PEPPOLMgt: Codeunit "PEPPOL Management";
TypeHelper: Codeunit "Type Helper";
FeatureNameTok: Label 'E-document XRechnung Format', Locked = true;
StartEventNameTok: Label 'E-document XRechnung export started', Locked = true;
EndEventNameTok: Label 'E-document XRechnung export completed', Locked = true;
XmlNamespaceCBC: Text;
XmlNamespaceCAC: Text;
AlwaysIncludeTwoDecimalPlacesForAmountFields: Boolean;

trigger OnRun();
begin
Expand All @@ -70,6 +72,7 @@ codeunit 13916 "Export XRechnung Document"
RecordRef.SetTable(SalesInvoiceHeader);

FindEDocumentService(RecordExportBuffer."Electronic Document Format");
InitializeDecimalFormatFlags();
RecordExportBuffer."File Content".CreateOutStream(FileOutStream, TextEncoding::UTF8);
CreateXML(SalesInvoiceHeader, FileOutStream);
RecordExportBuffer.Modify();
Expand All @@ -87,6 +90,7 @@ codeunit 13916 "Export XRechnung Document"
RecordRef.SetTable(SalesCrMemoHeader);

FindEDocumentService(RecordExportBuffer."Electronic Document Format");
InitializeDecimalFormatFlags();
RecordExportBuffer."File Content".CreateOutStream(FileOutStream, TextEncoding::UTF8);
CreateXML(SalesCrMemoHeader, FileOutStream);
RecordExportBuffer.Modify();
Expand All @@ -104,6 +108,7 @@ codeunit 13916 "Export XRechnung Document"
RecordRef.SetTable(ServiceInvoiceHeader);

FindEDocumentService(RecordExportBuffer."Electronic Document Format");
InitializeDecimalFormatFlags();
RecordExportBuffer."File Content".CreateOutStream(FileOutStream, TextEncoding::UTF8);
CreateXML(ServiceInvoiceHeader, FileOutStream);
RecordExportBuffer.Modify();
Expand All @@ -121,6 +126,7 @@ codeunit 13916 "Export XRechnung Document"
RecordRef.SetTable(ServiceCrMemoHeader);

FindEDocumentService(RecordExportBuffer."Electronic Document Format");
InitializeDecimalFormatFlags();
RecordExportBuffer."File Content".CreateOutStream(FileOutStream, TextEncoding::UTF8);
CreateXML(ServiceCrMemoHeader, FileOutStream);
RecordExportBuffer.Modify();
Expand Down Expand Up @@ -603,7 +609,7 @@ codeunit 13916 "Export XRechnung Document"
PriceElement: XmlElement;
begin
PriceElement := XmlElement.Create('Price', XmlNamespaceCAC);
PriceElement.Add(XmlElement.Create('PriceAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimalUnlimited(UnitPrice)));
PriceElement.Add(XmlElement.Create('PriceAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimalUnlimited(UnitPrice, AlwaysIncludeTwoDecimalPlacesForAmountFields)));
RootElement.Add(PriceElement);
end;

Expand Down Expand Up @@ -856,8 +862,8 @@ codeunit 13916 "Export XRechnung Document"
AllowanceChargeElement.Add(XmlElement.Create('ChargeIndicator', XmlNamespaceCBC, 'false'));
AllowanceChargeElement.Add(XmlElement.Create('AllowanceChargeReason', XmlNamespaceCBC, AllowanceChargeReason));
AllowanceChargeElement.Add(XmlElement.Create('MultiplierFactorNumeric', XmlNamespaceCBC, FormatFiveDecimal(MultiplierFactorNumeric)));
AllowanceChargeElement.Add(XmlElement.Create('Amount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(Amount)));
AllowanceChargeElement.Add(XmlElement.Create('BaseAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(BaseAmount)));
AllowanceChargeElement.Add(XmlElement.Create('Amount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(Amount, AlwaysIncludeTwoDecimalPlacesForAmountFields)));
AllowanceChargeElement.Add(XmlElement.Create('BaseAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(BaseAmount, AlwaysIncludeTwoDecimalPlacesForAmountFields)));
if InsertTaxCat then
InsertTaxCategory(AllowanceChargeElement, 'TaxCategory', TaxCategory, Percent);
RootXMLNode.Add(AllowanceChargeElement);
Expand All @@ -868,8 +874,8 @@ codeunit 13916 "Export XRechnung Document"
TaxSubtotalElement: XmlElement;
begin
TaxSubtotalElement := XmlElement.Create('TaxSubtotal', XmlNamespaceCAC);
TaxSubtotalElement.Add(XmlElement.Create('TaxableAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(TaxableAmount)));
TaxSubtotalElement.Add(XmlElement.Create('TaxAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(TaxAmount)));
TaxSubtotalElement.Add(XmlElement.Create('TaxableAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(TaxableAmount, AlwaysIncludeTwoDecimalPlacesForAmountFields)));
TaxSubtotalElement.Add(XmlElement.Create('TaxAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(TaxAmount, AlwaysIncludeTwoDecimalPlacesForAmountFields)));
InsertTaxCategory(TaxSubtotalElement, 'TaxCategory', TaxCategory, VATPercentage);
RootElement.Add(TaxSubtotalElement);
end;
Expand All @@ -890,7 +896,7 @@ codeunit 13916 "Export XRechnung Document"
TaxTotalElement: XmlElement;
begin
TaxTotalElement := XmlElement.Create('TaxTotal', XmlNamespaceCAC);
TaxTotalElement.Add(XmlElement.Create('TaxAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(GetTotalTaxAmount(SalesInvLine))));
TaxTotalElement.Add(XmlElement.Create('TaxAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(GetTotalTaxAmount(SalesInvLine), AlwaysIncludeTwoDecimalPlacesForAmountFields)));

if SalesInvLine.FindSet() then
repeat
Expand All @@ -916,7 +922,7 @@ codeunit 13916 "Export XRechnung Document"
TaxTotalElement: XmlElement;
begin
TaxTotalElement := XmlElement.Create('TaxTotal', XmlNamespaceCAC);
TaxTotalElement.Add(XmlElement.Create('TaxAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(GetTotalTaxAmount(SalesCrMemoLine))));
TaxTotalElement.Add(XmlElement.Create('TaxAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(GetTotalTaxAmount(SalesCrMemoLine), AlwaysIncludeTwoDecimalPlacesForAmountFields)));

if SalesCrMemoLine.FindSet() then
repeat
Expand All @@ -942,12 +948,12 @@ codeunit 13916 "Export XRechnung Document"
LegalMonetaryTotalElement: XmlElement;
begin
LegalMonetaryTotalElement := XmlElement.Create('LegalMonetaryTotal', XmlNamespaceCAC);
LegalMonetaryTotalElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName(Amount)) + LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxExclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName(Amount)))));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxInclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName(Amount)) + LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxExclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName(Amount)), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxInclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
if LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")) > 0 then
LegalMonetaryTotalElement.Add(XmlElement.Create('AllowanceTotalAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('PayableAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('AllowanceTotalAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
LegalMonetaryTotalElement.Add(XmlElement.Create('PayableAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
RootXMLNode.Add(LegalMonetaryTotalElement);
end;

Expand All @@ -956,12 +962,12 @@ codeunit 13916 "Export XRechnung Document"
LegalMonetaryTotalElement: XmlElement;
begin
LegalMonetaryTotalElement := XmlElement.Create('LegalMonetaryTotal', XmlNamespaceCAC);
LegalMonetaryTotalElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)) + LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxExclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)))));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxInclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)) + LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxExclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
LegalMonetaryTotalElement.Add(XmlElement.Create('TaxInclusiveAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
if LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")) > 0 then
LegalMonetaryTotalElement.Add(XmlElement.Create('AllowanceTotalAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('PayableAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")))));
LegalMonetaryTotalElement.Add(XmlElement.Create('AllowanceTotalAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
LegalMonetaryTotalElement.Add(XmlElement.Create('PayableAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")), AlwaysIncludeTwoDecimalPlacesForAmountFields)));
RootXMLNode.Add(LegalMonetaryTotalElement);
end;

Expand Down Expand Up @@ -1028,7 +1034,7 @@ codeunit 13916 "Export XRechnung Document"
ExcludeVAT(SalesInvLine, Currency."Amount Rounding Precision");
InvoiceLineElement.Add(XmlElement.Create('ID', XmlNamespaceCBC, Format(SalesInvLine."Line No.")));
InvoiceLineElement.Add(XmlElement.Create('InvoicedQuantity', XmlNamespaceCBC, XmlAttribute.Create('unitCode', GetUoMCode(SalesInvLine."Unit of Measure Code")), FormatDecimalUnlimited(SalesInvLine.Quantity)));
InvoiceLineElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(SalesInvLine.Amount + SalesInvLine."Inv. Discount Amount")));
InvoiceLineElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(SalesInvLine.Amount + SalesInvLine."Inv. Discount Amount", AlwaysIncludeTwoDecimalPlacesForAmountFields)));
if SalesInvLine."Shipment Date" <> 0D then
InsertInvoicePeriod(InvoiceLineElement, SalesInvLine."Shipment Date", SalesInvLine."Shipment Date");
InsertOrderLineReference(InvoiceLineElement, SalesInvLine."Line No.");
Expand Down Expand Up @@ -1067,7 +1073,7 @@ codeunit 13916 "Export XRechnung Document"
ExcludeVAT(SalesCrMemoLine, Currency."Amount Rounding Precision");
CrMemoLineElement.Add(XmlElement.Create('ID', XmlNamespaceCBC, Format(SalesCrMemoLine."Line No.")));
CrMemoLineElement.Add(XmlElement.Create('CreditedQuantity', XmlNamespaceCBC, XmlAttribute.Create('unitCode', GetUoMCode(SalesCrMemoLine."Unit of Measure Code")), FormatDecimalUnlimited(SalesCrMemoLine.Quantity)));
CrMemoLineElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(SalesCrMemoLine.Amount + SalesCrMemoLine."Inv. Discount Amount")));
CrMemoLineElement.Add(XmlElement.Create('LineExtensionAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(SalesCrMemoLine.Amount + SalesCrMemoLine."Inv. Discount Amount", AlwaysIncludeTwoDecimalPlacesForAmountFields)));
InsertOrderLineReference(CrMemoLineElement, SalesCrMemoLine."Line No.");
if SalesCrMemoLine."Shipment Date" <> 0D then
InsertInvoicePeriod(CrMemoLineElement, SalesCrMemoLine."Shipment Date", SalesCrMemoLine."Shipment Date");
Expand Down Expand Up @@ -1355,6 +1361,13 @@ codeunit 13916 "Export XRechnung Document"
if EDocumentService.FindLast() then;
OnAfterFindEDocumentService(EDocumentService, EDocumentFormat);
end;

local procedure InitializeDecimalFormatFlags()
begin
AlwaysIncludeTwoDecimalPlacesForAmountFields := false;
OnInitializeDecimalFormatFlags(AlwaysIncludeTwoDecimalPlacesForAmountFields);
end;

#region CommonFunctions
procedure FormatDate(VarDate: Date): Text[20];
begin
Expand All @@ -1365,12 +1378,31 @@ codeunit 13916 "Export XRechnung Document"

procedure FormatDecimal(VarDecimal: Decimal): Text[30];
begin
exit(Format(Round(VarDecimal, 0.01), 0, 9));
exit(FormatDecimal(VarDecimal, false));
end;

procedure FormatDecimal(VarDecimal: Decimal; IncludeDecimalPlaces: Boolean): Text[30];
var
DecimalRounded: Decimal;
begin
DecimalRounded := Round(VarDecimal, 0.01);
if IncludeDecimalPlaces then
exit(Format(DecimalRounded, 0, TypeHelper.GetXMLAmountFormatWithTwoDecimalPlaces()))
else
exit(Format(DecimalRounded, 0, 9));
end;

procedure FormatDecimalUnlimited(VarDecimal: Decimal): Text
begin
exit(Format(VarDecimal, 0, 9));
exit(FormatDecimalUnlimited(VarDecimal, false));
end;

procedure FormatDecimalUnlimited(VarDecimal: Decimal; IncludeMinTwoDecimals: Boolean): Text
begin
if IncludeMinTwoDecimals then
exit(Format(VarDecimal, 0, '<Precision,2:><Standard Format,9>'))
else
exit(Format(VarDecimal, 0, 9));
end;

#if not CLEAN29
Expand Down Expand Up @@ -1609,4 +1641,13 @@ codeunit 13916 "Export XRechnung Document"
local procedure OnInsertAttachmentOnAfterSetFilters(TableNo: Integer; DocumentNo: Code[20]; var DocumentAttachment: Record "Document Attachment")
begin
end;

/// <summary>
/// Use this event to always include two decimal places for amount fields
/// </summary>
/// <param name="AlwaysIncludeTwoDecimalPlacesForAmountFields">Set to true to force all amount fields to include two decimal places (e.g. 1.10 instead of 1.1)</param>
[IntegrationEvent(false, false)]
local procedure OnInitializeDecimalFormatFlags(var AlwaysIncludeTwoDecimalPlacesForAmountFields: Boolean)
begin
end;
}
Loading
Loading