From ae4901e26b01e73b00270dc25e3e41f8c55b0e3d Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Fri, 7 Jun 2024 13:50:30 +0300 Subject: [PATCH] fix/FBR-676 --- .../prequalification/data/ClientData.java | 1 + .../prequalification/data/LoanData.java | 1 + ...ationChecklistReadPlatformServiceImpl.java | 6 +- ...tionChecklistWritePlatformServiceImpl.java | 77 +++++++++-------- ...qualificationWritePlatformServiceImpl.java | 6 +- .../parts/0133_UpdateNewHardPolicyQueries.xml | 84 +++++++++++++++++++ 6 files changed, 135 insertions(+), 40 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 3042939ae15..e5ea78805e5 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 @@ -46,4 +46,5 @@ public class ClientData { private Integer buroCheckStatus; private Boolean isLoanTopup; private Long loanCycle; + private String categorization; } 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 1710b22a7df..ffa4f77abc1 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 @@ -34,4 +34,5 @@ public class LoanData { private String dpi; private BigDecimal principalAmount; private Boolean isTopup; + private String loanCycleCompleted; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistReadPlatformServiceImpl.java index ed84a27dbb1..c0302a1dd1f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistReadPlatformServiceImpl.java @@ -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(); 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 64ddc31450b..4236d104f27 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 @@ -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); } } @@ -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 = ? @@ -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(); @@ -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); @@ -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 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); } @@ -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 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); } 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 421e36fed97..53a1178ee0a 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 @@ -1049,6 +1049,7 @@ static final class GroupTypeLoanMapper implements RowMapper { 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 @@ -1057,6 +1058,8 @@ static final class GroupTypeLoanMapper implements RowMapper { 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 @@ -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(); } } 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 6184e86524e..99ec66632d5 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 @@ -200,4 +200,88 @@ + + + + + + + + + + + + + + + + + +