use of org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest in project head by mifos.
the class IndividualLoanScheduleFactory method createUnroundedLoanSchedulesFromInstallments.
private List<LoanScheduleEntity> createUnroundedLoanSchedulesFromInstallments(List<InstallmentDate> installmentDates, Money loanInterest, Money loanAmount, ScheduledEvent meetingScheduledEvent, List<InstallmentPrincipalAndInterest> principalWithInterestInstallments, List<AccountFeesEntity> accountFees, CustomerBO customer) {
List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
List<AccountFeesEntity> accountFeesWithNoTimeOfDibursementFees = new ArrayList<AccountFeesEntity>();
List<FeeInstallment> feeInstallments = new ArrayList<FeeInstallment>();
if (!accountFees.isEmpty()) {
InstallmentFeeCalculatorFactory installmentFeeCalculatorFactory = new InstallmentFeeCalculatorFactoryImpl();
for (AccountFeesEntity accountFeesEntity : accountFees) {
RateAmountFlag feeType = accountFeesEntity.getFees().getFeeType();
InstallmentFeeCalculator installmentFeeCalculator = installmentFeeCalculatorFactory.create(this.feeDao, feeType);
Double feeAmountOrRate = accountFeesEntity.getFeeAmount();
Money accountFeeAmount = installmentFeeCalculator.calculate(feeAmountOrRate, loanAmount, loanInterest, accountFeesEntity.getFees());
accountFeesEntity.setAccountFeeAmount(accountFeeAmount);
if (!accountFeesEntity.isTimeOfDisbursement()) {
accountFeesWithNoTimeOfDibursementFees.add(accountFeesEntity);
}
}
feeInstallments = FeeInstallment.createMergedFeeInstallments(meetingScheduledEvent, accountFeesWithNoTimeOfDibursementFees, installmentDates.size());
}
int installmentIndex = 0;
for (InstallmentDate installmentDate1 : installmentDates) {
InstallmentPrincipalAndInterest em = principalWithInterestInstallments.get(installmentIndex);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(null, customer, installmentDate1.getInstallmentId(), new java.sql.Date(installmentDate1.getInstallmentDueDate().getTime()), PaymentStatus.UNPAID, em.getPrincipal(), em.getInterest());
for (FeeInstallment feeInstallment : feeInstallments) {
if (feeInstallment.getInstallmentId().equals(installmentDate1.getInstallmentId())) {
LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
}
}
unroundedLoanSchedules.add(loanScheduleEntity);
installmentIndex++;
}
return unroundedLoanSchedules;
}
use of org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest in project head by mifos.
the class FlatLoanPrincipalWithInterestGenerator method generateFlatInstallmentsNoGrace_v2.
/**
* Divide principal and interest evenly among all installments, no grace period
*/
private List<InstallmentPrincipalAndInterest> generateFlatInstallmentsNoGrace_v2(Money principalPerInstallment, Money interestPerInstallment, Integer numberOfInstallments) {
List<InstallmentPrincipalAndInterest> emiInstallments = new ArrayList<InstallmentPrincipalAndInterest>();
for (int i = 0; i < numberOfInstallments; i++) {
InstallmentPrincipalAndInterest installment = new InstallmentPrincipalAndInterest(principalPerInstallment, interestPerInstallment);
emiInstallments.add(installment);
}
return emiInstallments;
}
use of org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest in project head by mifos.
the class FlatLoanPrincipalWithInterestGenerator method allFlatInstallments_v2.
/**
* Generate flat-interest installment variants based on the type of grace period.
* <ul>
* <li>If grace period is none, or applies to both principal and interest, the loan calculations are the same.
* <li>If grace period is for principal only, don't add new installments. The first grace installments are
* interest-only, and principal is paid off with the remaining installments. NOTE: Principal-only grace period
* should be disable for release 1.1.
* </ul>
*/
private List<InstallmentPrincipalAndInterest> allFlatInstallments_v2(final Money loanInterest, GraceType graceType, Money loanAmount, Integer numberOfInstallments, Integer gracePeriodDuration) {
List<InstallmentPrincipalAndInterest> emiInstallments = new ArrayList<InstallmentPrincipalAndInterest>();
Money principalPerInstallment = loanAmount.divide(numberOfInstallments);
Money interestPerInstallment = loanInterest.divide(numberOfInstallments);
if (graceType == GraceType.NONE || graceType == GraceType.GRACEONALLREPAYMENTS) {
emiInstallments = generateFlatInstallmentsNoGrace_v2(principalPerInstallment, interestPerInstallment, numberOfInstallments);
} else {
// getGraceType() == GraceType.PRINCIPALONLYGRACE which is disabled.
emiInstallments = generateFlatInstallmentsInterestOnly_v2(loanInterest, numberOfInstallments, gracePeriodDuration);
emiInstallments.addAll(generateFlatInstallmentsAfterInterestOnlyGraceInstallments_v2(loanInterest, loanAmount, numberOfInstallments, gracePeriodDuration));
}
return emiInstallments;
}
use of org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest in project head by mifos.
the class FlatLoanPrincipalWithInterestGenerator method generateFlatInstallmentsInterestOnly_v2.
/**
* Generate interest-only payments for the duration of the grace period. Interest is divided evenly among all
* installments, but only interest is paid during the grace period.
*/
private List<InstallmentPrincipalAndInterest> generateFlatInstallmentsInterestOnly_v2(final Money loanInterest, Integer numberOfInstallments, Integer gracePeriodDuration) {
List<InstallmentPrincipalAndInterest> emiInstallments = new ArrayList<InstallmentPrincipalAndInterest>();
Money zeroPrincipal = MoneyUtils.zero(loanInterest.getCurrency());
Money interestPerInstallment = loanInterest.divide(numberOfInstallments);
for (int i = 0; i < gracePeriodDuration; i++) {
InstallmentPrincipalAndInterest installment = new InstallmentPrincipalAndInterest(zeroPrincipal, interestPerInstallment);
emiInstallments.add(installment);
}
return emiInstallments;
}
use of org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest in project head by mifos.
the class FlatVariableInstallmentPrincipalWithInterestGenerator method generateEqualInstallments.
@Override
public List<InstallmentPrincipalAndInterest> generateEqualInstallments(LoanInterestCalculationDetails loanInterestCalculationDetails) {
List<InstallmentPrincipalAndInterest> principalAndInterestDetails = new ArrayList<InstallmentPrincipalAndInterest>();
Double interestRate = loanInterestCalculationDetails.getInterestRate();
Money loanAmount = loanInterestCalculationDetails.getLoanAmount();
LocalDate interestPeriodStartDate = loanInterestCalculationDetails.getDisbursementDate();
Money totalPrincipal = new Money(loanAmount.getCurrency(), Double.valueOf("0"));
if (loanInterestCalculationDetails.getTotalInstallmentAmounts().isEmpty()) {
// if empty just divide loan amount by number of installments to get principal due per installment
Money installmentPrincipalDue = loanAmount.divide(loanInterestCalculationDetails.getNumberOfInstallments());
int index = 0;
for (DateTime installmentDueDate : loanInterestCalculationDetails.getLoanScheduleDates()) {
Money interestForInstallment = formula.calculate(loanAmount, interestRate, interestPeriodStartDate, new LocalDate(installmentDueDate));
interestPeriodStartDate = new LocalDate(installmentDueDate);
totalPrincipal = totalPrincipal.add(installmentPrincipalDue);
if (index == loanInterestCalculationDetails.getLoanScheduleDates().size() - 1) {
// last installment
Money realTotalPrincipal = new Money(totalPrincipal.getCurrency(), totalPrincipal.toString());
if (realTotalPrincipal.isLessThan(loanInterestCalculationDetails.getLoanAmount())) {
Money difference = loanInterestCalculationDetails.getLoanAmount().subtract(realTotalPrincipal);
installmentPrincipalDue = installmentPrincipalDue.add(difference);
} else if (realTotalPrincipal.isGreaterThan(loanInterestCalculationDetails.getLoanAmount())) {
Money difference = realTotalPrincipal.subtract(loanInterestCalculationDetails.getLoanAmount());
installmentPrincipalDue = installmentPrincipalDue.subtract(difference);
}
}
principalAndInterestDetails.add(new InstallmentPrincipalAndInterest(installmentPrincipalDue, interestForInstallment));
index++;
}
} else {
int index = 0;
List<Money> totalInstallmentAmounts = loanInterestCalculationDetails.getTotalInstallmentAmounts();
for (DateTime installmentDueDate : loanInterestCalculationDetails.getLoanScheduleDates()) {
Money totalInstallmentPayment = totalInstallmentAmounts.get(index);
Money interestForInstallment = formula.calculate(loanAmount, interestRate, interestPeriodStartDate, new LocalDate(installmentDueDate));
interestPeriodStartDate = new LocalDate(installmentDueDate);
Money installmentPrincipalDue = totalInstallmentPayment.subtract(interestForInstallment);
totalPrincipal = totalPrincipal.add(installmentPrincipalDue);
if (index == loanInterestCalculationDetails.getLoanScheduleDates().size() - 1) {
// last installment
Money realTotalPrincipal = new Money(totalPrincipal.getCurrency(), totalPrincipal.toString());
if (realTotalPrincipal.isLessThan(loanInterestCalculationDetails.getLoanAmount())) {
Money difference = loanInterestCalculationDetails.getLoanAmount().subtract(realTotalPrincipal);
installmentPrincipalDue = installmentPrincipalDue.add(difference);
} else if (realTotalPrincipal.isGreaterThan(loanInterestCalculationDetails.getLoanAmount())) {
Money difference = realTotalPrincipal.subtract(loanInterestCalculationDetails.getLoanAmount());
installmentPrincipalDue = installmentPrincipalDue.subtract(difference);
}
}
principalAndInterestDetails.add(new InstallmentPrincipalAndInterest(installmentPrincipalDue, interestForInstallment));
index++;
}
}
return principalAndInterestDetails;
}
Aggregations