diff --git a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/creation/EInvoiceCreator.kt b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/creation/EInvoiceCreator.kt index dc1bfa4..21b202c 100644 --- a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/creation/EInvoiceCreator.kt +++ b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/creation/EInvoiceCreator.kt @@ -1,8 +1,10 @@ package net.codinux.invoicing.creation import net.codinux.invoicing.model.Invoice +import org.mustangproject.ZUGFeRD.IXMLProvider import org.mustangproject.ZUGFeRD.Profiles import org.mustangproject.ZUGFeRD.ZUGFeRD2PullProvider +import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA3 class EInvoiceCreator( private val mapper: MustangMapper = MustangMapper() @@ -11,7 +13,25 @@ class EInvoiceCreator( fun createXRechnungXml(invoice: Invoice): String { val provider = ZUGFeRD2PullProvider() provider.profile = Profiles.getByName("XRechnung") - provider.generateXML(mapper.mapToTransaction(invoice)) + + return createXml(provider, invoice) + } + + fun createZugferdXml(invoice: Invoice, zugferdVersion: Int = 2): String { + val exporter = ZUGFeRDExporterFromA3() + .setZUGFeRDVersion(zugferdVersion) + .setProfile("EN16931") + .setProducer("danki die geile Sau") + .setCreator(System.getProperty("user.name")) + + return createXml(exporter.provider, invoice) + } + + + private fun createXml(provider: IXMLProvider, invoice: Invoice): String { + val transaction = mapper.mapToTransaction(invoice) + + provider.generateXML(transaction) return String(provider.xml, Charsets.UTF_8) } diff --git a/e-invoicing-domain/src/test/kotlin/net/codinux/invoicing/creation/EInvoiceCreatorTest.kt b/e-invoicing-domain/src/test/kotlin/net/codinux/invoicing/creation/EInvoiceCreatorTest.kt index 7a75612..93033b5 100644 --- a/e-invoicing-domain/src/test/kotlin/net/codinux/invoicing/creation/EInvoiceCreatorTest.kt +++ b/e-invoicing-domain/src/test/kotlin/net/codinux/invoicing/creation/EInvoiceCreatorTest.kt @@ -23,6 +23,15 @@ class EInvoiceCreatorTest { assertThat(result).isNotEmpty() } + @Test + fun createZugferdXml() { + val invoice = createInvoice() + + val result = underTest.createZugferdXml(invoice) + + assertThat(result).isNotEmpty() + } + private fun createInvoice( invoiceNumber: String = "12345",