Skip to content

Commit b28f4e5

Browse files
committed
FINERACT-2399: Add global config to block transactions on closed/overpaid loans
1 parent 3a6f805 commit b28f4e5

File tree

8 files changed

+67
-0
lines changed

8 files changed

+67
-0
lines changed

fineract-core/src/main/java/org/apache/fineract/infrastructure/configuration/api/GlobalConfigurationConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public final class GlobalConfigurationConstants {
7979
public static final String ASSET_OWNER_TRANSFER_OUTSTANDING_INTEREST_CALCULATION_STRATEGY = "outstanding-interest-calculation-strategy-for-external-asset-transfer";
8080
public static final String ALLOWED_LOAN_STATUSES_FOR_EXTERNAL_ASSET_TRANSFER = "allowed-loan-statuses-for-external-asset-transfer";
8181
public static final String ALLOWED_LOAN_STATUSES_OF_DELAYED_SETTLEMENT_FOR_EXTERNAL_ASSET_TRANSFER = "allowed-loan-statuses-of-delayed-settlement-for-external-asset-transfer";
82+
public static final String BLOCK_TRANSACTIONS_ON_CLOSED_OVERPAID_LOANS = "block-transactions-on-closed-overpaid-loans";
8283

8384
private GlobalConfigurationConstants() {}
8485
}

fineract-core/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ConfigurationDomainService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,6 @@ public interface ConfigurationDomainService {
151151
boolean isImmediateChargeAccrualPostMaturityEnabled();
152152

153153
String getAssetOwnerTransferOustandingInterestStrategy();
154+
155+
boolean isBlockTransactionsOnClosedOverpaidLoansEnabled();
154156
}

fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ void validateRefund(Loan loan, LoanTransactionType loanTransactionType, LocalDat
9898
void validateManualInterestRefundTransaction(String json);
9999

100100
void validateClassificationCodeValue(String codeName, Long transactionClassificationId, DataValidatorBuilder baseDataValidator);
101+
102+
void validateLoanNotClosedOrOverpaidForTransactions(Loan loan);
101103
}

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ public void validateLoanGroupIsActive(Loan loan) {
506506
loanTransactionValidator.validateLoanGroupIsActive(loan);
507507
}
508508

509+
@Override
510+
public void validateLoanNotClosedOrOverpaidForTransactions(Loan loan) {
511+
loanTransactionValidator.validateLoanNotClosedOrOverpaidForTransactions(loan);
512+
}
513+
509514
@Override
510515
public void validateActivityNotBeforeLastTransactionDate(Loan loan, LocalDate activityDate, LoanEvent event) {
511516
loanTransactionValidator.validateActivityNotBeforeLastTransactionDate(loan, activityDate, event);

fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ConfigurationDomainServiceJpa.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,9 @@ public String getAssetOwnerTransferOustandingInterestStrategy() {
548548
return getGlobalConfigurationPropertyData(
549549
GlobalConfigurationConstants.ASSET_OWNER_TRANSFER_OUTSTANDING_INTEREST_CALCULATION_STRATEGY).getStringValue();
550550
}
551+
552+
@Override
553+
public boolean isBlockTransactionsOnClosedOverpaidLoansEnabled() {
554+
return getGlobalConfigurationPropertyData(GlobalConfigurationConstants.BLOCK_TRANSACTIONS_ON_CLOSED_OVERPAID_LOANS).isEnabled();
555+
}
551556
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidatorImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.lang3.StringUtils;
3838
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
3939
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
40+
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
4041
import org.apache.fineract.infrastructure.core.api.JsonCommand;
4142
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
4243
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
@@ -111,6 +112,7 @@ public class LoanTransactionValidatorImpl implements LoanTransactionValidator {
111112
private final LoanDownPaymentTransactionValidator loanDownPaymentTransactionValidator;
112113
private final LoanDisbursementValidator loanDisbursementValidator;
113114
private final CodeValueRepository codeValueRepository;
115+
private final ConfigurationDomainService configurationDomainService;
114116

115117
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
116118
if (!dataValidationErrors.isEmpty()) {
@@ -666,6 +668,14 @@ public void validateLoanGroupIsActive(final Loan loan) {
666668
}
667669
}
668670

671+
public void validateLoanNotClosedOrOverpaidForTransactions(Loan loan) {
672+
boolean blockTransactions = configurationDomainService.isBlockTransactionsOnClosedOverpaidLoansEnabled();
673+
if (blockTransactions && (loan.isClosed() || loan.getStatus().isOverpaid())) {
674+
throw new GeneralPlatformDomainRuleException("error.msg.loan.transaction.not.allowed.on.closed.or.overpaid",
675+
"Monetary transactions are not allowed on closed or overpaid loan accounts", loan.getId());
676+
}
677+
}
678+
669679
protected void validateLoanHasNoLaterChargeRefundTransactionToReverseOrCreateATransaction(Loan loan, LocalDate transactionDate,
670680
String reversedOrCreated) {
671681
for (LoanTransaction txn : loan.getLoanTransactions()) {

fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,5 @@
226226
<include file="parts/0205_add_read_familymembers_permission.xml" relativeToChangelogFile="true" />
227227
<include file="parts/0206_transaction_summary_with_asset_owner_classification_name_bug_fix.xml" relativeToChangelogFile="true" />
228228
<include file="parts/0207_add_allow_full_term_for_tranche.xml" relativeToChangelogFile="true" />
229+
<include file="parts/0208_add_configuration_block_transactions_on_closed_overpaid_loans.xml" relativeToChangelogFile="true" />
229230
</databaseChangeLog>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
25+
<changeSet author="fineract" id="1" context="postgresql">
26+
<sql>
27+
SELECT SETVAL('c_configuration_id_seq', COALESCE(MAX(id), 0)+1, false ) FROM c_configuration;
28+
</sql>
29+
</changeSet>
30+
<changeSet author="fineract" id="2">
31+
<insert tableName="c_configuration">
32+
<column name="name" value="block-transactions-on-closed-overpaid-loans"/>
33+
<column name="value"/>
34+
<column name="date_value"/>
35+
<column name="string_value"/>
36+
<column name="enabled" valueBoolean="false"/>
37+
<column name="is_trap_door" valueBoolean="false"/>
38+
<column name="description" value="If enabled: monetary transactions are blocked on closed and overpaid loan accounts"/>
39+
</insert>
40+
</changeSet>
41+
</databaseChangeLog>

0 commit comments

Comments
 (0)