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("")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
class InvoicingResource(
|
||||
private val service: InvoicingService
|
||||
) {
|
||||
|
@ -30,7 +30,6 @@ class InvoicingResource(
|
|||
|
||||
@Path("facturx/pdf")
|
||||
@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")
|
||||
fun createFacturXPdf(invoice: Invoice): Response {
|
||||
val pdfFile = service.createFacturXPdf(invoice)
|
||||
|
@ -40,4 +39,14 @@ class InvoicingResource(
|
|||
.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 net.codinux.invoicing.creation.EInvoiceCreator
|
||||
import net.codinux.invoicing.model.Invoice
|
||||
import net.codinux.invoicing.reader.EInvoiceReader
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.extension
|
||||
|
||||
@Singleton
|
||||
class InvoicingService {
|
||||
|
||||
private val creator = EInvoiceCreator()
|
||||
|
||||
private val reader = EInvoiceReader()
|
||||
|
||||
|
||||
fun createXRechnung(invoice: Invoice): String =
|
||||
creator.createXRechnungXml(invoice)
|
||||
|
@ -27,4 +32,11 @@ class InvoicingService {
|
|||
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.body.delete-uploaded-files-on-end=true
|
||||
|
||||
%dev.quarkus.http.cors=true
|
||||
quarkus.http.cors.origins=*
|
||||
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
|
||||
|
|
Loading…
Reference in New Issue