FINERACT-270 : Unable to waive all Loan charges
This commit is contained in:
+4
-4
@@ -4706,8 +4706,8 @@ public class Loan extends AbstractPersistableCustom<Long> {
|
||||
return loanCharges;
|
||||
}
|
||||
|
||||
public Set<LoanInstallmentCharge> generateInstallmentLoanCharges(final LoanCharge loanCharge) {
|
||||
final Set<LoanInstallmentCharge> loanChargePerInstallments = new HashSet<>();
|
||||
public List<LoanInstallmentCharge> generateInstallmentLoanCharges(final LoanCharge loanCharge) {
|
||||
final List<LoanInstallmentCharge> loanChargePerInstallments = new ArrayList<>();
|
||||
if (loanCharge.isInstalmentFee()) {
|
||||
List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments() ;
|
||||
for (final LoanRepaymentScheduleInstallment installment : installments) {
|
||||
@@ -5070,11 +5070,11 @@ public class Loan extends AbstractPersistableCustom<Long> {
|
||||
this.interestRecalculatedOn = DateUtils.getDateOfTenant();
|
||||
LocalDate lastRepaymentDate = this.getLastRepaymentPeriodDueDate(true);
|
||||
Set<LoanCharge> charges = this.charges();
|
||||
for (LoanCharge loanCharge : charges) {
|
||||
for (final LoanCharge loanCharge : charges) {
|
||||
if (!loanCharge.isDueAtDisbursement()) {
|
||||
updateOverdueScheduleInstallment(loanCharge);
|
||||
if (loanCharge.getDueLocalDate() == null || (!lastRepaymentDate.isBefore(loanCharge.getDueLocalDate()))) {
|
||||
if (!loanCharge.isWaived()
|
||||
if ((loanCharge.isInstalmentFee() || !loanCharge.isWaived())
|
||||
&& (loanCharge.getDueLocalDate() == null || !lastTransactionDate.isAfter(loanCharge.getDueLocalDate()))) {
|
||||
recalculateLoanCharge(loanCharge, generatorDTO.getPenaltyWaitPeriod());
|
||||
loanCharge.updateWaivedAmount(getCurrency());
|
||||
|
||||
+17
-7
@@ -22,6 +22,7 @@ import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -489,26 +490,35 @@ public class LoanCharge extends AbstractPersistableCustom<Long> {
|
||||
|
||||
private void updateInstallmentCharges() {
|
||||
final Collection<LoanInstallmentCharge> remove = new HashSet<>();
|
||||
final Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this);
|
||||
final List<LoanInstallmentCharge> newChargeInstallments = this.loan.generateInstallmentLoanCharges(this);
|
||||
if (this.loanInstallmentCharge.isEmpty()) {
|
||||
this.loanInstallmentCharge.addAll(chargePerInstallments);
|
||||
this.loanInstallmentCharge.addAll(newChargeInstallments);
|
||||
} else {
|
||||
int index = 0;
|
||||
final LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()];
|
||||
final LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments);
|
||||
for (final LoanInstallmentCharge chargePerInstallment : this.loanInstallmentCharge) {
|
||||
final List<LoanInstallmentCharge> oldChargeInstallments = new ArrayList<>();
|
||||
if(this.loanInstallmentCharge != null && !this.loanInstallmentCharge.isEmpty()){
|
||||
oldChargeInstallments.addAll(this.loanInstallmentCharge);
|
||||
}
|
||||
Collections.sort(oldChargeInstallments);
|
||||
final LoanInstallmentCharge[] loanChargePerInstallmentArray = newChargeInstallments.toArray(new LoanInstallmentCharge[newChargeInstallments.size()]);
|
||||
for (final LoanInstallmentCharge chargePerInstallment : oldChargeInstallments) {
|
||||
if (index == loanChargePerInstallmentArray.length) {
|
||||
remove.add(chargePerInstallment);
|
||||
//chargePerInstallment.updateInstallment(null);
|
||||
chargePerInstallment.updateInstallment(null);
|
||||
} else {
|
||||
chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]);
|
||||
}
|
||||
}
|
||||
this.loanInstallmentCharge.removeAll(remove);
|
||||
while (index < loanChargePerInstallmentArray.length - 1) {
|
||||
while (index < loanChargePerInstallmentArray.length) {
|
||||
this.loanInstallmentCharge.add(loanChargePerInstallmentArray[index++]);
|
||||
}
|
||||
}
|
||||
Money amount = Money.zero(this.loan.getCurrency());
|
||||
for(LoanInstallmentCharge charge:this.loanInstallmentCharge){
|
||||
amount =amount.plus(charge.getAmount());
|
||||
}
|
||||
this.amount =amount.getAmount();
|
||||
}
|
||||
|
||||
public boolean isDueAtDisbursement() {
|
||||
|
||||
+10
-2
@@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
@@ -32,13 +33,13 @@ import org.apache.fineract.organisation.monetary.domain.Money;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_loan_installment_charge")
|
||||
public class LoanInstallmentCharge extends AbstractPersistableCustom<Long> {
|
||||
public class LoanInstallmentCharge extends AbstractPersistableCustom<Long> implements Comparable<LoanInstallmentCharge> {
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "loan_charge_id", referencedColumnName = "id", nullable = false)
|
||||
private LoanCharge loancharge;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@ManyToOne(optional = false, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "loan_schedule_id", referencedColumnName = "id", nullable = false)
|
||||
private LoanRepaymentScheduleInstallment installment;
|
||||
|
||||
@@ -70,6 +71,11 @@ public class LoanInstallmentCharge extends AbstractPersistableCustom<Long> {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LoanInstallmentCharge o) {
|
||||
return this.installment.getInstallmentNumber().compareTo(o.installment.getInstallmentNumber());
|
||||
}
|
||||
|
||||
public LoanInstallmentCharge(final BigDecimal amount, final LoanCharge loanCharge, final LoanRepaymentScheduleInstallment installment) {
|
||||
this.loancharge = loanCharge;
|
||||
this.installment = installment;
|
||||
@@ -294,4 +300,6 @@ public class LoanInstallmentCharge extends AbstractPersistableCustom<Long> {
|
||||
public LoanRepaymentScheduleInstallment getInstallment() {
|
||||
return this.installment;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+6
-1
@@ -43,7 +43,7 @@ import org.joda.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_loan_repayment_schedule")
|
||||
public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCustom<AppUser, Long> {
|
||||
public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCustom<AppUser, Long> implements Comparable<LoanRepaymentScheduleInstallment> {
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "loan_id", referencedColumnName="id")
|
||||
@@ -319,6 +319,11 @@ public final class LoanRepaymentScheduleInstallment extends AbstractAuditableCus
|
||||
return !this.obligationsMet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LoanRepaymentScheduleInstallment o) {
|
||||
return this.installmentNumber.compareTo(o.installmentNumber);
|
||||
}
|
||||
|
||||
public boolean isPrincipalNotCompleted(final MonetaryCurrency currency) {
|
||||
return !isPrincipalCompleted(currency);
|
||||
}
|
||||
|
||||
+1
@@ -226,6 +226,7 @@ public class LoanChargeReadPlatformServiceImpl implements LoanChargeReadPlatform
|
||||
if (onlyPaymentPendingCharges) {
|
||||
sql = sql + "and lic.waived =0 and lic.is_paid_derived=0";
|
||||
}
|
||||
sql = sql + " order by lsi.installment";
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { loanChargeId });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user