Controlling now eInvoice XML format via EInvoiceXmlFormat
This commit is contained in:
parent
6ec302e50f
commit
f24b2004bb
|
@ -58,7 +58,7 @@ fun create() {
|
||||||
val creator = EInvoiceCreator()
|
val creator = EInvoiceCreator()
|
||||||
|
|
||||||
// create a PDF that also contains the eInvoice as XML attachment
|
// create a PDF that also contains the eInvoice as XML attachment
|
||||||
creator.createFacturXPdf(invoice, pdfResultFile)
|
creator.createPdfWithAttachedXml(invoice, pdfResultFile)
|
||||||
|
|
||||||
// create only the XML file
|
// create only the XML file
|
||||||
val xml = creator.createFacturXXml(invoice)
|
val xml = creator.createFacturXXml(invoice)
|
||||||
|
|
|
@ -27,7 +27,7 @@ class InvoicingService {
|
||||||
fun createFacturXPdf(invoice: Invoice): Path {
|
fun createFacturXPdf(invoice: Invoice): Path {
|
||||||
val resultFile = createTempPdfFile()
|
val resultFile = createTempPdfFile()
|
||||||
|
|
||||||
creator.createFacturXPdf(invoice, resultFile.toFile())
|
creator.createPdfWithAttachedXml(invoice, resultFile.toFile())
|
||||||
|
|
||||||
return resultFile
|
return resultFile
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,46 +10,39 @@ open class EInvoiceCreator(
|
||||||
protected open val mapper: MustangMapper = MustangMapper()
|
protected open val mapper: MustangMapper = MustangMapper()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
open fun createXRechnungXml(invoice: Invoice): String {
|
open fun createXRechnungXml(invoice: Invoice) = createXml(invoice, EInvoiceXmlFormat.XRechnung)
|
||||||
val provider = ZUGFeRD2PullProvider()
|
|
||||||
provider.profile = Profiles.getByName("XRechnung")
|
|
||||||
|
|
||||||
return createXml(provider, invoice)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synonym for [createFacturXXml] (ZUGFeRD 2 is a synonym for Factur-X).
|
* Synonym for [createFacturXXml] (ZUGFeRD 2 is a synonym for Factur-X).
|
||||||
*/
|
*/
|
||||||
open fun createZugferdXml(invoice: Invoice) = createFacturXXml(invoice)
|
open fun createZugferdXml(invoice: Invoice) = createFacturXXml(invoice)
|
||||||
|
|
||||||
open fun createFacturXXml(invoice: Invoice): String {
|
open fun createFacturXXml(invoice: Invoice) = createXml(invoice, EInvoiceXmlFormat.FacturX)
|
||||||
|
|
||||||
|
protected open fun createXml(invoice: Invoice, format: EInvoiceXmlFormat): String {
|
||||||
val exporter = ZUGFeRDExporterFromA3()
|
val exporter = ZUGFeRDExporterFromA3()
|
||||||
.setProfile("EN16931") // required for XML?
|
.setProfile(getProfileNameForFormat(format))
|
||||||
|
|
||||||
return createXml(exporter.provider, invoice)
|
return createXml(exporter.provider, invoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected open fun createXml(provider: IXMLProvider, invoice: Invoice): String {
|
||||||
* Synonym for [createFacturXPdf] (ZUGFeRD 2 is a synonym for Factur-X).
|
val transaction = mapper.mapToTransaction(invoice)
|
||||||
*/
|
|
||||||
open fun createZugferdPdf(invoice: Invoice, outputFile: File) = createFacturXPdf(invoice, outputFile)
|
|
||||||
|
|
||||||
open fun createFacturXPdf(invoice: Invoice, outputFile: File) {
|
provider.generateXML(transaction)
|
||||||
val xml = createFacturXXml(invoice)
|
|
||||||
|
|
||||||
createFacturXPdf(xml, EInvoiceXmlFormat.FacturX, outputFile)
|
return String(provider.xml, Charsets.UTF_8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synonym for [createFacturXPdfWithXRechnungXML] (ZUGFeRD 2 is a synonym for Factur-X).
|
* Creates a hybrid PDF that also contains the Factur-X / ZUGFeRD or XRechnung XML as attachment.
|
||||||
*/
|
*/
|
||||||
open fun createZugferdPdfWithXRechnungXML(invoice: Invoice, outputFile: File) = createFacturXPdfWithXRechnungXML(invoice, outputFile)
|
@JvmOverloads
|
||||||
|
open fun createPdfWithAttachedXml(invoice: Invoice, outputFile: File, format: EInvoiceXmlFormat = EInvoiceXmlFormat.FacturX) {
|
||||||
|
val xml = createXml(invoice, format)
|
||||||
|
|
||||||
open fun createFacturXPdfWithXRechnungXML(invoice: Invoice, outputFile: File) {
|
createFacturXPdf(xml, format, outputFile)
|
||||||
val xml = createXRechnungXml(invoice)
|
|
||||||
|
|
||||||
createFacturXPdf(xml, EInvoiceXmlFormat.XRechnung, outputFile)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun createFacturXPdf(invoiceXml: String, format: EInvoiceXmlFormat, outputFile: File) {
|
protected open fun createFacturXPdf(invoiceXml: String, format: EInvoiceXmlFormat, outputFile: File) {
|
||||||
|
@ -67,8 +60,9 @@ open class EInvoiceCreator(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun attachInvoiceXmlToPdf(invoice: Invoice, pdfFile: File, outputFile: File) =
|
@JvmOverloads
|
||||||
attachInvoiceXmlToPdf(createFacturXXml(invoice), EInvoiceXmlFormat.FacturX, pdfFile, outputFile)
|
open fun attachInvoiceXmlToPdf(invoice: Invoice, pdfFile: File, outputFile: File, format: EInvoiceXmlFormat = EInvoiceXmlFormat.FacturX) =
|
||||||
|
attachInvoiceXmlToPdf(createXml(invoice, format), format, pdfFile, outputFile)
|
||||||
|
|
||||||
open fun attachInvoiceXmlToPdf(invoiceXml: String, format: EInvoiceXmlFormat, pdfFile: File, outputFile: File) {
|
open fun attachInvoiceXmlToPdf(invoiceXml: String, format: EInvoiceXmlFormat, pdfFile: File, outputFile: File) {
|
||||||
val exporter = ZUGFeRDExporterFromA3()
|
val exporter = ZUGFeRDExporterFromA3()
|
||||||
|
@ -87,15 +81,6 @@ open class EInvoiceCreator(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected open fun createXml(provider: IXMLProvider, invoice: Invoice): String {
|
|
||||||
val transaction = mapper.mapToTransaction(invoice)
|
|
||||||
|
|
||||||
provider.generateXML(transaction)
|
|
||||||
|
|
||||||
return String(provider.xml, Charsets.UTF_8)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected open fun getProfileNameForFormat(format: EInvoiceXmlFormat) = when (format) {
|
protected open fun getProfileNameForFormat(format: EInvoiceXmlFormat) = when (format) {
|
||||||
EInvoiceXmlFormat.FacturX -> "EN16931" // available values: MINIMUM, BASICWL, BASIC, CIUS, EN16931, EXTENDED, XRECHNUNG
|
EInvoiceXmlFormat.FacturX -> "EN16931" // available values: MINIMUM, BASICWL, BASIC, CIUS, EN16931, EXTENDED, XRECHNUNG
|
||||||
EInvoiceXmlFormat.XRechnung -> "XRECHNUNG"
|
EInvoiceXmlFormat.XRechnung -> "XRECHNUNG"
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Demonstration {
|
||||||
val creator = EInvoiceCreator()
|
val creator = EInvoiceCreator()
|
||||||
|
|
||||||
// create a PDF that also contains the eInvoice as XML attachment
|
// create a PDF that also contains the eInvoice as XML attachment
|
||||||
creator.createFacturXPdf(invoice, pdfResultFile)
|
creator.createPdfWithAttachedXml(invoice, pdfResultFile)
|
||||||
|
|
||||||
// create only the XML file
|
// create only the XML file
|
||||||
val xml = creator.createFacturXXml(invoice)
|
val xml = creator.createFacturXXml(invoice)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.codinux.invoicing.creation
|
package net.codinux.invoicing.creation
|
||||||
|
|
||||||
|
import net.codinux.invoicing.model.EInvoiceXmlFormat
|
||||||
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
|
||||||
|
@ -30,11 +31,11 @@ class EInvoiceCreatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun createFacturXPdf() {
|
fun createPdfWithAttachedXml_FacturX() {
|
||||||
val invoice = createInvoice()
|
val invoice = createInvoice()
|
||||||
val testFile = File.createTempFile("Zugferd", ".pdf")
|
val testFile = File.createTempFile("Zugferd", ".pdf")
|
||||||
|
|
||||||
underTest.createFacturXPdf(invoice, testFile)
|
underTest.createPdfWithAttachedXml(invoice, testFile, EInvoiceXmlFormat.FacturX)
|
||||||
|
|
||||||
val importer = testFile.inputStream().use { ZUGFeRDInvoiceImporter(it) }
|
val importer = testFile.inputStream().use { ZUGFeRDInvoiceImporter(it) }
|
||||||
val xml = String(importer.rawXML, Charsets.UTF_8)
|
val xml = String(importer.rawXML, Charsets.UTF_8)
|
||||||
|
@ -43,11 +44,11 @@ class EInvoiceCreatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun createFacturXPdfWithXRechnungXML() {
|
fun createPdfWithAttachedXml_XRechnung() {
|
||||||
val invoice = createInvoice()
|
val invoice = createInvoice()
|
||||||
val testFile = File.createTempFile("Zugferd", ".pdf")
|
val testFile = File.createTempFile("Zugferd", ".pdf")
|
||||||
|
|
||||||
underTest.createFacturXPdfWithXRechnungXML(invoice, testFile)
|
underTest.createPdfWithAttachedXml(invoice, testFile, EInvoiceXmlFormat.XRechnung)
|
||||||
|
|
||||||
val importer = testFile.inputStream().use { ZUGFeRDInvoiceImporter(it) }
|
val importer = testFile.inputStream().use { ZUGFeRDInvoiceImporter(it) }
|
||||||
val xml = String(importer.rawXML, Charsets.UTF_8)
|
val xml = String(importer.rawXML, Charsets.UTF_8)
|
||||||
|
|
Loading…
Reference in New Issue