Skip to content
Merged
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 @@ -19,6 +19,7 @@ using Microsoft.Foundation.Address;
using Microsoft.Finance.Currency;
using System.IO;
using Microsoft.Sales.History;
using Microsoft.Foundation.Reporting;

codeunit 13916 "Export XRechnung Document"
{
Expand Down Expand Up @@ -513,7 +514,7 @@ codeunit 13916 "Export XRechnung Document"
PartyElement.Add(PartyLegalEntityElement);
end;

local procedure InsertContact(var RootElement: XmlElement; ContactName: Text[100]; Email: Text[80]);
local procedure InsertContact(var RootElement: XmlElement; ContactName: Text[100]; Email: Text[250]);
var
ContactElement: XmlElement;
begin
Expand Down Expand Up @@ -560,6 +561,8 @@ codeunit 13916 "Export XRechnung Document"
var
BillToAddress: Record "Standard Address";
Customer: Record Customer;
TempBodyReportSelections: Record "Report Selections" temporary;
ReportSelections: Record "Report Selections";
CustomerGLN: Text[13];
AccountingCustomerParty: XmlElement;
begin
Expand All @@ -573,17 +576,21 @@ codeunit 13916 "Export XRechnung Document"
AccountingCustomerParty := XmlElement.Create('AccountingCustomerParty', XmlNamespaceCAC);
if Customer."Use GLN in Electronic Document" then
CustomerGLN := Customer.GLN;
ReportSelections.FindEmailBodyUsageForCust("Report Selection Usage"::"S.Invoice", SalesInvoiceHeader."Bill-to Customer No.", TempBodyReportSelections);
InsertCustomerParty(
AccountingCustomerParty, Customer."VAT Registration No.", CustomerGLN,
SalesInvoiceHeader."Bill-to Name", BillToAddress, SalesInvoiceHeader."Sell-to Customer Name",
SalesInvoiceHeader."Sell-to Contact", SalesInvoiceHeader."Sell-to E-Mail");
AccountingCustomerParty, Customer."VAT Registration No.", CustomerGLN,
SalesInvoiceHeader."Bill-to Name", BillToAddress, SalesInvoiceHeader."Sell-to Customer Name",
SalesInvoiceHeader."Sell-to Contact",
ReportSelections.GetEmailAddressExt("Report Selection Usage"::"S.Invoice".AsInteger(), SalesInvoiceHeader, SalesInvoiceHeader."Bill-to Customer No.", TempBodyReportSelections));
RootXMLNode.Add(AccountingCustomerParty);
end;

local procedure InsertAccountingCustomerParty(var RootXMLNode: XmlElement; SalesCrMemoHeader: Record "Sales Cr.Memo Header")
var
BillToAddress: Record "Standard Address";
Customer: Record Customer;
TempBodyReportSelections: Record "Report Selections" temporary;
ReportSelections: Record "Report Selections";
CustomerGLN: Text[13];
AccountingCustomerParty: XmlElement;
begin
Expand All @@ -597,14 +604,16 @@ codeunit 13916 "Export XRechnung Document"
AccountingCustomerParty := XmlElement.Create('AccountingCustomerParty', XmlNamespaceCAC);
if Customer."Use GLN in Electronic Document" then
CustomerGLN := Customer.GLN;
ReportSelections.FindEmailBodyUsageForCust("Report Selection Usage"::"S.Cr.Memo", SalesCrMemoHeader."Bill-to Customer No.", TempBodyReportSelections);
InsertCustomerParty(
AccountingCustomerParty, Customer."VAT Registration No.", CustomerGLN,
SalesCrMemoHeader."Bill-to Name", BillToAddress, SalesCrMemoHeader."Sell-to Customer Name",
SalesCrMemoHeader."Sell-to Contact", SalesCrMemoHeader."Sell-to E-Mail");
AccountingCustomerParty, Customer."VAT Registration No.", CustomerGLN,
SalesCrMemoHeader."Bill-to Name", BillToAddress, SalesCrMemoHeader."Sell-to Customer Name",
SalesCrMemoHeader."Sell-to Contact",
ReportSelections.GetEmailAddressExt("Report Selection Usage"::"S.Cr.Memo".AsInteger(), SalesCrMemoHeader, SalesCrMemoHeader."Bill-to Customer No.", TempBodyReportSelections));
RootXMLNode.Add(AccountingCustomerParty);
end;

