preClosureInterestRate For DepositAccount

This commit is contained in:
Madhukar
2012-09-07 15:53:00 +05:30
parent e3223536a2
commit c686d0d628
7 changed files with 51 additions and 10 deletions
@@ -17,6 +17,7 @@ public class DepositAccountCommand {
private final BigDecimal depositAmount;
private final BigDecimal maturityInterestRate;
private final BigDecimal preClosureInterestRate;
private final Integer tenureInMonths;
private final Integer interestCompoundedEvery;
@@ -34,7 +35,7 @@ public class DepositAccountCommand {
final Long productId,
final String externalId,
final BigDecimal depositAmount,
final BigDecimal interestRate,
final BigDecimal interestRate, final BigDecimal preClosureInterestRate,
final Integer tenureInMonths, final Integer compoundingInterestFrequency, final Integer compoundingInterestFrequencyType, final LocalDate commencementDate,
final boolean renewalAllowed, final boolean preClosureAllowed) {
this.id = id;
@@ -44,6 +45,7 @@ public class DepositAccountCommand {
this.depositAmount = depositAmount;
this.maturityInterestRate = interestRate;
this.preClosureInterestRate = preClosureInterestRate;
this.tenureInMonths = tenureInMonths;
this.modifiedParameters = modifiedParameters;
@@ -78,6 +80,10 @@ public class DepositAccountCommand {
return maturityInterestRate;
}
public BigDecimal getPreClosureInterestRate() {
return preClosureInterestRate;
}
public Integer getTenureInMonths() {
return tenureInMonths;
}
@@ -114,6 +120,10 @@ public class DepositAccountCommand {
return this.modifiedParameters.contains("interestRate");
}
public boolean isPreClosureInterestRateChanged(){
return this.modifiedParameters.contains("preClosureInterestRate");
}
public boolean isRenewalAllowedChanged() {
return this.modifiedParameters.contains("renewalAllowed");
}
@@ -1017,7 +1017,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
// preClosureInterestRate
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("clientId", "productId", "externalId", "deposit", "maturityInterestRate",
Arrays.asList("clientId", "productId", "externalId", "deposit", "maturityInterestRate", "preClosureInterestRate",
"tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", "commencementDate",
"renewalAllowed", "preClosureAllowed",
"locale", "dateFormat")
@@ -1030,6 +1030,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
String externalId = extractStringParameter("externalId", requestMap,modifiedParameters);
BigDecimal deposit=extractBigDecimalParameter("deposit", requestMap, modifiedParameters);
BigDecimal interestRate = extractBigDecimalParameter("maturityInterestRate", requestMap, modifiedParameters);
BigDecimal preClosureInterestRate = extractBigDecimalParameter("preClosureInterestRate", requestMap, modifiedParameters);
Integer tenureInMonths = extractIntegerParameter("tenureInMonths", requestMap, modifiedParameters);
Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters);
@@ -1040,7 +1041,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
boolean preClosureAllowed = extractBooleanParameter("preClosureAllowed", requestMap, modifiedParameters);
return new DepositAccountCommand(modifiedParameters, resourceIdentifier, clientId, productId,
externalId, deposit, interestRate, tenureInMonths,
externalId, deposit, interestRate, preClosureInterestRate, tenureInMonths,
interestCompoundedEvery, interestCompoundedEveryPeriodType, commencementDate, renewalAllowed, preClosureAllowed);
}
@@ -0,0 +1,12 @@
package org.mifosng.platform.exceptions;
import java.math.BigDecimal;
public class DepositAccounDataValidationtException extends
AbstractPlatformDomainRuleException {
public DepositAccounDataValidationtException(BigDecimal preClosureInterestRate, BigDecimal maturityMinInterestRate) {
super("error.msg.deposit.account.preClosureInterestRate.should.lessthanOrEqualTo.maturityMinInterestRate", "PreClosureInterestRate : "+preClosureInterestRate+"should lessthan or equal to maturityMinInterestRate : "+maturityMinInterestRate, preClosureInterestRate,maturityMinInterestRate);
}
}
@@ -138,7 +138,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
public DepositAccount openNew(
final Client client, final DepositProduct product,
final String externalId, final Money deposit, final BigDecimal maturityInterestRate, final Integer tenureInMonths,
final String externalId, final Money deposit, final BigDecimal maturityInterestRate, final BigDecimal preClosureInterestRate, final Integer tenureInMonths,
final Integer interestCompoundedEvery,
final PeriodFrequencyType interestCompoundedFrequencyPeriodType,
final LocalDate commencementDate,
@@ -159,7 +159,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CREATED, from);
depositStatus = statusEnum.getValue();
return new DepositAccount(client, product, externalId, deposit, maturityInterestRate, tenureInMonths,
return new DepositAccount(client, product, externalId, deposit, maturityInterestRate, preClosureInterestRate, tenureInMonths,
interestCompoundedEvery, interestCompoundedFrequencyPeriodType, commencementDate, renewalAllowed, preClosureAllowed, futureValueOnMaturity,depositStatus);
}
@@ -169,7 +169,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
public DepositAccount(
final Client client, final DepositProduct product,
final String externalId, final Money deposit, final BigDecimal interestRate, final Integer termInMonths,
final String externalId, final Money deposit, final BigDecimal interestRate, final BigDecimal preClosureInterestRate, final Integer termInMonths,
final Integer interestCompoundedEvery,
final PeriodFrequencyType interestCompoundedFrequencyPeriodType,
final LocalDate commencementDate,
@@ -197,7 +197,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
this.renewalAllowed = renewalAllowed;
this.preClosureAllowed = preClosureAllowed;
this.preClosureInterestRate = BigDecimal.ZERO;
this.preClosureInterestRate = preClosureInterestRate;
// derived fields
this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.minus(deposit).getAmount();
@@ -9,12 +9,13 @@ import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.exceptions.ClientNotFoundException;
import org.mifosng.platform.exceptions.DepositAccounDataValidationtException;
import org.mifosng.platform.exceptions.DepositProductNotFoundException;
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
import org.mifosng.platform.saving.domain.DepositAccount;
import org.mifosng.platform.saving.domain.DepositAccountStatus;
import org.mifosng.platform.saving.domain.DepositLifecycleStateMachine;
import org.mifosng.platform.saving.domain.DepositLifecycleStateMachineImpl;
import org.mifosng.platform.saving.domain.DepositAccountStatus;
import org.mifosng.platform.saving.domain.FixedTermDepositInterestCalculator;
import org.mifosng.platform.savingproduct.domain.DepositProduct;
import org.mifosng.platform.savingproduct.domain.DepositProductRepository;
@@ -63,6 +64,15 @@ public class DepositAccountAssembler {
if (command.getMaturityInterestRate() != null) {
maturityInterestRate = command.getMaturityInterestRate();
}
BigDecimal preClosureInterestRate = product.getPreClosureInterestRate();
if(command.getPreClosureInterestRate()!=null){
preClosureInterestRate = command.getPreClosureInterestRate();
}
if(product.getMaturityMinInterestRate().compareTo(preClosureInterestRate)==-1){
throw new DepositAccounDataValidationtException(preClosureInterestRate, product.getMaturityMinInterestRate());
}
Integer compoundingInterestEvery = product.getInterestCompoundedEvery();
if (command.getInterestCompoundedEvery() != null) {
@@ -87,7 +97,7 @@ public class DepositAccountAssembler {
DepositAccount account =new DepositAccount().openNew(client, product, command.getExternalId(),
deposit,
maturityInterestRate,
maturityInterestRate, preClosureInterestRate,
tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency,
command.getCommencementDate(),
renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, defaultDepositLifecycleStateMachine());
@@ -59,6 +59,7 @@ public class DepositAccountCommandValidator {
baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).ignoreIfNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("preClosureInterestRate").value(command.getPreClosureInterestRate()).ignoreIfNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero();
baseDataValidator.reset().parameter("interestCompoundedEvery").value(command.getInterestCompoundedEvery()).ignoreIfNull().integerGreaterThanZero();
@@ -69,7 +69,6 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "is_preclosure_allowed", nullable=false)
private boolean preClosureAllowed = false;
@SuppressWarnings("unused")
@Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false)
private BigDecimal preClosureInterestRate;
@@ -135,6 +134,14 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
return maturityDefaultInterestRate;
}
public BigDecimal getMaturityMinInterestRate() {
return maturityMinInterestRate;
}
public BigDecimal getPreClosureInterestRate() {
return preClosureInterestRate;
}
public boolean isRenewalAllowed() {
return this.renewalAllowed;
}