FINERACT-2354: Validation of Re-age amount during submission

This commit is contained in:
Adam Saghy
2025-12-10 13:09:16 +01:00
parent 8644d66fc0
commit 1ad45759fd
@@ -101,9 +101,11 @@ public class LoanReAgingService {
public CommandProcessingResult reAge(final Long loanId, final JsonCommand command) {
final Loan loan = loanAssembler.assembleFrom(loanId);
reAgingValidator.validateReAge(loan, command);
BigDecimal userProvidedTxnAmount = command.bigDecimalValueOfParameterNamed(LoanReAgingApiConstants.transactionAmountParamName);
final LoanTransaction reAgeTransaction = createReAgeTransaction(loan, command);
processReAgeTransaction(loan, reAgeTransaction, true);
validateUserProvidedTransactionAmount(userProvidedTxnAmount, reAgeTransaction);
loanTransactionRepository.saveAndFlush(reAgeTransaction);
loan.updateLoanScheduleDependentDerivedFields();
@@ -236,15 +238,7 @@ public class LoanReAgingService {
}
// in case of a reaging transaction, only the outstanding principal amount until the business date is considered
Money txPrincipal = loan.getTotalPrincipalOutstandingUntil(transactionDate);
final BigDecimal txPrincipalAmount = txPrincipal.getAmount();
if (command.hasParameter(LoanReAgingApiConstants.transactionAmountParamName)) {
final BigDecimal transactionAmount = command
.bigDecimalValueOfParameterNamed(LoanReAgingApiConstants.transactionAmountParamName);
if (!MathUtil.isEqualTo(txPrincipalAmount, transactionAmount)) {
throw new GeneralPlatformDomainRuleException("error.msg.loan.reage.amount.not.match.with.calculated.reage.amount",
"re-age amount is not matching with the calculated re-age amount", txPrincipalAmount);
}
}
BigDecimal txPrincipalAmount = txPrincipal.getAmount();
final LoanTransaction reAgeTransaction = new LoanTransaction(loan, loan.getOffice(), LoanTransactionType.REAGE, transactionDate,
txPrincipalAmount, txPrincipalAmount, ZERO, ZERO, ZERO, null, false, null, txExternalId);
@@ -326,4 +320,16 @@ public class LoanReAgingService {
reAgeInterestHandlingType, null);
}
private void validateUserProvidedTransactionAmount(BigDecimal userProvidedTxnAmount, LoanTransaction reAgeTransaction) {
if (userProvidedTxnAmount != null) {
final BigDecimal calculatedReageTxnAmount = reAgeTransaction.getAmount();
if (!MathUtil.isEqualTo(calculatedReageTxnAmount, userProvidedTxnAmount)) {
String errorMessage = String.format(
"User provided re-age amount (%s) is not matching with the calculated re-age amount (%s)", userProvidedTxnAmount,
calculatedReageTxnAmount);
throw new GeneralPlatformDomainRuleException("error.msg.loan.reage.amount.not.match.with.calculated.reage.amount",
errorMessage, userProvidedTxnAmount, calculatedReageTxnAmount);
}
}
}
}