Skip to content

Commit

Permalink
sync with c# lib 2024 08 12 v14
Browse files Browse the repository at this point in the history
  • Loading branch information
landrix committed Aug 12, 2024
1 parent 97c3c7d commit de06a99
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 55 deletions.
1 change: 1 addition & 0 deletions Test/DUnitXZUGFeRDTest.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ uses
intf.ZUGFeRDInvoiceDescriptor20Reader,intf.ZUGFeRDInvoiceDescriptor20Writer,intf.ZUGFeRD20Tests.UnitTests,
intf.ZUGFeRDInvoiceDescriptor22CIIReader,intf.ZUGFeRDInvoiceDescriptor22Writer,intf.ZUGFeRD22Tests.UnitTests,
intf.ZUGFeRDInvoiceDescriptor22UBLReader,
intf.XRechnungUBLTests.UnitTests,
intf.ZUGFeRDBaseTests.UnitTests
;

Expand Down
136 changes: 136 additions & 0 deletions Test/intf.XRechnungUBLTests.UnitTests.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.}

unit intf.XRechnungUBLTests.UnitTests;

interface

uses
System.SysUtils
,DUnitX.TestFramework
,intf.ZUGFeRDInvoiceDescriptor
,intf.ZUGFeRDProfile,intf.ZUGFeRDInvoiceTypes
,intf.ZUGFeRDInvoiceProvider
,intf.ZUGFeRDVersion
;

type
[TestFixture]
TXRechnungUBLTests = class
public
[Test]
procedure TestInvoiceCreation;
[Test]
procedure TestTradelineitemProductCharacterstics;
/// <summary>
/// https://github.com/stephanstapel/ZUGFeRD-csharp/issues/319
/// </summary>
[Test]
procedure TestSkippingOfAllowanceChargeBasisAmount;
end;

implementation

{ TXRechnungUBLTests }

procedure TXRechnungUBLTests.TestInvoiceCreation;
begin
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
// MemoryStream ms = new MemoryStream();
//
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
// ms.Seek(0, SeekOrigin.Begin);
//
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
//
// Assert.AreEqual(loadedInvoice.Invoicee, null);
// Assert.AreNotEqual(loadedInvoice.Seller, null);
// Assert.AreEqual(loadedInvoice.Taxes.Count, 2);
// Assert.AreEqual(loadedInvoice.SellerContact.Name, "Max Mustermann");
// Assert.IsNull(loadedInvoice.BuyerContact);
end;

procedure TXRechnungUBLTests.TestSkippingOfAllowanceChargeBasisAmount;
begin
// // actual values do not matter
// decimal basisAmount = 123.0m;
// decimal percent = 11.0m;
// decimal allowanceChargeBasisAmount = 121.0m;
//
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
// desc.AddApplicableTradeTax(basisAmount, percent, TaxTypes.LOC, TaxCategoryCodes.K, allowanceChargeBasisAmount);
// MemoryStream ms = new MemoryStream();
//
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
// ms.Seek(0, SeekOrigin.Begin);
//
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
//
// Tax tax = loadedInvoice.Taxes.FirstOrDefault(t => t.TypeCode == TaxTypes.LOC);
// Assert.IsNotNull(tax);
// Assert.AreEqual(basisAmount, tax.BasisAmount);
// Assert.AreEqual(percent, tax.Percent);
// Assert.AreEqual(null, tax.AllowanceChargeBasisAmount);
end;

procedure TXRechnungUBLTests.TestTradelineitemProductCharacterstics;
begin
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
//
// desc.TradeLineItems[0].ApplicableProductCharacteristics = new ApplicableProductCharacteristic[]
// {
// new ApplicableProductCharacteristic()
// {
// Description = "Test Description",
// Value = "1.5 kg"
// },
// new ApplicableProductCharacteristic()
// {
// Description = "UBL Characterstics 2",
// Value = "3 kg"
// },
// }.ToList();
//
// MemoryStream ms = new MemoryStream();
//
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
// ms.Seek(0, SeekOrigin.Begin);
//
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
//
// Assert.IsNotNull(loadedInvoice.TradeLineItems);
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics.Count, 2);
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[0].Description, "Test Description");
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[1].Value, "3 kg");
end;

