Exemplo n.º 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);
  }
Exemplo n.º 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();
 }
Exemplo n.º 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);
  }
Exemplo n.º 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);
  }
Exemplo n.º 5
0
 public boolean spansAnyPortionOf(final LocalDateInterval periodInterval) {
   LocalDateInterval balanceInterval =
       LocalDateInterval.create(getTransactionLocalDate(), getEndOfBalanceLocalDate());
   return balanceInterval.containsPortionOf(periodInterval);
 }
Exemplo n.º 6
0
 public boolean fallsWithin(final LocalDateInterval periodInterval) {
   LocalDateInterval balanceInterval =
       LocalDateInterval.create(getTransactionLocalDate(), getEndOfBalanceLocalDate());
   return periodInterval.contains(balanceInterval);
 }
Exemplo n.º 7
0
 public boolean isAcceptableForDailyBalance(final LocalDateInterval interestPeriodInterval) {
   return isNotReversed()
       && interestPeriodInterval.contains(getTransactionLocalDate())
       && isABalanceForAtLeastOneDay();
 }