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

Commit

Permalink
Make the project builds! (certainly it's unstable)
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 24, 2022
1 parent 2939358 commit 5c3abc4
Show file tree
Hide file tree
Showing 38 changed files with 280 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class Transaction(
val type: TransactionType,
val amount: BigDecimal,
val toAccountId: UUID? = null,
val toAmount: BigDecimal,
val toAmount: BigDecimal = amount,
val title: String? = null,
val description: String? = null,
val dateTime: LocalDateTime? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ class PlannedPaymentsGenerator(
accountId = rule.accountId,
recurringRuleId = rule.id,
categoryId = rule.categoryId,
amount = rule.amount,
amount = rule.amount.toBigDecimal(),
title = rule.title,
description = rule.description,
dueDate = dueDate,
dateTime = null,
toAccountId = null,

isSynced = false
)
).toEntity()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.PlannedPaymentRule
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.logic.currency.sumByDoublePlannedInBaseCurrency
import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader
import com.ivy.wallet.domain.sync.uploader.TransactionUploader
import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.deprecated.logic.currency.sumByDoublePlannedInBaseCurrency
import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader
import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader
import com.ivy.wallet.io.persistence.dao.AccountDao
import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao
import com.ivy.wallet.io.persistence.dao.SettingsDao
Expand Down Expand Up @@ -40,9 +40,9 @@ class PlannedPaymentsLogic(
endDate = range.to()
).sumOf {
val amount = exchangeRatesLogic.amountBaseCurrency(
transaction = it,
transaction = it.toDomain(),
baseCurrency = baseCurrency,
accounts = accounts
accounts = accounts.map { it.toDomain() }
)

when (it.type) {
Expand All @@ -54,7 +54,7 @@ class PlannedPaymentsLogic(
}

fun oneTime(): List<PlannedPaymentRule> {
return plannedPaymentRuleDao.findAllByOneTime(oneTime = true)
return plannedPaymentRuleDao.findAllByOneTime(oneTime = true).map { it.toDomain() }
}

fun oneTimeIncome(): Double {
Expand All @@ -78,7 +78,7 @@ class PlannedPaymentsLogic(
}

fun recurring(): List<PlannedPaymentRule> =
plannedPaymentRuleDao.findAllByOneTime(oneTime = false)
plannedPaymentRuleDao.findAllByOneTime(oneTime = false).map { it.toDomain() }

fun recurringIncome(): Double {
return recurring()
Expand All @@ -100,7 +100,7 @@ class PlannedPaymentsLogic(
amountForMonthInBaseCurrency(
plannedPayment = it,
baseCurrency = baseCurrency,
accounts = accounts
accounts = accounts.map { it.toDomain() }
)
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class PlannedPaymentsLogic(
}

ioThread {
transactionDao.save(paidTransaction)
transactionDao.save(paidTransaction.toEntity())

if (plannedPaymentRule != null && plannedPaymentRule.oneTime) {
//delete paid oneTime planned payment rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.ivy.wallet.domain.deprecated.logic
import androidx.compose.ui.graphics.toArgb
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.logic.model.CreateAccountData
import com.ivy.wallet.domain.logic.model.CreateCategoryData
import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData
import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData
import com.ivy.wallet.io.persistence.dao.AccountDao
import com.ivy.wallet.io.persistence.dao.CategoryDao
import com.ivy.wallet.ui.onboarding.model.AccountBalance
Expand Down Expand Up @@ -41,8 +41,8 @@ class PreloadDataLogic(
isSynced = false
)

accountsDao.save(cash)
accountsDao.save(bank)
accountsDao.save(cash.toEntity())
accountsDao.save(bank.toEntity())
}

fun accountSuggestions(baseCurrency: String): List<CreateAccountData> = listOf(
Expand Down Expand Up @@ -152,7 +152,7 @@ class PreloadDataLogic(
isSynced = false
)

categoryDao.save(category)
categoryDao.save(category.toEntity())
}

fun categorySuggestions(): List<CreateCategoryData> = preloadCategoriesCreateData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.ivy.wallet.domain.deprecated.logic

import com.ivy.wallet.R
import com.ivy.wallet.domain.data.TransactionHistoryItem
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.io.persistence.dao.AccountDao
import com.ivy.wallet.io.persistence.dao.SettingsDao
import com.ivy.wallet.io.persistence.dao.TransactionDao
import com.ivy.wallet.stringRes
import com.ivy.wallet.ui.onboarding.model.FromToTimeRange
import com.ivy.wallet.ui.onboarding.model.filterOverdue
import com.ivy.wallet.ui.onboarding.model.filterUpcoming
Expand All @@ -31,7 +28,7 @@ class WalletAccountLogic(
actualBalance: Double = calculateAccountBalance(account),
newBalance: Double,

adjustTransactionTitle: String = stringRes(R.string.adjust_balance),
adjustTransactionTitle: String = "Adjust balance",

isFiat: Boolean? = null,
trnIsSyncedFlag: Boolean = false, //TODO: Remove this once Bank Integration trn sync is properly implemented
Expand Down Expand Up @@ -71,31 +68,6 @@ class WalletAccountLogic(
}
}

fun historyForAccount(account: Account, range: FromToTimeRange): List<TransactionHistoryItem> {
val startDate = range.from()
val endDate = range.to()

return transactionDao
.findAllByAccountAndBetween(
accountId = account.id,
startDate = startDate,
endDate = endDate
)
.plus(
transactionDao.findAllToAccountAndBetween(
toAccountId = account.id,
startDate = startDate,
endDate = endDate
)
)
.sortedByDescending { it.dateTime }
.withDateDividers(
exchangeRatesLogic = exchangeRatesLogic,
accountDao = accountDao,
settingsDao = settingsDao
)
}

fun calculateAccountBalance(
account: Account,
before: LocalDateTime? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency
import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.deprecated.logic.currency.sumInBaseCurrency
import com.ivy.wallet.domain.pure.transaction.withDateDividers
import com.ivy.wallet.io.persistence.dao.AccountDao
import com.ivy.wallet.io.persistence.dao.SettingsDao
import com.ivy.wallet.io.persistence.dao.TransactionDao
import com.ivy.wallet.ui.onboarding.model.FromToTimeRange
import com.ivy.wallet.ui.onboarding.model.filterOverdue
import com.ivy.wallet.ui.onboarding.model.filterUpcoming
import java.util.*

@Deprecated("Migrate to FP Style")
Expand All @@ -27,7 +30,7 @@ class WalletCategoryLogic(
transactions: List<Transaction> = emptyList()
): Double {
val baseCurrency = settingsDao.findFirst().currency
val accounts = accountDao.findAll()
val accounts = accountDao.findAll().map { it.toDomain() }

return historyByCategory(
category,
Expand Down Expand Up @@ -61,7 +64,7 @@ class WalletCategoryLogic(
type = TransactionType.INCOME,
startDate = range.from(),
endDate = range.to()
)
).map { it.toDomain() }
.filter {
accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId)
}
Expand Down Expand Up @@ -101,7 +104,7 @@ class WalletCategoryLogic(
)
.filter {
accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId)
}
}.map { it.toDomain() }
.sumInBaseCurrency(
exchangeRatesLogic = exchangeRatesLogic,
settingsDao = settingsDao,
Expand Down Expand Up @@ -135,7 +138,7 @@ class WalletCategoryLogic(
type = TransactionType.INCOME,
startDate = range.from(),
endDate = range.to()
)
).map { it.toDomain() }
.sumInBaseCurrency(
exchangeRatesLogic = exchangeRatesLogic,
settingsDao = settingsDao,
Expand All @@ -149,27 +152,16 @@ class WalletCategoryLogic(
type = TransactionType.EXPENSE,
startDate = range.from(),
endDate = range.to()
)
).map { it.toDomain() }
.sumInBaseCurrency(
exchangeRatesLogic = exchangeRatesLogic,
settingsDao = settingsDao,
accountDao = accountDao
)
}

fun historyByCategoryWithDateDividers(
category: Category,
range: FromToTimeRange
): List<TransactionHistoryItem> {
return historyByCategory(category, range)
.withDateDividers(
exchangeRatesLogic = exchangeRatesLogic,
settingsDao = settingsDao,
accountDao = accountDao
)
}

fun historyByCategoryAccountWithDateDividers(
suspend fun historyByCategoryAccountWithDateDividers(
category: Category,
range: FromToTimeRange,
accountFilterSet: Set<UUID>,
Expand Down Expand Up @@ -199,20 +191,20 @@ class WalletCategoryLogic(
categoryId = category.id,
startDate = range.from(),
endDate = range.to()
)
).map { it.toDomain() }
}

return trans.filter {
accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId)
}
}

fun historyUnspecified(range: FromToTimeRange): List<TransactionHistoryItem> {
suspend fun historyUnspecified(range: FromToTimeRange): List<TransactionHistoryItem> {
return transactionDao
.findAllUnspecifiedAndBetween(
startDate = range.from(),
endDate = range.to()
)
).map { it.toDomain() }
.withDateDividers(
exchangeRatesLogic = exchangeRatesLogic,
settingsDao = settingsDao,
Expand Down Expand Up @@ -266,14 +258,18 @@ class WalletCategoryLogic(
categoryId = category.id,
startDate = range.upcomingFrom(),
endDate = range.to()
).filterUpcoming()
)
.map { it.toDomain() }
.filterUpcoming()
}

fun upcomingUnspecified(range: FromToTimeRange): List<Transaction> {
return transactionDao.findAllDueToBetweenByCategoryUnspecified(
startDate = range.upcomingFrom(),
endDate = range.to()
).filterUpcoming()
)
.map { it.toDomain() }
.filterUpcoming()
}

fun calculateOverdueIncomeByCategory(category: Category, range: FromToTimeRange): Double {
Expand Down Expand Up @@ -322,14 +318,18 @@ class WalletCategoryLogic(
categoryId = category.id,
startDate = range.from(),
endDate = range.overdueTo()
).filterOverdue()
)
.map { it.toDomain() }
.filterOverdue()
}

fun overdueUnspecified(range: FromToTimeRange): List<Transaction> {
return transactionDao.findAllDueToBetweenByCategoryUnspecified(
startDate = range.from(),
endDate = range.overdueTo()
).filterOverdue()
)
.map { it.toDomain() }
.filterOverdue()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.logic.csv.model.CSVRow
import com.ivy.wallet.domain.logic.csv.model.ImportResult
import com.ivy.wallet.domain.logic.csv.model.RowMapping
import com.ivy.wallet.domain.deprecated.logic.csv.model.CSVRow
import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult
import com.ivy.wallet.domain.deprecated.logic.csv.model.RowMapping
import com.ivy.wallet.io.persistence.dao.AccountDao
import com.ivy.wallet.io.persistence.dao.CategoryDao
import com.ivy.wallet.io.persistence.dao.SettingsDao
Expand Down Expand Up @@ -78,10 +78,10 @@ class CSVImporter(
newCategoryColorIndex = 0
newAccountColorIndex = 0

accounts = accountDao.findAll()
accounts = accountDao.findAll().map { it.toDomain() }
val initialAccountsCount = accounts.size

categories = categoryDao.findAll()
categories = categoryDao.findAll().map { it.toDomain() }
val initialCategoriesCount = categories.size

val baseCurrency = settingsDao.findFirst().currency
Expand Down Expand Up @@ -120,7 +120,7 @@ class CSVImporter(
val progressPercent = if (rowsCount > 0)
index / transactions.size.toDouble() else 0.0
onProgress(0.5 + progressPercent / 2)
transactionDao.save(transaction)
transactionDao.save(transaction.toEntity())
}

return ImportResult(
Expand Down Expand Up @@ -212,10 +212,10 @@ class CSVImporter(
Transaction(
id = id,
type = type,
amount = amount,
amount = amount.toBigDecimal(),
accountId = account.id,
toAccountId = toAccount?.id,
toAmount = toAmount,
toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(),
dateTime = dateTime,
dueDate = dueDate,
categoryId = category?.id,
Expand Down Expand Up @@ -444,8 +444,8 @@ class CSVImporter(
icon = icon,
orderNum = orderNum ?: accountDao.findMaxOrderNum() + 1
)
accountDao.save(newAccount)
accounts = accountDao.findAll()
accountDao.save(newAccount.toEntity())
accounts = accountDao.findAll().map { it.toDomain() }

return newAccount
}
Expand Down Expand Up @@ -493,8 +493,8 @@ class CSVImporter(
icon = icon,
orderNum = orderNum ?: categoryDao.findMaxOrderNum() + 1
)
categoryDao.save(newCategory)
categories = categoryDao.findAll()
categoryDao.save(newCategory.toEntity())
categories = categoryDao.findAll().map { it.toDomain() }

return newCategory
}
Expand Down
Loading

0 comments on commit 5c3abc4

Please sign in to comment.