Skip to content

Commit

Permalink
Merge pull request #266 from fiterlatam/fix/FBR-404
Browse files Browse the repository at this point in the history
Policy Checks Implementations
  • Loading branch information
BrianMuhimbura authored Nov 13, 2023
2 parents fce0865 + 95fe0f0 commit cde5a7d
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ 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);
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);
Expand Down Expand Up @@ -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.getProductId());
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${prequalificationId}", prequalificationId);
reportParams.put("${loanProductId}", productId);
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams,
false);
return extractColorFromResultset(result);
}

/**
Expand Down Expand Up @@ -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<String, String> 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);
}

/**
Expand All @@ -551,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<String, String> reportParams = new HashMap<>();
reportParams.put("${clientId}", clientId);
reportParams.put("${loanProductId}", productId);
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = ${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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,29 @@
stripComments="true"/>
</changeSet>

<changeSet author="fineract" id="36">
<sqlFile
encoding="utf8"
path="db/changelog/tenant/commands/policy_run_10.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>
<changeSet author="fineract" id="37">
<sqlFile
encoding="utf8"
path="db/changelog/tenant/commands/policy_run_14.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>
<changeSet author="fineract" id="38">
<sqlFile
encoding="utf8"
path="db/changelog/tenant/commands/policy_run_16.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>

</databaseChangeLog>

0 comments on commit cde5a7d

Please sign in to comment.