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 @@ -4,6 +4,7 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.eServices.EDocument.Formats;

using Microsoft.CRM.Team;
using Microsoft.eServices.EDocument;
using Microsoft.Finance.Currency;
using Microsoft.Finance.GeneralLedger.Setup;
Expand All @@ -14,6 +15,7 @@ using Microsoft.Foundation.Company;
using Microsoft.Foundation.PaymentTerms;
using Microsoft.Foundation.Reporting;
using Microsoft.Foundation.UOM;
using Microsoft.Inventory.Location;
using Microsoft.Sales.Customer;
using Microsoft.Sales.Document;
using Microsoft.Sales.History;
Expand Down Expand Up @@ -114,7 +116,7 @@ codeunit 13916 "Export XRechnung Document"
InsertEmbeddedDocument(RootXMLNode, SalesInvoiceHeader);
InsertAttachment(RootXMLNode, Database::"Sales Invoice Header", SalesInvoiceHeader."No.");
CalculateLineAmounts(SalesInvoiceHeader, SalesInvLine, Currency, LineAmounts);
InsertAccountingSupplierParty(RootXMLNode);
InsertAccountingSupplierParty(SalesInvoiceHeader."Responsibility Center", SalesInvoiceHeader."Salesperson Code", RootXMLNode);
InsertAccountingCustomerParty(RootXMLNode, SalesInvoiceHeader);
InsertDelivery(RootXMLNode, SalesInvoiceHeader);
InsertPaymentMeans(RootXMLNode, '68', 'PayeeFinancialAccount', SalesInvoiceHeader."Company Bank Account Code");
Expand Down Expand Up @@ -159,7 +161,7 @@ codeunit 13916 "Export XRechnung Document"
InsertEmbeddedDocument(RootXMLNode, SalesCrMemoHeader);
InsertAttachment(RootXMLNode, Database::"Sales Cr.Memo Header", SalesCrMemoHeader."No.");
CalculateLineAmounts(SalesCrMemoHeader, SalesCrMemoLine, Currency, LineAmounts);
InsertAccountingSupplierParty(RootXMLNode);
InsertAccountingSupplierParty(SalesCrMemoHeader."Responsibility Center", SalesCrMemoHeader."Salesperson Code", RootXMLNode);
InsertAccountingCustomerParty(RootXMLNode, SalesCrMemoHeader);
InsertDelivery(RootXMLNode, SalesCrMemoHeader);
InsertPaymentMeans(RootXMLNode, '68', '', SalesCrMemoHeader."Company Bank Account Code");
Expand Down Expand Up @@ -285,12 +287,12 @@ codeunit 13916 "Export XRechnung Document"
until SalesCrMemoLine.Next() = 0;
end;

local procedure InsertAccountingSupplierParty(var RootXMLNode: XmlElement)
local procedure InsertAccountingSupplierParty(RespCenterCode: Code[10]; SalespersonCode: Code[20]; var RootXMLNode: XmlElement)
var
AccountingSupplierPartyElement: XmlElement;
begin
AccountingSupplierPartyElement := XmlElement.Create('AccountingSupplierParty', XmlNamespaceCAC);
InsertSupplierParty(AccountingSupplierPartyElement);
InsertSupplierParty(RespCenterCode, SalespersonCode, AccountingSupplierPartyElement);
RootXMLNode.Add(AccountingSupplierPartyElement);
end;

Expand Down Expand Up @@ -348,14 +350,16 @@ codeunit 13916 "Export XRechnung Document"
local procedure InsertAddress(var RootElement: XmlElement; ElementName: Text; Address: Record "Standard Address");
var
AddressElement: XmlElement;
IdentificationCode: Code[2];
begin
AddressElement := XmlElement.Create(ElementName, XmlNamespaceCAC);
AddressElement.Add(XmlElement.Create('StreetName', XmlNamespaceCBC, Address.Address));
if Address."Address 2" <> '' then
AddressElement.Add(XmlElement.Create('AdditionalStreetName', XmlNamespaceCBC, Address."Address 2"));
AddressElement.Add(XmlElement.Create('CityName', XmlNamespaceCBC, Address.City));
AddressElement.Add(XmlElement.Create('PostalZone', XmlNamespaceCBC, Address."Post Code"));
InsertCountry(AddressElement, GetCountryRegionCode(Address."Country/Region Code"));
IdentificationCode := GetCountryISOCode(GetCountryRegionCode(Address."Country/Region Code"));
InsertCountry(AddressElement, IdentificationCode);
RootElement.Add(AddressElement);
end;

Expand Down Expand Up @@ -530,18 +534,46 @@ codeunit 13916 "Export XRechnung Document"
RootElement.Add(ContactElement);
end;

local procedure InsertContact(var RootElement: XmlElement);
local procedure InsertSupplierContact(SalespersonCode: Code[20]; var RootElement: XmlElement)
var
ContactElement: XmlElement;
ContactName: Text;
EmailAddress: Text;
PhoneNumber: Text;
begin
if not SetSupplierContactFromSalesPerson(SalespersonCode, ContactName, PhoneNumber, EmailAddress) then
SetSupplierContactFromCompanyInformation(ContactName, PhoneNumber, EmailAddress);

