final SavingsPostingInterestPeriodType postingPeriodType = SavingsPostingInterestPeriodType.fromInt(this.interestPostingPeriodType);
final SavingsCompoundingInterestPeriodType compoundingPeriodType = SavingsCompoundingInterestPeriodType
.fromInt(this.interestCompoundingPeriodType);
final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType
.fromInt(this.interestCalculationDaysInYearType);
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(
getStartInterestCalculationDate(), upToInterestCalculationDate, postingPeriodType,
financialYearBeginningMonth);
final List<PostingPeriod> allPostingPeriods = new ArrayList<>();
Money periodStartingBalance;
if (this.startInterestCalculationDate != null) {
LocalDate startInterestCalculationDate = new LocalDate(this.startInterestCalculationDate);
final SavingsAccountTransaction transaction = findLastTransaction(startInterestCalculationDate);
if (transaction == null) {
final String defaultUserMessage = "No transactions were found on the specified date "
+ getStartInterestCalculationDate().toString() + " for account number " + this.accountNumber.toString()
+ " and resource id " + getId();
final ApiParameterError error = ApiParameterError.parameterError(
"error.msg.savingsaccount.transaction.incorrect.start.interest.calculation.date", defaultUserMessage,
"transactionDate", getStartInterestCalculationDate().toString());
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException(dataValidationErrors);
}
periodStartingBalance = transaction.getRunningBalance(this.currency);
} else
periodStartingBalance = Money.zero(this.currency);
final SavingsInterestCalculationType interestCalculationType = SavingsInterestCalculationType.fromInt(this.interestCalculationType);
final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, upToInterestCalculationDate);
final Collection<Long> interestPostTransactions = this.savingsHelper.fetchPostInterestTransactionIds(getId());
final Money minBalanceForInterestCalculation = Money.of(getCurrency(), minBalanceForInterestCalculation());
for (final LocalDateInterval periodInterval : postingPeriodIntervals) {
final PostingPeriod postingPeriod = PostingPeriod.createFrom(periodInterval, periodStartingBalance,
retreiveOrderedNonInterestPostingTransactions(), this.currency, compoundingPeriodType, interestCalculationType,
interestRateAsFraction, daysInYearType.getValue(), upToInterestCalculationDate, interestPostTransactions,
isInterestTransfer, minBalanceForInterestCalculation, isSavingsInterestPostingAtCurrentPeriodEnd);
periodStartingBalance = postingPeriod.closingBalance();
allPostingPeriods.add(postingPeriod);