Skip to content

Commit

Permalink
Don’t count reimbursements in stats (fixes #118) (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
scastiel committed Feb 29, 2024
1 parent b227401 commit 5529531
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/totals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand All @@ -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,
)
}
Expand All @@ -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,
Expand Down

0 comments on commit 5529531

Please sign in to comment.