fix in invoiceprep
This commit is contained in:
@@ -12,6 +12,18 @@ import {
|
||||
|
||||
import { eq, and, isNull, not } from "drizzle-orm"
|
||||
|
||||
const formatInvoiceItemDescription = (item: any) => {
|
||||
const parts = [
|
||||
typeof item.description === "string" ? item.description.trim() : "",
|
||||
item.quantity !== null && item.quantity !== undefined
|
||||
? [item.quantity, item.unit].filter(Boolean).join(" ")
|
||||
: (typeof item.unit === "string" ? item.unit.trim() : ""),
|
||||
typeof item.total === "number" ? `${item.total.toFixed(2)} EUR` : "",
|
||||
].filter(Boolean)
|
||||
|
||||
return parts.join(" - ")
|
||||
}
|
||||
|
||||
export function prepareIncomingInvoices(server: FastifyInstance) {
|
||||
const processInvoices = async (tenantId:number) => {
|
||||
console.log("▶ Starting Incoming Invoice Preparation")
|
||||
@@ -137,7 +149,8 @@ export function prepareIncomingInvoices(server: FastifyInstance) {
|
||||
if (data.reference) description += `Referenz: ${data.reference}\n`
|
||||
if (data.invoice_items) {
|
||||
for (const item of data.invoice_items) {
|
||||
description += `${item.description} - ${item.quantity} ${item.unit} - ${item.total}\n`
|
||||
const line = formatInvoiceItemDescription(item)
|
||||
if (line) description += `${line}\n`
|
||||
}
|
||||
}
|
||||
itemInfo.description = description.trim()
|
||||
|
||||
Reference in New Issue
Block a user