FINERACT-2181: Fix Consult Loan repayment schedule with disbursement harge using amount plus interest
This commit is contained in:
committed by
Adam Saghy
parent
9d6243442c
commit
94cc68ba7c
+7
-3
@@ -749,7 +749,8 @@ public class LoanScheduleAssembler {
|
|||||||
|
|
||||||
LoanScheduleModel loanScheduleModel = loanScheduleGenerator.generate(mc, loanApplicationTerms, loanCharges, detailDTO);
|
LoanScheduleModel loanScheduleModel = loanScheduleGenerator.generate(mc, loanApplicationTerms, loanCharges, detailDTO);
|
||||||
if (!nonCompoundingCharges.isEmpty()) {
|
if (!nonCompoundingCharges.isEmpty()) {
|
||||||
updateDisbursementWithCharges(loanScheduleModel.getPeriods(), nonCompoundingCharges);
|
updateDisbursementWithCharges(loanApplicationTerms.getPrincipal().getAmount(), loanScheduleModel.getPeriods(),
|
||||||
|
nonCompoundingCharges);
|
||||||
}
|
}
|
||||||
return loanScheduleModel;
|
return loanScheduleModel;
|
||||||
}
|
}
|
||||||
@@ -1564,14 +1565,17 @@ public class LoanScheduleAssembler {
|
|||||||
return interestCharges;
|
return interestCharges;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDisbursementWithCharges(final Collection<LoanScheduleModelPeriod> periods,
|
private void updateDisbursementWithCharges(final BigDecimal principal, final Collection<LoanScheduleModelPeriod> periods,
|
||||||
final Set<LoanCharge> nonCompoundingCharges) {
|
final Set<LoanCharge> nonCompoundingCharges) {
|
||||||
final BigDecimal totalInterest = periods.stream().filter(p -> p.isRepaymentPeriod()).map(LoanScheduleModelPeriod::interestDue)
|
final BigDecimal totalInterest = periods.stream().filter(p -> p.isRepaymentPeriod()).map(LoanScheduleModelPeriod::interestDue)
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
for (LoanScheduleModelPeriod loanScheduleModelPeriod : periods) {
|
for (LoanScheduleModelPeriod loanScheduleModelPeriod : periods) {
|
||||||
if (loanScheduleModelPeriod instanceof LoanScheduleModelDisbursementPeriod) {
|
if (loanScheduleModelPeriod instanceof LoanScheduleModelDisbursementPeriod) {
|
||||||
for (final LoanCharge loanCharge : nonCompoundingCharges) {
|
for (final LoanCharge loanCharge : nonCompoundingCharges) {
|
||||||
loanChargeService.populateDerivedFields(loanCharge, totalInterest, loanCharge.amountOrPercentage(), null,
|
final BigDecimal amountAppliedTo = loanCharge.getChargeCalculation().isPercentageOfAmountAndInterest()
|
||||||
|
? principal.add(totalInterest)
|
||||||
|
: totalInterest;
|
||||||
|
loanChargeService.populateDerivedFields(loanCharge, amountAppliedTo, loanCharge.amountOrPercentage(), null,
|
||||||
BigDecimal.ZERO);
|
BigDecimal.ZERO);
|
||||||
loanScheduleModelPeriod.addLoanCharges(loanCharge.getAmountOutstanding(), BigDecimal.ZERO);
|
loanScheduleModelPeriod.addLoanCharges(loanCharge.getAmountOutstanding(), BigDecimal.ZERO);
|
||||||
}
|
}
|
||||||
|
|||||||
+38
@@ -7062,6 +7062,44 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoanCharges_DISBURSEMENT_WITH_AMOUNT_AND_INTEREST() {
|
||||||
|
|
||||||
|
Calendar fourMonthsfromNowCalendar = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||||
|
fourMonthsfromNowCalendar.add(Calendar.MONTH, -4);
|
||||||
|
if (fourMonthsfromNowCalendar.get(Calendar.DAY_OF_MONTH) > 27) {
|
||||||
|
fourMonthsfromNowCalendar.add(Calendar.DAY_OF_MONTH, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fourMonthsfromNow = Utils.convertDateToURLFormat(fourMonthsfromNowCalendar);
|
||||||
|
final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
|
||||||
|
ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
|
||||||
|
final Integer loanProductID = createLoanProduct(false, NONE);
|
||||||
|
|
||||||
|
List<HashMap> charges = new ArrayList<>();
|
||||||
|
Integer disbursementFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
|
||||||
|
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "2"));
|
||||||
|
addCharges(charges, disbursementFee, "2", null);
|
||||||
|
|
||||||
|
List<HashMap> collaterals = new ArrayList<>();
|
||||||
|
final Integer loanID = applyForLoanApplicationWithPaymentStrategyAndPastMonth(clientID, loanProductID, charges, null, "1000",
|
||||||
|
LoanApplicationTestBuilder.DEFAULT_STRATEGY, fourMonthsfromNow, collaterals);
|
||||||
|
Assertions.assertNotNull(loanID);
|
||||||
|
|
||||||
|
LOAN_TRANSACTION_HELPER.approveLoan(fourMonthsfromNow, loanID);
|
||||||
|
|
||||||
|
String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
|
||||||
|
LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount(fourMonthsfromNow, loanID,
|
||||||
|
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
|
||||||
|
|
||||||
|
// check for disbursement fee: Principal 1,000 with 24% Annual Rate for 6 Months we have Total Interest of:
|
||||||
|
// 120.00
|
||||||
|
ArrayList<HashMap> loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
|
||||||
|
HashMap disbursementDetail = loanSchedule.get(0);
|
||||||
|
// Disbursement Fee: 2% of 1,120.00 = 22.40
|
||||||
|
validateNumberForEqual("22.40", String.valueOf(disbursementDetail.get("feeChargesDue")));
|
||||||
|
}
|
||||||
|
|
||||||
private void checkLoanTransactionOrder(Long loanId, String... transactionUUIDs) {
|
private void checkLoanTransactionOrder(Long loanId, String... transactionUUIDs) {
|
||||||
LOG.info("-------------------------------CHECK LOAN TRANSACTION ORDER-------------------------------------------");
|
LOG.info("-------------------------------CHECK LOAN TRANSACTION ORDER-------------------------------------------");
|
||||||
GetLoansLoanIdResponse loanDetailsResult = LOAN_TRANSACTION_HELPER.getLoanDetails(loanId);
|
GetLoansLoanIdResponse loanDetailsResult = LOAN_TRANSACTION_HELPER.getLoanDetails(loanId);
|
||||||
|
|||||||
Reference in New Issue
Block a user