Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.

Commit ec7f3d8

Browse files
authored
[BUG] [DE] Fix ZUGFeRD export Total Amounts (#29925)
#### Summary Fix Total Amount in ZUGFeRD export #### Work Item(s) Fixes #29923 [AB#631036](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/631036)
1 parent 467bc19 commit ec7f3d8

2 files changed

Lines changed: 48 additions & 12 deletions

File tree

‎Apps/DE/EDocumentDE/app/src/ZUGFeRD/ExportZUGFeRDDocument.Codeunit.al‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,13 @@ codeunit 13917 "Export ZUGFeRD Document"
745745

746746
InsertPaymentTerms(SettlementElement, SalesInvHeader."Payment Terms Code", SalesInvHeader."Due Date");
747747
MonetarySummationElement := XmlElement.Create('SpecifiedTradeSettlementHeaderMonetarySummation', XmlNamespaceRAM);
748-
MonetarySummationElement.Add(XmlElement.Create('LineTotalAmount', XmlNamespaceRAM, FormatDecimal(SalesInvLine.Amount + LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")))));
748+
MonetarySummationElement.Add(XmlElement.Create('LineTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName(Amount)) + LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")))));
749749
MonetarySummationElement.Add(XmlElement.Create('AllowanceTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Inv. Discount Amount")))));
750-
MonetarySummationElement.Add(XmlElement.Create('TaxBasisTotalAmount', XmlNamespaceRAM, FormatDecimal(SalesInvLine.Amount)));
751-
MonetarySummationElement.Add(XmlElement.Create('TaxTotalAmount', XmlNamespaceRAM, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(SalesInvLine."Amount Including VAT" - SalesInvLine.Amount)));
752-
MonetarySummationElement.Add(XmlElement.Create('GrandTotalAmount', XmlNamespaceRAM, FormatDecimal(SalesInvLine."Amount Including VAT")));
750+
MonetarySummationElement.Add(XmlElement.Create('TaxBasisTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName(Amount)))));
751+
MonetarySummationElement.Add(XmlElement.Create('TaxTotalAmount', XmlNamespaceRAM, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")) - LineAmounts.Get(SalesInvLine.FieldName(Amount)))));
752+
MonetarySummationElement.Add(XmlElement.Create('GrandTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")))));
753753
MonetarySummationElement.Add(XmlElement.Create('TotalPrepaidAmount', XmlNamespaceRAM, FormatDecimal(0)));
754-
MonetarySummationElement.Add(XmlElement.Create('DuePayableAmount', XmlNamespaceRAM, FormatDecimal(SalesInvLine."Amount Including VAT")));
754+
MonetarySummationElement.Add(XmlElement.Create('DuePayableAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesInvLine.FieldName("Amount Including VAT")))));
755755

756756
SettlementElement.Add(MonetarySummationElement);
757757
RootXMLNode.Add(SettlementElement);
@@ -770,13 +770,13 @@ codeunit 13917 "Export ZUGFeRD Document"
770770

771771
InsertPaymentTerms(SettlementElement, SalesCrMemoHeader."Payment Terms Code", SalesCrMemoHeader."Due Date");
772772
MonetarySummationElement := XmlElement.Create('SpecifiedTradeSettlementHeaderMonetarySummation', XmlNamespaceRAM);
773-
MonetarySummationElement.Add(XmlElement.Create('LineTotalAmount', XmlNamespaceRAM, FormatDecimal(SalesCrMemoLine.Amount + LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")))));
773+
MonetarySummationElement.Add(XmlElement.Create('LineTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)) + LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")))));
774774
MonetarySummationElement.Add(XmlElement.Create('AllowanceTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Inv. Discount Amount")))));
775-
MonetarySummationElement.Add(XmlElement.Create('TaxBasisTotalAmount', XmlNamespaceRAM, FormatDecimal(SalesCrMemoLine.Amount)));
776-
MonetarySummationElement.Add(XmlElement.Create('TaxTotalAmount', XmlNamespaceRAM, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(SalesCrMemoLine."Amount Including VAT" - SalesCrMemoLine.Amount)));
777-
MonetarySummationElement.Add(XmlElement.Create('GrandTotalAmount', XmlNamespaceRAM, FormatDecimal(SalesCrMemoLine."Amount Including VAT")));
775+
MonetarySummationElement.Add(XmlElement.Create('TaxBasisTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)))));
776+
MonetarySummationElement.Add(XmlElement.Create('TaxTotalAmount', XmlNamespaceRAM, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")) - LineAmounts.Get(SalesCrMemoLine.FieldName(Amount)))));
777+
MonetarySummationElement.Add(XmlElement.Create('GrandTotalAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")))));
778778
MonetarySummationElement.Add(XmlElement.Create('TotalPrepaidAmount', XmlNamespaceRAM, FormatDecimal(0)));
779-
MonetarySummationElement.Add(XmlElement.Create('DuePayableAmount', XmlNamespaceRAM, FormatDecimal(SalesCrMemoLine."Amount Including VAT")));
779+
MonetarySummationElement.Add(XmlElement.Create('DuePayableAmount', XmlNamespaceRAM, FormatDecimal(LineAmounts.Get(SalesCrMemoLine.FieldName("Amount Including VAT")))));
780780

781781
SettlementElement.Add(MonetarySummationElement);
782782
RootXMLNode.Add(SettlementElement);
@@ -877,7 +877,6 @@ codeunit 13917 "Export ZUGFeRD Document"
877877
until SalesInvoiceLine.Next() = 0;
878878
InsertApplicableHeaderTradeAgreement(SupplyChainTradeTransactionElement, SalesInvoiceHeader);
879879
InsertApplicableHeaderTradeDelivery(SupplyChainTradeTransactionElement, SalesInvoiceHeader);
880-
SalesInvoiceLine.CalcSums(Amount, "Amount Including VAT");
881880
InsertApplicableHeaderTradeSettlement(SupplyChainTradeTransactionElement, SalesInvoiceHeader, SalesInvoiceLine, CurrencyCode, LineAmount, LineVATAmount, LineAmounts, LineDiscAmount);
882881

883882
RootXMLNode.Add(SupplyChainTradeTransactionElement);
@@ -978,7 +977,6 @@ codeunit 13917 "Export ZUGFeRD Document"
978977
until SalesCrMemoLine.Next() = 0;
979978
InsertApplicableHeaderTradeAgreement(SupplyChainTradeTransactionElement, SalesCrMemoHeader);
980979
InsertApplicableHeaderTradeDelivery(SupplyChainTradeTransactionElement, SalesCrMemoHeader);
981-
SalesCrMemoLine.CalcSums(Amount, "Amount Including VAT");
982980
InsertApplicableHeaderTradeSettlement(SupplyChainTradeTransactionElement, SalesCrMemoHeader, SalesCrMemoLine, CurrencyCode, LineAmount, LineVATAmount, LineAmounts, LineDiscAmount);
983981

984982
RootXMLNode.Add(SupplyChainTradeTransactionElement);

‎Apps/DE/EDocumentDE/test/src/ZUGFeRDXMLDocumentTests.Codeunit.al‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,25 @@ codeunit 13922 "ZUGFeRD XML Document Tests"
427427
VerifyLegalMonetaryTotal(SalesInvoiceHeader, TempXMLBuffer);
428428
end;
429429

430+
[Test]
431+
procedure ExportPostedSalesInvoiceInZUGFeRDFormatVerifyLegalMonetaryTotalWithMultipleLines();
432+
var
433+
SalesInvoiceHeader: Record "Sales Invoice Header";
434+
TempXMLBuffer: Record "XML Buffer" temporary;
435+
begin
436+
// [SCENARIO] Export posted sales invoice with multiple lines creates ZUGFeRD document where LineTotalAmount equals the sum of all line amounts (BR-CO-10)
437+
Initialize();
438+
439+
// [GIVEN] Create and Post Sales Invoice with two lines.
440+
SalesInvoiceHeader.Get(CreateAndPostSalesDocumentWithTwoLines("Sales Document Type"::Invoice, Enum::"Sales Line Type"::Item, false));
441+
442+
// [WHEN] Export ZUGFeRD Electronic Document.
443+
ExportInvoice(SalesInvoiceHeader, TempXMLBuffer);
444+
445+
// [THEN] LineTotalAmount reflects the sum of all invoice lines, not just the last line
446+
VerifyLegalMonetaryTotal(SalesInvoiceHeader, TempXMLBuffer);
447+
end;
448+
430449
[Test]
431450
procedure ExportPostedSalesInvoiceInZUGFeRDFormatVerifyInvoiceLine();
432451
var
@@ -812,6 +831,25 @@ codeunit 13922 "ZUGFeRD XML Document Tests"
812831
VerifyLegalMonetaryTotal(SalesCrMemoHeader, TempXMLBuffer);
813832
end;
814833

834+
[Test]
835+
procedure ExportPostedSalesCrMemoInZUGFeRDFormatVerifyLegalMonetaryTotalWithMultipleLines();
836+
var
837+
SalesCrMemoHeader: Record "Sales Cr.Memo Header";
838+
TempXMLBuffer: Record "XML Buffer" temporary;
839+
begin
840+
// [SCENARIO] Export posted sales cr. memo with multiple lines creates ZUGFeRD document where LineTotalAmount equals the sum of all line amounts (BR-CO-10)
841+
Initialize();
842+
843+
// [GIVEN] Create and Post Sales Cr. Memo with two lines.
844+
SalesCrMemoHeader.Get(CreateAndPostSalesDocumentWithTwoLines("Sales Document Type"::"Credit Memo", Enum::"Sales Line Type"::Item, false));
845+
846+
// [WHEN] Export ZUGFeRD Electronic Document.
847+
ExportCreditMemo(SalesCrMemoHeader, TempXMLBuffer);
848+
849+
// [THEN] LineTotalAmount reflects the sum of all cr. memo lines, not just the last line
850+
VerifyLegalMonetaryTotal(SalesCrMemoHeader, TempXMLBuffer);
851+
end;
852+
815853
[Test]
816854
procedure ExportPostedSalesCrMemoInZUGFeRDFormatVerifyCrMemoLine();
817855
var

0 commit comments

Comments
 (0)