Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

fix-issue-3438 #3476

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 67 additions & 26 deletions screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,26 @@ class ReportViewModel @Inject constructor(
private suspend fun setFilter(reportFilter: ReportFilter?) {
scopedIOThread { scope ->
if (reportFilter == null) {
// clear filter
filter.value = null
setReportValues(
income = 0.00,
expense = 0.00,
upcomingIncomeExpenseTransferPair = IncomeExpenseTransferPair.zero(),
overDueIncomeExpenseTransferPair = IncomeExpenseTransferPair.zero(),
history = persistentListOf(),
upcomingTransactions = persistentListOf(),
overdueTransactions = persistentListOf(),
accounts = accountsAct(Unit),
reportFilter = filter.value,
accountIdFilters = persistentListOf(),
transactions = persistentListOf(),
balanceValue = 0.00
)
return@scopedIOThread
}

if (!reportFilter.validate()) return@scopedIOThread
val tempAccounts = reportFilter.accounts
val baseCurrency = baseCurrency.value
filter.value = reportFilter
loading.value = true

val transactionsList = filterTransactions(
Expand Down Expand Up @@ -294,33 +305,63 @@ class ReportViewModel @Inject constructor(
)
)

income.doubleValue = tempIncome
expenses.doubleValue = tempExpenses
upcomingExpenses.doubleValue = upcomingIncomeExpense.expense.toDouble()
upcomingIncome.doubleValue = upcomingIncomeExpense.income.toDouble()
overdueIncome.doubleValue = overdueIncomeExpense.income.toDouble()
overdueExpenses.doubleValue = overdueIncomeExpense.expense.toDouble()
history.value = historyWithDateDividers.await().toImmutableList()
upcomingTransactions.value = upcomingTransactionsList.map {
it.toLegacy(transactionMapper)
}.toImmutableList()
overdueTransactions.value = overdue.map {
it.toLegacy(transactionMapper)
}.toImmutableList()
accounts.value = tempAccounts.toImmutableList()
filter.value = reportFilter
setReportValues(
income = tempIncome,
expense = tempExpenses,
upcomingIncomeExpenseTransferPair = upcomingIncomeExpense,
overDueIncomeExpenseTransferPair = overdueIncomeExpense,
history = historyWithDateDividers.await().toImmutableList(),
upcomingTransactions = upcomingTransactionsList.map {
it.toLegacy(transactionMapper)
}.toImmutableList(),
overdueTransactions = overdue.map {
it.toLegacy(transactionMapper)
}.toImmutableList(),
accounts = tempAccounts.toImmutableList(),
reportFilter = reportFilter,
accountIdFilters = accountFilterIdList.await().toImmutableList(),
transactions = transactionsList.map {
it.toLegacy(transactionMapper)
}.toImmutableList(),
balanceValue = tempBalance
)

loading.value = false
accountIdFilters.value = accountFilterIdList.await().toImmutableList()
transactions.value = transactionsList.map {
it.toLegacy(transactionMapper)
}.toImmutableList()
balance.doubleValue = tempBalance
filterOverlayVisible.value = false
showTransfersAsIncExpCheckbox.value =
reportFilter.trnTypes.contains(TransactionType.TRANSFER)
}
}

private fun setReportValues(
income: Double,
expense: Double,
upcomingIncomeExpenseTransferPair: IncomeExpenseTransferPair,
overDueIncomeExpenseTransferPair: IncomeExpenseTransferPair,
history: ImmutableList<TransactionHistoryItem>,
upcomingTransactions: ImmutableList<LegacyTransaction>,
overdueTransactions: ImmutableList<LegacyTransaction>,
accounts: ImmutableList<Account>,
reportFilter: ReportFilter? = null,
accountIdFilters: ImmutableList<UUID>,
transactions: ImmutableList<LegacyTransaction>,
balanceValue: Double
) {
this.income.doubleValue = income
this.expenses.doubleValue = expense
this.upcomingExpenses.doubleValue = upcomingIncomeExpenseTransferPair.expense.toDouble()
this.upcomingIncome.doubleValue = upcomingIncomeExpenseTransferPair.income.toDouble()
this.overdueIncome.doubleValue = overDueIncomeExpenseTransferPair.income.toDouble()
this.overdueExpenses.doubleValue = overDueIncomeExpenseTransferPair.expense.toDouble()
this.history.value = history
this.upcomingTransactions.value = upcomingTransactions
this.overdueTransactions.value = overdueTransactions
this.accounts.value = accounts
this.filter.value = reportFilter
this.accountIdFilters.value = accountIdFilters
this.transactions.value = transactions
this.balance.doubleValue = balanceValue
this.showTransfersAsIncExpCheckbox.value =
reportFilter?.trnTypes?.contains(TransactionType.TRANSFER) ?: false
}

private suspend fun filterTransactions(
baseCurrency: String,
accounts: List<Account>,
Expand Down