Skip to content

Commit de06a99

Browse files
committed
sync with c# lib 2024 08 12 v14
1 parent 97c3c7d commit de06a99

6 files changed

+186
-55
lines changed

Test/DUnitXZUGFeRDTest.dpr

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ uses
8585
intf.ZUGFeRDInvoiceDescriptor20Reader,intf.ZUGFeRDInvoiceDescriptor20Writer,intf.ZUGFeRD20Tests.UnitTests,
8686
intf.ZUGFeRDInvoiceDescriptor22CIIReader,intf.ZUGFeRDInvoiceDescriptor22Writer,intf.ZUGFeRD22Tests.UnitTests,
8787
intf.ZUGFeRDInvoiceDescriptor22UBLReader,
88+
intf.XRechnungUBLTests.UnitTests,
8889
intf.ZUGFeRDBaseTests.UnitTests
8990
;
9091

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{* Licensed to the Apache Software Foundation (ASF) under one
2+
* or more contributor license agreements. See the NOTICE file
3+
* distributed with this work for additional information
4+
* regarding copyright ownership. The ASF licenses this file
5+
* to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.}
17+
18+
unit intf.XRechnungUBLTests.UnitTests;
19+
20+
interface
21+
22+
uses
23+
System.SysUtils
24+
,DUnitX.TestFramework
25+
,intf.ZUGFeRDInvoiceDescriptor
26+
,intf.ZUGFeRDProfile,intf.ZUGFeRDInvoiceTypes
27+
,intf.ZUGFeRDInvoiceProvider
28+
,intf.ZUGFeRDVersion
29+
;
30+
31+
type
32+
[TestFixture]
33+
TXRechnungUBLTests = class
34+
public
35+
[Test]
36+
procedure TestInvoiceCreation;
37+
[Test]
38+
procedure TestTradelineitemProductCharacterstics;
39+
/// <summary>
40+
/// https://github.com/stephanstapel/ZUGFeRD-csharp/issues/319
41+
/// </summary>
42+
[Test]
43+
procedure TestSkippingOfAllowanceChargeBasisAmount;
44+
end;
45+
46+
implementation
47+
48+
{ TXRechnungUBLTests }
49+
50+
procedure TXRechnungUBLTests.TestInvoiceCreation;
51+
begin
52+
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
53+
// MemoryStream ms = new MemoryStream();
54+
//
55+
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
56+
// ms.Seek(0, SeekOrigin.Begin);
57+
//
58+
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
59+
//
60+
// Assert.AreEqual(loadedInvoice.Invoicee, null);
61+
// Assert.AreNotEqual(loadedInvoice.Seller, null);
62+
// Assert.AreEqual(loadedInvoice.Taxes.Count, 2);
63+
// Assert.AreEqual(loadedInvoice.SellerContact.Name, "Max Mustermann");
64+
// Assert.IsNull(loadedInvoice.BuyerContact);
65+
end;
66+
67+
procedure TXRechnungUBLTests.TestSkippingOfAllowanceChargeBasisAmount;
68+
begin
69+
// // actual values do not matter
70+
// decimal basisAmount = 123.0m;
71+
// decimal percent = 11.0m;
72+
// decimal allowanceChargeBasisAmount = 121.0m;
73+
//
74+
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
75+
// desc.AddApplicableTradeTax(basisAmount, percent, TaxTypes.LOC, TaxCategoryCodes.K, allowanceChargeBasisAmount);
76+
// MemoryStream ms = new MemoryStream();
77+
//
78+
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
79+
// ms.Seek(0, SeekOrigin.Begin);
80+
//
81+
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
82+
//
83+
// Tax tax = loadedInvoice.Taxes.FirstOrDefault(t => t.TypeCode == TaxTypes.LOC);
84+
// Assert.IsNotNull(tax);
85+
// Assert.AreEqual(basisAmount, tax.BasisAmount);
86+
// Assert.AreEqual(percent, tax.Percent);
87+
// Assert.AreEqual(null, tax.AllowanceChargeBasisAmount);
88+
end;
89+
90+
procedure TXRechnungUBLTests.TestTradelineitemProductCharacterstics;
91+
begin
92+
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
93+
//
94+
// desc.TradeLineItems[0].ApplicableProductCharacteristics = new ApplicableProductCharacteristic[]
95+
// {
96+
// new ApplicableProductCharacteristic()
97+
// {
98+
// Description = "Test Description",
99+
// Value = "1.5 kg"
100+
// },
101+
// new ApplicableProductCharacteristic()
102+
// {
103+
// Description = "UBL Characterstics 2",
104+
// Value = "3 kg"
105+
// },
106+
// }.ToList();
107+
//
108+
// MemoryStream ms = new MemoryStream();
109+
//
110+
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
111+
// ms.Seek(0, SeekOrigin.Begin);
112+
//
113+
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
114+
//
115+
// Assert.IsNotNull(loadedInvoice.TradeLineItems);
116+
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics.Count, 2);
117+
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[0].Description, "Test Description");
118+
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[1].Value, "3 kg");
119+
end;
120+
121+
initialization
122+
123+
//I was hoping to use RTTI to discover the TestFixture classes, however unlike .NET
124+
//if we don't touch the class somehow then the linker will remove
125+
//the class from the resulting exe.
126+
//We could just do this:
127+
//TMyExampleTests.ClassName;
128+
//TExampleFixture2.ClassName;
129+
//which is enough to make the compiler link the classes into the exe, but that seems a
130+
//bit redundent so I guess we'll just use manual registration. If you use the
131+
//{$STRONGLINKTYPES ON} compiler directive then it will link the TestFixtures in and you
132+
//can use RTTI. The downside to that is the resulting exe will potentially much larger.
133+
//Not sure which version {$STRONGLINKTYPES ON} was introduced so we'll allow RTTI and
134+
//manual registration for now.
135+
136+
end.

