### Install ZUGFeRD-CSharp Libraries Source: https://context7.com/stephanstapel/zugferd-csharp/llms.txt Install the core ZUGFeRD-csharp library and the optional PDF/A-3 integration package using the .NET CLI. ```bash # Install core library via NuGet dotnet add package ZUGFeRD-csharp # Optional: PDF/A-3 integration dotnet add package ZUGFeRD.PDF-csharp ``` -------------------------------- ### Document-Level Discounts and Surcharges in C# Source: https://context7.com/stephanstapel/zugferd-csharp/llms.txt Adds document-level allowances (discounts) and charges (surcharges). Includes examples for early payment discounts, freight surcharges, and logistics service charges. ```csharp // 5% early-payment discount on the net total desc.AddTradeAllowance( basisAmount: 1000.00m, currency: CurrencyCodes.EUR, actualAmount: 50.00m, chargePercentage: 5m, reason: "Early payment discount", taxTypeCode: TaxTypes.VAT, taxCategoryCode: TaxCategoryCodes.S, taxPercent: 19m, reasonCode: AllowanceReasonCodes.Discount ); // Freight surcharge desc.AddTradeCharge( basisAmount: null, currency: CurrencyCodes.EUR, actualAmount: 10.00m, chargePercentage: null, reason: "Freight", taxTypeCode: TaxTypes.VAT, taxCategoryCode: TaxCategoryCodes.S, taxPercent: 19m ); // Logistics service charge (ZUGFeRD/Factur-X only, not XRechnung) desc.AddLogisticsServiceCharge(5.80m, "Shipping costs", TaxTypes.VAT, TaxCategoryCodes.S, 7m); ``` -------------------------------- ### Create a Basic ZUGFeRD Invoice Descriptor Source: https://github.com/stephanstapel/zugferd-csharp/blob/master/docs/getting-started.md Initializes an InvoiceDescriptor with essential details like invoice ID, date, currency, and reference. This is the starting point for building any ZUGFeRD invoice. ```csharp InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2013, 6, 5), CurrencyCodes.EUR, "GE2020211-471102"); desc.Name = "WARENRECHNUNG"; desc.ReferenceOrderNo = "AB-312"; desc.AddNote("Rechnung gemäß Bestellung Nr. 2013-471331 vom 01.03.2013."); desc.AddNote("Es bestehen Rabatt- und Bonusvereinbarungen.", SubjectCodes.AAK); desc.SetBuyer("Kunden Mitte AG", "69876", "Frankfurt", "Kundenstraße 15", CountryCodes.DE, "88", new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452")); desc.AddBuyerTaxRegistration("DE234567890", TaxRegistrationSchemeID.VA); desc.SetBuyerContact("Hans Muster"); desc.SetSeller("Lieferant GmbH", "80333", "München", "Lieferantenstraße 20", CountryCodes.DE, "88", new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452")); desc.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC); desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); desc.SetBuyerOrderReferenceDocument("2013-471331", new DateTime(2013, 03, 01)); desc.SetDeliveryNoteReferenceDocument("2013-51111", new DateTime(2013, 6, 3)); desc.ActualDeliveryDate = new DateTime(2013, 6, 3); desc.SetTotals(202.76m, 5.80m, 14.73m, 193.83m, 21.31m, 215.14m, 50.0m, 165.14m); desc.AddApplicableTradeTax(129.37m, 7m, TaxTypes.VAT, TaxCategoryCodes.S); desc.AddApplicableTradeTax(64.46m, 19m, TaxTypes.VAT, TaxCategoryCodes.S); desc.AddLogisticsServiceCharge(5.80m, "Versandkosten", TaxTypes.VAT, TaxCategoryCodes.S, 7m); desc.AddTradePaymentTerms("Zahlbar innerhalb 30 Tagen netto bis 04.04.2018", new DateTime(2018, 4, 4)); desc.AddTradePaymentTerms("3% Skonto innerhalb 10 Tagen bis 15.03.2018", new DateTime(2018, 3, 15), PaymentTermsType.Skonto, 30, 3m); ``` -------------------------------- ### XML Schema Validation Example Source: https://github.com/stephanstapel/zugferd-csharp/blob/master/documentation/zugferd240en/Examples/3. EN16931/EN16931_Reisekostenabrechnung/EN16931_Reisekostenabrechnung_analyzed-content.html Demonstrates how to validate an XML document against a specific schema. This is crucial for ensuring data integrity and compliance. ```csharp XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add("http://www.w3.org/2001/XMLSchema", "XSD_Schema.xsd"); XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas = schemaSet; settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); XmlReader reader = XmlReader.Create("XML_File.xml", settings); while (reader.Read()) { } reader.Close(); ``` -------------------------------- ### Validate Invoice Monetary Summation Source: https://context7.com/stephanstapel/zugferd-csharp/llms.txt Validate the monetary summation of an invoice and get a structured result. Use ValidateAndPrint to also output to a file. ```csharp ValidationResult result = InvoiceValidator.Validate(desc, ZUGFeRDVersion.Version23); if (result.IsValid) { Console.WriteLine("Invoice is valid."); } else { Console.WriteLine("Invoice validation FAILED:"); foreach (string msg in result.Messages) { Console.WriteLine($" {msg}"); } } ``` ```csharp // Validate and print to console and optionally to a file InvoiceValidator.ValidateAndPrint(desc, ZUGFeRDVersion.Version23, filename: "validation-report.txt"); ```