Unterkostenstellen in der Kostenstellenauswertung korrekt auflösen

This commit is contained in:
2026-04-24 23:03:23 +02:00
parent d3ab03da7e
commit bb61caed6d

View File

@@ -16,6 +16,14 @@ const selectedMonth = ref("all")
const currency = (value) => `${Number(value || 0).toFixed(2).replace(".", ",")} EUR`
const getCostCentreId = (value) => {
if (!value) {
return null
}
return typeof value === "object" ? value.id : value
}
const costCentreMap = computed(() => {
return new Map(costcentres.value.map((costcentre) => [costcentre.id, costcentre]))
})
@@ -30,15 +38,17 @@ const relevantCostCentreIds = computed(() => {
const childrenByParent = new Map()
costcentres.value.forEach((costcentre) => {
if (!costcentre.parentCostcentre) {
const parentId = getCostCentreId(costcentre.parentCostcentre)
if (!parentId) {
return
}
if (!childrenByParent.has(costcentre.parentCostcentre)) {
childrenByParent.set(costcentre.parentCostcentre, [])
if (!childrenByParent.has(parentId)) {
childrenByParent.set(parentId, [])
}
childrenByParent.get(costcentre.parentCostcentre).push(costcentre.id)
childrenByParent.get(parentId).push(costcentre.id)
})
const collectedIds = new Set([rootId])
@@ -107,7 +117,7 @@ const reportRows = computed(() => {
const amountNet = Number(account.amountNet || 0)
const amountTax = Number(account.amountTax || 0)
const amountGross = Number(account.amountGross || amountNet + amountTax || 0)
const accountCostCentre = costCentreMap.value.get(account.costCentre)
const accountCostCentre = costCentreMap.value.get(getCostCentreId(account.costCentre))
return {
id: `${invoice.id}-${index}`,