From e5fab70056ecdf9a79de7cdf8eb689ab5c45a1a9 Mon Sep 17 00:00:00 2001 From: flfeders Date: Sun, 9 Aug 2026 17:47:20 +0200 Subject: [PATCH] Gebuchte Eingangsbelege bearbeitbar machen --- .../pages/incomingInvoices/[mode]/[id].vue | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/frontend/pages/incomingInvoices/[mode]/[id].vue b/frontend/pages/incomingInvoices/[mode]/[id].vue index 7e336b3..38ef593 100644 --- a/frontend/pages/incomingInvoices/[mode]/[id].vue +++ b/frontend/pages/incomingInvoices/[mode]/[id].vue @@ -49,6 +49,11 @@ const loadedFileId = ref(null) const invoiceFiles = ref([]) const paymentTypeItems = ['Überweisung', 'Lastschrift', 'Kreditkarte', 'PayPal', 'Bar', 'Sonstiges'] const files = useFiles() +const hasActiveBankAssignmentIn = (allocations = []) => allocations.some((allocation) => { + if (allocation?.archived) return false + + return Boolean(allocation?.bankstatement || allocation?.bs_id) +}) const setup = async () => { // 1. Daten laden @@ -65,6 +70,18 @@ const setup = async () => { accounts: normalizeIncomingInvoiceAccounts(invoiceData.accounts || [], invoiceData.date) } + if (mode.value === "edit" && invoiceData.state === "Gebucht" && (invoiceData.archived || hasActiveBankAssignmentIn(invoiceData.statementallocations))) { + toast.add({ + title: "Bearbeiten nicht möglich", + description: invoiceData.archived + ? "Archivierte Eingangsbelege können nicht bearbeitet werden." + : "Der Eingangsbeleg ist bereits einer Bankbuchung zugewiesen.", + color: "error" + }) + await navigateTo(`/incomingInvoices/show/${invoiceData.id}`) + return + } + // Fallback Accounts if(itemInfo.value.accounts.length === 0) { itemInfo.value.accounts.push(createIncomingInvoiceAccount({ depreciationStartDate: itemInfo.value.date || null })) @@ -150,16 +167,19 @@ const bankBookingDateLabel = computed(() => { return bankBookingDates.value.map(formatDate).join(", ") }) -const hasActiveBankAssignment = computed(() => (itemInfo.value.statementallocations || []).some((allocation) => { - if (allocation?.archived) return false - - return Boolean(allocation?.bankstatement || allocation?.bs_id) -})) +const hasActiveBankAssignment = computed(() => hasActiveBankAssignmentIn(itemInfo.value.statementallocations)) +const isBookedIncomingInvoice = computed(() => itemInfo.value.state === "Gebucht") +const canEditIncomingInvoice = computed(() => ( + mode.value === "show" + && isBookedIncomingInvoice.value + && !itemInfo.value.archived + && !hasActiveBankAssignment.value +)) const canArchiveIncomingInvoice = computed(() => { if (itemInfo.value.archived) return false - if (mode.value !== "show") return true + if (isBookedIncomingInvoice.value) return !hasActiveBankAssignment.value - return itemInfo.value.state === "Gebucht" && !hasActiveBankAssignment.value + return mode.value !== "show" }) const vendorName = computed(() => vendors.value.find((vendor) => vendor.id === itemInfo.value.vendor)?.name || "-") const eInvoiceValidation = computed(() => itemInfo.value.eInvoiceValidation || null) @@ -259,7 +279,9 @@ const applyTotalTaxOverride = () => { // --- Saving --- const updateIncomingInvoice = async (setBooked = false) => { - if (setBooked && hasBlockingIncomingInvoiceErrors.value) { + const keepBooked = setBooked || isBookedIncomingInvoice.value + + if (keepBooked && hasBlockingIncomingInvoiceErrors.value) { toast.add({ title: "Buchen nicht möglich", description: "Bitte beheben Sie zuerst die rot markierten Pflichtfehler.", @@ -271,7 +293,7 @@ const updateIncomingInvoice = async (setBooked = false) => { let item = { ...itemInfo.value } item.accounts = (item.accounts || []).map((account) => ensureDepreciationDefaults({ ...account }, item.date)) delete item.files - item.state = setBooked ? "Gebucht" : "Entwurf" + item.state = keepBooked ? "Gebucht" : "Entwurf" await useEntities('incominginvoices').update(itemInfo.value.id, item, !setBooked) @@ -332,6 +354,14 @@ const hasBlockingIncomingInvoiceErrors = computed(() => blockingIncomingInvoiceE