local procedure InsertCustomerParty(var AccountingCustomerParty: XmlElement; VATRegNo: Text[20]; CustomerGLN: Code[13]; PartyName: Text[100]; PostalAddress: Record "Standard Address"; CustomerName: Text[100]; ContactName: Text[100]; ContactEMail: Text[80]);
local procedure InsertCustomerParty(var AccountingCustomerParty: XmlElement; VATRegNo: Text[20]; CustomerGLN: Code[13]; PartyName: Text[100]; PostalAddress: Record "Standard Address"; CustomerName: Text[100]; ContactName: Text[100]; ContactEMail: Text[250]);
var
PartyElement: XmlElement;
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.eServices.EDocument.Formats;

using Microsoft.eServices.EDocument.Formats;
using System.Telemetry;
using Microsoft.eServices.EDocument;
using Microsoft.Foundation.PaymentTerms;
Expand Down Expand Up @@ -283,13 +282,69 @@ codeunit 13917 "Export ZUGFeRD Document"
OnAfterInsertSalesCrMemoHeaderData(RootXMLNode, SalesCrMemoHeader);
end;

local procedure InsertApplicableHeaderTradeAgreement(var RootXMLNode: XmlElement; CustomerNo: Code[20]; YourReference: Text[35])
local procedure InsertApplicableHeaderTradeAgreement(var RootXMLNode: XmlElement; RecordVariant: Variant)
var
Customer: Record Customer;
SalesInvoiceHeader: Record "Sales Invoice Header";
SalesCrMemoHeader: Record "Sales Cr.Memo Header";
TempBodyReportSelections: Record "Report Selections" temporary;
ReportSelections: Record "Report Selections";
DataTypeManagement: Codeunit "Data Type Management";
HeaderRecordRef: RecordRef;
HeaderTradeAgreementElement, SellerTradePartyElement, BuyerTradePartyElement, SpecifiedTaxRegistrationElement, IDElement : XmlElement;
PostalTradeAddressElement, ContactElement : XmlElement;
SellerIDAttr, BuyerIDAttr : XmlAttribute;
begin
CustomerNo: Code[20];
CustomerName: Text[100];
Address: Text[100];
Address2: Text[100];
PostCode: Text[20];
City: Text[50];
CountryCode: Code[10];
VATRegistrationNo: Text[20];
YourReference: Text[35];
Contact: Text[100];
CustomerEmail: Text[250];
PhoneNumber: Text[30];
begin
if not DataTypeManagement.GetRecordRef(RecordVariant, HeaderRecordRef) then
exit;
case HeaderRecordRef.Number of
Database::"Sales Invoice Header":
begin
HeaderRecordRef.SetTable(SalesInvoiceHeader);
CustomerNo := SalesInvoiceHeader."Bill-to Customer No.";
CustomerName := SalesInvoiceHeader."Bill-to Name";
Address := SalesInvoiceHeader."Bill-to Address";
Address2 := SalesInvoiceHeader."Bill-to Address 2";
PostCode := SalesInvoiceHeader."Bill-to Post Code";
City := SalesInvoiceHeader."Bill-to City";
CountryCode := SalesInvoiceHeader."VAT Country/Region Code";
VATRegistrationNo := SalesInvoiceHeader."VAT Registration No.";
YourReference := SalesInvoiceHeader."Your Reference";
Contact := SalesInvoiceHeader."Sell-to Contact";
ReportSelections.FindEmailBodyUsageForCust("Report Selection Usage"::"S.Invoice", CustomerNo, TempBodyReportSelections);
CustomerEmail := ReportSelections.GetEmailAddressExt("Report Selection Usage"::"S.Invoice".AsInteger(), RecordVariant, CustomerNo, TempBodyReportSelections);
PhoneNumber := SalesInvoiceHeader."Sell-to Phone No.";
end;
Database::"Sales Cr.Memo Header":
begin
HeaderRecordRef.SetTable(SalesCrMemoHeader);
CustomerNo := SalesCrMemoHeader."Bill-to Customer No.";
CustomerName := SalesCrMemoHeader."Bill-to Name";
Address := SalesCrMemoHeader."Bill-to Address";
Address2 := SalesCrMemoHeader."Bill-to Address 2";
PostCode := SalesCrMemoHeader."Bill-to Post Code";
City := SalesCrMemoHeader."Bill-to City";
CountryCode := SalesCrMemoHeader."VAT Country/Region Code";
VATRegistrationNo := SalesCrMemoHeader."VAT Registration No.";
YourReference := SalesCrMemoHeader."Your Reference";
Contact := SalesCrMemoHeader."Sell-to Contact";
ReportSelections.FindEmailBodyUsageForCust("Report Selection Usage"::"S.Cr.Memo", CustomerNo, TempBodyReportSelections);
CustomerEmail := ReportSelections.GetEmailAddressExt("Report Selection Usage"::"S.Cr.Memo".AsInteger(), RecordVariant, CustomerNo, TempBodyReportSelections);
PhoneNumber := SalesCrMemoHeader."Sell-to Phone No.";
end;
end;

