diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformService.java index 97297c1507e..437a4befaef 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformService.java @@ -28,4 +28,6 @@ public interface AgencyReadPlatformService { AgencyData retrieveNewAgencyTemplate(); Collection retrieveAllByUser(); + + Collection retrieveByOfficeHierarchy(final String hierarchy); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformServiceImpl.java index e83b29a208a..3dd6c61826a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/agency/service/AgencyReadPlatformServiceImpl.java @@ -267,7 +267,24 @@ public AgencyData mapRow(final ResultSet rs, @SuppressWarnings("unused") final i public String schema() { return this.schema; } - } + @Override + public Collection retrieveByOfficeHierarchy(final String hierarchy) { + final String sql = """ + SELECT + ma.id AS id, + ma.name AS name + FROM + m_office mo + INNER JOIN m_office office_under ON + office_under.hierarchy LIKE CONCAT(mo.hierarchy, '%')AND office_under.hierarchy LIKE CONCAT(?, '%') + INNER JOIN m_appuser agency_responsible_user ON agency_responsible_user.office_id = office_under.id + INNER JOIN m_office agency_responsible_user_office ON agency_responsible_user_office.id = agency_responsible_user.office_id + INNER JOIN m_agency ma ON ma.responsible_user_id = agency_responsible_user.id + GROUP BY ma.id + """; + return this.jdbcTemplate.query(sql, (rs, rowNum) -> AgencyData.instance(rs.getLong("id"), rs.getString("name")), + new Object[] { hierarchy }); + } } 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 3f10eed229e..82e5148ff9e 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 @@ -24,7 +24,6 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import java.io.InputStream; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -44,6 +43,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.apache.fineract.commands.domain.CommandWrapper; import org.apache.fineract.commands.service.CommandWrapperBuilder; import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; @@ -63,7 +63,6 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.organisation.agency.data.AgencyData; import org.apache.fineract.organisation.agency.service.AgencyReadPlatformServiceImpl; -import org.apache.fineract.organisation.office.domain.OfficeHierarchyLevel; import org.apache.fineract.organisation.prequalification.data.GroupPrequalificationData; import org.apache.fineract.organisation.prequalification.domain.PrequalificationStatus; import org.apache.fineract.organisation.prequalification.domain.PrequalificationType; @@ -179,7 +178,14 @@ public String newClientIdentifierDetails(@Context final UriInfo uriInfo) { String type = queryParameters.getFirst("type"); String groupingType = queryParameters.getFirst("groupingType"); - + Long agencyId = null; + Long centerId = null; + if (queryParameters.getFirst("agencyId") != null) { + agencyId = NumberUtils.toLong(queryParameters.getFirst("agencyId"), Long.MAX_VALUE); + } + if (queryParameters.getFirst("centerId") != null) { + centerId = NumberUtils.toLong(queryParameters.getFirst("centerId"), Long.MAX_VALUE); + } Collection loanProducts = this.loanProductReadPlatformService.retrieveAllLoanProducts(); Integer prequalificationType = null; if (StringUtils.isNotBlank(groupingType)) { @@ -196,13 +202,10 @@ public String newClientIdentifierDetails(@Context final UriInfo uriInfo) { } } - Collection centerData = this.centerReadPlatformService - .retrieveAllForDropdown(this.context.authenticatedUser().getOffice().getId()); - - Collection agencies = this.agencyReadPlatformService.retrieveAllByUser(); - - final List appUsers = new ArrayList<>( - this.appUserReadPlatformService.retrieveUsersUnderHierarchy(Long.valueOf(OfficeHierarchyLevel.GRUPO.getValue()))); + final String hierarchy = this.context.authenticatedUser().getOffice().getHierarchy(); + final Collection centerData = this.centerReadPlatformService.retrieveByOfficeHierarchy(hierarchy, agencyId); + final Collection agencies = this.agencyReadPlatformService.retrieveByOfficeHierarchy(hierarchy); + final Collection appUsers = this.appUserReadPlatformService.retrieveByOfficeHierarchy(hierarchy, centerId); List statusOptions = Arrays.asList(status(PrequalificationStatus.CONSENT_ADDED), status(PrequalificationStatus.BLACKLIST_CHECKED), status(PrequalificationStatus.COMPLETED), diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java index f7c8c20830f..0627723d59a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java @@ -466,6 +466,7 @@ private CheckValidationColor runCheck9() { /** * Percentage of members with their own home + * * @param groupData */ private CheckValidationColor runCheck10(GroupData groupData) { @@ -476,8 +477,7 @@ private CheckValidationColor runCheck10(GroupData groupData) { final Map reportParams = new HashMap<>(); reportParams.put("${prequalificationId}", prequalificationId); reportParams.put("${loanProductId}", productId); - final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, - false); + final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false); return extractColorFromResultset(result); } @@ -571,6 +571,7 @@ private CheckValidationColor runCheck15() { /** * Payments outside the current term of the main product + * * @param clientData */ private CheckValidationColor runCheck16(ClientData clientData) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java index 037b98e7831..2ae79b7e4a9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java @@ -172,6 +172,36 @@ public static CenterData withTemplate(final CenterData templateCenter, final Cen return mapDTO(center, centerWithTemplate); } + public static CenterData instance(final Long id, final String name) { + final String accountNo = null; + final String externalId = null; + final EnumOptionData status = null; + final LocalDate activationDate = null; + final Long officeId = null; + final String officeName = null; + final Long staffId = null; + final String staffName = null; + final String hierarchy = null; + final Collection groupMembers = null; + final Collection officeOptions = null; + final Collection staffOptions = null; + final Collection groupMembersOptions = null; + final CalendarData collectionMeetingCalendar = null; + final GroupTimelineData timeline = null; + final BigDecimal totalCollected = null; + final BigDecimal totalOverdue = null; + final BigDecimal totaldue = null; + final BigDecimal installmentDue = null; + final Collection cityOptions = null; + final Collection stateOptions = null; + final Collection typeOptions = null; + final Collection meetingDayOptions = null; + final Collection closureReasons = null; + return new CenterData(id, accountNo, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy, + groupMembers, officeOptions, staffOptions, groupMembersOptions, collectionMeetingCalendar, closureReasons, timeline, + totalCollected, totalOverdue, totaldue, installmentDue, cityOptions, stateOptions, typeOptions, meetingDayOptions); + } + public static CenterData instance(final Long id, final String accountNo, final String name, final String externalId, final EnumOptionData status, final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName, final String hierarchy, final GroupTimelineData timeline, final CalendarData collectionMeetingCalendar, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java index ee243c436f8..82e29231999 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformService.java @@ -35,6 +35,8 @@ public interface CenterReadPlatformService { Collection retrieveAllForDropdown(Long officeId); + Collection retrieveByOfficeHierarchy(final String hierarchy, final Long agencyId); + Page retrievePagedAll(SearchParameters searchParameters, PaginationParameters parameters); Collection retrieveAll(SearchParameters searchParameters, PaginationParameters parameters); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java index d3735b7b70a..3f5ca2cd618 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -511,6 +511,37 @@ public Collection retrieveAllForDropdown(final Long officeId) { return this.jdbcTemplate.query(sql, this.centerMapper, new Object[] { officeId, GroupTypes.CENTER.getId(), hierarchySearchString }); // NOSONAR } + @Override + public Collection retrieveByOfficeHierarchy(final String hierarchy, final Long agencyId) { + String sql = """ + SELECT + center.id AS id, + center.display_name AS name + FROM + m_office mo + INNER JOIN m_office office_under ON office_under.hierarchy LIKE CONCAT(mo.hierarchy, '%')AND office_under.hierarchy LIKE CONCAT(?, '%') + INNER JOIN m_appuser agency_responsible_user ON agency_responsible_user.office_id = office_under.id + INNER JOIN m_office agency_responsible_user_office ON agency_responsible_user_office.id = agency_responsible_user.office_id + INNER JOIN m_agency ma ON ma.responsible_user_id = agency_responsible_user.id + INNER JOIN m_office agency_office_under ON agency_office_under.hierarchy LIKE CONCAT(agency_responsible_user_office.hierarchy, '%') + INNER JOIN m_appuser supervison_responsible_user ON agency_responsible_user.office_id = agency_office_under.id + INNER JOIN m_office supervision_responsible_user_office ON supervision_responsible_user_office.id = supervison_responsible_user.office_id + INNER JOIN m_supervision ms ON ms.responsible_user_id = supervison_responsible_user.id + INNER JOIN m_office supervison_office_under ON supervison_office_under.hierarchy LIKE CONCAT(supervision_responsible_user_office.hierarchy, '%') + INNER JOIN m_appuser portfolio_responsible_user ON portfolio_responsible_user.office_id = supervison_office_under.id + INNER JOIN m_portfolio mp ON mp.responsible_user_id = portfolio_responsible_user.id + INNER JOIN m_group center ON center.portfolio_id = mp.id + WHERE center.parent_id IS NULL AND center.level_id = 1 + """; + List params = new ArrayList<>(List.of(hierarchy)); + if (agencyId != null) { + sql = sql + " AND ma.id = ?"; + params.add(agencyId); + } + sql = sql + " GROUP BY center.id"; + return this.jdbcTemplate.query(sql, (rs, rowNum) -> CenterData.instance(rs.getLong("id"), rs.getString("name")), params.toArray()); + } + @Override public CenterData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java index 49f4ca698e2..b52a277f050 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java @@ -112,6 +112,20 @@ public static AppUserData instance(final Long id, final String username, final S selectedRoles, null, staff, passwordNeverExpire, isSelfServiceUser); } + public static AppUserData instance(final Long id, final String username, String firstname, final String lastname) { + final Long officeId = null; + final String officeName = null; + final String email = null; + final Boolean passwordNeverExpires = null; + final Collection availableRoles = null; + final Collection selfServiceRoles = null; + final Collection selectedRoles = null; + final StaffData staff = null; + final Boolean isSelfServiceUser = null; + return new AppUserData(id, username, email, officeId, officeName, firstname, lastname, availableRoles, selfServiceRoles, + selectedRoles, null, staff, passwordNeverExpires, isSelfServiceUser); + } + private AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName, final String firstname, final String lastname, final Collection availableRoles, final Collection selfServiceRoles, final Collection selectedRoles, diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformService.java index b0d348c5e4d..06f0fa6936d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformService.java @@ -35,5 +35,7 @@ public interface AppUserReadPlatformService { Collection retrieveUsersUnderHierarchy(Long hierarchyLevel); + Collection retrieveByOfficeHierarchy(final String hierarchy, final Long centerId); + Collection retrieveUsersForCommittees(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java index d9115f16497..e2309095f47 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; @@ -302,4 +303,33 @@ private void findUserWithRoleLike(Collection usersDataList, Collect } } + @Override + public Collection retrieveByOfficeHierarchy(String hierarchy, final Long centerId) { + String sql = """ + SELECT + facilitator.id AS id, + facilitator.username AS username, + facilitator.firstname AS firstname, + facilitator.lastname AS lastname, + facilitator.email AS email, + facilitator.office_id AS officeId, + mo.name AS officeName, + facilitator.is_self_service_user AS isSelfServiceUser + FROM m_office mo + INNER JOIN m_office office_under ON office_under.hierarchy LIKE CONCAT(mo.hierarchy, '%')AND office_under.hierarchy LIKE CONCAT(?, '%') + LEFT JOIN m_group center ON center.office_id = office_under.id + LEFT JOIN m_office center_office ON center_office.id = center.office_id + LEFT JOIN m_office center_office_under ON center_office_under.hierarchy LIKE CONCAT(center_office.hierarchy, '%') + LEFT JOIN m_appuser facilitator ON facilitator.office_id = center_office_under.id + WHERE facilitator.is_deleted = FALSE AND center.parent_id IS NULL AND center.level_id = 1 + """; + final List params = new ArrayList<>(List.of(hierarchy)); + if (centerId != null) { + sql = sql + " AND center.id = ? "; + params.add(centerId); + } + sql = sql + " GROUP BY facilitator.id ORDER BY facilitator.username"; + return this.jdbcTemplate.query(sql, (rs, rowNum) -> AppUserData.instance(rs.getLong("id"), rs.getString("username"), + rs.getString("firstname"), rs.getString("lastname")), params.toArray()); + } }