Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions core/ui/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<string name="savings_account">Savings Account</string>
<string name="available_balance">Client Name</string>
<string name="select_other_payment_account">Select other payment account</string>
<string name="pay_from">Pay from</string>
<string name="available_balance_formatted">Available Balance - %1$s</string>

<string name="feature_savings_filter">Filters</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.zIndex
import mifos_mobile.core.ui.generated.resources.Res
import mifos_mobile.core.ui.generated.resources.available_balance
import mifos_mobile.core.ui.generated.resources.ic_icon_dashboard
import mifos_mobile.core.ui.generated.resources.pay_from
import mifos_mobile.core.ui.generated.resources.savings_account
import mifos_mobile.core.ui.generated.resources.select_other_payment_account
import org.jetbrains.compose.resources.painterResource
Expand All @@ -58,23 +59,21 @@ fun MifosPayFromDropdownUI(
accounts: List<Pair<String, String>>,
onAccountSelected: (String, String) -> Unit,
modifier: Modifier = Modifier,
label: String = stringResource(Res.string.select_other_payment_account),
selectedAccountNo: String = "",
selectedAccountName: String = "",
label: String = stringResource(Res.string.pay_from),
) {
var selectedAccount by rememberSaveable { mutableStateOf("") }
var selectedBalance by rememberSaveable { mutableStateOf("") }
Column {
MifosDropDownPayFromComponent(
accountNumber = selectedAccount,
availableBalance = selectedBalance,
accountNumber = selectedAccountNo,
customerName = selectedAccountName,
modifier = modifier,
label = label,
)
AccountDropdownList(
accounts = accounts,
selectedAccount = selectedAccount,
selectedAccount = selectedAccountNo,
onAccountSelected = { accountNumber, balance ->
selectedAccount = accountNumber
selectedBalance = balance
onAccountSelected(accountNumber, balance)
},
)
Expand All @@ -84,7 +83,7 @@ fun MifosPayFromDropdownUI(
@Composable
fun MifosDropDownPayFromComponent(
accountNumber: String,
availableBalance: String,
customerName: String,
label: String,
modifier: Modifier = Modifier,
) {
Expand Down Expand Up @@ -130,7 +129,7 @@ fun MifosDropDownPayFromComponent(
color = AppColors.customWhite.copy(alpha = 0.5f),
)
Text(
text = availableBalance,
text = customerName,
style = MifosTypography.titleMediumEmphasized,
color = AppColors.customWhite,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ internal fun LoanAccountDetailsScreen(
event.route == Constants.MAKE_PAYMENT -> {
val transferArgs = AccountDetails(
accountId = uiState.accountId,
outstandingBalance = uiState.totalOutStandingBalance ?: 1.00,
transferType = TRANSFER_PAY_TO,
transferTarget = TransferType.SELF,
transferSuccessDestination = StatusNavigationDestination.LOAN_ACCOUNT.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ internal fun TptForm(
onAction(TptAction.OnFromAccountSelected(account))
},
label = stringResource(Res.string.feature_tpt_label_origin_account),
selectedAccountNo = state.fromAccount?.accountNo ?: "",
selectedAccountName = state.fromAccount?.clientName ?: "",
)

MifosDropDownDoubleTextField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.mifos.mobile.core.datastore.UserPreferencesRepository
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
import org.mifos.mobile.core.model.entity.templates.account.AccountOption
import org.mifos.mobile.core.model.entity.templates.account.AccountOptionsTemplate
import org.mifos.mobile.core.model.enums.AccountType
import org.mifos.mobile.core.ui.utils.BaseViewModel
import org.mifos.mobile.core.ui.utils.ValidationHelper
/**
Expand Down Expand Up @@ -165,6 +164,7 @@ internal class TptViewModel(
* @param fromAccount The account number of the selected 'from' account.
*/
private fun handleFromAccountChange(fromAccount: String) {
println("From Account Selected: $fromAccount")
val fromAccountSelected = state.accountOptionsTemplate.fromAccountOptions
.find { it.accountNo == fromAccount }

Expand Down Expand Up @@ -194,7 +194,7 @@ internal class TptViewModel(
.find { it.accountNo == toAccount }

val fromAccounts = state.accountOptionsTemplate.fromAccountOptions.filter {
it.accountNo != toAccount && it.accountType?.value == AccountType.SAVINGS.value
it.accountNo != toAccount
}

updateState {
Expand Down Expand Up @@ -409,14 +409,10 @@ internal class TptViewModel(
}

is DataState.Success -> {
val savingsAccounts = dataState.data.fromAccountOptions.filter { acc ->
acc.accountType?.value == AccountType.SAVINGS.value
}

updateState {
it.copy(
accountOptionsTemplate = dataState.data,
fromAccountOptions = savingsAccounts,
fromAccountOptions = dataState.data.fromAccountOptions,
toAccountOptions = dataState.data.toAccountOptions,
uiState = TptState.TptScreenState.Success,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ internal fun MakeTransferScreenContent(
onAccountSelected = { account, balance ->
onAction(MakeTransferAction.OnFromAccountSelected(account))
},
selectedAccountNo = state.fromAccount?.accountNo ?: "",
selectedAccountName = state.fromAccount?.clientName ?: "",
)

MifosOutlinedTextField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.mifos.mobile.core.model.entity.client.ClientAccounts
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
import org.mifos.mobile.core.model.entity.templates.account.AccountOption
import org.mifos.mobile.core.model.entity.templates.account.AccountOptionsTemplate
import org.mifos.mobile.core.model.enums.AccountType
import org.mifos.mobile.core.model.enums.TransferType
import org.mifos.mobile.core.ui.utils.BaseViewModel
import org.mifos.mobile.core.ui.utils.ValidationHelper
Expand Down Expand Up @@ -176,12 +177,15 @@ internal class MakeTransferViewModel(
* @param toAccountNo The account number of the newly selected `to` account.
*/
private fun handleToAccountChange(toAccountNo: String) {
val accountNo = toAccountNo
val toAccountSelected = state.accountOptionsTemplate.toAccountOptions
.find { it.accountNo == accountNo }
val fromAccounts = state.accountOptionsTemplate.fromAccountOptions.filter {
it.accountNo != accountNo
}
.find { it.accountNo == toAccountNo }

val fromAccounts = state.accountOptionsTemplate.fromAccountOptions
.filter {
it.accountType?.value == AccountType.SAVINGS.value &&
it.accountNo != toAccountNo
}

updateState {
it.copy(
toAccount = toAccountSelected,
Expand All @@ -201,12 +205,13 @@ internal class MakeTransferViewModel(
* @param fromAccountNo The account number of the newly selected `from` account.
*/
private fun handleFromAccountChange(fromAccountNo: String) {
val accountNo = fromAccountNo
val fromAccountSelected = state.accountOptionsTemplate.fromAccountOptions
.find { it.accountNo == accountNo }
val toAccounts = state.accountOptionsTemplate.toAccountOptions.filter {
it.accountNo != accountNo
}
.filter { it.accountType?.value == AccountType.SAVINGS.value }
.find { it.accountNo == fromAccountNo }

val toAccounts = state.accountOptionsTemplate.toAccountOptions
.filter { it.accountNo != fromAccountNo }

updateState {
it.copy(
fromAccount = fromAccountSelected,
Expand Down Expand Up @@ -402,36 +407,65 @@ internal class MakeTransferViewModel(
)
}
}

is DataState.Success -> {
updateState { current ->
val template = dataState.data

val matchedToAccount =
if (current.outstandingBalance != null) {
template.toAccountOptions.firstOrNull { option ->
option.accountId?.toLong() == current.accountId
when (current.transferSuccessDestination) {
StatusNavigationDestination.SAVINGS_ACCOUNT.name,
StatusNavigationDestination.LOAN_ACCOUNT.name,
-> {
val savingsFromAccounts = template.fromAccountOptions.filter {
it.accountType?.value == AccountType.SAVINGS.value
}
} else {
current.toAccount
}

val updatedFromAccountOptions =
if (current.outstandingBalance != null) {
template.fromAccountOptions.filterNot { option ->
option.accountId?.toLong() == current.accountId
val prepopulatedFromAccount = when (current.transferSuccessDestination) {
StatusNavigationDestination.SAVINGS_ACCOUNT.name,
StatusNavigationDestination.LOAN_ACCOUNT.name,
-> {
savingsFromAccounts.firstOrNull { it.accountId?.toLong() == current.accountId }
}
else -> current.fromAccount
}
} else {
template.fromAccountOptions
}

current.copy(
accountOptionsTemplate = template,
fromAccountOptions = updatedFromAccountOptions,
toAccountOptions = template.toAccountOptions,
toAccount = matchedToAccount,
amount = current.outstandingBalance?.toString() ?: "",
uiState = MakeTransferState.MakeTransferScreenState.Success,
)
val prepopulatedToAccount = when (current.transferSuccessDestination) {
StatusNavigationDestination.LOAN_ACCOUNT.name -> {
template.toAccountOptions.firstOrNull {
it.accountId?.toLong() == current.accountId
}
}
else -> current.toAccount
}

val amount = current.outstandingBalance?.toString() ?: current.amount

val filteredFromAccounts = savingsFromAccounts.filter {
it.accountNo != prepopulatedToAccount?.accountNo
}
val filteredToAccounts = template.toAccountOptions.filter {
it.accountNo != prepopulatedFromAccount?.accountNo
}

current.copy(
accountOptionsTemplate = template,
fromAccountOptions = filteredFromAccounts,
toAccountOptions = filteredToAccounts,
fromAccount = prepopulatedFromAccount,
toAccount = prepopulatedToAccount,
amount = amount,
uiState = MakeTransferState.MakeTransferScreenState.Success,
)
}
else -> {
current.copy(
accountOptionsTemplate = template,
fromAccountOptions = template.fromAccountOptions,
toAccountOptions = template.toAccountOptions,
uiState = MakeTransferState.MakeTransferScreenState.Success,
)
}
}
}
}
}
Expand Down
Loading