Moved convertInvoiceToHtml() to EInvoiceConverter
This commit is contained in:
parent
3f84e7994a
commit
bb48356011
|
@ -3,14 +3,36 @@ package net.codinux.invoicing.converter
|
||||||
import net.codinux.invoicing.creation.EInvoiceCreator
|
import net.codinux.invoicing.creation.EInvoiceCreator
|
||||||
import net.codinux.invoicing.model.Invoice
|
import net.codinux.invoicing.model.Invoice
|
||||||
import org.mustangproject.CII.CIIToUBL
|
import org.mustangproject.CII.CIIToUBL
|
||||||
|
import org.mustangproject.ZUGFeRD.ZUGFeRDVisualizer
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class EInvoiceConverter {
|
class EInvoiceConverter {
|
||||||
|
|
||||||
|
fun convertInvoiceToHtml(invoice: Invoice, outputFile: File, language: ZUGFeRDVisualizer.Language = ZUGFeRDVisualizer.Language.DE) =
|
||||||
|
convertInvoiceToHtml(createXRechnungXml(invoice), outputFile, language)
|
||||||
|
|
||||||
|
fun convertInvoiceToHtml(invoiceXml: String, outputFile: File, language: ZUGFeRDVisualizer.Language = ZUGFeRDVisualizer.Language.DE): String {
|
||||||
|
val xmlFile = File.createTempFile("Zugferd", ".xml")
|
||||||
|
.also { it.writeText(invoiceXml) }
|
||||||
|
|
||||||
|
val visualizer = ZUGFeRDVisualizer()
|
||||||
|
|
||||||
|
val html = visualizer.visualize(xmlFile.absolutePath, language)
|
||||||
|
|
||||||
|
outputFile.writeText(html)
|
||||||
|
copyResource("xrechnung-viewer.css", outputFile, ".css")
|
||||||
|
copyResource("xrechnung-viewer.js", outputFile, ".js")
|
||||||
|
|
||||||
|
xmlFile.delete()
|
||||||
|
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a CII (Cross Industry Invoice) invoice, e.g. a Zugferd or Factur-X invoice, to UBL (Universal Business Language).
|
* 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))
|
fun convertCiiToUbl(invoice: Invoice) = convertCiiToUbl(createXRechnungXml(invoice))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a CII (Cross Industry Invoice) invoice, e.g. a Zugferd or Factur-X invoice, to UBL (Universal Business Language).
|
* Converts a CII (Cross Industry Invoice) invoice, e.g. a Zugferd or Factur-X invoice, to UBL (Universal Business Language).
|
||||||
|
@ -38,4 +60,14 @@ class EInvoiceConverter {
|
||||||
val cii2Ubl = CIIToUBL()
|
val cii2Ubl = CIIToUBL()
|
||||||
cii2Ubl.convert(xmlFile, outputFile)
|
cii2Ubl.convert(xmlFile, outputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun createXRechnungXml(invoice: Invoice): String = EInvoiceCreator().createXRechnungXml(invoice)
|
||||||
|
|
||||||
|
private fun copyResource(resourceName: String, outputFile: File, outputFileExtension: String) {
|
||||||
|
javaClass.classLoader.getResourceAsStream(resourceName).use {
|
||||||
|
it?.copyTo(File(outputFile.parentFile, outputFile.nameWithoutExtension + outputFileExtension).outputStream())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -52,33 +52,6 @@ class EInvoiceCreator(
|
||||||
exporter.export(outputFile.outputStream())
|
exporter.export(outputFile.outputStream())
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract to EInvoiceConverter?
|
|
||||||
fun convertInvoiceToHtml(invoice: Invoice, outputFile: File, language: ZUGFeRDVisualizer.Language = ZUGFeRDVisualizer.Language.DE) =
|
|
||||||
convertInvoiceToHtml(createXRechnungXml(invoice), outputFile, language)
|
|
||||||
|
|
||||||
fun convertInvoiceToHtml(invoiceXml: String, outputFile: File, language: ZUGFeRDVisualizer.Language = ZUGFeRDVisualizer.Language.DE): String {
|
|
||||||
val xmlFile = File.createTempFile("Zugferd", ".xml")
|
|
||||||
.also { it.writeText(invoiceXml) }
|
|
||||||
|
|
||||||
val visualizer = ZUGFeRDVisualizer()
|
|
||||||
|
|
||||||
val html = visualizer.visualize(xmlFile.absolutePath, language)
|
|
||||||
|
|
||||||
outputFile.writeText(html)
|
|
||||||
copyResource("xrechnung-viewer.css", outputFile, ".css")
|
|
||||||
copyResource("xrechnung-viewer.js", outputFile, ".js")
|
|
||||||
|
|
||||||
xmlFile.delete()
|
|
||||||
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun copyResource(resourceName: String, outputFile: File, outputFileExtension: String) {
|
|
||||||
javaClass.classLoader.getResourceAsStream(resourceName).use {
|
|
||||||
it?.copyTo(File(outputFile.parentFile, outputFile.nameWithoutExtension + outputFileExtension).outputStream())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun createXml(provider: IXMLProvider, invoice: Invoice): String {
|
private fun createXml(provider: IXMLProvider, invoice: Invoice): String {
|
||||||
val transaction = mapper.mapToTransaction(invoice)
|
val transaction = mapper.mapToTransaction(invoice)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.codinux.invoicing.converter
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
import assertk.assertions.isNotEmpty
|
import assertk.assertions.isNotEmpty
|
||||||
import net.codinux.invoicing.test.DataGenerator
|
import net.codinux.invoicing.test.DataGenerator
|
||||||
|
import java.io.File
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
|
||||||
class EInvoiceConverterTest {
|
class EInvoiceConverterTest {
|
||||||
|
@ -10,6 +11,16 @@ class EInvoiceConverterTest {
|
||||||
private val underTest = EInvoiceConverter()
|
private val underTest = EInvoiceConverter()
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun convertInvoiceToHtml() {
|
||||||
|
val invoice = createInvoice()
|
||||||
|
val testFile = File.createTempFile("Zugferd", ".html")
|
||||||
|
|
||||||
|
val result = underTest.convertInvoiceToHtml(invoice, testFile)
|
||||||
|
|
||||||
|
assertThat(result).isNotEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun convertCiiToUbl() {
|
fun convertCiiToUbl() {
|
||||||
val invoice = createInvoice()
|
val invoice = createInvoice()
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.codinux.invoicing.creation
|
package net.codinux.invoicing.creation
|
||||||
|
|
||||||
import assertk.assertThat
|
|
||||||
import assertk.assertions.isNotEmpty
|
|
||||||
import net.codinux.invoicing.test.DataGenerator
|
import net.codinux.invoicing.test.DataGenerator
|
||||||
import net.codinux.invoicing.test.InvoiceAsserter
|
import net.codinux.invoicing.test.InvoiceAsserter
|
||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDInvoiceImporter
|
import org.mustangproject.ZUGFeRD.ZUGFeRDInvoiceImporter
|
||||||
|
@ -44,16 +42,6 @@ class EInvoiceCreatorTest {
|
||||||
assertInvoiceXml(xml)
|
assertInvoiceXml(xml)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun convertInvoiceToHtml() {
|
|
||||||
val invoice = createInvoice()
|
|
||||||
val testFile = File.createTempFile("Zugferd", ".html")
|
|
||||||
|
|
||||||
val result = underTest.convertInvoiceToHtml(invoice, testFile)
|
|
||||||
|
|
||||||
assertThat(result).isNotEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun createInvoice() = DataGenerator.createInvoice()
|
private fun createInvoice() = DataGenerator.createInvoice()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue