public LoanInstallmentCharge getInstallmentLoanCharge(final LocalDate periodDueDate) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { if (periodDueDate.isEqual(loanChargePerInstallment.getRepaymentInstallment().getDueDate())) { return loanChargePerInstallment; } } return null; }
public void resetPaidAmount(final MonetaryCurrency currency) { this.amountPaid = BigDecimal.ZERO; this.amountOutstanding = calculateAmountOutstanding(currency); this.paid = false; for (final LoanInstallmentCharge installmentCharge : this.loanInstallmentCharge) { installmentCharge.resetPaidAmount(currency); } }
public LoanInstallmentCharge getInstallmentLoanCharge(final Integer installmentNumber) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { if (installmentNumber.equals( loanChargePerInstallment.getRepaymentInstallment().getInstallmentNumber().intValue())) { return loanChargePerInstallment; } } return null; }
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++]); } } } } }
public void resetToOriginal(final MonetaryCurrency currency) { this.amountPaid = BigDecimal.ZERO; this.amountWaived = BigDecimal.ZERO; this.amountWrittenOff = BigDecimal.ZERO; this.amountOutstanding = calculateAmountOutstanding(currency); this.paid = false; this.waived = false; for (final LoanInstallmentCharge installmentCharge : this.loanInstallmentCharge) { installmentCharge.resetToOriginal(currency); } }
public LoanRepaymentScheduleInstallment fetchRepaymentInstallment(final Money trasferedAmount) { for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { if (loanChargePerInstallment.isPending() && trasferedAmount .getAmount() .equals( loanChargePerInstallment .getAmountThroughChargePayment(trasferedAmount.getCurrency()) .getAmount())) { return loanChargePerInstallment.getRepaymentInstallment(); } } return null; }
public LoanInstallmentCharge getUnpaidInstallmentLoanCharge() { LoanInstallmentCharge unpaidChargePerInstallment = null; for (final LoanInstallmentCharge loanChargePerInstallment : this.loanInstallmentCharge) { if (loanChargePerInstallment.isPending() && (unpaidChargePerInstallment == null || unpaidChargePerInstallment .getRepaymentInstallment() .getDueDate() .isAfter(loanChargePerInstallment.getRepaymentInstallment().getDueDate()))) { unpaidChargePerInstallment = loanChargePerInstallment; } } return unpaidChargePerInstallment; }
public Money waive(final MonetaryCurrency currency, final Integer loanInstallmentNumber) { if (isInstalmentFee()) { final LoanInstallmentCharge chargePerInstallment = getInstallmentLoanCharge(loanInstallmentNumber); final Money amountWaived = chargePerInstallment.waive(currency); if (this.amountWaived == null) { this.amountWaived = BigDecimal.ZERO; } this.amountWaived = this.amountWaived.add(amountWaived.getAmount()); this.amountOutstanding = this.amountOutstanding.subtract(amountWaived.getAmount()); if (determineIfFullyPaid()) { this.paid = false; this.waived = true; } return amountWaived; } this.amountWaived = this.amountOutstanding; this.amountOutstanding = BigDecimal.ZERO; this.paid = false; this.waived = true; return getAmountWaived(currency); }
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; }
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++]); } } } }