Skip to content

ipax77/pax.XRechnung.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet Version .NET

Introduction

pax.XRechnung.NET is a .NET library that helps validate, map, and generate XRechnung XML invoices, following specification 3.0.2.

Features

  • Validation: Ensure XML invoices conform to XRechnung 3.0.2 schema and Schematron rules.
  • 🔁 Mapping: Convert XML invoices into strongly typed DTOs.
  • 🧾 Generation: Create compliant XML invoices from C# objects.

Getting started

Installation

dotnet add package pax.XRechnung.NET

Usage

Validate XML schema

    var xmlText = "<Invoice>...</invoice>";
    var serializer = new XmlSerializer(typeof(XmlInvoice));
    using var stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlText));
    stream.Position = 0;
    var xmlInvoice = (XmlInvoice?)serializer.Deserialize(stream);
    Assert.IsNotNull(xmlInvoice);
    var validationResult = XmlInvoiceValidator.Validate(xmlInvoice);
    Assert.IsTrue(validationresult.IsValid);

Handle Sample Invoice

public static InvoiceBaseDto GetInvoiceBaseDto()
{
    return new()
    {
        GlobalTaxCategory = "S",
        GlobalTaxScheme = "VAT",
        GlobalTax = 19.0,
        Id = "1",
        IssueDate = new DateTime(2025, 05, 01),
        InvoiceTypeCode = "380",
        DocumentCurrencyCode = "EUR",
        SellerParty = new PartyBaseDto()
        {
            Name = "Seller Name",
            StreetName = "Test Street",
            City = "Test City",
            PostCode = "123456",
            CountryCode = "DE",
            Telefone = "1234/54321",
            Email = "seller@example.com",
            RegistrationName = "Seller Name",
            TaxId = "DE12345678"
        },
        BuyerParty = new PartyBaseDto()
        {
            Name = "Buyer Name",
            StreetName = "Test Street",
            City = "Test City",
            PostCode = "123456",
            CountryCode = "DE",
            Telefone = "1234/54321",
            Email = "buyer@example.com",
            RegistrationName = "Buyer Name",
            BuyerReference = "04011000-12345-34",
        },
        PaymentMeans = new PaymentMeansBaseDto()
        {
            Iban = "DE12 1234 1234 1234 1234 12",
            Bic = "BICABCDE",
            Name = "Bank Name",
            PaymentMeansTypeCode = "30",
        },
        PaymentTermsNote = "Zahlbar innerhalb von 14 Tagen nach Erhalt der Rechnung.",
        PayableAmount = 119.0,
        InvoiceLines = [
            new InvoiceLineBaseDto()
            {
                Id = "1",
                Quantity = 1.0,
                QuantityCode = "HUR",
                UnitPrice = 100.0,
                Name = "Test Job"
            }
        ]
    };
}

Serialize DTO to XML

    var invoiceBaseDto = GetInvoiceBaseDto();
    var mapper = new InvoiceMapper();
    var xmlInvoice = mapper.ToXml(invoiceBaseDto);
    var xmlText = XmlInvoiceWriter.Serialize(xmlInvoice);

Validate schematron - requires Kosit validator

    var invoiceBaseDto = GetInvoiceBaseDto();
    var mapper = new InvoiceMapper();
    XmlInvoice xmlInvoice = mapper.ToXml(invoiceBaseDto);
    var result = await XmlInvoiceValidator.ValidateSchematron(xmlInvoice);
    var resultText = string.Join(Environment.NewLine, result.Validations.Select(s => $"{s.Severity}:\t{s.Message}"));
    Assert.IsTrue(result.Validations.Count == 0, resultText);
    Assert.IsTrue(result.IsValid, resultText);

The InvoiceBaseDto is designed to be easily extended see BaseDtoExtensionTests

Java Schematron Validator

Requires a running Kosit validation server. Setup: xrechnung usage

Server start: java -jar .\validationtool-1.5.0-standalone.jar -s .\scenarios.xml -r ${PWD} -D

ChangeLog

v0.3.2
  • Update to dotnet 10
v0.3.1
  • Breaking Changes
  • Code Lists fix to receive meta information
  • DTO rework to be more flexible and robust:
  • PaymentMeansTypeCode to PaymentMeans
  • BuyerReference to BuyerParty
v0.3.0
  • Breaking Changes
  • DTO rework to be more flexible and robust.
  • InvoiceAnnotationDto now available with Required fields and CodeList validation
v0.2.0
  • Breaking Changes
  • Fixed/Renamed XmlInvoice properties and dependencies. All existing properties are now xml schema conform.
  • Added Kosit schematron validation. See Java Schematron Validator
  • Replaced all DTOs with InvoiceBaseDto
v0.1.0
  • Breaking Changes
  • Added FinancialInstitutionBranch to FinancialAccountType (XmlPaymentInstructions)
  • Seller/Buyer cleanup and reference XmlParty
  • Changed XmlAdditionalDocumentReference to XmlAdditionalDocumentReferences as list
v0.0.1
  • Initial release
  • Support for invoice validation and serialization
  • Partial DTO implementation

About

dotnet XRechnung xml validation and mapping

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published