mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
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:
26
lib/stats.ts
26
lib/stats.ts
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user