Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/FBR-465: Retrieve Loan Product from Prequalification #306

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public String newClientIdentifierDetails(@Context final UriInfo uriInfo) {
String groupId = queryParameters.getFirst("groupId");
Long agencyId = null;
Long centerId = null;
if (!StringUtils.isBlank(groupId)){
if (!StringUtils.isBlank(groupId)) {
GroupPrequalificationData prequalificationGroup = this.prequalificationReadPlatformService.retrieveOne(Long.valueOf(groupId));
agencyId = prequalificationGroup.getAgencyId();
centerId = prequalificationGroup.getCenterId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface PrequalificationReadPlatformService {
MemberPrequalificationData retrieveOneMember(Long clientId);

Collection<GroupPrequalificationData> retrievePrequalificationGroupsMappings(Long groupId);

Collection<GroupPrequalificationData> retrievePrequalificationIndividualMappings(Long clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class PrequalificationReadPlatformServiceImpl implements Prequalification
private final ColumnValidator columnValidator;
private final PrequalificationsGroupMapper prequalificationsGroupMapper = new PrequalificationsGroupMapper();
private final PrequalificationsGroupMappingsMapper mappingsMapper = new PrequalificationsGroupMappingsMapper();
private final PrequalificationIndividualMappingsMapper prequalificationIndividualMappingsMapper = new PrequalificationIndividualMappingsMapper();
private final PrequalificationsMemberMapper prequalificationsMemberMapper = new PrequalificationsMemberMapper();
private final DatabaseSpecificSQLGenerator sqlGenerator;
private final PreQualificationMemberRepository preQualificationMemberRepository;
Expand Down Expand Up @@ -256,6 +257,14 @@ public Collection<GroupPrequalificationData> retrievePrequalificationGroupsMappi
return prequalificationGroups;
}

@Override
public Collection<GroupPrequalificationData> retrievePrequalificationIndividualMappings(final Long clientId) {
final String sql = "select " + this.prequalificationIndividualMappingsMapper.schema() + " WHERE mc.id = ?";
final Collection<GroupPrequalificationData> prequalificationGroups = this.jdbcTemplate.query(sql,
this.prequalificationIndividualMappingsMapper, new Object[] { clientId });
return prequalificationGroups;
}

private String buildSqlStringFromBlacklistCriteria(final SearchParameters searchParameters, List<Object> paramList, boolean isGroup) {

AppUser appUser = this.context.authenticatedUser();
Expand Down Expand Up @@ -286,6 +295,10 @@ private String buildSqlStringFromBlacklistCriteria(final SearchParameters search
if (groupingType.equals("individual")) {
extraCriteria += " and g.prequalification_type_enum = ? ";
paramList.add(PrequalificationType.INDIVIDUAL.getValue());
if (dpiNumber != null) {
extraCriteria += " and g.dpi = ? ";
paramList.add(dpiNumber);
}
}
}

Expand Down Expand Up @@ -555,23 +568,53 @@ public String schema() {

@Override
public GroupPrequalificationData mapRow(final ResultSet rs, final int rowNum) throws SQLException {

final Integer statusEnum = JdbcSupport.getInteger(rs, "status");
final EnumOptionData status = PreQualificationsEnumerations.status(statusEnum);

final Long id = JdbcSupport.getLong(rs, "id");
final String prequalificationNumber = rs.getString("prequalificationNumber");
String groupName = rs.getString("groupName");
final String productName = rs.getString("productName");
final LocalDate createdAt = JdbcSupport.getLocalDate(rs, "created_at");

final String addedBy = rs.getString("firstname") + " " + rs.getString("lastname");

return GroupPrequalificationData.simpeGroupData(id, prequalificationNumber, status, groupName, productName, addedBy, createdAt);

}
}

private static final class PrequalificationIndividualMappingsMapper implements RowMapper<GroupPrequalificationData> {

private final String schema;

PrequalificationIndividualMappingsMapper() {
this.schema = """
mpg.id AS id, mpg.prequalification_number AS prequalificationNumber, mpg.group_name AS groupName, mpg.status AS status,
mpl.name AS productName, mpg.created_at, ma.firstname, ma.lastname
FROM m_prequalification_group mpg
INNER JOIN m_product_loan mpl ON mpl.id = mpg.product_id
INNER JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mpg.id
INNER JOIN m_client mc ON mc.dpi = mpgm.dpi
LEFT JOIN m_appuser ma ON ma.id = mpg.added_by
""";
}

public String schema() {
return this.schema;
}

@Override
public GroupPrequalificationData mapRow(final ResultSet rs, final int rowNum) throws SQLException {
final Integer statusEnum = JdbcSupport.getInteger(rs, "status");
final EnumOptionData status = PreQualificationsEnumerations.status(statusEnum);
final Long id = JdbcSupport.getLong(rs, "id");
final String prequalificationNumber = rs.getString("prequalificationNumber");
String groupName = rs.getString("groupName");
final String productName = rs.getString("productName");
final LocalDate createdAt = JdbcSupport.getLocalDate(rs, "created_at");
final String addedBy = rs.getString("firstname") + " " + rs.getString("lastname");
return GroupPrequalificationData.simpeGroupData(id, prequalificationNumber, status, groupName, productName, addedBy, createdAt);
}
}

private static final class PrequalificationsMemberMapper implements RowMapper<MemberPrequalificationData> {

private final String schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.organisation.prequalification.data.GroupPrequalificationData;
import org.apache.fineract.organisation.prequalification.service.PrequalificationReadPlatformService;
import org.apache.fineract.portfolio.accountdetails.data.AccountSummaryCollectionData;
import org.apache.fineract.portfolio.accountdetails.service.AccountDetailsReadPlatformService;
import org.apache.fineract.portfolio.client.data.ClientData;
Expand Down Expand Up @@ -98,6 +100,7 @@ public class ClientsApiResource {
private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService;
private final GuarantorReadPlatformService guarantorReadPlatformService;
private final CodeValueReadPlatformService codeValueReadPlatformService;
private final PrequalificationReadPlatformService prequalificationReadPlatformService;

@GET
@Path("template")
Expand Down Expand Up @@ -201,6 +204,9 @@ public String retrieveOne(@PathParam("clientId") @Parameter(description = "clien
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());

ClientData clientData = this.clientReadPlatformService.retrieveOne(clientId);
Collection<GroupPrequalificationData> prequalificationDataList = this.prequalificationReadPlatformService
.retrievePrequalificationIndividualMappings(clientId);
clientData.setClientPrequalifications(prequalificationDataList);
if (settings.isTemplate()) {
final ClientData templateData = this.clientReadPlatformService.retrieveTemplate(clientData.officeId(),
staffInSelectedOfficeOnly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.dataqueries.data.DatatableData;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.organisation.prequalification.data.GroupPrequalificationData;
import org.apache.fineract.organisation.staff.data.StaffData;
import org.apache.fineract.portfolio.address.data.AddressData;
import org.apache.fineract.portfolio.collateralmanagement.domain.ClientCollateralManagement;
Expand Down Expand Up @@ -99,6 +100,7 @@ public final class ClientData implements Comparable<ClientData>, Serializable {
private final Collection<CodeValueData> clientClassificationOptions;
private final Collection<CodeValueData> clientNonPersonConstitutionOptions;
private final Collection<CodeValueData> clientNonPersonMainBusinessLineOptions;
private Collection<GroupPrequalificationData> clientPrequalifications;
private final String firstlastname;
private final String secondlastname;
private final String departmentDpiName;
Expand Down Expand Up @@ -784,4 +786,12 @@ public void updateClientAddressTemplate(Collection<CodeValueData> clientAreas, C
this.departamentoOptions = ldepartamento;
this.municipioOptions = lmunicipio;
}

public Collection<GroupPrequalificationData> getClientPrequalifications() {
return clientPrequalifications;
}

public void setClientPrequalifications(Collection<GroupPrequalificationData> clientPrequalifications) {
this.clientPrequalifications = clientPrequalifications;
}
}
Loading