Skip to content

Commit

Permalink
migrate savings account
Browse files Browse the repository at this point in the history
b

b

b
  • Loading branch information
itsPronay committed Jul 15, 2024
1 parent 05e86dc commit ac916db
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 662 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ fun MifosOutlinedTextField(
visualTransformation: VisualTransformation = VisualTransformation.None,
trailingIcon: @Composable (() -> Unit)? = null,
keyboardType: KeyboardType = KeyboardType.Text,
error: Int?
error: Int?,
enabled: Boolean = true
) {

OutlinedTextField(
Expand All @@ -223,6 +224,7 @@ fun MifosOutlinedTextField(
label = { Text(label) },
modifier = modifier,
readOnly = readOnly,
enabled = enabled,
leadingIcon = if (icon != null) {
{
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.mifos.core.designsystem.theme.DarkGray
fun MifosSweetError(
message: String,
isRetryEnabled : Boolean = true,
buttonText : String = stringResource(id = R.string.core_designsystem_try_again),
onclick: () -> Unit
) {
Column(
Expand Down Expand Up @@ -87,7 +88,7 @@ fun MifosSweetError(
) {
Text(
modifier = Modifier.padding(start = 20.dp, end = 20.dp),
text = stringResource(id = R.string.core_designsystem_try_again),
text = buttonText,
fontSize = 15.sp
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.mifos.mifosxdroid.online.savingsaccount

import com.mifos.core.objects.client.Savings
import com.mifos.core.objects.organisation.ProductSavings
import com.mifos.core.objects.templates.savings.SavingProductsTemplate
import com.mifos.core.objects.zipmodels.SavingProductsAndTemplate

/**
* Created by Aditya Gupta on 08/08/23.
Expand All @@ -12,14 +14,9 @@ sealed class SavingAccountUiState {

data class ShowFetchingError(val message: Int) : SavingAccountUiState()

// data class AllLoan (val getProductSaving: List<ProductSavings>?) : SavingAccountUiState()

data class ShowAllSavingsAccount(val getProductSaving: List<ProductSavings>?) :
data class LoadAllSavings(val savingsTemplate: SavingProductsAndTemplate) :
SavingAccountUiState()

// data class ShowSavingsAccountTemplateByProduct(val savingProductsTemplate: SavingProductsTemplate) :
// SavingAccountUiState()

data class ShowSavingsAccountCreatedSuccessfully(val savings: Savings?) : SavingAccountUiState()

data class ShowFetchingErrorString(val message: String) : SavingAccountUiState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.online.savingsaccount

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.data.SavingsPayload
Expand All @@ -11,6 +12,7 @@ import com.mifos.core.objects.templates.savings.SavingProductsTemplate
import com.mifos.core.objects.zipmodels.SavingProductsAndTemplate
import com.mifos.mifosxdroid.R
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -32,25 +34,21 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
val savingAccountUiState: StateFlow<SavingAccountUiState> get() = _savingAccountUiState

var clientId = 0
private var productId = 0
var groupId = 0
var isGroupAccount = false

private val _savingProductsTemplate = MutableStateFlow(SavingProductsTemplate())
val savingProductsTemplate = _savingProductsTemplate.asStateFlow()

fun loadSavings() = viewModelScope.launch {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
if (isGroupAccount){
loadGroupSavingAccountTemplateByProduct()
}
else{
loadClientSavingAccountTemplateByProduct()
fun loadLoanTemplateByProduct(productId: Int) {
if (isGroupAccount) {
loadGroupSavingAccountTemplateByProduct(groupId, productId)
} else {
loadClientSavingAccountTemplateByProduct(clientId, productId)
}
}

fun loadSavingsAccountsAndTemplate() {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
Observable.combineLatest(
repository.savingsAccounts(),
repository.savingsAccountTemplate()
Expand All @@ -65,14 +63,15 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}

override fun onNext(productsAndTemplate: SavingProductsAndTemplate?) {
_savingAccountUiState.value =
SavingAccountUiState.ShowAllSavingsAccount(productsAndTemplate?.getmProductSavings())
if (productsAndTemplate != null) {
_savingAccountUiState.value =
SavingAccountUiState.LoadAllSavings(productsAndTemplate)
}
}
})
}

fun loadClientSavingAccountTemplateByProduct() {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
private fun loadClientSavingAccountTemplateByProduct(clientId: Int, productId: Int) {
repository.getClientSavingsAccountTemplateByProduct(clientId, productId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand All @@ -86,20 +85,13 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}

override fun onNext(savingProductsTemplate: SavingProductsTemplate?) {
if (savingProductsTemplate != null) {
_savingProductsTemplate.value = savingProductsTemplate
}
// _savingAccountUiState.value = savingProductsTemplate?.let {
// SavingAccountUiState.ShowSavingsAccountTemplateByProduct(
// it
// )
// }!!
_savingProductsTemplate.value =
savingProductsTemplate ?: SavingProductsTemplate()
}
})
}

fun loadGroupSavingAccountTemplateByProduct() {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
private fun loadGroupSavingAccountTemplateByProduct(groupId: Int, productId: Int) {
repository.getGroupSavingsAccountTemplateByProduct(groupId, productId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand All @@ -113,14 +105,8 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}

override fun onNext(savingProductsTemplate: SavingProductsTemplate?) {
if (savingProductsTemplate != null) {
_savingProductsTemplate.value = savingProductsTemplate
}
// _savingAccountUiState.value = savingProductsTemplate?.let {
// SavingAccountUiState.ShowSavingsAccountTemplateByProduct(
// it
// )
// }!!
_savingProductsTemplate.value =
savingProductsTemplate ?: SavingProductsTemplate()
}
})
}
Expand All @@ -143,32 +129,4 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}
})
}

fun filterSpinnerOptions(interestTypes: List<InterestType>?): List<String> {
val interestNameList = ArrayList<String>()
Observable.from(interestTypes)
.subscribe { interestType -> interestType.value?.let { interestNameList.add(it) } }
return interestNameList
}

fun filterSavingProductsNames(productSavings: List<ProductSavings>?): List<String> {
val productsNames = ArrayList<String>()
Observable.from(productSavings)
.subscribe { product -> product.name?.let { productsNames.add(it) } }
return productsNames
}

fun filterFieldOfficerNames(fieldOfficerOptions: List<FieldOfficerOptions>?): List<String> {
val fieldOfficerNames = ArrayList<String>()
Observable.from(fieldOfficerOptions)
.subscribe { fieldOfficerOptions ->
fieldOfficerOptions.displayName?.let {
fieldOfficerNames.add(
it
)
}
}
return fieldOfficerNames
}

}
Loading

0 comments on commit ac916db

Please sign in to comment.