Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feature:loan): migrated to CMP #2786

Open
wants to merge 1 commit into
base: kmp-impl
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions cmp-android/dependencies/demoDebugRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,20 @@ io.github.vinceglb:filekit-compose-android:0.8.7
io.github.vinceglb:filekit-compose:0.8.7
io.github.vinceglb:filekit-core-android:0.8.7
io.github.vinceglb:filekit-core:0.8.7
io.insert-koin:koin-android:4.0.1-RC1
io.insert-koin:koin-androidx-compose:4.0.1-RC1
io.insert-koin:koin-androidx-navigation:4.0.1-RC1
io.insert-koin:koin-android:4.0.2
io.insert-koin:koin-androidx-compose:4.0.2
io.insert-koin:koin-androidx-navigation:4.0.2
io.insert-koin:koin-annotations-jvm:1.4.0-RC4
io.insert-koin:koin-annotations:1.4.0-RC4
io.insert-koin:koin-bom:4.0.1-RC1
io.insert-koin:koin-compose-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel:4.0.1-RC1
io.insert-koin:koin-compose:4.0.1-RC1
io.insert-koin:koin-core-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel:4.0.1-RC1
io.insert-koin:koin-core:4.0.1-RC1
io.insert-koin:koin-bom:4.0.2
io.insert-koin:koin-compose-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel:4.0.2
io.insert-koin:koin-compose:4.0.2
io.insert-koin:koin-core-jvm:4.0.2
io.insert-koin:koin-core-viewmodel-jvm:4.0.2
io.insert-koin:koin-core-viewmodel:4.0.2
io.insert-koin:koin-core:4.0.2
io.ktor:ktor-client-auth-jvm:3.0.3
io.ktor:ktor-client-auth:3.0.3
io.ktor:ktor-client-content-negotiation-jvm:3.0.3
Expand Down
24 changes: 12 additions & 12 deletions cmp-android/dependencies/demoReleaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,20 @@ io.github.vinceglb:filekit-compose-android:0.8.7
io.github.vinceglb:filekit-compose:0.8.7
io.github.vinceglb:filekit-core-android:0.8.7
io.github.vinceglb:filekit-core:0.8.7
io.insert-koin:koin-android:4.0.1-RC1
io.insert-koin:koin-androidx-compose:4.0.1-RC1
io.insert-koin:koin-androidx-navigation:4.0.1-RC1
io.insert-koin:koin-android:4.0.2
io.insert-koin:koin-androidx-compose:4.0.2
io.insert-koin:koin-androidx-navigation:4.0.2
io.insert-koin:koin-annotations-jvm:1.4.0-RC4
io.insert-koin:koin-annotations:1.4.0-RC4
io.insert-koin:koin-bom:4.0.1-RC1
io.insert-koin:koin-compose-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel:4.0.1-RC1
io.insert-koin:koin-compose:4.0.1-RC1
io.insert-koin:koin-core-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel:4.0.1-RC1
io.insert-koin:koin-core:4.0.1-RC1
io.insert-koin:koin-bom:4.0.2
io.insert-koin:koin-compose-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel:4.0.2
io.insert-koin:koin-compose:4.0.2
io.insert-koin:koin-core-jvm:4.0.2
io.insert-koin:koin-core-viewmodel-jvm:4.0.2
io.insert-koin:koin-core-viewmodel:4.0.2
io.insert-koin:koin-core:4.0.2
io.ktor:ktor-client-auth-jvm:3.0.3
io.ktor:ktor-client-auth:3.0.3
io.ktor:ktor-client-content-negotiation-jvm:3.0.3
Expand Down
24 changes: 12 additions & 12 deletions cmp-android/dependencies/prodDebugRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,20 @@ io.github.vinceglb:filekit-compose-android:0.8.7
io.github.vinceglb:filekit-compose:0.8.7
io.github.vinceglb:filekit-core-android:0.8.7
io.github.vinceglb:filekit-core:0.8.7
io.insert-koin:koin-android:4.0.1-RC1
io.insert-koin:koin-androidx-compose:4.0.1-RC1
io.insert-koin:koin-androidx-navigation:4.0.1-RC1
io.insert-koin:koin-android:4.0.2
io.insert-koin:koin-androidx-compose:4.0.2
io.insert-koin:koin-androidx-navigation:4.0.2
io.insert-koin:koin-annotations-jvm:1.4.0-RC4
io.insert-koin:koin-annotations:1.4.0-RC4
io.insert-koin:koin-bom:4.0.1-RC1
io.insert-koin:koin-compose-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel:4.0.1-RC1
io.insert-koin:koin-compose:4.0.1-RC1
io.insert-koin:koin-core-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel:4.0.1-RC1
io.insert-koin:koin-core:4.0.1-RC1
io.insert-koin:koin-bom:4.0.2
io.insert-koin:koin-compose-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel:4.0.2
io.insert-koin:koin-compose:4.0.2
io.insert-koin:koin-core-jvm:4.0.2
io.insert-koin:koin-core-viewmodel-jvm:4.0.2
io.insert-koin:koin-core-viewmodel:4.0.2
io.insert-koin:koin-core:4.0.2
io.ktor:ktor-client-auth-jvm:3.0.3
io.ktor:ktor-client-auth:3.0.3
io.ktor:ktor-client-content-negotiation-jvm:3.0.3
Expand Down
24 changes: 12 additions & 12 deletions cmp-android/dependencies/prodReleaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,20 @@ io.github.vinceglb:filekit-compose-android:0.8.7
io.github.vinceglb:filekit-compose:0.8.7
io.github.vinceglb:filekit-core-android:0.8.7
io.github.vinceglb:filekit-core:0.8.7
io.insert-koin:koin-android:4.0.1-RC1
io.insert-koin:koin-androidx-compose:4.0.1-RC1
io.insert-koin:koin-androidx-navigation:4.0.1-RC1
io.insert-koin:koin-android:4.0.2
io.insert-koin:koin-androidx-compose:4.0.2
io.insert-koin:koin-androidx-navigation:4.0.2
io.insert-koin:koin-annotations-jvm:1.4.0-RC4
io.insert-koin:koin-annotations:1.4.0-RC4
io.insert-koin:koin-bom:4.0.1-RC1
io.insert-koin:koin-compose-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-compose-viewmodel:4.0.1-RC1
io.insert-koin:koin-compose:4.0.1-RC1
io.insert-koin:koin-core-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel-jvm:4.0.1-RC1
io.insert-koin:koin-core-viewmodel:4.0.1-RC1
io.insert-koin:koin-core:4.0.1-RC1
io.insert-koin:koin-bom:4.0.2
io.insert-koin:koin-compose-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel-jvm:4.0.2
io.insert-koin:koin-compose-viewmodel:4.0.2
io.insert-koin:koin-compose:4.0.2
io.insert-koin:koin-core-jvm:4.0.2
io.insert-koin:koin-core-viewmodel-jvm:4.0.2
io.insert-koin:koin-core-viewmodel:4.0.2
io.insert-koin:koin-core:4.0.2
io.ktor:ktor-client-auth-jvm:3.0.3
io.ktor:ktor-client-auth:3.0.3
io.ktor:ktor-client-content-negotiation-jvm:3.0.3
Expand Down
2 changes: 1 addition & 1 deletion cmp-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
kotlin {
sourceSets {
commonMain.dependencies {

implementation(projects.feature.loan)
implementation(projects.feature.auth)
implementation(projects.feature.home)
implementation(projects.feature.accounts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.mifos.mobile.core.network.di.NetworkModule
import org.mifos.mobile.feature.accounts.di.accountsModule
import org.mifos.mobile.feature.auth.di.AuthModule
import org.mifos.mobile.feature.home.di.HomeModule
import org.mifos.mobile.feature.loan.di.LoanModule
import org.mifos.mobile.feature.loanaccount.di.loanAccountModule
import org.mifos.mobile.feature.savingsaccount.di.savingsAccountModule
import org.mifos.mobile.feature.shareaccount.di.shareAccountModule
Expand Down Expand Up @@ -48,6 +49,7 @@ object KoinModules {
savingsAccountModule,
loanAccountModule,
shareAccountModule,
LoanModule,
)
}
private val LibraryModule = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import org.mifos.mobile.feature.accounts.navigation.navigateToAccountsScreen
import org.mifos.mobile.feature.home.navigation.HomeDestinations
import org.mifos.mobile.feature.home.navigation.HomeNavigation
import org.mifos.mobile.feature.home.navigation.homeNavGraph
import org.mifos.mobile.feature.loan.navigation.loanNavGraph
import org.mifos.mobile.feature.loan.navigation.navigateToLoanApplication
import org.mifos.mobile.feature.loan.navigation.navigateToLoanDetailScreen

@Composable
internal fun FeatureNavHost(
Expand All @@ -45,12 +48,27 @@ internal fun FeatureNavHost(

accountsNavGraph(
navController = appState.navController,
navigateToLoanApplicationScreen = { },
navigateToLoanApplicationScreen = appState.navController::navigateToLoanApplication,
navigateToSavingsApplicationScreen = { },
navigateToAccountDetail = { _, _ -> },
navigateToAccountDetail = { accountType, id ->
when (accountType) {
AccountType.SAVINGS -> { }
AccountType.LOAN ->
appState.navController.navigateToLoanDetailScreen(loanId = id)
AccountType.SHARE -> { }
}
},
)

aboutUsNavGraph(navController = appState.navController, navigateToOssLicense = { })

loanNavGraph(
navController = appState.navController,
viewQr = { },
viewGuarantor = { },
viewCharges = { },
makePayment = { _, _, _ -> },
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.common

import java.text.DecimalFormat

actual fun formatAmount(amount: Double): String {
val formatter = DecimalFormat("#,##0.00")
return formatter.format(amount)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.datetime.format
import kotlinx.datetime.format.FormatStringsInDatetimeFormats
import kotlinx.datetime.format.byUnicodePattern
import kotlinx.datetime.toLocalDateTime
import org.mifos.mobile.core.common.FileUtils.Companion.logger

@OptIn(FormatStringsInDatetimeFormats::class)
object DateHelper {
Expand Down Expand Up @@ -51,6 +52,7 @@ object DateHelper {
* @return date in the format day month year (ex 14 Apr 2016)
*/
fun getDateAsString(integersOfDate: List<Int>): String {
logger.d { "ktorClient $integersOfDate" }
val stringBuilder = StringBuilder()
stringBuilder.append(integersOfDate[2])
.append(' ')
Expand All @@ -68,6 +70,27 @@ object DateHelper {
)
}

private val monthMap = mapOf(
"Jan" to 1, "Feb" to 2, "Mar" to 3, "Apr" to 4,
"May" to 5, "Jun" to 6, "Jul" to 7, "Aug" to 8,
"Sep" to 9, "Oct" to 10, "Nov" to 11, "Dec" to 12,
)

fun getMonthNumber(monthName: String): Int {
return monthMap[monthName]
?: throw IllegalArgumentException("Invalid month name: $monthName")
}

fun getDateAsList(date: String): List<Int> {
val dateList = date.split(" ")

val day = dateList[0].toInt()
val month = getMonthNumber(dateList[1])
val year = dateList[2].toInt()

return listOf(year, month, day)
}

/**
* This Method converting the dd-MM-yyyy format type date string into dd MMMM yyyy
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.common

expect fun formatAmount(amount: Double): String
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.common

import java.text.DecimalFormat

actual fun formatAmount(amount: Double): String {
val formatter = DecimalFormat("#,##0.00") // Ensures two decimal places
return formatter.format(amount)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.common

actual fun formatAmount(amount: Double): String {
return amount.asDynamic().toFixed(2) as String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.common

import platform.Foundation.NSNumber
import platform.Foundation.NSNumberFormatter
import platform.Foundation.NSNumberFormatterDecimalStyle

actual fun formatAmount(amount: Double): String {
val formatter = NSNumberFormatter().apply {
numberStyle = NSNumberFormatterDecimalStyle
maximumFractionDigits = 2.toULong()
minimumFractionDigits = 2.toULong()
}
return formatter.stringFromNumber(NSNumber(amount)) ?: amount.toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.common

@JsFun("a => a.toFixed(2)")
external fun jsToFixed(amount: Double): String

actual fun formatAmount(amount: Double): String {
return jsToFixed(amount)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ package org.mifos.mobile.core.data.repositoryImpl

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import org.mifos.mobile.core.common.DataState
import org.mifos.mobile.core.common.FileUtils.Companion.logger
import org.mifos.mobile.core.common.asDataStateFlow
import org.mifos.mobile.core.data.repository.LoanRepository
import org.mifos.mobile.core.model.entity.accounts.loan.LoanWithAssociations
Expand All @@ -31,7 +34,14 @@ class LoanRepositoryImp(
loanId: Long?,
): Flow<DataState<LoanWithAssociations?>> {
return dataManager.loanAccountsListApi.getLoanWithAssociations(loanId!!, associationType)
.asDataStateFlow().flowOn(ioDispatcher)
.map { response ->
logger.d { "success Getting loan details from server repo $response" }
DataState.Success(response)
}.catch { exception ->
logger.e { "Error fetching loan details: ${exception.message}" }
DataState.Error(exception, null)
}
.flowOn(ioDispatcher)
}

override suspend fun withdrawLoanAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ data class LoanWithAssociations(

val repaymentFrequencyType: RepaymentFrequencyType? = null,

val interestRatePerPeriod: Int? = null,
val interestRatePerPeriod: Double? = null,

val interestRateFrequencyType: InterestRateFrequencyType? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
*/
package org.mifos.mobile.core.model.entity.accounts.loan

import kotlinx.serialization.Serializable
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

@Serializable
@Parcelize
data class LoanWithdraw(
val withdrawnOnDate: String? = null,
Expand Down
Loading
Loading