Exemple #1
0
  public LoanCharge(
      final Loan loan,
      final Charge chargeDefinition,
      final BigDecimal loanPrincipal,
      final BigDecimal amount,
      final ChargeTimeType chargeTime,
      final ChargeCalculationType chargeCalculation,
      final LocalDate dueDate,
      final ChargePaymentMode chargePaymentMode,
      final Integer numberOfRepayments,
      final BigDecimal loanCharge) {
    this.loan = loan;
    this.charge = chargeDefinition;
    this.penaltyCharge = chargeDefinition.isPenalty();
    this.minCap = chargeDefinition.getMinCap();
    this.maxCap = chargeDefinition.getMaxCap();

    this.chargeTime = chargeDefinition.getChargeTime();
    if (chargeTime != null) {
      this.chargeTime = chargeTime.getValue();
    }

    if (ChargeTimeType.fromInt(this.chargeTime).equals(ChargeTimeType.SPECIFIED_DUE_DATE)
        || ChargeTimeType.fromInt(this.chargeTime).equals(ChargeTimeType.OVERDUE_INSTALLMENT)) {

      if (dueDate == null) {
        final String defaultUserMessage = "Loan charge is missing due date.";
        throw new LoanChargeWithoutMandatoryFieldException(
            "loanCharge",
            "dueDate",
            defaultUserMessage,
            chargeDefinition.getId(),
            chargeDefinition.getName());
      }

      this.dueDate = dueDate.toDate();
    } else {
      this.dueDate = null;
    }

    this.chargeCalculation = chargeDefinition.getChargeCalculation();
    if (chargeCalculation != null) {
      this.chargeCalculation = chargeCalculation.getValue();
    }

    BigDecimal chargeAmount = chargeDefinition.getAmount();
    if (amount != null) {
      chargeAmount = amount;
    }

    this.chargePaymentMode = chargeDefinition.getChargePaymentMode();
    if (chargePaymentMode != null) {
      this.chargePaymentMode = chargePaymentMode.getValue();
    }
    populateDerivedFields(loanPrincipal, chargeAmount, numberOfRepayments, loanCharge);
    this.paid = determineIfFullyPaid();
  }
Exemple #2
0
 public ChargePaymentMode getChargePaymentMode() {
   return ChargePaymentMode.fromInt(this.chargePaymentMode);
 }