Skip to content

Commit

Permalink
FBR-381: Implment prequalification template filters by offices (#267)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius Peter Oketayot <[email protected]>
  • Loading branch information
fiter-julius-oketayot and Julius Peter Oketayot authored Nov 14, 2023
1 parent b909fc0 commit 534e2a2
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface AgencyReadPlatformService {
AgencyData retrieveNewAgencyTemplate();

Collection<AgencyData> retrieveAllByUser();

Collection<AgencyData> retrieveByOfficeHierarchy(final String hierarchy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,24 @@ public AgencyData mapRow(final ResultSet rs, @SuppressWarnings("unused") final i
public String schema() {
return this.schema;
}

}

@Override
public Collection<AgencyData> 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 });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<LoanProductData> loanProducts = this.loanProductReadPlatformService.retrieveAllLoanProducts();
Integer prequalificationType = null;
if (StringUtils.isNotBlank(groupingType)) {
Expand All @@ -196,13 +202,10 @@ public String newClientIdentifierDetails(@Context final UriInfo uriInfo) {
}
}

Collection<CenterData> centerData = this.centerReadPlatformService
.retrieveAllForDropdown(this.context.authenticatedUser().getOffice().getId());

Collection<AgencyData> agencies = this.agencyReadPlatformService.retrieveAllByUser();

final List<AppUserData> appUsers = new ArrayList<>(
this.appUserReadPlatformService.retrieveUsersUnderHierarchy(Long.valueOf(OfficeHierarchyLevel.GRUPO.getValue())));
final String hierarchy = this.context.authenticatedUser().getOffice().getHierarchy();
final Collection<CenterData> centerData = this.centerReadPlatformService.retrieveByOfficeHierarchy(hierarchy, agencyId);
final Collection<AgencyData> agencies = this.agencyReadPlatformService.retrieveByOfficeHierarchy(hierarchy);
final Collection<AppUserData> appUsers = this.appUserReadPlatformService.retrieveByOfficeHierarchy(hierarchy, centerId);

List<EnumOptionData> statusOptions = Arrays.asList(status(PrequalificationStatus.CONSENT_ADDED),
status(PrequalificationStatus.BLACKLIST_CHECKED), status(PrequalificationStatus.COMPLETED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ private CheckValidationColor runCheck9() {

/**
* Percentage of members with their own home
*
* @param groupData
*/
private CheckValidationColor runCheck10(GroupData groupData) {
Expand All @@ -476,8 +477,7 @@ private CheckValidationColor runCheck10(GroupData groupData) {
final Map<String, String> 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);
}

Expand Down Expand Up @@ -571,6 +571,7 @@ private CheckValidationColor runCheck15() {

/**
* Payments outside the current term of the main product
*
* @param clientData
*/
private CheckValidationColor runCheck16(ClientData clientData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupGeneralData> groupMembers = null;
final Collection<OfficeData> officeOptions = null;
final Collection<StaffData> staffOptions = null;
final Collection<GroupGeneralData> 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<CodeValueData> cityOptions = null;
final Collection<CodeValueData> stateOptions = null;
final Collection<CodeValueData> typeOptions = null;
final Collection<CodeValueData> meetingDayOptions = null;
final Collection<CodeValueData> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface CenterReadPlatformService {

Collection<CenterData> retrieveAllForDropdown(Long officeId);

Collection<CenterData> retrieveByOfficeHierarchy(final String hierarchy, final Long agencyId);

Page<CenterData> retrievePagedAll(SearchParameters searchParameters, PaginationParameters parameters);

Collection<CenterData> retrieveAll(SearchParameters searchParameters, PaginationParameters parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,37 @@ public Collection<CenterData> retrieveAllForDropdown(final Long officeId) {
return this.jdbcTemplate.query(sql, this.centerMapper, new Object[] { officeId, GroupTypes.CENTER.getId(), hierarchySearchString }); // NOSONAR
}

@Override
public Collection<CenterData> 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<Object> 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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoleData> availableRoles = null;
final Collection<RoleData> selfServiceRoles = null;
final Collection<RoleData> 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<RoleData> availableRoles,
final Collection<RoleData> selfServiceRoles, final Collection<RoleData> selectedRoles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public interface AppUserReadPlatformService {

Collection<AppUserData> retrieveUsersUnderHierarchy(Long hierarchyLevel);

Collection<AppUserData> retrieveByOfficeHierarchy(final String hierarchy, final Long centerId);

Collection<AppUserData> retrieveUsersForCommittees();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -302,4 +303,33 @@ private void findUserWithRoleLike(Collection<AppUserData> usersDataList, Collect
}
}

@Override
public Collection<AppUserData> 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<Object> 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());
}
}

0 comments on commit 534e2a2

Please sign in to comment.