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

fix/FBR-676 #773

Merged
merged 1 commit into from
Jun 7, 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 @@ -46,4 +46,5 @@ public class ClientData {
private Integer buroCheckStatus;
private Boolean isLoanTopup;
private Long loanCycle;
private String categorization;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public class LoanData {
private String dpi;
private BigDecimal principalAmount;
private Boolean isTopup;
private String loanCycleCompleted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public PrequalificationChecklistData retrieveHardPolicyValidationResults(final L
String memberId = null;
String clientName;
String dpi;
for (PolicyData policy : individualPolicies) {
for (ChecklistValidationResult validationResult : validationResults) {
if (policy.getId().equals(validationResult.getPolicyId())
for (PolicyData policy : individualPolicies) {
for (ChecklistValidationResult validationResult : validationResults) {
if (policy.getId().equals(validationResult.getPolicyId())
&& PrequalificationType.INDIVIDUAL.getValue().equals(validationResult.getPrequalificationTypeEnum())
&& member.getId().equals(validationResult.getMemberId().longValue())) {
final String validationColor = CheckValidationColor.fromInt(validationResult.getColorEnum()).name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,29 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal
clientData.setLoanId(submittedLoanData.getLoanId());
clientData.setIsLoanTopup(submittedLoanData.getIsTopup());
clientData.setProductId(productId);
ValidationChecklistResult validationChecklistResult = new ValidationChecklistResult();
validationChecklistResult.setPrequalificationId(prequalificationId);
validationChecklistResult.setPolicyId(policyCategoryData.getId());
validationChecklistResult.setClientId(clientData.getClientId());
validationChecklistResult.setPrequalificationMemberId(clientData.getPrequalificationMemberId());
validationChecklistResult.setPrequalificationType(PrequalificationType.INDIVIDUAL.getValue());

String loanCycleCompleted = submittedLoanData.getLoanCycleCompleted();
clientData.setCategorization(StringUtils.equalsIgnoreCase(loanCycleCompleted, "fromAnotherGroup") ? "RECREDITO" : "NUEVO");
CheckValidationColor checkValidationColor = this.validateGenericPolicy(Policies.fromInt(policyCategoryData.getId()),
clientData, groupData);
validationChecklistResult.setValidationColor(checkValidationColor.getValue());
AppUser authenticatedUser = platformSecurityContext.authenticatedUser();
final LocalDateTime localDateTime = DateUtils.getLocalDateTimeOfSystem();
if (authenticatedUser != null && authenticatedUser.getId() != null) {
validationChecklistResult.setCreatedBy(authenticatedUser.getId());
validationChecklistResult.setLastModifiedBy(authenticatedUser.getId());
if (checkValidationColor!=null){
ValidationChecklistResult validationChecklistResult = new ValidationChecklistResult();
validationChecklistResult.setPrequalificationId(prequalificationId);
validationChecklistResult.setPolicyId(policyCategoryData.getId());
validationChecklistResult.setClientId(clientData.getClientId());
validationChecklistResult.setPrequalificationMemberId(clientData.getPrequalificationMemberId());
validationChecklistResult.setPrequalificationType(PrequalificationType.INDIVIDUAL.getValue());
validationChecklistResult.setValidationColor(checkValidationColor.getValue());
AppUser authenticatedUser = platformSecurityContext.authenticatedUser();
final LocalDateTime localDateTime = DateUtils.getLocalDateTimeOfSystem();
if (authenticatedUser != null && authenticatedUser.getId() != null) {
validationChecklistResult.setCreatedBy(authenticatedUser.getId());
validationChecklistResult.setLastModifiedBy(authenticatedUser.getId());
}
validationChecklistResult.setCreatedDate(localDateTime);
validationChecklistResult.setLastModifiedDate(localDateTime);
validationChecklistResults.add(validationChecklistResult);
}
validationChecklistResult.setCreatedDate(localDateTime);
validationChecklistResult.setLastModifiedDate(localDateTime);
validationChecklistResults.add(validationChecklistResult);
}
}

Expand Down Expand Up @@ -250,10 +255,12 @@ public String schema() {
SELECT mc.id AS clientId,mc.loan_cycle as loanCycle, mpgm.id AS prequalificationMemberId, IFNULL(mc.display_name,mpgm.name) AS name, mpg.id AS prequalificationId,\s
mpgm.requested_amount AS requestedAmount, IFNULL(mc.date_of_birth, mpgm.dob) AS dateOfBirth, IFNULL(mc.dpi, mpgm.dpi) AS dpi,
mpgm.work_with_puente AS workWithPuente, mcv.code_value As gender, mpgm.is_president AS president, mpgm.buro_check_status buroCheckStatus,
ml.is_topup AS isTopup, ml.id AS loanId
FROM m_prequalification_group_members mpgm\s
LEFT JOIN m_client mc ON mc.dpi = mpgm.dpi\s
LEFT JOIN m_code_value mcv ON mcv.id = mc.gender_cv_id
ml.is_topup AS isTopup, ml.id AS loanId, areacv.code_value as clientArea
FROM m_prequalification_group_members mpgm
LEFT JOIN m_client mc ON mc.dpi = mpgm.dpi
LEFT JOIN m_client_contact_info cinf ON cinf.client_id = mc.id
LEFT JOIN m_code_value mcv ON mcv.id = mc.gender_cv_id
LEFT JOIN m_code_value areacv ON areacv.id = cinf.area
LEFT JOIN m_prequalification_group mpg ON mpg.id = mpgm.group_id
LEFT JOIN m_loan ml ON ml.client_id = mc.id AND ml.loan_status_id = 100 AND ml.prequalification_id = mpg.id
WHERE mpg.id = ?
Expand All @@ -275,7 +282,8 @@ public ClientData mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException
final BigDecimal requestedAmount = rs.getBigDecimal("requestedAmount");
final String workWithPuente = rs.getString("workWithPuente");
final String gender = rs.getString("gender");
return ClientData.builder().clientId(clientId).prequalificationId(prequalificationId)
final String clientArea = StringUtils.equalsIgnoreCase(rs.getString("clientArea"), "Rural")?"RURAL":"URBAN";
return ClientData.builder().clientId(clientId).prequalificationId(prequalificationId).clientArea(clientArea)
.prequalificationMemberId(prequalificationMemberId).name(name).dateOfBirth(dateOfBirth).dpi(dpi)
.requestedAmount(requestedAmount).gender(gender).workWithPuente(workWithPuente).president(president)
.buroCheckStatus(buroCheckStatus).isLoanTopup(isTopup).loanCycle(loanCycle).build();
Expand All @@ -291,7 +299,7 @@ private CheckValidationColor validateGenericPolicy(final Policies policy, final
case FOUR -> checkValidationColor = this.runCheck4(clientData);
case FIVE -> checkValidationColor = this.runCheck5(clientData);
case SIX -> checkValidationColor = this.runCheck6(groupData);
case SEVEN -> checkValidationColor = this.runCheck7(groupData);
case SEVEN -> checkValidationColor = this.runCheck7(clientData);
case EIGHT -> checkValidationColor = this.runCheck8(groupData);
case NINE -> checkValidationColor = this.runCheck9(groupData);
case TEN -> checkValidationColor = this.runCheck10(groupData);
Expand Down Expand Up @@ -526,22 +534,20 @@ private CheckValidationColor runCheck6(final GroupData groupData) {

/**
* Minimum and maximum amount
* @param clientData
*/
private CheckValidationColor runCheck7(final GroupData groupData) {
String clientArea = "RURAL";
if (!CollectionUtils.isEmpty(groupData.getMembers())) {
final ClientData clientData = groupData.getMembers().get(0);
final ClientData params = retrieveClientParams(clientData.getClientId(), clientData.getProductId());
clientArea = params.getClientArea();
}
final String prequalificationId = String.valueOf(groupData.getId());
private CheckValidationColor runCheck7(final ClientData clientData) {
String clientArea = clientData.getClientArea();
final String prequalificationId = String.valueOf(clientData.getPrequalificationId());
final String reportName = Policies.SEVEN.getName() + " Policy Check";
final String productId = Long.toString(groupData.getProductId());
final String productId = Long.toString(clientData.getProductId());
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${prequalificationId}", prequalificationId);
reportParams.put("${loanProductId}", productId);
reportParams.put("${clientArea}", clientArea);
reportParams.put("${requestedAmount}", String.valueOf(groupData.getRequestedAmount()));
reportParams.put("${categorization}", String.valueOf(clientData.getCategorization()));
reportParams.put("${isTopup}", String.valueOf(clientData.getIsLoanTopup()));
reportParams.put("${requestedAmount}", String.valueOf(clientData.getRequestedAmount()));
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}
Expand Down Expand Up @@ -1152,13 +1158,12 @@ WHERE mlag.loan_id IN ( %s ) AND mcv.code_value = 'microentreprenuer'
}

private CheckValidationColor runCheck34(final ClientData clientData) {
final String clientId = String.valueOf(clientData.getClientId());
if (!clientData.getIsLoanTopup()){
return null;
}
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);
reportParams.put("${loanId}", String.valueOf(clientData.getLoanId()));
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ static final class GroupTypeLoanMapper implements RowMapper<LoanData> {
ml.is_topup AS isTopup,
mpg.id AS prequalificationId,
mg.id AS groupId,
mcv.code_description AS loanCycleCompleted,
ml.principal_amount AS principalAmount
FROM m_prequalification_group mpg
INNER JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mpg.id
Expand All @@ -1057,6 +1058,8 @@ static final class GroupTypeLoanMapper implements RowMapper<LoanData> {
INNER JOIN m_group mg ON mg.id = mgc.group_id
INNER JOIN m_client mc ON (mgc.client_id = mc.id AND mpgm.dpi = mc.dpi)
INNER JOIN m_loan ml ON (ml.client_id = mc.id OR ml.group_id = mg.id)
LEFT JOIN m_loan_additionals_group mlad ON mlad.loan_id = ml.id
LEFT JOIN m_code_value mcv ON mcv.id = mlad.loan_cycle_completed
WHERE mpg.id = ? AND mpg.prequalification_type_enum = 2 AND (ml.client_id = (SELECT mt.id FROM m_client mt WHERE mt.dpi = ?))
AND ml.loan_status_id = 100 AND ml.prequalification_id = ?
GROUP BY ml.id
Expand All @@ -1073,10 +1076,11 @@ public LoanData mapRow(ResultSet rs, int rowNum) throws SQLException {
final Long clientId = JdbcSupport.getLong(rs, "clientId");
final Long prequalificationId = JdbcSupport.getLong(rs, "prequalificationId");
final Boolean isTopup = rs.getBoolean("isTopup");
final String loanCycleCompleted = rs.getString("loanCycleCompleted");
final Long groupId = JdbcSupport.getLong(rs, "groupId");
final BigDecimal principalAmount = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "principalAmount");
return LoanData.builder().loanId(loanId).clientId(clientId).prequalificationId(prequalificationId).groupId(groupId)
.principalAmount(principalAmount).isTopup(isTopup).build();
.principalAmount(principalAmount).isTopup(isTopup).loanCycleCompleted(loanCycleCompleted).build();

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,88 @@
</sql>
</changeSet>

<changeSet id="9" author="fineract">
<sql>
<![CDATA[
UPDATE stretchy_report
SET report_sql = "SELECT mc.id, main_loan_details.pending_installments, recredit_loan_details.amount,
CASE
WHEN main_loan_details.pending_installments <= 2 AND recredit_loan_details.amount = (1.5*mpgm.approved_amount) THEN 'GREEN'
WHEN main_loan_details.pending_installments = 3 AND recredit_loan_details.amount = (2.5 *mpgm.approved_amount)THEN 'GREEN'
ELSE 'RED'
END as color
FROM m_loan mln
join m_client mc on mc.id=mln.client_id
join m_prequalification_group_members mpgm ON mpgm.dpi = mc.dpi AND mpgm.group_id=mln.prequalification_id
join m_loan_topup mlt on mlt.loan_id = mln.id
join m_loan originalLoan on originalLoan.id = mlt.closure_loan_id
INNER JOIN (
SELECT ml.id AS loan_id, COUNT(mlrs.id) AS pending_installments
FROM m_loan_repayment_schedule mlrs join m_loan ml on ml.id = mlrs.loan_id
AND (ml.is_topup IS NULL OR ml.is_topup = 0)
AND mlrs.obligations_met_on_date IS NULL
GROUP BY ml.id
)main_loan_details ON main_loan_details.loan_id = originalLoan.id
LEFT JOIN (
SELECT ml.id AS loan_id, coalesce(mc2.name,'N/A') charge_name, coalesce(mc2.amount,0) as amount
FROM m_loan ml
LEFT JOIN m_loan_charge mlc on mlc.loan_id = ml.id
LEFT JOIN m_charge mc2 on mc2.id = mlc.charge_id AND mc2.name LIKE 'Cargo por ampliación%'
WHERE ml.id = ${loanId}
)recredit_loan_details ON recredit_loan_details.loan_id = mln.id
WHERE mln.id = ${loanId}"
WHERE report_name = "Early Recapitalization Fee Policy Check";
]]>
</sql>
</changeSet>

<changeSet id="10" author="fineract">
<sql>
<![CDATA[
UPDATE stretchy_report SET report_sql = "SELECT
CASE
WHEN (${isTopup} = true) AND (${loanProductId} IN (2,8,9)) AND ('${categorization}' = 'RECREDITO') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'
WHEN (${isTopup} = true) AND (${loanProductId} IN (4,5)) AND ('${categorization}' = 'RECREDITO') AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN'

WHEN (${isTopup} = false) AND (${loanProductId} = 2) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 5000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 2) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 2) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${requestedAmount} BETWEEN 1500 AND 5000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 2) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'

WHEN (${isTopup} = false) AND (${loanProductId} = 8) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 5000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 8) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 8) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${requestedAmount} BETWEEN 1500 AND 5000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 8) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'

WHEN (${isTopup} = false) AND (${loanProductId} = 9) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 5000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 9) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 9) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${requestedAmount} BETWEEN 1500 AND 5000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 9) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN'

WHEN (${isTopup} = false) AND (${loanProductId} = 4) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 5000 AND 10000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 4) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 4) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${requestedAmount} BETWEEN 5000 AND 10000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 4) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN'

WHEN (${isTopup} = false) AND (${loanProductId} = 5) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 5000 AND 10000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 5) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 5000 AND 20000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 5) AND ('${categorization}' = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${requestedAmount} BETWEEN 5000 AND 10000) THEN 'GREEN'
WHEN (${isTopup} = false) AND (${loanProductId} = 5) AND ('${categorization}' = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${requestedAmount} BETWEEN 5000 AND 20000) THEN 'GREEN'

ELSE 'RED'
END AS color"
WHERE report_name = "Minimum and maximum amount Policy Check";
]]>
</sql>
</changeSet>

<changeSet id="11" author="fineract">
<sql>
<![CDATA[
UPDATE m_product_policy SET evaluation_type = "INDIVIDUAL"
WHERE policy_id = (SELECT id FROM m_policy WHERE name = "Minimum and maximum amount" limit 1);
]]>
</sql>
</changeSet>

</databaseChangeLog>
Loading