adamsaghy commented on code in PR #5358:
URL: https://github.com/apache/fineract/pull/5358#discussion_r2721090292


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/data/ProgressiveLoanRescheduleRequestDataValidator.java:
##########
@@ -223,17 +222,14 @@ public void validateForRejectAction(JsonCommand 
jsonCommand, LoanRescheduleReque
         throw new UnsupportedOperationException("Nothing to override here");
     }
 
-    private void validateInterestRateChangeRescheduleFromDate(Loan loan, 
LocalDate rescheduleFromDate) {
-        boolean alreadyExistInterestRateChange = 
loanRescheduleRequestRepository.exists((root, query, criteriaBuilder) -> {
-            Predicate loanPredicate = criteriaBuilder.equal(root.get("loan"), 
loan);
-            Predicate statusPredicate = root.get("statusEnum")
-                    
.in(List.of(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(), 
LoanStatus.APPROVED.getValue()));
-            Predicate datePredicate = 
criteriaBuilder.equal(root.get("rescheduleFromDate"), rescheduleFromDate);
-            return criteriaBuilder.and(loanPredicate, statusPredicate, 
datePredicate);
-        });
-        if (alreadyExistInterestRateChange) {
-            throw new 
GeneralPlatformDomainRuleException("loan.reschedule.interest.rate.change.already.exists",
-                    "Interest rate change for the provided date is already 
exists.", rescheduleFromDate);
+    private void validateInterestRateChangeRescheduleFromDate(final Loan loan, 
final LocalDate rescheduleFromDate) {
+        Optional<LoanRescheduleRequest> optLoanRescheduleRequest = 
loanRescheduleRequestRepository.fetchByLoanAndFromDateAndStatus(loan, //
+                rescheduleFromDate, 
List.of(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(), 
LoanStatus.APPROVED.getValue()));
+
+        if (optLoanRescheduleRequest.isPresent()) {
+            LoanRescheduleRequest loanRescheduleRequest = 
optLoanRescheduleRequest.get();
+            
loanRescheduleRequest.reject(loanRescheduleRequest.getSubmittedByUser(), 
rescheduleFromDate);
+            loanRescheduleRequestRepository.save(loanRescheduleRequest);

Review Comment:
   I think we need to do the following instead:
   - We are not changing on the `LoanRescheduleRequest`. It should reflect the 
original values!
   
   If there is 2 **same** loan term variations, mark the existing one as 
`isActive=false`! Only the latter one will be active and in effect:
   
   1. Change interest rate from 2 February 2025 to 4%
   - LoanRescheduleRequest is created with PENDING status, No Loan term 
variations created yet.
   - Once its approved, loan term variation is created
   
   2. Change interest rate from 2 February 2025 to 5%
   - LoanRescheduleRequest is created with PENDING status, No **new** Loan term 
variations created yet.
   - Once its approved, we should check whether there is ACTIVE loan term 
variation with the same type and date and if so mark this as INACTIVE and 
create a new loan term variations with the new details.
    



-- 
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