getAvailableInterest for withdrawal
This commit is contained in:
+2
-4
@@ -72,7 +72,7 @@ public class DepositAccountsApiResource {
|
|||||||
"interestCompoundedEvery","interestCompoundingAllowed",
|
"interestCompoundedEvery","interestCompoundingAllowed",
|
||||||
"interestCompoundedEveryPeriodType", "renewalAllowed",
|
"interestCompoundedEveryPeriodType", "renewalAllowed",
|
||||||
"preClosureAllowed", "preClosureInterestRate",
|
"preClosureAllowed", "preClosureInterestRate",
|
||||||
"withdrawnonDate","rejectedonDate","closedonDate","transactions","interestPaid","isInterestWithdrawable"));
|
"withdrawnonDate","rejectedonDate","closedonDate","transactions","interestPaid","isInterestWithdrawable","availableInterestForWithdrawal"));
|
||||||
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@@ -112,7 +112,6 @@ public class DepositAccountsApiResource {
|
|||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
DepositPermissionData permissions = null;
|
DepositPermissionData permissions = null;
|
||||||
BigDecimal availableInterestForWithdrawal = null;
|
|
||||||
|
|
||||||
if (responseParameters.isEmpty()) {
|
if (responseParameters.isEmpty()) {
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
@@ -129,12 +128,11 @@ public class DepositAccountsApiResource {
|
|||||||
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
if (associationParameters.contains("all")) {
|
if (associationParameters.contains("all")) {
|
||||||
responseParameters.addAll(Arrays.asList("permissions","availableInterestForWithdrawal"));
|
responseParameters.addAll(Arrays.asList("permissions"));
|
||||||
} else {
|
} else {
|
||||||
responseParameters.addAll(associationParameters);
|
responseParameters.addAll(associationParameters);
|
||||||
}
|
}
|
||||||
permissions = this.depositAccountReadPlatformService.retrieveDepositAccountsPermissions(account);
|
permissions = this.depositAccountReadPlatformService.retrieveDepositAccountsPermissions(account);
|
||||||
availableInterestForWithdrawal = this.depositAccountReadPlatformService.retrieveAvailableInterestForWithdrawal(account);
|
|
||||||
account = new DepositAccountData(account, permissions, account.getTransactions());
|
account = new DepositAccountData(account, permissions, account.getTransactions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
import org.joda.time.Months;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable data object for deposit accounts.
|
* Immutable data object for deposit accounts.
|
||||||
@@ -51,6 +52,7 @@ public class DepositAccountData {
|
|||||||
|
|
||||||
private final Collection<DepositAccountTransactionData> transactions;
|
private final Collection<DepositAccountTransactionData> transactions;
|
||||||
private final DepositPermissionData permissions;
|
private final DepositPermissionData permissions;
|
||||||
|
private final BigDecimal availableInterestForWithdrawal;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* used when returning account template data but only a clientId is passed, no selected product.
|
* used when returning account template data but only a clientId is passed, no selected product.
|
||||||
@@ -99,6 +101,7 @@ public class DepositAccountData {
|
|||||||
this.interestPaid=null;
|
this.interestPaid=null;
|
||||||
this.isInterestWithdrawable=false;
|
this.isInterestWithdrawable=false;
|
||||||
this.interestCompoundingAllowed = true;
|
this.interestCompoundingAllowed = true;
|
||||||
|
this.availableInterestForWithdrawal = new BigDecimal(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositAccountData(
|
public DepositAccountData(
|
||||||
@@ -141,6 +144,7 @@ public class DepositAccountData {
|
|||||||
this.interestPaid=account.getInterestPaid();
|
this.interestPaid=account.getInterestPaid();
|
||||||
this.isInterestWithdrawable=account.isInterestWithdrawable();
|
this.isInterestWithdrawable=account.isInterestWithdrawable();
|
||||||
this.interestCompoundingAllowed=account.isInterestCompoundingAllowed();
|
this.interestCompoundingAllowed=account.isInterestCompoundingAllowed();
|
||||||
|
this.availableInterestForWithdrawal=new BigDecimal(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositAccountData(final DepositAccountData account, final DepositPermissionData permissions, final Collection<DepositAccountTransactionData> transactions) {
|
public DepositAccountData(final DepositAccountData account, final DepositPermissionData permissions, final Collection<DepositAccountTransactionData> transactions) {
|
||||||
@@ -180,6 +184,7 @@ public class DepositAccountData {
|
|||||||
this.interestPaid=account.getInterestPaid();
|
this.interestPaid=account.getInterestPaid();
|
||||||
this.isInterestWithdrawable=account.isInterestWithdrawable();
|
this.isInterestWithdrawable=account.isInterestWithdrawable();
|
||||||
this.interestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
this.interestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
||||||
|
this.availableInterestForWithdrawal=getAvailableInterestForWithdrawal(account);;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositAccountData(
|
public DepositAccountData(
|
||||||
@@ -248,6 +253,7 @@ public class DepositAccountData {
|
|||||||
this.interestPaid =interestPaid;
|
this.interestPaid =interestPaid;
|
||||||
this.isInterestWithdrawable=isInterestWithdrawable;
|
this.isInterestWithdrawable=isInterestWithdrawable;
|
||||||
this.interestCompoundingAllowed = interestCompoundingAllowed;
|
this.interestCompoundingAllowed = interestCompoundingAllowed;
|
||||||
|
this.availableInterestForWithdrawal = new BigDecimal(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositAccountData(
|
public DepositAccountData(
|
||||||
@@ -300,6 +306,7 @@ public class DepositAccountData {
|
|||||||
this.interestPaid=null;
|
this.interestPaid=null;
|
||||||
this.isInterestWithdrawable=false;
|
this.isInterestWithdrawable=false;
|
||||||
this.interestCompoundingAllowed=interestCompoundingAllowed;
|
this.interestCompoundingAllowed=interestCompoundingAllowed;
|
||||||
|
this.availableInterestForWithdrawal= new BigDecimal(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@@ -434,4 +441,18 @@ public class DepositAccountData {
|
|||||||
return interestCompoundingAllowed;
|
return interestCompoundingAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAvailableInterestForWithdrawal() {
|
||||||
|
return availableInterestForWithdrawal;
|
||||||
|
}
|
||||||
|
public BigDecimal getAvailableInterestForWithdrawal(DepositAccountData account) {
|
||||||
|
if(account.getStatus().getId()==300){
|
||||||
|
BigDecimal interstGettingForPeriod = BigDecimal.valueOf(account.getActualInterestAccrued().doubleValue()/new Double(account.getTenureInMonths()));
|
||||||
|
Integer noOfMonthsforInterestCal = Months.monthsBetween(account.getActualCommencementDate(), new LocalDate()).getMonths();
|
||||||
|
Integer noOfPeriods = noOfMonthsforInterestCal / account.getInterestCompoundedEvery();
|
||||||
|
return BigDecimal.valueOf(interstGettingForPeriod.multiply(new BigDecimal(noOfPeriods)).doubleValue()-account.getInterestPaid().doubleValue());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return new BigDecimal(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package org.mifosng.platform.exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
public class DepositAccountTransactionsException extends AbstractPlatformDomainRuleException {
|
||||||
|
|
||||||
|
public DepositAccountTransactionsException(String remainInterestForWithdrawal) {
|
||||||
|
super("deposit.transaction.interest.withdrawal.exception", "You can Withdraw "+remainInterestForWithdrawal+" only", remainInterestForWithdrawal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+4
-3
@@ -21,6 +21,7 @@ import org.mifosng.platform.client.domain.NoteRepository;
|
|||||||
import org.mifosng.platform.currency.domain.Money;
|
import org.mifosng.platform.currency.domain.Money;
|
||||||
import org.mifosng.platform.exceptions.DepositAccountNotFoundException;
|
import org.mifosng.platform.exceptions.DepositAccountNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.DepositAccountReopenException;
|
import org.mifosng.platform.exceptions.DepositAccountReopenException;
|
||||||
|
import org.mifosng.platform.exceptions.DepositAccountTransactionsException;
|
||||||
import org.mifosng.platform.exceptions.NoAuthorizationException;
|
import org.mifosng.platform.exceptions.NoAuthorizationException;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
import org.mifosng.platform.exceptions.ProductNotFoundException;
|
import org.mifosng.platform.exceptions.ProductNotFoundException;
|
||||||
@@ -349,11 +350,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
BigDecimal remainInterestForWithdrawal = totalAvailableInterestForWithdrawal.subtract(interestPaid);
|
BigDecimal remainInterestForWithdrawal = totalAvailableInterestForWithdrawal.subtract(interestPaid);
|
||||||
|
|
||||||
if(remainInterestForWithdrawal.doubleValue() > 0){
|
if(remainInterestForWithdrawal.doubleValue() > 0){
|
||||||
if(remainInterestForWithdrawal.doubleValue() > command.getWithdrawInterest().doubleValue()){
|
if(remainInterestForWithdrawal.doubleValue() >= command.getWithdrawInterest().doubleValue()&&command.getWithdrawInterest().doubleValue()>0){
|
||||||
account.withdrawInterest(Money.of(account.getDeposit().getCurrency(), command.getWithdrawInterest()));
|
account.withdrawInterest(Money.of(account.getDeposit().getCurrency(), command.getWithdrawInterest()));
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
}else {
|
}else {
|
||||||
throw new RuntimeException("You can Withdraw "+remainInterestForWithdrawal+" only, \n please enter a valid amount for withdrawal");
|
throw new DepositAccountTransactionsException("You can Withdraw "+remainInterestForWithdrawal+" only");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -369,7 +370,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}*/
|
}*/
|
||||||
}else{
|
}else{
|
||||||
throw new RuntimeException("You can not withdraw interst for this account");
|
throw new DepositAccountTransactionsException("You can not withdraw interst for this account");
|
||||||
}
|
}
|
||||||
return new EntityIdentifier(account.getId());
|
return new EntityIdentifier(account.getId());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user