From 4efa008040deb0495e2d7b8dce559da5c5426268 Mon Sep 17 00:00:00 2001 From: shamim-emon Date: Thu, 5 Sep 2024 20:07:10 +0600 Subject: [PATCH 1/4] fix-issue-3438 --- .../java/com/ivy/reports/ReportViewModel.kt | 98 ++++++++++++++----- 1 file changed, 74 insertions(+), 24 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..d04059f52c 100644 --- a/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt +++ b/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt @@ -215,7 +215,23 @@ class ReportViewModel @Inject constructor( scopedIOThread { scope -> if (reportFilter == null) { // clear filter - filter.value = null + filter.value = reportFilter + setReportValues( + incomeValue = 0.00, + expenseValue = 0.00, + upcomingIncomeValue = 0.00, + upcomingExpenseValue = 0.00, + overDueIncomeValue = 0.00, + overDueExpenseValue = 0.00, + historyValue = persistentListOf(), + upcomingTransactionsListValue = persistentListOf(), + overdueTransactionsValue =persistentListOf(), + accountsValue = accountsAct(Unit), + reportFilterValue = filter.value, + accountFilterIdListValue = persistentListOf(), + transactionsListValue = persistentListOf(), + balanceValue = 0.00 + ) return@scopedIOThread } @@ -294,33 +310,67 @@ 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( + incomeValue = tempIncome, + expenseValue = tempExpenses, + upcomingIncomeValue = upcomingIncomeExpense.income.toDouble(), + upcomingExpenseValue = upcomingIncomeExpense.expense.toDouble(), + overDueIncomeValue = overdueIncomeExpense.income.toDouble(), + overDueExpenseValue = overdueIncomeExpense.expense.toDouble(), + historyValue = historyWithDateDividers.await().toImmutableList(), + upcomingTransactionsListValue = upcomingTransactionsList.map { + it.toLegacy(transactionMapper) + }.toImmutableList(), + overdueTransactionsValue = overdue.map { + it.toLegacy(transactionMapper) + }.toImmutableList(), + accountsValue = tempAccounts.toImmutableList(), + reportFilterValue = reportFilter, + accountFilterIdListValue = accountFilterIdList.await().toImmutableList(), + transactionsListValue = 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( + incomeValue: Double, + expenseValue: Double, + upcomingIncomeValue: Double, + upcomingExpenseValue: Double, + overDueIncomeValue: Double, + overDueExpenseValue: Double, + historyValue: ImmutableList, + upcomingTransactionsListValue: ImmutableList, + overdueTransactionsValue: ImmutableList, + accountsValue: ImmutableList, + reportFilterValue: ReportFilter? = null, + accountFilterIdListValue: ImmutableList, + transactionsListValue: ImmutableList, + balanceValue: Double + ) { + income.doubleValue = incomeValue + expenses.doubleValue = expenseValue + upcomingExpenses.doubleValue = upcomingExpenseValue + upcomingIncome.doubleValue = upcomingIncomeValue + overdueIncome.doubleValue = overDueIncomeValue + overdueExpenses.doubleValue = overDueExpenseValue + history.value = historyValue + upcomingTransactions.value = upcomingTransactionsListValue + overdueTransactions.value = overdueTransactionsValue + accounts.value = accountsValue + filter.value = reportFilterValue + accountIdFilters.value = accountFilterIdListValue + transactions.value = transactionsListValue + balance.doubleValue = balanceValue + showTransfersAsIncExpCheckbox.value = + reportFilterValue?.trnTypes?.contains(TransactionType.TRANSFER) ?: false + } + private suspend fun filterTransactions( baseCurrency: String, accounts: List, From ffb0ac0238e1cb93be79bd3a2a1228d5ce033e88 Mon Sep 17 00:00:00 2001 From: shamim-emon Date: Thu, 5 Sep 2024 20:50:11 +0600 Subject: [PATCH 2/4] fix-issue-3438 --- screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d04059f52c..595cf649dc 100644 --- a/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt +++ b/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt @@ -225,7 +225,7 @@ class ReportViewModel @Inject constructor( overDueExpenseValue = 0.00, historyValue = persistentListOf(), upcomingTransactionsListValue = persistentListOf(), - overdueTransactionsValue =persistentListOf(), + overdueTransactionsValue = persistentListOf(), accountsValue = accountsAct(Unit), reportFilterValue = filter.value, accountFilterIdListValue = persistentListOf(), From e7233ccbb382c68d0e2efc8f43751abe884733ee Mon Sep 17 00:00:00 2001 From: shamim-emon Date: Thu, 5 Sep 2024 22:12:37 +0600 Subject: [PATCH 3/4] fix-issue-3438 --- .../java/com/ivy/reports/ReportViewModel.kt | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 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 595cf649dc..07401f832b 100644 --- a/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt +++ b/screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt @@ -219,10 +219,8 @@ class ReportViewModel @Inject constructor( setReportValues( incomeValue = 0.00, expenseValue = 0.00, - upcomingIncomeValue = 0.00, - upcomingExpenseValue = 0.00, - overDueIncomeValue = 0.00, - overDueExpenseValue = 0.00, + upcomingIncomeExpenseTransferPair = IncomeExpenseTransferPair.zero(), + overDueIncomeExpenseTransferPair = IncomeExpenseTransferPair.zero(), historyValue = persistentListOf(), upcomingTransactionsListValue = persistentListOf(), overdueTransactionsValue = persistentListOf(), @@ -313,10 +311,8 @@ class ReportViewModel @Inject constructor( setReportValues( incomeValue = tempIncome, expenseValue = tempExpenses, - upcomingIncomeValue = upcomingIncomeExpense.income.toDouble(), - upcomingExpenseValue = upcomingIncomeExpense.expense.toDouble(), - overDueIncomeValue = overdueIncomeExpense.income.toDouble(), - overDueExpenseValue = overdueIncomeExpense.expense.toDouble(), + upcomingIncomeExpenseTransferPair = upcomingIncomeExpense, + overDueIncomeExpenseTransferPair = overdueIncomeExpense, historyValue = historyWithDateDividers.await().toImmutableList(), upcomingTransactionsListValue = upcomingTransactionsList.map { it.toLegacy(transactionMapper) @@ -338,12 +334,10 @@ class ReportViewModel @Inject constructor( } private fun setReportValues( - incomeValue: Double, - expenseValue: Double, - upcomingIncomeValue: Double, - upcomingExpenseValue: Double, - overDueIncomeValue: Double, - overDueExpenseValue: Double, + incomeValue : Double, + expenseValue : Double, + upcomingIncomeExpenseTransferPair: IncomeExpenseTransferPair, + overDueIncomeExpenseTransferPair: IncomeExpenseTransferPair, historyValue: ImmutableList, upcomingTransactionsListValue: ImmutableList, overdueTransactionsValue: ImmutableList, @@ -355,10 +349,10 @@ class ReportViewModel @Inject constructor( ) { income.doubleValue = incomeValue expenses.doubleValue = expenseValue - upcomingExpenses.doubleValue = upcomingExpenseValue - upcomingIncome.doubleValue = upcomingIncomeValue - overdueIncome.doubleValue = overDueIncomeValue - overdueExpenses.doubleValue = overDueExpenseValue + upcomingExpenses.doubleValue = upcomingIncomeExpenseTransferPair.expense.toDouble() + upcomingIncome.doubleValue = upcomingIncomeExpenseTransferPair.income.toDouble() + overdueIncome.doubleValue = overDueIncomeExpenseTransferPair.income.toDouble() + overdueExpenses.doubleValue = overDueIncomeExpenseTransferPair.expense.toDouble() history.value = historyValue upcomingTransactions.value = upcomingTransactionsListValue overdueTransactions.value = overdueTransactionsValue From 9afa998695f2d34000406e099a60e4be1f206fda Mon Sep 17 00:00:00 2001 From: shamim-emon Date: Thu, 5 Sep 2024 22:26:03 +0600 Subject: [PATCH 4/4] fix-issue-3438 --- .../java/com/ivy/reports/ReportViewModel.kt | 89 +++++++++---------- 1 file changed, 43 insertions(+), 46 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 07401f832b..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,20 +214,18 @@ class ReportViewModel @Inject constructor( private suspend fun setFilter(reportFilter: ReportFilter?) { scopedIOThread { scope -> if (reportFilter == null) { - // clear filter - filter.value = reportFilter setReportValues( - incomeValue = 0.00, - expenseValue = 0.00, + income = 0.00, + expense = 0.00, upcomingIncomeExpenseTransferPair = IncomeExpenseTransferPair.zero(), overDueIncomeExpenseTransferPair = IncomeExpenseTransferPair.zero(), - historyValue = persistentListOf(), - upcomingTransactionsListValue = persistentListOf(), - overdueTransactionsValue = persistentListOf(), - accountsValue = accountsAct(Unit), - reportFilterValue = filter.value, - accountFilterIdListValue = persistentListOf(), - transactionsListValue = persistentListOf(), + history = persistentListOf(), + upcomingTransactions = persistentListOf(), + overdueTransactions = persistentListOf(), + accounts = accountsAct(Unit), + reportFilter = filter.value, + accountIdFilters = persistentListOf(), + transactions = persistentListOf(), balanceValue = 0.00 ) return@scopedIOThread @@ -236,7 +234,6 @@ class ReportViewModel @Inject constructor( if (!reportFilter.validate()) return@scopedIOThread val tempAccounts = reportFilter.accounts val baseCurrency = baseCurrency.value - filter.value = reportFilter loading.value = true val transactionsList = filterTransactions( @@ -309,21 +306,21 @@ class ReportViewModel @Inject constructor( ) setReportValues( - incomeValue = tempIncome, - expenseValue = tempExpenses, + income = tempIncome, + expense = tempExpenses, upcomingIncomeExpenseTransferPair = upcomingIncomeExpense, overDueIncomeExpenseTransferPair = overdueIncomeExpense, - historyValue = historyWithDateDividers.await().toImmutableList(), - upcomingTransactionsListValue = upcomingTransactionsList.map { + history = historyWithDateDividers.await().toImmutableList(), + upcomingTransactions = upcomingTransactionsList.map { it.toLegacy(transactionMapper) }.toImmutableList(), - overdueTransactionsValue = overdue.map { + overdueTransactions = overdue.map { it.toLegacy(transactionMapper) }.toImmutableList(), - accountsValue = tempAccounts.toImmutableList(), - reportFilterValue = reportFilter, - accountFilterIdListValue = accountFilterIdList.await().toImmutableList(), - transactionsListValue = transactionsList.map { + accounts = tempAccounts.toImmutableList(), + reportFilter = reportFilter, + accountIdFilters = accountFilterIdList.await().toImmutableList(), + transactions = transactionsList.map { it.toLegacy(transactionMapper) }.toImmutableList(), balanceValue = tempBalance @@ -334,35 +331,35 @@ class ReportViewModel @Inject constructor( } private fun setReportValues( - incomeValue : Double, - expenseValue : Double, + income: Double, + expense: Double, upcomingIncomeExpenseTransferPair: IncomeExpenseTransferPair, overDueIncomeExpenseTransferPair: IncomeExpenseTransferPair, - historyValue: ImmutableList, - upcomingTransactionsListValue: ImmutableList, - overdueTransactionsValue: ImmutableList, - accountsValue: ImmutableList, - reportFilterValue: ReportFilter? = null, - accountFilterIdListValue: ImmutableList, - transactionsListValue: ImmutableList, + history: ImmutableList, + upcomingTransactions: ImmutableList, + overdueTransactions: ImmutableList, + accounts: ImmutableList, + reportFilter: ReportFilter? = null, + accountIdFilters: ImmutableList, + transactions: ImmutableList, balanceValue: Double ) { - income.doubleValue = incomeValue - expenses.doubleValue = expenseValue - upcomingExpenses.doubleValue = upcomingIncomeExpenseTransferPair.expense.toDouble() - upcomingIncome.doubleValue = upcomingIncomeExpenseTransferPair.income.toDouble() - overdueIncome.doubleValue = overDueIncomeExpenseTransferPair.income.toDouble() - overdueExpenses.doubleValue = overDueIncomeExpenseTransferPair.expense.toDouble() - history.value = historyValue - upcomingTransactions.value = upcomingTransactionsListValue - overdueTransactions.value = overdueTransactionsValue - accounts.value = accountsValue - filter.value = reportFilterValue - accountIdFilters.value = accountFilterIdListValue - transactions.value = transactionsListValue - balance.doubleValue = balanceValue - showTransfersAsIncExpCheckbox.value = - reportFilterValue?.trnTypes?.contains(TransactionType.TRANSFER) ?: false + 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(