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 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);
  }