Search in sources :

Example 1 with RepaymentTotals

use of org.mifos.accounts.loan.business.RepaymentTotals in project head by mifos.

the class FirstInstallmentRoudingDifferenceLoanScheduleRounder method round.

@Override
public List<LoanScheduleEntity> round(GraceType graceType, Short gracePeriodDuration, Money loanAmount, InterestType interestType, List<LoanScheduleEntity> unroundedLoanSchedules, List<LoanScheduleEntity> allExistingLoanSchedules) {
    if (!interestType.equals(InterestType.FLAT)) {
        return super.round(graceType, gracePeriodDuration, loanAmount, interestType, unroundedLoanSchedules, allExistingLoanSchedules);
    }
    Collections.sort(unroundedLoanSchedules);
    List<LoanScheduleEntity> roundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
    RepaymentTotals totals = loanScheduleInstallmentRounder.calculateInitialTotals_v2(unroundedLoanSchedules, loanAmount, allExistingLoanSchedules);
    Integer gracePeriodInstallmentsCount = countGracePeriodInstallments(unroundedLoanSchedules, graceType, gracePeriodDuration);
    roundGracePeriodInstallments(gracePeriodInstallmentsCount, graceType, gracePeriodDuration, unroundedLoanSchedules, roundedLoanSchedules, totals);
    roundNonGracePeriodInstallments(gracePeriodInstallmentsCount, unroundedLoanSchedules, roundedLoanSchedules, totals);
    Collections.sort(roundedLoanSchedules);
    return roundedLoanSchedules;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) RepaymentTotals(org.mifos.accounts.loan.business.RepaymentTotals) ArrayList(java.util.ArrayList)

Example 2 with RepaymentTotals

use of org.mifos.accounts.loan.business.RepaymentTotals in project head by mifos.

the class DefaultLoanScheduleRounder method round.

@Override
public List<LoanScheduleEntity> round(GraceType graceType, Short gracePeriodDuration, Money loanAmount, InterestType interestType, List<LoanScheduleEntity> unroundedLoanSchedules, List<LoanScheduleEntity> allExistingLoanSchedules) {
    Collections.sort(unroundedLoanSchedules);
    List<LoanScheduleEntity> roundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
    RepaymentTotals totals = loanScheduleInstallmentRounder.calculateInitialTotals_v2(unroundedLoanSchedules, loanAmount, allExistingLoanSchedules);
    int installmentNum = 0;
    for (Iterator<LoanScheduleEntity> it = unroundedLoanSchedules.iterator(); it.hasNext(); ) {
        LoanScheduleEntity currentInstallment = it.next();
        LoanScheduleEntity roundedInstallment = currentInstallment;
        installmentNum++;
        if (it.hasNext()) {
            // handle all but the last installment
            if (loanScheduleInstallmentRounder.isGraceInstallment_v2(installmentNum, graceType, gracePeriodDuration)) {
                roundedInstallment = loanScheduleInstallmentRounder.roundAndAdjustGraceInstallment_v2(roundedInstallment);
            } else if (interestType.equals(InterestType.DECLINING_EPI)) {
                loanScheduleInstallmentRounder.roundAndAdjustNonGraceInstallmentForDecliningEPI_v2(roundedInstallment);
            } else {
                loanScheduleInstallmentRounder.roundAndAdjustButLastNonGraceInstallment_v2(roundedInstallment);
            }
            loanScheduleInstallmentRounder.updateRunningTotals_v2(totals, roundedInstallment);
        } else {
            loanScheduleInstallmentRounder.roundAndAdjustLastInstallment_v2(roundedInstallment, totals);
        }
        roundedLoanSchedules.add(roundedInstallment);
    }
    // for
    return roundedLoanSchedules;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) RepaymentTotals(org.mifos.accounts.loan.business.RepaymentTotals) ArrayList(java.util.ArrayList)

Example 3 with RepaymentTotals

use of org.mifos.accounts.loan.business.RepaymentTotals 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;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) RepaymentTotals(org.mifos.accounts.loan.business.RepaymentTotals)

Aggregations

LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)3 RepaymentTotals (org.mifos.accounts.loan.business.RepaymentTotals)3 ArrayList (java.util.ArrayList)2 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)1 Money (org.mifos.framework.util.helpers.Money)1