From 79e457b0a3bfc1776c2e4a926278791cc3d10341 Mon Sep 17 00:00:00 2001 From: Shamim Shahrier Emon Date: Fri, 6 Sep 2024 15:43:28 +0600 Subject: [PATCH] fix-issue-3438 (#3476) * fix-issue-3438 * fix-issue-3438 * fix-issue-3438 * fix-issue-3438 --- .../java/com/ivy/reports/ReportViewModel.kt | 93 +++++++++++++------ 1 file changed, 67 insertions(+), 26 deletions(-) diff --git a/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt b/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt index 6fd9f1ab9e..f57f12669d 100644 --- a/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt +++ b/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt @@ -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( @@ -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, + upcomingTransactions: ImmutableList, + overdueTransactions: ImmutableList, + accounts: ImmutableList, + reportFilter: ReportFilter? = null, + accountIdFilters: ImmutableList, + transactions: ImmutableList, + 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,