From 980f00c00f2a621179a16e0c9fa74982ab756f77 Mon Sep 17 00:00:00 2001 From: Brian Muhimbura Date: Wed, 5 Jun 2024 14:41:53 +0300 Subject: [PATCH] Qa/fbr 673 674 (#769) * fix FBR 674 * fix REPORTS * fix Topu Loan Policies * Fix/fbr 673 (#768) * fix Policy Labels * fix Hard Policy Labels --- .../prequalification/data/ClientData.java | 2 + .../prequalification/data/GroupData.java | 1 + .../prequalification/data/LoanData.java | 1 + ...tionChecklistWritePlatformServiceImpl.java | 25 ++-- ...qualificationWritePlatformServiceImpl.java | 8 +- .../parts/0133_UpdateNewHardPolicyQueries.xml | 130 ++++++++++++++++++ 6 files changed, 157 insertions(+), 10 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/ClientData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/ClientData.java index 793dc2da900..3042939ae15 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/ClientData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/ClientData.java @@ -44,4 +44,6 @@ public class ClientData { private String recreditCategorization; private Boolean president; private Integer buroCheckStatus; + private Boolean isLoanTopup; + private Long loanCycle; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/GroupData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/GroupData.java index 2f64e33b43d..ec918297ea3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/GroupData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/GroupData.java @@ -33,4 +33,5 @@ public class GroupData { private BigDecimal requestedAmount; private Integer numberOfMembers; private List members; + private List topupMembers; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/LoanData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/LoanData.java index b8f5323e243..1710b22a7df 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/LoanData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/data/LoanData.java @@ -33,4 +33,5 @@ public class LoanData { private Long prequalificationMemberId; private String dpi; private BigDecimal principalAmount; + private Boolean isTopup; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java index a4b089f4eff..64ddc31450b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java @@ -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 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 validationChecklistResults = new ArrayList<>(); final List groupPolicies = this.jdbcTemplate.query(this.policyMapper.schema(), this.policyMapper, productId, @@ -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); @@ -243,13 +247,15 @@ private static final class ClientDataMapper implements RowMapper { 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 = ? """; } @@ -257,10 +263,12 @@ mpgm.requested_amount AS requestedAmount, IFNULL(mc.date_of_birth, mpgm.dob) AS @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"); @@ -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(); } } @@ -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()); @@ -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"; @@ -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"; diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java index 0c4ad2b9b21..421e36fed97 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java @@ -1046,6 +1046,7 @@ static final class GroupTypeLoanMapper implements RowMapper { 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 @@ -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(); } } @@ -1088,6 +1090,7 @@ static final class IndividualTypeLoanMapper implements RowMapper { 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 @@ -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(); } } diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0133_UpdateNewHardPolicyQueries.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0133_UpdateNewHardPolicyQueries.xml index a1541e91c58..6184e86524e 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0133_UpdateNewHardPolicyQueries.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0133_UpdateNewHardPolicyQueries.xml @@ -69,5 +69,135 @@ ]]> + + + + + + + + + + + + + + = 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"; + ]]> + + + + + + 0" + WHERE report_name = "Clients In Arrears Policy Check"; + ]]> + + + + + + + + + + + + +