initialization

//I was hoping to use RTTI to discover the TestFixture classes, however unlike .NET
//if we don't touch the class somehow then the linker will remove
//the class from the resulting exe.
//We could just do this:
//TMyExampleTests.ClassName;
//TExampleFixture2.ClassName;
//which is enough to make the compiler link the classes into the exe, but that seems a
//bit redundent so I guess we'll just use manual registration. If you use the
//{$STRONGLINKTYPES ON} compiler directive then it will link the TestFixtures in and you
//can use RTTI. The downside to that is the resulting exe will potentially much larger.
//Not sure which version {$STRONGLINKTYPES ON} was introduced so we'll allow RTTI and
//manual registration for now.

end.
93 changes: 41 additions & 52 deletions Test/intf.ZUGFeRD22Tests.UnitTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ TZUGFeRD22Tests = class
[Test]
procedure TestSpecifiedTradeAllowanceCharge;
[Test]
procedure TestUBLInvoiceCreation;
[Test]
procedure TestUBLTradelineitemProductCharacterstics;
[Test]
procedure TestSellerDescription;
[Test]
procedure TestSellerContact;
end;

implementation
Expand Down Expand Up @@ -1245,6 +1243,45 @@ procedure TZUGFeRD22Tests.TestOrderInformation;
//
end;

procedure TZUGFeRD22Tests.TestSellerContact;
begin
// InvoiceDescriptor invoice = InvoiceProvider.CreateInvoice();
//
// string description = "Test description";
//
// invoice.SetSeller(name: "Lieferant GmbH",
// postcode: "80333",
// city: "München",
// street: "Lieferantenstraße 20",
// country: CountryCodes.DE,
// id: "",
// globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452"),
// legalOrganization: new LegalOrganization(GlobalIDSchemeIdentifiers.GLN, "4000001123452", "Lieferant GmbH"),
// description: description
// );
//
// string SELLER_CONTACT = "1-123";
// string ORG_UNIT = "2-123";
// string EMAIL_ADDRESS = "3-123";
// string PHONE_NO = "4-123";
// string FAX_NO = "5-123";
// invoice.SetSellerContact(SELLER_CONTACT, ORG_UNIT, EMAIL_ADDRESS, PHONE_NO, FAX_NO);
//
// MemoryStream ms = new MemoryStream();
// invoice.Save(ms, ZUGFeRDVersion.Version22, Profile.Extended);
// ms.Position = 0;
//
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
//
// Assert.AreEqual(SELLER_CONTACT, loadedInvoice.SellerContact.Name);
// Assert.AreEqual(ORG_UNIT, loadedInvoice.SellerContact.OrgUnit);
// Assert.AreEqual(EMAIL_ADDRESS, loadedInvoice.SellerContact.EmailAddress);
// Assert.AreEqual(PHONE_NO, loadedInvoice.SellerContact.PhoneNo);
// Assert.AreEqual(FAX_NO, loadedInvoice.SellerContact.FaxNo);
//
// Assert.AreEqual(loadedInvoice.Seller.Description, description);
end;

procedure TZUGFeRD22Tests.TestSellerDescription;
begin
// InvoiceDescriptor invoice = InvoiceProvider.CreateInvoice();
Expand Down Expand Up @@ -1785,54 +1822,6 @@ procedure TZUGFeRD22Tests.TestTradeAllowanceChargeWithoutExplicitPercentage;
// Assert.AreEqual(allowanceCharges[0].ChargePercentage, null);
end;

procedure TZUGFeRD22Tests.TestUBLInvoiceCreation;
begin
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
// MemoryStream ms = new MemoryStream();
//
// desc.Save(ms, ZUGFeRDVersion.Version22,Profile.XRechnung,ZUGFeRDFormats.UBL);
// ms.Seek(0, SeekOrigin.Begin);
//
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
//
// Assert.AreEqual(loadedInvoice.Invoicee, null);
// Assert.AreNotEqual(loadedInvoice.Seller, null);
// Assert.AreEqual(loadedInvoice.Taxes.Count, 2);
// Assert.AreEqual(loadedInvoice.SellerContact.Name, "Max Mustermann");
// Assert.IsNull(loadedInvoice.BuyerContact);
end;

