Skip to content

Commit

Permalink
Fixed Loan Increase Main Transaction Issue (Ivy-Apps#3014)
Browse files Browse the repository at this point in the history
* [IVY-2981] Fixed LoanIncrease Main Transaction Issue

* [IVY-2981] Fixed Create Transaction Failure From LoanRecord

* [IVY-2981] Refactor
  • Loading branch information
Vishwa-Raghavendra authored Mar 9, 2024
1 parent 2e911b0 commit 8f06eeb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ivy.wallet.domain.deprecated.logic.loantrasactions

import com.ivy.base.legacy.Transaction
import com.ivy.base.model.LoanRecordType
import com.ivy.base.model.TransactionType
import com.ivy.data.model.LoanType
import com.ivy.legacy.datamodel.Account
Expand Down Expand Up @@ -30,6 +31,7 @@ class LTLoanMapper @Inject constructor(
selectedAccountId = data.account?.id,
title = data.name,
isLoanRecord = false,
loanRecordType = LoanRecordType.DECREASE
)
}
}
Expand All @@ -49,7 +51,8 @@ class LTLoanMapper @Inject constructor(
title = loan.name,
isLoanRecord = false,
transaction = transaction,
time = transaction?.dateTime
time = transaction?.dateTime,
loanRecordType = LoanRecordType.DECREASE
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class LTLoanRecordMapper @Inject constructor(
title = loanRecord.note,
time = loanRecord.dateTime,
isLoanRecord = true,
transaction = transaction
transaction = transaction,
loanRecordType = loanRecord.loanRecordType
)
}
}
Expand All @@ -51,6 +52,7 @@ class LTLoanRecordMapper @Inject constructor(
loanId = loan.id,
selectedAccountId = data.account?.id,
isLoanRecord = true,
loanRecordType = data.loanRecordType
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ivy.legacy.domain.deprecated.logic.loantrasactions
import androidx.compose.ui.graphics.toArgb
import com.ivy.base.legacy.Transaction
import com.ivy.base.legacy.stringRes
import com.ivy.base.model.LoanRecordType
import com.ivy.base.model.TransactionType
import com.ivy.data.db.dao.read.AccountDao
import com.ivy.data.db.dao.read.LoanDao
Expand Down Expand Up @@ -114,6 +115,7 @@ class LoanTransactionsCore @Inject constructor(
time: LocalDateTime? = null,
isLoanRecord: Boolean = false,
transaction: Transaction? = null,
loanRecordType: LoanRecordType
) {
if (isLoanRecord && loanRecordId == null) {
return
Expand All @@ -130,7 +132,8 @@ class LoanTransactionsCore @Inject constructor(
categoryId = category?.id?.value ?: transaction.categoryId,
time = time ?: transaction.dateTime ?: timeNowUTC(),
isLoanRecord = isLoanRecord,
transaction = transaction
transaction = transaction,
loanRecordType = loanRecordType
)
} else if (createTransaction && transaction == null) {
createMainTransaction(
Expand All @@ -143,7 +146,8 @@ class LoanTransactionsCore @Inject constructor(
categoryId = category?.id?.value,
time = time ?: timeNowUTC(),
isLoanRecord = isLoanRecord,
transaction = transaction
transaction = transaction,
loanRecordType = loanRecordType
)
} else {
deleteTransaction(transaction = transaction)
Expand All @@ -160,13 +164,14 @@ class LoanTransactionsCore @Inject constructor(
categoryId: UUID? = null,
time: LocalDateTime = timeNowUTC(),
isLoanRecord: Boolean = false,
transaction: Transaction? = null
transaction: Transaction? = null,
loanRecordType: LoanRecordType
) {
if (selectedAccountId == null) {
return
}

val transType = if (isLoanRecord) {
val transType = if (isLoanRecord && loanRecordType != LoanRecordType.INCREASE) {
if (loanType == LoanType.BORROW) TransactionType.EXPENSE else TransactionType.INCOME
} else if (loanType == LoanType.BORROW) TransactionType.INCOME else TransactionType.EXPENSE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ivy.base.model.LoanRecordType
import com.ivy.data.model.primitive.NotBlankTrimmedString
import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.design.utils.thenIf
Expand Down Expand Up @@ -393,7 +394,7 @@ private fun save(
) {
if (loanRecord != null) {
val record = loanRecord.copy(
note = noteTextFieldValue.text.trim(),
note = NotBlankTrimmedString.from(noteTextFieldValue.text).getOrNull()?.value,
amount = amount,
dateTime = dateTime,
interest = loanRecordInterest,
Expand All @@ -411,7 +412,7 @@ private fun save(
} else {
onCreate(
CreateLoanRecordData(
note = noteTextFieldValue.text.trim(),
note = NotBlankTrimmedString.from(noteTextFieldValue.text).getOrNull()?.value,
amount = amount,
dateTime = dateTime,
interest = loanRecordInterest,
Expand Down

0 comments on commit 8f06eeb

Please sign in to comment.