budaidev commented on code in PR #6585:
URL: https://github.com/apache/fineract/pull/6585#discussion_r4323258317


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -267,59 +300,83 @@ public void validateContractTermination(final JsonCommand 
command, final Long lo
             return;
         }
 
-        Validator.validateOrThrow("loan.contract.termination", 
baseDataValidator -> {
+        Validator.validateOrThrow(rules.resource(), baseDataValidator -> {
             if (transactionDate == null) {
                 // A sent but unparseable date reads as null too, and must not 
take the business date default
                 
baseDataValidator.reset().parameter(TRANSACTION_DATE).failWithCode("invalid.date.format",
-                        "Contract termination transaction date could not be 
read as a date");
+                        rules.label() + " transaction date could not be read 
as a date");
             } else if (DateUtils.isBeforeBusinessDate(transactionDate)) {
-                
baseDataValidator.reset().parameter(TRANSACTION_DATE).value(transactionDate).failWithCode("cannot.be.before.business.date",
-                        "Contract termination transaction date cannot be 
before the business date");
+                if (rules.backdatingAllowed()) {
+                    validateBackdatedEarlyTermination(baseDataValidator, 
transactionDate,
+                            
this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true), rules);
+                } else {
+                    
baseDataValidator.reset().parameter(TRANSACTION_DATE).value(transactionDate).failWithCode(
+                            "cannot.be.before.business.date", rules.label() + 
" transaction date cannot be before the business date");
+                }
             } else if (DateUtils.isDateInTheFuture(transactionDate)) {
                 // Deliberately future dated only: terminating on the business 
date after maturity stays allowed
                 final Loan loan = 
this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId);
                 final LocalDate maturityDate = loan.getMaturityDate();
                 if (maturityDate != null && 
!transactionDate.isBefore(maturityDate)) {
                     
baseDataValidator.reset().parameter(TRANSACTION_DATE).value(transactionDate).failWithCode(
-                            "must.be.before.maturity.date", "Contract 
termination transaction date must be before the maturity date");
+                            "must.be.before.maturity.date", rules.label() + " 
transaction date must be before the maturity date");
                 }
             }
         });
     }
 
-    @Override
-    public void validateContractTerminationUndo(final JsonCommand command, 
final Long loanId) {
+    /**
+     * A backdated early termination may not move behind anything already 
recorded on the loan: its last transaction and
+     * the charges submitted on it.
+     */
+    private void validateBackdatedEarlyTermination(final DataValidatorBuilder 
baseDataValidator, final LocalDate transactionDate,
+            final Loan loan, final EarlyTerminationRules rules) {
+        if (DateUtils.isBefore(transactionDate, 
loan.getLastUserTransactionDate())) {

Review Comment:
   Fixed. The backdating check now skips capitalized income and buy-down fee 
amortization and their adjustments. I left getLastUserTransactionDate() alone 
because about 20 other flows use it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to