diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/SearchParameters.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/SearchParameters.java index 469cd9f1175..05ebcee45bb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/SearchParameters.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/SearchParameters.java @@ -129,7 +129,7 @@ public static SearchParameters forBlacklist(final String displayName, final Stri public static SearchParameters forPrequalification(final String displayName, final String status, final Integer offset, final Integer limit, final String orderBy, final String sortOrder, final String type, String searchText, - final String groupingType, Long portfolioCenterId) { + final String groupingType, Long portfolioCenterId, Long agencyId) { final Integer maxLimitAllowed = getCheckedLimit(limit); final Long staffId = null; @@ -139,7 +139,7 @@ public static SearchParameters forPrequalification(final String displayName, fin return new SearchParameters(searchText, null, null, displayName, null, null, null, status, offset, maxLimitAllowed, orderBy, sortOrder, staffId, accountNo, loanId, savingsId, null, false, null, type, null, null, null, groupingType, - portfolioCenterId); + portfolioCenterId,agencyId); } public static SearchParameters forBankCheques(final Long agencyId, final String chequeNo, final String bankAccNo, final Long batchId, @@ -622,7 +622,7 @@ private SearchParameters(final String sqlSearch, final Long officeId, final Stri final Integer limit, final String orderBy, final String sortOrder, final Long staffId, final String accountNo, final Long loanId, final Long savingsId, final Boolean orphansOnly, boolean isSelfUser, final String dpiNumber, final String type, final String groupName, final String groupNumber, final String centerName, final String groupingType, - Long portfolioCenterId) { + Long portfolioCenterId, Long agencyId) { this.sqlSearch = sqlSearch; this.officeId = officeId; this.externalId = externalId; @@ -659,7 +659,7 @@ private SearchParameters(final String sqlSearch, final Long officeId, final Stri this.disbursementStartDate = null; this.approvalEndDate = null; this.approvalStartDate = null; - this.agencyId = null; + this.agencyId = agencyId; this.clientNo = null; this.groupId = null; this.centerId = portfolioCenterId; diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/GroupPrequalificationApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/GroupPrequalificationApiResource.java index f0437332910..2019366dd4f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/GroupPrequalificationApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/GroupPrequalificationApiResource.java @@ -145,6 +145,7 @@ public String retrieveAllBlacklistItems(@Context final UriInfo uriInfo, @QueryParam("limit") @Parameter(description = "limit") final Integer limit, @QueryParam("orderBy") @Parameter(description = "orderBy") final String orderBy, @QueryParam("status") @Parameter(description = "status") final String status, + @QueryParam("agencyId") @Parameter(description = "agencyId") final Long agencyId, @QueryParam("type") @Parameter(description = "type") final String type, @QueryParam("portfolioCenterId") @Parameter(description = "type") final Long portfolioCenterId, @QueryParam("searchText") @Parameter(description = "searchText") final String searchText, @@ -157,7 +158,7 @@ public String retrieveAllBlacklistItems(@Context final UriInfo uriInfo, String clientName = queryParameters.getFirst("clientName"); SearchParameters searchParameters = SearchParameters.forPrequalification(clientName, status, offset, limit, orderBy, sortOrder, - type, searchText, groupingType, portfolioCenterId); + type, searchText, groupingType, portfolioCenterId, agencyId); final Page clientData = this.prequalificationReadPlatformService.retrieveAll(searchParameters); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(queryParameters); @@ -174,6 +175,7 @@ public String retrieveAllBlacklistItems(@Context final UriInfo uriInfo, public String newClientIdentifierDetails(@Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasViewPermission(this.resourceNameForPermissions); + final String hierarchy = this.context.authenticatedUser().getOffice().getHierarchy(); MultivaluedMap queryParameters = uriInfo.getQueryParameters(); @@ -183,7 +185,7 @@ public String newClientIdentifierDetails(@Context final UriInfo uriInfo) { Long agencyId = null; Long centerId = null; Collection centerData = null; - Collection agencies = null; + Collection agencies = this.agencyReadPlatformService.retrieveByOfficeHierarchy(hierarchy); Collection appUsers = null; Collection loanProducts = null; GlobalConfigurationPropertyData timespan = null; @@ -226,7 +228,6 @@ public String newClientIdentifierDetails(@Context final UriInfo uriInfo) { } } - final String hierarchy = this.context.authenticatedUser().getOffice().getHierarchy(); centerData = this.centerReadPlatformService.retrieveByOfficeHierarchy(hierarchy, agencyId); agencies = this.agencyReadPlatformService.retrieveAllByAgencyLeader(); if (agencies.isEmpty()) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/IndividualPrequalificationApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/IndividualPrequalificationApiResource.java index 8a47ee41742..25a45a39e75 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/IndividualPrequalificationApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/api/IndividualPrequalificationApiResource.java @@ -124,7 +124,7 @@ public String retrieveAllBlacklistItems(@Context final UriInfo uriInfo, String clientName = queryParameters.getFirst("clientName"); SearchParameters searchParameters = SearchParameters.forPrequalification(clientName, status, offset, limit, orderBy, sortOrder, - type, searchText, groupingType, portfolioCenterId); + type, searchText, groupingType, portfolioCenterId,null); final Page memberData = this.prequalificationReadPlatformService.retrieveAllMembers(searchParameters); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(queryParameters); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java index ee2cb0f05db..231d380ec30 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java @@ -277,6 +277,7 @@ private String buildSqlStringFromBlacklistCriteria(final SearchParameters search String sqlSearch = searchParameters.getSqlSearch(); final Long officeId = searchParameters.getOfficeId(); final Long centerId = searchParameters.getCenterId(); + final Long agencyId = searchParameters.getAgencyId(); final String dpiNumber = searchParameters.getName(); final String status = searchParameters.getStatus(); final String type = searchParameters.getType(); @@ -298,12 +299,6 @@ private String buildSqlStringFromBlacklistCriteria(final SearchParameters search paramList.add(appUser.getId()); } } - - // add hierrachy filter here. - extraCriteria += " and (mo.hierarchy LIKE CONCAT(?, '%') OR ? like CONCAT(mo.hierarchy, '%'))"; - paramList.add(appUser.getOffice().getHierarchy()); - paramList.add(appUser.getOffice().getHierarchy()); - } if (StringUtils.equals(groupingType, "individual")) { @@ -314,6 +309,14 @@ private String buildSqlStringFromBlacklistCriteria(final SearchParameters search paramList.add(dpiNumber); } } + extraCriteria += " and (moind.hierarchy LIKE CONCAT(?, '%') OR ? like CONCAT(moind.hierarchy, '%'))"; + paramList.add(appUser.getOffice().getHierarchy()); + paramList.add(appUser.getOffice().getHierarchy()); + + if (agencyId != null) { + extraCriteria += " and individualOffice.agency_id = ? "; + paramList.add(agencyId); + } } if (sqlSearch != null && !isGroup) { @@ -457,12 +460,25 @@ LEFT JOIN ( FROM m_prequalification_group_members mpgm GROUP BY mpgm.group_id ) prequalification_numbers ON prequalification_numbers.prequalification_id = g.id + + LEFT JOIN( + select DISTINCT mc.office_id, ms.agency_id, mpgm.group_id, ms.linked_office_id as supervision_office + from m_prequalification_group_members mpgm + INNER JOIN m_client mc on mc.dpi = mpgm.dpi + INNER JOIN m_group_client mgc on mgc.client_id = mc.id + INNER JOIN m_group mg on mg.id = mgc.group_id + INNER JOIN m_group center on center.id = mg.parent_id + INNER JOIN m_portfolio mp on mp.id = center.portfolio_id + INNER JOIN m_supervision ms on ms.id = mp.supervision_id + ) individualOffice ON individualOffice.group_id = g.id + LEFT JOIN m_agency ma ON g.agency_id = ma.id LEFT JOIN( select agency_id, linked_office_id from m_supervision GROUP BY agency_id ) supv ON supv.agency_id = ma.id LEFT JOIN m_office mo on mo.id = supv.linked_office_id + LEFT JOIN m_office moind on moind.id = individualOffice.supervision_office LEFT JOIN ( SELECT p.id AS groupid,