You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "alberto-art3ch (via GitHub)" <gi...@apache.org> on 2025/02/07 13:12:13 UTC

[PR] FINERACT-1971 Repayment schedule period - Incorrect values after char… [fineract]

alberto-art3ch opened a new pull request, #4314:
URL: https://github.com/apache/fineract/pull/4314

   …ge with large amount
   
   ## Description
   Repayment schedule period data is incorrect when a large amount of charge (123456789012.12) is created
   
   [FINERACT-1971](https://github.com/apache/fineract/pull/FINERACT-1971)
   
   <img width="1335" alt="Screenshot 2025-02-07 at 7 49 21 a m" src="https://github.com/user-attachments/assets/01326635-feab-4574-903e-c67d7d777061" />
   
   
   ## 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-1971 Repayment schedule period - Incorrect values after charge with large amount [fineract]

Posted by "alberto-art3ch (via GitHub)" <gi...@apache.org>.
alberto-art3ch commented on code in PR #4314:
URL: https://github.com/apache/fineract/pull/4314#discussion_r1954575977


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/LoanSchedulePeriodData.java:
##########
@@ -156,11 +158,13 @@ public static LoanSchedulePeriodData periodWithPayments(final Integer periodNumb
             final BigDecimal totalPaidLateForPeriod, final BigDecimal totalWaived, final BigDecimal totalWrittenOff,
             final BigDecimal totalCredits, final boolean isDownPayment, final BigDecimal totalAccruedInterest) {
 
-        BigDecimal totalDue = MathUtil.add(principalOriginalDue, interestDue, feeChargesDue, penaltyChargesDue);
-        BigDecimal totalOutstanding = MathUtil.add(principalOutstanding, interestOutstanding, feeChargesOutstanding,
+        final MathContext mc = new MathContext(MoneyHelper.PRECISION_16, MoneyHelper.getMathContext().getRoundingMode());

Review Comment:
   It was set in the same place as in the past, MoneyHelper class



-- 
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-1971 Repayment schedule period - Incorrect values after charge with large amount [fineract]

Posted by "alberto-art3ch (via GitHub)" <gi...@apache.org>.
alberto-art3ch commented on code in PR #4314:
URL: https://github.com/apache/fineract/pull/4314#discussion_r1954574807


##########
fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java:
##########
@@ -33,7 +33,9 @@ public class MoneyHelper {
 
     private static RoundingMode roundingMode = null;
     private static MathContext mathContext;
-    private static final int PRECISION = 12;
+    public static final int PRECISION = 12;

Review Comment:
   Precisions were removed and I just change from 12 to 19



-- 
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-1971 Repayment schedule period - Incorrect values after char… [fineract]

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


##########
fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java:
##########
@@ -33,7 +33,9 @@ public class MoneyHelper {
 
     private static RoundingMode roundingMode = null;
     private static MathContext mathContext;
-    private static final int PRECISION = 12;
+    public static final int PRECISION = 12;

Review Comment:
   Definitely we shouldn't use 24 precision in the code, that'll lead to very very hard to investigated bugs in the future. Either go with 19 (like the DB column) or smaller precision.



##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/LoanSchedulePeriodData.java:
##########
@@ -156,11 +158,13 @@ public static LoanSchedulePeriodData periodWithPayments(final Integer periodNumb
             final BigDecimal totalPaidLateForPeriod, final BigDecimal totalWaived, final BigDecimal totalWrittenOff,
             final BigDecimal totalCredits, final boolean isDownPayment, final BigDecimal totalAccruedInterest) {
 
-        BigDecimal totalDue = MathUtil.add(principalOriginalDue, interestDue, feeChargesDue, penaltyChargesDue);
-        BigDecimal totalOutstanding = MathUtil.add(principalOutstanding, interestOutstanding, feeChargesOutstanding,
+        final MathContext mc = new MathContext(MoneyHelper.PRECISION_16, MoneyHelper.getMathContext().getRoundingMode());

Review Comment:
   You mean in the rest of the codebase? If so, then I completely agree. We should go with 12 consistently everywhere.



-- 
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-1971 Repayment schedule period - Incorrect values after char… [fineract]

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


##########
fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java:
##########
@@ -33,7 +33,9 @@ public class MoneyHelper {
 
     private static RoundingMode roundingMode = null;
     private static MathContext mathContext;
-    private static final int PRECISION = 12;
+    public static final int PRECISION = 12;

Review Comment:
   This multiple precisions seems random... i dont think we should have multiple precisions...



-- 
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-1971 Repayment schedule period - Incorrect values after char… [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/LoanSchedulePeriodData.java:
##########
@@ -156,11 +158,13 @@ public static LoanSchedulePeriodData periodWithPayments(final Integer periodNumb
             final BigDecimal totalPaidLateForPeriod, final BigDecimal totalWaived, final BigDecimal totalWrittenOff,
             final BigDecimal totalCredits, final boolean isDownPayment, final BigDecimal totalAccruedInterest) {
 
-        BigDecimal totalDue = MathUtil.add(principalOriginalDue, interestDue, feeChargesDue, penaltyChargesDue);
-        BigDecimal totalOutstanding = MathUtil.add(principalOutstanding, interestOutstanding, feeChargesOutstanding,
+        final MathContext mc = new MathContext(MoneyHelper.PRECISION_16, MoneyHelper.getMathContext().getRoundingMode());

Review Comment:
   We can move the precision to a common place and let everything use 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-1971 Repayment schedule period - Incorrect values after char… [fineract]

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


##########
fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java:
##########
@@ -33,7 +33,9 @@ public class MoneyHelper {
 
     private static RoundingMode roundingMode = null;
     private static MathContext mathContext;
-    private static final int PRECISION = 12;
+    public static final int PRECISION = 12;

Review Comment:
   Since we are storing in database bigdecimal values with precision of 19, shouldnt we use the same at backend side everywhere?



-- 
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-1971 Repayment schedule period - Incorrect values after char… [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/LoanSchedulePeriodData.java:
##########
@@ -156,11 +158,13 @@ public static LoanSchedulePeriodData periodWithPayments(final Integer periodNumb
             final BigDecimal totalPaidLateForPeriod, final BigDecimal totalWaived, final BigDecimal totalWrittenOff,
             final BigDecimal totalCredits, final boolean isDownPayment, final BigDecimal totalAccruedInterest) {
 
-        BigDecimal totalDue = MathUtil.add(principalOriginalDue, interestDue, feeChargesDue, penaltyChargesDue);
-        BigDecimal totalOutstanding = MathUtil.add(principalOutstanding, interestOutstanding, feeChargesOutstanding,
+        final MathContext mc = new MathContext(MoneyHelper.PRECISION_16, MoneyHelper.getMathContext().getRoundingMode());

Review Comment:
   It seems pretty random to support 16 digits precisions here where everywhere else it is 12...



-- 
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-1971 Repayment schedule period - Incorrect values after char… [fineract]

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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/LoanSchedulePeriodData.java:
##########
@@ -156,11 +158,13 @@ public static LoanSchedulePeriodData periodWithPayments(final Integer periodNumb
             final BigDecimal totalPaidLateForPeriod, final BigDecimal totalWaived, final BigDecimal totalWrittenOff,
             final BigDecimal totalCredits, final boolean isDownPayment, final BigDecimal totalAccruedInterest) {
 
-        BigDecimal totalDue = MathUtil.add(principalOriginalDue, interestDue, feeChargesDue, penaltyChargesDue);
-        BigDecimal totalOutstanding = MathUtil.add(principalOutstanding, interestOutstanding, feeChargesOutstanding,
+        final MathContext mc = new MathContext(MoneyHelper.PRECISION_16, MoneyHelper.getMathContext().getRoundingMode());

Review Comment:
   I think precision 19 would be the best, since we are storing in database with 19 precision anyway



-- 
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-1971 Repayment schedule period - Incorrect values after charge with large amount [fineract]

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


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