From 252cbd496d163db2b89a024a429330d2cf0a1fbb Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Mon, 7 Sep 2026 21:04:31 +0200 Subject: [PATCH] KI-AGENT: BWA-Ausgaben nach Kontosaldo berechnen --- frontend/components/displayBWASummary.vue | 20 +++++++++++------- frontend/composables/useDepreciation.ts | 25 +++++++++++++++++++++++ frontend/pages/accounting/bwa.vue | 10 +++------ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/frontend/components/displayBWASummary.vue b/frontend/components/displayBWASummary.vue index 4d01b8a..687ecb2 100644 --- a/frontend/components/displayBWASummary.vue +++ b/frontend/components/displayBWASummary.vue @@ -8,7 +8,7 @@ import { getIncomingInvoiceDepreciationRows, getIncomingInvoiceImmediateExpenseNet, getStatementAllocationImmediateExpenseAmount, - getStatementAllocationImmediateExpenseImpact + getStatementAccountExpenseTotal } from "~/composables/useDepreciation" const loading = ref(true) @@ -74,11 +74,19 @@ const loadSummary = async () => { }) const directAccountAllocations = (allocations || []).filter((allocation: any) => { - const statementDate = allocation?.bankstatement?.date || allocation?.bankstatement?.valueDate || allocation?.date || allocation?.created_at + const statementDate = allocation?.bankstatement?.date + || allocation?.bankstatement?.valueDate + || allocation?.date + || allocation?.manualBookingDate + || allocation?.created_at const date = dayjs(statementDate) - const impact = getStatementAllocationImmediateExpenseImpact(allocation) + const touchesAccount = ( + allocation?.account !== null && allocation?.account !== undefined + ) || ( + allocation?.contraAccount !== null && allocation?.contraAccount !== undefined + ) - return impact !== 0 && date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day") + return touchesAccount && date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day") }) const income = outputDocs.reduce((sum: number, doc: any) => { @@ -99,9 +107,7 @@ const loadSummary = async () => { return sum + getIncomingInvoiceImmediateExpenseNet(invoice) }, 0) - const directAccountExpenses = directAccountAllocations.reduce((sum: number, allocation: any) => { - return sum + Number(getStatementAllocationImmediateExpenseImpact(allocation) || 0) - }, 0) + const directAccountExpenses = getStatementAccountExpenseTotal(directAccountAllocations) const depreciationRows = [ ...inputDocs.flatMap((invoice: any) => getIncomingInvoiceDepreciationRows(invoice, bounds.start, bounds.end)) diff --git a/frontend/composables/useDepreciation.ts b/frontend/composables/useDepreciation.ts index 60b1a1d..bbebd8d 100644 --- a/frontend/composables/useDepreciation.ts +++ b/frontend/composables/useDepreciation.ts @@ -317,6 +317,31 @@ export const getStatementAllocationImmediateExpenseAmount = (allocation: any) => return Math.max(0, getStatementAllocationImmediateExpenseImpact(allocation)) } +export const getStatementAccountExpenseTotal = (allocations: any[] = []) => { + const balances = new Map() + const addAmount = (account: any, amount: number) => { + const id = account?.id || account + if (id === null || id === undefined || id === "") return + + const key = String(id) + balances.set(key, Number(balances.get(key) || 0) + amount) + } + + ;(allocations || []).forEach((allocation) => { + if (normalizeExpenseBookingMode(allocation?.bookingMode) !== "expense") return + + const amount = Number(allocation?.amount || 0) + addAmount(allocation?.account, amount) + addAmount(allocation?.contraAccount, -amount) + }) + + const total = Array.from(balances.values()).reduce((sum, balance) => { + return balance < 0 ? sum + Math.abs(balance) : sum + }, 0) + + return Number(total.toFixed(2)) +} + export const getStatementAllocationDepreciationAmount = (allocation: any, rangeStart: any, rangeEnd: any) => { const mode = normalizeExpenseBookingMode(allocation?.bookingMode) const rawAmount = Number(allocation?.amount || 0) diff --git a/frontend/pages/accounting/bwa.vue b/frontend/pages/accounting/bwa.vue index 29512a7..b0ac327 100644 --- a/frontend/pages/accounting/bwa.vue +++ b/frontend/pages/accounting/bwa.vue @@ -11,7 +11,7 @@ import { isDepreciationBookingMode, normalizeIncomingInvoiceAccount, getStatementAllocationImmediateExpenseAmount, - getStatementAllocationImmediateExpenseImpact + getStatementAccountExpenseTotal } from "~/composables/useDepreciation" const router = useRouter() @@ -191,9 +191,7 @@ const expenseNetTotal = computed(() => { return sum + getIncomingInvoiceImmediateExpenseNet(invoice) }, 0) - const directAccountExpenses = filteredStatementAllocations.value.reduce((sum, allocation) => { - return sum + Number(getStatementAllocationImmediateExpenseImpact(allocation) || 0) - }, 0) + const directAccountExpenses = getStatementAccountExpenseTotal(filteredStatementAllocations.value) const depreciations = depreciationTotal.value @@ -203,9 +201,7 @@ const expenseNetTotal = computed(() => { const expenseGrossTotal = computed(() => { const invoiceExpenses = filteredIncomingInvoices.value.reduce((sum, invoice) => sum + getIncomingInvoiceImmediateExpenseGross(invoice), 0) - const directAccountExpenses = filteredStatementAllocations.value.reduce((sum, allocation) => { - return sum + Number(getStatementAllocationImmediateExpenseImpact(allocation) || 0) - }, 0) + const directAccountExpenses = getStatementAccountExpenseTotal(filteredStatementAllocations.value) const depreciations = depreciationTotal.value