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


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountInterestPostingServiceImpl.java:
##########
@@ -268,16 +271,66 @@ public List<PostingPeriod> calculateInterestUsing(final 
MathContext mc, final Lo
             if 
(postedAsOnDates.contains(periodInterval.endDate().plusDays(1))) {
                 isUserPosting = true;
             }
-            final PostingPeriod postingPeriod = 
PostingPeriod.createFromDTO(periodInterval, periodStartingBalance,
-                    
retreiveOrderedNonInterestPostingTransactions(savingsAccountData), 
monetaryCurrency, compoundingPeriodType,
-                    interestCalculationType, interestRateAsFraction, 
daysInYearType.getValue(), upToInterestCalculationDate,
-                    interestPostTransactions, isInterestTransfer, 
minBalanceForInterestCalculation,
-                    isSavingsInterestPostingAtCurrentPeriodEnd, 
overdraftInterestRateAsFraction, minOverdraftForInterestCalculation,
-                    isUserPosting, financialYearBeginningMonth, 
savingsAccountData.isAllowOverdraft());
+            if (savingsAccountData.isAllowOverdraft() && 
!MathUtil.isZero(savingsAccountData.getGlAccountIdForInterestReceivable())) {
+
+                List<SavingsAccountTransactionData> 
overdraftTransactionsInPeriod = listForOverdraft(savingsAccountData, 
periodInterval);
+                List<SavingsAccountTransactionData> 
interestPostingTransactionsInPeriod = listForInterestPosting(savingsAccountData,
+                        periodInterval);
+                Boolean isOverdraftAccountType = 
isOverdraftAccount(savingsAccountData, periodInterval);
+                List<SavingsAccountTransactionData> prioritizedTransactionList 
= null;
+                List<SavingsAccountTransactionData> fallbackTransactionList = 
null;
 
-            periodStartingBalance = postingPeriod.closingBalance();
+                Boolean flagIntroduce = false;
+
+                if (isOverdraftAccountType) {
+                    prioritizedTransactionList = overdraftTransactionsInPeriod;
+                    fallbackTransactionList = 
interestPostingTransactionsInPeriod;
+                } else {
+                    prioritizedTransactionList = 
interestPostingTransactionsInPeriod;
+                    fallbackTransactionList = overdraftTransactionsInPeriod;
+                }
+                if (!prioritizedTransactionList.isEmpty()) {
+                    final PostingPeriod postingPeriod = 
PostingPeriod.createFromDTO(periodInterval, periodStartingBalance,
+                            prioritizedTransactionList, monetaryCurrency, 
compoundingPeriodType, interestCalculationType,
+                            interestRateAsFraction, daysInYearType.getValue(), 
upToInterestCalculationDate, interestPostTransactions,
+                            isInterestTransfer, 
minBalanceForInterestCalculation, isSavingsInterestPostingAtCurrentPeriodEnd,
+                            overdraftInterestRateAsFraction, 
minOverdraftForInterestCalculation, isUserPosting, financialYearBeginningMonth,
+                            savingsAccountData.isAllowOverdraft(), 
flagIntroduce);
+                    flagIntroduce = postingPeriod.getEndTransaction();
+                    periodStartingBalance = postingPeriod.closingBalance();
+                    if 
(!(MathUtil.isZero(postingPeriod.getOpeningBalance().getAmount())
+                            && 
MathUtil.isZero(postingPeriod.closingBalance().getAmount()))) {
+                        allPostingPeriods.add(postingPeriod);
+                    }
+                }
+
+                if (!fallbackTransactionList.isEmpty()) {
+                    final PostingPeriod postingPeriod = 
PostingPeriod.createFromDTO(periodInterval, periodStartingBalance,

Review Comment:
   ```
   if (!prioritizedTransactionList.isEmpty()) {
                       final PostingPeriod postingPeriod = 
PostingPeriod.createFromDTO(periodInterval, periodStartingBalance,
                               prioritizedTransactionList, monetaryCurrency, 
compoundingPeriodType, interestCalculationType,
                               interestRateAsFraction, 
daysInYearType.getValue(), upToInterestCalculationDate, 
interestPostTransactions,
                               isInterestTransfer, 
minBalanceForInterestCalculation, isSavingsInterestPostingAtCurrentPeriodEnd,
                               overdraftInterestRateAsFraction, 
minOverdraftForInterestCalculation, isUserPosting, financialYearBeginningMonth,
                               savingsAccountData.isAllowOverdraft());
                       periodStartingBalance = postingPeriod.closingBalance();
                       if 
(!(MathUtil.isZero(postingPeriod.getOpeningBalance().getAmount())
                               && 
MathUtil.isZero(postingPeriod.closingBalance().getAmount()))) {
                           allPostingPeriods.add(postingPeriod);
                       }
                   }
   ```
   and 
   ```
   if (!fallbackTransactionList.isEmpty()) {
                       final PostingPeriod postingPeriod = 
PostingPeriod.createFromDTO(periodInterval, 
periodStartingBalance,fallbackTransactionList, monetaryCurrency, 
compoundingPeriodType, interestCalculationType,
                               interestRateAsFraction, 
daysInYearType.getValue(), upToInterestCalculationDate, 
interestPostTransactions,
                               isInterestTransfer, 
minBalanceForInterestCalculation, isSavingsInterestPostingAtCurrentPeriodEnd,
                               overdraftInterestRateAsFraction, 
minOverdraftForInterestCalculation, isUserPosting, financialYearBeginningMonth,
                               savingsAccountData.isAllowOverdraft());
   
                       periodStartingBalance = postingPeriod.closingBalance();
                       if 
(!(MathUtil.isZero(postingPeriod.getOpeningBalance().getAmount())
                               && 
MathUtil.isZero(postingPeriod.closingBalance().getAmount()))) {
                           allPostingPeriods.add(postingPeriod);
                       }
   ```
   
   Is letter to letter the same...
   
   `hasEndTransactionFromPreviousPeriod` cannot be found in the code anywhere...



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