From f052cb18e535eff498ff7445deee4198bf502e7c Mon Sep 17 00:00:00 2001 From: Faheem Ahmad Date: Thu, 2 May 2024 12:20:40 +0500 Subject: [PATCH 1/2] initial commit FBR-644 hard policy updates --- .../prequalification/domain/Policies.java | 10 +- ...tionChecklistWritePlatformServiceImpl.java | 118 +++ ...hard_policy_checks_updates_sql_updates.xml | 813 ++++++++++++++++++ 3 files changed, 940 insertions(+), 1 deletion(-) create mode 100644 fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/Policies.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/Policies.java index 870a346eab5..8c5a017ceac 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/Policies.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/Policies.java @@ -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; 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 8e5a005188f..cb1f5537c12 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 @@ -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; @@ -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 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); } @@ -483,6 +489,7 @@ 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 reportParams = new HashMap<>(); reportParams.put("${prequalificationId}", prequalificationId); reportParams.put("${loanProductId}", productId); @@ -490,6 +497,7 @@ private CheckValidationColor runCheck6(final GroupData groupData) { 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); } @@ -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 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); } @@ -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 @@ -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> res = this.jdbcTemplate.queryForList(query, + new Object[] {prequalificationId}); + if (!res.isEmpty()) { + Map 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 reportParams = new HashMap<>(); reportParams.put("${clientId}", clientId); reportParams.put("${loanProductId}", productId); @@ -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); } @@ -1087,4 +1124,85 @@ 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 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 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 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 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 }; + return this.jdbcTemplate.queryForObject(currentCreditValueSQL, Integer.class, params); + } + } diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml new file mode 100644 index 00000000000..6d13c8cd6e6 --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml @@ -0,0 +1,813 @@ + + + + + + + + 1500) AND (IFNULL(${currentCreditValue}, 0) <= 3000) AND (IFNULL(${percentageIncrease}, 0) <= 150) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 3000) AND (IFNULL(${currentCreditValue}, 0) <= 3500) AND (IFNULL(${percentageIncrease}, 0) <= 100) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 3500) AND (IFNULL(${currentCreditValue}, 0) <= 4000) AND (IFNULL(${percentageIncrease}, 0) <= 80) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 4000) AND (IFNULL(${percentageIncrease}, 0) <= 60) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) <= 1500) AND (IFNULL(${percentageIncrease}, 0) > 200) THEN 'RED' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 1500) AND (IFNULL(${currentCreditValue}, 0) <= 3000) AND (IFNULL(${percentageIncrease}, 0) > 150) THEN 'RED' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 3000) AND (IFNULL(${currentCreditValue}, 0) <= 3500) AND (IFNULL(${percentageIncrease}, 0) > 100) THEN 'RED' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 3500) AND (IFNULL(${currentCreditValue}, 0) <= 4000) AND (IFNULL(${percentageIncrease}, 0) > 80) THEN 'RED' + WHEN (${loanProductId} = 2) AND (IFNULL(${currentCreditValue}, 0) > 4000) AND (IFNULL(${percentageIncrease}, 0) > 60) THEN 'RED' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) <= 1500) AND (IFNULL(${percentageIncrease}, 0) <= 200) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 1500) AND (IFNULL(${currentCreditValue}, 0) <= 3000) AND (IFNULL(${percentageIncrease}, 0) <= 150) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 3000) AND (IFNULL(${currentCreditValue}, 0) <= 3500) AND (IFNULL(${percentageIncrease}, 0) <= 100) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 3500) AND (IFNULL(${currentCreditValue}, 0) <= 4000) AND (IFNULL(${percentageIncrease}, 0) <= 80) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 4000) AND (IFNULL(${percentageIncrease}, 0) <= 60) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) <= 1500) AND (IFNULL(${percentageIncrease}, 0) > 200) THEN 'RED' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 1500) AND (IFNULL(${currentCreditValue}, 0) <= 3000) AND (IFNULL(${percentageIncrease}, 0) > 150) THEN 'RED' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 3000) AND (IFNULL(${currentCreditValue}, 0) <= 3500) AND (IFNULL(${percentageIncrease}, 0) > 100) THEN 'RED' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 3500) AND (IFNULL(${currentCreditValue}, 0) <= 4000) AND (IFNULL(${percentageIncrease}, 0) > 80) THEN 'RED' + WHEN (${loanProductId} = 9) AND (IFNULL(${currentCreditValue}, 0) > 4000) AND (IFNULL(${percentageIncrease}, 0) > 60) THEN 'RED' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) <= 1500) AND (IFNULL(${percentageIncrease}, 0) <= 200) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 1500) AND (IFNULL(${currentCreditValue}, 0) <= 3000) AND (IFNULL(${percentageIncrease}, 0) <= 150) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 3000) AND (IFNULL(${currentCreditValue}, 0) <= 3500) AND (IFNULL(${percentageIncrease}, 0) <= 100) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 3500) AND (IFNULL(${currentCreditValue}, 0) <= 4000) AND (IFNULL(${percentageIncrease}, 0) <= 80) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 4000) AND (IFNULL(${percentageIncrease}, 0) <= 60) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) <= 1500) AND (IFNULL(${percentageIncrease}, 0) > 200) THEN 'RED' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 1500) AND (IFNULL(${currentCreditValue}, 0) <= 3000) AND (IFNULL(${percentageIncrease}, 0) > 150) THEN 'RED' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 3000) AND (IFNULL(${currentCreditValue}, 0) <= 3500) AND (IFNULL(${percentageIncrease}, 0) > 100) THEN 'RED' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 3500) AND (IFNULL(${currentCreditValue}, 0) <= 4000) AND (IFNULL(${percentageIncrease}, 0) > 80) THEN 'RED' + WHEN (${loanProductId} = 8) AND (IFNULL(${currentCreditValue}, 0) > 4000) AND (IFNULL(${percentageIncrease}, 0) > 60) THEN 'RED' + WHEN (${loanProductId} = 4) AND (IFNULL(${percentageIncrease}, 0) <= 60) THEN 'GREEN' + WHEN (${loanProductId} = 4) AND (IFNULL(${percentageIncrease}, 0) > 60) THEN 'ORANGE' + WHEN (${loanProductId} = 5) AND (IFNULL(${percentageIncrease}, 0) <= 60) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (IFNULL(${percentageIncrease}, 0) > 60) THEN 'ORANGE' + END AS color + FROM m_client mc + WHERE mc.id = ${clientId} + GROUP BY mc.id" WHERE report_name = "Increase percentage Policy Check"; + ]]> + + + + + + = 7) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') + AND (prequalification_details.recurring_members_count / ${numberOfMembers} < 50) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') + AND (prequalification_details.recurring_members_count / ${numberOfMembers} < 50) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND (prequalification_details.recurring_members_count / ${numberOfMembers} >= 50) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND (prequalification_details.recurring_members_count / ${numberOfMembers} >= 50) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} < 7) THEN 'ORANGE' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} < 7) THEN 'ORANGE' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} < 7) THEN 'ORANGE' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 7) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} < 7) THEN 'ORANGE' + WHEN (${loanProductId} = 4) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} >= 0) THEN 'GREEN' + WHEN (${loanProductId} = 4) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} >= 0) THEN 'GREEN' + WHEN (${loanProductId} = 4) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 0) THEN 'GREEN' + WHEN (${loanProductId} = 4) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 0) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} >= 2) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${numberOfMembers} < 2) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} >= 2) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${numberOfMembers} < 2) THEN 'GREEN' + END AS color + FROM m_prequalification_group mpg + INNER JOIN ( + SELECT p.id AS prequalification_id, + (CASE WHEN p.previous_prequalification IS NOT NULL THEN 'RECREDITO' ELSE 'NUEVO' END) AS recreditCategorization, + (select count(*) FROM m_prequalification_group mp + LEFT JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id + LEFT JOIN m_client mc ON mc.dpi = mpgm.dpi + LEFT JOIN m_loan ml ON ml.client_id = mc.id + LEFT JOIN m_loan_additionals_group mlag on mlag.loan_id = ml.id + LEFT JOIN m_code_value mcv on mcv.id = mlag.loan_cycle_completed + WHERE + ml.loan_status_id < 300 AND ml.product_id = ${loanProductId} + AND ((mc.loan_cycle > 0) OR (mc.loan_cycle <= 2 AND mcv.code_value = 'fromAnotherGroup')) + AND mp.id = ${prequalificationId} + ) recurring_members_count + FROM m_prequalification_group p + ) prequalification_details ON prequalification_details.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}" WHERE report_name = "Number of members according to policy Policy Check"; + ]]> + + + + + + 0 AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 1500 AND 20000) THEN 'GREEN' + WHEN (${loanProductId} = 4) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN' + WHEN (${loanProductId} = 4) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN' + WHEN (${loanProductId} = 5) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${requestedAmount} BETWEEN 5000 AND 25000) THEN 'GREEN' + END AS color + FROM m_prequalification_group mpg + INNER JOIN ( + SELECT p.id AS prequalification_id, + (CASE WHEN p.previous_prequalification IS NOT NULL THEN 'RECREDITO' ELSE 'NUEVO' END) AS recreditCategorization + FROM m_prequalification_group p + ) prequalification_details ON prequalification_details.prequalification_id = mpg.id + LEFT JOIN ( + SELECT p.id AS prequalification_id, + (select count(ml.id) FROM m_prequalification_group mp + LEFT JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id + LEFT JOIN m_client mc ON mc.dpi = mpgm.dpi + LEFT 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} + ) recredit_count + FROM m_prequalification_group p + ) recredit_loan ON recredit_loan.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}" WHERE report_name = "Minimum and maximum amount Policy Check"; + ]]> + + + + + + 3) THEN 'YELLOW' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} > 4) THEN 'YELLOW' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} BETWEEN 1 AND 3) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} > 3) THEN 'YELLOW' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} > 4) THEN 'YELLOW' + + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} > 4) THEN 'YELLOW' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} > 4) THEN 'YELLOW' + + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} BETWEEN 1 AND 3) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} > 3) THEN 'YELLOW' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} BETWEEN 1 AND 3) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} > 3) THEN 'YELLOW' + + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} BETWEEN 1 AND 3) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} > 3) THEN 'YELLOW' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') AND (${disparityRatio} > 4) THEN 'YELLOW' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} BETWEEN 1 AND 3) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} > 3) THEN 'YELLOW' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (${disparityRatio} > 4) THEN 'YELLOW' + + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} > 4) THEN 'YELLOW' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} > 4) THEN 'YELLOW' + + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} > 4) THEN 'YELLOW' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} > 4) THEN 'YELLOW' + + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'URBAN') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} > 4) THEN 'YELLOW' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} BETWEEN 1 AND 4) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') + AND recredit_loan.recredit_count > 0 AND (${disparityRatio} > 4) THEN 'YELLOW' + + END AS color + FROM m_prequalification_group mpg + INNER JOIN ( + SELECT p.id AS prequalification_id, + (CASE WHEN p.previous_prequalification IS NOT NULL THEN 'RECREDITO' ELSE 'NUEVO' END) AS recreditCategorization + FROM m_prequalification_group p + ) prequalification_details ON prequalification_details.prequalification_id = mpg.id + LEFT JOIN ( + SELECT p.id AS prequalification_id, + (select count(ml.id) FROM m_prequalification_group mp + LEFT JOIN m_prequalification_group_members mpgm ON mpgm.group_id = mp.id + LEFT JOIN m_client mc ON mc.dpi = mpgm.dpi + LEFT 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} + ) recredit_count + FROM m_prequalification_group p + ) recredit_loan ON recredit_loan.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}" WHERE report_name = "Value disparity Policy Check"; + ]]> + + + + + + = 3) THEN 'RECURRING' + WHEN (${loanProductId} IN (4,5)) AND (COALESCE(mc.loan_cycle, 0) >= 1) THEN 'RECURRING' + ELSE 'NEW' + END AS clientCategorization, + 'GREEN' AS color, + CASE + WHEN client_area.code_value = 'Urbana' THEN 'URBANA' + WHEN client_area.code_value = 'Rural' THEN 'RURAL' + WHEN client_area.code_value = 'PeriUrbana' THEN 'PERI_URBANA' + ELSE 'RURAL' + END AS clientArea, + CASE + WHEN COALESCE(client_loan_details.number_of_submitted_loans, 0) > 0 THEN 'RECREDITO' + ELSE 'NUEVO' + END AS recreditCategorization, + client_loan_details.submittedon_years, + client_loan_details.rejoining_years, + client_loan_details.number_of_loan_cycles, + client_loan_details.number_of_closed_loans, + client_loan_details.number_of_submitted_loans + FROM m_client mc + INNER JOIN ( + SELECT mcl.id AS client_id, + TIMESTAMPDIFF(YEAR, mcl.submittedon_date, CURDATE()) AS submittedon_years, + IFNULL(TIMESTAMPDIFF(YEAR, mcl.submittedon_date, mcl.reactivated_on_date), 0) AS rejoining_years, + COALESCE((SELECT COUNT(*) FROM m_loan WHERE client_id = mcl.id AND approvedon_date IS NOT NULL), 0) AS number_of_loan_cycles, + COALESCE((SELECT COUNT(*) FROM m_loan WHERE client_id = mcl.id AND loan_status_id = 600), 0) AS number_of_closed_loans, + COALESCE((SELECT COUNT(*) FROM m_loan WHERE client_id = mcl.id), 0) AS number_of_submitted_loans + FROM m_client mcl + )client_loan_details ON client_loan_details.client_id = mc.id + LEFT JOIN m_client_contact_info mcci ON mcci.client_id = mc.id + LEFT JOIN m_code_value client_area ON client_area.id = mcci.area + WHERE mc.id = ${clientId} + GROUP BY mc.id " WHERE report_name = "Client Categorization Policy Check"; + ]]> + + + + + + = 1) AND (${requestedAmount} BETWEEN 10000 AND 40000 ) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'NUEVO') AND ('${businessAge}' >= 1.5) AND (${requestedAmount} BETWEEN 20000 AND 60000 ) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'NUEVO') AND ('${businessAge}' >= 2) AND (${requestedAmount} > 60000 ) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'NUEVO') AND ('${businessAge}' < 1) AND (${requestedAmount} BETWEEN 10000 AND 40000 ) THEN 'RED' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'NUEVO') AND ('${businessAge}' < 1.5) AND (${requestedAmount} BETWEEN 20000 AND 60000 ) THEN 'RED' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'NUEVO') AND ('${businessAge}' < 2) AND (${requestedAmount} > 60000 ) THEN 'RED' + + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ('${businessAge}' >= 1) AND (${requestedAmount} BETWEEN 10000 AND 40000 ) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ('${businessAge}' >= 1.5) AND (${requestedAmount} BETWEEN 40000 AND 60000 ) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ('${businessAge}' >= 2) AND (${requestedAmount} > 60000 ) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ('${businessAge}' < 1) AND (${requestedAmount} BETWEEN 10000 AND 40000 ) THEN 'RED' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ('${businessAge}' < 1.5) AND (${requestedAmount} BETWEEN 40000 AND 60000 ) THEN 'RED' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ('${businessAge}' < 2) AND (${requestedAmount} > 60000 ) THEN 'RED' + + END AS color + FROM m_client mc + WHERE mc.id = ${clientId}" + WHERE report_name = "Age Of Business Policy Check"; + ]]> + + + + + + 250000) THEN 'RED' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND (${requestedAmount} BETWEEN 10000 AND 250000) THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND (${requestedAmount} < 10000 OR ${requestedAmount} > 250000) THEN 'RED' + END AS color + FROM m_client mc + WHERE mc.id = ${clientId}" WHERE report_name = "Amount Policy Check"; + ]]> + + + + + + = 50) THEN 'GREEN' + WHEN ('${loanProductId}' = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ( COALESCE(client_details.principal_paid_percentage, 0) >= 40) THEN 'GREEN' + WHEN ('${loanProductId}' = 6) AND ('${recreditCategorization}' = 'RECREDITO') AND ( COALESCE(client_details.principal_paid_percentage, 0) < 40) THEN 'RED' + WHEN ('${loanProductId}' = 3) AND ( COALESCE(client_details.principal_paid_percentage, 0) >= 50) THEN 'GREEN' + END AS color + FROM m_client mc + INNER JOIN ( + SELECT mc.id AS client_id, (100 * SUM(ml.principal_repaid_derived)/SUM(ml.principal_disbursed_derived)) AS principal_paid_percentage + FROM m_client mc + LEFT JOIN m_loan ml ON ml.client_id = mc.id + WHERE ml.loan_status_id in (300,600) AND COALESCE(ml.principal_disbursed_derived, 0) > 0 + GROUP BY mc.id + )client_details ON client_details.client_id = mc.id + WHERE mc.id = ${clientId}" WHERE report_name = "Credits Policy Check"; + ]]> + + + + + + = 1) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND (client_details.number_of_principal_loans >= 1) THEN 'GREEN' + END AS color + FROM m_client mc + INNER JOIN ( + SELECT mc.id AS client_id, COUNT(DISTINCT ml.id) AS number_of_principal_loans + FROM m_client mc + LEFT JOIN m_loan ml ON ml.client_id = mc.id + WHERE ml.product_id IN (2, 4, 5, 6, 8, 9) AND (ml.loan_status_id = 300) + GROUP BY mc.id + )client_details ON client_details.client_id = mc.id + WHERE mc.id = ${clientId}" WHERE report_name = "General condition Policy Check"; + ]]> + + + + + + 5 AND ((client_details.current_loan_amount) * 150/100 <= ${requestedAmount}) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND client_details.loan_cycle = 2 AND (${requestedAmount} <= 2000) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND client_details.loan_cycle = 3 AND (${requestedAmount} <= 3000) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND client_details.loan_cycle >= 4 AND (${requestedAmount} BETWEEN 3001 AND 5000) AND (${photographCount} > 0) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND (${requestedAmount} BETWEEN 1000 AND 3000) AND payment_details.completed_installment_count < 1 AND (${photographCount} > 0) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND (${requestedAmount} > client_details.current_loan_amount) THEN 'RED' + WHEN ('${loanProductId}' = 3) AND (${requestedAmount} > 5000) THEN 'RED' + END AS color + FROM m_client mc + INNER JOIN ( + SELECT mc.id AS client_id, mc.loan_cycle, (select COALESCE(ml.principal_amount,0) from m_loan ml where ml.client_id = mc.id and ml.product_id not in (7,6,3) and ml.loan_status_id = 300 ORDER BY id desc limit 1 ) as current_loan_amount FROM m_client mc + )client_details ON client_details.client_id = mc.id + INNER JOIN ( + SELECT mc.id AS client_id, (select count(*) from m_loan_repayment_schedule mlrs join m_loan ml on ml.id = mlrs.loan_id where ml.client_id = mc.id and ml.product_id not in (7,6,3) and ml.loan_status_id = 300 and mlrs.obligations_met_on_date is not null) as completed_installment_count FROM m_client mc + )payment_details ON payment_details.client_id = mc.id + WHERE mc.id = ${clientId}" WHERE report_name = "Amount requested in relation to the current amount of main products Policy Check"; + ]]> + + + + + + 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 3) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 4) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 5) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 7) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 2 THEN 'GREEN' + WHEN (${loanProductId} = 8) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 9) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 10) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + ELSE 'RED' + END AS color + FROM m_client mc WHERE mc.id = ${clientId}" + WHERE report_name = "Mandatory to attach photographs and investment plan Policy Check"; + ]]> + + + + + + 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 3) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 4) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 5) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 7) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 2 THEN 'GREEN' + WHEN (${loanProductId} = 8) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 9) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 10) AND ${numberOfFirstDocument} > 0 AND ${numberOfSecondDocument} > 0 THEN 'GREEN' + ELSE 'RED' + END AS color + FROM m_client mc WHERE mc.id = ${clientId}" + WHERE report_name = "Mandatory to attach photographs and investment plan Policy Check"; + ]]> + + + + + 0 THEN 'GREEN' + WHEN (${loanProductId} = 3) AND ${numberOfDocuments} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 4) AND ${numberOfDocuments} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 5) AND ${numberOfDocuments} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 6) AND ${numberOfDocuments} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 7) AND ${requestedAmount} <= 7000) THEN 'GREEN' + WHEN (${loanProductId} = 7) AND ${requestedAmount} BETWEEN 7001 AND 10000) AND upper(${cliente_activo_fiador1}) = 'SI' AND ${categoria_fiador1} IN ('A', 'B', 'C', 'D') THEN 'GREEN' + WHEN (${loanProductId} = 7) AND ${requestedAmount} > 10000) AND upper(${cliente_activo_fiador1}) = 'SI' AND upper(${cliente_activo_fiador2}) = 'SI' AND ${categoria_fiador1} IN ('A', 'B', 'C', 'D') AND ${categoria_fiador2} IN ('A', 'B', 'C', 'D') THEN 'GREEN' + WHEN (${loanProductId} = 8) AND ${numberOfDocuments} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 9) AND ${numberOfDocuments} > 0 THEN 'GREEN' + WHEN (${loanProductId} = 10) AND ${numberOfDocuments} > 0 THEN 'GREEN' + ELSE 'RED' + END AS color + FROM m_client mc WHERE mc.id = ${clientId}" + WHERE report_name = "Add endorsement Policy Check"; + ]]> + + + + + = 5 AND (client_loan_details.number_of_installments - client_details.number_of_pending_installments <= 4) THEN 'GREEN' + WHEN ('${loanProductId}' = 7) AND client_details.loan_cycle >= 5 AND (client_loan_details.number_of_installments - client_details.number_of_pending_installments > 4) THEN 'ORANGE' + WHEN ('${loanProductId}' = 3) AND (client_loan_details.number_of_installments - client_details.number_of_pending_installments < 4) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND client_details.loan_cycle >= 5 AND (client_loan_details.number_of_installments - client_details.number_of_pending_installments <= 4) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND client_details.loan_cycle >= 5 AND (client_loan_details.number_of_installments - client_details.number_of_pending_installments > 4) THEN 'ORANGE' + END AS color + FROM m_client mc + INNER JOIN ( + SELECT mc.id AS client_id, mc.loan_cycle, COUNT(DISTINCT RS.id) AS number_of_pending_installments + FROM m_client mc + LEFT JOIN m_loan ml ON ml.client_id = mc.id + LEFT JOIN m_loan_repayment_schedule RS ON RS.loan_id = ml.id + WHERE ml.product_id IN (2, 4, 5, 6, 8, 9) AND (ml.loan_status_id = 300) AND RS.completed_derived =0 + GROUP BY mc.id + )client_details ON client_details.client_id = mc.id + INNER JOIN ( + SELECT mc.id AS client_id,COUNT(DISTINCT RS.id) AS number_of_installments + FROM m_client mc + LEFT JOIN m_loan ml ON ml.client_id = mc.id + LEFT JOIN m_loan_repayment_schedule RS ON RS.loan_id = ml.id + WHERE ml.product_id IN (7) AND (ml.loan_status_id < 300) + GROUP BY mc.id + )client_loan_details ON client_loan_details.client_id = mc.id + WHERE mc.id = ${clientId}" WHERE report_name = "Payments outside the current term of the main product Policy Check"; + ]]> + + + + + + + + + + = 0) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'RECREDITO') AND ('${clientArea}' = 'RURAL') AND (COALESCE(prequalification_details.number_of_completed_loans, 0) >= 0) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'URBAN') AND (COALESCE(prequalification_details.number_of_completed_loans, 0) >= 0) THEN 'GREEN' + WHEN (${loanProductId} = 9) AND (prequalification_details.recreditCategorization = 'NUEVO') AND ('${clientArea}' = 'RURAL') AND (COALESCE(prequalification_details.number_of_completed_loans, 0) >= 0) THEN 'GREEN' + END AS color + FROM m_prequalification_group mpg + LEFT JOIN ( + SELECT p.id AS prequalification_id, + (CASE WHEN p.previous_prequalification IS NOT NULL THEN 'RECREDITO' ELSE 'NUEVO' END) AS recreditCategorization, + (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_loan ml ON ml.group_id = mg.id + WHERE ml.loan_status_id >= 600 AND mg.status_enum = 300 AND mp.id = ${prequalificationId} + GROUP BY mp.id) AS number_of_completed_loans + FROM m_prequalification_group p + )prequalification_details ON prequalification_details.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}" WHERE report_name = "Cancelled Cycles Count Policy Check"; + ]]> + + + + + + + + + + 50 THEN ''GREEN'' +WHEN prequalification_details.client_count > 0 THEN ''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 + )prequalification_details ON prequalification_details.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}', 'Number Of Cycles Policy Check', 0, 0, 0); + ]]> + + + + + 0 AND main_loans.loan_count = recredit_loans.loan_count THEN ''GREEN'' + WHEN recredit_loans.loan_count > 0 AND main_loans.loan_count != recredit_loans.loan_count THEN ''RED'' + WHEN recredit_loans.loan_count = 0 THEN ''GREEN'' + 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 + )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_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 IS NULL OR ml.is_topup = 0) + AND mp.id = ${prequalificationId} + ) AS loan_count + FROM m_prequalification_group p + )main_loans ON main_loans.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}', 'Percentage Of Clients To Be Recredited In The Group Policy Check', 0, 0, 0); + ]]> + + + + + 0 AND overdue_loans.loan_count = 0 THEN 'GREEN' + WHEN recredit_loans.loan_count > 0 AND overdue_loans.loan_count > 0 THEN 'RED' + WHEN recredit_loans.loan_count = 0 THEN 'GREEN' + 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 + )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 + )recredit_loans ON recredit_loans.prequalification_id = mpg.id + WHERE mpg.id = ${prequalificationId}', 'Clients In Arrears Policy Check', 0, 0, 0); + ]]> + + + + + + + + + From 723a2655c2ee1cb69db723d2d58d94ba319c7332 Mon Sep 17 00:00:00 2001 From: Faheem Ahmad Date: Fri, 3 May 2024 17:20:20 +0500 Subject: [PATCH 2/2] FBR-644 --- ...qualificationChecklistWritePlatformServiceImpl.java | 8 +++++++- ..._FBR_644_hard_policy_checks_updates_sql_updates.xml | 10 +++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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 cb1f5537c12..fba744c40bf 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 @@ -1202,7 +1202,13 @@ and COALESCE(mc.loan_cycle, 0) >= 3 GROUP BY mp.id """; final Object[] params = new Object[] { preQualificationId }; - return this.jdbcTemplate.queryForObject(currentCreditValueSQL, Integer.class, params); + Integer count = 0; + try { + count = this.jdbcTemplate.queryForObject(currentCreditValueSQL, Integer.class, params); + } catch (EmptyResultDataAccessException e) { + count = 0; + } + return count; } } diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml index 6d13c8cd6e6..a16bea14952 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0131_FBR_644_hard_policy_checks_updates_sql_updates.xml @@ -490,10 +490,6 @@ 0 THEN 'GREEN' WHEN (${loanProductId} = 3) AND ${numberOfDocuments} > 0 THEN 'GREEN' @@ -708,7 +704,7 @@ WHEN prequalification_details.client_count > 0 THEN ''RED'' ]]> - + - + - +