ContactElement := XmlElement.Create('Contact', XmlNamespaceCAC);
ContactElement.Add(XmlElement.Create('Name', XmlNamespaceCBC, CompanyInformation."Contact Person"));
ContactElement.Add(XmlElement.Create('Telephone', XmlNamespaceCBC, CompanyInformation."Phone No."));
ContactElement.Add(XmlElement.Create('ElectronicMail', XmlNamespaceCBC, CompanyInformation."E-Mail"));
ContactElement.Add(XmlElement.Create('Name', XmlNamespaceCBC, ContactName));
ContactElement.Add(XmlElement.Create('Telephone', XmlNamespaceCBC, PhoneNumber));
ContactElement.Add(XmlElement.Create('ElectronicMail', XmlNamespaceCBC, EmailAddress));
RootElement.Add(ContactElement);
end;

local procedure InsertSupplierParty(var AccountingSupplierPartyElement: XmlElement);
local procedure SetSupplierContactFromSalesPerson(SalespersonCode: Code[20]; var ContactName: Text; var PhoneNumber: Text; var EmailAddress: Text): Boolean
var
Salesperson: Record "Salesperson/Purchaser";
begin
if SalesPersonCode = '' then
exit(false);
Salesperson.SetLoadFields(Name, "Phone No.", "E-Mail");
if not Salesperson.Get(SalesPersonCode) then
exit(false);
ContactName := Salesperson.Name;
PhoneNumber := Salesperson."Phone No.";
EmailAddress := Salesperson."E-Mail";
exit(true);
end;

local procedure SetSupplierContactFromCompanyInformation(var ContactName: Text; var PhoneNumber: Text; var EmailAddress: Text)
begin
ContactName := CompanyInformation."Contact Person";
PhoneNumber := CompanyInformation."Phone No.";
EmailAddress := CompanyInformation."E-Mail";
end;

local procedure InsertSupplierParty(RespCenterCode: Code[10]; SalespersonCode: Code[20]; var AccountingSupplierPartyElement: XmlElement);
var
TempCompanyAddress: Record "Standard Address" temporary;
PartyElement: XmlElement;
Expand All @@ -555,10 +587,11 @@ codeunit 13916 "Export XRechnung Document"
InsertPartyIdentification(PartyElement, GetVATRegistrationNo(CompanyInformation."VAT Registration No.", CompanyInformation."Country/Region Code"));
InsertPartyName(PartyElement, CompanyInformation.Name);
TempCompanyAddress.CopyFromCompanyInformation(CompanyInformation);
UpdateSellerAddressFromResponsibilityCenter(RespCenterCode, TempCompanyAddress);
InsertAddress(PartyElement, 'PostalAddress', TempCompanyAddress);
InsertPartyTaxScheme(PartyElement, CompanyInformation."VAT Registration No.", CompanyInformation."Country/Region Code");
InsertPartyLegalEntity(PartyElement);
InsertContact(PartyElement);
InsertSupplierContact(SalespersonCode, PartyElement);
AccountingSupplierPartyElement.Add(PartyElement);
end;

Expand Down Expand Up @@ -1088,6 +1121,24 @@ codeunit 13916 "Export XRechnung Document"
TotalAmounts.Set(VATPercent, TotalAmounts.Get(VATPercent) + NewAmount);
end;

local procedure UpdateSellerAddressFromResponsibilityCenter(RespCenterCode: Code[10]; var TempCompanyAddress: Record "Standard Address" temporary)
var
RespCenter: Record "Responsibility Center";
begin
if RespCenterCode = '' then
exit;
if not RespCenter.Get(RespCenterCode) then
exit;

TempCompanyAddress.Address := RespCenter.Address;
TempCompanyAddress."Address 2" := RespCenter."Address 2";
TempCompanyAddress.City := RespCenter.City;
TempCompanyAddress."Country/Region Code" := RespCenter."Country/Region Code";
TempCompanyAddress."Post Code" := RespCenter."Post Code";
TempCompanyAddress.County := RespCenter.County;
TempCompanyAddress.Modify(false);
end;

local procedure FindEDocumentService(EDocumentFormat: Code[20])
begin
if EDocumentFormat = '' then
Expand Down Expand Up @@ -1170,6 +1221,14 @@ codeunit 13916 "Export XRechnung Document"
end;
end;

local procedure GetCountryISOCode(CountryRegionCode: Code[10]): Code[2]
var
CountryRegion: Record "Country/Region";
begin
CountryRegion.Get(CountryRegionCode);
exit(CountryRegion."ISO Code");
end;

local procedure GetCountryRegionCode(CountryRegionCode: Code[10]): Code[10]
begin
if CountryRegionCode <> '' then
Expand Down
Loading
Loading