Skip to content

Commit 18712ef

Browse files
committed
refactor(loan): unified getter for all loan status
1 parent b983294 commit 18712ef

File tree

4 files changed

+84
-45
lines changed

4 files changed

+84
-45
lines changed

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/LoanStatus.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ enum class LoanStatus(val status: String) {
1414

1515
CLOSED("Closed"),
1616

17+
CLOSED_OBLIGATIONS_MET("Closed (obligations met)"),
18+
1719
MATURED("Matured"),
1820

1921
APPROVED("Approved"),
@@ -24,7 +26,10 @@ enum class LoanStatus(val status: String) {
2426

2527
REJECTED("Rejected"),
2628

27-
WITHDRAWN("Withdrawn by applicant");
29+
WITHDRAWN("Withdrawn by applicant"),
30+
31+
OVERPAID("Overpaid"),
32+
;
2833

2934
companion object {
3035
fun fromStatus(value: String?): LoanStatus? =

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsScreen.kt

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ import androidx.compose.runtime.remember
2828
import androidx.compose.ui.Modifier
2929
import androidx.compose.ui.unit.dp
3030
import androidx.lifecycle.compose.collectAsStateWithLifecycle
31-
import kotlinx.collections.immutable.ImmutableList
3231
import mifos_mobile.feature.loan_account.generated.resources.Res
33-
import mifos_mobile.feature.loan_account.generated.resources.feature_account_action_make_payment
3432
import mifos_mobile.feature.loan_account.generated.resources.feature_account_details_action
3533
import mifos_mobile.feature.loan_account.generated.resources.feature_account_details_top_bar_title
3634
import mifos_mobile.feature.loan_account.generated.resources.feature_loan_next_installment_label
@@ -46,7 +44,6 @@ import org.mifos.mobile.core.designsystem.theme.AppColors
4644
import org.mifos.mobile.core.designsystem.theme.DesignToken
4745
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
4846
import org.mifos.mobile.core.designsystem.theme.MifosTypography
49-
import org.mifos.mobile.core.model.LoanStatus
5047
import org.mifos.mobile.core.model.entity.AccountDetails
5148
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
5249
import org.mifos.mobile.core.model.enums.ChargeType
@@ -165,15 +162,14 @@ internal fun LoanAccountDetailsContent(
165162
)
166163
}
167164

168-
if (state.shouldShowAction) {
169-
SavingsAccountActions(
170-
canMakeTransfer = state.canMakeTransfer,
171-
items = state.items,
172-
onActionClick = {
173-
onAction(LoanAccountDetailsAction.OnNavigateToAction(it))
174-
},
175-
)
176-
}
165+
val visibleActions = state.accountStatus?.allowedActions ?: emptySet()
166+
167+
SavingsAccountActions(
168+
visibleActions = visibleActions,
169+
onActionClick = {
170+
onAction(LoanAccountDetailsAction.OnNavigateToAction(it))
171+
},
172+
)
177173
}
178174
}
179175
}
@@ -225,9 +221,7 @@ internal fun AccountDetailsGrid(
225221

226222
@Composable
227223
internal fun SavingsAccountActions(
228-
canMakeTransfer: Boolean,
229-
items: ImmutableList<LoanActionItems>,
230-
// onAction: (LoanAccountDetailsAction) -> Unit,
224+
visibleActions: Set<LoanActionItems>,
231225
onActionClick: (String) -> Unit,
232226
) {
233227
Column(
@@ -241,18 +235,15 @@ internal fun SavingsAccountActions(
241235
FlowRow(
242236
modifier = Modifier.fillMaxWidth(),
243237
) {
244-
items
245-
.filter { item ->
246-
!(item.title == Res.string.feature_account_action_make_payment && !canMakeTransfer)
247-
}
238+
visibleActions
248239
.forEach { item ->
249-
MifosActionCard(
250-
title = item.title,
251-
subTitle = item.subTitle,
252-
icon = item.icon,
253-
onClick = { onActionClick(item.route) },
254-
)
255-
}
240+
MifosActionCard(
241+
title = item.title,
242+
subTitle = item.subTitle,
243+
icon = item.icon,
244+
onClick = { onActionClick(item.route) },
245+
)
246+
}
256247
}
257248
}
258249
}

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsViewModel.kt

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,58 @@ internal data class LoanAccountDetailsState(
230230
data object Loading : DialogState
231231
}
232232

233-
val shouldShowAction: Boolean
234-
get() = accountStatus !in setOf(
235-
LoanStatus.SUBMIT_AND_PENDING_APPROVAL,
236-
LoanStatus.REJECTED
233+
}
234+
235+
val LoanStatus.allowedActions: Set<LoanActionItems>
236+
get() = when (this) {
237+
LoanStatus.SUBMIT_AND_PENDING_APPROVAL -> setOf(
238+
LoanActionItems.LoanSummary,
237239
)
238240

239-
val canMakeTransfer: Boolean
240-
get() = accountStatus in setOf(LoanStatus.ACTIVE, LoanStatus.DISBURSED)
241-
}
241+
LoanStatus.APPROVED -> setOf(
242+
LoanActionItems.LoanSummary,
243+
LoanActionItems.Charges,
244+
)
245+
246+
LoanStatus.DISBURSED,
247+
LoanStatus.ACTIVE,
248+
-> setOf(
249+
LoanActionItems.MakePayment,
250+
LoanActionItems.LoanSummary,
251+
LoanActionItems.RepaymentSchedule,
252+
LoanActionItems.Transactions,
253+
LoanActionItems.Charges,
254+
LoanActionItems.QrCode,
255+
256+
)
257+
258+
LoanStatus.MATURED -> setOf(
259+
LoanActionItems.LoanSummary,
260+
LoanActionItems.RepaymentSchedule,
261+
LoanActionItems.Transactions,
262+
)
263+
264+
LoanStatus.CLOSED -> setOf(
265+
LoanActionItems.LoanSummary,
266+
LoanActionItems.Transactions,
267+
)
268+
269+
LoanStatus.CLOSED_OBLIGATIONS_MET -> setOf(
270+
LoanActionItems.LoanSummary,
271+
LoanActionItems.Transactions,
272+
)
273+
274+
LoanStatus.REJECTED,
275+
LoanStatus.WITHDRAWN,
276+
-> setOf(
277+
LoanActionItems.LoanSummary,
278+
)
279+
280+
LoanStatus.OVERPAID -> setOf(
281+
LoanActionItems.LoanSummary,
282+
LoanActionItems.Transactions,
283+
)
284+
}
242285

