Merge pull request #1211 from fynmanoj/AL-9

FINERACT-1108 Custom-installment-in-reshedule
This commit is contained in:
Avik Ganguly
2020-08-14 21:48:30 +05:30
committed by GitHub
5 changed files with 91 additions and 4 deletions
@@ -206,4 +206,25 @@ public class LoanRescheduleRequestTest {
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId); LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
} }
/**
* create new loan reschedule request
**/
private void createLoanRescheduleChangeEMIRequest() {
LOG.info("---------------------------------CREATING LOAN RESCHEDULE REQUEST CHANGE EMI------------------------------------------");
final String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnPrincipal(null).updateGraceOnInterest(null)
.updateExtraTerms(null).updateEMI("5000").updateEmiChangeEndDate("4 February 2015")
.updateRescheduleFromDate("04 January 2015").updateRecalculateInterest(true).build(this.loanId.toString());
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
}
@Test
public void testCreateLoanRescheduleChangeEMIRequest() {
this.createLoanRescheduleChangeEMIRequest();
}
} }
@@ -33,6 +33,8 @@ public class LoanRescheduleRequestTestBuilder {
private String rescheduleReasonId = "1"; private String rescheduleReasonId = "1";
private String rescheduleReasonComment = null; private String rescheduleReasonComment = null;
private String submittedOnDate = "04 September 2014"; private String submittedOnDate = "04 September 2014";
private String emi = null;
private String emiEndDate = null;
public String build(final String loanId) { public String build(final String loanId) {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
@@ -71,6 +73,14 @@ public class LoanRescheduleRequestTestBuilder {
map.put("rescheduleReasonComment", rescheduleReasonComment); map.put("rescheduleReasonComment", rescheduleReasonComment);
} }
if (emi != null) {
map.put("emi", emi);
}
if (emiEndDate != null) {
map.put("endDate", emiEndDate);
}
return new Gson().toJson(map); return new Gson().toJson(map);
} }
@@ -136,6 +146,16 @@ public class LoanRescheduleRequestTestBuilder {
return this; return this;
} }
public LoanRescheduleRequestTestBuilder updateEmiChangeEndDate(final String emiChangeEndDate) {
this.emiEndDate = emiChangeEndDate;
return this;
}
public LoanRescheduleRequestTestBuilder updateEMI(final String emi) {
this.emi = emi;
return this;
}
public String getRejectLoanRescheduleRequestJSON() { public String getRejectLoanRescheduleRequestJSON() {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("locale", "en"); map.put("locale", "en");
@@ -53,6 +53,9 @@ public class RescheduleLoansApiConstants {
public static final String pendingCommandParamName = "pending"; public static final String pendingCommandParamName = "pending";
public static final String rejectCommandParamName = "reject"; public static final String rejectCommandParamName = "reject";
public static final String endDateParamName = "endDate";
public static final String emiParamName = "emi";
// reject action request parameters // reject action request parameters
public static final String rejectedOnDateParam = "rejectedOnDate"; public static final String rejectedOnDateParam = "rejectedOnDate";
@@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.loanaccount.rescheduleloan.data;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@@ -56,7 +57,8 @@ public class LoanRescheduleRequestDataValidator {
RescheduleLoansApiConstants.rescheduleFromDateParamName, RescheduleLoansApiConstants.newInterestRateParamName, RescheduleLoansApiConstants.rescheduleFromDateParamName, RescheduleLoansApiConstants.newInterestRateParamName,
RescheduleLoansApiConstants.rescheduleReasonIdParamName, RescheduleLoansApiConstants.rescheduleReasonCommentParamName, RescheduleLoansApiConstants.rescheduleReasonIdParamName, RescheduleLoansApiConstants.rescheduleReasonCommentParamName,
RescheduleLoansApiConstants.submittedOnDateParamName, RescheduleLoansApiConstants.loanIdParamName, RescheduleLoansApiConstants.submittedOnDateParamName, RescheduleLoansApiConstants.loanIdParamName,
RescheduleLoansApiConstants.adjustedDueDateParamName, RescheduleLoansApiConstants.recalculateInterestParamName)); RescheduleLoansApiConstants.adjustedDueDateParamName, RescheduleLoansApiConstants.recalculateInterestParamName,
RescheduleLoansApiConstants.endDateParamName, RescheduleLoansApiConstants.emiParamName));
private static final Set<String> REJECT_REQUEST_DATA_PARAMETERS = new HashSet<>( private static final Set<String> REJECT_REQUEST_DATA_PARAMETERS = new HashSet<>(
Arrays.asList(RescheduleLoansApiConstants.localeParamName, RescheduleLoansApiConstants.dateFormatParamName, Arrays.asList(RescheduleLoansApiConstants.localeParamName, RescheduleLoansApiConstants.dateFormatParamName,
@@ -141,6 +143,25 @@ public class LoanRescheduleRequestDataValidator {
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonCommentParamName).value(rescheduleReasonComment) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonCommentParamName).value(rescheduleReasonComment)
.ignoreIfNull().notExceedingLengthOf(500); .ignoreIfNull().notExceedingLengthOf(500);
if (this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.emiParamName, jsonElement)
|| this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.endDateParamName, jsonElement)) {
final LocalDate endDate = jsonCommand.localDateValueOfParameterNamed(RescheduleLoansApiConstants.endDateParamName);
final BigDecimal emi = jsonCommand.bigDecimalValueOfParameterNamed(RescheduleLoansApiConstants.emiParamName);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.endDateParamName).value(endDate).notNull();
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.emiParamName).value(emi).notNull().positiveAmount();
if (endDate != null) {
LoanRepaymentScheduleInstallment endInstallment = loan.getRepaymentScheduleInstallment(endDate);
if (endInstallment == null) {
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.endDateParamName)
.failWithCode("repayment.schedule.installment.does.not.exist", "Repayment schedule installment does not exist");
}
}
}
final LocalDate adjustedDueDate = this.fromJsonHelper.extractLocalDateNamed(RescheduleLoansApiConstants.adjustedDueDateParamName, final LocalDate adjustedDueDate = this.fromJsonHelper.extractLocalDateNamed(RescheduleLoansApiConstants.adjustedDueDateParamName,
jsonElement); jsonElement);
@@ -155,7 +176,8 @@ public class LoanRescheduleRequestDataValidator {
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)) { && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.emiParamName, jsonElement)) {
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName).notNull(); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName).notNull();
} }
LoanRepaymentScheduleInstallment installment = null; LoanRepaymentScheduleInstallment installment = null;
@@ -212,6 +212,9 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
final Boolean recalculateInterest = jsonCommand final Boolean recalculateInterest = jsonCommand
.booleanObjectValueOfParameterNamed(RescheduleLoansApiConstants.recalculateInterestParamName); .booleanObjectValueOfParameterNamed(RescheduleLoansApiConstants.recalculateInterestParamName);
final Date endDate = jsonCommand.dateValueOfParameterNamed(RescheduleLoansApiConstants.endDateParamName);
final BigDecimal emi = jsonCommand.bigDecimalValueOfParameterNamed(RescheduleLoansApiConstants.emiParamName);
// initialize set the value to null // initialize set the value to null
Date submittedOnDate = null; Date submittedOnDate = null;
@@ -277,7 +280,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
// create term variations for flat and declining balance loans // create term variations for flat and declining balance loans
createLoanTermVariationsForRegularLoans(loan, graceOnPrincipal, graceOnInterest, extraTerms, interestRate, rescheduleFromDate, createLoanTermVariationsForRegularLoans(loan, graceOnPrincipal, graceOnInterest, extraTerms, interestRate, rescheduleFromDate,
adjustedDueDate, loanRescheduleRequest, loanRescheduleRequestToTermVariationMappings, isActive, isSpecificToInstallment, adjustedDueDate, loanRescheduleRequest, loanRescheduleRequestToTermVariationMappings, isActive, isSpecificToInstallment,
decimalValue, dueDate); decimalValue, dueDate, endDate, emi);
// create a new entry in the m_loan_reschedule_request table // create a new entry in the m_loan_reschedule_request table
this.loanRescheduleRequestRepository.save(loanRescheduleRequest); this.loanRescheduleRequestRepository.save(loanRescheduleRequest);
@@ -301,7 +304,25 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
final Integer extraTerms, final BigDecimal interestRate, Date rescheduleFromDate, Date adjustedDueDate, final Integer extraTerms, final BigDecimal interestRate, Date rescheduleFromDate, Date adjustedDueDate,
final LoanRescheduleRequest loanRescheduleRequest, final LoanRescheduleRequest loanRescheduleRequest,
List<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings, final Boolean isActive, List<LoanRescheduleRequestToTermVariationMapping> loanRescheduleRequestToTermVariationMappings, final Boolean isActive,
final boolean isSpecificToInstallment, BigDecimal decimalValue, Date dueDate) { final boolean isSpecificToInstallment, BigDecimal decimalValue, Date dueDate, Date endDate, BigDecimal emi) {
if (rescheduleFromDate != null && endDate != null && emi != null) {
LoanTermVariations parent = null;
LocalDate rescheduleFromLocDate = new LocalDate(rescheduleFromDate);
LocalDate endDateLocDate = new LocalDate(endDate);
final Integer termType = LoanTermVariationType.EMI_AMOUNT.getValue();
List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments();
for (LoanRepaymentScheduleInstallment installment : installments) {
if (installment.getDueDate().isEqual(rescheduleFromLocDate) || installment.getDueDate().isEqual(endDateLocDate)
|| (installment.getDueDate().isAfter(rescheduleFromLocDate) && installment.getDueDate().isBefore(endDateLocDate))) {
createLoanTermVariations(termType, loan, installment.getDueDate().toDate(), installment.getDueDate().toDate(),
loanRescheduleRequestToTermVariationMappings, isActive, true, emi, parent);
}
if (installment.getDueDate().isAfter(endDateLocDate)) {
break;
}
}
}
if (rescheduleFromDate != null && adjustedDueDate != null) { if (rescheduleFromDate != null && adjustedDueDate != null) {
LoanTermVariations parent = null; LoanTermVariations parent = null;