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)