Skip to content

Commit

Permalink
Qa/fbr 673 674 (#769)
Browse files Browse the repository at this point in the history
* fix FBR 674

* fix REPORTS

* fix Topu Loan Policies

* Fix/fbr 673 (#768)

* fix Policy Labels

* fix Hard Policy Labels
  • Loading branch information
BrianMuhimbura authored Jun 5, 2024
1 parent a333e49 commit 980f00c
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public class ClientData {
private String recreditCategorization;
private Boolean president;
private Integer buroCheckStatus;
private Boolean isLoanTopup;
private Long loanCycle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public class GroupData {
private BigDecimal requestedAmount;
private Integer numberOfMembers;
private List<ClientData> members;
private List<ClientData> topupMembers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public class LoanData {
private Long prequalificationMemberId;
private String dpi;
private BigDecimal principalAmount;
private Boolean isTopup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal
final Integer noOfMembers = prequalificationGroup.getMembers().size();
final BigDecimal totalAmountRequested = prequalificationGroup.getMembers().stream()
.map(PrequalificationGroupMember::getRequestedAmount).reduce(BigDecimal.ONE, BigDecimal::add);
// get all loan topup clients
List<ClientData> loanTopupClients = clientDatas.stream().filter(ClientData::getIsLoanTopup).toList();

final GroupData groupData = GroupData.builder().id(prequalificationId).productId(productId).numberOfMembers(noOfMembers)
.requestedAmount(totalAmountRequested).members(clientDatas).previousPrequalification(prequalificationGroup.getPreviousPrequalification()).build();
.requestedAmount(totalAmountRequested).members(clientDatas).topupMembers(loanTopupClients).previousPrequalification(prequalificationGroup.getPreviousPrequalification()).build();
Integer fromStatus = prequalificationGroup.getStatus();
List<ValidationChecklistResult> validationChecklistResults = new ArrayList<>();
final List<PolicyData> groupPolicies = this.jdbcTemplate.query(this.policyMapper.schema(), this.policyMapper, productId,
Expand All @@ -138,6 +141,7 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal
}
final LoanData submittedLoanData = submittedLoans.get(0);
clientData.setLoanId(submittedLoanData.getLoanId());
clientData.setIsLoanTopup(submittedLoanData.getIsTopup());
clientData.setProductId(productId);
ValidationChecklistResult validationChecklistResult = new ValidationChecklistResult();
validationChecklistResult.setPrequalificationId(prequalificationId);
Expand Down Expand Up @@ -243,24 +247,28 @@ private static final class ClientDataMapper implements RowMapper<ClientData> {

public String schema() {
return """
SELECT mc.id AS clientId, mpgm.id AS prequalificationMemberId, IFNULL(mc.display_name,mpgm.name) AS name, mpg.id AS prequalificationId,\s
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
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
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 = ?
""";
}

@Override
public ClientData mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException {
final Long clientId = JdbcSupport.getLong(rs, "clientId");
final Long loanCycle = JdbcSupport.getLong(rs, "loanCycle");
final Integer prequalificationMemberId = JdbcSupport.getInteger(rs, "prequalificationMemberId");
final Integer prequalificationId = JdbcSupport.getInteger(rs, "prequalificationId");
final String name = rs.getString("name");
final boolean president = rs.getBoolean("president");
final boolean isTopup = rs.getBoolean("isTopup");
final Integer buroCheckStatus = JdbcSupport.getInteger(rs, "buroCheckStatus");
final Date dateOfBirth = rs.getDate("dateOfBirth");
final String dpi = rs.getString("dpi");
Expand All @@ -270,7 +278,7 @@ public ClientData mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException
return ClientData.builder().clientId(clientId).prequalificationId(prequalificationId)
.prequalificationMemberId(prequalificationMemberId).name(name).dateOfBirth(dateOfBirth).dpi(dpi)
.requestedAmount(requestedAmount).gender(gender).workWithPuente(workWithPuente).president(president)
.buroCheckStatus(buroCheckStatus).build();
.buroCheckStatus(buroCheckStatus).isLoanTopup(isTopup).loanCycle(loanCycle).build();
}
}

Expand Down Expand Up @@ -1156,11 +1164,12 @@ private CheckValidationColor runCheck34(final ClientData clientData) {
}

private CheckValidationColor runCheck35(final GroupData groupData) {
if (groupData.getPreviousPrequalification()==null) {
if (groupData.getTopupMembers().size()<=0) {
return null;
}
final String reportName = Policies.THIRTY_FIVE.getName() + " Policy Check";
final String numberOfMembers = String.valueOf(groupData.getNumberOfMembers());
//only validate with topup members only
final String numberOfMembers = String.valueOf(groupData.getTopupMembers().size());
final String prequalificationId = String.valueOf(groupData.getId());
final String productId = Long.toString(groupData.getProductId());

Expand All @@ -1173,7 +1182,7 @@ private CheckValidationColor runCheck35(final GroupData groupData) {
}

private CheckValidationColor runCheck36(final GroupData groupData) {
if (groupData.getPreviousPrequalification()==null) {
if (groupData.getTopupMembers().size()<=0) {
return null;
}
final String reportName = Policies.THIRTY_SIX.getName() + " Policy Check";
Expand All @@ -1188,7 +1197,7 @@ private CheckValidationColor runCheck36(final GroupData groupData) {
}

private CheckValidationColor runCheck37(final GroupData groupData) {
if (groupData.getPreviousPrequalification()==null) {
if (groupData.getTopupMembers().size()<=0) {
return null;
}
final String reportName = Policies.THIRTY_SEVEN.getName() + " Policy Check";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ static final class GroupTypeLoanMapper implements RowMapper<LoanData> {
this.schema = """
SELECT ml.id AS loanId,
mc.id AS clientId,
ml.is_topup AS isTopup,
mpg.id AS prequalificationId,
mg.id AS groupId,
ml.principal_amount AS principalAmount
Expand All @@ -1071,10 +1072,11 @@ public LoanData mapRow(ResultSet rs, int rowNum) throws SQLException {
final Long loanId = JdbcSupport.getLong(rs, "loanId");
final Long clientId = JdbcSupport.getLong(rs, "clientId");
final Long prequalificationId = JdbcSupport.getLong(rs, "prequalificationId");
final Boolean isTopup = rs.getBoolean("isTopup");
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).build();
.principalAmount(principalAmount).isTopup(isTopup).build();

}
}
Expand All @@ -1088,6 +1090,7 @@ static final class IndividualTypeLoanMapper implements RowMapper<LoanData> {
SELECT ml.id AS loanId,
mc.id AS clientId,
mpg.id AS prequalificationId,
ml.is_topup AS isTopup,
ml.principal_amount AS principalAmount
FROM m_prequalification_group mpg
INNER JOIN m_prequalification_group_members mpgm ON mpg.id = mpgm.group_id
Expand All @@ -1107,9 +1110,10 @@ public LoanData mapRow(ResultSet rs, int rowNum) throws SQLException {
final Long loanId = JdbcSupport.getLong(rs, "loanId");
final Long clientId = JdbcSupport.getLong(rs, "clientId");
final Long prequalificationId = JdbcSupport.getLong(rs, "prequalificationId");
final Boolean isTopup = rs.getBoolean("isTopup");
final BigDecimal principalAmount = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "principalAmount");
return LoanData.builder().loanId(loanId).clientId(clientId).prequalificationId(prequalificationId)
.principalAmount(principalAmount).build();
.principalAmount(principalAmount).isTopup(isTopup).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,135 @@
]]>
</sql>
</changeSet>
<changeSet id="3" author="fineract">
<sql>
<![CDATA[
INSERT INTO m_product_policy (policy_id, product_id, evaluation_type) VALUES((select id from m_policy where name = 'Categories of clients to accept' limit 1), 3, 'INDIVIDUAL');
]]>
</sql>
</changeSet>
<changeSet id="4" author="fineract">
<sql>
<![CDATA[
INSERT INTO m_product_policy (policy_id, product_id, evaluation_type) VALUES((select id from m_policy where name = 'Payments outside the current term of the main product' limit 1), 3, 'INDIVIDUAL');
]]>
</sql>
</changeSet>

<changeSet id="5" author="fineract">
<sql>
<![CDATA[
UPDATE stretchy_report SET report_sql = "SELECT prequalification_details.client_count,
CASE WHEN prequalification_details.client_count / ${numberOfMembers} * 100 >= 50 THEN 'GREEN'
ELSE 'RED'
END as color
FROM m_prequalification_group mpg
LEFT JOIN (
SELECT p.id AS prequalification_id,
(SELECT COUNT(mc.id)
FROM m_prequalification_group mp
JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id
JOIN m_client mc ON mc.dpi = mpgm.dpi
JOIN m_loan ml ON ml.client_id = mc.id
WHERE ml.loan_status_id < 300 AND ml.product_id = ${loanProductId} AND ml.is_topup = 1
AND mc.loan_cycle >= 2
AND mp.id = ${prequalificationId}
) AS client_count
FROM m_prequalification_group p where p.id = ${prequalificationId}
) prequalification_details ON prequalification_details.prequalification_id = mpg.id
WHERE mpg.id = ${prequalificationId}" WHERE report_name = "Number Of Cycles Policy Check";
]]>
</sql>
</changeSet>

<changeSet id="6" author="fineract">
<sql>
<![CDATA[
UPDATE stretchy_report SET report_sql = "SELECT overdue_loans.loan_count overdue_loan_count, recredit_loans.loan_count recredit_loan_count,
CASE
WHEN overdue_loans.loan_count <= 0 THEN 'GREEN'
ELSE 'RED'
END as color
FROM m_prequalification_group mpg
LEFT JOIN (
SELECT p.id AS prequalification_id,
(SELECT COUNT(distinct ml.id)
FROM m_prequalification_group mp
JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id
JOIN m_client mc ON mc.dpi = mpgm.dpi
JOIN m_loan ml ON ml.client_id = mc.id
JOIN m_loan_repayment_schedule mlrs on mlrs.loan_id = ml.id
WHERE ml.loan_status_id = 300 AND ml.product_id = ${loanProductId} AND (ml.is_topup IS NULL OR ml.is_topup = 0)
AND mlrs.duedate < CURRENT_DATE AND mlrs.obligations_met_on_date IS NULL
AND mp.id = ${prequalificationId}
) AS loan_count
FROM m_prequalification_group p where p.id = ${prequalificationId}
)overdue_loans ON overdue_loans.prequalification_id = mpg.id
LEFT JOIN (
SELECT p.id AS prequalification_id,
(SELECT COUNT(ml.id)
FROM m_prequalification_group mp
JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id
JOIN m_client mc ON mc.dpi = mpgm.dpi
JOIN m_loan ml ON ml.client_id = mc.id
WHERE ml.loan_status_id < 300 AND ml.product_id = ${loanProductId} AND ml.is_topup = 1
AND mp.id = ${prequalificationId}
) AS loan_count
FROM m_prequalification_group p where p.id = ${prequalificationId}
)recredit_loans ON recredit_loans.prequalification_id = mpg.id
WHERE mpg.id = ${prequalificationId} AND recredit_loans.loan_count>0"
WHERE report_name = "Clients In Arrears Policy Check";
]]>
</sql>
</changeSet>

<changeSet id="7" author="fineract">
<sql>
<![CDATA[
UPDATE stretchy_report
SET report_sql = "SELECT main_loans.loan_count main_loan_count, recredit_loans.loan_count recredit_loan_count,
CASE
WHEN recredit_loans.loan_count = main_loans.loan_count THEN 'GREEN'
ELSE 'RED'
END as color
FROM m_prequalification_group mpg
LEFT JOIN (
SELECT p.id AS prequalification_id,
(SELECT COUNT(ml.id)
FROM m_prequalification_group mp
JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id
JOIN m_client mc ON mc.dpi = mpgm.dpi
JOIN m_loan ml ON ml.client_id = mc.id
WHERE ml.loan_status_id < 300 AND ml.product_id = ${loanProductId} AND ml.is_topup = 1
AND mp.id = ${prequalificationId}
) AS loan_count
FROM m_prequalification_group p where p.id = ${prequalificationId}
)recredit_loans ON recredit_loans.prequalification_id = mpg.id
LEFT JOIN (
SELECT p.id AS prequalification_id,
(SELECT COUNT(ml.id)
FROM m_prequalification_group mp
JOIN m_group_client mgc ON mgc.group_id = (SELECT group_id from m_loan where prequalification_id = ${prequalificationId} limit 1)
JOIN m_client mc ON mc.id = mgc.client_id
JOIN m_loan ml ON ml.client_id = mc.id
WHERE ml.loan_status_id = 300 AND ml.product_id = ${loanProductId} AND (ml.is_topup IS NULL OR ml.is_topup = 0)
AND mp.id = ${prequalificationId} AND ml.prequalification_id is not null
) AS loan_count
FROM m_prequalification_group p where p.id = ${prequalificationId}
)main_loans ON main_loans.prequalification_id = mpg.id
WHERE mpg.id = ${prequalificationId}"
WHERE report_name = "Percentage Of Clients To Be Recredited In The Group Policy Check";
]]>
</sql>
</changeSet>
<changeSet id="8" author="fineract">
<sql>
<![CDATA[
update m_policy set description = 'Cantidad de ciclos cancelados como grupo' where description = 'Cantidade ciclos cancelados como grupo';
update m_policy set description = 'Categorízación de clienta recurrente' where description = 'Categoríazación de clienta recurruente';
]]>
</sql>
</changeSet>

</databaseChangeLog>

0 comments on commit 980f00c

Please sign in to comment.