FINERACT-2354: Validation of Re-age amount during submission
This commit is contained in:
+15
-9
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user