Merge pull request #1211 from fynmanoj/AL-9
FINERACT-1108 Custom-installment-in-reshedule
This commit is contained in:
+3
@@ -53,6 +53,9 @@ public class RescheduleLoansApiConstants {
|
||||
public static final String pendingCommandParamName = "pending";
|
||||
public static final String rejectCommandParamName = "reject";
|
||||
|
||||
public static final String endDateParamName = "endDate";
|
||||
public static final String emiParamName = "emi";
|
||||
|
||||
// reject action request parameters
|
||||
public static final String rejectedOnDateParam = "rejectedOnDate";
|
||||
|
||||
|
||||
+24
-2
@@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.loanaccount.rescheduleloan.data;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -56,7 +57,8 @@ public class LoanRescheduleRequestDataValidator {
|
||||
RescheduleLoansApiConstants.rescheduleFromDateParamName, RescheduleLoansApiConstants.newInterestRateParamName,
|
||||
RescheduleLoansApiConstants.rescheduleReasonIdParamName, RescheduleLoansApiConstants.rescheduleReasonCommentParamName,
|
||||
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<>(
|
||||
Arrays.asList(RescheduleLoansApiConstants.localeParamName, RescheduleLoansApiConstants.dateFormatParamName,
|
||||
@@ -141,6 +143,25 @@ public class LoanRescheduleRequestDataValidator {
|
||||
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonCommentParamName).value(rescheduleReasonComment)
|
||||
.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,
|
||||
jsonElement);
|
||||
|
||||
@@ -155,7 +176,8 @@ public class LoanRescheduleRequestDataValidator {
|
||||
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement)
|
||||
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, 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();
|
||||
}
|
||||
LoanRepaymentScheduleInstallment installment = null;
|
||||
|
||||
+23
-2
@@ -212,6 +212,9 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
|
||||
final Boolean recalculateInterest = jsonCommand
|
||||
.booleanObjectValueOfParameterNamed(RescheduleLoansApiConstants.recalculateInterestParamName);
|
||||
|
||||
final Date endDate = jsonCommand.dateValueOfParameterNamed(RescheduleLoansApiConstants.endDateParamName);
|
||||
final BigDecimal emi = jsonCommand.bigDecimalValueOfParameterNamed(RescheduleLoansApiConstants.emiParamName);
|
||||
|
||||
// initialize set the value to null
|
||||
Date submittedOnDate = null;
|
||||
|
||||
@@ -277,7 +280,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
|
||||
// create term variations for flat and declining balance loans
|
||||
createLoanTermVariationsForRegularLoans(loan, graceOnPrincipal, graceOnInterest, extraTerms, interestRate, rescheduleFromDate,
|
||||
adjustedDueDate, loanRescheduleRequest, loanRescheduleRequestToTermVariationMappings, isActive, isSpecificToInstallment,
|
||||
decimalValue, dueDate);
|
||||
decimalValue, dueDate, endDate, emi);
|
||||
|
||||
// create a new entry in the m_loan_reschedule_request table
|
||||
this.loanRescheduleRequestRepository.save(loanRescheduleRequest);
|
||||
@@ -301,7 +304,25 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
|
||||
final Integer extraTerms, final BigDecimal interestRate, Date rescheduleFromDate, Date adjustedDueDate,
|
||||
final LoanRescheduleRequest loanRescheduleRequest,
|
||||
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) {
|
||||
LoanTermVariations parent = null;
|
||||
|
||||
Reference in New Issue
Block a user