Go to file
dankito a5928c5644 Updated kI18n version 2024-12-13 17:51:27 +01:00
docs Renamed customerReference to customerReferenceNumber 2024-12-02 22:36:37 +01:00
e-invoice-api Extracted InvoiceDetails 2024-12-02 04:08:07 +01:00
e-invoice-domain Updated kI18n version 2024-12-13 17:51:27 +01:00
e-invoice-spec-parser Added isContainedIn and contains to Country 2024-12-13 17:49:50 +01:00
gradle Configured publishing to Maven repository 2024-11-21 23:29:11 +01:00
invoice-creator Implemented OpenHtmlToPdfHtmlToPdfConverter to convert HTML to PDF 2024-12-01 23:41:08 +01:00
.gitignore Initial commit 2024-11-13 15:56:21 +01:00
.gitmodules Configured publishing to Maven repository 2024-11-21 23:29:11 +01:00
README.md Renamed totalAmounts to totals and added articleNumber to InvoiceItem 2024-12-02 17:59:13 +01:00
build.gradle.kts Forgot to commit added dependencies 2024-12-13 05:56:13 +01:00
gradle.properties Updated kI18n version 2024-12-13 17:51:27 +01:00
gradlew Initial commit 2024-11-13 15:56:21 +01:00
gradlew.bat Initial commit 2024-11-13 15:56:21 +01:00
settings.gradle.kts Implemented parsing CEF (EU) genericode Code Lists to Kotlin enum classes 2024-12-04 05:39:57 +01:00

README.md

eInvoicing

Tools for working with eInvoicing according to EU standard EU 16931.

As ZUGFeRD 2 and Factur-X unified their specification, these two names are used synonymously and interchangeably throughout the documentation and code.

Reading

Extract eInvoice from a PDF or XML file:

val reader = EInvoiceReader()

// extract invoice data from a ZUGFeRD or Factor-X PDF that contains eInvoice XML as attachment
val invoiceFromPDF = reader.extractFromPdf(File("ZUGFeRD.pdf"))

// extract eInvoice data from a XML file like XRechnung:
val invoiceFromXml = reader.extractFromXml(File("XRechnung.xml"))

Find all invoices of an IMAP email account

val emailsFetcher = EmailsFetcher()

val fetchResult = emailsFetcher.fetchAllEmails(EmailAccount(
    username = "", // your email account username
    password = "", // your email account username
    serverAddress = "", // IMAP server address
    port = null // IMAP server port, can be left null for default port 993
))

fetchResult.emails.forEach { email ->
    println("${email.sender}: ${email.attachments.firstNotNullOfOrNull { it.invoice }?.totals?.duePayableAmount}")
}

Validate eInvoice

val validator = EInvoiceValidator()
val invoiceFile = File("ZUGFeRD.pdf") // or XRechnung,xml, ...

val result = validator.validate(invoiceFile)

println("Is valid? ${result.isValid}")
println(result.report)

Create eInvoice

fun create() {
    val invoice = createInvoice()
    val pdfResultFile = File.createTempFile("Zugferd", ".pdf")

    val creator = EInvoiceCreator()

    // create a PDF that also contains the eInvoice as XML attachment
    creator.createPdfWithAttachedXml(invoice, pdfResultFile)

    // create only the XML file
    val xml = creator.createFacturXXml(invoice)

    // create a XRechnung
    val xRechnung = creator.createXRechnungXml(invoice)
}

private fun createInvoice() = Invoice(
    details = InvoiceDetails("RE-00001", LocalDate.now()),
    supplier = Party("codinux GmbH & Co. KG", "Fun Street 1", null, "12345", "Glückstadt"),
    customer = Party("Abzock GmbH", "Ausbeutstr.", null, "12345", "Abzockhausen"),
    items = listOf(InvoiceItem("Erbrachte Dienstleistungen", BigDecimal(170), "HUR", BigDecimal(105), BigDecimal(19))) // HUR = EN code for hour
)

Attach invoice XML to existing PDF

val invoice: Invoice = createInvoice()
val existingPdf = File("Invoice.pdf")
val output = File("Zugferd.pdf")

val creator = EInvoiceCreator()

creator.attachInvoiceXmlToPdf(invoice, existingPdf, output)

// or if you already have the invoice XML:
val invoiceXml = creator.createXRechnungXml(invoice) // or creator.createZugferdXml(invoice), ...

creator.attachInvoiceXmlToPdf(invoiceXml, EInvoiceXmlFormat.XRechnung, existingPdf, output)