KI-AGENT: Beleg-Relationswerte vor dem Speichern normalisieren
This commit is contained in:
@@ -936,7 +936,16 @@ export default async function resourceRoutes(server: FastifyInstance) {
|
|||||||
|
|
||||||
const normalizeDate = (val: any) => { const d = new Date(val); return isNaN(d.getTime()) ? null : d; }
|
const normalizeDate = (val: any) => { const d = new Date(val); return isNaN(d.getTime()) ? null : d; }
|
||||||
Object.keys(createData).forEach((key) => {
|
Object.keys(createData).forEach((key) => {
|
||||||
if (key.toLowerCase().includes("date") && key !== "deliveryDateType") createData[key] = normalizeDate(createData[key])
|
const value = createData[key]
|
||||||
|
const shouldNormalize =
|
||||||
|
isDateLikeField(key) &&
|
||||||
|
value !== null &&
|
||||||
|
value !== undefined &&
|
||||||
|
(typeof value === "string" || typeof value === "number" || value instanceof Date)
|
||||||
|
|
||||||
|
if (shouldNormalize) {
|
||||||
|
createData[key] = normalizeDate(value)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const [created] = await server.db.insert(table).values(createData).returning()
|
const [created] = await server.db.insert(table).values(createData).returning()
|
||||||
|
|||||||
@@ -303,6 +303,11 @@ watch(
|
|||||||
const loaded = ref(false)
|
const loaded = ref(false)
|
||||||
const normalizeEntityId = (value) => {
|
const normalizeEntityId = (value) => {
|
||||||
if (value === null || typeof value === "undefined") return null
|
if (value === null || typeof value === "undefined") return null
|
||||||
|
if (value instanceof Date) return null
|
||||||
|
if (typeof value === "string") {
|
||||||
|
const normalized = value.trim()
|
||||||
|
if (!/^\d+$/.test(normalized) && dayjs(normalized).isValid()) return null
|
||||||
|
}
|
||||||
return typeof value === "object" ? (value.id ?? null) : value
|
return typeof value === "object" ? (value.id ?? null) : value
|
||||||
}
|
}
|
||||||
const normalizeCreatedDocumentRow = (row) => {
|
const normalizeCreatedDocumentRow = (row) => {
|
||||||
@@ -1567,14 +1572,14 @@ const saveSerialInvoice = async () => {
|
|||||||
let createData = {
|
let createData = {
|
||||||
type: itemInfo.value.type,
|
type: itemInfo.value.type,
|
||||||
state: 'Erstellt',
|
state: 'Erstellt',
|
||||||
customer: itemInfo.value.customer,
|
customer: normalizeEntityId(itemInfo.value.customer),
|
||||||
contact: itemInfo.value.contact,
|
contact: normalizeEntityId(itemInfo.value.contact),
|
||||||
contract: itemInfo.value.contract,
|
contract: normalizeEntityId(itemInfo.value.contract),
|
||||||
address: itemInfo.value.address,
|
address: itemInfo.value.address,
|
||||||
project: itemInfo.value.project,
|
project: normalizeEntityId(itemInfo.value.project),
|
||||||
paymentDays: itemInfo.value.paymentDays,
|
paymentDays: itemInfo.value.paymentDays,
|
||||||
payment_type: itemInfo.value.payment_type,
|
payment_type: itemInfo.value.payment_type,
|
||||||
outgoingsepamandate: itemInfo.value.outgoingsepamandate,
|
outgoingsepamandate: normalizeEntityId(itemInfo.value.outgoingsepamandate),
|
||||||
deliveryDateType: "Leistungszeitraum",
|
deliveryDateType: "Leistungszeitraum",
|
||||||
createdBy: itemInfo.value.createdBy,
|
createdBy: itemInfo.value.createdBy,
|
||||||
created_by: itemInfo.value.created_by,
|
created_by: itemInfo.value.created_by,
|
||||||
@@ -1650,19 +1655,19 @@ const saveDocument = async (state, resetup = false) => {
|
|||||||
type: itemInfo.value.type,
|
type: itemInfo.value.type,
|
||||||
taxType: ['invoices', 'cancellationInvoices', 'advanceInvoices', 'confirmationOrders', ...quoteLikeDocumentTypes].includes(itemInfo.value.type) ? normalizeTaxTypeValue(itemInfo.value.taxType) : null,
|
taxType: ['invoices', 'cancellationInvoices', 'advanceInvoices', 'confirmationOrders', ...quoteLikeDocumentTypes].includes(itemInfo.value.type) ? normalizeTaxTypeValue(itemInfo.value.taxType) : null,
|
||||||
state: itemInfo.value.state || "Entwurf",
|
state: itemInfo.value.state || "Entwurf",
|
||||||
customer: itemInfo.value.customer,
|
customer: normalizeEntityId(itemInfo.value.customer),
|
||||||
contact: itemInfo.value.contact,
|
contact: normalizeEntityId(itemInfo.value.contact),
|
||||||
contract: itemInfo.value.contract,
|
contract: normalizeEntityId(itemInfo.value.contract),
|
||||||
address: itemInfo.value.address,
|
address: itemInfo.value.address,
|
||||||
project: itemInfo.value.project,
|
project: normalizeEntityId(itemInfo.value.project),
|
||||||
plant: itemInfo.value.plant,
|
plant: normalizeEntityId(itemInfo.value.plant),
|
||||||
documentNumber: itemInfo.value.documentNumber,
|
documentNumber: itemInfo.value.documentNumber,
|
||||||
documentDate: itemInfo.value.documentDate,
|
documentDate: itemInfo.value.documentDate,
|
||||||
deliveryDate: itemInfo.value.deliveryDate,
|
deliveryDate: itemInfo.value.deliveryDate,
|
||||||
deliveryDateEnd: itemInfo.value.deliveryDateEnd,
|
deliveryDateEnd: itemInfo.value.deliveryDateEnd,
|
||||||
paymentDays: itemInfo.value.paymentDays,
|
paymentDays: itemInfo.value.paymentDays,
|
||||||
payment_type: itemInfo.value.payment_type,
|
payment_type: itemInfo.value.payment_type,
|
||||||
outgoingsepamandate: itemInfo.value.outgoingsepamandate,
|
outgoingsepamandate: normalizeEntityId(itemInfo.value.outgoingsepamandate),
|
||||||
deliveryDateType: itemInfo.value.deliveryDateType,
|
deliveryDateType: itemInfo.value.deliveryDateType,
|
||||||
info: {},
|
info: {},
|
||||||
createdBy: itemInfo.value.createdBy,
|
createdBy: itemInfo.value.createdBy,
|
||||||
@@ -1673,9 +1678,9 @@ const saveDocument = async (state, resetup = false) => {
|
|||||||
endText: itemInfo.value.endText,
|
endText: itemInfo.value.endText,
|
||||||
rows: itemInfo.value.rows,
|
rows: itemInfo.value.rows,
|
||||||
contactPerson: itemInfo.value.contactPerson,
|
contactPerson: itemInfo.value.contactPerson,
|
||||||
createddocument: itemInfo.value.createddocument,
|
createddocument: normalizeEntityId(itemInfo.value.createddocument),
|
||||||
agriculture: itemInfo.value.agriculture,
|
agriculture: itemInfo.value.agriculture,
|
||||||
letterhead: itemInfo.value.letterhead,
|
letterhead: normalizeEntityId(itemInfo.value.letterhead),
|
||||||
usedAdvanceInvoices: itemInfo.value.usedAdvanceInvoices,
|
usedAdvanceInvoices: itemInfo.value.usedAdvanceInvoices,
|
||||||
availableInPortal: itemInfo.value.availableInPortal,
|
availableInPortal: itemInfo.value.availableInPortal,
|
||||||
customSurchargePercentage: itemInfo.value.customSurchargePercentage,
|
customSurchargePercentage: itemInfo.value.customSurchargePercentage,
|
||||||
|
|||||||
Reference in New Issue
Block a user