Example #1
0
  /**
   * @param feeAmount TODO
   * @param processAmount Amount used to pay off this charge
   * @return Actual amount paid on this charge
   */
  public Money updatePaidAmountBy(
      final Money incrementBy, final Integer installmentNumber, final Money feeAmount) {
    Money processAmount = Money.zero(incrementBy.getCurrency());
    if (isInstalmentFee()) {
      if (installmentNumber == null) {
        processAmount = getUnpaidInstallmentLoanCharge().updatePaidAmountBy(incrementBy, feeAmount);
      } else {
        processAmount =
            getInstallmentLoanCharge(installmentNumber).updatePaidAmountBy(incrementBy, feeAmount);
      }
    } else {
      processAmount = incrementBy;
    }
    Money amountPaidToDate = Money.of(processAmount.getCurrency(), this.amountPaid);
    final Money amountOutstanding = Money.of(processAmount.getCurrency(), this.amountOutstanding);

    Money amountPaidOnThisCharge = Money.zero(processAmount.getCurrency());
    if (processAmount.isGreaterThanOrEqualTo(amountOutstanding)) {
      amountPaidOnThisCharge = amountOutstanding;
      amountPaidToDate = amountPaidToDate.plus(amountOutstanding);
      this.amountPaid = amountPaidToDate.getAmount();
      this.amountOutstanding = BigDecimal.ZERO;
      this.paid = true;

    } else {
      amountPaidOnThisCharge = processAmount;
      amountPaidToDate = amountPaidToDate.plus(processAmount);
      this.amountPaid = amountPaidToDate.getAmount();
      this.amountOutstanding = calculateAmountOutstanding(incrementBy.getCurrency());
    }
    return amountPaidOnThisCharge;
  }
  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);
  }
Example #3
0
 public Money calculateTotalInterestWrittenOff(
     final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
     final MonetaryCurrency currency) {
   Money total = Money.zero(currency);
   for (LoanRepaymentScheduleInstallment installment : repaymentScheduleInstallments) {
     total = total.plus(installment.getInterestWrittenOff(currency));
   }
   return total;
 }
Example #4
0
 public Money calculateTotalPrincipalRepaid(
     final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
     final MonetaryCurrency currency) {
   Money total = Money.zero(currency);
   for (LoanRepaymentScheduleInstallment installment : repaymentScheduleInstallments) {
     total = total.plus(installment.getPrincipalCompleted(currency));
   }
   return total;
 }
Example #5
0
 public Money calculateTotalPenaltyChargesWaived(
     final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
     final MonetaryCurrency currency) {
   Money total = Money.zero(currency);
   for (LoanRepaymentScheduleInstallment installment : repaymentScheduleInstallments) {
     total = total.plus(installment.getPenaltyChargesWaived(currency));
   }
   return total;
 }
  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);
  }
Example #7
0
 public Money calculateTotalInterestOverdueOn(
     final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
     final MonetaryCurrency currency,
     final LocalDate overdueAsOf) {
   Money total = Money.zero(currency);
   for (LoanRepaymentScheduleInstallment installment : repaymentScheduleInstallments) {
     if (installment.isOverdueOn(overdueAsOf)) {
       total = total.plus(installment.getInterestOutstanding(currency));
     }
   }
   return total;
 }
Example #8
0
  public Money calculateTotalOverdueOn(
      final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
      final MonetaryCurrency currency,
      final LocalDate overdueAsOf) {

    final Money principalOverdue =
        calculateTotalPrincipalOverdueOn(repaymentScheduleInstallments, currency, overdueAsOf);
    final Money interestOverdue =
        calculateTotalInterestOverdueOn(repaymentScheduleInstallments, currency, overdueAsOf);
    final Money feeChargesOverdue =
        calculateTotalFeeChargesOverdueOn(repaymentScheduleInstallments, currency, overdueAsOf);
    final Money penaltyChargesOverdue =
        calculateTotalPenaltyChargesOverdueOn(repaymentScheduleInstallments, currency, overdueAsOf);

    return principalOverdue
        .plus(interestOverdue)
        .plus(feeChargesOverdue)
        .plus(penaltyChargesOverdue);
  }
  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);
  }
Example #10
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();
  }