Implemented extracting eInvoice data via API
This commit is contained in:
parent
07007ad619
commit
d879ba74d8
|
@ -9,7 +9,7 @@ import org.eclipse.microprofile.openapi.annotations.Operation
|
||||||
|
|
||||||
@Path("")
|
@Path("")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
class InvoicingResource(
|
class InvoicingResource(
|
||||||
private val service: InvoicingService
|
private val service: InvoicingService
|
||||||
) {
|
) {
|
||||||
|
@ -30,7 +30,6 @@ class InvoicingResource(
|
||||||
|
|
||||||
@Path("facturx/pdf")
|
@Path("facturx/pdf")
|
||||||
@POST
|
@POST
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
|
||||||
@Operation(summary = "Create a Factur-X / ZUGFeRD XML, transforms it to PDF and attaches before created XML to it")
|
@Operation(summary = "Create a Factur-X / ZUGFeRD XML, transforms it to PDF and attaches before created XML to it")
|
||||||
fun createFacturXPdf(invoice: Invoice): Response {
|
fun createFacturXPdf(invoice: Invoice): Response {
|
||||||
val pdfFile = service.createFacturXPdf(invoice)
|
val pdfFile = service.createFacturXPdf(invoice)
|
||||||
|
@ -40,4 +39,14 @@ class InvoicingResource(
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Path("extract")
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Operation(summary = "Extract invoice data from a Factur-x / ZUGFeRD or XRechnung file")
|
||||||
|
fun extractInvoiceData(invoice: java.nio.file.Path) =
|
||||||
|
service.extractInvoiceData(invoice)
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,13 +3,18 @@ package net.codinux.invoicing.service
|
||||||
import jakarta.inject.Singleton
|
import jakarta.inject.Singleton
|
||||||
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 net.codinux.invoicing.reader.EInvoiceReader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.io.path.extension
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class InvoicingService {
|
class InvoicingService {
|
||||||
|
|
||||||
private val creator = EInvoiceCreator()
|
private val creator = EInvoiceCreator()
|
||||||
|
|
||||||
|
private val reader = EInvoiceReader()
|
||||||
|
|
||||||
|
|
||||||
fun createXRechnung(invoice: Invoice): String =
|
fun createXRechnung(invoice: Invoice): String =
|
||||||
creator.createXRechnungXml(invoice)
|
creator.createXRechnungXml(invoice)
|
||||||
|
@ -27,4 +32,11 @@ class InvoicingService {
|
||||||
return resultFile
|
return resultFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun extractInvoiceData(invoiceFile: Path) = when (invoiceFile.extension.lowercase()) {
|
||||||
|
"xml" -> reader.readFromXml(invoiceFile.toFile())
|
||||||
|
"pdf" -> reader.extractFromPdf(invoiceFile.toFile())
|
||||||
|
else -> throw IllegalArgumentException("We can only extract eInvoice data from .xml and .pdf files")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
quarkus.http.enable-compression=true
|
quarkus.http.enable-compression=true
|
||||||
|
|
||||||
|
quarkus.http.body.delete-uploaded-files-on-end=true
|
||||||
|
|
||||||
%dev.quarkus.http.cors=true
|
%dev.quarkus.http.cors=true
|
||||||
quarkus.http.cors.origins=*
|
quarkus.http.cors.origins=*
|
||||||
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
|
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
|
||||||
|
|
Loading…
Reference in New Issue