feat(banking): add cost centres and VAT to account allocations

This commit is contained in:
2026-09-23 18:08:09 +02:00
parent 847a616285
commit cbec5b058d
21 changed files with 517 additions and 42 deletions

View File

@@ -1,5 +1,6 @@
<script setup>
import dayjs from "dayjs"
import { getBankAllocationAmounts, isDirectBankAllocation } from "~/utils/bankAllocationTax"
const props = defineProps({
item: {
@@ -12,6 +13,8 @@ const loading = ref(true)
const incomingInvoices = ref([])
const createddocuments = ref([])
const costcentres = ref([])
const bankAllocations = ref([])
const accounts = ref([])
const selectedYear = ref(String(dayjs().year()))
const selectedMonth = ref("all")
@@ -74,8 +77,10 @@ const relevantCostCentreIds = computed(() => {
const yearItems = computed(() => {
const years = [...new Set(
incomingInvoices.value
.map((invoice) => invoice.date ? String(dayjs(invoice.date).year()) : null)
[...incomingInvoices.value.map(invoice => invoice.date),
...createddocuments.value.map(document => document.documentDate),
...bankAllocations.value.map(allocation => allocation.bankstatement?.date)]
.map((date) => date ? String(dayjs(date).year()) : null)
.filter(Boolean)
)].sort((a, b) => Number(b) - Number(a))
@@ -183,7 +188,33 @@ const reportRows = computed(() => {
.filter(Boolean)
})
return [...incomingRows, ...outgoingRows]
const bankRows = bankAllocations.value.flatMap((allocation) => {
const statement = allocation.bankstatement
const date = dayjs(statement.date || statement.valueDate)
if (!date.isValid() || String(date.year()) !== selectedYear.value
|| (selectedMonth.value !== "all" && date.month() + 1 !== Number(selectedMonth.value))) return []
const centre = costCentreMap.value.get(getCostCentreId(allocation.costcentre))
const account = accounts.value.find(account => account.id === (allocation.account?.id || allocation.account)) || allocation.ownaccount
const amounts = getBankAllocationAmounts(allocation)
// As for incoming documents, expenses are positive and refunds negative.
const sign = amounts.kind === "input" || (amounts.kind === "none" && amounts.amountGross < 0) ? -1 : 1
return [{
id: `bank-${allocation.id}`,
sourceLabel: "Bankbuchung",
statementId: statement.id,
reference: `Bank #${statement.id}`,
date: statement.date || statement.valueDate,
state: "Gebucht",
vendorName: statement.debName || statement.credName || "-",
accountLabel: `${account?.number || ""} ${account?.label || account?.name || ""}`.trim() || "-",
costCentreName: centre ? `${centre.number} - ${centre.name}` : "-",
description: allocation.description || statement.text || "-",
amountNet: amounts.amountNet * sign,
amountTax: amounts.amountTax * sign,
amountGross: amounts.amountGross * sign,
}]
})
return [...incomingRows, ...outgoingRows, ...bankRows]
})
const totals = computed(() => {
@@ -212,8 +243,12 @@ const setupPage = async () => {
loading.value = true
costcentres.value = await useEntities("costcentres").select("*", null, false, true)
accounts.value = await useEntities("accounts").selectSpecial()
const invoices = await useEntities("incominginvoices").select("*, vendor(id,name)")
const documents = await useEntities("createddocuments").select("*, customer(id,name)")
const allocations = await useEntities("statementallocations").select("*, bankstatement(*), account(*), ownaccount(*)")
bankAllocations.value = allocations.filter(allocation => isDirectBankAllocation(allocation)
&& relevantCostCentreIds.value.has(getCostCentreId(allocation.costcentre)))
incomingInvoices.value = invoices.filter((invoice) =>
(invoice.accounts || []).some((account) => relevantCostCentreIds.value.has(account.costCentre))
@@ -283,7 +318,10 @@ setupPage()
class="w-full"
>
<template #reference-cell="{ row }">
<div class="truncate font-medium">{{ row.original.reference }}</div>
<NuxtLink v-if="row.original.statementId" :to="`/banking/statements/show/${row.original.statementId}`" class="font-medium text-primary">
{{ row.original.reference }}
</NuxtLink>
<div v-else class="truncate font-medium">{{ row.original.reference }}</div>
</template>
<template #date-cell="{ row }">

View File

@@ -1,5 +1,6 @@
<script setup lang="ts">
import dayjs from "dayjs"
import { getBankAllocationTaxBreakdown } from "~/utils/bankAllocationTax"
import {
getCreatedDocumentTaxBreakdown,
getIncomingInvoiceTaxBreakdown
@@ -125,6 +126,12 @@ const loadSummary = async () => {
return sum + breakdown.tax19 + breakdown.tax7
}, 0)
const bankTaxBalance = (allocations || []).reduce((sum: number, allocation: any) => {
const date = dayjs(allocation.bankstatement?.date || allocation.bankstatement?.valueDate)
if (!date.isValid() || date.isBefore(bounds.start, "day") || date.isAfter(bounds.end, "day")) return sum
const { output, input } = getBankAllocationTaxBreakdown(allocation)
return sum + output.tax19 + output.tax7 - input.tax19 - input.tax7
}, 0)
const expenses = invoiceExpenses + directAccountExpenses + depreciations
summary.value = {
@@ -133,7 +140,7 @@ const loadSummary = async () => {
expenses: Number(expenses.toFixed(2)),
depreciations: Number(depreciations.toFixed(2)),
result: Number((income - Math.abs(expenses)).toFixed(2)),
taxBalance: Number((outputTax - inputTax).toFixed(2)),
taxBalance: Number((outputTax - inputTax + bankTaxBalance).toFixed(2)),
incomeCount: outputDocs.length,
expenseCount: inputDocs.filter((invoice: any) => getIncomingInvoiceImmediateExpenseNet(invoice) > 0).length + directAccountAllocations.filter((allocation: any) => getStatementAllocationImmediateExpenseAmount(allocation) > 0).length,
depreciationCount: depreciationRows.length