KI-AGENT: ZUGFeRD- und E-Rechnungserkennung ergänzen

This commit is contained in:
2026-07-21 19:59:44 +02:00
parent 430ab74522
commit 6c613857fa
4 changed files with 200 additions and 24 deletions

View File

@@ -1,6 +1,8 @@
import { FastifyInstance } from "fastify"
import dayjs from "dayjs"
import { getInvoiceDataFromGPT } from "../../utils/gpt"
import { loadFileBuffer } from "../../utils/fileBuffer"
import { detectElectronicInvoice } from "../einvoice/detectElectronicInvoice"
// Drizzle schema
import {
@@ -90,7 +92,32 @@ export function prepareIncomingInvoices(server: FastifyInstance) {
for (const file of filesRes) {
console.log(`Processing file ${file.id} for tenant ${tenantId}`)
const data = await getInvoiceDataFromGPT(server,file, tenantId)
let fileData: Buffer
try {
fileData = await loadFileBuffer(file.path!)
} catch (error) {
server.log.error(error, `Datei ${file.id} konnte nicht aus S3 geladen werden.`)
continue
}
const electronicInvoice = await detectElectronicInvoice(fileData, file)
if (electronicInvoice) {
server.log.info({
fileId: file.id,
container: electronicInvoice.container,
syntax: electronicInvoice.syntax,
attachmentName: electronicInvoice.attachmentName,
}, "Strukturierte E-Rechnung erkannt.")
if (electronicInvoice.container === "xml") {
server.log.warn({ fileId: file.id }, "Die Auswertung eigenständiger E-Rechnungs-XML folgt in Etappe 2.")
continue
}
}
const data = await getInvoiceDataFromGPT(server, file, tenantId, fileData)
if (!data) {
server.log.warn(`GPT returned no data for file ${file.id}`)