diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanTransactionComparator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanTransactionComparator.java index c9cf2def9..8f35b0d27 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanTransactionComparator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanTransactionComparator.java @@ -8,7 +8,8 @@ package org.mifosplatform.portfolio.loanaccount.domain; import java.util.Comparator; /** - * Sort loan transactions by transaction date and transaction type placing + * Sort loan transactions by transaction date, created date and transaction type + * placing */ public class LoanTransactionComparator implements Comparator { @@ -16,13 +17,18 @@ public class LoanTransactionComparator implements Comparator { public int compare(final LoanTransaction o1, final LoanTransaction o2) { int compareResult = 0; final int comparsion = o1.getTransactionDate().compareTo(o2.getTransactionDate()); + /** + * For transactions bearing the same transaction date, we sort + * transactions based on created date (when available) after which + * sorting for waivers takes place + **/ if (comparsion == 0) { - int comparsionCreate = 0; - if (o1.getCreatedDateTime() != null && o2.getCreatedDateTime() != null){ - comparsionCreate = o1.getCreatedDateTime().compareTo(o2.getCreatedDateTime()); + int comparisonBasedOnCreatedDate = 0; + if (o1.getCreatedDateTime() != null && o2.getCreatedDateTime() != null) { + comparisonBasedOnCreatedDate = o1.getCreatedDateTime().compareTo(o2.getCreatedDateTime()); } // equal transaction dates - if (comparsionCreate == 0) { + if (comparisonBasedOnCreatedDate == 0) { if (o1.isWaiver() && o2.isNotWaiver()) { compareResult = -1; } else if (o1.isNotWaiver() && o2.isWaiver()) {