getAvailableInterest for withdrawal
This commit is contained in:
+2
-4
@@ -72,7 +72,7 @@ public class DepositAccountsApiResource {
|
||||
"interestCompoundedEvery","interestCompoundingAllowed",
|
||||
"interestCompoundedEveryPeriodType", "renewalAllowed",
|
||||
"preClosureAllowed", "preClosureInterestRate",
|
||||
"withdrawnonDate","rejectedonDate","closedonDate","transactions","interestPaid","isInterestWithdrawable"));
|
||||
"withdrawnonDate","rejectedonDate","closedonDate","transactions","interestPaid","isInterestWithdrawable","availableInterestForWithdrawal"));
|
||||
|
||||
|
||||
@POST
|
||||
@@ -112,7 +112,6 @@ public class DepositAccountsApiResource {
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
|
||||
DepositPermissionData permissions = null;
|
||||
BigDecimal availableInterestForWithdrawal = null;
|
||||
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
@@ -129,12 +128,11 @@ public class DepositAccountsApiResource {
|
||||
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (!associationParameters.isEmpty()) {
|
||||
if (associationParameters.contains("all")) {
|
||||
responseParameters.addAll(Arrays.asList("permissions","availableInterestForWithdrawal"));
|
||||
responseParameters.addAll(Arrays.asList("permissions"));
|
||||
} else {
|
||||
responseParameters.addAll(associationParameters);
|
||||
}
|
||||
permissions = this.depositAccountReadPlatformService.retrieveDepositAccountsPermissions(account);
|
||||
availableInterestForWithdrawal = this.depositAccountReadPlatformService.retrieveAvailableInterestForWithdrawal(account);
|
||||
account = new DepositAccountData(account, permissions, account.getTransactions());
|
||||
}
|
||||
|
||||
|
||||
+22
-1
@@ -6,6 +6,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.Months;
|
||||
|
||||
/**
|
||||
* Immutable data object for deposit accounts.
|
||||
@@ -51,6 +52,7 @@ public class DepositAccountData {
|
||||
|
||||
private final Collection<DepositAccountTransactionData> transactions;
|
||||
private final DepositPermissionData permissions;
|
||||
private final BigDecimal availableInterestForWithdrawal;
|
||||
|
||||
/*
|
||||
* 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.isInterestWithdrawable=false;
|
||||
this.interestCompoundingAllowed = true;
|
||||
this.availableInterestForWithdrawal = new BigDecimal(0);
|
||||
}
|
||||
|
||||
public DepositAccountData(
|
||||
@@ -141,6 +144,7 @@ public class DepositAccountData {
|
||||
this.interestPaid=account.getInterestPaid();
|
||||
this.isInterestWithdrawable=account.isInterestWithdrawable();
|
||||
this.interestCompoundingAllowed=account.isInterestCompoundingAllowed();
|
||||
this.availableInterestForWithdrawal=new BigDecimal(0);
|
||||
}
|
||||
|
||||
public DepositAccountData(final DepositAccountData account, final DepositPermissionData permissions, final Collection<DepositAccountTransactionData> transactions) {
|
||||
@@ -180,6 +184,7 @@ public class DepositAccountData {
|
||||
this.interestPaid=account.getInterestPaid();
|
||||
this.isInterestWithdrawable=account.isInterestWithdrawable();
|
||||
this.interestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
||||
this.availableInterestForWithdrawal=getAvailableInterestForWithdrawal(account);;
|
||||
}
|
||||
|
||||
public DepositAccountData(
|
||||
@@ -248,6 +253,7 @@ public class DepositAccountData {
|
||||
this.interestPaid =interestPaid;
|
||||
this.isInterestWithdrawable=isInterestWithdrawable;
|
||||
this.interestCompoundingAllowed = interestCompoundingAllowed;
|
||||
this.availableInterestForWithdrawal = new BigDecimal(0);
|
||||
}
|
||||
|
||||
public DepositAccountData(
|
||||
@@ -300,6 +306,7 @@ public class DepositAccountData {
|
||||
this.interestPaid=null;
|
||||
this.isInterestWithdrawable=false;
|
||||
this.interestCompoundingAllowed=interestCompoundingAllowed;
|
||||
this.availableInterestForWithdrawal= new BigDecimal(0);
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -433,5 +440,19 @@ public class DepositAccountData {
|
||||
public boolean isInterestCompoundingAllowed() {
|
||||
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.exceptions.DepositAccountNotFoundException;
|
||||
import org.mifosng.platform.exceptions.DepositAccountReopenException;
|
||||
import org.mifosng.platform.exceptions.DepositAccountTransactionsException;
|
||||
import org.mifosng.platform.exceptions.NoAuthorizationException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosng.platform.exceptions.ProductNotFoundException;
|
||||
@@ -349,11 +350,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
BigDecimal remainInterestForWithdrawal = totalAvailableInterestForWithdrawal.subtract(interestPaid);
|
||||
|
||||
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()));
|
||||
this.depositAccountRepository.save(account);
|
||||
}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();
|
||||
}*/
|
||||
}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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user