Search in sources :

Example 51 with LoanScheduleEntity

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

Example 52 with LoanScheduleEntity

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;
}
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)

Example 53 with LoanScheduleEntity

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);
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity)

Example 54 with LoanScheduleEntity

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;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) BigDecimal(java.math.BigDecimal)

Aggregations

LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)54 Money (org.mifos.framework.util.helpers.Money)32 ArrayList (java.util.ArrayList)19 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)18 Test (org.junit.Test)16 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 BigDecimal (java.math.BigDecimal)11 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)8 LoanBO (org.mifos.accounts.loan.business.LoanBO)8 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)7 Date (java.util.Date)5 CustomerBO (org.mifos.customers.business.CustomerBO)5 UserContext (org.mifos.security.util.UserContext)5 LocalDate (org.joda.time.LocalDate)4 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)4 OriginalLoanScheduleEntitiesMatcher (org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher)4 InstallmentDetailsDto (org.mifos.dto.domain.InstallmentDetailsDto)4 LoanInstallmentDetailsDto (org.mifos.dto.domain.LoanInstallmentDetailsDto)4 MifosUser (org.mifos.security.MifosUser)4 Date (java.sql.Date)3