HeaderTradeAgreementElement := XmlElement.Create('ApplicableHeaderTradeAgreement', XmlNamespaceRAM);
HeaderTradeAgreementElement.Add(XmlElement.Create('BuyerReference', XmlNamespaceRAM, GetBuyerReference(YourReference, CustomerNo)));

Expand All @@ -313,14 +368,22 @@ codeunit 13917 "Export ZUGFeRD Document"
SellerTradePartyElement.Add(ContactElement);
end;


// Seller Address
PostalTradeAddressElement := XmlElement.Create('PostalTradeAddress', XmlNamespaceRAM);
PostalTradeAddressElement.Add(XmlElement.Create('PostcodeCode', XmlNamespaceRAM, CompanyInformation."Post Code"));
PostalTradeAddressElement.Add(XmlElement.Create('LineOne', XmlNamespaceRAM, CompanyInformation.Address));
if CompanyInformation."Address 2" <> '' then
PostalTradeAddressElement.Add(XmlElement.Create('LineTwo', XmlNamespaceRAM, CompanyInformation."Address 2"));
PostalTradeAddressElement.Add(XmlElement.Create('CityName', XmlNamespaceRAM, CompanyInformation.City));
PostalTradeAddressElement.Add(XmlElement.Create('CountryID', XmlNamespaceRAM, GetCountryRegionCode(CompanyInformation."Country/Region Code")));
SellerTradePartyElement.Add(PostalTradeAddressElement);

//Seller E-Mail
if CompanyInformation."E-Mail" <> '' then
SellerTradePartyElement.Add(XmlElement.Create('URIUniversalCommunication', XmlNamespaceRAM,
XmlElement.Create('URIID', XmlNamespaceRAM, XmlAttribute.Create('schemeID', 'EM'), CompanyInformation."E-Mail")));

if CompanyInformation."VAT Registration No." <> '' then begin
SellerIDAttr := XmlAttribute.Create('schemeID', 'VA');
IDElement := XmlElement.Create('ID', XmlNamespaceRAM, SellerIDAttr, GetVATRegistrationNo(CompanyInformation."VAT Registration No.", CompanyInformation."Country/Region Code"));
Expand All @@ -331,33 +394,40 @@ codeunit 13917 "Export ZUGFeRD Document"
HeaderTradeAgreementElement.Add(SellerTradePartyElement);

// Buyer
Customer.Get(CustomerNo);
BuyerTradePartyElement := XmlElement.Create('BuyerTradeParty', XmlNamespaceRAM);
BuyerTradePartyElement.Add(XmlElement.Create('Name', XmlNamespaceRAM, Customer.Name));
BuyerTradePartyElement.Add(XmlElement.Create('Name', XmlNamespaceRAM, CustomerName));

