Skip to content

Commit 9fd4fe5

Browse files
Merge pull request #295 from shahchandra/feature/UBLWriter
UBL Writer
2 parents 9b00d7f + 7068f9f commit 9fd4fe5

File tree

6 files changed

+618
-5
lines changed

6 files changed

+618
-5
lines changed

ZUGFeRD-Test/InvoiceProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ internal InvoiceDescriptor CreateInvoice()
8888
desc.ActualDeliveryDate = new DateTime(2018, 03, 05);
8989
desc.SetPaymentMeans(PaymentMeansTypeCodes.SEPACreditTransfer, "Zahlung per SEPA Überweisung.");
9090
desc.AddCreditorFinancialAccount(iban: "DE02120300000000202051", bic: "BYLADEM1001", name: "Kunden AG");
91-
92-
desc.AddApplicableTradeTax(basisAmount: 275.0m,
91+
desc.AddDebitorFinancialAccount(iban: "DB02120300000000202051", bic: "DBBYLADEM1001", bankName: "KundenDB AG");
92+
desc.AddApplicableTradeTax(basisAmount: 275.0m,
9393
percent: 7m,
9494
typeCode: TaxTypes.VAT,
9595
categoryCode: TaxCategoryCodes.S

ZUGFeRD-Test/ZUGFeRD22Tests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,24 @@ public void TestMinimumInvoice()
254254
Assert.AreEqual(loadedInvoice.Seller.SpecifiedLegalOrganization.TradingBusinessName, "");
255255
} // !TestMinimumInvoice()
256256

257+
[TestMethod]
258+
public void TestUBLInvoiceCreation()
259+
{
260+
InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
261+
262+
MemoryStream ms = new MemoryStream();
263+
264+
desc.Save(ms, ZUGFeRDVersion.Version22,Profile.XRechnung,ZUGFeRDFormats.UBL);
265+
ms.Seek(0, SeekOrigin.Begin);
266+
267+
InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
268+
269+
Assert.AreEqual(loadedInvoice.Invoicee, null);
270+
Assert.AreNotEqual(loadedInvoice.Seller, null);
271+
Assert.AreEqual(loadedInvoice.Taxes.Count, 2);
272+
Assert.AreEqual(loadedInvoice.SellerContact.Name, "Max Mustermann");
273+
Assert.IsNull(loadedInvoice.BuyerContact);
274+
}
257275

258276
[TestMethod]
259277
public void TestInvoiceWithAttachmentXRechnung()

ZUGFeRD/IInvoiceDescriptorWriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ protected string _formatDecimal(decimal value, int numDecimals = 2)
5252
} // !_formatDecimal()
5353

5454

55-
protected string _formatDate(DateTime date, bool formatAs102 = true)
55+
protected string _formatDate(DateTime date, bool formatAs102 = true, bool toUBLDate = false)
5656
{
5757
if (formatAs102)
5858
{
5959
return date.ToString("yyyyMMdd");
6060
}
6161
else
6262
{
63+
if (toUBLDate)
64+
return date.ToString("yyyy-MM-dd");
65+
6366
return date.ToString("yyyy-MM-ddTHH:mm:ss");
6467
}
6568
} // !_formatDate()

ZUGFeRD/InvoiceDescriptor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,12 @@ private IInvoiceDescriptorWriter _selectInvoiceDescriptorWriter(ZUGFeRDVersion v
925925
/// <param name="stream">The stream where the data should be saved to.</param>
926926
/// <param name="version">The ZUGFeRD version you want to use. Defaults to version 1.</param>
927927
/// <param name="profile">The ZUGFeRD profile you want to use. Defaults to Basic.</param>
928-
public void Save(Stream stream, ZUGFeRDVersion version = ZUGFeRDVersion.Version1, Profile profile = Profile.Basic)
928+
/// <param name="format">The format of the target file that may be CII or UBL</param>
929+
public void Save(Stream stream, ZUGFeRDVersion version = ZUGFeRDVersion.Version1, Profile profile = Profile.Basic, ZUGFeRDFormats format = ZUGFeRDFormats.CII)
929930
{
930931
this.Profile = profile;
931932
IInvoiceDescriptorWriter writer = _selectInvoiceDescriptorWriter(version);
932-
writer.Save(this, stream);
933+
writer.Save(this, stream,format);
933934
} // !Save()
934935

935936

0 commit comments

Comments
 (0)