You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "marta-jankovics (via GitHub)" <gi...@apache.org> on 2024/12/12 22:04:01 UTC

[PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

marta-jankovics opened a new pull request, #4220:
URL: https://github.com/apache/fineract/pull/4220

   … loan
   
   ## Description
   
   Describe the changes made and why they were made.
   
   Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
   
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "galovics (via GitHub)" <gi...@apache.org>.
galovics commented on code in PR #4220:
URL: https://github.com/apache/fineract/pull/4220#discussion_r1883592418


##########
fineract-e2e-tests-core/src/test/resources/fineract-test-application.properties:
##########
@@ -23,7 +23,7 @@ fineract-test.api.password=${TEST_PASSWORD:password}
 fineract-test.api.strong-password=${TEST_STRONG_PASSWORD:A1b2c3d4e5f$}
 fineract-test.api.tenant-id=${TEST_TENANT_ID:default}
 
-fineract-test.initialization.enabled=${INITIALIZATION_ENABLED:false}
+fineract-test.initialization.enabled=${INITIALIZATION_ENABLED:true}

Review Comment:
   Can you pls explain the purpose of this change?



##########
fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/ErrorMessageHelper.java:
##########
@@ -348,9 +348,18 @@ public static String wrongDataInDelinquentLastRepaymentDate(String actual, Strin
     }
 
     public static String wrongLoanStatus(Integer actual, Integer expected) {
+        return wrongLoanStatus(null, actual, expected);
+    }
+
+    public static String wrongLoanStatus(String resourceId, Integer actual, Integer expected) {
         String actualToStr = actual.toString();
         String expectedToStr = expected.toString();
-        return String.format("Wrong Loan status ID. Actual ID is: %s - But expected ID is: %s", actualToStr, expectedToStr);
+        String prefx = "Wrong Loan status ID";
+        String postfx = ". Actual ID is: %s - But expected ID is: %s";
+        if (resourceId != null) {
+            return String.format(prefx + " of resource %s" + postfx, resourceId, actualToStr, expectedToStr);
+        }
+        return String.format(prefx + postfx, actualToStr, expectedToStr);

Review Comment:
   I'm not a big fan of this string joining. Why didn't we just have the 2 messages inline?



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualActivityProcessingServiceImpl.java:
##########
@@ -46,58 +51,93 @@
 public class LoanAccrualActivityProcessingServiceImpl implements LoanAccrualActivityProcessingService {
 
     private final LoanRepositoryWrapper loanRepositoryWrapper;
-    private final LoanWritePlatformService loanWritePlatformService;
     private final ExternalIdFactory externalIdFactory;
     private final BusinessEventNotifierService businessEventNotifierService;
-    private final LoanChargeValidator loanChargeValidator;
+    private final LoanTransactionAssembler loanTransactionAssembler;
+    private final LoanAccountDomainService loanAccountDomainService;
 
     @Override
     @Transactional(propagation = Propagation.REQUIRES_NEW)
-    public void makeAccrualActivityTransaction(Long loanId, final LocalDate currentDate) {
+    public void makeAccrualActivityTransaction(@NotNull Long loanId, @NotNull LocalDate currentDate) {
         Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
         makeAccrualActivityTransaction(loan, currentDate);
     }
 
     @Override
-    public Loan makeAccrualActivityTransaction(Loan loan, final LocalDate currentDate) {
-        if (loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
-            // check if loan has installment due on business day
-            Optional<LoanRepaymentScheduleInstallment> first = loan.getRepaymentScheduleInstallments().stream()
-                    .filter(loanRepaymentScheduleInstallment -> loanRepaymentScheduleInstallment.getDueDate().isEqual(currentDate))
-                    .findFirst();
-            if (first.isPresent()) {
-                final LoanRepaymentScheduleInstallment installment = first.get();
-                // check if there is no not-replayed-accrual-activity related to business date
-                List<LoanTransaction> loanTransactions = loan.getLoanTransactions(loanTransaction -> loanTransaction.isNotReversed()
-                        && loanTransaction.isAccrualActivity() && loanTransaction.getTransactionDate().isEqual(currentDate));
-                if (loanTransactions.isEmpty()) {
-                    loan = loanWritePlatformService.makeAccrualActivityTransaction(loan, installment, currentDate);
-                }
+    public void makeAccrualActivityTransaction(@NotNull Loan loan, @NotNull LocalDate currentDate) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
+        // check if loan has installment in the past or due on current date
+        List<LoanRepaymentScheduleInstallment> installments = loan
+                .getRepaymentScheduleInstallments(i -> !i.isDownPayment() && !DateUtils.isBefore(currentDate, i.getDueDate()));
+        for (LoanRepaymentScheduleInstallment installment : installments) {
+            LocalDate dueDate = installment.getDueDate();
+            // check if there is any not-replayed-accrual-activity related to business date
+            ArrayList<LoanTransaction> existingActivities = new ArrayList<>(
+                    loan.getLoanTransactions(t -> t.isNotReversed() && t.isAccrualActivity() && t.getTransactionDate().isEqual(dueDate)));
+            if (existingActivities.isEmpty()) {
+                makeAccrualActivityTransaction(loan, installment, dueDate);
+            } else {
+                LoanTransaction existingActivity = existingActivities.get(0);
+                reverseReplayAccrualActivityTransaction(loan, existingActivity, installment, dueDate);
+                existingActivities.remove(existingActivity);
+                existingActivities.forEach(this::reverseAccrualActivityTransaction);
             }
         }
-        return loan;
     }
 
     @Override
     @Transactional
-    public void processAccrualActivityForLoanClosure(Loan loan) {
+    public void processAccrualActivityForLoanClosure(@NotNull Loan loan) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
         LocalDate date = loan.isOverPaid() ? loan.getOverpaidOnDate() : loan.getClosedOnDate();
         List<LoanTransaction> accrualActivityTransaction = loan.getLoanTransactions().stream().filter(LoanTransaction::isNotReversed)
                 .filter(LoanTransaction::isAccrualActivity).filter(loanTransaction -> loanTransaction.getDateOf().isAfter(date)).toList();
         if (!accrualActivityTransaction.isEmpty()) {
             accrualActivityTransaction.forEach(this::reverseAccrualActivityTransaction);
         }
         LoanTransaction loanTransaction = assembleClosingAccrualActivityTransaction(loan, date);
-        if (loanTransaction.getAmount().compareTo(BigDecimal.ZERO) != 0) {
-            loanWritePlatformService.makeAccrualActivityTransaction(loan, loanTransaction);
+        if (loanTransaction != null) {
+            makeAccrualActivityTransaction(loan, loanTransaction);
         }
     }
 
-    private void reverseAccrualActivityTransaction(LoanTransaction loanTransaction) {
-        loanChargeValidator.validateRepaymentTypeTransactionNotBeforeAChargeRefund(loanTransaction.getLoan(), loanTransaction, "reversed");
-        loanTransaction.reverse();
-        LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(loanTransaction);
-        businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
+    @Override
+    @Transactional
+    public void processAccrualActivityForLoanReopen(@NotNull Loan loan) {

Review Comment:
   As far as I can tell this method existed before but now it's impossible to verify what was changed here exactly. Can you please revert the method reordering (same thing for others if it happened)?
   
   if reordering makes sense, feel free to open a separate PR just for that.



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "marta-jankovics (via GitHub)" <gi...@apache.org>.
marta-jankovics commented on code in PR #4220:
URL: https://github.com/apache/fineract/pull/4220#discussion_r1883720961


##########
fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/ErrorMessageHelper.java:
##########
@@ -348,9 +348,18 @@ public static String wrongDataInDelinquentLastRepaymentDate(String actual, Strin
     }
 
     public static String wrongLoanStatus(Integer actual, Integer expected) {
+        return wrongLoanStatus(null, actual, expected);
+    }
+
+    public static String wrongLoanStatus(String resourceId, Integer actual, Integer expected) {
         String actualToStr = actual.toString();
         String expectedToStr = expected.toString();
-        return String.format("Wrong Loan status ID. Actual ID is: %s - But expected ID is: %s", actualToStr, expectedToStr);
+        String prefx = "Wrong Loan status ID";
+        String postfx = ". Actual ID is: %s - But expected ID is: %s";
+        if (resourceId != null) {
+            return String.format(prefx + " of resource %s" + postfx, resourceId, actualToStr, expectedToStr);
+        }
+        return String.format(prefx + postfx, actualToStr, expectedToStr);

Review Comment:
   Agree, me neither.



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "galovics (via GitHub)" <gi...@apache.org>.
galovics merged PR #4220:
URL: https://github.com/apache/fineract/pull/4220


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "marta-jankovics (via GitHub)" <gi...@apache.org>.
marta-jankovics commented on code in PR #4220:
URL: https://github.com/apache/fineract/pull/4220#discussion_r1883805984


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualActivityProcessingServiceImpl.java:
##########
@@ -46,58 +51,93 @@
 public class LoanAccrualActivityProcessingServiceImpl implements LoanAccrualActivityProcessingService {
 
     private final LoanRepositoryWrapper loanRepositoryWrapper;
-    private final LoanWritePlatformService loanWritePlatformService;
     private final ExternalIdFactory externalIdFactory;
     private final BusinessEventNotifierService businessEventNotifierService;
-    private final LoanChargeValidator loanChargeValidator;
+    private final LoanTransactionAssembler loanTransactionAssembler;
+    private final LoanAccountDomainService loanAccountDomainService;
 
     @Override
     @Transactional(propagation = Propagation.REQUIRES_NEW)
-    public void makeAccrualActivityTransaction(Long loanId, final LocalDate currentDate) {
+    public void makeAccrualActivityTransaction(@NotNull Long loanId, @NotNull LocalDate currentDate) {
         Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
         makeAccrualActivityTransaction(loan, currentDate);
     }
 
     @Override
-    public Loan makeAccrualActivityTransaction(Loan loan, final LocalDate currentDate) {
-        if (loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
-            // check if loan has installment due on business day
-            Optional<LoanRepaymentScheduleInstallment> first = loan.getRepaymentScheduleInstallments().stream()
-                    .filter(loanRepaymentScheduleInstallment -> loanRepaymentScheduleInstallment.getDueDate().isEqual(currentDate))
-                    .findFirst();
-            if (first.isPresent()) {
-                final LoanRepaymentScheduleInstallment installment = first.get();
-                // check if there is no not-replayed-accrual-activity related to business date
-                List<LoanTransaction> loanTransactions = loan.getLoanTransactions(loanTransaction -> loanTransaction.isNotReversed()
-                        && loanTransaction.isAccrualActivity() && loanTransaction.getTransactionDate().isEqual(currentDate));
-                if (loanTransactions.isEmpty()) {
-                    loan = loanWritePlatformService.makeAccrualActivityTransaction(loan, installment, currentDate);
-                }
+    public void makeAccrualActivityTransaction(@NotNull Loan loan, @NotNull LocalDate currentDate) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
+        // check if loan has installment in the past or due on current date
+        List<LoanRepaymentScheduleInstallment> installments = loan
+                .getRepaymentScheduleInstallments(i -> !i.isDownPayment() && !DateUtils.isBefore(currentDate, i.getDueDate()));
+        for (LoanRepaymentScheduleInstallment installment : installments) {
+            LocalDate dueDate = installment.getDueDate();
+            // check if there is any not-replayed-accrual-activity related to business date
+            ArrayList<LoanTransaction> existingActivities = new ArrayList<>(
+                    loan.getLoanTransactions(t -> t.isNotReversed() && t.isAccrualActivity() && t.getTransactionDate().isEqual(dueDate)));
+            if (existingActivities.isEmpty()) {
+                makeAccrualActivityTransaction(loan, installment, dueDate);
+            } else {
+                LoanTransaction existingActivity = existingActivities.get(0);
+                reverseReplayAccrualActivityTransaction(loan, existingActivity, installment, dueDate);
+                existingActivities.remove(existingActivity);
+                existingActivities.forEach(this::reverseAccrualActivityTransaction);
             }
         }
-        return loan;
     }
 
     @Override
     @Transactional
-    public void processAccrualActivityForLoanClosure(Loan loan) {
+    public void processAccrualActivityForLoanClosure(@NotNull Loan loan) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
         LocalDate date = loan.isOverPaid() ? loan.getOverpaidOnDate() : loan.getClosedOnDate();
         List<LoanTransaction> accrualActivityTransaction = loan.getLoanTransactions().stream().filter(LoanTransaction::isNotReversed)
                 .filter(LoanTransaction::isAccrualActivity).filter(loanTransaction -> loanTransaction.getDateOf().isAfter(date)).toList();
         if (!accrualActivityTransaction.isEmpty()) {
             accrualActivityTransaction.forEach(this::reverseAccrualActivityTransaction);
         }
         LoanTransaction loanTransaction = assembleClosingAccrualActivityTransaction(loan, date);
-        if (loanTransaction.getAmount().compareTo(BigDecimal.ZERO) != 0) {
-            loanWritePlatformService.makeAccrualActivityTransaction(loan, loanTransaction);
+        if (loanTransaction != null) {
+            makeAccrualActivityTransaction(loan, loanTransaction);
         }
     }
 
-    private void reverseAccrualActivityTransaction(LoanTransaction loanTransaction) {
-        loanChargeValidator.validateRepaymentTypeTransactionNotBeforeAChargeRefund(loanTransaction.getLoan(), loanTransaction, "reversed");
-        loanTransaction.reverse();
-        LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(loanTransaction);
-        businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
+    @Override
+    @Transactional
+    public void processAccrualActivityForLoanReopen(@NotNull Loan loan) {

Review Comment:
   Common private methods were moved to the utility section, following the call order.



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "galovics (via GitHub)" <gi...@apache.org>.
galovics commented on code in PR #4220:
URL: https://github.com/apache/fineract/pull/4220#discussion_r1884131063


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualActivityProcessingServiceImpl.java:
##########
@@ -46,58 +51,93 @@
 public class LoanAccrualActivityProcessingServiceImpl implements LoanAccrualActivityProcessingService {
 
     private final LoanRepositoryWrapper loanRepositoryWrapper;
-    private final LoanWritePlatformService loanWritePlatformService;
     private final ExternalIdFactory externalIdFactory;
     private final BusinessEventNotifierService businessEventNotifierService;
-    private final LoanChargeValidator loanChargeValidator;
+    private final LoanTransactionAssembler loanTransactionAssembler;
+    private final LoanAccountDomainService loanAccountDomainService;
 
     @Override
     @Transactional(propagation = Propagation.REQUIRES_NEW)
-    public void makeAccrualActivityTransaction(Long loanId, final LocalDate currentDate) {
+    public void makeAccrualActivityTransaction(@NotNull Long loanId, @NotNull LocalDate currentDate) {
         Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
         makeAccrualActivityTransaction(loan, currentDate);
     }
 
     @Override
-    public Loan makeAccrualActivityTransaction(Loan loan, final LocalDate currentDate) {
-        if (loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
-            // check if loan has installment due on business day
-            Optional<LoanRepaymentScheduleInstallment> first = loan.getRepaymentScheduleInstallments().stream()
-                    .filter(loanRepaymentScheduleInstallment -> loanRepaymentScheduleInstallment.getDueDate().isEqual(currentDate))
-                    .findFirst();
-            if (first.isPresent()) {
-                final LoanRepaymentScheduleInstallment installment = first.get();
-                // check if there is no not-replayed-accrual-activity related to business date
-                List<LoanTransaction> loanTransactions = loan.getLoanTransactions(loanTransaction -> loanTransaction.isNotReversed()
-                        && loanTransaction.isAccrualActivity() && loanTransaction.getTransactionDate().isEqual(currentDate));
-                if (loanTransactions.isEmpty()) {
-                    loan = loanWritePlatformService.makeAccrualActivityTransaction(loan, installment, currentDate);
-                }
+    public void makeAccrualActivityTransaction(@NotNull Loan loan, @NotNull LocalDate currentDate) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
+        // check if loan has installment in the past or due on current date
+        List<LoanRepaymentScheduleInstallment> installments = loan
+                .getRepaymentScheduleInstallments(i -> !i.isDownPayment() && !DateUtils.isBefore(currentDate, i.getDueDate()));
+        for (LoanRepaymentScheduleInstallment installment : installments) {
+            LocalDate dueDate = installment.getDueDate();
+            // check if there is any not-replayed-accrual-activity related to business date
+            ArrayList<LoanTransaction> existingActivities = new ArrayList<>(
+                    loan.getLoanTransactions(t -> t.isNotReversed() && t.isAccrualActivity() && t.getTransactionDate().isEqual(dueDate)));
+            if (existingActivities.isEmpty()) {
+                makeAccrualActivityTransaction(loan, installment, dueDate);
+            } else {
+                LoanTransaction existingActivity = existingActivities.get(0);
+                reverseReplayAccrualActivityTransaction(loan, existingActivity, installment, dueDate);
+                existingActivities.remove(existingActivity);
+                existingActivities.forEach(this::reverseAccrualActivityTransaction);
             }
         }
-        return loan;
     }
 
     @Override
     @Transactional
-    public void processAccrualActivityForLoanClosure(Loan loan) {
+    public void processAccrualActivityForLoanClosure(@NotNull Loan loan) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
         LocalDate date = loan.isOverPaid() ? loan.getOverpaidOnDate() : loan.getClosedOnDate();
         List<LoanTransaction> accrualActivityTransaction = loan.getLoanTransactions().stream().filter(LoanTransaction::isNotReversed)
                 .filter(LoanTransaction::isAccrualActivity).filter(loanTransaction -> loanTransaction.getDateOf().isAfter(date)).toList();
         if (!accrualActivityTransaction.isEmpty()) {
             accrualActivityTransaction.forEach(this::reverseAccrualActivityTransaction);
         }
         LoanTransaction loanTransaction = assembleClosingAccrualActivityTransaction(loan, date);
-        if (loanTransaction.getAmount().compareTo(BigDecimal.ZERO) != 0) {
-            loanWritePlatformService.makeAccrualActivityTransaction(loan, loanTransaction);
+        if (loanTransaction != null) {
+            makeAccrualActivityTransaction(loan, loanTransaction);
         }
     }
 
-    private void reverseAccrualActivityTransaction(LoanTransaction loanTransaction) {
-        loanChargeValidator.validateRepaymentTypeTransactionNotBeforeAChargeRefund(loanTransaction.getLoan(), loanTransaction, "reversed");
-        loanTransaction.reverse();
-        LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(loanTransaction);
-        businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
+    @Override
+    @Transactional
+    public void processAccrualActivityForLoanReopen(@NotNull Loan loan) {

Review Comment:
   I honestly disagree with it and the reason of not reverting the method movement (rewrote most of the methods) doesn't have a ground. Even if you refactored the method bodies, you can revert the method movement - making it possible to review it.
   
   I'll approve it just to get the ball going but next time, please keep in mind to not do unnecessary changes that makes PR reviews hell.



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "marta-jankovics (via GitHub)" <gi...@apache.org>.
marta-jankovics commented on code in PR #4220:
URL: https://github.com/apache/fineract/pull/4220#discussion_r1883720256


##########
fineract-e2e-tests-core/src/test/resources/fineract-test-application.properties:
##########
@@ -23,7 +23,7 @@ fineract-test.api.password=${TEST_PASSWORD:password}
 fineract-test.api.strong-password=${TEST_STRONG_PASSWORD:A1b2c3d4e5f$}
 fineract-test.api.tenant-id=${TEST_TENANT_ID:default}
 
-fineract-test.initialization.enabled=${INITIALIZATION_ENABLED:false}
+fineract-test.initialization.enabled=${INITIALIZATION_ENABLED:true}

Review Comment:
   Integration tests can not run without initialization, that is why I've changed the default value. But I can write it back for now.



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2060: Progressive loan - final accrual calculation on closed… [fineract]

Posted by "marta-jankovics (via GitHub)" <gi...@apache.org>.
marta-jankovics commented on code in PR #4220:
URL: https://github.com/apache/fineract/pull/4220#discussion_r1883805984


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualActivityProcessingServiceImpl.java:
##########
@@ -46,58 +51,93 @@
 public class LoanAccrualActivityProcessingServiceImpl implements LoanAccrualActivityProcessingService {
 
     private final LoanRepositoryWrapper loanRepositoryWrapper;
-    private final LoanWritePlatformService loanWritePlatformService;
     private final ExternalIdFactory externalIdFactory;
     private final BusinessEventNotifierService businessEventNotifierService;
-    private final LoanChargeValidator loanChargeValidator;
+    private final LoanTransactionAssembler loanTransactionAssembler;
+    private final LoanAccountDomainService loanAccountDomainService;
 
     @Override
     @Transactional(propagation = Propagation.REQUIRES_NEW)
-    public void makeAccrualActivityTransaction(Long loanId, final LocalDate currentDate) {
+    public void makeAccrualActivityTransaction(@NotNull Long loanId, @NotNull LocalDate currentDate) {
         Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
         makeAccrualActivityTransaction(loan, currentDate);
     }
 
     @Override
-    public Loan makeAccrualActivityTransaction(Loan loan, final LocalDate currentDate) {
-        if (loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
-            // check if loan has installment due on business day
-            Optional<LoanRepaymentScheduleInstallment> first = loan.getRepaymentScheduleInstallments().stream()
-                    .filter(loanRepaymentScheduleInstallment -> loanRepaymentScheduleInstallment.getDueDate().isEqual(currentDate))
-                    .findFirst();
-            if (first.isPresent()) {
-                final LoanRepaymentScheduleInstallment installment = first.get();
-                // check if there is no not-replayed-accrual-activity related to business date
-                List<LoanTransaction> loanTransactions = loan.getLoanTransactions(loanTransaction -> loanTransaction.isNotReversed()
-                        && loanTransaction.isAccrualActivity() && loanTransaction.getTransactionDate().isEqual(currentDate));
-                if (loanTransactions.isEmpty()) {
-                    loan = loanWritePlatformService.makeAccrualActivityTransaction(loan, installment, currentDate);
-                }
+    public void makeAccrualActivityTransaction(@NotNull Loan loan, @NotNull LocalDate currentDate) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
+        // check if loan has installment in the past or due on current date
+        List<LoanRepaymentScheduleInstallment> installments = loan
+                .getRepaymentScheduleInstallments(i -> !i.isDownPayment() && !DateUtils.isBefore(currentDate, i.getDueDate()));
+        for (LoanRepaymentScheduleInstallment installment : installments) {
+            LocalDate dueDate = installment.getDueDate();
+            // check if there is any not-replayed-accrual-activity related to business date
+            ArrayList<LoanTransaction> existingActivities = new ArrayList<>(
+                    loan.getLoanTransactions(t -> t.isNotReversed() && t.isAccrualActivity() && t.getTransactionDate().isEqual(dueDate)));
+            if (existingActivities.isEmpty()) {
+                makeAccrualActivityTransaction(loan, installment, dueDate);
+            } else {
+                LoanTransaction existingActivity = existingActivities.get(0);
+                reverseReplayAccrualActivityTransaction(loan, existingActivity, installment, dueDate);
+                existingActivities.remove(existingActivity);
+                existingActivities.forEach(this::reverseAccrualActivityTransaction);
             }
         }
-        return loan;
     }
 
     @Override
     @Transactional
-    public void processAccrualActivityForLoanClosure(Loan loan) {
+    public void processAccrualActivityForLoanClosure(@NotNull Loan loan) {
+        if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
+            return;
+        }
         LocalDate date = loan.isOverPaid() ? loan.getOverpaidOnDate() : loan.getClosedOnDate();
         List<LoanTransaction> accrualActivityTransaction = loan.getLoanTransactions().stream().filter(LoanTransaction::isNotReversed)
                 .filter(LoanTransaction::isAccrualActivity).filter(loanTransaction -> loanTransaction.getDateOf().isAfter(date)).toList();
         if (!accrualActivityTransaction.isEmpty()) {
             accrualActivityTransaction.forEach(this::reverseAccrualActivityTransaction);
         }
         LoanTransaction loanTransaction = assembleClosingAccrualActivityTransaction(loan, date);
-        if (loanTransaction.getAmount().compareTo(BigDecimal.ZERO) != 0) {
-            loanWritePlatformService.makeAccrualActivityTransaction(loan, loanTransaction);
+        if (loanTransaction != null) {
+            makeAccrualActivityTransaction(loan, loanTransaction);
         }
     }
 
-    private void reverseAccrualActivityTransaction(LoanTransaction loanTransaction) {
-        loanChargeValidator.validateRepaymentTypeTransactionNotBeforeAChargeRefund(loanTransaction.getLoan(), loanTransaction, "reversed");
-        loanTransaction.reverse();
-        LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(loanTransaction);
-        businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
+    @Override
+    @Transactional
+    public void processAccrualActivityForLoanReopen(@NotNull Loan loan) {

Review Comment:
   Common private methods were moved to the utility section, following the call order. Since I rewrote most of the methods here, I would like to keep this order. 



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org