Test/intf.ZUGFeRD22Tests.UnitTests.pas

+41-52
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ TZUGFeRD22Tests = class
128128
[Test]
129129
procedure TestSpecifiedTradeAllowanceCharge;
130130
[Test]
131-
procedure TestUBLInvoiceCreation;
132-
[Test]
133-
procedure TestUBLTradelineitemProductCharacterstics;
134-
[Test]
135131
procedure TestSellerDescription;
132+
[Test]
133+
procedure TestSellerContact;
136134
end;
137135

138136
implementation
@@ -1245,6 +1243,45 @@ procedure TZUGFeRD22Tests.TestOrderInformation;
12451243
//
12461244
end;
12471245

1246+
procedure TZUGFeRD22Tests.TestSellerContact;
1247+
begin
1248+
// InvoiceDescriptor invoice = InvoiceProvider.CreateInvoice();
1249+
//
1250+
// string description = "Test description";
1251+
//
1252+
// invoice.SetSeller(name: "Lieferant GmbH",
1253+
// postcode: "80333",
1254+
// city: "München",
1255+
// street: "Lieferantenstraße 20",
1256+
// country: CountryCodes.DE,
1257+
// id: "",
1258+
// globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452"),
1259+
// legalOrganization: new LegalOrganization(GlobalIDSchemeIdentifiers.GLN, "4000001123452", "Lieferant GmbH"),
1260+
// description: description
1261+
// );
1262+
//
1263+
// string SELLER_CONTACT = "1-123";
1264+
// string ORG_UNIT = "2-123";
1265+
// string EMAIL_ADDRESS = "3-123";
1266+
// string PHONE_NO = "4-123";
1267+
// string FAX_NO = "5-123";
1268+
// invoice.SetSellerContact(SELLER_CONTACT, ORG_UNIT, EMAIL_ADDRESS, PHONE_NO, FAX_NO);
1269+
//
1270+
// MemoryStream ms = new MemoryStream();
1271+
// invoice.Save(ms, ZUGFeRDVersion.Version22, Profile.Extended);
1272+
// ms.Position = 0;
1273+
//
1274+
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
1275+
//
1276+
// Assert.AreEqual(SELLER_CONTACT, loadedInvoice.SellerContact.Name);
1277+
// Assert.AreEqual(ORG_UNIT, loadedInvoice.SellerContact.OrgUnit);
1278+
// Assert.AreEqual(EMAIL_ADDRESS, loadedInvoice.SellerContact.EmailAddress);
1279+
// Assert.AreEqual(PHONE_NO, loadedInvoice.SellerContact.PhoneNo);
1280+
// Assert.AreEqual(FAX_NO, loadedInvoice.SellerContact.FaxNo);
1281+
//
1282+
// Assert.AreEqual(loadedInvoice.Seller.Description, description);
1283+
end;
1284+
12481285
procedure TZUGFeRD22Tests.TestSellerDescription;
12491286
begin
12501287
// InvoiceDescriptor invoice = InvoiceProvider.CreateInvoice();
@@ -1785,54 +1822,6 @@ procedure TZUGFeRD22Tests.TestTradeAllowanceChargeWithoutExplicitPercentage;
17851822
// Assert.AreEqual(allowanceCharges[0].ChargePercentage, null);
17861823
end;
17871824

