Skip to content

Commit

Permalink
Merge pull request #465 from Tr1ckMan/set_OrderReference_to_optional_…
Browse files Browse the repository at this point in the history
…in_UBL_export

Set order reference and financial card holder to optional elements in ubl export
  • Loading branch information
stephanstapel authored Dec 2, 2024
2 parents ad1b165 + 5fcc2e3 commit 863d58a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 6 deletions.
84 changes: 84 additions & 0 deletions ZUGFeRD.Test/XRechnungUBLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -775,5 +775,89 @@ public void TestInDebitInvoiceThePaymentMandateIdShouldExist()
Assert.IsTrue(Regex.IsMatch(content, @"<cac:PaymentMeans.*>.*<cac:PaymentMandate.*>.*<cbc:ID.*>REF A-123</cbc:ID.*>.*</cac:PaymentMandate>", RegexOptions.Singleline));
}
} // !TestInDebitInvoiceThePaymentMandateIdShouldExist()

[TestMethod]
public void TestInvoiceWithoutOrderReferenceShouldNotWriteEmptyOrderReferenceElement()
{
var d = new InvoiceDescriptor();
d.Type = InvoiceType.Invoice;
d.InvoiceNo = "471102";
d.Currency = CurrencyCodes.EUR;
d.InvoiceDate = new DateTime(2018, 3, 5);
d.AddTradeLineItem(
lineID: "1",
id: new GlobalID(GlobalIDSchemeIdentifiers.EAN, "4012345001235"),
sellerAssignedID: "TB100A4",
name: "Trennblätter A4",
billedQuantity: 20m,
unitCode: QuantityCodes.H87,
netUnitPrice: 9.9m,
grossUnitPrice: 11.781m,
categoryCode: TaxCategoryCodes.S,
taxPercent: 19.0m,
taxType: TaxTypes.VAT);
d.SetSeller(
id: null,
globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452"),
name: "Lieferant GmbH",
postcode: "80333",
city: "München",
street: "Lieferantenstraße 20",
country: CountryCodes.DE,
legalOrganization: new LegalOrganization(GlobalIDSchemeIdentifiers.GLN, "4000001123452", "Lieferant GmbH"));
d.SetBuyer(
id: "GE2020211",
globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001987658"),
name: "Kunden AG Mitte",
postcode: "69876",
city: "Frankfurt",
street: "Kundenstraße 15",
country: CountryCodes.DE);
d.SetPaymentMeansSepaDirectDebit(
"DE98ZZZ09999999999",
"REF A-123");
d.AddDebitorFinancialAccount(
"DE21860000000086001055",
null);
d.AddTradePaymentTerms(
"Der Betrag in Höhe von EUR 235,62 wird am 20.03.2018 von Ihrem Konto per SEPA-Lastschrift eingezogen.");
d.SetTotals(
198.00m,
0.00m,
0.00m,
198.00m,
37.62m,
235.62m,
0.00m,
235.62m);
d.SellerTaxRegistration.Add(
new TaxRegistration
{
SchemeID = TaxRegistrationSchemeID.FC,
No = "201/113/40209"
});
d.SellerTaxRegistration.Add(
new TaxRegistration
{
SchemeID = TaxRegistrationSchemeID.VA,
No = "DE123456789"
});
d.AddApplicableTradeTax(
198.00m,
19.00m,
TaxTypes.VAT,
TaxCategoryCodes.S);

using (var stream = new MemoryStream())
{
d.Save(stream, ZUGFeRDVersion.Version23, Profile.XRechnung, ZUGFeRDFormats.UBL);
stream.Seek(0, SeekOrigin.Begin);

// test the raw xml file
string content = Encoding.UTF8.GetString(stream.ToArray());

Assert.IsFalse(content.Contains("OrderReference"));
}
} // !TestInvoiceWithoutOrderReferenceShouldNotWriteEmptyOrderReferenceElement()
}
}
16 changes: 10 additions & 6 deletions ZUGFeRD/InvoiceDescriptor22UBLWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo

Writer.WriteOptionalElementString("cbc", "BuyerReference", this.Descriptor.ReferenceOrderNo);

// OrderReference
Writer.WriteStartElement("cac", "OrderReference");
Writer.WriteElementString("cbc", "ID", this.Descriptor.OrderNo);
Writer.WriteOptionalElementString("cbc", "SalesOrderID", this.Descriptor.SellerOrderReferencedDocument?.ID);
Writer.WriteEndElement(); // !OrderReference
// OrderReference is optional
if (!string.IsNullOrWhiteSpace(this.Descriptor.OrderNo))
{
Writer.WriteStartElement("cac", "OrderReference");
Writer.WriteElementString("cbc", "ID", this.Descriptor.OrderNo);
Writer.WriteOptionalElementString("cbc", "SalesOrderID",
this.Descriptor.SellerOrderReferencedDocument?.ID);
Writer.WriteEndElement(); // !OrderReference
}

// BillingReference
if (this.Descriptor.GetInvoiceReferencedDocuments().Count > 0)
Expand Down Expand Up @@ -275,7 +279,7 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo
{
Writer.WriteStartElement("cac", "CardAccount", Profile.BasicWL | Profile.Basic | Profile.Comfort | Profile.Extended | Profile.XRechnung1 | Profile.XRechnung);
Writer.WriteElementString("cbc", "PrimaryAccountNumberID", this.Descriptor.PaymentMeans.FinancialCard.Id);
Writer.WriteElementString("cbc", "HolderName", this.Descriptor.PaymentMeans.FinancialCard.CardholderName);
Writer.WriteOptionalElementString("cbc", "HolderName", this.Descriptor.PaymentMeans.FinancialCard.CardholderName);
Writer.WriteEndElement(); //!CardAccount
}

Expand Down

0 comments on commit 863d58a

Please sign in to comment.