Don’t count reimbursements in stats (fixes #118) (#119)

This commit is contained in:
Sebastien Castiel
2024-02-29 10:21:23 -05:00
committed by GitHub
parent b227401dd6
commit 552953151a

View File

@@ -5,7 +5,7 @@ export function getTotalGroupSpending(
): number {
return expenses.reduce(
(total, expense) =>
!expense.isReimbursement ? total + expense.amount : total + 0,
expense.isReimbursement ? total : total + expense.amount,
0,
)
}
@@ -16,7 +16,9 @@ export function getTotalActiveUserPaidFor(
): number {
return expenses.reduce(
(total, expense) =>
expense.paidBy.id === activeUserId ? total + expense.amount : total + 0,
expense.paidBy.id === activeUserId && !expense.isReimbursement
? total + expense.amount
: total,
0,
)
}
@@ -28,6 +30,8 @@ export function getTotalActiveUserShare(
let total = 0
expenses.forEach((expense) => {
if (expense.isReimbursement) return
const paidFors = expense.paidFor
const userPaidFor = paidFors.find(
(paidFor) => paidFor.participantId === activeUserId,