Merge pull request #1065 from avikganguly01/startinterest
Start Interest Calculation Date
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `m_savings_account`
|
||||||
|
ADD COLUMN `start_interest_calculation_date` DATE NULL DEFAULT NULL AFTER `min_balance_for_interest_calculation`;
|
||||||
+63
-2
@@ -246,6 +246,10 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
|||||||
|
|
||||||
@Column(name = "min_required_balance", scale = 6, precision = 19, nullable = true)
|
@Column(name = "min_required_balance", scale = 6, precision = 19, nullable = true)
|
||||||
private BigDecimal minRequiredBalance;
|
private BigDecimal minRequiredBalance;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.DATE)
|
||||||
|
@Column(name = "start_interest_calculation_date")
|
||||||
|
protected Date startInterestCalculationDate;
|
||||||
|
|
||||||
@Embedded
|
@Embedded
|
||||||
protected SavingsAccountSummary summary;
|
protected SavingsAccountSummary summary;
|
||||||
@@ -468,6 +472,21 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
|||||||
|
|
||||||
return postingTransation;
|
return postingTransation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Determine the last transaction for given day
|
||||||
|
protected SavingsAccountTransaction findLastTransaction(final LocalDate date) {
|
||||||
|
|
||||||
|
SavingsAccountTransaction savingsTransaction = null;
|
||||||
|
|
||||||
|
for (final SavingsAccountTransaction transaction : this.transactions) {
|
||||||
|
if (transaction.isNotReversed() && transaction.occursOn(date)) {
|
||||||
|
savingsTransaction = transaction;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return savingsTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All interest calculation based on END-OF-DAY-BALANCE.
|
* All interest calculation based on END-OF-DAY-BALANCE.
|
||||||
@@ -510,12 +529,42 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
|||||||
final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType
|
final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType
|
||||||
.fromInt(this.interestCalculationDaysInYearType);
|
.fromInt(this.interestCalculationDaysInYearType);
|
||||||
|
|
||||||
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(getActivationLocalDate(),
|
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(getStartInterestCalculationDate(),
|
||||||
upToInterestCalculationDate, postingPeriodType);
|
upToInterestCalculationDate, postingPeriodType);
|
||||||
|
|
||||||
final List<PostingPeriod> allPostingPeriods = new ArrayList<>();
|
final List<PostingPeriod> allPostingPeriods = new ArrayList<>();
|
||||||
|
|
||||||
|
Money periodStartingBalance;
|
||||||
|
if (this.startInterestCalculationDate != null) {
|
||||||
|
LocalDate startInterestCalculationDate = new LocalDate(
|
||||||
|
this.startInterestCalculationDate);
|
||||||
|
final SavingsAccountTransaction transaction = findLastTransaction(startInterestCalculationDate);
|
||||||
|
|
||||||
Money periodStartingBalance = Money.zero(this.currency);
|
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 SavingsInterestCalculationType interestCalculationType = SavingsInterestCalculationType.fromInt(this.interestCalculationType);
|
||||||
final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, upToInterestCalculationDate);
|
final BigDecimal interestRateAsFraction = getEffectiveInterestRateAsFraction(mc, upToInterestCalculationDate);
|
||||||
@@ -700,6 +749,18 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
|||||||
}
|
}
|
||||||
return activationLocalDate;
|
return activationLocalDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//startInterestCalculationDate is set during migration so that there is no
|
||||||
|
//interference with interest posting of previous system
|
||||||
|
public LocalDate getStartInterestCalculationDate() {
|
||||||
|
LocalDate startInterestCalculationLocalDate = null;
|
||||||
|
if (this.startInterestCalculationDate != null) {
|
||||||
|
startInterestCalculationLocalDate = new LocalDate(
|
||||||
|
this.startInterestCalculationDate);
|
||||||
|
} else
|
||||||
|
startInterestCalculationLocalDate = getActivationLocalDate();
|
||||||
|
return startInterestCalculationLocalDate;
|
||||||
|
}
|
||||||
|
|
||||||
public SavingsAccountTransaction withdraw(final SavingsAccountTransactionDTO transactionDTO, final boolean applyWithdrawFee) {
|
public SavingsAccountTransaction withdraw(final SavingsAccountTransactionDTO transactionDTO, final boolean applyWithdrawFee) {
|
||||||
|
|
||||||
|
|||||||
+4
@@ -216,6 +216,10 @@ public final class SavingsAccountTransaction extends AbstractPersistable<Long> {
|
|||||||
public Money getAmount(final MonetaryCurrency currency) {
|
public Money getAmount(final MonetaryCurrency currency) {
|
||||||
return Money.of(currency, this.amount);
|
return Money.of(currency, this.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Money getRunningBalance(final MonetaryCurrency currency) {
|
||||||
|
return Money.of(currency, this.runningBalance);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isDeposit() {
|
public boolean isDeposit() {
|
||||||
return SavingsAccountTransactionType.fromInt(this.typeOf).isDeposit();
|
return SavingsAccountTransactionType.fromInt(this.typeOf).isDeposit();
|
||||||
|
|||||||
+2
-2
@@ -29,12 +29,12 @@ public final class SavingsHelper {
|
|||||||
|
|
||||||
private final CompoundInterestHelper compoundInterestHelper = new CompoundInterestHelper();
|
private final CompoundInterestHelper compoundInterestHelper = new CompoundInterestHelper();
|
||||||
|
|
||||||
public List<LocalDateInterval> determineInterestPostingPeriods(final LocalDate activationLocalDate,
|
public List<LocalDateInterval> determineInterestPostingPeriods(final LocalDate startInterestCalculationLocalDate,
|
||||||
final LocalDate interestPostingUpToDate, final SavingsPostingInterestPeriodType postingPeriodType) {
|
final LocalDate interestPostingUpToDate, final SavingsPostingInterestPeriodType postingPeriodType) {
|
||||||
|
|
||||||
final List<LocalDateInterval> postingPeriods = new ArrayList<>();
|
final List<LocalDateInterval> postingPeriods = new ArrayList<>();
|
||||||
|
|
||||||
LocalDate periodStartDate = activationLocalDate;
|
LocalDate periodStartDate = startInterestCalculationLocalDate;
|
||||||
LocalDate periodEndDate = periodStartDate;
|
LocalDate periodEndDate = periodStartDate;
|
||||||
|
|
||||||
while (!periodStartDate.isAfter(interestPostingUpToDate) && !periodEndDate.isAfter(interestPostingUpToDate)) {
|
while (!periodStartDate.isAfter(interestPostingUpToDate) && !periodEndDate.isAfter(interestPostingUpToDate)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user