adamsaghy commented on code in PR #5454:
URL: https://github.com/apache/fineract/pull/5454#discussion_r2816551711
##########
fineract-core/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsHelper.java:
##########
@@ -40,96 +41,128 @@ public final class SavingsHelper {
private final AccountTransfersReadPlatformService
accountTransfersReadPlatformService;
+ private static final CompoundInterestHelper COMPOUND_INTEREST_HELPER = new
CompoundInterestHelper();
+
@Autowired
public SavingsHelper(AccountTransfersReadPlatformService
accountTransfersReadPlatformService) {
this.accountTransfersReadPlatformService =
accountTransfersReadPlatformService;
}
- private static final CompoundInterestHelper COMPOUND_INTEREST_HELPER = new
CompoundInterestHelper();
+
+ // FIXED METHOD (FINERACT-1266)
+
- public List<LocalDateInterval> determineInterestPostingPeriods(final
LocalDate startInterestCalculationLocalDate,
- final LocalDate interestPostingUpToDate, final
SavingsPostingInterestPeriodType postingPeriodType,
- final Integer financialYearBeginningMonth, List<LocalDate>
postInterestAsOn) {
+ public List<LocalDateInterval> determineInterestPostingPeriods(
+ final LocalDate startInterestCalculationLocalDate,
+ final LocalDate interestPostingUpToDate,
+ final SavingsPostingInterestPeriodType postingPeriodType,
+ final Integer financialYearBeginningMonth,
+ List<LocalDate> postInterestAsOn) {
final List<LocalDateInterval> postingPeriods = new ArrayList<>();
if (startInterestCalculationLocalDate == null ||
interestPostingUpToDate == null) {
return postingPeriods;
}
+ // 🔐 Null-safe list
+ if (postInterestAsOn == null) {
+ postInterestAsOn = Collections.emptyList();
+ }
+
+ // 🔐 Null-safe posting period
+ final SavingsPostingInterestPeriodType safePostingPeriodType =
+ postingPeriodType != null ? postingPeriodType :
SavingsPostingInterestPeriodType.INVALID;
+
LocalDate periodStartDate = startInterestCalculationLocalDate;
LocalDate periodEndDate = periodStartDate;
LocalDate actualPeriodStartDate = periodStartDate;
- while (!DateUtils.isAfter(periodStartDate, interestPostingUpToDate) &&
!DateUtils.isAfter(periodEndDate, interestPostingUpToDate)) {
- final LocalDate interestPostingLocalDate =
determineInterestPostingPeriodEndDateFrom(periodStartDate, postingPeriodType,
- interestPostingUpToDate, financialYearBeginningMonth);
+ while (!DateUtils.isAfter(periodStartDate, interestPostingUpToDate)
+ && !DateUtils.isAfter(periodEndDate, interestPostingUpToDate))
{
+
+ final LocalDate interestPostingLocalDate =
+ determineInterestPostingPeriodEndDateFrom(
+ periodStartDate,
+ safePostingPeriodType,
+ interestPostingUpToDate,
+ financialYearBeginningMonth);
periodEndDate = interestPostingLocalDate.minusDays(1);
- if (!postInterestAsOn.isEmpty()) {
- for (LocalDate transactiondate : postInterestAsOn) {
- if (DateUtils.isAfter(transactiondate, periodStartDate) &&
!DateUtils.isAfter(transactiondate, periodEndDate)) {
- periodEndDate = transactiondate.minusDays(1);
- actualPeriodStartDate = periodEndDate;
- break;
- }
+ for (LocalDate transactionDate : postInterestAsOn) {
+ if (DateUtils.isAfter(transactionDate, periodStartDate)
+ && !DateUtils.isAfter(transactionDate, periodEndDate))
{
+ periodEndDate = transactionDate.minusDays(1);
+ actualPeriodStartDate = periodEndDate;
+ break;
}
}
postingPeriods.add(LocalDateInterval.create(periodStartDate,
periodEndDate));
if (DateUtils.isEqual(actualPeriodStartDate, periodEndDate)) {
- periodEndDate = actualPeriodStartDate.plusDays(1);
periodStartDate = actualPeriodStartDate.plusDays(1);
+ periodEndDate = actualPeriodStartDate.plusDays(1);
} else {
- periodEndDate = interestPostingLocalDate;
periodStartDate = interestPostingLocalDate;
+ periodEndDate = interestPostingLocalDate;
}
}
return postingPeriods;
}
- private LocalDate determineInterestPostingPeriodEndDateFrom(final
LocalDate periodStartDate,
- final SavingsPostingInterestPeriodType interestPostingPeriodType,
final LocalDate interestPostingUpToDate,
+
+ // FIXED HELPER METHOD
+
+
+ private LocalDate determineInterestPostingPeriodEndDateFrom(
+ final LocalDate periodStartDate,
+ final SavingsPostingInterestPeriodType interestPostingPeriodType,
+ final LocalDate interestPostingUpToDate,
Integer financialYearBeginningMonth) {
+ // 🔐 Null-safe fallback
Review Comment:
Please remove the AI generated, useless comments!
--
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]