FINERACT-1657 Allow schedule approved/submitted multi non-tranche loans
This commit is contained in:
committed by
Arnold Gálovics
parent
0487bece0b
commit
16aafdf95b
+38
-20
@@ -1906,27 +1906,40 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
|
|||||||
private BigDecimal getDisbursementAmount(final LoanApplicationTerms loanApplicationTerms, LocalDate disbursementDate,
|
private BigDecimal getDisbursementAmount(final LoanApplicationTerms loanApplicationTerms, LocalDate disbursementDate,
|
||||||
final Collection<LoanScheduleModelPeriod> periods, final BigDecimal chargesDueAtTimeOfDisbursement,
|
final Collection<LoanScheduleModelPeriod> periods, final BigDecimal chargesDueAtTimeOfDisbursement,
|
||||||
final Map<LocalDate, Money> disurseDetail, final boolean excludePastUndisbursed) {
|
final Map<LocalDate, Money> disurseDetail, final boolean excludePastUndisbursed) {
|
||||||
|
|
||||||
|
// this method relates to multi-disbursement loans
|
||||||
BigDecimal principal = BigDecimal.ZERO;
|
BigDecimal principal = BigDecimal.ZERO;
|
||||||
MonetaryCurrency currency = loanApplicationTerms.getPrincipal().getCurrency();
|
if (loanApplicationTerms.getDisbursementDatas().size() == 0) {
|
||||||
for (DisbursementData disbursementData : loanApplicationTerms.getDisbursementDatas()) {
|
// non tranche loans have no disbursement data entries in submitted and approved status
|
||||||
if (disbursementData.disbursementDate().equals(disbursementDate)) {
|
// the appropriate approved amount or applied for amount is used to show a proposed schedule
|
||||||
final LoanScheduleModelDisbursementPeriod disbursementPeriod = LoanScheduleModelDisbursementPeriod.disbursement(
|
if (loanApplicationTerms.getApprovedPrincipal().getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
disbursementData.disbursementDate(), Money.of(currency, disbursementData.amount()), chargesDueAtTimeOfDisbursement);
|
principal = loanApplicationTerms.getApprovedPrincipal().getAmount();
|
||||||
periods.add(disbursementPeriod);
|
} else {
|
||||||
principal = principal.add(disbursementData.amount());
|
principal = loanApplicationTerms.getPrincipal().getAmount();
|
||||||
} else if (!excludePastUndisbursed || disbursementData.isDisbursed()
|
}
|
||||||
|| !disbursementData.disbursementDate().isBefore(DateUtils.getBusinessLocalDate())) {
|
} else {
|
||||||
/*
|
MonetaryCurrency currency = loanApplicationTerms.getPrincipal().getCurrency();
|
||||||
* JW: sums up amounts by disbursal date in case of side-effect issues. Original assumed that there were
|
for (DisbursementData disbursementData : loanApplicationTerms.getDisbursementDatas()) {
|
||||||
* no duplicate disbursal dates and 'put' each amount into the map keyed by date
|
if (disbursementData.disbursementDate().equals(disbursementDate)) {
|
||||||
*/
|
final LoanScheduleModelDisbursementPeriod disbursementPeriod = LoanScheduleModelDisbursementPeriod.disbursement(
|
||||||
Money prevsum = disurseDetail.get(disbursementData.disbursementDate());
|
disbursementData.disbursementDate(), Money.of(currency, disbursementData.amount()),
|
||||||
BigDecimal sumToNow = BigDecimal.ZERO;
|
chargesDueAtTimeOfDisbursement);
|
||||||
if (prevsum != null) {
|
periods.add(disbursementPeriod);
|
||||||
sumToNow = prevsum.getAmount();
|
principal = principal.add(disbursementData.amount());
|
||||||
|
} else if (!excludePastUndisbursed || disbursementData.isDisbursed()
|
||||||
|
|| !disbursementData.disbursementDate().isBefore(DateUtils.getLocalDateOfTenant())) {
|
||||||
|
/*
|
||||||
|
* JW: sums up amounts by disbursal date in case of side-effect issues. Original assumed that there
|
||||||
|
* were no duplicate disbursal dates and 'put' each amount into the map keyed by date
|
||||||
|
*/
|
||||||
|
Money prevsum = disurseDetail.get(disbursementData.disbursementDate());
|
||||||
|
BigDecimal sumToNow = BigDecimal.ZERO;
|
||||||
|
if (prevsum != null) {
|
||||||
|
sumToNow = prevsum.getAmount();
|
||||||
|
}
|
||||||
|
sumToNow = sumToNow.add(disbursementData.amount());
|
||||||
|
disurseDetail.put(disbursementData.disbursementDate(), Money.of(currency, sumToNow));
|
||||||
}
|
}
|
||||||
sumToNow = sumToNow.add(disbursementData.amount());
|
|
||||||
disurseDetail.put(disbursementData.disbursementDate(), Money.of(currency, sumToNow));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return principal;
|
return principal;
|
||||||
@@ -1937,7 +1950,12 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
|
|||||||
|
|
||||||
Collection<LoanScheduleModelPeriod> periods = null;
|
Collection<LoanScheduleModelPeriod> periods = null;
|
||||||
if (loanApplicationTerms.isMultiDisburseLoan()) {
|
if (loanApplicationTerms.isMultiDisburseLoan()) {
|
||||||
periods = new ArrayList<>(numberOfRepayments + loanApplicationTerms.getDisbursementDatas().size());
|
int multiDisbursalTrancheEntries = loanApplicationTerms.getDisbursementDatas().size();
|
||||||
|
if (multiDisbursalTrancheEntries == 0) {
|
||||||
|
// will be zero for non-tranche multi-disbursal loan when submitted or approved
|
||||||
|
multiDisbursalTrancheEntries = 1;
|
||||||
|
}
|
||||||
|
periods = new ArrayList<>(numberOfRepayments + multiDisbursalTrancheEntries);
|
||||||
} else {
|
} else {
|
||||||
periods = new ArrayList<>(numberOfRepayments + 1);
|
periods = new ArrayList<>(numberOfRepayments + 1);
|
||||||
final LoanScheduleModelDisbursementPeriod disbursementPeriod = LoanScheduleModelDisbursementPeriod
|
final LoanScheduleModelDisbursementPeriod disbursementPeriod = LoanScheduleModelDisbursementPeriod
|
||||||
|
|||||||
+39
@@ -203,4 +203,43 @@ public class ClientLoanNonTrancheMultipleDisbursementsIntegrationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkThatNonTrancheMultiDisbursalsCreateAScheduleOnSubmitAndApprovalTest() {
|
||||||
|
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||||
|
|
||||||
|
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||||
|
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Create loan product allowing non-tranche multiple disbursals with interest recalculation
|
||||||
|
*/
|
||||||
|
boolean isInterestRecalculationEnabled = true;
|
||||||
|
final Integer loanProductID = createLoanProduct(isInterestRecalculationEnabled);
|
||||||
|
Assertions.assertNotNull(loanProductID);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Apply for loan application and verify loan status
|
||||||
|
*/
|
||||||
|
final String savingsId = null;
|
||||||
|
String submitDate = "01 January 2022";
|
||||||
|
Integer repaymentsNo = 3;
|
||||||
|
final Integer loanID = applyForLoanApplication(clientID, loanProductID, savingsId, APPLIED_FOR_PRINCIPAL, submitDate,
|
||||||
|
repaymentsNo.toString());
|
||||||
|
Assertions.assertNotNull(loanID);
|
||||||
|
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||||
|
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||||
|
ArrayList<HashMap> loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||||
|
Integer loanScheduleLineCount = loanSchedule.size() - 1; // exclude disbursement line
|
||||||
|
Assertions.assertEquals(repaymentsNo, loanScheduleLineCount);
|
||||||
|
|
||||||
|
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
|
||||||
|
final Float approved = 9000.00f;
|
||||||
|
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(submitDate, null, approved.toString(), loanID, null);
|
||||||
|
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||||
|
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||||
|
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||||
|
loanScheduleLineCount = loanSchedule.size() - 1;
|
||||||
|
Assertions.assertEquals(repaymentsNo, loanScheduleLineCount);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user