// Buyer Contact
if Customer."Phone No." <> '' then begin
if PhoneNumber <> '' then begin
ContactElement := XmlElement.Create('DefinedTradeContact', XmlNamespaceRAM);
ContactElement.Add(XmlElement.Create('PersonName', XmlNamespaceRAM, Customer.Contact));
ContactElement.Add(XmlElement.Create('PersonName', XmlNamespaceRAM, Contact));
ContactElement.Add(XmlElement.Create('TelephoneUniversalCommunication', XmlNamespaceRAM,
XmlElement.Create('CompleteNumber', XmlNamespaceRAM, Customer."Phone No.")));
if Customer."E-Mail" <> '' then
XmlElement.Create('CompleteNumber', XmlNamespaceRAM, PhoneNumber)));
if CustomerEmail <> '' then
ContactElement.Add(XmlElement.Create('EmailURIUniversalCommunication', XmlNamespaceRAM,
XmlElement.Create('URIID', XmlNamespaceRAM, Customer."E-Mail")));
XmlElement.Create('URIID', XmlNamespaceRAM, CustomerEmail)));
BuyerTradePartyElement.Add(ContactElement);
end;


// Buyer Address
PostalTradeAddressElement := XmlElement.Create('PostalTradeAddress', XmlNamespaceRAM);
PostalTradeAddressElement.Add(XmlElement.Create('PostcodeCode', XmlNamespaceRAM, Customer."Post Code"));
PostalTradeAddressElement.Add(XmlElement.Create('LineOne', XmlNamespaceRAM, Customer.Address));
PostalTradeAddressElement.Add(XmlElement.Create('CityName', XmlNamespaceRAM, Customer.City));
PostalTradeAddressElement.Add(XmlElement.Create('CountryID', XmlNamespaceRAM, GetCountryRegionCode(Customer."Country/Region Code")));
PostalTradeAddressElement.Add(XmlElement.Create('PostcodeCode', XmlNamespaceRAM, PostCode));
PostalTradeAddressElement.Add(XmlElement.Create('LineOne', XmlNamespaceRAM, Address));
if Address2 <> '' then
PostalTradeAddressElement.Add(XmlElement.Create('LineTwo', XmlNamespaceRAM, Address2));
PostalTradeAddressElement.Add(XmlElement.Create('CityName', XmlNamespaceRAM, City));
PostalTradeAddressElement.Add(XmlElement.Create('CountryID', XmlNamespaceRAM, GetCountryRegionCode(CountryCode)));
BuyerTradePartyElement.Add(PostalTradeAddressElement);

if Customer."VAT Registration No." <> '' then begin
// Buyer E-Mail
if CustomerEmail <> '' then
BuyerTradePartyElement.Add(XmlElement.Create('URIUniversalCommunication', XmlNamespaceRAM,
XmlElement.Create('URIID', XmlNamespaceRAM, XmlAttribute.Create('schemeID', 'EM'), CustomerEmail)));

