diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java index 28dbf438e..14c2c6539 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java @@ -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"); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java index 75b2e6c8a..533177e36 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java @@ -1017,7 +1017,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { // preClosureInterestRate Set supportedParams = new HashSet( - 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); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/DepositAccounDataValidationtException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/DepositAccounDataValidationtException.java new file mode 100644 index 000000000..d089b3fc9 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/DepositAccounDataValidationtException.java @@ -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); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java index ddd4f2c09..a5aa4a240 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java @@ -138,7 +138,7 @@ public class DepositAccount extends AbstractAuditableCustom { 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 { 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 { 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 { this.renewalAllowed = renewalAllowed; this.preClosureAllowed = preClosureAllowed; - this.preClosureInterestRate = BigDecimal.ZERO; + this.preClosureInterestRate = preClosureInterestRate; // derived fields this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.minus(deposit).getAmount(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountAssembler.java index c724fa0f2..17226c3ab 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountAssembler.java @@ -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()); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountCommandValidator.java index 8178f2859..7abe2027e 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountCommandValidator.java @@ -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(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/domain/DepositProduct.java b/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/domain/DepositProduct.java index 5f30bc370..512482f7c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/domain/DepositProduct.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/domain/DepositProduct.java @@ -69,7 +69,6 @@ public class DepositProduct extends AbstractAuditableCustom { @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 { return maturityDefaultInterestRate; } + public BigDecimal getMaturityMinInterestRate() { + return maturityMinInterestRate; + } + + public BigDecimal getPreClosureInterestRate() { + return preClosureInterestRate; + } + public boolean isRenewalAllowed() { return this.renewalAllowed; }