Fix BWA Calc

This commit is contained in:
2026-04-08 18:52:16 +02:00
parent f125617af0
commit 02b5769049
5 changed files with 53 additions and 38 deletions

View File

@@ -7,7 +7,6 @@ import {
import {
getIncomingInvoiceDepreciationRows,
getIncomingInvoiceImmediateExpenseNet,
getStatementAllocationDepreciationRow,
getStatementAllocationImmediateExpenseAmount
} from "~/composables/useDepreciation"
@@ -79,9 +78,9 @@ const loadSummary = async () => {
const statementDate = allocation?.bankstatement?.date || allocation?.bankstatement?.valueDate || allocation?.date || allocation?.created_at
const date = dayjs(statementDate)
const amount = Number(allocation?.amount || 0)
const amount = getStatementAllocationImmediateExpenseAmount(allocation)
return amount < 0 && date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day")
return amount > 0 && date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day")
})
const income = outputDocs.reduce((sum: number, doc: any) => {
@@ -103,12 +102,11 @@ const loadSummary = async () => {
}, 0)
const directAccountExpenses = directExpenses.reduce((sum: number, allocation: any) => {
return sum + getStatementAllocationImmediateExpenseAmount(allocation)
return sum + Number(getStatementAllocationImmediateExpenseAmount(allocation) || 0)
}, 0)
const depreciationRows = [
...inputDocs.flatMap((invoice: any) => getIncomingInvoiceDepreciationRows(invoice, bounds.start, bounds.end)),
...(allocations || []).map((allocation: any) => getStatementAllocationDepreciationRow(allocation, bounds.start, bounds.end)).filter(Boolean)
...inputDocs.flatMap((invoice: any) => getIncomingInvoiceDepreciationRows(invoice, bounds.start, bounds.end))
]
const depreciations = depreciationRows.reduce((sum: number, row: any) => sum + Number(row.amount || 0), 0)

View File

@@ -2,6 +2,10 @@
import customParseFormat from "dayjs/plugin/customParseFormat";
import dayjs from "dayjs";
import { Line } from "vue-chartjs";
import {
getIncomingInvoiceImmediateExpenseGross,
getIncomingInvoiceImmediateExpenseNet
} from "~/composables/useDepreciation";
dayjs.extend(customParseFormat)
@@ -84,7 +88,7 @@ const loadData = async () => {
])
incomeDocuments.value = (docs || []).filter((item) => item.state === "Gebucht" && ["invoices", "advanceInvoices", "cancellationInvoices"].includes(item.type))
expenseInvoices.value = (incoming || []).filter((item) => item.date)
expenseInvoices.value = (incoming || []).filter((item) => item.state === "Gebucht" && item.date)
}
const yearsInData = computed(() => {
@@ -128,18 +132,9 @@ const computeDocumentAmount = (doc) => {
}
const computeIncomingInvoiceAmount = (invoice) => {
let amount = 0
;(invoice.accounts || []).forEach((account) => {
const net = Number(account.amountNet || 0)
const tax = Number(account.amountTax || 0)
const grossValue = Number(account.amountGross)
const gross = Number.isFinite(grossValue) ? grossValue : (net + tax)
amount += amountMode.value === "gross" ? gross : net
})
return Number(amount.toFixed(2))
return amountMode.value === "gross"
? getIncomingInvoiceImmediateExpenseGross(invoice)
: getIncomingInvoiceImmediateExpenseNet(invoice)
}
const buckets = computed(() => {