diff --git a/frontend/components/displayBWASummary.vue b/frontend/components/displayBWASummary.vue index 0acf563..4d01b8a 100644 --- a/frontend/components/displayBWASummary.vue +++ b/frontend/components/displayBWASummary.vue @@ -7,7 +7,8 @@ import { import { getIncomingInvoiceDepreciationRows, getIncomingInvoiceImmediateExpenseNet, - getStatementAllocationImmediateExpenseAmount + getStatementAllocationImmediateExpenseAmount, + getStatementAllocationImmediateExpenseImpact } from "~/composables/useDepreciation" const loading = ref(true) @@ -72,16 +73,12 @@ const loadSummary = async () => { return date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day") }) - const directExpenses = (allocations || []).filter((allocation: any) => { - if (allocation?.account === null || typeof allocation?.account === "undefined") { - return false - } - + const directAccountAllocations = (allocations || []).filter((allocation: any) => { const statementDate = allocation?.bankstatement?.date || allocation?.bankstatement?.valueDate || allocation?.date || allocation?.created_at const date = dayjs(statementDate) - const amount = getStatementAllocationImmediateExpenseAmount(allocation) + const impact = getStatementAllocationImmediateExpenseImpact(allocation) - return amount > 0 && date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day") + return impact !== 0 && date.isValid() && !date.isBefore(bounds.start, "day") && !date.isAfter(bounds.end, "day") }) const income = outputDocs.reduce((sum: number, doc: any) => { @@ -102,8 +99,8 @@ const loadSummary = async () => { return sum + getIncomingInvoiceImmediateExpenseNet(invoice) }, 0) - const directAccountExpenses = directExpenses.reduce((sum: number, allocation: any) => { - return sum + Number(getStatementAllocationImmediateExpenseAmount(allocation) || 0) + const directAccountExpenses = directAccountAllocations.reduce((sum: number, allocation: any) => { + return sum + Number(getStatementAllocationImmediateExpenseImpact(allocation) || 0) }, 0) const depreciationRows = [ @@ -132,7 +129,7 @@ const loadSummary = async () => { result: Number((income - expenses).toFixed(2)), taxBalance: Number((outputTax - inputTax).toFixed(2)), incomeCount: outputDocs.length, - expenseCount: inputDocs.filter((invoice: any) => getIncomingInvoiceImmediateExpenseNet(invoice) > 0).length + directExpenses.filter((allocation: any) => getStatementAllocationImmediateExpenseAmount(allocation) > 0).length, + expenseCount: inputDocs.filter((invoice: any) => getIncomingInvoiceImmediateExpenseNet(invoice) > 0).length + directAccountAllocations.filter((allocation: any) => getStatementAllocationImmediateExpenseAmount(allocation) > 0).length, depreciationCount: depreciationRows.length } } finally { diff --git a/frontend/composables/useDepreciation.ts b/frontend/composables/useDepreciation.ts index 538392e..60b1a1d 100644 --- a/frontend/composables/useDepreciation.ts +++ b/frontend/composables/useDepreciation.ts @@ -301,14 +301,20 @@ export const getIncomingInvoiceDepreciationRows = (invoice: any, rangeStart: any .filter(Boolean) } -export const getStatementAllocationImmediateExpenseAmount = (allocation: any) => { +export const getStatementAllocationImmediateExpenseImpact = (allocation: any) => { const hasLinkedDocument = allocation?.incominginvoice || allocation?.createddocument || allocation?.ii_id || allocation?.cd_id if (hasLinkedDocument) return 0 + if (allocation?.account === null || allocation?.account === undefined) return 0 + const mode = normalizeExpenseBookingMode(allocation?.bookingMode) const amount = Number(allocation?.amount || 0) - if (mode !== "expense" || amount >= 0) return 0 - return Number(Math.abs(amount).toFixed(2)) + if (mode !== "expense") return 0 + return Number((-amount).toFixed(2)) +} + +export const getStatementAllocationImmediateExpenseAmount = (allocation: any) => { + return Math.max(0, getStatementAllocationImmediateExpenseImpact(allocation)) } export const getStatementAllocationDepreciationAmount = (allocation: any, rangeStart: any, rangeEnd: any) => { diff --git a/frontend/pages/accounting/bwa.vue b/frontend/pages/accounting/bwa.vue index 1ebed96..29512a7 100644 --- a/frontend/pages/accounting/bwa.vue +++ b/frontend/pages/accounting/bwa.vue @@ -10,7 +10,8 @@ import { getIncomingInvoiceImmediateExpenseNet, isDepreciationBookingMode, normalizeIncomingInvoiceAccount, - getStatementAllocationImmediateExpenseAmount + getStatementAllocationImmediateExpenseAmount, + getStatementAllocationImmediateExpenseImpact } from "~/composables/useDepreciation" const router = useRouter() @@ -190,8 +191,8 @@ const expenseNetTotal = computed(() => { return sum + getIncomingInvoiceImmediateExpenseNet(invoice) }, 0) - const directAccountExpenses = filteredAccountStatementAllocations.value.reduce((sum, allocation) => { - return sum + Number(getStatementAllocationImmediateExpenseAmount(allocation) || 0) + const directAccountExpenses = filteredStatementAllocations.value.reduce((sum, allocation) => { + return sum + Number(getStatementAllocationImmediateExpenseImpact(allocation) || 0) }, 0) const depreciations = depreciationTotal.value @@ -202,8 +203,8 @@ const expenseNetTotal = computed(() => { const expenseGrossTotal = computed(() => { const invoiceExpenses = filteredIncomingInvoices.value.reduce((sum, invoice) => sum + getIncomingInvoiceImmediateExpenseGross(invoice), 0) - const directAccountExpenses = filteredAccountStatementAllocations.value.reduce((sum, allocation) => { - return sum + Number(getStatementAllocationImmediateExpenseAmount(allocation) || 0) + const directAccountExpenses = filteredStatementAllocations.value.reduce((sum, allocation) => { + return sum + Number(getStatementAllocationImmediateExpenseImpact(allocation) || 0) }, 0) const depreciations = depreciationTotal.value