From 548144a8366c5b5bf3ebe9b0ebb9aad1dd263647 Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Mon, 13 Nov 2023 13:15:58 +0300 Subject: [PATCH 1/4] Policy Checks Implementations --- ...tionChecklistWritePlatformServiceImpl.java | 28 +++++++-- .../tenant/commands/policy_run_10.sql | 57 +++++++++++++++++++ .../tenant/commands/policy_run_14.sql | 56 ++++++++++++++++++ ...FBR_372_hard_policy_check_sql_redesign.xml | 17 ++++++ 4 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql create mode 100644 fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_14.sql 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 2b97921c87e..5d1852b13d9 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 @@ -227,7 +227,7 @@ private CheckValidationColor validateGenericPolicy(final Policies policy, final case SEVEN -> checkValidationColor = this.runCheck7(groupData); case EIGHT -> checkValidationColor = this.runCheck8(groupData); case NINE -> checkValidationColor = this.runCheck9(); - case TEN -> checkValidationColor = this.runCheck10(); + case TEN -> checkValidationColor = this.runCheck10(groupData); case ELEVEN -> checkValidationColor = this.runCheck11(groupData); case TWELVE -> checkValidationColor = this.runCheck12(clientData); case THIRTEEN -> checkValidationColor = this.runCheck13(clientData); @@ -466,9 +466,19 @@ private CheckValidationColor runCheck9() { /** * Percentage of members with their own home + * @param groupData */ - private CheckValidationColor runCheck10() { - return CheckValidationColor.RED; + private CheckValidationColor runCheck10(GroupData groupData) { + final String reportName = Policies.TEN.getName() + " Policy Check"; + + final String prequalificationId = String.valueOf(groupData.getId()); + final String productId = String.valueOf(groupData.getId()); + 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); } /** @@ -539,7 +549,17 @@ private CheckValidationColor runCheck13(final ClientData clientData) { * Amount requested in relation to the current amount of main products */ private CheckValidationColor runCheck14(final ClientData clientData) { - return CheckValidationColor.RED; + final String clientId = String.valueOf(clientData.getClientId()); + 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 Map reportParams = new HashMap<>(); + reportParams.put("${clientId}", clientId); + reportParams.put("${loanProductId}", productId); + reportParams.put("${requestedAmount}", requestedAmount); + final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false); + return extractColorFromResultset(result); } /** diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql new file mode 100644 index 00000000000..1d7ace8853d --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql @@ -0,0 +1,57 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +-- liquibase formatted sql +-- changeset fineract:1 +-- MySQL dump 10.13 Distrib 5.1.60, for Win32 (ia32) +-- +-- Host: localhost Database: fineract_default +-- ------------------------------------------------------ +-- Server version 5.1.60-community + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES UTF8MB4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- Percentage of members with their own home -- +INSERT INTO stretchy_report (report_name,report_type,report_category,report_sql,description,core_report,use_report,self_service_user_report) +VALUES ("Percentage of members with their own home Policy Check", "Table", "Prequalification", +"SELECT + housing_type.owner_percent, + CASE + WHEN (${loanProductId} = 2) AND (housing_type.owner_percent <=50) THEN 'GREEN' + WHEN (${loanProductId} = 2) AND (housing_type.owner_percent >50) THEN 'YELLOW' + + WHEN (${loanProductId} = 8) AND (housing_type.owner_percent <=50) THEN 'GREEN' + WHEN (${loanProductId} = 8) AND (housing_type.owner_percent >50) THEN 'YELLOW' + + END AS color + FROM m_prequalification_group mpg + INNER JOIN ( select (((select count(*) from m_prequalification_group_members mpm INNER JOIN m_client mc on mc.dpi = mpm.dpi + INNER JOIN m_client_contact_info mcinf on mcinf.client_id = mc.id INNER JOIN m_code_value mcv on mcv.id = mcinf.housing_type where mcv.code_value = 'Propia' and mpm.group_id = ${groupId})/ + (select count(*) from m_prequalification_group_members mpg where mpg.group_id = ${prequalificationId}))*100) as owner_percent, ${prequalificationId} as grp_id ) + housing_type ON housing_type.grp_id = mpg.id + WHERE mpg.id = ${prequalificationId}", "Percentage of members with their own home Policy Check", 0, 0, 0); diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_14.sql b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_14.sql new file mode 100644 index 00000000000..82575464d2a --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_14.sql @@ -0,0 +1,56 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +-- liquibase formatted sql +-- changeset fineract:1 +-- MySQL dump 10.13 Distrib 5.1.60, for Win32 (ia32) +-- +-- Host: localhost Database: fineract_default +-- ------------------------------------------------------ +-- Server version 5.1.60-community + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES UTF8MB4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- Amount requested in relation to the current amount of main products -- +INSERT INTO stretchy_report (report_name,report_type,report_category,report_sql,description,core_report,use_report,self_service_user_report) +VALUES ("Amount requested in relation to the current amount of main products", "Table", "Prequalification", + "SELECT + client_details.number_of_principal_loans, + CASE + WHEN ('${loanProductId}' = 7) AND ((client_details.current_loan_amount)/${requestedAmount} <= 4) THEN 'GREEN' + WHEN ('${loanProductId}' = 7) AND ((client_details.current_loan_amount)/${requestedAmount} = 5) THEN 'GREEN' + WHEN ('${loanProductId}' = 7) AND ((client_details.current_loan_amount)/${requestedAmount} >= 6) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND (${requestedAmount} <= 3000) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND (${requestedAmount} > client_details.current_loan_amount) THEN 'RED' + WHEN ('${loanProductId}' = 3) AND (${requestedAmount} > 3000) THEN 'RED' + END AS color + FROM m_client mc + INNER JOIN ( + SELECT mc.id AS client_id, (select COALESCE(ml.principal_amount,0) from m_loan ml where ml.client_id = mc.id and ml.product_id = ${loanProductId} 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 + WHERE mc.id = ${clientId}", "Amount requested in relation to the current amount of main products", 0, 0, 0); diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml index 4163b2d0854..140182f9b35 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml @@ -471,4 +471,21 @@ stripComments="true"/> + + + + + + + From 60e44a0a57ee8186565833e3fd5b064cee7b50a6 Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Mon, 13 Nov 2023 14:54:53 +0300 Subject: [PATCH 2/4] Policy Checks Implementations --- .../resources/db/changelog/tenant/commands/policy_run_10.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql index 1d7ace8853d..8ff10751ae5 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql +++ b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_10.sql @@ -51,7 +51,7 @@ VALUES ("Percentage of members with their own home Policy Check", "Table", "Preq END AS color FROM m_prequalification_group mpg INNER JOIN ( select (((select count(*) from m_prequalification_group_members mpm INNER JOIN m_client mc on mc.dpi = mpm.dpi - INNER JOIN m_client_contact_info mcinf on mcinf.client_id = mc.id INNER JOIN m_code_value mcv on mcv.id = mcinf.housing_type where mcv.code_value = 'Propia' and mpm.group_id = ${groupId})/ + INNER JOIN m_client_contact_info mcinf on mcinf.client_id = mc.id INNER JOIN m_code_value mcv on mcv.id = mcinf.housing_type where mcv.code_value = 'Propia' and mpm.group_id = ${prequalificationId})/ (select count(*) from m_prequalification_group_members mpg where mpg.group_id = ${prequalificationId}))*100) as owner_percent, ${prequalificationId} as grp_id ) housing_type ON housing_type.grp_id = mpg.id WHERE mpg.id = ${prequalificationId}", "Percentage of members with their own home Policy Check", 0, 0, 0); From 67408cdebb39b9710f7fa61c9e28a1332b7ca14a Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Mon, 13 Nov 2023 14:59:17 +0300 Subject: [PATCH 3/4] Policy Checks Implementations --- .../PrequalificationChecklistWritePlatformServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5d1852b13d9..f05c9fa18b7 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 @@ -472,7 +472,7 @@ private CheckValidationColor runCheck10(GroupData groupData) { final String reportName = Policies.TEN.getName() + " Policy Check"; final String prequalificationId = String.valueOf(groupData.getId()); - final String productId = String.valueOf(groupData.getId()); + final String productId = String.valueOf(groupData.getProductId()); final Map reportParams = new HashMap<>(); reportParams.put("${prequalificationId}", prequalificationId); reportParams.put("${loanProductId}", productId); From 95fe0f06397f68b613f4e51b6101af63adb66049 Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Mon, 13 Nov 2023 18:49:08 +0300 Subject: [PATCH 4/4] Policy Checks Implementations --- ...tionChecklistWritePlatformServiceImpl.java | 16 ++++- .../tenant/commands/policy_run_16.sql | 59 +++++++++++++++++++ ...FBR_372_hard_policy_check_sql_redesign.xml | 8 +++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_16.sql 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 f05c9fa18b7..98793b2fc58 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 @@ -233,7 +233,7 @@ private CheckValidationColor validateGenericPolicy(final Policies policy, final case THIRTEEN -> checkValidationColor = this.runCheck13(clientData); case FOURTEEN -> checkValidationColor = this.runCheck14(clientData); case FIFTEEN -> checkValidationColor = this.runCheck15(); - case SIXTEEN -> checkValidationColor = this.runCheck16(); + case SIXTEEN -> checkValidationColor = this.runCheck16(clientData); case SEVENTEEN -> checkValidationColor = this.runCheck17(groupData); case EIGHTEEN -> checkValidationColor = this.runCheck18(clientData); case NINETEEN -> checkValidationColor = this.runCheck19(clientData); @@ -571,9 +571,19 @@ private CheckValidationColor runCheck15() { /** * Payments outside the current term of the main product + * @param clientData */ - private CheckValidationColor runCheck16() { - return CheckValidationColor.RED; + private CheckValidationColor runCheck16(ClientData clientData) { + final String clientId = String.valueOf(clientData.getClientId()); + final String reportName = Policies.SIXTEEN.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 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); } /** diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_16.sql b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_16.sql new file mode 100644 index 00000000000..fdb226dc193 --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/commands/policy_run_16.sql @@ -0,0 +1,59 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +-- liquibase formatted sql +-- changeset fineract:1 +-- MySQL dump 10.13 Distrib 5.1.60, for Win32 (ia32) +-- +-- Host: localhost Database: fineract_default +-- ------------------------------------------------------ +-- Server version 5.1.60-community + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES UTF8MB4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- Payments outside the current term of the main product -- +INSERT INTO stretchy_report (report_name,report_type,report_category,report_sql,description,core_report,use_report,self_service_user_report) +VALUES ("Payments outside the current term of the main product Policy Check", "Table", "Prequalification", +"SELECT + client_details.number_of_principal_loans, + CASE + WHEN ('${loanProductId}' = 7) AND (client_details.number_of_pending_installments = 4) THEN 'GREEN' + WHEN ('${loanProductId}' = 7) AND (client_details.number_of_pending_installments > 4) THEN 'ORANGE' + WHEN ('${loanProductId}' = 3) AND (client_details.number_of_pending_installments = 4) THEN 'GREEN' + WHEN ('${loanProductId}' = 3) AND (client_details.number_of_pending_installments > 4) THEN 'ORANGE' + END AS color + FROM m_client mc + INNER JOIN ( + SELECT mc.id AS client_id, 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) AND (ml.loan_status_id = 300) AND RS.completed_derived =0 + GROUP BY mc.id + )client_details ON client_details.client_id = mc.id + WHERE mc.id = ${clientId}", "Payments outside the current term of the main product Policy Check", 0, 0, 0); diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml index 140182f9b35..34bb5399d14 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0103_FBR_372_hard_policy_check_sql_redesign.xml @@ -487,5 +487,13 @@ splitStatements="true" stripComments="true"/> + + +