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

initial commit FBR-644 hard policy updates #655

Merged
merged 2 commits into from
May 17, 2024
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 @@ -63,7 +63,15 @@ public enum Policies {
32,
"Percentage of members with agricultural business"), THIRTY_THREE(
33,
"Percentage of members with their own business");
"Percentage of members with their own business"), THIRTY_FOUR(
34,
"Early Recapitalization Fee"), THIRTY_FIVE(
35,
"Number Of Cycles"), THIRTY_SIX(
36,
"Percentage Of Clients To Be Recredited In The Group"), THIRTY_SEVEN(
37,
"Clients In Arrears");

private final Integer id;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ private CheckValidationColor validateGenericPolicy(final Policies policy, final
case THIRTY_ONE -> checkValidationColor = this.runCheck31(clientData);
case THIRTY_TWO -> checkValidationColor = this.runCheck32(groupData);
case THIRTY_THREE -> checkValidationColor = this.runCheck33(groupData);
case THIRTY_FOUR -> checkValidationColor = this.runCheck34(clientData);
case THIRTY_FIVE -> checkValidationColor = this.runCheck35(groupData);
case THIRTY_SIX -> checkValidationColor = this.runCheck36(groupData);
case THIRTY_SEVEN -> checkValidationColor = this.runCheck37(groupData);
default -> checkValidationColor = CheckValidationColor.INVALID;
}
return checkValidationColor;
Expand Down Expand Up @@ -335,10 +339,12 @@ CASE WHEN (mlag.current_credit_value <= 0) THEN 0
""";
final Object[] params = new Object[] { loanId };
final BigDecimal percentageIncrease = this.jdbcTemplate.queryForObject(percentageIncreaseSQL, BigDecimal.class, params);
final BigDecimal currentCreditValue = getCurrentCreditValue(loanId);
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${clientId}", clientId);
reportParams.put("${loanProductId}", productId);
reportParams.put("${percentageIncrease}", String.valueOf(percentageIncrease));
reportParams.put("${currentCreditValue}", String.valueOf(currentCreditValue));
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}
Expand Down Expand Up @@ -483,13 +489,15 @@ private CheckValidationColor runCheck6(final GroupData groupData) {
final String reportName = Policies.SIX.getName() + " Policy Check";
final String productId = Long.toString(groupData.getProductId());
final String numberOfMembers = String.valueOf(groupData.getNumberOfMembers());
final String numberOfRecurringMembers = String.valueOf(getRecurringMembers(Long.getLong(prequalificationId)));
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${prequalificationId}", prequalificationId);
reportParams.put("${loanProductId}", productId);
reportParams.put("${clientCategorization}", clientCategorization);
reportParams.put("${clientArea}", clientArea);
reportParams.put("${recreditCategorization}", recreditCategorization);
reportParams.put("${numberOfMembers}", numberOfMembers);
reportParams.put("${numberOfRecurringMembers}", numberOfRecurringMembers);
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}
Expand Down Expand Up @@ -667,14 +675,25 @@ private CheckValidationColor runCheck13(final ClientData clientData) {
*/
private CheckValidationColor runCheck14(final ClientData clientData) {
final String clientId = String.valueOf(clientData.getClientId());
final Long loanId = clientData.getLoanId();
final String reportName = Policies.FOURTEEN.getName() + " Policy Check";
final String productId = Long.toString(clientData.getProductId());
final String requestedAmount = clientData.getRequestedAmount().toPlainString();
final ClientData params = retrieveClientParams(clientData.getClientId(), clientData.getProductId());
final String photographCountSql = """
SELECT COUNT(*)
FROM m_document md
LEFT JOIN m_code_value mcvd ON md.document_type = mcvd.id
WHERE md.parent_entity_type = 'loans' AND md.parent_entity_id = ? AND (md.name = ? OR mcvd.code_value = ?)
""";
Object[] photographParams = new Object[] { loanId, "Fotografias", "Fotografias" };
final Long photographCount = ObjectUtils
.defaultIfNull(this.jdbcTemplate.queryForObject(photographCountSql, Long.class, photographParams), 0L);
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${clientId}", clientId);
reportParams.put("${loanProductId}", productId);
reportParams.put("${requestedAmount}", requestedAmount);
reportParams.put("${photographCount}", String.valueOf(photographCount));
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}
Expand All @@ -687,6 +706,11 @@ private CheckValidationColor runCheck15(final ClientData clientData) {
final String reportName = Policies.FIFTEEN.getName() + " Policy Check";
final String productId = Long.toString(clientData.getProductId());
final Long loanId = clientData.getLoanId();
Integer prequalificationId = clientData.getPrequalificationId();
String categoria_fiador1 = "";
String categoria_fiador2 = "";
String cliente_activo_fiador1 = "";
String cliente_activo_fiador2 = "";
final String documentCountSql = """
SELECT COUNT(*)
FROM m_document md
Expand All @@ -695,6 +719,18 @@ SELECT COUNT(*)
""";
Object[] params = new Object[] { loanId, "Agregar aval", "Agregar aval" };
final Long documentCount = this.jdbcTemplate.queryForObject(documentCountSql, Long.class, params);

String query = "Select categoria_fiador1, categoria_fiador2, cliente_activo_fiador1, cliente_activo_fiador2 " +
"from m_prequalification_group where id = ?";
List<Map<String, Object>> res = this.jdbcTemplate.queryForList(query,
new Object[] {prequalificationId});
if (!res.isEmpty()) {
Map<String, Object> guarantee_fields = res.get(0);
categoria_fiador1 = (String) guarantee_fields.get("categoria_fiador1");
categoria_fiador2 = (String) guarantee_fields.get("categoria_fiador2");
cliente_activo_fiador1 = (String) guarantee_fields.get("cliente_activo_fiador1");
cliente_activo_fiador2 = (String) guarantee_fields.get("cliente_activo_fiador2");
}
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${clientId}", clientId);
reportParams.put("${loanProductId}", productId);
Expand Down Expand Up @@ -894,6 +930,7 @@ private CheckValidationColor runCheck25(final ClientData clientData) {
reportParams.put("${clientCategorization}", params.getClientCategorization());
reportParams.put("${recreditCategorization}", params.getRecreditCategorization());
reportParams.put("${businessAge}", String.valueOf(yearsInBusiness));
reportParams.put("${requestedAmount}", String.valueOf(clientData.getRequestedAmount()));
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}
Expand Down Expand Up @@ -1087,4 +1124,91 @@ WHERE mlag.loan_id IN ( %s ) AND mcv.code_value = 'microentreprenuer'
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}

private CheckValidationColor runCheck34(final ClientData clientData) {
final String clientId = String.valueOf(clientData.getClientId());
final String reportName = Policies.THIRTY_FOUR.getName() + " Policy Check";
final String productId = Long.toString(clientData.getProductId());
final ClientData params = retrieveClientParams(clientData.getClientId(), clientData.getProductId());
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${clientId}", clientId);
reportParams.put("${loanProductId}", productId);
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}

private CheckValidationColor runCheck35(final GroupData groupData) {
final String reportName = Policies.THIRTY_FIVE.getName() + " Policy Check";
final String numberOfMembers = String.valueOf(groupData.getNumberOfMembers());
final String prequalificationId = String.valueOf(groupData.getId());
final String productId = Long.toString(groupData.getProductId());

final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${numberOfMembers}", numberOfMembers);
reportParams.put("${prequalificationId}", prequalificationId);
reportParams.put("${loanProductId}", productId);
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}

private CheckValidationColor runCheck36(final GroupData groupData) {
final String reportName = Policies.THIRTY_SIX.getName() + " Policy Check";
final String prequalificationId = String.valueOf(groupData.getId());
final String productId = Long.toString(groupData.getProductId());

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);
return extractColorFromResultset(result);
}

private CheckValidationColor runCheck37(final GroupData groupData) {
final String reportName = Policies.THIRTY_SEVEN.getName() + " Policy Check";
final String prequalificationId = String.valueOf(groupData.getId());
final String productId = Long.toString(groupData.getProductId());

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);
return extractColorFromResultset(result);
}

private BigDecimal getCurrentCreditValue(Long loanId) {
final String currentCreditValueSQL = """
SELECT
mlag.current_credit_value
FROM m_loan_additionals_group mlag
INNER JOIN m_loan ml ON ml.id = mlag.loan_id
WHERE ml.id = ?
""";
final Object[] params = new Object[] { loanId };
return this.jdbcTemplate.queryForObject(currentCreditValueSQL, BigDecimal.class, params);
}

private Integer getRecurringMembers(Long preQualificationId) {
final String currentCreditValueSQL = """
select count(*)
FROM m_prequalification_group mp
LEFT JOIN m_group_prequalification_relationship mgpr ON mgpr.prequalification_id = mp.id
LEFT JOIN m_group mg ON (mg.prequalification_id = mp.id OR mg.id = mgpr.group_id)
left join m_group_client mgc on mgc.group_id = mg.id
left join m_client mc on mc.id = mgc.client_id
where
mc.status_enum = 300
and mp.id = ?
and COALESCE(mc.loan_cycle, 0) >= 3
GROUP BY mp.id
""";
final Object[] params = new Object[] { preQualificationId };
Integer count = 0;
try {
count = this.jdbcTemplate.queryForObject(currentCreditValueSQL, Integer.class, params);
} catch (EmptyResultDataAccessException e) {
count = 0;
}
return count;
}

}
Loading
Loading