Implemented creating Zugferd XML

This commit is contained in:
dankito 2024-11-14 00:37:23 +01:00
parent 3273625f7a
commit 3bd3024f11
2 changed files with 30 additions and 1 deletions

View File

@ -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)
}

View File

@ -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",