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

@@ -16,7 +16,8 @@ const loading = ref(true)
const saving = ref(false)
const incomingInvoices = ref<any[]>([])
const statementAllocations = ref<any[]>([])
const asOfDate = ref(dayjs().format("YYYY-MM-DD"))
const periodStart = ref(dayjs().startOf("month").format("YYYY-MM-DD"))
const periodEnd = ref(dayjs().endOf("month").format("YYYY-MM-DD"))
const selectedAsset = ref<any | null>(null)
const editState = ref<any | null>(null)
const editOpen = computed({
@@ -32,6 +33,22 @@ const formatCurrency = (value: number) => new Intl.NumberFormat("de-DE", {
}).format(Number(value || 0))
const isRelevantInputInvoice = (invoice: any) => invoice?.state === "Gebucht" && !!invoice?.date
const normalizedPeriod = computed(() => {
const start = dayjs(periodStart.value)
const end = dayjs(periodEnd.value)
if (start.isValid() && end.isValid() && start.isAfter(end, "day")) {
return {
start: end.startOf("day"),
end: start.endOf("day"),
}
}
return {
start: start.isValid() ? start.startOf("day") : dayjs().startOf("month"),
end: end.isValid() ? end.endOf("day") : dayjs().endOf("month"),
}
})
const loadData = async () => {
loading.value = true
@@ -62,9 +79,9 @@ const depreciationAssets = computed(() => {
depreciationStartDate: normalized.depreciationStartDate || invoice.date,
depreciationMethod: normalized.depreciationMethod,
residualValue: normalized.residualValue,
}, asOfDate.value)
}, normalizedPeriod.value.end)
const currentPeriodRow = getIncomingInvoiceDepreciationRows(invoice, dayjs(asOfDate.value).startOf("month"), dayjs(asOfDate.value).endOf("month"))
const currentPeriodRow = getIncomingInvoiceDepreciationRows(invoice, normalizedPeriod.value.start, normalizedPeriod.value.end)
.find((row: any) => row.index === index)
return {
@@ -102,9 +119,9 @@ const depreciationAssets = computed(() => {
depreciationStartDate: allocation.depreciationStartDate || allocation.created_at,
depreciationMethod: allocation.depreciationMethod,
residualValue: allocation.residualValue,
}, asOfDate.value)
}, normalizedPeriod.value.end)
const currentPeriodRow = getStatementAllocationDepreciationRow(allocation, dayjs(asOfDate.value).startOf("month"), dayjs(asOfDate.value).endOf("month"))
const currentPeriodRow = getStatementAllocationDepreciationRow(allocation, normalizedPeriod.value.start, normalizedPeriod.value.end)
return {
key: `allocation-${allocation.id}`,
@@ -260,7 +277,8 @@ onMounted(loadData)
<UDashboardNavbar title="Abschreibungen">
<template #right>
<div class="flex items-center gap-2">
<UInput v-model="asOfDate" type="date" class="w-44" />
<UInput v-model="periodStart" type="date" class="w-44" />
<UInput v-model="periodEnd" type="date" class="w-44" />
<UButton icon="i-heroicons-arrow-path" variant="outline" :loading="loading" @click="loadData">
Aktualisieren
</UButton>
@@ -278,7 +296,7 @@ onMounted(loadData)
<UCard>
<div class="text-sm text-gray-500 dark:text-gray-400">Bereits abgeschrieben</div>
<div class="mt-2 text-2xl font-semibold text-primary-600 dark:text-primary-400">{{ formatCurrency(totals.depreciated) }}</div>
<div class="mt-2 text-sm text-gray-500 dark:text-gray-400">Stand {{ dayjs(asOfDate).format("DD.MM.YYYY") }}</div>
<div class="mt-2 text-sm text-gray-500 dark:text-gray-400">Stand {{ normalizedPeriod.end.format("DD.MM.YYYY") }}</div>
</UCard>
<UCard>
<div class="text-sm text-gray-500 dark:text-gray-400">Restbuchwert</div>
@@ -286,9 +304,9 @@ onMounted(loadData)
<div class="mt-2 text-sm text-gray-500 dark:text-gray-400">Nach Restwertlogik</div>
</UCard>
<UCard>
<div class="text-sm text-gray-500 dark:text-gray-400">Aktuelle Abschreibung</div>
<div class="text-sm text-gray-500 dark:text-gray-400">Abschreibung im Zeitraum</div>
<div class="mt-2 text-2xl font-semibold text-error">{{ formatCurrency(totals.currentPeriodAmount) }}</div>
<div class="mt-2 text-sm text-gray-500 dark:text-gray-400">{{ totals.bundleCount }} Sammelposten</div>
<div class="mt-2 text-sm text-gray-500 dark:text-gray-400">{{ normalizedPeriod.start.format("DD.MM.YYYY") }} - {{ normalizedPeriod.end.format("DD.MM.YYYY") }}</div>
</UCard>
</div>
@@ -351,7 +369,7 @@ onMounted(loadData)
<div class="mt-1 font-semibold text-primary-600 dark:text-primary-400">{{ formatCurrency(asset.depreciated) }}</div>
</div>
<div>
<div class="text-xs text-gray-500 dark:text-gray-400">Aktueller Zeitraum</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Im Zeitraum</div>
<div class="mt-1 font-semibold text-error">{{ formatCurrency(asset.currentPeriodAmount) }}</div>
</div>
<div>