243286
/**
244287
* One-time navigation or effect events for the Loan Account Details screen.

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountSummary/AccountSummaryViewModel.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,23 @@ internal class LoanAccountSummaryViewModel(
149149
LabelValueItem(
150150
Res.string.feature_loan_expected_payoff_label,
151151
CurrencyFormatter.format(
152-
loan?.summary?.totalExpectedRepayment,
152+
loan?.summary?.totalExpectedRepayment ?: 0.0,
153153
currencyCode,
154154
maxDigits,
155155
),
156156
),
157157
LabelValueItem(
158158
Res.string.feature_loan_interest_payoff_label,
159159
CurrencyFormatter.format(
160-
loan?.summary?.interestCharged,
160+
loan?.summary?.interestCharged ?: 0.0,
161161
currencyCode,
162162
maxDigits,
163163
),
164164
),
165165
LabelValueItem(
166166
Res.string.feature_loan_principal_label,
167167
CurrencyFormatter.format(
168-
loan?.summary?.principalDisbursed,
168+
loan?.summary?.principalDisbursed ?: 0.0,
169169
currencyCode,
170170
maxDigits,
171171
),
@@ -184,15 +184,15 @@ internal class LoanAccountSummaryViewModel(
184184
LabelValueItem(
185185
Res.string.feature_loan_fees_label,
186186
CurrencyFormatter.format(
187-
loan?.summary?.feeChargesCharged,
187+
loan?.summary?.feeChargesCharged ?: 0.0,
188188
currencyCode,
189189
maxDigits,
190190
),
191191
),
192192
LabelValueItem(
193193
Res.string.feature_loan_penalties_label,
194194
CurrencyFormatter.format(
195-
loan?.summary?.penaltyChargesCharged,
195+
loan?.summary?.penaltyChargesCharged ?: 0.0,
196196
currencyCode,
197197
maxDigits,
198198
),
@@ -203,23 +203,23 @@ internal class LoanAccountSummaryViewModel(
203203
LabelValueItem(
204204
Res.string.feature_loan_interest_waived_label,
205205
CurrencyFormatter.format(
206-
loan?.summary?.interestWaived,
206+
loan?.summary?.interestWaived ?: 0.0,
207207
currencyCode,
208208
maxDigits,
209209
),
210210
),
211211
LabelValueItem(
212212
Res.string.feature_loan_penalty_waived_label,
213213
CurrencyFormatter.format(
214-
loan?.summary?.penaltyChargesWaived,
214+
loan?.summary?.penaltyChargesWaived ?: 0.0,
215215
currencyCode,
216216
maxDigits,
217217
),
218218
),
219219
LabelValueItem(
220220
Res.string.feature_loan_fees_waived_label,
221221
CurrencyFormatter.format(
222-
loan?.summary?.feeChargesWaived,
222+
loan?.summary?.feeChargesWaived ?: 0.0,
223223
currencyCode,
224224
maxDigits,
225225
),
@@ -230,15 +230,15 @@ internal class LoanAccountSummaryViewModel(
230230
LabelValueItem(
231231
Res.string.feature_loan_interest_paid_off_label,
232232
CurrencyFormatter.format(
233-
loan?.summary?.interestPaid,
233+
loan?.summary?.interestPaid ?: 0.0,
234234
currencyCode,
235235
maxDigits,
236236
),
237237
),
238238
LabelValueItem(
239239
Res.string.feature_loan_principal_paid_off_label,
240240
CurrencyFormatter.format(
241-
loan?.summary?.principalPaid,
241+
loan?.summary?.principalPaid ?: 0.0,
242242
currencyCode,
243243
maxDigits,
244244
),
@@ -266,7 +266,7 @@ internal class LoanAccountSummaryViewModel(
266266
LabelValueItem(
267267
Res.string.feature_loan_total_outstanding_label,
268268
CurrencyFormatter.format(
269-
loan?.summary?.totalOutstanding,
269+
loan?.summary?.totalOutstanding ?: 0.0,
270270
currencyCode,
271271
maxDigits,
272272
),

0 commit comments

Comments
 (0)