Implemented converting CII to UBL

This commit is contained in:
dankito 2024-11-15 02:11:28 +01:00
parent 59b2999ec2
commit 3f84e7994a
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package net.codinux.invoicing.converter
import net.codinux.invoicing.creation.EInvoiceCreator
import net.codinux.invoicing.model.Invoice
import org.mustangproject.CII.CIIToUBL
import java.io.File
class EInvoiceConverter {
/**
* Converts a CII (Cross Industry Invoice) invoice, e.g. a Zugferd or Factur-X invoice, to UBL (Universal Business Language).
*/
fun convertCiiToUbl(invoice: Invoice) = convertCiiToUbl(EInvoiceCreator().createXRechnungXml(invoice))
/**
* Converts a CII (Cross Industry Invoice) invoice, e.g. a Zugferd or Factur-X invoice, to UBL (Universal Business Language).
*/
fun convertCiiToUbl(invoiceXml: String): String {
// TODO: extract a common method for this
val xmlFile = File.createTempFile("Zugferd", ".xml")
.also { it.writeText(invoiceXml) }
val ublFile = File(xmlFile.parentFile, xmlFile.nameWithoutExtension + "-ubl.xml")
convertCiiToUbl(xmlFile, ublFile)
val ubl = ublFile.readText()
xmlFile.delete()
ublFile.delete()
return ubl
}
/**
* Converts a CII (Cross Industry Invoice) invoice, e.g. a Zugferd or Factur-X invoice, to UBL (Universal Business Language).
*/
fun convertCiiToUbl(xmlFile: File, outputFile: File) {
val cii2Ubl = CIIToUBL()
cii2Ubl.convert(xmlFile, outputFile)
}
}

View File

@ -0,0 +1,25 @@
package net.codinux.invoicing.converter
import assertk.assertThat
import assertk.assertions.isNotEmpty
import net.codinux.invoicing.test.DataGenerator
import kotlin.test.Test
class EInvoiceConverterTest {
private val underTest = EInvoiceConverter()
@Test
fun convertCiiToUbl() {
val invoice = createInvoice()
val result = underTest.convertCiiToUbl(invoice)
assertThat(result).isNotEmpty()
}
private fun createInvoice() = DataGenerator.createInvoice()
}