Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public final class GlobalConfigurationConstants {
public static final String FORCE_WITHDRAWAL_ON_SAVINGS_ACCOUNT = "allow-force-withdrawal-on-savings-account";
public static final String FORCE_WITHDRAWAL_ON_SAVINGS_ACCOUNT_LIMIT = "force-withdrawal-on-savings-account-limit";
public static final String FORCE_PASSWORD_RESET_ON_FIRST_LOGIN = "force-password-reset-on-first-login";
public static final String BLOCK_TRANSACTIONS_ON_CLOSED_OVERPAID_LOANS = "block-transactions-on-closed-overpaid-loans";

private GlobalConfigurationConstants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@ public interface ConfigurationDomainService {
boolean isMaxLoginRetriesEnabled();

Integer retrieveMaxLoginRetries();

boolean isBlockTransactionsOnClosedOverpaidLoansEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface LoanTransactionValidator {

void validateTransaction(String json);

default void validateTransaction(Loan loan, LoanTransactionType loanTransactionType, String json) {
validateTransaction(json);
validateLoanNotClosedOrOverpaidForTransactions(loan, loanTransactionType);
}

void validateChargebackTransaction(String json);

void validateNewRepaymentTransaction(String json);
Expand Down Expand Up @@ -98,4 +103,8 @@ void validateRefund(Loan loan, LoanTransactionType loanTransactionType, LocalDat
void validateManualInterestRefundTransaction(String json);

void validateClassificationCodeValue(String codeName, Long transactionClassificationId, DataValidatorBuilder baseDataValidator);

void validateLoanNotClosedOrOverpaidForTransactions(Loan loan);

void validateLoanNotClosedOrOverpaidForTransactions(Loan loan, LoanTransactionType loanTransactionType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ public void validateLoanGroupIsActive(Loan loan) {
loanTransactionValidator.validateLoanGroupIsActive(loan);
}

@Override
public void validateLoanNotClosedOrOverpaidForTransactions(Loan loan) {
loanTransactionValidator.validateLoanNotClosedOrOverpaidForTransactions(loan);
}

@Override
public void validateLoanNotClosedOrOverpaidForTransactions(Loan loan, LoanTransactionType loanTransactionType) {
loanTransactionValidator.validateLoanNotClosedOrOverpaidForTransactions(loan, loanTransactionType);
}

@Override
public void validateActivityNotBeforeLastTransactionDate(Loan loan, LocalDate activityDate, LoanEvent event) {
loanTransactionValidator.validateActivityNotBeforeLastTransactionDate(loan, activityDate, event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,9 @@ public Integer retrieveMaxLoginRetries() {
GlobalConfigurationConstants.MAX_LOGIN_RETRY_ATTEMPTS);
return property.getValue() == null ? null : property.getValue().intValue();
}

@Override
public boolean isBlockTransactionsOnClosedOverpaidLoansEnabled() {
return getGlobalConfigurationPropertyData(GlobalConfigurationConstants.BLOCK_TRANSACTIONS_ON_CLOSED_OVERPAID_LOANS).isEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public LoanTransaction makeRepayment(final LoanTransactionType repaymentTransact
final boolean isRecoveryRepayment, final String chargeRefundChargeType, boolean isAccountTransfer,
HolidayDetailDTO holidayDetailDto, Boolean isHolidayValidationDone, final boolean isLoanToLoanTransfer) {
checkClientOrGroupActive(loan);
loanTransactionValidator.validateLoanNotClosedOrOverpaidForTransactions(loan, repaymentTransactionType);

LoanBusinessEvent repaymentEvent = getLoanRepaymentTypeBusinessEvent(repaymentTransactionType, isRecoveryRepayment, loan);
businessEventNotifierService.notifyPreBusinessEvent(repaymentEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
Expand Down Expand Up @@ -111,6 +112,7 @@ public class LoanTransactionValidatorImpl implements LoanTransactionValidator {
private final LoanDownPaymentTransactionValidator loanDownPaymentTransactionValidator;
private final LoanDisbursementValidator loanDisbursementValidator;
private final CodeValueRepository codeValueRepository;
private final ConfigurationDomainService configurationDomainService;

private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) {
Expand Down Expand Up @@ -667,6 +669,23 @@ public void validateLoanGroupIsActive(final Loan loan) {
}
}

@Override
public void validateLoanNotClosedOrOverpaidForTransactions(Loan loan) {
validateLoanNotClosedOrOverpaidForTransactions(loan, null);
}

@Override
public void validateLoanNotClosedOrOverpaidForTransactions(Loan loan, LoanTransactionType loanTransactionType) {
boolean blockTransactions = configurationDomainService.isBlockTransactionsOnClosedOverpaidLoansEnabled();
if (LoanTransactionType.CREDIT_BALANCE_REFUND.equals(loanTransactionType)) {
return;
}
if (blockTransactions && (loan.isClosed() || loan.getStatus().isOverpaid())) {
throw new GeneralPlatformDomainRuleException("error.msg.loan.transaction.not.allowed.on.closed.or.overpaid",
"Monetary transactions are not allowed on closed or overpaid loan accounts", loan.getId());
}
}

protected void validateLoanHasNoLaterChargeRefundTransactionToReverseOrCreateATransaction(Loan loan, LocalDate transactionDate,
String reversedOrCreated) {
for (LoanTransaction txn : loan.getLoanTransactions()) {
Expand Down Expand Up @@ -789,6 +808,7 @@ public void validateLoanTransactionInterestPaymentWaiver(JsonCommand command) {
validateLoanClientIsActive(loan);
validateLoanHasCurrency(loan);
validateLoanGroupIsActive(loan);
validateLoanNotClosedOrOverpaidForTransactions(loan, LoanTransactionType.INTEREST_PAYMENT_WAIVER);
loanDownPaymentTransactionValidator.validateLoanStatusIsActiveOrFullyPaidOrOverpaid(loan);
validateLoanDisbursementIsBeforeTransactionDate(loan, transactionDate);
validateLoanHasNoLaterChargeRefundTransactionToReverseOrCreateATransaction(loan, transactionDate, "created");
Expand Down Expand Up @@ -826,6 +846,7 @@ public void validateRefund(String json) {
public void validateRefund(final Loan loan, LoanTransactionType loanTransactionType, final LocalDate transactionDate,
ScheduleGeneratorDTO scheduleGeneratorDTO) {
checkClientOrGroupActive(loan);
validateLoanNotClosedOrOverpaidForTransactions(loan, loanTransactionType);
loanDownPaymentTransactionValidator.validateLoanStatusIsActiveOrFullyPaidOrOverpaid(loan);
validateActivityNotBeforeClientOrGroupTransferDate(loan, transactionDate);
validateRepaymentTypeTransactionNotBeforeAChargeRefund(loan, loanTransactionType, transactionDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ private Loan saveAndFlushLoanWithDataIntegrityViolationChecks(final Loan loan) {
final Throwable realCause = e.getCause();
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
if (realCause.getMessage().toLowerCase(java.util.Locale.ROOT).contains("external_id_unique")) {
if (realCause.getMessage().toLowerCase(Locale.ROOT).contains("external_id_unique")) {
baseDataValidator.reset().parameter(LoanApiConstants.externalIdParameterName).failWithCode("value.must.be.unique");
}
if (!dataValidationErrors.isEmpty()) {
Expand All @@ -705,7 +705,7 @@ private void saveLoanWithDataIntegrityViolationChecks(final Loan loan) {
final Throwable realCause = e.getCause();
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
if (realCause.getMessage().toLowerCase(java.util.Locale.ROOT).contains("external_id_unique")) {
if (realCause.getMessage().toLowerCase(Locale.ROOT).contains("external_id_unique")) {
baseDataValidator.reset().parameter(LoanApiConstants.externalIdParameterName).failWithCode("value.must.be.unique");
}
if (!dataValidationErrors.isEmpty()) {
Expand Down Expand Up @@ -1377,9 +1377,6 @@ private void validateLoanTransactionAmountChargeBack(LoanTransaction loanTransac
@Transactional
@Override
public CommandProcessingResult waiveInterestOnLoan(final Long loanId, final JsonCommand command) {

this.loanTransactionValidator.validateTransaction(command.json());

final Map<String, Object> changes = new LinkedHashMap<>();
changes.put("transactionDate", command.stringValueOfParameterNamed("transactionDate"));
changes.put("transactionAmount", command.stringValueOfParameterNamed("transactionAmount"));
Expand All @@ -1390,6 +1387,7 @@ public CommandProcessingResult waiveInterestOnLoan(final Long loanId, final Json
final ExternalId externalId = externalIdFactory.createFromCommand(command, LoanApiConstants.externalIdParameterName);

Loan loan = this.loanAssembler.assembleFrom(loanId);
loanTransactionValidator.validateTransaction(loan, LoanTransactionType.WAIVE_INTEREST, command.json());
checkClientOrGroupActive(loan);

final Money transactionAmountAsMoney = Money.of(loan.getCurrency(), transactionAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,5 @@
<include file="parts/0219_remove_self_service_feature.xml" relativeToChangelogFile="true"/>
<include file="parts/0220_add_login_retry_configuration.xml" relativeToChangelogFile="true" />
<include file="parts/0221_transaction_summary_reports_fix_after_originator_details.xml" relativeToChangelogFile="true" />
<include file="parts/0222_add_configuration_block_transactions_on_closed_overpaid_loans.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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.

-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">

<changeSet author="fineract" id="2">
<insert tableName="c_configuration">
<column name="name" value="block-transactions-on-closed-overpaid-loans"/>
<column name="value"/>
<column name="date_value"/>
<column name="string_value"/>
<column name="enabled" valueBoolean="false"/>
<column name="is_trap_door" valueBoolean="false"/>
<column name="description" value="If enabled: monetary transactions are blocked on closed and overpaid loan accounts"/>
</insert>
</changeSet>
</databaseChangeLog>
Loading
Loading