Implemented convertInvoiceToHtml()
This commit is contained in:
parent
658c02296a
commit
1a967efcbd
|
@ -52,6 +52,33 @@ class EInvoiceCreator(
|
|||
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 {
|
||||
val transaction = mapper.mapToTransaction(invoice)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.codinux.invoicing.creation
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isNotEmpty
|
||||
import net.codinux.invoicing.test.DataGenerator
|
||||
import net.codinux.invoicing.test.InvoiceAsserter
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDInvoiceImporter
|
||||
|
@ -31,8 +33,8 @@ class EInvoiceCreatorTest {
|
|||
|
||||
@Test
|
||||
fun createZugferdPdf() {
|
||||
val testFile = File.createTempFile("Zugferd", ".pdf")
|
||||
val invoice = createInvoice()
|
||||
val testFile = File.createTempFile("Zugferd", ".pdf")
|
||||
|
||||
underTest.createZugferdPdf(invoice, testFile)
|
||||
|
||||
|
@ -42,6 +44,16 @@ class EInvoiceCreatorTest {
|
|||
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue