use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class LoanSchedule method modifyPrincipalAmounts.
public void modifyPrincipalAmounts(List<Number> installmentTotalAmounts) {
int index = 0;
for (LoanScheduleEntity scheduleEntity : this.roundedLoanSchedules) {
Money newTotalAmount = new Money(scheduleEntity.getCurrency(), installmentTotalAmounts.get(index).doubleValue());
Money feesAndInterest = scheduleEntity.getTotalDueWithoutPrincipal();
Money newPrincipalForInstallment = newTotalAmount.subtract(feesAndInterest);
scheduleEntity.setPrincipal(newPrincipalForInstallment);
index++;
}
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class DefaultLoanScheduleRounderHelper method calculateInitialTotals_v2.
@Override
public RepaymentTotals calculateInitialTotals_v2(List<LoanScheduleEntity> unroundedLoanSchedules, Money loanAmount, List<LoanScheduleEntity> allInstallments) {
RepaymentTotals totals = new RepaymentTotals(loanAmount.getCurrency());
Money exactTotalInterestDue = new Money(loanAmount.getCurrency(), "0");
Money exactTotalAccountFeesDue = new Money(loanAmount.getCurrency(), "0");
Money exactTotalMiscFeesDue = new Money(loanAmount.getCurrency(), "0");
Money exactTotalMiscPenaltiesDue = new Money(loanAmount.getCurrency(), "0");
// principal due = loan amount less any payments on principal
Money exactTotalPrincipalDue = loanAmount;
for (AccountActionDateEntity e : allInstallments) {
LoanScheduleEntity installment = (LoanScheduleEntity) e;
exactTotalPrincipalDue = exactTotalPrincipalDue.subtract(installment.getPrincipalPaid());
}
for (Object element : unroundedLoanSchedules) {
LoanScheduleEntity currentInstallment = (LoanScheduleEntity) element;
exactTotalInterestDue = exactTotalInterestDue.add(currentInstallment.getInterestDue());
exactTotalAccountFeesDue = exactTotalAccountFeesDue.add(currentInstallment.getTotalFeesDue());
exactTotalMiscFeesDue = exactTotalMiscFeesDue.add(currentInstallment.getMiscFeeDue());
exactTotalMiscPenaltiesDue = exactTotalMiscPenaltiesDue.add(currentInstallment.getMiscPenaltyDue());
}
Money exactTotalPaymentsDue = exactTotalInterestDue.add(exactTotalAccountFeesDue).add(exactTotalMiscFeesDue).add(exactTotalMiscPenaltiesDue).add(exactTotalPrincipalDue);
totals.setRoundedPaymentsDue(MoneyUtils.finalRound(exactTotalPaymentsDue));
totals.setRoundedAccountFeesDue(MoneyUtils.currencyRound(exactTotalAccountFeesDue));
totals.setRoundedMiscFeesDue(MoneyUtils.currencyRound(exactTotalMiscFeesDue));
totals.setRoundedMiscPenaltiesDue(MoneyUtils.currencyRound(exactTotalMiscPenaltiesDue));
totals.setRoundedPrincipalDue(exactTotalPrincipalDue);
// Adjust interest to account for rounding discrepancies
totals.setRoundedInterestDue(totals.getRoundedPaymentsDue().subtract(totals.getRoundedAccountFeesDue()).subtract(totals.getRoundedMiscFeesDue()).subtract(totals.getRoundedPenaltiesDue()).subtract(totals.getRoundedMiscPenaltiesDue()).subtract(totals.getRoundedPrincipalDue()));
return totals;
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class FirstInstallmentRoudingDifferenceLoanScheduleRounder method roundNonGracePeriodInstallments.
private void roundNonGracePeriodInstallments(Integer gracePeriodInstallmentsCount, List<LoanScheduleEntity> unroundedLoanSchedules, List<LoanScheduleEntity> roundedLoanSchedules, RepaymentTotals totals) {
int installmentNum;
for (installmentNum = unroundedLoanSchedules.size() - 1; installmentNum >= gracePeriodInstallmentsCount; installmentNum--) {
LoanScheduleEntity currentInstallment = unroundedLoanSchedules.get(installmentNum);
LoanScheduleEntity roundedInstallment = currentInstallment;
if (installmentNum != gracePeriodInstallmentsCount) {
loanScheduleInstallmentRounder.roundAndAdjustButLastNonGraceInstallment_v2(roundedInstallment);
loanScheduleInstallmentRounder.updateRunningTotals_v2(totals, roundedInstallment);
} else {
loanScheduleInstallmentRounder.roundAndAdjustLastInstallment_v2(roundedInstallment, totals);
}
roundedLoanSchedules.add(roundedInstallment);
}
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class VariableInstallmentLoanScheduleRounder method round.
@Override
public List<LoanScheduleEntity> round(GraceType graceType, Short gracePeriodDuration, Money loanAmount, InterestType interestType, List<LoanScheduleEntity> unroundedLoanSchedules, List<LoanScheduleEntity> allExistingLoanSchedules) {
// for variable installments - want to round all installments total amount values except for the last installment.
Money totalDue = new Money(loanAmount.getCurrency(), Double.valueOf("0"));
for (LoanScheduleEntity loanScheduleEntity : unroundedLoanSchedules) {
totalDue = totalDue.add(loanScheduleEntity.getPrincipalDue()).add(loanScheduleEntity.getInterestDue()).add(loanScheduleEntity.getTotalFeesDue());
}
BigDecimal installmentAmount = totalDue.getAmount().divide(BigDecimal.valueOf(Integer.valueOf(unroundedLoanSchedules.size())), RoundingMode.HALF_UP);
long roundedValue = Math.round(installmentAmount.doubleValue());
Money totalInstallmentMonetaryAmount = new Money(loanAmount.getCurrency(), BigDecimal.valueOf(roundedValue));
Money totalPrincipalToDate = new Money(loanAmount.getCurrency(), BigDecimal.ZERO);
int index = 0;
for (LoanScheduleEntity loanScheduleEntity : unroundedLoanSchedules) {
if (index == unroundedLoanSchedules.size() - 1) {
// last installment
loanScheduleEntity.setPrincipal(loanAmount.subtract(totalPrincipalToDate));
} else {
Money principal = totalInstallmentMonetaryAmount.subtract(loanScheduleEntity.getInterest());
loanScheduleEntity.setPrincipal(principal);
totalPrincipalToDate = totalPrincipalToDate.add(principal);
}
index++;
}
return unroundedLoanSchedules;
}
Aggregations