KI-AGENT: Fange fehlende Dokument-Auswahldaten ab
This commit is contained in:
@@ -12,6 +12,7 @@ const route = useRoute()
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const modal = useModal()
|
const modal = useModal()
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
|
const toast = useToast()
|
||||||
const quoteLikeDocumentTypes = ["quotes", "costEstimates"]
|
const quoteLikeDocumentTypes = ["quotes", "costEstimates"]
|
||||||
const deliveryNoteLikeDocumentTypes = ["deliveryNotes", "packingSlips"]
|
const deliveryNoteLikeDocumentTypes = ["deliveryNotes", "packingSlips"]
|
||||||
const documentStorageFallbackTypes = {
|
const documentStorageFallbackTypes = {
|
||||||
@@ -114,6 +115,18 @@ const serialIntervalItems = ['wöchentlich', '2 - wöchentlich', 'monatlich', 'v
|
|||||||
const serialDateDirectionItems = ['Rückwirkend', 'Im Voraus']
|
const serialDateDirectionItems = ['Rückwirkend', 'Im Voraus']
|
||||||
const taxPercentItems = [19, 7, 0]
|
const taxPercentItems = [19, 7, 0]
|
||||||
const selectedCustomer = computed(() => customers.value.find(i => i.id === itemInfo.value.customer) || null)
|
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) => {
|
const normalizeExternalUrl = (value) => {
|
||||||
if (!value || typeof value !== "string") return null
|
if (!value || typeof value !== "string") return null
|
||||||
|
|
||||||
@@ -195,7 +208,11 @@ watch(() => itemInfo.value.deliveryDateType, () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const setupData = async () => {
|
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("*")
|
createddocuments.value = await useEntities("createddocuments").select("*")
|
||||||
projects.value = await useEntities("projects").select("*")
|
projects.value = await useEntities("projects").select("*")
|
||||||
plants.value = await useEntities("plants").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.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")) {
|
if (itemInfo.value.type === "advanceInvoices" && !itemInfo.value.rows.find(i => i.text === "Abschlagszahlung")) {
|
||||||
|
|
||||||
@@ -1431,15 +1450,15 @@ const getDocumentData = async () => {
|
|||||||
}] : [],
|
}] : [],
|
||||||
...itemInfo.value.plant ? [{
|
...itemInfo.value.plant ? [{
|
||||||
label: "Objekt",
|
label: "Objekt",
|
||||||
content: plants.value.find(i => i.id === itemInfo.value.plant).name,
|
content: getPlantName(itemInfo.value.plant),
|
||||||
}] : [],
|
}] : [],
|
||||||
...itemInfo.value.project ? [{
|
...itemInfo.value.project ? [{
|
||||||
label: "Projekt",
|
label: "Projekt",
|
||||||
content: projects.value.find(i => i.id === itemInfo.value.project).name
|
content: getProjectName(itemInfo.value.project)
|
||||||
}] : [],
|
}] : [],
|
||||||
...itemInfo.value.contract ? [{
|
...itemInfo.value.contract ? [{
|
||||||
label: "Vertrag",
|
label: "Vertrag",
|
||||||
content: contracts.value.find(i => i.id === itemInfo.value.contract).contractNumber
|
content: getContractNumber(itemInfo.value.contract)
|
||||||
}] : []
|
}] : []
|
||||||
],
|
],
|
||||||
title: itemInfo.value.title,
|
title: itemInfo.value.title,
|
||||||
@@ -1494,7 +1513,14 @@ const showDocument = ref(false)
|
|||||||
const uri = ref("")
|
const uri = ref("")
|
||||||
const generateDocument = async () => {
|
const generateDocument = async () => {
|
||||||
showDocument.value = false
|
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 useFunctions().useCreatePDF(await getDocumentData(), path, "createdDocument")
|
||||||
/*uri.value = await useNuxtApp().$api("/api/functions/createinvoicepdf",{
|
/*uri.value = await useNuxtApp().$api("/api/functions/createinvoicepdf",{
|
||||||
@@ -1984,7 +2010,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
:color="itemInfo.letterhead ? 'primary' : 'error'"
|
:color="itemInfo.letterhead ? 'primary' : 'error'"
|
||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
{{ itemInfo.letterhead ? letterheads.find(i => i.id === itemInfo.letterhead).name : "Kein Briefpapier gewählt" }}
|
{{ itemInfo.letterhead ? getLetterheadName(itemInfo.letterhead) : "Kein Briefpapier gewählt" }}
|
||||||
</template>
|
</template>
|
||||||
</USelectMenu>
|
</USelectMenu>
|
||||||
</UFormField>
|
</UFormField>
|
||||||
@@ -2077,7 +2103,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
</UFormField>
|
</UFormField>
|
||||||
<UFormField
|
<UFormField
|
||||||
label="Ansprechpartner:"
|
label="Ansprechpartner:"
|
||||||
v-if="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).isCompany : false "
|
v-if="selectedCustomer?.isCompany"
|
||||||
>
|
>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<USelectMenu
|
<USelectMenu
|
||||||
@@ -2093,7 +2119,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
<span
|
<span
|
||||||
class="truncate">{{ itemInfo.contact ? contacts.find(i => i.id === itemInfo.contact).fullName : "Kein Kontakt ausgewählt" }}</span>
|
class="truncate">{{ itemInfo.contact ? getContactName(itemInfo.contact) : "Kein Kontakt ausgewählt" }}</span>
|
||||||
</template>
|
</template>
|
||||||
</USelectMenu>
|
</USelectMenu>
|
||||||
<!-- <UButton
|
<!-- <UButton
|
||||||
@@ -2124,14 +2150,14 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
>
|
>
|
||||||
<UInput
|
<UInput
|
||||||
v-model="itemInfo.address.street"
|
v-model="itemInfo.address.street"
|
||||||
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.street : 'Straße + Hausnummer'"
|
:placeholder="selectedCustomer?.infoData?.street || 'Straße + Hausnummer'"
|
||||||
:color="itemInfo.address.street ? 'primary' : 'error'"
|
:color="itemInfo.address.street ? 'primary' : 'error'"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
/>
|
/>
|
||||||
<UInput
|
<UInput
|
||||||
v-model="itemInfo.address.special"
|
v-model="itemInfo.address.special"
|
||||||
class="mt-3 w-full"
|
class="mt-3 w-full"
|
||||||
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.special : 'Adresszusatz'"
|
:placeholder="selectedCustomer?.infoData?.special || 'Adresszusatz'"
|
||||||
/>
|
/>
|
||||||
<InputGroup class="mt-3 w-full">
|
<InputGroup class="mt-3 w-full">
|
||||||
<UInput
|
<UInput
|
||||||
@@ -2142,13 +2168,13 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
maxlength="5"
|
maxlength="5"
|
||||||
@input="sanitizeAddressZipInput"
|
@input="sanitizeAddressZipInput"
|
||||||
@change="checkAddressZip"
|
@change="checkAddressZip"
|
||||||
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.zip : 'PLZ'"
|
:placeholder="selectedCustomer?.infoData?.zip || 'PLZ'"
|
||||||
:color="itemInfo.address.zip ? 'primary' : 'error'"
|
:color="itemInfo.address.zip ? 'primary' : 'error'"
|
||||||
/>
|
/>
|
||||||
<UInput
|
<UInput
|
||||||
class="w-full min-w-0"
|
class="w-full min-w-0"
|
||||||
v-model="itemInfo.address.city"
|
v-model="itemInfo.address.city"
|
||||||
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.city : 'Ort'"
|
:placeholder="selectedCustomer?.infoData?.city || 'Ort'"
|
||||||
:color="itemInfo.address.city ? 'primary' : 'error'"
|
:color="itemInfo.address.city ? 'primary' : 'error'"
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
@@ -2422,7 +2448,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
:disabled="!itemInfo.customer"
|
:disabled="!itemInfo.customer"
|
||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
{{ plants.find(i => i.id === itemInfo.plant) ? plants.find(i => i.id === itemInfo.plant).name : "Kein Objekt ausgewählt" }}
|
{{ itemInfo.plant ? getPlantName(itemInfo.plant) : "Kein Objekt ausgewählt" }}
|
||||||
</template>
|
</template>
|
||||||
<template #item="{ item: plant }">
|
<template #item="{ item: plant }">
|
||||||
{{ plant.name }}
|
{{ plant.name }}
|
||||||
@@ -2459,7 +2485,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
:disabled="!itemInfo.customer"
|
:disabled="!itemInfo.customer"
|
||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
{{ itemInfo.project ? projects.find(i => i.id === itemInfo.project).name : "Kein Projekt ausgewählt" }}
|
{{ itemInfo.project ? getProjectName(itemInfo.project) : "Kein Projekt ausgewählt" }}
|
||||||
</template>
|
</template>
|
||||||
<template #item="{ item: project }">
|
<template #item="{ item: project }">
|
||||||
{{ customers.find(i => i.id === project.customer) ? customers.find(i => i.id === project.customer).name : "" }}
|
{{ customers.find(i => i.id === project.customer) ? customers.find(i => i.id === project.customer).name : "" }}
|
||||||
@@ -2497,7 +2523,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
|||||||
:disabled="!itemInfo.customer"
|
:disabled="!itemInfo.customer"
|
||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
{{ itemInfo.contract ? contracts.find(i => i.id === itemInfo.contract).name : "Kein Vertrag ausgewählt" }}
|
{{ itemInfo.contract ? getContractName(itemInfo.contract) : "Kein Vertrag ausgewählt" }}
|
||||||
</template>
|
</template>
|
||||||
<template #item="{ item: contract }">
|
<template #item="{ item: contract }">
|
||||||
{{ customers.find(i => i.id === contract.customer) ? customers.find(i => i.id === contract.customer).name : "" }}
|
{{ customers.find(i => i.id === contract.customer) ? customers.find(i => i.id === contract.customer).name : "" }}
|
||||||
|
|||||||
Reference in New Issue
Block a user