if VATRegistrationNo <> '' then begin
BuyerIDAttr := XmlAttribute.Create('schemeID', 'VA');
IDElement := XmlElement.Create('ID', XmlNamespaceRAM, BuyerIDAttr, GetVATRegistrationNo(Customer."VAT Registration No.", Customer."Country/Region Code"));
IDElement := XmlElement.Create('ID', XmlNamespaceRAM, BuyerIDAttr, GetVATRegistrationNo(VATRegistrationNo, CountryCode));
SpecifiedTaxRegistrationElement := XmlElement.Create('SpecifiedTaxRegistration', XmlNamespaceRAM);
SpecifiedTaxRegistrationElement.Add(IDElement);
BuyerTradePartyElement.Add(SpecifiedTaxRegistrationElement);
Expand Down Expand Up @@ -526,7 +596,7 @@ codeunit 13917 "Export ZUGFeRD Document"
repeat
InsertInvoiceLine(SupplyChainTradeTransactionElement, SalesInvoiceLine, Currency, CurrencyCode, SalesInvoiceHeader."Prices Including VAT");
until SalesInvoiceLine.Next() = 0;
InsertApplicableHeaderTradeAgreement(SupplyChainTradeTransactionElement, SalesInvoiceHeader."Sell-to Customer No.", SalesInvoiceHeader."Your Reference");
InsertApplicableHeaderTradeAgreement(SupplyChainTradeTransactionElement, SalesInvoiceHeader);
InsertApplicableHeaderTradeDelivery(SupplyChainTradeTransactionElement, SalesInvoiceHeader);
SalesInvoiceHeader.CalcFields("Amount Including VAT", Amount);
InsertApplicableHeaderTradeSettlement(SupplyChainTradeTransactionElement, SalesInvoiceHeader, SalesInvoiceLine, CurrencyCode, LineAmount, LineVATAmount, LineAmounts, LineDiscAmount);
Expand Down Expand Up @@ -608,7 +678,7 @@ codeunit 13917 "Export ZUGFeRD Document"
repeat
InsertCrMemoLine(SupplyChainTradeTransactionElement, SalesCrMemoLine, Currency, CurrencyCode, SalesCrMemoHeader."Prices Including VAT");
until SalesCrMemoLine.Next() = 0;
InsertApplicableHeaderTradeAgreement(SupplyChainTradeTransactionElement, SalesCrMemoHeader."Sell-to Customer No.", SalesCrMemoHeader."Your Reference");
InsertApplicableHeaderTradeAgreement(SupplyChainTradeTransactionElement, SalesCrMemoHeader);
InsertApplicableHeaderTradeDelivery(SupplyChainTradeTransactionElement, SalesCrMemoHeader);
SalesCrMemoHeader.CalcFields("Amount Including VAT", Amount);
InsertApplicableHeaderTradeSettlement(SupplyChainTradeTransactionElement, SalesCrMemoHeader, SalesCrMemoLine, CurrencyCode, LineAmount, LineVATAmount, LineAmounts, LineDiscAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ codeunit 13918 "XRechnung XML Document Tests"

local procedure SetEdocumentServiceBuyerReference(EInvoiceBuyerReference: Enum "E-Document Buyer Reference");
begin
EDocumentService."Buyer Reference Mandatory" := true;
EDocumentService."Buyer Reference" := EInvoiceBuyerReference;
EDocumentService.Modify();
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ codeunit 13922 "ZUGFeRD XML Document Tests"
Customer.Validate("Country/Region Code", CompanyInformation."Country/Region Code");
Customer.Validate("VAT Registration No.", CompanyInformation."VAT Registration No.");
Customer.Validate("E-Invoice Routing No.", LibraryUtility.GenerateRandomText(20));
Customer.Validate("E-Mail", LibraryUtility.GenerateRandomEmail());
Customer.Modify(true);
exit(Customer."No.")
end;
Expand Down Expand Up @@ -972,6 +973,9 @@ codeunit 13922 "ZUGFeRD XML Document Tests"
Path := DocumentTok + '/ram:PostalTradeAddress/ram:CityName';
Assert.AreEqual(CompanyInformation.City, GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));

Path := DocumentTok + '/ram:URIUniversalCommunication/ram:URIID';
Assert.AreEqual(CompanyInformation."E-Mail", GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));

Path := DocumentTok + '/ram:SpecifiedTaxRegistration/ram:ID';
Assert.AreEqual(GetVATRegistrationNo(CompanyInformation."VAT Registration No.", CompanyInformation."Country/Region Code"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
end;
Expand All @@ -983,6 +987,10 @@ codeunit 13922 "ZUGFeRD XML Document Tests"
begin
Path := DocumentPartyTok + '/ram:Name';
Assert.AreEqual(SalesInvoiceHeader."Bill-to Name", GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));

Path := DocumentPartyTok + '/ram:URIUniversalCommunication/ram:URIID';
Assert.AreEqual(SalesInvoiceHeader."Sell-to E-Mail", GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));

Path := DocumentPartyTok + '/ram:SpecifiedTaxRegistration/ram:ID';
Assert.AreEqual(GetVATRegistrationNo(SalesInvoiceHeader."VAT Registration No.", CompanyInformation."Country/Region Code"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
end;
Expand Down Expand Up @@ -1240,6 +1248,7 @@ codeunit 13922 "ZUGFeRD XML Document Tests"

local procedure SetEdocumentServiceBuyerReference(EInvoiceBuyerReference: Enum "E-Document Buyer Reference");
begin
EDocumentService."Buyer Reference Mandatory" := true;
EDocumentService."Buyer Reference" := EInvoiceBuyerReference;
EDocumentService.Modify();
end;
Expand Down
Loading