Skip to content

Commit

Permalink
Fix expense update issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-amisha-i committed Jan 22, 2025
1 parent f46ca5f commit fa44eb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Splito/UI/Home/Groups/CalculateExpensesFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,21 @@ public func getUpdatedMemberBalanceFor(expense: Expense, group: Groups, updateTy
}

case .Update(let oldExpense):
let oldSplitAmount = oldExpense.getTotalSplitAmountOf(member: member)
let oldSplitAmount = oldExpense.getCalculatedSplitAmountOf(member: member)
let oldTotalSplitAmount = oldExpense.getTotalSplitAmountOf(member: member)
let oldCurrency = oldExpense.currencyCode ?? Currency.defaultCurrency.code

memberBalance[index].balanceByCurrency[oldCurrency]?.balance -= oldSplitAmount

// Update the old date's summary by reversing the old expense values
let groupOldTotalSummary = memberBalance[index].balanceByCurrency[oldCurrency]?.totalSummary ?? []
if let oldSummaryIndex = getLatestSummaryIndex(totalSummary: groupOldTotalSummary,
date: oldExpense.date.dateValue()) {
var oldSummary = groupOldTotalSummary[oldSummaryIndex].summary
oldSummary.groupTotalSpending -= oldExpense.amount
oldSummary.totalPaidAmount -= (oldExpense.paidBy[member] ?? 0)
oldSummary.totalShare -= abs(oldSplitAmount)
oldSummary.totalShare -= abs(oldTotalSplitAmount)
oldSummary.changeInBalance = (oldSummary.totalPaidAmount - oldSummary.totalShare) - oldSummary.receivedAmount + oldSummary.paidAmount

memberBalance[index].balanceByCurrency[oldCurrency]?.balance -= oldSplitAmount
memberBalance[index].balanceByCurrency[oldCurrency]?.totalSummary[oldSummaryIndex].summary = oldSummary
}

Expand Down
1 change: 1 addition & 0 deletions Splito/UI/Home/Groups/Group/GroupHomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class GroupHomeViewModel: BaseViewModel, ObservableObject {
.mapValues { summaries in
summaries.reduce(0) { $0 + $1.summary.totalShare }
}
.filter({ $0.value != 0 })
}

func refetchTransactionsCount() {
Expand Down

0 comments on commit fa44eb4

Please sign in to comment.