You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "mariiaKraievska (via GitHub)" <gi...@apache.org> on 2025/06/24 14:16:44 UTC

[PR] FINERACT-1981: Progressive Loan schedule handling - Installment charges [fineract]

mariiaKraievska opened a new pull request, #4800:
URL: https://github.com/apache/fineract/pull/4800

   ## 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-1981: Progressive Loan schedule handling - Installment charges [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4800:
URL: https://github.com/apache/fineract/pull/4800#issuecomment-3000810692

   @mariiaKraievska Please run `spotlessApply` to avoid checkstyle issues!


-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/SingleLoanChargeRepaymentScheduleProcessingWrapper.java:
##########
@@ -143,13 +139,12 @@ private Money calcChargeDue(final LocalDate periodStart, final LocalDate periodE
     }
 
     private Money calcChargeWaived(final LocalDate periodStart, final LocalDate periodEnd, final LoanCharge loanCharge,
-            final MonetaryCurrency currency, boolean isInstallmentChargeApplicable, boolean isFirstPeriod,
-            Predicate<LoanCharge> predicate) {
+            final MonetaryCurrency currency, boolean isFirstPeriod, Predicate<LoanCharge> predicate) {
         Money zero = Money.zero(currency);
         if (!predicate.test(loanCharge)) {
             return zero;
         }
-        if (loanCharge.isInstalmentFee() && isInstallmentChargeApplicable) {

Review Comment:
   I have reverted this change, since we agreed to disallow installment fee charges that are calculated as a percentage of principal or interest when interest recalculation is enabled.



##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanChargeApiJsonValidator.java:
##########
@@ -264,16 +264,8 @@ public void validateLoanCharges(final Set<LoanCharge> charges, final List<ApiPar
         for (LoanCharge loanCharge : charges) {
             String errorcode = null;
             switch (loanCharge.getChargeCalculation()) {
-                case PERCENT_OF_AMOUNT:

Review Comment:
   I have reverted this change, since we agreed to disallow installment fee charges that are calculated as a percentage of principal or interest when interest recalculation is enabled.



-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeService.java:
##########
@@ -575,49 +608,67 @@ private BigDecimal calculatePerInstallmentChargeAmount(final Loan loan, final Lo
     }
 
     private void updateInstallmentCharges(final LoanCharge loanCharge) {
-        final Collection<LoanInstallmentCharge> remove = new HashSet<>();
+        for (LoanInstallmentCharge oldCharge : loanCharge.getLoanInstallmentCharge()) {
+            oldCharge.getInstallment().getInstallmentCharges().remove(oldCharge);
+        }
+        loanCharge.getLoanInstallmentCharge().clear();

Review Comment:
   Thank you for your question!
   After reverting to the previous logic, I encountered a database integrity error during testing (specifically on charge-off with accelerate maturity date behaviour), caused by a foreign key constraint violation between m_loan_installment_charge and m_loan_repayment_schedule.
   It seems that the old approach does not always properly remove or update all related installment charges before the repayment schedule is changed, which leads to this issue.
   That’s why the logic to clear and recreate all charges was introduced — to ensure data consistency and avoid such integrity problems.



-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4800:
URL: https://github.com/apache/fineract/pull/4800#issuecomment-3047965765

   @mariiaKraievska Please rebase this PR.


-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4800:
URL: https://github.com/apache/fineract/pull/4800#issuecomment-3025059593

   @mariiaKraievska please rebase


-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeService.java:
##########
@@ -575,49 +608,67 @@ private BigDecimal calculatePerInstallmentChargeAmount(final Loan loan, final Lo
     }
 
     private void updateInstallmentCharges(final LoanCharge loanCharge) {
-        final Collection<LoanInstallmentCharge> remove = new HashSet<>();
+        for (LoanInstallmentCharge oldCharge : loanCharge.getLoanInstallmentCharge()) {
+            oldCharge.getInstallment().getInstallmentCharges().remove(oldCharge);
+        }
+        loanCharge.getLoanInstallmentCharge().clear();

Review Comment:
   Well, it is suboptimal, as we are recreating charges which are unchanged :/ I wonder whether we should have some logic which can compare them properly...



-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeService.java:
##########
@@ -575,49 +608,67 @@ private BigDecimal calculatePerInstallmentChargeAmount(final Loan loan, final Lo
     }
 
     private void updateInstallmentCharges(final LoanCharge loanCharge) {
-        final Collection<LoanInstallmentCharge> remove = new HashSet<>();
+        for (LoanInstallmentCharge oldCharge : loanCharge.getLoanInstallmentCharge()) {
+            oldCharge.getInstallment().getInstallmentCharges().remove(oldCharge);
+        }
+        loanCharge.getLoanInstallmentCharge().clear();

Review Comment:
   Please check updated version of this method 🙏 



-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeService.java:
##########
@@ -575,49 +608,67 @@ private BigDecimal calculatePerInstallmentChargeAmount(final Loan loan, final Lo
     }
 
     private void updateInstallmentCharges(final LoanCharge loanCharge) {
-        final Collection<LoanInstallmentCharge> remove = new HashSet<>();
+        for (LoanInstallmentCharge oldCharge : loanCharge.getLoanInstallmentCharge()) {
+            oldCharge.getInstallment().getInstallmentCharges().remove(oldCharge);
+        }
+        loanCharge.getLoanInstallmentCharge().clear();

Review Comment:
   Why do we need to drop all charges? That would recreate charges every time... Was the previous version which only updated the existing once wrong?



-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java:
##########
@@ -1587,16 +1587,9 @@ private int adjustNumberOfRepayments() {
         return repaymetsForAdjust;
     }
 
-    public int fetchNumberOfInstallmensAfterExceptions() {
+    public int fetchNumberOfInstallmentsAfterExceptions() {
         if (!this.repaymentScheduleInstallments.isEmpty()) {
-            List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();

Review Comment:
   I have reverted this change, since we agreed to disallow installment fee charges that are calculated as a percentage of principal or interest when interest recalculation is enabled.



##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/SingleLoanChargeRepaymentScheduleProcessingWrapper.java:
##########
@@ -60,25 +60,21 @@ public void reprocess(final MonetaryCurrency currency, final LocalDate disbursem
             if (installment.isDownPayment()) {
                 continue;
             }
-            boolean installmentChargeApplicable = !installment.isRecalculatedInterestComponent();

Review Comment:
   I have reverted this change, since we agreed to disallow installment fee charges that are calculated as a percentage of principal or interest when interest recalculation is enabled.



##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/SingleLoanChargeRepaymentScheduleProcessingWrapper.java:
##########
@@ -104,15 +100,15 @@ public void reprocess(final MonetaryCurrency currency, final LocalDate disbursem
     @NotNull
     private Money calcChargeDue(final LocalDate periodStart, final LocalDate periodEnd, final LoanCharge loanCharge,
             final MonetaryCurrency currency, LoanRepaymentScheduleInstallment period, final Money totalPrincipal, final Money totalInterest,
-            boolean isInstallmentChargeApplicable, boolean isFirstPeriod, Predicate<LoanCharge> predicate) {
+            boolean isFirstPeriod, Predicate<LoanCharge> predicate) {
         Money zero = Money.zero(currency);
         if (!predicate.test(loanCharge)) {
             return zero;
         }
         if (loanCharge.isFeeCharge() && loanCharge.isDueAtDisbursement()) {
             return zero;
         }
-        if (loanCharge.isInstalmentFee() && isInstallmentChargeApplicable) {

Review Comment:
   I have reverted this change, since we agreed to disallow installment fee charges that are calculated as a percentage of principal or interest when interest recalculation is enabled.



-- 
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-1981: Progressive Loan schedule handling - Installment charges [fineract]

Posted by "mariiaKraievska (via GitHub)" <gi...@apache.org>.
mariiaKraievska commented on PR #4800:
URL: https://github.com/apache/fineract/pull/4800#issuecomment-3048063079

   > @mariiaKraievska Please rebase this PR.
   
   Done


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