예제 #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 EndOfDayBalance toEndOfDayBalance(final Money openingBalance) {
    MonetaryCurrency currency = openingBalance.getCurrency();
    Money endOfDayBalance = openingBalance.copy();
    if (isDeposit()) {
      endOfDayBalance = openingBalance.plus(getAmount(currency));
    } else if (isWithdrawal() || isWithdrawalFee()) {
      endOfDayBalance = openingBalance.minus(getAmount(currency));
    }

    return EndOfDayBalance.from(
        getTransactionLocalDate(), openingBalance, endOfDayBalance, this.balanceNumberOfDays);
  }
예제 #3
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);
  }
예제 #4
0
  public void updateSummary(
      final MonetaryCurrency currency,
      final Money principal,
      final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
      final LoanSummaryWrapper summaryWrapper,
      final Boolean disbursed) {

    this.totalPrincipalDisbursed = principal.getAmount();
    this.totalPrincipalRepaid =
        summaryWrapper
            .calculateTotalPrincipalRepaid(repaymentScheduleInstallments, currency)
            .getAmount();
    this.totalPrincipalWrittenOff =
        summaryWrapper
            .calculateTotalPrincipalWrittenOff(repaymentScheduleInstallments, currency)
            .getAmount();

    this.totalPrincipalOutstanding =
        principal.minus(this.totalPrincipalRepaid).minus(this.totalPrincipalWrittenOff).getAmount();

    final Money totalInterestCharged =
        summaryWrapper.calculateTotalInterestCharged(repaymentScheduleInstallments, currency);
    this.totalInterestCharged = totalInterestCharged.getAmount();
    this.totalInterestRepaid =
        summaryWrapper
            .calculateTotalInterestRepaid(repaymentScheduleInstallments, currency)
            .getAmount();
    this.totalInterestWaived =
        summaryWrapper
            .calculateTotalInterestWaived(repaymentScheduleInstallments, currency)
            .getAmount();
    this.totalInterestWrittenOff =
        summaryWrapper
            .calculateTotalInterestWrittenOff(repaymentScheduleInstallments, currency)
            .getAmount();

    this.totalInterestOutstanding =
        totalInterestCharged
            .minus(this.totalInterestRepaid)
            .minus(this.totalInterestWaived)
            .minus(this.totalInterestWrittenOff)
            .getAmount();

    final Money totalFeeChargesCharged =
        summaryWrapper
            .calculateTotalFeeChargesCharged(repaymentScheduleInstallments, currency)
            .plus(this.totalFeeChargesDueAtDisbursement);
    this.totalFeeChargesCharged = totalFeeChargesCharged.getAmount();

    Money totalFeeChargesRepaid =
        summaryWrapper.calculateTotalFeeChargesRepaid(repaymentScheduleInstallments, currency);
    if (disbursed) {
      totalFeeChargesRepaid = totalFeeChargesRepaid.plus(this.totalFeeChargesDueAtDisbursement);
    }
    this.totalFeeChargesRepaid = totalFeeChargesRepaid.getAmount();

    this.totalFeeChargesWaived =
        summaryWrapper
            .calculateTotalFeeChargesWaived(repaymentScheduleInstallments, currency)
            .getAmount();
    this.totalFeeChargesWrittenOff =
        summaryWrapper
            .calculateTotalFeeChargesWrittenOff(repaymentScheduleInstallments, currency)
            .getAmount();

    this.totalFeeChargesOutstanding =
        totalFeeChargesCharged
            .minus(this.totalFeeChargesRepaid)
            .minus(this.totalFeeChargesWaived)
            .minus(this.totalFeeChargesWrittenOff)
            .getAmount();

    final Money totalPenaltyChargesCharged =
        summaryWrapper.calculateTotalPenaltyChargesCharged(repaymentScheduleInstallments, currency);
    this.totalPenaltyChargesCharged = totalPenaltyChargesCharged.getAmount();
    this.totalPenaltyChargesRepaid =
        summaryWrapper
            .calculateTotalPenaltyChargesRepaid(repaymentScheduleInstallments, currency)
            .getAmount();
    this.totalPenaltyChargesWaived =
        summaryWrapper
            .calculateTotalPenaltyChargesWaived(repaymentScheduleInstallments, currency)
            .getAmount();
    this.totalPenaltyChargesWrittenOff =
        summaryWrapper
            .calculateTotalPenaltyChargesWrittenOff(repaymentScheduleInstallments, currency)
            .getAmount();

    this.totalPenaltyChargesOutstanding =
        totalPenaltyChargesCharged
            .minus(this.totalPenaltyChargesRepaid)
            .minus(this.totalPenaltyChargesWaived)
            .minus(this.totalPenaltyChargesWrittenOff)
            .getAmount();

    final Money totalExpectedRepayment =
        Money.of(currency, this.totalPrincipalDisbursed)
            .plus(this.totalInterestCharged)
            .plus(this.totalFeeChargesCharged)
            .plus(this.totalPenaltyChargesCharged);
    this.totalExpectedRepayment = totalExpectedRepayment.getAmount();

    final Money totalRepayment =
        Money.of(currency, this.totalPrincipalRepaid)
            .plus(this.totalInterestRepaid)
            .plus(this.totalFeeChargesRepaid)
            .plus(this.totalPenaltyChargesRepaid);
    this.totalRepayment = totalRepayment.getAmount();

    final Money totalExpectedCostOfLoan =
        Money.of(currency, this.totalInterestCharged)
            .plus(this.totalFeeChargesCharged)
            .plus(this.totalPenaltyChargesCharged);
    this.totalExpectedCostOfLoan = totalExpectedCostOfLoan.getAmount();

    final Money totalCostOfLoan =
        Money.of(currency, this.totalInterestRepaid)
            .plus(this.totalFeeChargesRepaid)
            .plus(this.totalPenaltyChargesRepaid);
    this.totalCostOfLoan = totalCostOfLoan.getAmount();

    final Money totalWaived =
        Money.of(currency, this.totalInterestWaived)
            .plus(this.totalFeeChargesWaived)
            .plus(this.totalPenaltyChargesWaived);
    this.totalWaived = totalWaived.getAmount();

    final Money totalWrittenOff =
        Money.of(currency, this.totalPrincipalWrittenOff)
            .plus(this.totalInterestWrittenOff)
            .plus(this.totalFeeChargesWrittenOff)
            .plus(this.totalPenaltyChargesWrittenOff);
    this.totalWrittenOff = totalWrittenOff.getAmount();

    final Money totalOutstanding =
        Money.of(currency, this.totalPrincipalOutstanding)
            .plus(this.totalInterestOutstanding)
            .plus(this.totalFeeChargesOutstanding)
            .plus(this.totalPenaltyChargesOutstanding);
    this.totalOutstanding = totalOutstanding.getAmount();
  }