procedure TZUGFeRD22Tests.TestUBLTradelineitemProductCharacterstics;
begin
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
//
// desc.TradeLineItems[0].ApplicableProductCharacteristics = new ApplicableProductCharacteristic[]
// {
// new ApplicableProductCharacteristic()
// {
// Description = "Test Description",
// Value = "1.5 kg"
// },
// new ApplicableProductCharacteristic()
// {
// Description = "UBL Characterstics 2",
// Value = "3 kg"
// },
// }.ToList();
//
// MemoryStream ms = new MemoryStream();
//
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
// ms.Seek(0, SeekOrigin.Begin);
//
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
//
// Assert.IsNotNull(loadedInvoice.TradeLineItems);
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics.Count, 2);
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[0].Description, "Test Description");
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[1].Value, "3 kg");
end;

// !TestTradeAllowanceChargeWithoutExplicitPercentage()

procedure TZUGFeRD22Tests.TestTradeAllowanceChargeWithExplicitPercentage;
Expand Down
1 change: 1 addition & 0 deletions intf.ZUGFeRDInvoiceDescriptor20Reader.pas
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function TZUGFeRDInvoiceDescriptor20Reader.Load(xmldocument : IXMLDocument): TZU

Result.PaymentReference := _nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:PaymentReference');
Result.Currency := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode'));
Result.SellerReferenceNo := _nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:InvoiceIssuerReference');

// TODO: Multiple SpecifiedTradeSettlementPaymentMeans can exist for each account/institution (with different SEPA?)
var _tempPaymentMeans : TZUGFeRDPaymentMeans := TZUGFeRDPaymentMeans.Create;
Expand Down
6 changes: 5 additions & 1 deletion intf.ZUGFeRDInvoiceDescriptor22CIIReader.pas
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ function TZUGFeRDInvoiceDescriptor22CIIReader.Load(xmldocument : IXMLDocument):

Result.PaymentReference := _nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:PaymentReference');
Result.Currency := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode'));
Result.TaxCurrency := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:TaxCurrencyCode')); // BT-6
Result.SellerReferenceNo := _nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:InvoiceIssuerReference');

var optionalTaxCurrency : TZUGFeRDCurrencyCodes := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:TaxCurrencyCode')); // BT-6
if (optionalTaxCurrency <> TZUGFeRDCurrencyCodes.Unknown) then
Result.TaxCurrency := optionalTaxCurrency;

// TODO: Multiple SpecifiedTradeSettlementPaymentMeans can exist for each account/institution (with different SEPA?)
var _tempPaymentMeans : TZUGFeRDPaymentMeans := TZUGFeRDPaymentMeans.Create;
Expand Down
4 changes: 2 additions & 2 deletions intf.ZUGFeRDInvoiceDescriptor22CIIWriter.pas
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ procedure TZUGFeRDInvoiceDescriptor22CIIWriter.Save(

//#region IssuerAssignedID
//Bestellnummer
Writer.WriteOptionalElementString('ram:IssuerAssignedID', tradeLineItem.BuyerOrderReferencedDocument.ID);
Writer.WriteOptionalElementString('ram:IssuerAssignedID', tradeLineItem.BuyerOrderReferencedDocument.ID,[TZUGFeRDProfile.Extended]);
//#endregion

//#region LineID
Expand All @@ -292,7 +292,7 @@ procedure TZUGFeRDInvoiceDescriptor22CIIWriter.Save(
//#region IssueDateTime
if (tradeLineItem.BuyerOrderReferencedDocument.IssueDateTime.HasValue) then
begin
Writer.WriteStartElement('ram:FormattedIssueDateTime');
Writer.WriteStartElement('ram:FormattedIssueDateTime',[TZUGFeRDProfile.Extended]);
Writer.WriteStartElement('qdt:DateTimeString');
Writer.WriteAttributeString('format', '102');
Writer.WriteValue(_formatDate(tradeLineItem.BuyerOrderReferencedDocument.IssueDateTime.Value));
Expand Down

0 comments on commit de06a99

Please sign in to comment.