disable ability to pass currency code and digits after decimal properties during loan creation. inherit from loan product.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
{{#each scheduledLoanInstallments}}
|
||||
<tr>
|
||||
<td>{{=$ctx.number(installmentNumber)}}</td>
|
||||
<td>{{=$ctx.globalDateAsISOString(periodEnd)}}</td>
|
||||
<td>{{=$ctx.globalDate(periodEnd)}}</td>
|
||||
<td>{{=$ctx.money(principalDue)}}</td>
|
||||
<td>{{=$ctx.money(interestDue)}}</td>
|
||||
<td>{{=$ctx.money(totalInstallmentDue)}}</td>
|
||||
@@ -55,8 +55,6 @@
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<input type="hidden" id="clientId" name="clientId" value="{{=clientId}}" />
|
||||
<input type="hidden" id="currencyCode" name="currencyCode" value="{{=selectedProduct.principal.currencyCode}}" />
|
||||
<input type="hidden" id="digitsAfterDecimal" name="digitsAfterDecimal" value="{{=$ctx.number(selectedProduct.principal.digitsAfterDecimal)}}" />
|
||||
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
|
||||
<input type="hidden" id="locale" name="locale" value="${currentLocale}" />
|
||||
|
||||
@@ -607,13 +605,13 @@
|
||||
|
||||
<div class="row">
|
||||
<span class="longrowlabel"><spring:message code="label.client.account.loan.term"/></span>
|
||||
<span class="rowvalue">{{=expectedLoanTermInMonths}} <spring:message code="label.months"/> / ({{=expectedLoanTermInDays}} <spring:message code="label.days"/>)</span>
|
||||
<span class="rowvalue">{{=convenienceData.expectedLoanTermInMonths}} <spring:message code="label.months"/> / ({{=convenienceData.expectedLoanTermInDays}} <spring:message code="label.days"/>)</span>
|
||||
</div>
|
||||
|
||||
{{#if closedOnDate !== null}}
|
||||
<div class="row">
|
||||
<span class="longrowlabel"><spring:message code="label.client.account.loan.actual.term"/></span>
|
||||
<span class="rowvalue">{{=actualLoanTermInMonths}} <spring:message code="label.months"/> / ({{=actualLoanTermInDays}} <spring:message code="label.days"/>)</span>
|
||||
<span class="rowvalue">{{=convenienceData.actualLoanTermInMonths}} <spring:message code="label.months"/> / ({{=convenienceData.actualLoanTermInDays}} <spring:message code="label.days"/>)</span>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
|
||||
@@ -134,14 +134,12 @@ public class LoansApiResource {
|
||||
BigDecimal inArrearsToleranceValue = this.apiDataConversionService.convertFrom(command.getInArrearsTolerance(), "inArrearsTolerance", clientApplicationLocale);
|
||||
BigDecimal interestRatePerPeriodValue = this.apiDataConversionService.convertFrom(command.getInterestRatePerPeriod(),"interestRatePerPeriod", clientApplicationLocale);
|
||||
|
||||
Integer digitsAfterDecimalValue = this.apiDataConversionService.convertToInteger(command.getDigitsAfterDecimal(), "digitsAfterDecimal", clientApplicationLocale);
|
||||
Integer repaymentEveryValue = this.apiDataConversionService.convertToInteger(command.getRepaymentEvery(), "repaymentEvery", clientApplicationLocale);
|
||||
Integer numberOfRepaymentsValue = this.apiDataConversionService.convertToInteger(command.getNumberOfRepayments(), "numberOfRepayments", clientApplicationLocale);
|
||||
|
||||
command.setPrincipalValue(principalValue);
|
||||
command.setInArrearsToleranceValue(inArrearsToleranceValue);
|
||||
command.setInterestRatePerPeriodValue(interestRatePerPeriodValue);
|
||||
command.setDigitsAfterDecimalValue(digitsAfterDecimalValue);
|
||||
command.setRepaymentEveryValue(repaymentEveryValue);
|
||||
command.setNumberOfRepaymentsValue(numberOfRepaymentsValue);
|
||||
|
||||
|
||||
+28
-21
@@ -9,8 +9,7 @@ import org.joda.time.LocalDate;
|
||||
@XmlRootElement
|
||||
public class CalculateLoanScheduleCommand {
|
||||
|
||||
private String currencyCode;
|
||||
private Integer digitsAfterDecimalValue;
|
||||
private Long productId;
|
||||
private BigDecimal principalValue;
|
||||
private BigDecimal inArrearsToleranceValue;
|
||||
|
||||
@@ -32,15 +31,15 @@ public class CalculateLoanScheduleCommand {
|
||||
//
|
||||
}
|
||||
|
||||
public CalculateLoanScheduleCommand(final String currencyCode,
|
||||
final Integer digitsAfterDecimal, final Number principal,
|
||||
public CalculateLoanScheduleCommand(
|
||||
final Long productId,
|
||||
final Number principal,
|
||||
final Number interestRatePerPeriod, Integer interestRateFrequencyMethod, final Integer interestMethod, final Integer interestCalculationPeriodMethod,
|
||||
final Integer repaymentEvery, final Integer repaymentFrequency, final Integer numberOfRepayments, Integer amortizationMethod,
|
||||
final LocalDate expectedDisbursementDate,
|
||||
final LocalDate repaymentsStartingFromDate, final LocalDate interestCalculatedFromDate) {
|
||||
|
||||
this.currencyCode = currencyCode;
|
||||
this.digitsAfterDecimalValue = digitsAfterDecimal;
|
||||
this.productId = productId;
|
||||
if (principal != null) {
|
||||
this.principalValue = BigDecimal.valueOf(principal.doubleValue());
|
||||
}
|
||||
@@ -60,21 +59,21 @@ public class CalculateLoanScheduleCommand {
|
||||
this.interestChargedFromLocalDate= interestCalculatedFromDate;
|
||||
}
|
||||
|
||||
public String getCurrencyCode() {
|
||||
return currencyCode;
|
||||
}
|
||||
|
||||
public void setCurrencyCode(String currencyCode) {
|
||||
this.currencyCode = currencyCode;
|
||||
}
|
||||
|
||||
public Integer getDigitsAfterDecimalValue() {
|
||||
return digitsAfterDecimalValue;
|
||||
}
|
||||
|
||||
public void setDigitsAfterDecimalValue(Integer digitsAfterDecimalValue) {
|
||||
this.digitsAfterDecimalValue = digitsAfterDecimalValue;
|
||||
}
|
||||
// public String getCurrencyCode() {
|
||||
// return currencyCode;
|
||||
// }
|
||||
//
|
||||
// public void setCurrencyCode(String currencyCode) {
|
||||
// this.currencyCode = currencyCode;
|
||||
// }
|
||||
//
|
||||
// public Integer getDigitsAfterDecimalValue() {
|
||||
// return digitsAfterDecimalValue;
|
||||
// }
|
||||
//
|
||||
// public void setDigitsAfterDecimalValue(Integer digitsAfterDecimalValue) {
|
||||
// this.digitsAfterDecimalValue = digitsAfterDecimalValue;
|
||||
// }
|
||||
|
||||
public BigDecimal getPrincipalValue() {
|
||||
return principalValue;
|
||||
@@ -183,4 +182,12 @@ public class CalculateLoanScheduleCommand {
|
||||
LocalDate interestChargedFromLocalDate) {
|
||||
this.interestChargedFromLocalDate = interestChargedFromLocalDate;
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Long productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
}
|
||||
+4
-32
@@ -15,9 +15,6 @@ public class SubmitLoanApplicationCommand {
|
||||
|
||||
// product
|
||||
private String locale;
|
||||
private String currencyCode;
|
||||
private String digitsAfterDecimal;
|
||||
private Integer digitsAfterDecimalValue;
|
||||
private BigDecimal principalValue;
|
||||
private String principal;
|
||||
private BigDecimal inArrearsToleranceValue;
|
||||
@@ -63,8 +60,8 @@ public class SubmitLoanApplicationCommand {
|
||||
final LocalDate expectedDisbursementDate,
|
||||
final LocalDate repaymentsStartingFromDate,
|
||||
final LocalDate interestChargedFromLocalDate,
|
||||
final LoanSchedule loanSchedule, final String currencyCode,
|
||||
final Integer digitsAfterDecimal, final Number principal,
|
||||
final LoanSchedule loanSchedule,
|
||||
final Number principal,
|
||||
final Number interestRatePerPeriod, Integer interestRateFrequencyMethod, final Integer interestMethod, final Integer interestCalculationPeriodMethod,
|
||||
final Integer repaymentEvery, final Integer repaymentFrequency, final Integer numberOfRepayments, Integer amortizationMethod, final Number toleranceAmount) {
|
||||
this.clientId = clientId;
|
||||
@@ -77,8 +74,6 @@ public class SubmitLoanApplicationCommand {
|
||||
this.loanSchedule = loanSchedule;
|
||||
this.inArrearsToleranceValue = BigDecimal.valueOf(toleranceAmount.doubleValue());
|
||||
|
||||
this.currencyCode = currencyCode;
|
||||
this.digitsAfterDecimalValue = digitsAfterDecimal;
|
||||
this.principalValue = BigDecimal.valueOf(principal.doubleValue());
|
||||
this.interestRatePerPeriodValue = BigDecimal.valueOf(interestRatePerPeriod.doubleValue());
|
||||
this.interestRateFrequencyType = interestRateFrequencyMethod;
|
||||
@@ -91,7 +86,8 @@ public class SubmitLoanApplicationCommand {
|
||||
}
|
||||
|
||||
public CalculateLoanScheduleCommand toCalculateLoanScheduleCommand() {
|
||||
return new CalculateLoanScheduleCommand(currencyCode, digitsAfterDecimalValue, principalValue, interestRatePerPeriodValue, interestRateFrequencyType, interestType, interestCalculationPeriodType, repaymentEveryValue, repaymentFrequencyType, numberOfRepaymentsValue, amortizationType,
|
||||
return new CalculateLoanScheduleCommand(productId,
|
||||
principalValue, interestRatePerPeriodValue, interestRateFrequencyType, interestType, interestCalculationPeriodType, repaymentEveryValue, repaymentFrequencyType, numberOfRepaymentsValue, amortizationType,
|
||||
expectedDisbursementLocalDate, repaymentsStartingFromLocalDate, interestChargedFromLocalDate);
|
||||
}
|
||||
|
||||
@@ -127,14 +123,6 @@ public class SubmitLoanApplicationCommand {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public String getCurrencyCode() {
|
||||
return currencyCode;
|
||||
}
|
||||
|
||||
public void setCurrencyCode(String currencyCode) {
|
||||
this.currencyCode = currencyCode;
|
||||
}
|
||||
|
||||
public String getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
@@ -159,22 +147,6 @@ public class SubmitLoanApplicationCommand {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String getDigitsAfterDecimal() {
|
||||
return digitsAfterDecimal;
|
||||
}
|
||||
|
||||
public void setDigitsAfterDecimal(String digitsAfterDecimal) {
|
||||
this.digitsAfterDecimal = digitsAfterDecimal;
|
||||
}
|
||||
|
||||
public Integer getDigitsAfterDecimalValue() {
|
||||
return digitsAfterDecimalValue;
|
||||
}
|
||||
|
||||
public void setDigitsAfterDecimalValue(Integer digitsAfterDecimalValue) {
|
||||
this.digitsAfterDecimalValue = digitsAfterDecimalValue;
|
||||
}
|
||||
|
||||
public BigDecimal getPrincipalValue() {
|
||||
return principalValue;
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,8 +22,8 @@ public class CalculateLoanScheduleCommandValidator {
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
|
||||
|
||||
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
|
||||
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimalValue()).notNull().inMinMaxRange(0, 6);
|
||||
// baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
|
||||
// baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimalValue()).notNull().inMinMaxRange(0, 6);
|
||||
baseDataValidator.reset().parameter("principal").value(command.getPrincipalValue()).notNull().positiveAmount();
|
||||
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).notNull().inMinMaxRange(0, 3);
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEveryValue()).notNull().greaterThanZero();
|
||||
|
||||
+24
-4
@@ -1,5 +1,7 @@
|
||||
package org.mifosng.platform.loan.service;
|
||||
|
||||
import static org.mifosng.platform.Specifications.productThatMatches;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
@@ -12,18 +14,23 @@ import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.exceptions.CurrencyNotFoundException;
|
||||
import org.mifosng.platform.exceptions.LoanNotFoundException;
|
||||
import org.mifosng.platform.exceptions.LoanProductNotFoundException;
|
||||
import org.mifosng.platform.loan.domain.AmortizationMethod;
|
||||
import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod;
|
||||
import org.mifosng.platform.loan.domain.InterestMethod;
|
||||
import org.mifosng.platform.loan.domain.Loan;
|
||||
import org.mifosng.platform.loan.domain.LoanPayoffSummary;
|
||||
import org.mifosng.platform.loan.domain.LoanProduct;
|
||||
import org.mifosng.platform.loan.domain.LoanProductRelatedDetail;
|
||||
import org.mifosng.platform.loan.domain.LoanProductRepository;
|
||||
import org.mifosng.platform.loan.domain.LoanRepository;
|
||||
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
|
||||
import org.mifosng.platform.loanschedule.domain.AprCalculator;
|
||||
import org.mifosng.platform.loanschedule.domain.DefaultLoanScheduleGeneratorFactory;
|
||||
import org.mifosng.platform.loanschedule.domain.LoanScheduleGenerator;
|
||||
import org.mifosng.platform.loanschedule.domain.LoanScheduleGeneratorFactory;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -33,12 +40,18 @@ public class CalculationPlatformServiceImpl implements
|
||||
|
||||
private final LoanScheduleGeneratorFactory loanScheduleFactory;
|
||||
private final LoanRepository loanRepository;
|
||||
private final LoanProductRepository loanProductRepository;
|
||||
private final ApplicationCurrencyRepository applicationCurrencyRepository;
|
||||
private final AprCalculator aprCalculator;
|
||||
private final PlatformSecurityContext context;
|
||||
|
||||
@Autowired
|
||||
public CalculationPlatformServiceImpl(final LoanRepository loanRepository, final ApplicationCurrencyRepository applicationCurrencyRepository, final AprCalculator aprCalculator) {
|
||||
public CalculationPlatformServiceImpl(final PlatformSecurityContext context,
|
||||
final LoanRepository loanRepository, final LoanProductRepository loanProductRepository,
|
||||
final ApplicationCurrencyRepository applicationCurrencyRepository, final AprCalculator aprCalculator) {
|
||||
this.context = context;
|
||||
this.loanRepository = loanRepository;
|
||||
this.loanProductRepository = loanProductRepository;
|
||||
this.applicationCurrencyRepository = applicationCurrencyRepository;
|
||||
this.aprCalculator = aprCalculator;
|
||||
this.loanScheduleFactory = new DefaultLoanScheduleGeneratorFactory();
|
||||
@@ -47,6 +60,8 @@ public class CalculationPlatformServiceImpl implements
|
||||
@Override
|
||||
public LoanSchedule calculateLoanSchedule(final CalculateLoanScheduleCommand command) {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
CalculateLoanScheduleCommandValidator validator = new CalculateLoanScheduleCommandValidator(command);
|
||||
validator.validate();
|
||||
|
||||
@@ -62,7 +77,12 @@ public class CalculationPlatformServiceImpl implements
|
||||
|
||||
final BigDecimal defaultAnnualNominalInterestRate = this.aprCalculator.calculateFrom(interestPeriodFrequencyType, defaultNominalInterestRatePerPeriod);
|
||||
|
||||
final MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimalValue());
|
||||
LoanProduct loanProduct = this.loanProductRepository.findOne(productThatMatches(currentUser.getOrganisation(), command.getProductId()));
|
||||
if (loanProduct == null) {
|
||||
throw new LoanProductNotFoundException(command.getProductId());
|
||||
}
|
||||
|
||||
final MonetaryCurrency currency = loanProduct.getCurrency();
|
||||
|
||||
// in arrerars tolerance isnt relevant when auto-calculating a loan schedule
|
||||
final BigDecimal inArrearsTolerance = BigDecimal.ZERO;
|
||||
@@ -75,8 +95,8 @@ public class CalculationPlatformServiceImpl implements
|
||||
|
||||
LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory.create(interestMethod);
|
||||
|
||||
ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneByCode(command.getCurrencyCode());
|
||||
CurrencyData currencyData = new CurrencyData(applicationCurrency.getCode(), applicationCurrency.getName(), command.getDigitsAfterDecimalValue(),
|
||||
ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneByCode(currency.getCode());
|
||||
CurrencyData currencyData = new CurrencyData(applicationCurrency.getCode(), applicationCurrency.getName(), currency.getDigitsAfterDecimal(),
|
||||
applicationCurrency.getDisplaySymbol(), applicationCurrency.getNameCode());
|
||||
|
||||
return loanScheduleGenerator.generate(loanScheduleInfo, command.getExpectedDisbursementLocalDate(), command.getRepaymentsStartingFromLocalDate(),
|
||||
|
||||
@@ -60,9 +60,7 @@ public class LoanAssembler {
|
||||
throw new ClientNotFoundException(command.getClientId());
|
||||
}
|
||||
|
||||
// FIXME - should probably fetch applicationCurrency with currencycode to check its validity.
|
||||
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimalValue());
|
||||
|
||||
MonetaryCurrency currency = loanProduct.getCurrency();
|
||||
final BigDecimal defaultNominalInterestRatePerPeriod = command.getInterestRatePerPeriodValue();
|
||||
final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyType());
|
||||
|
||||
|
||||
+5
-3
@@ -266,8 +266,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
LocalDate interestCalculatedFromDate = loan.getInterestChargedFromDate();
|
||||
|
||||
Number principalAsDecimal = loan.getLoanRepaymentScheduleDetail().getPrincipal().getAmount();
|
||||
String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode();
|
||||
int currencyDigits = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyDigitsAfterDecimal();
|
||||
// String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode();
|
||||
// int currencyDigits = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyDigitsAfterDecimal();
|
||||
|
||||
Number interestRatePerYear = loan.getLoanRepaymentScheduleDetail().getAnnualNominalInterestRate();
|
||||
Integer numberOfInstallments = loan.getLoanRepaymentScheduleDetail().getNumberOfRepayments();
|
||||
@@ -283,7 +283,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
Integer interestMethod = loan.getLoanRepaymentScheduleDetail().getInterestMethod().getValue();
|
||||
Integer interestCalculationInPeriod = loan.getLoanRepaymentScheduleDetail().getInterestCalculationPeriodMethod().getValue();
|
||||
|
||||
CalculateLoanScheduleCommand calculateCommand = new CalculateLoanScheduleCommand(currencyCode, currencyDigits, principalAsDecimal,
|
||||
CalculateLoanScheduleCommand calculateCommand = new CalculateLoanScheduleCommand(
|
||||
loan.getLoanProduct().getId(),
|
||||
principalAsDecimal,
|
||||
interestRatePerPeriod, interestRateFrequencyMethod, interestMethod, interestCalculationInPeriod,
|
||||
repaidEvery, selectedRepaymentFrequency, numberOfInstallments,
|
||||
selectedRepaymentSchedule, actualDisbursementDate, repaymentsStartingFromDate, interestCalculatedFromDate);
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class SubmitLoanApplicationCommandValidator {
|
||||
try {
|
||||
// reuse calculate loan schedule validator for now
|
||||
CalculateLoanScheduleCommand calculateLoanScheduleCommand = new CalculateLoanScheduleCommand(
|
||||
command.getCurrencyCode(), command.getDigitsAfterDecimalValue(),
|
||||
command.getProductId(),
|
||||
command.getPrincipalValue(), command.getInterestRatePerPeriodValue(),
|
||||
command.getInterestRateFrequencyType(),
|
||||
command.getInterestType(), command.getInterestCalculationPeriodType(),
|
||||
|
||||
Reference in New Issue
Block a user