feat: display both net total and turnover in transactions footer (#53)

- Add calcNetTotalPerCurrency function to calculate signed totals (income positive, expenses negative)
- Update transaction list footer to display both net total and turnover
- Use semantic HTML markup (<dl>, <dt>, <dd>) for better accessibility
- Add color coding: green for positive net, red for negative net
- Maintain turnover calculation for total transaction volume

Fixes issue where transaction totals did not respect transaction type (income/expense)
This commit is contained in:
Artem Sushchev
2025-10-22 09:28:19 +02:00
committed by GitHub
parent 07e05aabe7
commit 3223d5026b
2 changed files with 50 additions and 8 deletions

View File

@@ -16,6 +16,32 @@ export function calcTotalPerCurrency(transactions: Transaction[]): Record<string
)
}
export function calcNetTotalPerCurrency(transactions: Transaction[]): Record<string, number> {
return transactions.reduce(
(acc, transaction) => {
let amount = 0
let currency: string | undefined
if (
transaction.convertedTotal !== null &&
transaction.convertedTotal !== undefined &&
transaction.convertedCurrencyCode
) {
amount = transaction.convertedTotal
currency = transaction.convertedCurrencyCode.toUpperCase()
} else if (transaction.total !== null && transaction.total !== undefined && transaction.currencyCode) {
amount = transaction.total
currency = transaction.currencyCode.toUpperCase()
}
if (currency && amount !== 0) {
const sign = transaction.type === "expense" ? -1 : 1
acc[currency] = (acc[currency] || 0) + amount * sign
}
return acc
},
{} as Record<string, number>
)
}
export const isTransactionIncomplete = (fields: Field[], transaction: Transaction): boolean => {
const incompleteFields = incompleteTransactionFields(fields, transaction)