From 9c6a6a841a21d6bc2a810978fe9ef180cea90047 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Mon, 18 May 2026 21:15:34 +0200 Subject: [PATCH] KI-AGENT: Fange fehlende Dokument-Auswahldaten ab --- frontend/pages/createDocument/edit/[[id]].vue | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/frontend/pages/createDocument/edit/[[id]].vue b/frontend/pages/createDocument/edit/[[id]].vue index e91e09a..c207c38 100644 --- a/frontend/pages/createDocument/edit/[[id]].vue +++ b/frontend/pages/createDocument/edit/[[id]].vue @@ -12,6 +12,7 @@ const route = useRoute() const router = useRouter() const modal = useModal() const auth = useAuthStore() +const toast = useToast() const quoteLikeDocumentTypes = ["quotes", "costEstimates"] const deliveryNoteLikeDocumentTypes = ["deliveryNotes", "packingSlips"] const documentStorageFallbackTypes = { @@ -114,6 +115,18 @@ const serialIntervalItems = ['wöchentlich', '2 - wöchentlich', 'monatlich', 'v const serialDateDirectionItems = ['Rückwirkend', 'Im Voraus'] const taxPercentItems = [19, 7, 0] const selectedCustomer = computed(() => customers.value.find(i => i.id === itemInfo.value.customer) || null) +const findById = (items, id) => { + if (id === null || typeof id === "undefined") return null + + return items.find((item) => item.id === id) || null +} +const getContactName = (id) => findById(contacts.value, id)?.fullName || "Kontakt nicht gefunden" +const getContractName = (id) => findById(contracts.value, id)?.name || "Vertrag nicht gefunden" +const getContractNumber = (id) => findById(contracts.value, id)?.contractNumber || "Vertrag nicht gefunden" +const getLetterheadName = (id) => findById(letterheads.value, id)?.name || "Briefpapier nicht gefunden" +const getPlantName = (id) => findById(plants.value, id)?.name || "Objekt nicht gefunden" +const getProjectName = (id) => findById(projects.value, id)?.name || "Projekt nicht gefunden" +const getSelectedLetterhead = () => findById(letterheads.value, itemInfo.value.letterhead) const normalizeExternalUrl = (value) => { if (!value || typeof value !== "string") return null @@ -195,7 +208,11 @@ watch(() => itemInfo.value.deliveryDateType, () => { }) const setupData = async () => { - letterheads.value = (await useEntities("letterheads").select("*")).filter(i => i.documentTypes.length === 0 || i.documentTypes.includes(itemInfo.value.type)) + letterheads.value = (await useEntities("letterheads").select("*")).filter(i => { + const documentTypes = Array.isArray(i.documentTypes) ? i.documentTypes : [] + + return documentTypes.length === 0 || documentTypes.includes(itemInfo.value.type) + }) createddocuments.value = await useEntities("createddocuments").select("*") projects.value = await useEntities("projects").select("*") plants.value = await useEntities("plants").select("*") @@ -647,7 +664,9 @@ const setDocumentTypeConfig = (withTexts = false) => { //itemInfo.value.endText = texttemplates.value.find(i => i.documentType === itemInfo.value.type && i.default && i.pos === "endText").text } - itemInfo.value.letterhead = letterheads.value[0].id + if (!getSelectedLetterhead()) { + itemInfo.value.letterhead = letterheads.value[0]?.id || null + } if (itemInfo.value.type === "advanceInvoices" && !itemInfo.value.rows.find(i => i.text === "Abschlagszahlung")) { @@ -1431,15 +1450,15 @@ const getDocumentData = async () => { }] : [], ...itemInfo.value.plant ? [{ label: "Objekt", - content: plants.value.find(i => i.id === itemInfo.value.plant).name, + content: getPlantName(itemInfo.value.plant), }] : [], ...itemInfo.value.project ? [{ label: "Projekt", - content: projects.value.find(i => i.id === itemInfo.value.project).name + content: getProjectName(itemInfo.value.project) }] : [], ...itemInfo.value.contract ? [{ label: "Vertrag", - content: contracts.value.find(i => i.id === itemInfo.value.contract).contractNumber + content: getContractNumber(itemInfo.value.contract) }] : [] ], title: itemInfo.value.title, @@ -1494,7 +1513,14 @@ const showDocument = ref(false) const uri = ref("") const generateDocument = async () => { showDocument.value = false - const path = letterheads.value.find(i => i.id === itemInfo.value.letterhead).path + const selectedLetterhead = getSelectedLetterhead() + + if (!selectedLetterhead?.path) { + toast.add({ title: "Briefpapier fehlt", color: "error" }) + return + } + + const path = selectedLetterhead.path uri.value = await useFunctions().useCreatePDF(await getDocumentData(), path, "createdDocument") /*uri.value = await useNuxtApp().$api("/api/functions/createinvoicepdf",{ @@ -1984,7 +2010,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = { :color="itemInfo.letterhead ? 'primary' : 'error'" > @@ -2077,7 +2103,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {