Skip to content

Commit 02dd8a1

Browse files
committed
feat(loan): implement reject loan screen
1 parent 909158d commit 02dd8a1

21 files changed

Lines changed: 580 additions & 8 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
@@ -40,6 +40,7 @@ import com.mifos.core.data.repository.GroupListRepository
4040
import com.mifos.core.data.repository.GroupLoanAccountRepository
4141
import com.mifos.core.data.repository.GroupsListRepository
4242
import com.mifos.core.data.repository.IndividualCollectionSheetDetailsRepository
43+
import com.mifos.core.data.repository.LoanRejectRepository
4344
import com.mifos.core.data.repository.LoginRepository
4445
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
4546
import com.mifos.core.data.repository.NoteRepository
@@ -152,6 +153,7 @@ import com.mifos.core.data.repositoryImp.loan.LoanChargeRepositoryImp
152153
import com.mifos.core.data.repositoryImp.loan.LoanCreateGuarantorRepositoryImp
153154
import com.mifos.core.data.repositoryImp.loan.LoanDisburseRepositoryImpl
154155
import com.mifos.core.data.repositoryImp.loan.LoanOfficerRepositoryImpl
156+
import com.mifos.core.data.repositoryImp.loan.LoanRejectRepositoryImpl
155157
import com.mifos.core.data.repositoryImp.loan.LoanRepaymentRepositoryImp
156158
import com.mifos.core.data.repositoryImp.loan.LoanRepaymentScheduleRepositoryImp
157159
import com.mifos.core.data.repositoryImp.loan.LoanReschedulesRepositoryImpl
@@ -206,6 +208,7 @@ val RepositoryModule = module {
206208
singleOf(::LoanDisburseRepositoryImpl) bind LoanDisburseRepository::class
207209
singleOf(::LoanCreateGuarantorRepositoryImp) bind LoanCreateGuarantorRepository::class
208210
singleOf(::LoanOfficerRepositoryImpl) bind LoanOfficerRepository::class
211+
singleOf(::LoanRejectRepositoryImpl) bind LoanRejectRepository::class
209212

210213
// Account Transfer
211214
singleOf(::AmountTransferRepositoryImp) bind AmountTransferRepository::class
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.data.repository
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.model.objects.account.loan.RejectLoanInput
14+
15+
interface LoanRejectRepository {
16+
suspend fun rejectLoan(loanId: Int, request: RejectLoanInput): DataState<Unit>
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.loan
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.data.repository.LoanRejectRepository
14+
import com.mifos.core.data.util.NetworkMonitor
15+
import com.mifos.core.data.util.runAsDataState
16+
import com.mifos.core.model.objects.account.loan.RejectLoanInput
17+
import com.mifos.core.network.datamanager.DataManagerLoan
18+
import com.mifos.core.network.dto.loans.RejectLoanRequestDto
19+
import template.core.base.common.manager.DispatcherManager
20+
21+
class LoanRejectRepositoryImpl(
22+
private val dataManagerLoan: DataManagerLoan,
23+
private val networkMonitor: NetworkMonitor,
24+
private val dispatcher: DispatcherManager,
25+
) : LoanRejectRepository {
26+
override suspend fun rejectLoan(
27+
loanId: Int,
28+
request: RejectLoanInput,
29+
): DataState<Unit> {
30+
return runAsDataState(
31+
networkMonitor = networkMonitor,
32+
context = dispatcher.io,
33+
) {
34+
dataManagerLoan.rejectLoan(
35+
loanId = loanId,
36+
request = RejectLoanRequestDto(
37+
rejectedOnDate = request.rejectedOnDate,
38+
note = request.note,
39+
locale = request.locale,
40+
dateFormat = request.dateFormat,
41+
),
42+
)
43+
}
44+
}
45+
}

core/domain/src/commonMain/kotlin/com/mifos/core/domain/di/UseCaseModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import com.mifos.core.domain.useCases.loanChargeOff.GetLoanChargeOffTemplateUseC
9898
import com.mifos.core.domain.useCases.loanChargeOff.LoanChargeOffUseCase
9999
import com.mifos.core.domain.useCases.loanDisburse.GetLoanDisburseTemplateUseCase
100100
import com.mifos.core.domain.useCases.loanDisburse.LoanDisburseUseCase
101+
import com.mifos.core.domain.useCases.loanReject.RejectLoanUseCase
101102
import org.koin.core.module.dsl.factoryOf
102103
import org.koin.dsl.module
103104

@@ -189,6 +190,7 @@ val UseCaseModule = module {
189190
factoryOf(::LoanChargeOffUseCase)
190191
factoryOf(::GetLoanDisburseTemplateUseCase)
191192
factoryOf(::LoanDisburseUseCase)
193+
factoryOf(::RejectLoanUseCase)
192194
factoryOf(::GetLoanOfficerOptionsUseCase)
193195
factoryOf(::AssignLoanOfficerUseCase)
194196
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.domain.useCases.loanReject
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.data.repository.LoanRejectRepository
14+
import com.mifos.core.model.objects.account.loan.RejectLoanInput
15+
16+
class RejectLoanUseCase(
17+
private val repository: LoanRejectRepository,
18+
) {
19+
suspend operator fun invoke(
20+
loanId: Int,
21+
request: RejectLoanInput,
22+
): DataState<Unit> = repository.rejectLoan(loanId, request)
23+
}
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
11+
12+
import com.mifos.core.model.utils.DateConstants
13+
14+
data class RejectLoanInput(
15+
val rejectedOnDate: String,
16+
val note: String? = null,
17+
val locale: String = DateConstants.LOCALE,
18+
val dateFormat: String = "dd-MM-yyyy",
19+
)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import com.mifos.core.network.dto.loans.CreateGuarantorResponseDto
2626
import com.mifos.core.network.dto.loans.GuarantorRequestDto
2727
import com.mifos.core.network.dto.loans.LoanChargeOffRequestDto
2828
import com.mifos.core.network.dto.loans.LoanChargeOffResponseDto
29+
import com.mifos.core.network.dto.loans.RejectLoanRequestDto
30+
import com.mifos.core.network.dto.loans.RejectLoanResponseDto
2931
import com.mifos.core.network.dto.loans.assignLoanOfficer.AssignLoanOfficerRequestDto
3032
import com.mifos.core.network.dto.loans.assignLoanOfficer.AssignLoanOfficerResponseDto
3133
import com.mifos.core.network.dto.loans.disburse.LoanDisburseRequestDto
@@ -156,6 +158,13 @@ class DataManagerLoan(
156158
return mBaseApiManager.loanService.chargeOff(loanId, loanChargeOffRequestDto)
157159
}
158160

161+
suspend fun rejectLoan(
162+
loanId: Int,
163+
request: RejectLoanRequestDto,
164+
): RejectLoanResponseDto {
165+
return mBaseApiManager.loanService.rejectLoan(loanId, request)
166+
}
167+
159168
fun createLoansAccount(loansPayload: LoansPayload?): Flow<HttpResponse> {
160169
return mBaseApiManager.loanService.createLoansAccount(loansPayload).map { response ->
161170

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.network.dto.loans
11+
import kotlinx.serialization.Serializable
12+
13+
@Serializable
14+
data class RejectLoanRequestDto(
15+
val rejectedOnDate: String,
16+
val note: String? = null,
17+
val locale: String,
18+
val dateFormat: String,
19+
)
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.network.dto.loans
11+
import kotlinx.serialization.Serializable
12+
13+
@Serializable
14+
data class RejectLoanResponseDto(
15+
val officeId: Int,
16+
val clientId: Int,
17+
val loanId: Int,
18+
val resourceId: Int,
19+
)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import com.mifos.core.network.dto.loans.CreateGuarantorResponseDto
2626
import com.mifos.core.network.dto.loans.GuarantorRequestDto
2727
import com.mifos.core.network.dto.loans.LoanChargeOffRequestDto
2828
import com.mifos.core.network.dto.loans.LoanChargeOffResponseDto
29+
import com.mifos.core.network.dto.loans.RejectLoanRequestDto
30+
import com.mifos.core.network.dto.loans.RejectLoanResponseDto
2931
import com.mifos.core.network.dto.loans.assignLoanOfficer.AssignLoanOfficerRequestDto
3032
import com.mifos.core.network.dto.loans.assignLoanOfficer.AssignLoanOfficerResponseDto
3133
import com.mifos.core.network.dto.loans.disburse.LoanDisburseRequestDto
@@ -88,6 +90,12 @@ interface LoanService {
8890
@Body loanChargeOffRequest: LoanChargeOffRequestDto,
8991
): LoanChargeOffResponseDto
9092

93+
@POST(APIEndPoint.LOANS + "/{loanId}?command=reject")
94+
suspend fun rejectLoan(
95+
@Path("loanId") loanId: Int,
96+
@Body request: RejectLoanRequestDto,
97+
): RejectLoanResponseDto
98+
9199
@GET(APIEndPoint.LOANS + "/{loanId}?associations=repaymentSchedule")
92100
fun getLoanRepaymentSchedule(@Path("loanId") loanId: Int): Flow<LoanWithAssociationsEntity>
93101

0 commit comments

Comments
 (0)