From 60327fe928dba6c2d837dc46a471a6fbc8d4ee29 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Mon, 7 Sep 2026 20:38:10 +0200 Subject: [PATCH] =?UTF-8?q?KI-AGENT:=20Gegenkonten=20in=20der=20BWA=20voll?= =?UTF-8?q?st=C3=A4ndig=20saldieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/pages/accounting/bwa.vue | 53 ++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/frontend/pages/accounting/bwa.vue b/frontend/pages/accounting/bwa.vue index 21140c1..1ebed96 100644 --- a/frontend/pages/accounting/bwa.vue +++ b/frontend/pages/accounting/bwa.vue @@ -78,7 +78,12 @@ const isRelevantInputInvoice = (invoice: any) => { const sameId = (left: any, right: any) => String(left ?? "") === String(right ?? "") const getStatementDate = (allocation: any) => { - return allocation?.bankstatement?.date || allocation?.bankstatement?.valueDate || allocation?.date || allocation?.created_at || null + return allocation?.bankstatement?.date + || allocation?.bankstatement?.valueDate + || allocation?.date + || allocation?.manualBookingDate + || allocation?.created_at + || null } const matchesSelectedPeriod = (dateValue: any) => { @@ -154,21 +159,12 @@ const filteredStatementAllocations = computed(() => { return statementAllocations.value.filter((allocation) => matchesSelectedPeriod(getStatementDate(allocation))) }) -const filteredDirectAccountStatementAllocations = computed(() => { +const filteredAccountStatementAllocations = computed(() => { return filteredStatementAllocations.value.filter((allocation) => { if (allocation.account === null || allocation.account === undefined) { return false } - return !allocation?.incominginvoice - && !allocation?.createddocument - && !allocation?.ii_id - && !allocation?.cd_id - }) -}) - -const filteredAccountStatementAllocations = computed(() => { - return filteredDirectAccountStatementAllocations.value.filter((allocation) => { return getStatementAllocationImmediateExpenseAmount(allocation) > 0 }) }) @@ -307,7 +303,7 @@ const accountRows = computed(() => { })) }) - const directBookings = filteredDirectAccountStatementAllocations.value + const debitBookings = filteredStatementAllocations.value .filter((allocation) => sameId(allocation.account?.id || allocation.account, account.id)) .map((allocation) => { const amount = Number(allocation.amount || 0) @@ -320,7 +316,20 @@ const accountRows = computed(() => { } }) - const bookings = [...invoiceBookings, ...directBookings] + const creditBookings = filteredStatementAllocations.value + .filter((allocation) => sameId(allocation.contraAccount?.id || allocation.contraAccount, account.id)) + .map((allocation) => { + const amount = -Number(allocation.amount || 0) + + return { + type: "statementallocation", + amountNet: amount, + amountTax: 0, + amountGross: amount + } + }) + + const bookings = [...invoiceBookings, ...debitBookings, ...creditBookings] if (bookings.length === 0) { return null @@ -350,23 +359,29 @@ const accountRows = computed(() => { const ownAccountRows = computed(() => { return ownAccounts.value .map((account) => { - const bookings = filteredStatementAllocations.value.filter((allocation) => sameId(allocation.ownaccount?.id || allocation.ownaccount, account.id)) + const debitBookings = filteredStatementAllocations.value + .filter((allocation) => sameId(allocation.ownaccount?.id || allocation.ownaccount, account.id)) + .map((allocation) => Number(allocation.amount || 0)) + + const creditBookings = filteredStatementAllocations.value + .filter((allocation) => sameId(allocation.contraOwnaccount?.id || allocation.contraOwnaccount, account.id)) + .map((allocation) => -Number(allocation.amount || 0)) + + const bookings = [...debitBookings, ...creditBookings] if (bookings.length === 0) { return null } - const income = bookings.reduce((sum, booking) => { - const amount = Number(booking.amount || 0) + const income = bookings.reduce((sum, amount) => { return amount > 0 ? sum + amount : sum }, 0) - const expenses = bookings.reduce((sum, booking) => { - const amount = Number(booking.amount || 0) + const expenses = bookings.reduce((sum, amount) => { return amount < 0 ? sum + Math.abs(amount) : sum }, 0) - const balance = bookings.reduce((sum, booking) => sum + Number(booking.amount || 0), 0) + const balance = bookings.reduce((sum, amount) => sum + amount, 0) return { id: account.id,