Skip to content

Commit b56ac00

Browse files
committed
feat(feature/loan): loan foreclosurescreen
feat(feature/loan): loan foreclosurescreen feat(feature/loan): loan foreclosurescreen feat(feature/loan): loan foreclosurescreen feat(feature/loan): loan foreclosurescreen feat(feature/loan): loan foreclosurescreen
1 parent b3ed04e commit b56ac00

16 files changed

Lines changed: 737 additions & 0 deletions

File tree

core/data/src/commonMain/kotlin/com/mifos/core/data/di/RepositoryModule.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import com.mifos.core.data.repository.LoanAccountRepository
4646
import com.mifos.core.data.repository.LoanAccountSummaryRepository
4747
import com.mifos.core.data.repository.LoanChargeFormRepository
4848
import com.mifos.core.data.repository.LoanChargeRepository
49+
import com.mifos.core.data.repository.LoanForeclosureRepository
4950
import com.mifos.core.data.repository.LoanRepaymentRepository
5051
import com.mifos.core.data.repository.LoanRepaymentScheduleRepository
5152
import com.mifos.core.data.repository.LoanReschedulesRepository
@@ -115,6 +116,7 @@ import com.mifos.core.data.repositoryImp.LoanAccountRepositoryImp
115116
import com.mifos.core.data.repositoryImp.LoanAccountSummaryRepositoryImp
116117
import com.mifos.core.data.repositoryImp.LoanChargeFormRepositoryImp
117118
import com.mifos.core.data.repositoryImp.LoanChargeRepositoryImp
119+
import com.mifos.core.data.repositoryImp.LoanForeclosureRepositoryImp
118120
import com.mifos.core.data.repositoryImp.LoanRepaymentRepositoryImp
119121
import com.mifos.core.data.repositoryImp.LoanRepaymentScheduleRepositoryImp
120122
import com.mifos.core.data.repositoryImp.LoanReschedulesRepositoryImpl
@@ -197,6 +199,7 @@ val RepositoryModule = module {
197199
singleOf(::LoanRepaymentScheduleRepositoryImp) bind LoanRepaymentScheduleRepository::class
198200
singleOf(::LoanTransactionsRepositoryImp) bind LoanTransactionsRepository::class
199201
singleOf(::LoanReschedulesRepositoryImpl) bind LoanReschedulesRepository::class
202+
singleOf(::LoanForeclosureRepositoryImp) bind LoanForeclosureRepository::class
200203

201204
// Account Transfer
202205
singleOf(::AmountTransferRepositoryImp) bind AmountTransferRepository::class
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.data.repository
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.model.objects.account.loan.foreclosure.LoanForeclosureInput
14+
import com.mifos.core.model.objects.account.loan.foreclosure.LoanForeclosureTemplate
15+
16+
interface LoanForeclosureRepository {
17+
18+
suspend fun getLoanForeclosureTemplate(
19+
loanId: Int,
20+
transactionDate: String,
21+
dateFormat: String,
22+
locale: String,
23+
): DataState<LoanForeclosureTemplate>
24+
25+
suspend fun submitLoanForeclosure(
26+
loanId: Int,
27+
input: LoanForeclosureInput,
28+
): DataState<Unit>
29+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.data.repositoryImp
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.data.repository.LoanForeclosureRepository
14+
import com.mifos.core.model.objects.account.loan.foreclosure.LoanForeclosureInput
15+
import com.mifos.core.model.objects.account.loan.foreclosure.LoanForeclosureTemplate
16+
import com.mifos.core.network.datamanager.DataManagerLoan
17+
import com.mifos.core.network.mappers.loan.toDomain
18+
import com.mifos.core.network.mappers.loan.toDto
19+
import kotlinx.coroutines.withContext
20+
import template.core.base.common.manager.DispatcherManager
21+
22+
class LoanForeclosureRepositoryImp(
23+
private val dataManager: DataManagerLoan,
24+
private val dispatcher: DispatcherManager,
25+
) : LoanForeclosureRepository {
26+
27+
override suspend fun getLoanForeclosureTemplate(
28+
loanId: Int,
29+
transactionDate: String,
30+
dateFormat: String,
31+
locale: String,
32+
): DataState<LoanForeclosureTemplate> {
33+
return withContext(dispatcher.io) {
34+
try {
35+
val dto = dataManager.getLoanForeclosureTemplate(
36+
loanId = loanId,
37+
transactionDate = transactionDate,
38+
dateFormat = dateFormat,
39+
locale = locale,
40+
)
41+
DataState.Success(dto.toDomain())
42+
} catch (e: Exception) {
43+
DataState.Error(e)
44+
}
45+
}
46+
}
47+
48+
override suspend fun submitLoanForeclosure(
49+
loanId: Int,
50+
input: LoanForeclosureInput,
51+
): DataState<Unit> {
52+
return withContext(dispatcher.io) {
53+
try {
54+
dataManager.submitLoanForeclosure(loanId, input.toDto())
55+
DataState.Success(Unit)
56+
} catch (e: Exception) {
57+
DataState.Error(e)
58+
}
59+
}
60+
}
61+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.model.objects.account.loan.foreclosure
11+
12+
data class LoanForeclosureInput(
13+
val transactionDate: String,
14+
val note: String,
15+
val dateFormat: String,
16+
val locale: String,
17+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.model.objects.account.loan.foreclosure
11+
12+
data class LoanForeclosureTemplate(
13+
val loanId: Int? = null,
14+
val amount: Double? = null,
15+
val principalPortion: Double? = null,
16+
val interestPortion: Double? = null,
17+
val feeChargesPortion: Double? = null,
18+
val penaltyChargesPortion: Double? = null,
19+
)

core/network/src/commonMain/kotlin/com/mifos/core/network/datamanager/DataManagerLoan.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.mifos.core.model.objects.account.loan.transfer.AccountTransferTemplat
2424
import com.mifos.core.network.BaseApiManager
2525
import com.mifos.core.network.GenericResponse
2626
import com.mifos.core.network.model.LoansPayload
27+
import com.mifos.core.network.model.loan.LoanForeclosureRequestDto
28+
import com.mifos.core.network.model.loan.LoanForeclosureTemplateDto
2729
import com.mifos.room.entities.PaymentTypeOptionEntity
2830
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequestEntity
2931
import com.mifos.room.entities.accounts.loans.LoanRepaymentResponseEntity
@@ -412,4 +414,37 @@ class DataManagerLoan(
412414
throw IllegalStateException(extractErrorMessage(response))
413415
}
414416
}
417+
418+
suspend fun getLoanForeclosureTemplate(
419+
loanId: Int,
420+
transactionDate: String,
421+
dateFormat: String,
422+
locale: String,
423+
): LoanForeclosureTemplateDto {
424+
val response = mBaseApiManager.loanService.getLoanForeclosureTemplate(
425+
loanId = loanId,
426+
transactionDate = transactionDate,
427+
dateFormat = dateFormat,
428+
locale = locale,
429+
)
430+
if (!response.status.isSuccess()) {
431+
val errorMessage = extractErrorMessage(response)
432+
throw IllegalStateException(errorMessage)
433+
}
434+
435+
return Json { ignoreUnknownKeys = true }.decodeFromString<LoanForeclosureTemplateDto>(response.bodyAsText())
436+
}
437+
438+
suspend fun submitLoanForeclosure(
439+
loanId: Int,
440+
request: LoanForeclosureRequestDto,
441+
) {
442+
val response = mBaseApiManager.loanService.submitLoanForeclosure(
443+
loanId = loanId,
444+
body = request,
445+
)
446+
if (!response.status.isSuccess()) {
447+
throw IllegalStateException(extractErrorMessage(response))
448+
}
449+
}
415450
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.network.mappers.loan
11+
12+
import com.mifos.core.model.objects.account.loan.foreclosure.LoanForeclosureInput
13+
import com.mifos.core.model.objects.account.loan.foreclosure.LoanForeclosureTemplate
14+
import com.mifos.core.network.model.loan.LoanForeclosureRequestDto
15+
import com.mifos.core.network.model.loan.LoanForeclosureTemplateDto
16+
17+
fun LoanForeclosureTemplateDto.toDomain(): LoanForeclosureTemplate =
18+
LoanForeclosureTemplate(
19+
loanId = loanId,
20+
amount = amount,
21+
principalPortion = principalPortion,
22+
interestPortion = interestPortion,
23+
feeChargesPortion = feeChargesPortion,
24+
penaltyChargesPortion = penaltyChargesPortion,
25+
)
26+
27+
fun LoanForeclosureInput.toDto(): LoanForeclosureRequestDto =
28+
LoanForeclosureRequestDto(
29+
transactionDate = transactionDate,
30+
note = note,
31+
dateFormat = dateFormat,
32+
locale = locale,
33+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.network.model.loan
11+
12+
import kotlinx.serialization.Serializable
13+
14+
@Serializable
15+
data class LoanForeclosureRequestDto(
16+
val transactionDate: String,
17+
val note: String,
18+
val dateFormat: String,
19+
val locale: String,
20+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2026 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mifos-x-field-officer-app/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.network.model.loan
11+
12+
import kotlinx.serialization.Serializable
13+
14+
@Serializable
15+
data class LoanForeclosureTemplateDto(
16+
val loanId: Int? = null,
17+
val amount: Double? = null,
18+
val principalPortion: Double? = null,
19+
val interestPortion: Double? = null,
20+
val feeChargesPortion: Double? = null,
21+
val penaltyChargesPortion: Double? = null,
22+
)

core/network/src/commonMain/kotlin/com/mifos/core/network/services/LoanService.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.mifos.core.model.objects.payloads.GroupLoanPayload
2424
import com.mifos.core.model.objects.template.loan.GroupLoanTemplate
2525
import com.mifos.core.network.GenericResponse
2626
import com.mifos.core.network.model.LoansPayload
27+
import com.mifos.core.network.model.loan.LoanForeclosureRequestDto
2728
import com.mifos.room.basemodel.APIEndPoint
2829
import com.mifos.room.entities.accounts.loans.Loan
2930
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequestEntity
@@ -196,4 +197,18 @@ interface LoanService {
196197
@Path("scheduleId") scheduleId: Int,
197198
@Body request: LoanRescheduleRejectionRequest,
198199
): HttpResponse
200+
201+
@GET(APIEndPoint.LOANS + "/{loanId}/transactions/template?command=foreclosure")
202+
suspend fun getLoanForeclosureTemplate(
203+
@Path("loanId") loanId: Int,
204+
@Query("transactionDate") transactionDate: String,
205+
@Query("dateFormat") dateFormat: String,
206+
@Query("locale") locale: String,
207+
): HttpResponse
208+
209+
@POST(APIEndPoint.LOANS + "/{loanId}/transactions?command=foreclosure")
210+
suspend fun submitLoanForeclosure(
211+
@Path("loanId") loanId: Int,
212+
@Body body: LoanForeclosureRequestDto,
213+
): HttpResponse
199214
}

0 commit comments

Comments
 (0)