You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by na...@apache.org on 2017/03/23 13:20:12 UTC
incubator-fineract git commit: FINERACT-270 : Unable to waive all
Loan charges
Repository: incubator-fineract
Updated Branches:
refs/heads/develop 14a1216d0 -> 935d6146c
FINERACT-270 : Unable to waive all Loan charges
Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/935d6146
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/935d6146
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/935d6146
Branch: refs/heads/develop
Commit: 935d6146c00e5f13cc53baf44ba78800c3b3796b
Parents: 14a1216
Author: nazeer1100126 <na...@confluxtechnologies.com>
Authored: Tue Mar 21 17:50:32 2017 +0530
Committer: nazeer1100126 <na...@confluxtechnologies.com>
Committed: Thu Mar 23 18:45:00 2017 +0530
----------------------------------------------------------------------
.../portfolio/loanaccount/domain/Loan.java | 8 +++----
.../loanaccount/domain/LoanCharge.java | 24 ++++++++++++++------
.../domain/LoanInstallmentCharge.java | 12 ++++++++--
.../LoanRepaymentScheduleInstallment.java | 7 +++++-
.../LoanChargeReadPlatformServiceImpl.java | 1 +
5 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/935d6146/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
index eb48952..3b35c53 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
@@ -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());
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/935d6146/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java
index 05de5fa..88a8aee 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java
@@ -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() {
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/935d6146/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInstallmentCharge.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInstallmentCharge.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInstallmentCharge.java
index 22e23f5..f0459a2 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInstallmentCharge.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInstallmentCharge.java
@@ -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;
}
+
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/935d6146/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepaymentScheduleInstallment.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepaymentScheduleInstallment.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepaymentScheduleInstallment.java
index 81eff34..e46ed66 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepaymentScheduleInstallment.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepaymentScheduleInstallment.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/935d6146/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeReadPlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeReadPlatformServiceImpl.java
index 02ba736..783bad7 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeReadPlatformServiceImpl.java
@@ -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 });
}