KI-AGENT: Fange fehlende Dokument-Auswahldaten ab
This commit is contained in:
@@ -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'"
|
||||
>
|
||||
<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>
|
||||
</USelectMenu>
|
||||
</UFormField>
|
||||
@@ -2077,7 +2103,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
||||
</UFormField>
|
||||
<UFormField
|
||||
label="Ansprechpartner:"
|
||||
v-if="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).isCompany : false "
|
||||
v-if="selectedCustomer?.isCompany"
|
||||
>
|
||||
<InputGroup>
|
||||
<USelectMenu
|
||||
@@ -2093,7 +2119,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
||||
>
|
||||
<template #default>
|
||||
<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>
|
||||
</USelectMenu>
|
||||
<!-- <UButton
|
||||
@@ -2124,14 +2150,14 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
||||
>
|
||||
<UInput
|
||||
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'"
|
||||
class="w-full"
|
||||
/>
|
||||
<UInput
|
||||
v-model="itemInfo.address.special"
|
||||
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">
|
||||
<UInput
|
||||
@@ -2142,13 +2168,13 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
||||
maxlength="5"
|
||||
@input="sanitizeAddressZipInput"
|
||||
@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'"
|
||||
/>
|
||||
<UInput
|
||||
class="w-full min-w-0"
|
||||
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'"
|
||||
/>
|
||||
</InputGroup>
|
||||
@@ -2422,7 +2448,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
||||
:disabled="!itemInfo.customer"
|
||||
>
|
||||
<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 #item="{ item: plant }">
|
||||
{{ plant.name }}
|
||||
@@ -2459,7 +2485,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
|
||||
:disabled="!itemInfo.customer"
|
||||
>
|
||||
<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 #item="{ item: project }">
|
||||
{{ 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"
|
||||
>
|
||||
<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 #item="{ item: contract }">
|
||||
{{ customers.find(i => i.id === contract.customer) ? customers.find(i => i.id === contract.customer).name : "" }}
|
||||
|
||||
Reference in New Issue
Block a user