Fix up issue with fee charges not been summed up correctly for preview loan schedule.

This commit is contained in:
Keith Woodlock
2013-03-05 17:13:56 +00:00
parent e251633960
commit da7caddd46
3 changed files with 43 additions and 17 deletions
@@ -62,8 +62,6 @@ public class EqualInstallmentsAmortizationLoanScheduleGenerator implements Amort
}
}
BigDecimal cumulativeChargesToDate = chargesDueAtTimeOfDisbursement;
// create entries of disbursement period on loan schedule
final LoanSchedulePeriodData disbursementPeriod = LoanSchedulePeriodData.disbursementOnlyPeriod(disbursementDate,
principalDisbursed.getAmount(), chargesDueAtTimeOfDisbursement, false);
@@ -74,7 +72,7 @@ public class EqualInstallmentsAmortizationLoanScheduleGenerator implements Amort
BigDecimal totalPrincipalExpected = BigDecimal.ZERO;
BigDecimal totalPrincipalPaid = BigDecimal.ZERO;
BigDecimal totalInterestCharged = BigDecimal.ZERO;
BigDecimal totalFeeChargesCharged = BigDecimal.ZERO;
BigDecimal totalFeeChargesCharged = chargesDueAtTimeOfDisbursement;
BigDecimal totalPenaltyChargesCharged = BigDecimal.ZERO;
BigDecimal totalWaived = BigDecimal.ZERO;
BigDecimal totalWrittenOff = BigDecimal.ZERO;
@@ -135,7 +133,6 @@ public class EqualInstallmentsAmortizationLoanScheduleGenerator implements Amort
monetaryCurrency);
final Money totalInstallmentDue = principalForInstallment.plus(interestForInstallment).plus(feeChargesForInstallment)
.plus(penaltyChargesForInstallment);
cumulativeChargesToDate = cumulativeChargesToDate.add(feeChargesForInstallment.getAmount());
LoanSchedulePeriodData installment = LoanSchedulePeriodData.repaymentOnlyPeriod(periodNumber, startDate, scheduledDueDate,
principalForInstallment.getAmount(), outstandingBalance.getAmount(), interestForInstallment.getAmount(),
@@ -147,6 +144,8 @@ public class EqualInstallmentsAmortizationLoanScheduleGenerator implements Amort
loanTermInDays += daysInPeriod;
totalPrincipalExpected = totalPrincipalExpected.add(principalForInstallment.getAmount());
totalInterestCharged = totalInterestCharged.add(interestForInstallment.getAmount());
totalFeeChargesCharged = totalFeeChargesCharged.add(feeChargesForInstallment.getAmount());
totalPenaltyChargesCharged = totalPenaltyChargesCharged.add(penaltyChargesForInstallment.getAmount());
totalRepaymentExpected = totalRepaymentExpected.add(totalInstallmentDue.getAmount());
startDate = scheduledDueDate;
@@ -57,8 +57,6 @@ public class EqualPrincipalAmortizationLoanScheduleGenerator implements Amortiza
}
}
BigDecimal cumulativeChargesToDate = chargesDueAtTimeOfDisbursement;
// create entries of disbursement period on loan schedule
final LoanSchedulePeriodData disbursementPeriod = LoanSchedulePeriodData.disbursementOnlyPeriod(disbursementDate,
principalDisbursed.getAmount(), chargesDueAtTimeOfDisbursement, false);
@@ -69,7 +67,7 @@ public class EqualPrincipalAmortizationLoanScheduleGenerator implements Amortiza
BigDecimal totalPrincipalExpected = BigDecimal.ZERO;
BigDecimal totalPrincipalPaid = BigDecimal.ZERO;
BigDecimal totalInterestCharged = BigDecimal.ZERO;
BigDecimal totalFeeChargesCharged = BigDecimal.ZERO;
BigDecimal totalFeeChargesCharged = chargesDueAtTimeOfDisbursement;
BigDecimal totalPenaltyChargesCharged = BigDecimal.ZERO;
BigDecimal totalWaived = BigDecimal.ZERO;
BigDecimal totalWrittenOff = BigDecimal.ZERO;
@@ -117,10 +115,12 @@ public class EqualPrincipalAmortizationLoanScheduleGenerator implements Amortiza
outstandingBalance = outstandingBalance.minus(principalForInstallment);
Money feeChargesForInstallment = Money.zero(monetaryCurrency);
Money penaltyChargesForInstallment = Money.zero(monetaryCurrency);
Money totalInstallmentDue = principalForInstallment.plus(interestForInstallment).plus(feeChargesForInstallment);
cumulativeChargesToDate = cumulativeChargesToDate.add(feeChargesForInstallment.getAmount());
final Money feeChargesForInstallment = cumulativeFeeChargesDueWithin(startDate, scheduledDueDate, loanCharges, monetaryCurrency);
final Money penaltyChargesForInstallment = cumulativePenaltyChargesDueWithin(startDate, scheduledDueDate, loanCharges,
monetaryCurrency);
final Money totalInstallmentDue = principalForInstallment.plus(interestForInstallment).plus(feeChargesForInstallment)
.plus(penaltyChargesForInstallment);
LoanSchedulePeriodData installment = LoanSchedulePeriodData.repaymentOnlyPeriod(periodNumber, startDate, scheduledDueDate,
principalForInstallment.getAmount(), outstandingBalance.getAmount(), interestForInstallment.getAmount(),
@@ -132,6 +132,8 @@ public class EqualPrincipalAmortizationLoanScheduleGenerator implements Amortiza
loanTermInDays += daysInPeriod;
totalPrincipalExpected = totalPrincipalExpected.add(principalForInstallment.getAmount());
totalInterestCharged = totalInterestCharged.add(interestForInstallment.getAmount());
totalFeeChargesCharged = totalFeeChargesCharged.add(feeChargesForInstallment.getAmount());
totalPenaltyChargesCharged = totalPenaltyChargesCharged.add(penaltyChargesForInstallment.getAmount());
totalRepaymentExpected = totalRepaymentExpected.add(totalInstallmentDue.getAmount());
startDate = scheduledDueDate;
@@ -145,4 +147,32 @@ public class EqualPrincipalAmortizationLoanScheduleGenerator implements Amortiza
totalPrincipalPaid, totalInterestCharged, totalFeeChargesCharged, totalPenaltyChargesCharged, totalWaived, totalWrittenOff,
totalRepaymentExpected, totalRepayment, totalOutstanding);
}
private Money cumulativeFeeChargesDueWithin(final LocalDate periodStart, final LocalDate periodEnd, final Set<LoanCharge> loanCharges,
final MonetaryCurrency monetaryCurrency) {
Money cumulative = Money.zero(monetaryCurrency);
for (LoanCharge loanCharge : loanCharges) {
if (loanCharge.isDueForCollectionFromAndUpToAndIncluding(periodStart, periodEnd) && loanCharge.isFeeCharge()) {
cumulative = cumulative.plus(loanCharge.amount());
}
}
return cumulative;
}
private Money cumulativePenaltyChargesDueWithin(final LocalDate periodStart, final LocalDate periodEnd,
final Set<LoanCharge> loanCharges, final MonetaryCurrency monetaryCurrency) {
Money cumulative = Money.zero(monetaryCurrency);
for (LoanCharge loanCharge : loanCharges) {
if (loanCharge.isDueForCollectionFromAndUpToAndIncluding(periodStart, periodEnd) && loanCharge.isPenaltyCharge()) {
cumulative = cumulative.plus(loanCharge.amount());
}
}
return cumulative;
}
}
@@ -67,8 +67,6 @@ public class FlatMethodLoanScheduleGenerator implements LoanScheduleGenerator {
}
}
BigDecimal cumulativeChargesToDate = chargesDueAtTimeOfDisbursement;
// create entries of disbursement period on loan schedule
final LoanSchedulePeriodData disbursementPeriod = LoanSchedulePeriodData.disbursementOnlyPeriod(disbursementDate,
principalDisbursed.getAmount(), chargesDueAtTimeOfDisbursement, false);
@@ -79,7 +77,7 @@ public class FlatMethodLoanScheduleGenerator implements LoanScheduleGenerator {
BigDecimal totalPrincipalExpected = BigDecimal.ZERO;
BigDecimal totalPrincipalPaid = BigDecimal.ZERO;
BigDecimal totalInterestCharged = BigDecimal.ZERO;
BigDecimal totalFeeChargesCharged = BigDecimal.ZERO;
BigDecimal totalFeeChargesCharged = chargesDueAtTimeOfDisbursement;
BigDecimal totalPenaltyChargesCharged = BigDecimal.ZERO;
BigDecimal totalWaived = BigDecimal.ZERO;
BigDecimal totalWrittenOff = BigDecimal.ZERO;
@@ -124,9 +122,6 @@ public class FlatMethodLoanScheduleGenerator implements LoanScheduleGenerator {
.plus(feeChargesForInstallment) //
.plus(penaltyChargesForInstallment);
cumulativeChargesToDate = cumulativeChargesToDate.add(feeChargesForInstallment.getAmount()).add(
penaltyChargesForInstallment.getAmount());
LoanSchedulePeriodData installment = LoanSchedulePeriodData.repaymentOnlyPeriod(periodNumber, startDate, scheduledDueDate,
principalPerInstallment.getAmount(), outstandingBalance.getAmount(), interestPerInstallment.getAmount(),
feeChargesForInstallment.getAmount(), penaltyChargesForInstallment.getAmount(), totalInstallmentDue.getAmount());
@@ -137,6 +132,8 @@ public class FlatMethodLoanScheduleGenerator implements LoanScheduleGenerator {
loanTermInDays += daysInPeriod;
totalPrincipalExpected = totalPrincipalExpected.add(principalPerInstallment.getAmount());
totalInterestCharged = totalInterestCharged.add(interestPerInstallment.getAmount());
totalFeeChargesCharged = totalFeeChargesCharged.add(feeChargesForInstallment.getAmount());
totalPenaltyChargesCharged = totalPenaltyChargesCharged.add(penaltyChargesForInstallment.getAmount());
totalRepaymentExpected = totalRepaymentExpected.add(totalInstallmentDue.getAmount());
startDate = scheduledDueDate;