Merge pull request #1596 from pramodn02/variableInstallment

Added installment amount for period in schedule data
This commit is contained in:
Shaik Nazeer Hussain
2016-01-14 16:07:04 +05:30
7 changed files with 146 additions and 132 deletions
@@ -58,6 +58,7 @@ public class LoanSchedulePeriodData {
private final BigDecimal totalOutstandingForPeriod;
private final BigDecimal totalOverdue;
private final BigDecimal totalActualCostOfLoanForPeriod;
private final BigDecimal totalInstallmentAmountForPeriod;
public static LoanSchedulePeriodData disbursementOnlyPeriod(final LocalDate disbursementDate, final BigDecimal principalDisbursed,
final BigDecimal feeChargesDueAtTimeOfDisbursement, final boolean isDisbursed) {
@@ -69,10 +70,12 @@ public class LoanSchedulePeriodData {
public static LoanSchedulePeriodData repaymentOnlyPeriod(final Integer periodNumber, final LocalDate fromDate, final LocalDate dueDate,
final BigDecimal principalDue, final BigDecimal principalOutstanding, final BigDecimal interestDueOnPrincipalOutstanding,
final BigDecimal feeChargesDueForPeriod, final BigDecimal penaltyChargesDueForPeriod, final BigDecimal totalDueForPeriod) {
final BigDecimal feeChargesDueForPeriod, final BigDecimal penaltyChargesDueForPeriod, final BigDecimal totalDueForPeriod,
final BigDecimal totalInstallmentAmountForPeriod) {
return new LoanSchedulePeriodData(periodNumber, fromDate, dueDate, principalDue, principalOutstanding,
interestDueOnPrincipalOutstanding, feeChargesDueForPeriod, penaltyChargesDueForPeriod, totalDueForPeriod);
interestDueOnPrincipalOutstanding, feeChargesDueForPeriod, penaltyChargesDueForPeriod, totalDueForPeriod,
totalInstallmentAmountForPeriod);
}
public static LoanSchedulePeriodData repaymentPeriodWithPayments(@SuppressWarnings("unused") final Long loanId,
@@ -87,7 +90,7 @@ public class LoanSchedulePeriodData {
final BigDecimal penaltyChargesWrittenOff, final BigDecimal penaltyChargesOutstanding, final BigDecimal totalDueForPeriod,
final BigDecimal totalPaid, final BigDecimal totalPaidInAdvanceForPeriod, final BigDecimal totalPaidLateForPeriod,
final BigDecimal totalWaived, final BigDecimal totalWrittenOff, final BigDecimal totalOutstanding,
final BigDecimal totalActualCostOfLoanForPeriod) {
final BigDecimal totalActualCostOfLoanForPeriod, final BigDecimal totalInstallmentAmountForPeriod) {
return new LoanSchedulePeriodData(periodNumber, fromDate, dueDate, obligationsMetOnDate, complete, principalOriginalDue,
principalPaid, principalWrittenOff, principalOutstanding, outstandingPrincipalBalanceOfLoan,
@@ -95,7 +98,7 @@ public class LoanSchedulePeriodData {
feeChargesPaid, feeChargesWaived, feeChargesWrittenOff, feeChargesOutstanding, penaltyChargesDue, penaltyChargesPaid,
penaltyChargesWaived, penaltyChargesWrittenOff, penaltyChargesOutstanding, totalDueForPeriod, totalPaid,
totalPaidInAdvanceForPeriod, totalPaidLateForPeriod, totalWaived, totalWrittenOff, totalOutstanding,
totalActualCostOfLoanForPeriod);
totalActualCostOfLoanForPeriod, totalInstallmentAmountForPeriod);
}
public static LoanSchedulePeriodData WithPaidDetail(final LoanSchedulePeriodData loanSchedulePeriodData, final boolean complete,
@@ -115,7 +118,7 @@ public class LoanSchedulePeriodData {
loanSchedulePeriodData.totalPaidForPeriod, loanSchedulePeriodData.totalPaidInAdvanceForPeriod,
loanSchedulePeriodData.totalPaidLateForPeriod, loanSchedulePeriodData.totalWaivedForPeriod,
loanSchedulePeriodData.totalWrittenOffForPeriod, loanSchedulePeriodData.totalOutstandingForPeriod,
loanSchedulePeriodData.totalActualCostOfLoanForPeriod);
loanSchedulePeriodData.totalActualCostOfLoanForPeriod, loanSchedulePeriodData.totalInstallmentAmountForPeriod);
}
/*
@@ -177,6 +180,7 @@ public class LoanSchedulePeriodData {
this.totalWrittenOffForPeriod = null;
this.totalOutstandingForPeriod = this.feeChargesOutstanding;
this.totalActualCostOfLoanForPeriod = this.feeChargesDue;
this.totalInstallmentAmountForPeriod = null;
if (dueDate.isBefore(new LocalDate())) {
this.totalOverdue = this.totalOutstandingForPeriod;
} else {
@@ -191,7 +195,7 @@ public class LoanSchedulePeriodData {
private LoanSchedulePeriodData(final Integer periodNumber, final LocalDate fromDate, final LocalDate dueDate,
final BigDecimal principalOriginalDue, final BigDecimal principalOutstanding,
final BigDecimal interestDueOnPrincipalOutstanding, final BigDecimal feeChargesDueForPeriod,
final BigDecimal penaltyChargesDueForPeriod, final BigDecimal totalDueForPeriod) {
final BigDecimal penaltyChargesDueForPeriod, final BigDecimal totalDueForPeriod, BigDecimal totalInstallmentAmountForPeriod) {
this.period = periodNumber;
this.fromDate = fromDate;
this.dueDate = dueDate;
@@ -238,6 +242,7 @@ public class LoanSchedulePeriodData {
this.totalWrittenOffForPeriod = null;
this.totalOutstandingForPeriod = totalDueForPeriod;
this.totalActualCostOfLoanForPeriod = interestDueOnPrincipalOutstanding.add(feeChargesDueForPeriod);
this.totalInstallmentAmountForPeriod = totalInstallmentAmountForPeriod;
if (dueDate.isBefore(new LocalDate())) {
this.totalOverdue = this.totalOutstandingForPeriod;
@@ -261,7 +266,7 @@ public class LoanSchedulePeriodData {
final BigDecimal penaltyChargesWrittenOff, final BigDecimal penaltyChargesOutstanding, final BigDecimal totalDueForPeriod,
final BigDecimal totalPaid, final BigDecimal totalPaidInAdvanceForPeriod, final BigDecimal totalPaidLateForPeriod,
final BigDecimal totalWaived, final BigDecimal totalWrittenOff, final BigDecimal totalOutstanding,
final BigDecimal totalActualCostOfLoanForPeriod) {
final BigDecimal totalActualCostOfLoanForPeriod, final BigDecimal totalInstallmentAmountForPeriod) {
this.period = periodNumber;
this.fromDate = fromDate;
this.dueDate = dueDate;
@@ -308,6 +313,7 @@ public class LoanSchedulePeriodData {
this.totalWrittenOffForPeriod = totalWrittenOff;
this.totalOutstandingForPeriod = totalOutstanding;
this.totalActualCostOfLoanForPeriod = totalActualCostOfLoanForPeriod;
this.totalInstallmentAmountForPeriod = totalInstallmentAmountForPeriod;
if (dueDate.isBefore(new LocalDate())) {
this.totalOverdue = this.totalOutstandingForPeriod;
@@ -428,7 +434,6 @@ public class LoanSchedulePeriodData {
return this.principalLoanBalanceOutstanding;
}
public Boolean getComplete() {
return this.complete;
}
@@ -55,7 +55,7 @@ public final class LoanScheduleModelRepaymentPeriod implements LoanScheduleModel
public LoanSchedulePeriodData toData() {
return LoanSchedulePeriodData.repaymentOnlyPeriod(this.periodNumber, this.fromDate, this.dueDate, this.principalDue.getAmount(),
this.outstandingLoanBalance.getAmount(), this.interestDue.getAmount(), this.feeChargesDue.getAmount(),
this.penaltyChargesDue.getAmount(), this.totalDue.getAmount());
this.penaltyChargesDue.getAmount(), this.totalDue.getAmount(), this.principalDue.plus(this.interestDue).getAmount());
}
@Override
@@ -124,11 +124,11 @@ public final class LoanScheduleModelRepaymentPeriod implements LoanScheduleModel
this.penaltyChargesDue = this.penaltyChargesDue.plus(penaltyCharge);
this.totalDue = this.totalDue.plus(feeCharge).plus(penaltyCharge);
}
@Override
public void addPrincipalAmount(final Money principalDue){
this.principalDue = this.principalDue.plus(principalDue);
this.totalDue = this.totalDue.plus(principalDue);
public void addPrincipalAmount(final Money principalDue) {
this.principalDue = this.principalDue.plus(principalDue);
this.totalDue = this.totalDue.plus(principalDue);
}
@Override
@@ -190,7 +190,8 @@ public class LoanScheduleCalculationPlatformServiceImpl implements LoanScheduleC
periodData.periodFromDate(), periodData.periodDueDate(), totalPrincipal.getAmount(), periodData
.principalLoanBalanceOutstanding(), interestDue.getAmount(), loanRepaymentScheduleInstallment
.getFeeChargesCharged(currency).getAmount(),
loanRepaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount(), totalAmount.getAmount());
loanRepaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount(), totalAmount.getAmount(),
totalPrincipal.plus(interestDue).getAmount());
futureInstallments.add(loanSchedulePeriodData);
isNewPaymentRequired = false;
} else if (periodData.periodDueDate().isAfter(today)) {
@@ -246,7 +247,7 @@ public class LoanScheduleCalculationPlatformServiceImpl implements LoanScheduleC
installment.getFromDate(), installment.getDueDate(), installment.getPrincipal(currency).getAmount(),
outstanding.getAmount(), installment.getInterestCharged(currency).getAmount(),
installment.getFeeChargesCharged(currency).getAmount(), installment.getPenaltyChargesCharged(currency).getAmount(),
installment.getDue(currency).getAmount());
installment.getDue(currency).getAmount(), installment.getTotalPrincipalAndInterest(currency).getAmount());
installmentData.add(loanSchedulePeriodData);
totalInterest = totalInterest.plus(installment.getInterestCharged(currency));
totalCharge = totalCharge.plus(installment.getFeeChargesCharged(currency));
@@ -163,6 +163,9 @@ public class LoanScheduleHistoryReadPlatformServiceImpl implements LoanScheduleH
final BigDecimal interestExpectedDue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestDue");
totalInterestCharged = totalInterestCharged.plus(interestExpectedDue);
final BigDecimal totalInstallmentAmount = totalPrincipalExpected.zero().plus(principalDue).plus(interestExpectedDue)
.getAmount();
final BigDecimal feeChargesExpectedDue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "feeChargesDue");
totalFeeChargesCharged = totalFeeChargesCharged.plus(feeChargesExpectedDue);
@@ -187,7 +190,7 @@ public class LoanScheduleHistoryReadPlatformServiceImpl implements LoanScheduleH
final LoanSchedulePeriodData periodData = LoanSchedulePeriodData.repaymentOnlyPeriod(period, fromDate, dueDate,
principalDue, outstandingPrincipalBalanceOfLoan, interestExpectedDue, feeChargesExpectedDue,
penaltyChargesExpectedDue, totalDueForPeriod);
penaltyChargesExpectedDue, totalDueForPeriod, totalInstallmentAmount);
periods.add(periodData);
}
@@ -12,9 +12,9 @@ import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanSchedulePeriodData;
public final class LoanRescheduleModelRepaymentPeriod implements LoanRescheduleModalPeriod {
private int periodNumber;
private int oldPeriodNumber;
private int periodNumber;
private int oldPeriodNumber;
private LocalDate fromDate;
private LocalDate dueDate;
private Money principalDue;
@@ -24,148 +24,148 @@ public final class LoanRescheduleModelRepaymentPeriod implements LoanRescheduleM
private Money penaltyChargesDue;
private Money totalDue;
private boolean isNew;
public LoanRescheduleModelRepaymentPeriod(final int periodNumber, final int oldPeriodNumber, LocalDate fromDate,
final LocalDate dueDate, final Money principalDue, final Money outstandingLoanBalance, final Money interestDue,
final Money feeChargesDue, final Money penaltyChargesDue, final Money totalDue, final boolean isNew) {
this.periodNumber = periodNumber;
this.oldPeriodNumber = oldPeriodNumber;
this.fromDate = fromDate;
this.dueDate = dueDate;
this.principalDue = principalDue;
this.outstandingLoanBalance = outstandingLoanBalance;
this.interestDue = interestDue;
this.feeChargesDue = feeChargesDue;
this.penaltyChargesDue = penaltyChargesDue;
this.totalDue = totalDue;
this.isNew = isNew;
}
public static LoanRescheduleModelRepaymentPeriod instance(final int periodNumber, final int oldPeriodNumber, LocalDate fromDate,
final LocalDate dueDate, final Money principalDue, final Money outstandingLoanBalance, final Money interestDue,
final Money feeChargesDue, final Money penaltyChargesDue, final Money totalDue, final boolean isNew) {
return new LoanRescheduleModelRepaymentPeriod(periodNumber, oldPeriodNumber, fromDate, dueDate, principalDue,
outstandingLoanBalance, interestDue, feeChargesDue, penaltyChargesDue, totalDue, isNew);
public LoanRescheduleModelRepaymentPeriod(final int periodNumber, final int oldPeriodNumber, LocalDate fromDate,
final LocalDate dueDate, final Money principalDue, final Money outstandingLoanBalance, final Money interestDue,
final Money feeChargesDue, final Money penaltyChargesDue, final Money totalDue, final boolean isNew) {
this.periodNumber = periodNumber;
this.oldPeriodNumber = oldPeriodNumber;
this.fromDate = fromDate;
this.dueDate = dueDate;
this.principalDue = principalDue;
this.outstandingLoanBalance = outstandingLoanBalance;
this.interestDue = interestDue;
this.feeChargesDue = feeChargesDue;
this.penaltyChargesDue = penaltyChargesDue;
this.totalDue = totalDue;
this.isNew = isNew;
}
@Override
public LoanSchedulePeriodData toData() {
return LoanSchedulePeriodData.repaymentOnlyPeriod(this.periodNumber, this.fromDate, this.dueDate, this.principalDue.getAmount(),
public static LoanRescheduleModelRepaymentPeriod instance(final int periodNumber, final int oldPeriodNumber, LocalDate fromDate,
final LocalDate dueDate, final Money principalDue, final Money outstandingLoanBalance, final Money interestDue,
final Money feeChargesDue, final Money penaltyChargesDue, final Money totalDue, final boolean isNew) {
return new LoanRescheduleModelRepaymentPeriod(periodNumber, oldPeriodNumber, fromDate, dueDate, principalDue,
outstandingLoanBalance, interestDue, feeChargesDue, penaltyChargesDue, totalDue, isNew);
}
@Override
public LoanSchedulePeriodData toData() {
return LoanSchedulePeriodData.repaymentOnlyPeriod(this.periodNumber, this.fromDate, this.dueDate, this.principalDue.getAmount(),
this.outstandingLoanBalance.getAmount(), this.interestDue.getAmount(), this.feeChargesDue.getAmount(),
this.penaltyChargesDue.getAmount(), this.totalDue.getAmount());
}
this.penaltyChargesDue.getAmount(), this.totalDue.getAmount(), this.principalDue.plus(this.interestDue).getAmount());
}
@Override
public Integer periodNumber() {
return this.periodNumber;
}
@Override
public Integer oldPeriodNumber() {
return this.oldPeriodNumber;
}
@Override
public Integer periodNumber() {
return this.periodNumber;
}
@Override
public LocalDate periodFromDate() {
return this.fromDate;
}
@Override
public Integer oldPeriodNumber() {
return this.oldPeriodNumber;
}
@Override
public LocalDate periodDueDate() {
return this.dueDate;
}
@Override
public LocalDate periodFromDate() {
return this.fromDate;
}
@Override
public LocalDate periodDueDate() {
return this.dueDate;
}
@Override
public BigDecimal principalDue() {
BigDecimal value = null;
@Override
public BigDecimal principalDue() {
BigDecimal value = null;
if (this.principalDue != null) {
value = this.principalDue.getAmount();
}
return value;
}
}
@Override
public BigDecimal interestDue() {
BigDecimal value = null;
@Override
public BigDecimal interestDue() {
BigDecimal value = null;
if (this.interestDue != null) {
value = this.interestDue.getAmount();
}
return value;
}
}
@Override
public BigDecimal feeChargesDue() {
BigDecimal value = null;
@Override
public BigDecimal feeChargesDue() {
BigDecimal value = null;
if (this.feeChargesDue != null) {
value = this.feeChargesDue.getAmount();
}
return value;
}
}
@Override
public BigDecimal penaltyChargesDue() {
BigDecimal value = null;
@Override
public BigDecimal penaltyChargesDue() {
BigDecimal value = null;
if (this.penaltyChargesDue != null) {
value = this.penaltyChargesDue.getAmount();
}
return value;
}
}
@Override
public boolean isNew() {
return isNew;
}
public void updatePeriodNumber(Integer periodNumber) {
this.periodNumber = periodNumber;
}
public void updateOldPeriodNumber(Integer oldPeriodNumber) {
this.oldPeriodNumber = oldPeriodNumber;
}
@Override
public boolean isNew() {
return isNew;
}
public void updatePeriodNumber(Integer periodNumber) {
this.periodNumber = periodNumber;
}
public void updateOldPeriodNumber(Integer oldPeriodNumber) {
this.oldPeriodNumber = oldPeriodNumber;
}
public void updatePeriodFromDate(LocalDate periodFromDate) {
this.fromDate = periodFromDate;
}
public void updatePeriodDueDate(LocalDate periodDueDate) {
this.dueDate = periodDueDate;
}
public void updatePrincipalDue(Money principalDue) {
this.principalDue = principalDue;
}
public void updateInterestDue(Money interestDue) {
this.interestDue = interestDue;
}
public void updateFeeChargesDue(Money feeChargesDue) {
this.feeChargesDue = feeChargesDue;
}
public void updatePenaltyChargesDue(Money penaltyChargesDue) {
this.penaltyChargesDue = penaltyChargesDue;
}
public void updateOutstandingLoanBalance(Money outstandingLoanBalance) {
this.outstandingLoanBalance = outstandingLoanBalance;
}
public void updateTotalDue(Money totalDue) {
this.totalDue = totalDue;
this.fromDate = periodFromDate;
}
public void updateIsNew(boolean isNew) {
this.isNew = isNew;
}
public void updatePeriodDueDate(LocalDate periodDueDate) {
this.dueDate = periodDueDate;
}
public void updatePrincipalDue(Money principalDue) {
this.principalDue = principalDue;
}
public void updateInterestDue(Money interestDue) {
this.interestDue = interestDue;
}
public void updateFeeChargesDue(Money feeChargesDue) {
this.feeChargesDue = feeChargesDue;
}
public void updatePenaltyChargesDue(Money penaltyChargesDue) {
this.penaltyChargesDue = penaltyChargesDue;
}
public void updateOutstandingLoanBalance(Money outstandingLoanBalance) {
this.outstandingLoanBalance = outstandingLoanBalance;
}
public void updateTotalDue(Money totalDue) {
this.totalDue = totalDue;
}
public void updateIsNew(boolean isNew) {
this.isNew = isNew;
}
}
@@ -434,6 +434,7 @@ public class LoanArrearsAgingServiceImpl implements LoanArrearsAgingService, Bus
final LocalDate dueDate = JdbcSupport.getLocalDate(rs, "dueDate");
final BigDecimal principalDue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "principalAmount");
final BigDecimal interestDueOnPrincipalOutstanding = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestAmount");
final BigDecimal totalInstallmentAmount = principalDue.add(interestDueOnPrincipalOutstanding);
final BigDecimal feeChargesDueForPeriod = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "feeAmount");
final BigDecimal penaltyChargesDueForPeriod = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "penaltyAmount");
final Integer periodNumber = null;
@@ -441,7 +442,8 @@ public class LoanArrearsAgingServiceImpl implements LoanArrearsAgingService, Bus
final BigDecimal principalOutstanding = null;
final BigDecimal totalDueForPeriod = null;
return LoanSchedulePeriodData.repaymentOnlyPeriod(periodNumber, fromDate, dueDate, principalDue, principalOutstanding,
interestDueOnPrincipalOutstanding, feeChargesDueForPeriod, penaltyChargesDueForPeriod, totalDueForPeriod);
interestDueOnPrincipalOutstanding, feeChargesDueForPeriod, penaltyChargesDueForPeriod, totalDueForPeriod,
totalInstallmentAmount);
}
}
@@ -1079,6 +1079,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final BigDecimal interestPaid = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestPaid");
final BigDecimal interestWaived = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestWaived");
final BigDecimal interestWrittenOff = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestWrittenOff");
final BigDecimal totalInstallmentAmount = totalPrincipalPaid.zero().plus(principalDue).plus(interestExpectedDue)
.getAmount();
final BigDecimal interestActualDue = interestExpectedDue.subtract(interestWaived).subtract(interestWrittenOff);
final BigDecimal interestOutstanding = interestActualDue.subtract(interestPaid);
@@ -1143,7 +1145,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
feeChargesOutstanding, penaltyChargesExpectedDue, penaltyChargesPaid, penaltyChargesWaived,
penaltyChargesWrittenOff, penaltyChargesOutstanding, totalDueForPeriod, totalPaidForPeriod,
totalPaidInAdvanceForPeriod, totalPaidLateForPeriod, totalWaivedForPeriod, totalWrittenOffForPeriod,
totalOutstandingForPeriod, totalActualCostOfLoanForPeriod);
totalOutstandingForPeriod, totalActualCostOfLoanForPeriod, totalInstallmentAmount);
periods.add(periodData);
}
@@ -1889,6 +1891,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final BigDecimal totalWrittenOff = null;
final BigDecimal totalOutstanding = null;
final BigDecimal totalPaid = null;
final BigDecimal totalInstallmentAmount = null;
return LoanSchedulePeriodData.repaymentPeriodWithPayments(loanId, period, fromDate, dueDate, obligationsMetOnDate, complete,
principalOriginalDue, principalPaid, principalWrittenOff, principalOutstanding, outstandingPrincipalBalanceOfLoan,
@@ -1896,7 +1899,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
feeChargesDue, feeChargesPaid, feeChargesWaived, feeChargesWrittenOff, feeChargesOutstanding, penaltyChargesDue,
penaltyChargesPaid, penaltyChargesWaived, penaltyChargesWrittenOff, penaltyChargesOutstanding, totalDueForPeriod,
totalPaid, totalPaidInAdvanceForPeriod, totalPaidLateForPeriod, totalWaived, totalWrittenOff, totalOutstanding,
totalActualCostOfLoanForPeriod);
totalActualCostOfLoanForPeriod, totalInstallmentAmount);
}
}