Exemplo n.º 1
0
  public void update(
      final BigDecimal amount,
      final LocalDate dueDate,
      final BigDecimal loanPrincipal,
      Integer numberOfRepayments,
      BigDecimal loanCharge) {
    if (dueDate != null) {
      this.dueDate = dueDate.toDate();
    }

    if (amount != null) {
      switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
          break;
        case FLAT:
          if (isInstalmentFee()) {
            if (numberOfRepayments == null) {
              numberOfRepayments = this.loan.repaymentScheduleDetail().getNumberOfRepayments();
            }
            this.amount = amount.multiply(BigDecimal.valueOf(numberOfRepayments));
          } else {
            this.amount = amount;
          }
          break;
        case PERCENT_OF_AMOUNT:
        case PERCENT_OF_AMOUNT_AND_INTEREST:
        case PERCENT_OF_INTEREST:
          this.percentage = amount;
          this.amountPercentageAppliedTo = loanPrincipal;
          if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
            loanCharge = percentageOf(this.amountPercentageAppliedTo);
          }
          this.amount = minimumAndMaximumCap(loanCharge);
          break;
      }
      this.amountOrPercentage = amount;
      this.amountOutstanding = calculateOutstanding();
      if (this.loan != null && isInstalmentFee()) {
        final Set<LoanInstallmentCharge> chargePerInstallments =
            this.loan.generateInstallmentLoanCharges(this);
        if (this.loanInstallmentCharge.isEmpty()) {
          this.loanInstallmentCharge.addAll(chargePerInstallments);
        } else {
          int index = 0;
          final LoanInstallmentCharge[] loanChargePerInstallments =
              new LoanInstallmentCharge[chargePerInstallments.size()];
          final LoanInstallmentCharge[] loanChargePerInstallmentArray =
              chargePerInstallments.toArray(loanChargePerInstallments);
          for (final LoanInstallmentCharge chargePerInstallment : this.loanInstallmentCharge) {
            chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  public Map<String, Object> update(final JsonCommand command, final BigDecimal amount) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(7);

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();

    final String dueDateParamName = "dueDate";
    if (command.isChangeInLocalDateParameterNamed(dueDateParamName, getDueLocalDate())) {
      final String valueAsInput = command.stringValueOfParameterNamed(dueDateParamName);
      actualChanges.put(dueDateParamName, valueAsInput);
      actualChanges.put("dateFormat", dateFormatAsInput);
      actualChanges.put("locale", localeAsInput);

      final LocalDate newValue = command.localDateValueOfParameterNamed(dueDateParamName);
      this.dueDate = newValue.toDate();
    }

    final String amountParamName = "amount";
    if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) {
      final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName);
      actualChanges.put(amountParamName, newValue);
      actualChanges.put("locale", localeAsInput);
      switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
          break;
        case FLAT:
          if (isInstalmentFee()) {
            this.amount =
                newValue.multiply(
                    BigDecimal.valueOf(
                        this.loan.repaymentScheduleDetail().getNumberOfRepayments()));
          } else {
            this.amount = newValue;
          }
          this.amountOutstanding = calculateOutstanding();
          break;
        case PERCENT_OF_AMOUNT:
        case PERCENT_OF_AMOUNT_AND_INTEREST:
        case PERCENT_OF_INTEREST:
          this.percentage = newValue;
          this.amountPercentageAppliedTo = amount;
          BigDecimal loanCharge = BigDecimal.ZERO;
          if (isInstalmentFee()) {
            loanCharge =
                this.loan.calculatePerInstallmentChargeAmount(
                    ChargeCalculationType.fromInt(this.chargeCalculation), this.percentage);
          }
          if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
            loanCharge = percentageOf(this.amountPercentageAppliedTo);
          }
          this.amount = minimumAndMaximumCap(loanCharge);
          this.amountOutstanding = calculateOutstanding();
          break;
      }
      this.amountOrPercentage = newValue;
      if (isInstalmentFee()) {
        final Set<LoanInstallmentCharge> chargePerInstallments =
            this.loan.generateInstallmentLoanCharges(this);
        if (this.loanInstallmentCharge.isEmpty()) {
          this.loanInstallmentCharge.addAll(chargePerInstallments);
        } else {
          int index = 0;
          final LoanInstallmentCharge[] loanChargePerInstallments =
              new LoanInstallmentCharge[chargePerInstallments.size()];
          final LoanInstallmentCharge[] loanChargePerInstallmentArray =
              chargePerInstallments.toArray(loanChargePerInstallments);
          for (final LoanInstallmentCharge chargePerInstallment : this.loanInstallmentCharge) {
            chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
          }
        }
      }
    }
    return actualChanges;
  }
Exemplo n.º 3
0
  private void populateDerivedFields(
      final BigDecimal amountPercentageAppliedTo,
      final BigDecimal chargeAmount,
      Integer numberOfRepayments,
      BigDecimal loanCharge) {

    switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
      case INVALID:
        this.percentage = null;
        this.amount = null;
        this.amountPercentageAppliedTo = null;
        this.amountPaid = null;
        this.amountOutstanding = BigDecimal.ZERO;
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
      case FLAT:
        this.percentage = null;
        this.amountPercentageAppliedTo = null;
        this.amountPaid = null;
        if (isInstalmentFee()) {
          if (numberOfRepayments == null) {
            numberOfRepayments = this.loan.repaymentScheduleDetail().getNumberOfRepayments();
          }
          this.amount = chargeAmount.multiply(BigDecimal.valueOf(numberOfRepayments));
        } else {
          this.amount = chargeAmount;
        }
        this.amountOutstanding = this.amount;
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
      case PERCENT_OF_AMOUNT:
      case PERCENT_OF_AMOUNT_AND_INTEREST:
      case PERCENT_OF_INTEREST:
        this.percentage = chargeAmount;
        this.amountPercentageAppliedTo = amountPercentageAppliedTo;
        if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
          loanCharge = percentageOf(this.amountPercentageAppliedTo);
        }
        this.amount = minimumAndMaximumCap(loanCharge);
        this.amountPaid = null;
        this.amountOutstanding = calculateOutstanding();
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
    }
    this.amountOrPercentage = chargeAmount;
    if (this.loan != null && isInstalmentFee()) {
      final Set<LoanInstallmentCharge> chargePerInstallments =
          this.loan.generateInstallmentLoanCharges(this);
      if (this.loanInstallmentCharge.isEmpty()) {
        this.loanInstallmentCharge.addAll(chargePerInstallments);
      } else {
        int index = 0;
        final LoanInstallmentCharge[] loanChargePerInstallments =
            new LoanInstallmentCharge[chargePerInstallments.size()];
        final LoanInstallmentCharge[] loanChargePerInstallmentArray =
            chargePerInstallments.toArray(loanChargePerInstallments);
        for (final LoanInstallmentCharge chargePerInstallment : this.loanInstallmentCharge) {
          chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
        }
      }
    }
  }