mirror of
https://github.com/vas3k/TaxHacker.git
synced 2026-05-06 14:29:09 -05:00
18 lines
671 B
TypeScript
18 lines
671 B
TypeScript
import { Transaction } from "@/prisma/client"
|
|
|
|
export function calcTotalPerCurrency(transactions: Transaction[]): Record<string, number> {
|
|
return transactions.reduce(
|
|
(acc, transaction) => {
|
|
if (transaction.convertedCurrencyCode) {
|
|
acc[transaction.convertedCurrencyCode.toUpperCase()] =
|
|
(acc[transaction.convertedCurrencyCode.toUpperCase()] || 0) + (transaction.convertedTotal || 0)
|
|
} else if (transaction.currencyCode) {
|
|
acc[transaction.currencyCode.toUpperCase()] =
|
|
(acc[transaction.currencyCode.toUpperCase()] || 0) + (transaction.total || 0)
|
|
}
|
|
return acc
|
|
},
|
|
{} as Record<string, number>
|
|
)
|
|
}
|