diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java index 69107b482..d7cd0b957 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java @@ -231,7 +231,9 @@ public class ClientsApiResource { Set typicalResponseParameters = new HashSet( Arrays.asList("pendingApprovalLoans", "awaitingDisbursalLoans", "openLoans", "closedLoans", "anyLoanCount", "pendingApprovalLoanCount", "awaitingDisbursalLoanCount", "activeLoanCount", "closedLoanCount", - "pendingApprovalDespositAccountsCount", "pendingApprovalDespositAccounts", "approvedDespositAccountsCount", "approvedDespositAccounts") + "pendingApprovalDespositAccountsCount", "pendingApprovalDespositAccounts", "approvedDespositAccountsCount", "approvedDespositAccounts", + "withdrawnByClientDespositAccountsCount","withdrawnByClientDespositAccounts","closedDepositAccountsCount","closedDepositAccounts", + "rejectedDepositAccountsCount","rejectedDepositAccounts","preclosedDepositAccountsCount","preclosedDepositAccounts") ); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java index 43edf4c79..942973320 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java @@ -1,5 +1,6 @@ package org.mifosng.platform.api; +import java.math.BigDecimal; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -111,6 +112,7 @@ public class DepositAccountsApiResource { Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); DepositPermissionData permissions = null; + BigDecimal availableInterestForWithdrawal = null; if (responseParameters.isEmpty()) { responseParameters.addAll(typicalResponseParameters); @@ -127,11 +129,12 @@ public class DepositAccountsApiResource { Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); if (!associationParameters.isEmpty()) { if (associationParameters.contains("all")) { - responseParameters.addAll(Arrays.asList("permissions")); + responseParameters.addAll(Arrays.asList("permissions","availableInterestForWithdrawal")); } else { responseParameters.addAll(associationParameters); } permissions = this.depositAccountReadPlatformService.retrieveDepositAccountsPermissions(account); + availableInterestForWithdrawal = this.depositAccountReadPlatformService.retrieveAvailableInterestForWithdrawal(account); account = new DepositAccountData(account, permissions, account.getTransactions()); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientAccountSummaryCollectionData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientAccountSummaryCollectionData.java index 912ab570a..b73000d23 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientAccountSummaryCollectionData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientAccountSummaryCollectionData.java @@ -20,6 +20,14 @@ public class ClientAccountSummaryCollectionData { private final List pendingApprovalDepositAccounts; private final int approvedDespositAccountsCount; private final List approvedDepositAccounts; + private final int withdrawnByClientDespositAccountsCount; + private final List withdrawnByClientDespositAccounts; + private final int closedDepositAccountsCount; + private final List closedDepositAccounts; + private final int rejectedDepositAccountsCount; + private final List rejectedDepositAccounts; + private final int preclosedDepositAccountsCount; + private final List preclosedDepositAccounts; public ClientAccountSummaryCollectionData( final List pendingApprovalLoans, @@ -27,13 +35,21 @@ public class ClientAccountSummaryCollectionData { final List openLoans, final List closedLoans, final List pendingApprovalDepositAccounts, - final List approvedDepositAccounts) { + final List approvedDepositAccounts, + final List withdrawnByClientDespositAccounts, + final List rejectedDepositAccounts, + final List closedDepositAccounts, + final List preclosedDepositAccounts) { this.pendingApprovalLoans = pendingApprovalLoans; this.awaitingDisbursalLoans = awaitingDisbursalLoans; this.openLoans = openLoans; this.closedLoans = closedLoans; this.pendingApprovalDepositAccounts = pendingApprovalDepositAccounts; this.approvedDepositAccounts = approvedDepositAccounts; + this.withdrawnByClientDespositAccounts = withdrawnByClientDespositAccounts; + this.closedDepositAccounts = closedDepositAccounts; + this.rejectedDepositAccounts = rejectedDepositAccounts; + this.preclosedDepositAccounts = preclosedDepositAccounts; this.pendingApprovalLoanCount = this.pendingApprovalLoans.size(); this.awaitingDisbursalLoanCount = this.awaitingDisbursalLoans.size(); @@ -43,6 +59,11 @@ public class ClientAccountSummaryCollectionData { this.pendingApprovalDespositAccountsCount = this.pendingApprovalDepositAccounts.size(); this.approvedDespositAccountsCount = this.approvedDepositAccounts.size(); + this.withdrawnByClientDespositAccountsCount = this.withdrawnByClientDespositAccounts.size(); + this.closedDepositAccountsCount = this.closedDepositAccounts.size(); + this.rejectedDepositAccountsCount = this.rejectedDepositAccounts.size(); + this.preclosedDepositAccountsCount = this.preclosedDepositAccounts.size(); + } public int getAnyLoanCount() { @@ -96,4 +117,36 @@ public class ClientAccountSummaryCollectionData { public List getApprovedDepositAccounts() { return approvedDepositAccounts; } + + public int getWithdrawnByClientDespositAccountsCount() { + return withdrawnByClientDespositAccountsCount; + } + + public List getWithdrawnByClientDespositAccounts() { + return withdrawnByClientDespositAccounts; + } + + public int getClosedDepositAccountsCount() { + return closedDepositAccountsCount; + } + + public List getClosedDepositAccounts() { + return closedDepositAccounts; + } + + public int getRejectedDepositAccountsCount() { + return rejectedDepositAccountsCount; + } + + public List getRejectedDepositAccounts() { + return rejectedDepositAccounts; + } + + public int getPreclosedDepositAccountsCount() { + return preclosedDepositAccountsCount; + } + + public List getPreclosedDepositAccounts() { + return preclosedDepositAccounts; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java index 605a72524..8e812bc94 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java @@ -262,7 +262,8 @@ public class DepositAccountData { final EnumOptionData interestCompoundedEveryPeriodType, final boolean renewalAllowed, final boolean preClosureAllowed, - final BigDecimal preClosureInterestRate) { + final BigDecimal preClosureInterestRate, + final boolean interestCompoundingAllowed) { this.id=null; this.externalId = null; this.status = null; @@ -298,7 +299,7 @@ public class DepositAccountData { this.permissions = null; this.interestPaid=null; this.isInterestWithdrawable=false; - this.interestCompoundingAllowed=true; + this.interestCompoundingAllowed=interestCompoundingAllowed; } public Long getId() { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositPermissionData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositPermissionData.java index b3637f4e5..fedcf8b6b 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositPermissionData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositPermissionData.java @@ -6,17 +6,18 @@ public class DepositPermissionData { private final boolean withdrawnByApplicantAllowed; private final boolean undoApprovalAllowed; private final boolean pendingApproval; - //private final boolean isActive; + private final boolean isInterestWithdrawalAllowed; private final boolean anyActionOnAccountAllowed; - public DepositPermissionData(final boolean rejectAllowed,final boolean withdrawnByApplicantAllowed,final boolean undoApprovalAllowed,final boolean pendingApproval) { + public DepositPermissionData(final boolean rejectAllowed,final boolean withdrawnByApplicantAllowed,final boolean undoApprovalAllowed,final boolean pendingApproval,final boolean interestWithdrawalAllowed) { this.rejectAllowed = rejectAllowed; this.withdrawnByApplicantAllowed = withdrawnByApplicantAllowed; this.undoApprovalAllowed = undoApprovalAllowed; this.pendingApproval = pendingApproval; - this.anyActionOnAccountAllowed = isRejectAllowed() || isPendingApproval() || isUndoApprovalAllowed() || isWithdrawnByApplicantAllowed(); + this.isInterestWithdrawalAllowed = interestWithdrawalAllowed; + this.anyActionOnAccountAllowed = isRejectAllowed() || isPendingApproval() || isUndoApprovalAllowed() || isWithdrawnByApplicantAllowed() || isInterestWithdrawalAllowed(); } public boolean isRejectAllowed() { @@ -39,7 +40,7 @@ public class DepositPermissionData { return anyActionOnAccountAllowed; } - /*public boolean isActive() { - return isActive; - }*/ + public boolean isInterestWithdrawalAllowed() { + return isInterestWithdrawalAllowed; + } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java index 005dc5d31..5cdbd2c5b 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java @@ -109,8 +109,8 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ "interestCompoundedEvery", "interestCompoundedEveryPeriodType", "renewalAllowed","preClosureAllowed","preClosureInterestRate", "withdrawnonDate","rejectedonDate","closedonDate","transactions", - "permissions","isInterestWithdrawable","interestPaid","interestCompoundingAllowed" - ) + "permissions","isInterestWithdrawable","interestPaid","interestCompoundingAllowed", + "availableInterestForWithdrawal") ); private static final Set CLIENT_DATA_PARAMETERS = new HashSet( @@ -125,7 +125,11 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ "activeLoanCount", "closedLoanCount", "pendingApprovalDespositAccountsCount", "pendingApprovalDespositAccounts", - "approvedDespositAccountsCount", "approvedDespositAccounts")); + "approvedDespositAccountsCount", "approvedDespositAccounts", + "withdrawnByClientDespositAccountsCount","withdrawnByClientDespositAccounts", + "closedDepositAccountsCount","closedDepositAccounts", + "rejectedDepositAccountsCount","rejectedDepositAccounts", + "preclosedDepositAccountsCount","preclosedDepositAccounts")); private static final Set GROUP_DATA_PARAMETERS = new HashSet( Arrays.asList("id", "name", "externalId", "clientMembers", diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java index 664c496fc..26df06a60 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java @@ -196,8 +196,10 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService List pendingApprovalDepositAccounts = new ArrayList(); List approvedDepositAccounts = new ArrayList(); -// List openDepositAccounts = new ArrayList(); -// List closedDepositAccounts = new ArrayList(); + List withdrawnByClientDespositAccounts = new ArrayList(); + List closedDepositAccounts = new ArrayList(); + List rejectedDepositAccounts = new ArrayList(); + List preclosedDepositAccounts = new ArrayList(); ClientDespoitAccountSummaryDataMapper depositAccountMapper = new ClientDespoitAccountSummaryDataMapper(); @@ -210,12 +212,21 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService pendingApprovalDepositAccounts.add(row); } else if (row.getAccountStatusId() == 300) { approvedDepositAccounts.add(row); - } + } else if (row.getAccountStatusId() == 400) { + withdrawnByClientDespositAccounts.add(row); + } else if (row.getAccountStatusId() == 500) { + rejectedDepositAccounts.add(row); + } else if (row.getAccountStatusId() == 600) { + closedDepositAccounts.add(row); + } else if (row.getAccountStatusId() == 800) { + preclosedDepositAccounts.add(row); + } } } return new ClientAccountSummaryCollectionData(pendingApprovalLoans, awaitingDisbursalLoans, openLoans, closedLoans, - pendingApprovalDepositAccounts, approvedDepositAccounts); + pendingApprovalDepositAccounts, approvedDepositAccounts, withdrawnByClientDespositAccounts, + rejectedDepositAccounts,closedDepositAccounts,preclosedDepositAccounts); } catch (EmptyResultDataAccessException e) { throw new ClientNotFoundException(clientId); } 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 22e1c6c90..2a8f1453e 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 @@ -293,7 +293,7 @@ public class DepositAccount extends AbstractAuditableCustom { getInterestCompoundedFrequencyType()); } this.interestAccrued = futureValueOnMaturity.minus(getDeposit()).getAmount(); - this.total = this.interestCompoundingAllowed ? futureValueOnMaturity.getAmount() : getDeposit().getAmount(); + this.total = futureValueOnMaturity.getAmount(); DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.deposit(getDeposit(), getActualCommencementDate(),getAccuredInterest()); depositaccountTransaction.updateAccount(this); @@ -593,7 +593,7 @@ public class DepositAccount extends AbstractAuditableCustom { interestCompoundedEvery, this.product.getInterestCompoundedEveryPeriodType()); } - this.total = account.isInterestCompoundingAllowed()?accuredtotalAmount.getAmount():getDeposit().getAmount(); + this.total = account.isInterestCompoundingAllowed()?accuredtotalAmount.getAmount():BigDecimal.valueOf(accuredtotalAmount.getAmount().doubleValue()-this.interstPaid.doubleValue()); this.interestAccrued = accuredtotalAmount.minus(deposit).getAmount(); } @@ -605,6 +605,7 @@ public class DepositAccount extends AbstractAuditableCustom { depositAccountTransaction.updateAccount(this); this.depositaccountTransactions.add(depositAccountTransaction); this.interstPaid = this.interstPaid.add(interest.getAmount()); + this.total = this.total.subtract(this.interstPaid); } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java index 1edb6272e..f3e33d1a3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java @@ -1,5 +1,6 @@ package org.mifosng.platform.saving.service; +import java.math.BigDecimal; import java.util.Collection; import org.mifosng.platform.api.data.DepositAccountData; @@ -13,5 +14,7 @@ public interface DepositAccountReadPlatformService { DepositAccountData retrieveNewDepositAccountDetails(Long clientId, Long productId); - DepositPermissionData retrieveDepositAccountsPermissions(DepositAccountData depositAccountData); + DepositPermissionData retrieveDepositAccountsPermissions(DepositAccountData depositAccountData); + + BigDecimal retrieveAvailableInterestForWithdrawal(DepositAccountData account); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java index 44a0176c9..a43d79583 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java @@ -6,6 +6,7 @@ import java.sql.SQLException; import java.util.Collection; import org.joda.time.LocalDate; +import org.joda.time.Months; import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.CurrencyData; import org.mifosng.platform.api.data.DepositAccountData; @@ -122,7 +123,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead currency, selectedProduct.getMinimumBalance(), selectedProduct.getMaturityDefaultInterestRate(), selectedProduct.getTenureInMonths(), selectedProduct.getInterestCompoundedEvery(), selectedProduct.getInterestCompoundedEveryPeriodType(), selectedProduct.isRenewalAllowed(), selectedProduct.isPreClosureAllowed(), - selectedProduct.getPreClosureInterestRate()); + selectedProduct.getPreClosureInterestRate(),selectedProduct.isInterestCompoundingAllowed()); } else { accountData = DepositAccountData.createFrom(clientAccount.getId(), clientAccount.getDisplayName()); } @@ -256,7 +257,16 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead //boolean isActive = (depositAccountData.getStatus().getId().equals(300L)); boolean rejectAllowed = pendingApproval; boolean withdrawnByApplicantAllowed = pendingApproval; + boolean interestWithdrawAllowed = depositAccountData.isInterestWithdrawable(); - return new DepositPermissionData(rejectAllowed, withdrawnByApplicantAllowed, undoApprovalAllowed, pendingApproval); + return new DepositPermissionData(rejectAllowed, withdrawnByApplicantAllowed, undoApprovalAllowed, pendingApproval, interestWithdrawAllowed); + } + + @Override + public BigDecimal retrieveAvailableInterestForWithdrawal(DepositAccountData account) { + 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()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index ea9c0f6b5..546f86d09 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -336,7 +336,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); } - if(account.isInterestWithdrawable()){ + if(account.isInterestWithdrawable() && !account.isInterestCompoundingAllowed()){ /*BigDecimal interstGettingForPeriod = BigDecimal.valueOf(account.getAccuredInterest().getAmount().doubleValue()/new Double(account.getTenureInMonths())); LocalDate lastInterestTakenDate = getLastTxnDate(account); Integer noOfMonthsforInterestCal = Months.monthsBetween(lastInterestTakenDate, new LocalDate()).getMonths();