FINERACT-78 : Specified due date percentage charge calculation uses loan principal amount instead of installment principal amount

This commit is contained in:
nazeer1100126
2017-03-28 13:52:20 +05:30
parent 254d259705
commit 8baf9f4cd0
3 changed files with 58 additions and 5 deletions
@@ -6065,12 +6065,24 @@ public class Loan extends AbstractPersistableCustom<Long> {
return nextRepaymentDate;
}
public BigDecimal getDerivedAmountForCharge(LoanCharge loanCharge) {
public BigDecimal getDerivedAmountForCharge(final LoanCharge loanCharge) {
BigDecimal amount = BigDecimal.ZERO;
if (isMultiDisburmentLoan() && (loanCharge.getCharge().getChargeTimeType() == ChargeTimeType.DISBURSEMENT.getValue())) {
amount = getApprovedPrincipal();
} else {
amount = getPrincpal().getAmount();
// If charge type is specified due date and loan is multi disburment
// loan.
// Then we need to get as of this loan charge due date how much
// amount disbursed.
if (loanCharge.isSpecifiedDueDate() && this.isMultiDisburmentLoan()) {
for (final LoanDisbursementDetails loanDisbursementDetails : this.getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate().after(loanCharge.getDueDate())) {
amount = amount.add(loanDisbursementDetails.principal());
}
}
} else {
amount = getPrincpal().getAmount();
}
}
return amount;
}
@@ -182,6 +182,19 @@ public class LoanCharge extends AbstractPersistableCustom<Long> {
percentage);
}
// If charge type is specified due date and loan is multi disburment
// loan.
// Then we need to get as of this loan charge due date how much amount
// disbursed.
if (chargeDefinition.getChargeTimeType().equals(ChargeTimeType.SPECIFIED_DUE_DATE.getValue()) && loan.isMultiDisburmentLoan()) {
amountPercentageAppliedTo = BigDecimal.ZERO;
for (final LoanDisbursementDetails loanDisbursementDetails : loan.getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate().after(dueDate.toDate())) {
amountPercentageAppliedTo = amountPercentageAppliedTo.add(loanDisbursementDetails.principal());
}
}
}
return new LoanCharge(loan, chargeDefinition, amountPercentageAppliedTo, amount, chargeTime, chargeCalculation, dueDate,
chargePaymentMode, null, loanCharge);
}
@@ -408,7 +421,19 @@ public class LoanCharge extends AbstractPersistableCustom<Long> {
if (this.loan != null) {
switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
case PERCENT_OF_AMOUNT:
amountPercentageAppliedTo = this.loan.getPrincpal().getAmount();
// If charge type is specified due date and loan is multi
// disburment loan.
// Then we need to get as of this loan charge due date how
// much amount disbursed.
if (this.loan.isMultiDisburmentLoan() && this.isSpecifiedDueDate()) {
for (final LoanDisbursementDetails loanDisbursementDetails : this.loan.getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate().after(this.getDueDate())) {
amountPercentageAppliedTo = amountPercentageAppliedTo.add(loanDisbursementDetails.principal());
}
}
} else {
amountPercentageAppliedTo = this.loan.getPrincpal().getAmount();
}
break;
case PERCENT_OF_AMOUNT_AND_INTEREST:
amountPercentageAppliedTo = this.loan.getPrincpal().getAmount().add(this.loan.getTotalInterest());
@@ -553,6 +578,10 @@ public class LoanCharge extends AbstractPersistableCustom<Long> {
}
return dueDate;
}
public Date getDueDate() {
return this.dueDate;
}
private boolean determineIfFullyPaid() {
if (this.amount == null) { return true; }
@@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.loanaccount.domain;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -71,7 +72,6 @@ public class LoanRepaymentScheduleProcessingWrapper {
final Money totalInterest, boolean isInstallmentChargeApplicable) {
Money cumulative = Money.zero(monetaryCurrency);
for (final LoanCharge loanCharge : loanCharges) {
if (loanCharge.isFeeCharge() && !loanCharge.isDueAtDisbursement()) {
if (loanCharge.isInstalmentFee() && isInstallmentChargeApplicable) {
@@ -102,7 +102,19 @@ public class LoanRepaymentScheduleProcessingWrapper {
} else if (loanCharge.getChargeCalculation().isPercentageOfInterest()) {
amount = amount.add(totalInterest.getAmount());
} else {
amount = amount.add(totalPrincipal.getAmount());
// If charge type is specified due date and loan is
// multi disburment loan.
// Then we need to get as of this loan charge due date
// how much amount disbursed.
if (loanCharge.getLoan() != null && loanCharge.isSpecifiedDueDate() && loanCharge.getLoan().isMultiDisburmentLoan()) {
for (final LoanDisbursementDetails loanDisbursementDetails : loanCharge.getLoan().getDisbursementDetails()) {
if (!loanDisbursementDetails.expectedDisbursementDate().after(loanCharge.getDueDate())) {
amount = amount.add(loanDisbursementDetails.principal());
}
}
} else {
amount = amount.add(totalPrincipal.getAmount());
}
}
BigDecimal loanChargeAmt = amount.multiply(loanCharge.getPercentage()).divide(BigDecimal.valueOf(100));
cumulative = cumulative.plus(loanChargeAmt);