Abhishek6122008 commented on code in PR #6782:
URL: https://github.com/apache/fineract/pull/6782#discussion_r4418252725


##########
fineract-core/src/main/java/org/apache/fineract/portfolio/savings/domain/interest/CompoundInterestHelper.java:
##########
@@ -48,23 +48,42 @@ public Money calculateInterestForAllPostingPeriods(final 
MonetaryCurrency curren
         BigDecimal compoundedInterest = BigDecimal.ZERO;
         BigDecimal unCompoundedInterest = BigDecimal.ZERO;
         final CompoundInterestValues compoundInterestValues = new 
CompoundInterestValues(compoundedInterest, unCompoundedInterest);
-        for (final PostingPeriod postingPeriod : allPeriods) {
-
-            final BigDecimal interestEarnedThisPeriod = 
postingPeriod.calculateInterest(compoundInterestValues);
+        int index = 0;
+        while (index < allPeriods.size()) {
+            final PostingPeriod postingPeriod = allPeriods.get(index);
+            // the overdraft split builds two periods for one posting 
interval, which are calculated together
+            final PostingPeriod otherPeriodOfInterval = index + 1 < 
allPeriods.size()
+                    && hasSameInterval(postingPeriod, allPeriods.get(index + 
1)) ? allPeriods.get(index + 1) : null;
+            final List<PostingPeriod> periodsOfInterval;
+            if (otherPeriodOfInterval == null) {
+                postingPeriod.calculateInterest(compoundInterestValues);
+                periodsOfInterval = List.of(postingPeriod);
+            } else {
+                PostingPeriod.calculateInterest(postingPeriod, 
otherPeriodOfInterval, compoundInterestValues);
+                periodsOfInterval = List.of(postingPeriod, 
otherPeriodOfInterval);

Review Comment:
   Made the new method void. The helper reads each period's own interest so 
they're rounded separately, like before. I left the instance calculateInterest 
as it is: the accrual job already ignored its return value before this PR, so 
changing its signature is out of scope here.
   



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