MIFSOX-493 Update LoanTerms onChange product
This commit is contained in:
+28
@@ -1001,6 +1001,21 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
actualChanges.put(collateralParamName, listOfLoanCollateralData(possiblyModifedLoanCollateralItems));
|
||||
}
|
||||
}
|
||||
|
||||
final String loanTermFrequencyParamName = "loanTermFrequency";
|
||||
if (command.isChangeInIntegerParameterNamed(loanTermFrequencyParamName, this.termFrequency)) {
|
||||
final Integer newValue = command.integerValueOfParameterNamed(loanTermFrequencyParamName);
|
||||
actualChanges.put(externalIdParamName, newValue);
|
||||
this.termFrequency = newValue;
|
||||
}
|
||||
|
||||
final String loanTermFrequencyTypeParamName = "loanTermFrequencyType";
|
||||
if (command.isChangeInIntegerParameterNamed(loanTermFrequencyTypeParamName, this.termPeriodFrequencyType)) {
|
||||
final Integer newValue = command.integerValueOfParameterNamed(loanTermFrequencyTypeParamName);
|
||||
final PeriodFrequencyType newTermPeriodFrequencyType = PeriodFrequencyType.fromInt(newValue);
|
||||
actualChanges.put(loanTermFrequencyTypeParamName, newTermPeriodFrequencyType.getValue());
|
||||
this.termPeriodFrequencyType = newValue;
|
||||
}
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
@@ -2378,4 +2393,17 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return LoanType.fromInt(this.loanType).isGroupLoan();
|
||||
}
|
||||
|
||||
public void updateInterestRateFrequencyType() {
|
||||
this.loanRepaymentScheduleDetail.updatenterestPeriodFrequencyType(this.loanProduct.getInterestPeriodFrequencyType());
|
||||
}
|
||||
|
||||
public Integer getTermFrequency() {
|
||||
return this.termFrequency;
|
||||
}
|
||||
|
||||
|
||||
public Integer getTermPeriodFrequencyType() {
|
||||
return this.termPeriodFrequencyType;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -203,7 +203,7 @@ public final class CalculateLoanScheduleQueryFromApiJsonHelper {
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
private void validateSelectedPeriodFrequencyTypeIsTheSame(final List<ApiParameterError> dataValidationErrors,
|
||||
public void validateSelectedPeriodFrequencyTypeIsTheSame(final List<ApiParameterError> dataValidationErrors,
|
||||
final Integer loanTermFrequency, final Integer loanTermFrequencyType, final Integer numberOfRepayments,
|
||||
final Integer repaymentEvery, final Integer repaymentEveryType) {
|
||||
if (loanTermFrequencyType != null && !loanTermFrequencyType.equals(repaymentEveryType)) {
|
||||
|
||||
+13
-1
@@ -52,10 +52,13 @@ public final class LoanApplicationCommandFromApiJsonHelper {
|
||||
));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final CalculateLoanScheduleQueryFromApiJsonHelper apiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public LoanApplicationCommandFromApiJsonHelper(final FromJsonHelper fromApiJsonHelper) {
|
||||
public LoanApplicationCommandFromApiJsonHelper(final FromJsonHelper fromApiJsonHelper,
|
||||
final CalculateLoanScheduleQueryFromApiJsonHelper apiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.apiJsonHelper = apiJsonHelper;
|
||||
}
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
@@ -666,5 +669,14 @@ public final class LoanApplicationCommandFromApiJsonHelper {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateLoanTermAndRepaidEveryValues(final Integer loanTermFrequency, final Integer loanTermFrequencyType,
|
||||
final Integer numberOfRepayments, final Integer repaymentEvery, final Integer repaymentEveryType) {
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
this.apiJsonHelper.validateSelectedPeriodFrequencyTypeIsTheSame(dataValidationErrors, loanTermFrequency, loanTermFrequencyType,
|
||||
numberOfRepayments, repaymentEvery, repaymentEveryType);
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -54,6 +54,7 @@ import org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanSchedule
|
||||
import org.mifosplatform.portfolio.loanaccount.serialization.LoanApplicationCommandFromApiJsonHelper;
|
||||
import org.mifosplatform.portfolio.loanaccount.serialization.LoanApplicationTransitionApiJsonValidator;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProduct;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductRelatedDetail;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductRepository;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanTransactionProcessingStrategy;
|
||||
import org.mifosplatform.portfolio.loanproduct.exception.LoanProductNotFoundException;
|
||||
@@ -153,6 +154,11 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
|
||||
final Loan newLoanApplication = loanAssembler.assembleFrom(command, currentUser);
|
||||
|
||||
final LoanProductRelatedDetail productRelatedDetail = newLoanApplication.repaymentScheduleDetail();
|
||||
this.fromApiJsonDeserializer.validateLoanTermAndRepaidEveryValues(newLoanApplication.getTermFrequency(), newLoanApplication.getTermPeriodFrequencyType(),
|
||||
productRelatedDetail.getNumberOfRepayments(), productRelatedDetail.getRepayEvery(),
|
||||
productRelatedDetail.getRepaymentPeriodFrequencyType().getValue());
|
||||
|
||||
this.loanRepository.save(newLoanApplication);
|
||||
|
||||
@@ -229,10 +235,17 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
if (loanProduct == null) { throw new LoanProductNotFoundException(productId); }
|
||||
|
||||
existingLoanApplication.updateLoanProduct(loanProduct);
|
||||
if (!changes.containsKey("interestRateFrequencyType")) {
|
||||
existingLoanApplication.updateInterestRateFrequencyType();
|
||||
}
|
||||
}
|
||||
|
||||
// validate min and maximum constraints
|
||||
this.fromApiJsonDeserializer.validateForModify(command.json());
|
||||
final LoanProductRelatedDetail productRelatedDetail = existingLoanApplication.repaymentScheduleDetail();
|
||||
this.fromApiJsonDeserializer.validateLoanTermAndRepaidEveryValues(existingLoanApplication.getTermFrequency(), existingLoanApplication.getTermPeriodFrequencyType(),
|
||||
productRelatedDetail.getNumberOfRepayments(), productRelatedDetail.getRepayEvery(),
|
||||
productRelatedDetail.getRepaymentPeriodFrequencyType().getValue());
|
||||
|
||||
final String fundIdParamName = "fundId";
|
||||
if (changes.containsKey(fundIdParamName)) {
|
||||
|
||||
+4
@@ -385,4 +385,8 @@ public class LoanProductRelatedDetail implements LoanProductMinimumRepaymentSche
|
||||
public boolean hasCurrencyCodeOf(final String currencyCode) {
|
||||
return this.currency.getCode().equalsIgnoreCase(currencyCode);
|
||||
}
|
||||
|
||||
public void updatenterestPeriodFrequencyType(final PeriodFrequencyType interestPeriodFrequencyType) {
|
||||
this.interestPeriodFrequencyType = interestPeriodFrequencyType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user