WIP on support loan charges on loan schedule.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package org.mifosng.platform.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Immutable data object to represent aspects of a loan schedule such as:
|
||||
*
|
||||
* <ul>
|
||||
* <li>summary information - the totals for each part of schedule monitored</li>
|
||||
* <li>repayment schedule - the principal due, outstanding balance and cost of loan items such as interest and charges</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class NewLoanScheduleData {
|
||||
|
||||
/**
|
||||
* The cumulative total of all money (principal) disbursed to the loan applicant.
|
||||
*/
|
||||
private final BigDecimal principalDisbursed;
|
||||
private final BigDecimal principalPaid;
|
||||
private final BigDecimal principalOutstanding;
|
||||
|
||||
/**
|
||||
* The total interest expected on any principal disbursed.
|
||||
*/
|
||||
private final BigDecimal interestExpected;
|
||||
private final BigDecimal interestPaid;
|
||||
private final BigDecimal interestWaived;
|
||||
private final BigDecimal interestOutstanding;
|
||||
|
||||
/**
|
||||
* The cumulative total of all charges applied on the loan to date.
|
||||
*/
|
||||
private final BigDecimal chargesToDate;
|
||||
private final BigDecimal chargesPaid;
|
||||
private final BigDecimal chargesOutstanding;
|
||||
|
||||
/**
|
||||
* The cumulative total of all costs on the loan.
|
||||
* Costs tracked are:
|
||||
* <ul>
|
||||
* <li>Interest</li>
|
||||
* <li>Charges (fees and penalties)</li>
|
||||
* </ul>
|
||||
*/
|
||||
private final BigDecimal totalCostOfLoan;
|
||||
|
||||
/**
|
||||
* The sum of <code>principalDisbursed</code> and <code>totalCostOfLoan</code>.
|
||||
*/
|
||||
private final BigDecimal totalExpectedRepayment;
|
||||
private final BigDecimal totalInArrears;
|
||||
|
||||
public NewLoanScheduleData() {
|
||||
this.principalDisbursed = null;
|
||||
this.principalPaid = null;
|
||||
this.principalOutstanding = null;
|
||||
|
||||
this.interestExpected = null;
|
||||
this.interestPaid = null;
|
||||
this.interestWaived = null;
|
||||
this.interestOutstanding = null;
|
||||
|
||||
this.chargesToDate = null;
|
||||
this.chargesPaid = null;
|
||||
this.chargesOutstanding = null;
|
||||
|
||||
this.totalCostOfLoan = null;
|
||||
|
||||
this.totalExpectedRepayment = null;
|
||||
this.totalInArrears = null;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
/**
|
||||
* Immutable data object that represents a period of a loan schedule.
|
||||
*/
|
||||
public class LoanSchedulePeriodData {
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package org.mifosng.platform.loan.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.exceptions.LoanProductNotFoundException;
|
||||
import org.mifosng.platform.loan.domain.AmortizationMethod;
|
||||
import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod;
|
||||
import org.mifosng.platform.loan.domain.InterestMethod;
|
||||
import org.mifosng.platform.loan.domain.LoanProduct;
|
||||
import org.mifosng.platform.loan.domain.LoanProductRelatedDetail;
|
||||
import org.mifosng.platform.loan.domain.LoanProductRepository;
|
||||
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
|
||||
import org.mifosng.platform.loanschedule.domain.AprCalculator;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class LoanProductRelatedDetailAssembler {
|
||||
|
||||
private final LoanProductRepository loanProductRepository;
|
||||
private final AprCalculator aprCalculator;
|
||||
|
||||
public LoanProductRelatedDetailAssembler(
|
||||
final LoanProductRepository loanProductRepository,
|
||||
final AprCalculator aprCalculator) {
|
||||
this.loanProductRepository = loanProductRepository;
|
||||
this.aprCalculator = aprCalculator;
|
||||
}
|
||||
|
||||
public LoanProductRelatedDetail assembleFrom(final CalculateLoanScheduleCommand command) {
|
||||
|
||||
final BigDecimal principalAmount = command.getPrincipal();
|
||||
final BigDecimal defaultNominalInterestRatePerPeriod = command.getInterestRatePerPeriod();
|
||||
final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyType());
|
||||
final InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestType());
|
||||
final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodType());
|
||||
|
||||
final Integer defaultNumberOfInstallments = command.getNumberOfRepayments();
|
||||
final Integer repayEvery = command.getRepaymentEvery();
|
||||
final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequencyType());
|
||||
|
||||
final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationType());
|
||||
|
||||
final BigDecimal defaultAnnualNominalInterestRate = this.aprCalculator.calculateFrom(interestPeriodFrequencyType, defaultNominalInterestRatePerPeriod);
|
||||
|
||||
final LoanProduct loanProduct = this.loanProductRepository.findOne(command.getProductId());
|
||||
if (loanProduct == null) {
|
||||
throw new LoanProductNotFoundException(command.getProductId());
|
||||
}
|
||||
|
||||
final MonetaryCurrency currency = loanProduct.getCurrency();
|
||||
|
||||
// in arrerars tolerance isnt relevant when auto-calculating a loan schedule
|
||||
final BigDecimal inArrearsTolerance = BigDecimal.ZERO;
|
||||
|
||||
return new LoanProductRelatedDetail(currency, principalAmount,
|
||||
defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate,
|
||||
interestMethod, interestCalculationPeriodMethod,
|
||||
repayEvery, repaymentFrequencyType, defaultNumberOfInstallments, amortizationMethod,
|
||||
inArrearsTolerance);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user