diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/PortfolioAccountDTO.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/PortfolioAccountDTO.java index b259ff16b..5b9be0b1c 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/PortfolioAccountDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/PortfolioAccountDTO.java @@ -22,6 +22,7 @@ public class PortfolioAccountDTO { private final Integer accountTypeId; private final Long clientId; + private Long groupId; private final String currencyCode; private final long[] accountStatus; private final Integer depositType; @@ -79,5 +80,13 @@ public class PortfolioAccountDTO { public boolean isExcludeOverDraftAccounts() { return this.excludeOverDraftAccounts; } + + public Long getGroupId() { + return this.groupId; + } + + public void setGroupId(final Long groupId) { + this.groupId = groupId; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/PortfolioAccountReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/PortfolioAccountReadPlatformServiceImpl.java index 0c323ddc1..dc4edb1e9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/PortfolioAccountReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/PortfolioAccountReadPlatformServiceImpl.java @@ -104,8 +104,8 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount @Override public Collection retrieveAllForLookup(final PortfolioAccountDTO portfolioAccountDTO) { - List sqlParams = new ArrayList<>(); - sqlParams.add(portfolioAccountDTO.getClientId()); + final List sqlParams = new ArrayList<>(); + //sqlParams.add(portfolioAccountDTO.getClientId()); Collection accounts = null; String sql = null; String defaultAccountStatus = "300"; @@ -120,8 +120,13 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount case INVALID: break; case LOAN: - sql = "select " + this.loanAccountMapper.schema() + " where la.client_id = ? and la.loan_status_id in (" - + defaultAccountStatus.toString() + ")"; + sql = "select " + this.loanAccountMapper.schema() + " where "; + if (portfolioAccountDTO.getClientId() != null) { + sql += " la.client_id = ? and la.loan_status_id in (" + defaultAccountStatus.toString() + ") "; + sqlParams.add(portfolioAccountDTO.getClientId()); + } else { + sql += " la.loan_status_id in (" + defaultAccountStatus.toString() + ") "; + } if (portfolioAccountDTO.getCurrencyCode() != null) { sql += " and la.currency_code = ?"; sqlParams.add(portfolioAccountDTO.getCurrencyCode()); @@ -130,8 +135,13 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount accounts = this.jdbcTemplate.query(sql, this.loanAccountMapper, sqlParams.toArray()); break; case SAVINGS: - sql = "select " + this.savingsAccountMapper.schema() + " where sa.client_id = ? and sa.status_enum in (" - + defaultAccountStatus.toString() + ")"; + sql = "select " + this.savingsAccountMapper.schema() + " where "; + if (portfolioAccountDTO.getClientId() != null) { + sql += " sa.client_id = ? and sa.status_enum in (" + defaultAccountStatus.toString() + ") "; + sqlParams.add(portfolioAccountDTO.getClientId()); + } else { + sql += " sa.status_enum in (" + defaultAccountStatus.toString() + ") "; + } if (portfolioAccountDTO.getCurrencyCode() != null) { sql += " and sa.currency_code = ?"; sqlParams.add(portfolioAccountDTO.getCurrencyCode()); @@ -145,7 +155,12 @@ public class PortfolioAccountReadPlatformServiceImpl implements PortfolioAccount if(portfolioAccountDTO.isExcludeOverDraftAccounts()){ sql += " and sa.allow_overdraft = 0"; } - + + if(portfolioAccountDTO.getClientId() == null && portfolioAccountDTO.getGroupId() != null){ + sql += " and sa.group_id = ? "; + sqlParams.add(portfolioAccountDTO.getGroupId()); + } + accounts = this.jdbcTemplate.query(sql, this.savingsAccountMapper, sqlParams.toArray()); break; default: diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java index bded4157b..8da89c094 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java @@ -267,6 +267,7 @@ public class LoansApiResource { Collection calendarOptions = null; LoanAccountData newLoanAccount = null; Long officeId = null; + Collection accountLinkingOptions = null; if (productId != null) { newLoanAccount = this.loanReadPlatformService.retrieveLoanProductDetailsTemplate(productId, clientId, groupId); @@ -306,6 +307,7 @@ public class LoansApiResource { calendarOptions = this.loanReadPlatformService.retrieveCalendars(groupId); newLoanAccount = newLoanAccount == null ? loanAccountGroupData : LoanAccountData.populateGroupDefaults(newLoanAccount, loanAccountGroupData); + accountLinkingOptions = getaccountLinkingOptions(newLoanAccount, clientId, groupId); } else if (templateType.equals("jlgbulk")) { // get group details along with members in that group @@ -317,9 +319,11 @@ public class LoansApiResource { if (productId != null) { Map memberLoanCycle = new HashMap<>(); Collection members = loanAccountGroupData.groupData().clientMembers(); + accountLinkingOptions = new ArrayList<>(); for (ClientData clientData : members) { Integer loanCounter = this.loanReadPlatformService.retriveLoanCounter(clientData.id(), productId); memberLoanCycle.put(clientData.id(), loanCounter); + accountLinkingOptions.addAll(getaccountLinkingOptions(newLoanAccount, clientData.id(), groupId)); } newLoanAccount = LoanAccountData.associateMemberVariations(newLoanAccount, memberLoanCycle); } @@ -331,18 +335,8 @@ public class LoansApiResource { allowedLoanOfficers = this.loanReadPlatformService.retrieveAllowedLoanOfficers(officeId, staffInSelectedOfficeOnly); - Collection accountLinkingOptions = null; if (clientId != null) { - final CurrencyData currencyData = newLoanAccount.currency(); - String currencyCode = null; - if (currencyData != null) { - currencyCode = currencyData.code(); - } - final long[] accountStatus = { SavingsAccountStatusType.ACTIVE.getValue() }; - PortfolioAccountDTO portfolioAccountDTO = new PortfolioAccountDTO(PortfolioAccountType.SAVINGS.getValue(), clientId, - currencyCode, accountStatus, DepositAccountType.SAVINGS_DEPOSIT.getValue()); - accountLinkingOptions = this.portfolioAccountReadPlatformService.retrieveAllForLookup(portfolioAccountDTO); - + accountLinkingOptions = getaccountLinkingOptions(newLoanAccount, clientId, groupId); } // add product options, allowed loan officers and calendar options @@ -358,6 +352,22 @@ public class LoansApiResource { return this.toApiJsonSerializer.serialize(settings, newLoanAccount, this.LOAN_DATA_PARAMETERS); } + private Collection getaccountLinkingOptions(final LoanAccountData newLoanAccount, final Long clientId, + final Long groupId) { + final CurrencyData currencyData = newLoanAccount.currency(); + String currencyCode = null; + if (currencyData != null) { + currencyCode = currencyData.code(); + } + final long[] accountStatus = { SavingsAccountStatusType.ACTIVE.getValue() }; + final PortfolioAccountDTO portfolioAccountDTO = new PortfolioAccountDTO(PortfolioAccountType.SAVINGS.getValue(), clientId, currencyCode, + accountStatus, DepositAccountType.SAVINGS_DEPOSIT.getValue()); + if (groupId != null) { + portfolioAccountDTO.setGroupId(groupId); + } + return this.portfolioAccountReadPlatformService.retrieveAllForLookup(portfolioAccountDTO); + } + @GET @Path("{loanId}") @Consumes({ MediaType.APPLICATION_JSON })