adamsaghy commented on code in PR #4837:
URL: https://github.com/apache/fineract/pull/4837#discussion_r2213114767
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountInterestPostingServiceImpl.java:
##########
@@ -268,16 +324,106 @@ 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.getGlAccountIdForInterestReceivableNegative())){
+ List<SavingsAccountTransactionData> listOfTransactions =
retreiveOrderedNonInterestPostingTransactions(savingsAccountData);
+
+ List<SavingsAccountTransactionData> listOfTransactionsNegative
= new ArrayList<>();
+ List<SavingsAccountTransactionData> listOfTransactionsPositive
= new ArrayList<>();
+ boolean firstIsNegative = false;
+ boolean firstIsSet = false;
+
+ for (SavingsAccountTransactionData lists : listOfTransactions)
{
+
+ if (MathUtil.isLessThanZero(lists.getRunningBalance())
+ && periodInterval.startDate().getMonth() ==
lists.getDate().getMonth()) {
+ listOfTransactionsNegative.add(lists);
+ if (!firstIsSet) {
+ firstIsNegative = true;
+ firstIsSet = true;
+ }
+ } else if (periodInterval.startDate().getMonth() ==
lists.getDate().getMonth()) {
+ BigDecimal bd = new
BigDecimal(String.valueOf(lists.getRunningBalance())).setScale(2,
RoundingMode.DOWN);
+ if (!MathUtil.isZero(bd)) {
+ listOfTransactionsPositive.add(lists);
+ if (!firstIsSet) {
+ firstIsNegative = false;
+ firstIsSet = true;
+ }
+ }
+ }
+
+ }
+ List<SavingsAccountTransactionData> firstList = null;
+ List<SavingsAccountTransactionData> secondList = null;
+
+ if (firstIsNegative) {
+ firstList = listOfTransactionsNegative;
+ secondList = listOfTransactionsPositive;
+ } else {
+ firstList = listOfTransactionsPositive;
+ secondList = listOfTransactionsNegative;
+ }
+ Boolean flagIntroduce = false;
+
+ if (firstList.isEmpty() && secondList.isEmpty()) {
+ 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(), false);
+
+ periodStartingBalance = postingPeriod.closingBalance();
+
+ allPostingPeriods.add(postingPeriod);
+ continue;
Review Comment:
Please refactor this logic... having 200-300 lines long foreach and random
`continue` is not acceptable!
Please refactor this whole logic and split into much smaller pieces....
--
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]