Skip to content

Commit

Permalink
FBR-370: Implement hard policy check (#265)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius Peter Oketayot <[email protected]>
  • Loading branch information
fiter-julius-oketayot and Julius Peter Oketayot authored Nov 10, 2023
1 parent d9e220b commit fce0865
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ private CheckValidationColor validateGenericPolicy(final Policies policy, final
case NINE -> checkValidationColor = this.runCheck9();
case TEN -> checkValidationColor = this.runCheck10();
case ELEVEN -> checkValidationColor = this.runCheck11(groupData);
case TWELVE -> checkValidationColor = this.runCheck12();
case THIRTEEN -> checkValidationColor = this.runCheck13();
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();
Expand All @@ -243,7 +243,7 @@ private CheckValidationColor validateGenericPolicy(final Policies policy, final
case TWENTY_THREE -> checkValidationColor = this.runCheck23(clientData);
case TWENTY_FOUR -> checkValidationColor = this.runCheck24(clientData);
case TWENTY_FIVE -> checkValidationColor = this.runCheck25(clientData);
case TWENTY_SIX -> checkValidationColor = this.runCheck26();
case TWENTY_SIX -> checkValidationColor = this.runCheck26(clientData);
case TWENTY_SEVEN -> checkValidationColor = this.runCheck27(groupData);
case TWENTY_EIGHT -> checkValidationColor = this.runCheck28(groupData);
case TWENTY_NINE -> checkValidationColor = this.runCheck29();
Expand Down Expand Up @@ -501,15 +501,38 @@ private CheckValidationColor runCheck11(final GroupData groupData) {
/**
* General condition
*/
private CheckValidationColor runCheck12() {
return CheckValidationColor.RED;
private CheckValidationColor runCheck12(final ClientData clientData) {
final String clientId = String.valueOf(clientData.getClientId());
final String reportName = Policies.TWELVE.getName() + " Policy Check";
final String productId = Long.toString(clientData.getProductId());
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("${clientCategorization}", params.getClientCategorization());
reportParams.put("${recreditCategorization}", params.getRecreditCategorization());
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}

/**
* Categories of clients to accept
*/
private CheckValidationColor runCheck13() {
return CheckValidationColor.RED;
private CheckValidationColor runCheck13(final ClientData clientData) {
final String clientId = String.valueOf(clientData.getClientId());
final String reportName = Policies.THIRTEEN.getName() + " Policy Check";
final String productId = Long.toString(clientData.getProductId());
final ClientData params = retrieveClientParams(clientData.getClientId(), clientData.getProductId());
final Integer bureauStatus = clientData.getBuroCheckStatus();
final BuroCheckClassification buroCheckClassification = BuroCheckClassification.fromInt(bureauStatus);
final Map<String, String> reportParams = new HashMap<>();
reportParams.put("${clientId}", clientId);
reportParams.put("${loanProductId}", productId);
reportParams.put("${clientCategorization}", params.getClientCategorization());
reportParams.put("${recreditCategorization}", params.getRecreditCategorization());
reportParams.put("${buroCheckClassification}", buroCheckClassification.getLetter());
final GenericResultsetData result = this.readReportingService.retrieveGenericResultset(reportName, "report", reportParams, false);
return extractColorFromResultset(result);
}

/**
Expand Down Expand Up @@ -686,8 +709,18 @@ private CheckValidationColor runCheck25(final ClientData clientData) {
/**
* Credits
*/
private CheckValidationColor runCheck26() {
return CheckValidationColor.RED;
private CheckValidationColor runCheck26(final ClientData clientData) {
final String clientId = String.valueOf(clientData.getClientId());
final String reportName = Policies.TWENTY_SIX.getName() + " Policy Check";
final String productId = Long.toString(clientData.getProductId());
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("${clientCategorization}", params.getClientCategorization());
reportParams.put("${recreditCategorization}", params.getRecreditCategorization());
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
Expand Up @@ -335,8 +335,9 @@ private String buildSqlStringFromBlacklistCriteria(final SearchParameters search
} else if (type.equals("agency")) {
extraCriteria += " and g.status IN( " + PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL.getValue().toString() + ", "
+ PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS.getValue().toString() + ") ";
}else if (type.equals("exceptionsqueue")) {
extraCriteria += " and g.status IN( " + PrequalificationStatus.ANALYSIS_UNIT_PENDING_APPROVAL_WITH_EXCEPTIONS.getValue().toString() + ", "
} else if (type.equals("exceptionsqueue")) {
extraCriteria += " and g.status IN( "
+ PrequalificationStatus.ANALYSIS_UNIT_PENDING_APPROVAL_WITH_EXCEPTIONS.getValue().toString() + ", "
+ PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS.getValue().toString() + ") ";
} else if (type.equals("committeeapprovals")) {

Expand Down
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 */;

-- General condition Policy Check --
INSERT INTO stretchy_report (report_name,report_type,report_category,report_sql,description,core_report,use_report,self_service_user_report)
VALUES ("General condition Policy Check", "Table", "Prequalification",
"SELECT
client_details.number_of_principal_loans,
CASE
WHEN ('${loanProductId}' = 7) AND (client_details.number_of_principal_loans >= 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) AND (ml.loan_status_id = 300)
GROUP BY mc.id
)client_details ON client_details.client_id = mc.id
WHERE mc.id = ${clientId}", "General condition 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 */;

-- Categories of clients to accept Policy Check --
INSERT INTO stretchy_report (report_name,report_type,report_category,report_sql,description,core_report,use_report,self_service_user_report)
VALUES ("Categories of clients to accept Policy Check", "Table", "Prequalification",
"SELECT
CASE
WHEN (${loanProductId} = 7) AND ('${buroCheckClassification}' = 'A') THEN 'GREEN'
WHEN (${loanProductId} = 7) AND ('${buroCheckClassification}' = 'B') THEN 'GREEN'
WHEN (${loanProductId} = 7) AND ('${buroCheckClassification}' = 'C') THEN 'ORANGE'
WHEN (${loanProductId} = 7) AND ('${buroCheckClassification}' = 'D') THEN 'ORANGE'
WHEN (${loanProductId} = 3) AND ('${buroCheckClassification}' = 'A') THEN 'GREEN'
WHEN (${loanProductId} = 3) AND ('${buroCheckClassification}' = 'B') THEN 'GREEN'
WHEN (${loanProductId} = 3) AND ('${buroCheckClassification}' = 'C') THEN 'ORANGE'
WHEN (${loanProductId} = 3) AND ('${buroCheckClassification}' = 'D') THEN 'ORANGE'
END AS color
FROM m_client mc
WHERE mc.id = ${clientId}
", "Categories of clients to accept 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 */;

-- Credits Policy Check --
INSERT INTO stretchy_report (report_name,report_type,report_category,report_sql,description,core_report,use_report,self_service_user_report)
VALUES ("Credits Policy Check", "Table", "Prequalification",
"SELECT
COALESCE(client_details.principal_paid_percentage, 0) AS principal_paid_percentage,
CASE
WHEN ('${loanProductId}' = 7) AND ( COALESCE(client_details.principal_paid_percentage, 0) >= 50) THEN 'GREEN'
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 = 300 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}", "Credits Policy Check", 0, 0, 0);
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,29 @@
splitStatements="true"
stripComments="true"/>
</changeSet>
<changeSet author="fineract" id="33">
<sqlFile
encoding="utf8"
path="db/changelog/tenant/commands/policy_run_12.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>
<changeSet author="fineract" id="34">
<sqlFile
encoding="utf8"
path="db/changelog/tenant/commands/policy_run_26.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>
<changeSet author="fineract" id="35">
<sqlFile
encoding="utf8"
path="db/changelog/tenant/commands/policy_run_13.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>

</databaseChangeLog>

0 comments on commit fce0865

Please sign in to comment.