@@ -101,9 +101,11 @@ public class LoanReAgingService {
101101 public CommandProcessingResult reAge (final Long loanId , final JsonCommand command ) {
102102 final Loan loan = loanAssembler .assembleFrom (loanId );
103103 reAgingValidator .validateReAge (loan , command );
104+ BigDecimal userProvidedTxnAmount = command .bigDecimalValueOfParameterNamed (LoanReAgingApiConstants .transactionAmountParamName );
104105
105106 final LoanTransaction reAgeTransaction = createReAgeTransaction (loan , command );
106107 processReAgeTransaction (loan , reAgeTransaction , true );
108+ validateUserProvidedTransactionAmount (userProvidedTxnAmount , reAgeTransaction );
107109 loanTransactionRepository .saveAndFlush (reAgeTransaction );
108110 loan .updateLoanScheduleDependentDerivedFields ();
109111
@@ -236,15 +238,7 @@ private LoanTransaction createReAgeTransaction(Loan loan, JsonCommand command) {
236238 }
237239 // in case of a reaging transaction, only the outstanding principal amount until the business date is considered
238240 Money txPrincipal = loan .getTotalPrincipalOutstandingUntil (transactionDate );
239- final BigDecimal txPrincipalAmount = txPrincipal .getAmount ();
240- if (command .hasParameter (LoanReAgingApiConstants .transactionAmountParamName )) {
241- final BigDecimal transactionAmount = command
242- .bigDecimalValueOfParameterNamed (LoanReAgingApiConstants .transactionAmountParamName );
243- if (!MathUtil .isEqualTo (txPrincipalAmount , transactionAmount )) {
244- throw new GeneralPlatformDomainRuleException ("error.msg.loan.reage.amount.not.match.with.calculated.reage.amount" ,
245- "re-age amount is not matching with the calculated re-age amount" , txPrincipalAmount );
246- }
247- }
241+ BigDecimal txPrincipalAmount = txPrincipal .getAmount ();
248242
249243 final LoanTransaction reAgeTransaction = new LoanTransaction (loan , loan .getOffice (), LoanTransactionType .REAGE , transactionDate ,
250244 txPrincipalAmount , txPrincipalAmount , ZERO , ZERO , ZERO , null , false , null , txExternalId );
@@ -326,4 +320,16 @@ private LoanReAgeParameter createReAgeParameterFromPreviewRequest(final LoanTran
326320 reAgeInterestHandlingType , null );
327321 }
328322
323+ private void validateUserProvidedTransactionAmount (BigDecimal userProvidedTxnAmount , LoanTransaction reAgeTransaction ) {
324+ if (userProvidedTxnAmount != null ) {
325+ final BigDecimal calculatedReageTxnAmount = reAgeTransaction .getAmount ();
326+ if (!MathUtil .isEqualTo (calculatedReageTxnAmount , userProvidedTxnAmount )) {
327+ String errorMessage = String .format (
328+ "User provided re-age amount (%s) is not matching with the calculated re-age amount (%s)" , userProvidedTxnAmount ,
329+ calculatedReageTxnAmount );
330+ throw new GeneralPlatformDomainRuleException ("error.msg.loan.reage.amount.not.match.with.calculated.reage.amount" ,
331+ errorMessage , userProvidedTxnAmount , calculatedReageTxnAmount );
332+ }
333+ }
334+ }
329335}
0 commit comments