コード例 #1
0
  public EndOfDayBalance toEndOfDayBalanceBoundedBy(
      final Money openingBalance, final LocalDateInterval boundedBy) {

    MonetaryCurrency currency = openingBalance.getCurrency();
    Money endOfDayBalance = openingBalance.copy();

    int numberOfDaysOfBalance = this.balanceNumberOfDays;

    LocalDate balanceStartDate = getTransactionLocalDate();
    LocalDate balanceEndDate = getEndOfBalanceLocalDate();

    if (boundedBy.startDate().isAfter(balanceStartDate)) {
      balanceStartDate = boundedBy.startDate();
      LocalDateInterval spanOfBalance = LocalDateInterval.create(balanceStartDate, balanceEndDate);
      numberOfDaysOfBalance = spanOfBalance.daysInPeriodInclusiveOfEndDate();
    } else {
      if (isDeposit()) {
        endOfDayBalance = openingBalance.plus(getAmount(currency));
      } else if (isWithdrawal() || isWithdrawalFee()) {
        endOfDayBalance = openingBalance.minus(getAmount(currency));
      }
    }

    if (balanceEndDate.isAfter(boundedBy.endDate())) {
      balanceEndDate = boundedBy.endDate();
      LocalDateInterval spanOfBalance = LocalDateInterval.create(balanceStartDate, balanceEndDate);
      numberOfDaysOfBalance = spanOfBalance.daysInPeriodInclusiveOfEndDate();
    }

    return EndOfDayBalance.from(
        balanceStartDate, openingBalance, endOfDayBalance, numberOfDaysOfBalance);
  }
コード例 #2
0
 public void updateCumulativeBalanceAndDates(
     final MonetaryCurrency currency, final LocalDate endOfBalanceDate) {
   this.balanceEndDate = endOfBalanceDate.toDate();
   this.balanceNumberOfDays =
       LocalDateInterval.create(getTransactionLocalDate(), endOfBalanceDate)
           .daysInPeriodInclusiveOfEndDate();
   this.cumulativeBalance =
       Money.of(currency, this.runningBalance).multipliedBy(this.balanceNumberOfDays).getAmount();
 }
コード例 #3
0
  public EndOfDayBalance toEndOfDayBalance(
      final LocalDateInterval periodInterval, final MonetaryCurrency currency) {

    Money endOfDayBalance = Money.of(currency, this.runningBalance);
    Money openingBalance = endOfDayBalance;

    LocalDate balanceDate = periodInterval.startDate();

    int numberOfDays = periodInterval.daysInPeriodInclusiveOfEndDate();
    if (periodInterval.contains(getTransactionLocalDate())) {
      balanceDate = getTransactionLocalDate();
      LocalDateInterval newInterval =
          LocalDateInterval.create(getTransactionLocalDate(), periodInterval.endDate());
      numberOfDays = newInterval.daysInPeriodInclusiveOfEndDate();
    }

    return EndOfDayBalance.from(balanceDate, openingBalance, endOfDayBalance, numberOfDays);
  }
コード例 #4
0
  public EndOfDayBalance toEndOfDayBalance(
      final Money openingBalance, final LocalDate nextTransactionDate) {

    MonetaryCurrency currency = openingBalance.getCurrency();
    Money endOfDayBalance = openingBalance.copy();
    if (isDeposit()) {
      endOfDayBalance = openingBalance.plus(getAmount(currency));
    } else if (isWithdrawal() || isWithdrawalFee()) {
      endOfDayBalance = openingBalance.minus(getAmount(currency));
    }

    int numberOfDays =
        LocalDateInterval.create(getTransactionLocalDate(), nextTransactionDate)
            .daysInPeriodInclusiveOfEndDate();
    if (!openingBalance.isEqualTo(endOfDayBalance) && numberOfDays > 1) {
      numberOfDays = numberOfDays - 1;
    }
    return EndOfDayBalance.from(
        getTransactionLocalDate(), openingBalance, endOfDayBalance, numberOfDays);
  }
コード例 #5
0
 public boolean spansAnyPortionOf(final LocalDateInterval periodInterval) {
   LocalDateInterval balanceInterval =
       LocalDateInterval.create(getTransactionLocalDate(), getEndOfBalanceLocalDate());
   return balanceInterval.containsPortionOf(periodInterval);
 }
コード例 #6
0
 public boolean fallsWithin(final LocalDateInterval periodInterval) {
   LocalDateInterval balanceInterval =
       LocalDateInterval.create(getTransactionLocalDate(), getEndOfBalanceLocalDate());
   return periodInterval.contains(balanceInterval);
 }
コード例 #7
0
 public boolean isAcceptableForDailyBalance(final LocalDateInterval interestPeriodInterval) {
   return isNotReversed()
       && interestPeriodInterval.contains(getTransactionLocalDate())
       && isABalanceForAtLeastOneDay();
 }