1788-
procedure TZUGFeRD22Tests.TestUBLInvoiceCreation;
1789-
begin
1790-
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
1791-
// MemoryStream ms = new MemoryStream();
1792-
//
1793-
// desc.Save(ms, ZUGFeRDVersion.Version22,Profile.XRechnung,ZUGFeRDFormats.UBL);
1794-
// ms.Seek(0, SeekOrigin.Begin);
1795-
//
1796-
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
1797-
//
1798-
// Assert.AreEqual(loadedInvoice.Invoicee, null);
1799-
// Assert.AreNotEqual(loadedInvoice.Seller, null);
1800-
// Assert.AreEqual(loadedInvoice.Taxes.Count, 2);
1801-
// Assert.AreEqual(loadedInvoice.SellerContact.Name, "Max Mustermann");
1802-
// Assert.IsNull(loadedInvoice.BuyerContact);
1803-
end;
1804-
1805-
procedure TZUGFeRD22Tests.TestUBLTradelineitemProductCharacterstics;
1806-
begin
1807-
// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
1808-
//
1809-
// desc.TradeLineItems[0].ApplicableProductCharacteristics = new ApplicableProductCharacteristic[]
1810-
// {
1811-
// new ApplicableProductCharacteristic()
1812-
// {
1813-
// Description = "Test Description",
1814-
// Value = "1.5 kg"
1815-
// },
1816-
// new ApplicableProductCharacteristic()
1817-
// {
1818-
// Description = "UBL Characterstics 2",
1819-
// Value = "3 kg"
1820-
// },
1821-
// }.ToList();
1822-
//
1823-
// MemoryStream ms = new MemoryStream();
1824-
//
1825-
// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL);
1826-
// ms.Seek(0, SeekOrigin.Begin);
1827-
//
1828-
// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
1829-
//
1830-
// Assert.IsNotNull(loadedInvoice.TradeLineItems);
1831-
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics.Count, 2);
1832-
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[0].Description, "Test Description");
1833-
// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[1].Value, "3 kg");
1834-
end;
1835-
18361825
// !TestTradeAllowanceChargeWithoutExplicitPercentage()
18371826

18381827
procedure TZUGFeRD22Tests.TestTradeAllowanceChargeWithExplicitPercentage;

intf.ZUGFeRDInvoiceDescriptor20Reader.pas

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ function TZUGFeRDInvoiceDescriptor20Reader.Load(xmldocument : IXMLDocument): TZU
231231

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

235236
// TODO: Multiple SpecifiedTradeSettlementPaymentMeans can exist for each account/institution (with different SEPA?)
236237
var _tempPaymentMeans : TZUGFeRDPaymentMeans := TZUGFeRDPaymentMeans.Create;

intf.ZUGFeRDInvoiceDescriptor22CIIReader.pas

+5-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ function TZUGFeRDInvoiceDescriptor22CIIReader.Load(xmldocument : IXMLDocument):
321321

322322
Result.PaymentReference := _nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:PaymentReference');
323323
Result.Currency := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode'));
324-
Result.TaxCurrency := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:TaxCurrencyCode')); // BT-6
324+
Result.SellerReferenceNo := _nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:InvoiceIssuerReference');
325+
326+
var optionalTaxCurrency : TZUGFeRDCurrencyCodes := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableHeaderTradeSettlement/ram:TaxCurrencyCode')); // BT-6
327+
if (optionalTaxCurrency <> TZUGFeRDCurrencyCodes.Unknown) then
328+
Result.TaxCurrency := optionalTaxCurrency;
325329

326330
// TODO: Multiple SpecifiedTradeSettlementPaymentMeans can exist for each account/institution (with different SEPA?)
327331
var _tempPaymentMeans : TZUGFeRDPaymentMeans := TZUGFeRDPaymentMeans.Create;

intf.ZUGFeRDInvoiceDescriptor22CIIWriter.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ procedure TZUGFeRDInvoiceDescriptor22CIIWriter.Save(
281281

282282
//#region IssuerAssignedID
283283
//Bestellnummer
284-
Writer.WriteOptionalElementString('ram:IssuerAssignedID', tradeLineItem.BuyerOrderReferencedDocument.ID);
284+
Writer.WriteOptionalElementString('ram:IssuerAssignedID', tradeLineItem.BuyerOrderReferencedDocument.ID,[TZUGFeRDProfile.Extended]);
285285
//#endregion
286286

287287
//#region LineID
@@ -292,7 +292,7 @@ procedure TZUGFeRDInvoiceDescriptor22CIIWriter.Save(
292292
//#region IssueDateTime
293293
if (tradeLineItem.BuyerOrderReferencedDocument.IssueDateTime.HasValue) then
294294
begin
295-
Writer.WriteStartElement('ram:FormattedIssueDateTime');
295+
Writer.WriteStartElement('ram:FormattedIssueDateTime',[TZUGFeRDProfile.Extended]);
296296
Writer.WriteStartElement('qdt:DateTimeString');
297297
Writer.WriteAttributeString('format', '102');
298298
Writer.WriteValue(_formatDate(tradeLineItem.BuyerOrderReferencedDocument.IssueDateTime.Value));

0 commit comments

Comments
 (0)