Skip to content

Commit

Permalink
FINERACT-2060: Accrual reverse replay logic and Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Jankovics committed Nov 22, 2024
1 parent ebfc11c commit af92749
Show file tree
Hide file tree
Showing 62 changed files with 1,870 additions and 2,559 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.charge.service;

import java.util.Collection;
import java.util.List;
import org.apache.fineract.portfolio.charge.data.ChargeData;
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;

Expand Down Expand Up @@ -53,7 +54,7 @@ public interface ChargeReadPlatformService {
* Excludes Given List of Charge Types from the response
* @return
*/
Collection<ChargeData> retrieveLoanAccountApplicableCharges(Long loanId, ChargeTimeType[] excludeChargeTimes);
List<ChargeData> retrieveLoanAccountApplicableCharges(Long loanId, ChargeTimeType[] excludeChargeTimes);

/**
* Returns all charges applicable for a given loan product (filter based on Currency of Selected Loan Product)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,23 @@ public static int compare(OffsetDateTime first, OffsetDateTime second) {
}

public static int compare(OffsetDateTime first, OffsetDateTime second, ChronoUnit truncate) {
return compare(first, second, truncate, true);
}

public static int compareWithNullsLast(OffsetDateTime first, OffsetDateTime second) {
return compare(first, second, null, false);
}

public static int compareWithNullsLast(@NotNull Optional<OffsetDateTime> first, @NotNull Optional<OffsetDateTime> second) {
return compareWithNullsLast(first.orElse(null), second.orElse(null));
}

public static int compare(OffsetDateTime first, OffsetDateTime second, ChronoUnit truncate, boolean nullFirst) {
if (first == null) {
return second == null ? 0 : -1;
return second == null ? 0 : (nullFirst ? -1 : 1);
}
if (second == null) {
return 1;
return nullFirst ? 1 : -1;
}
first = first.withOffsetSameInstant(ZoneOffset.UTC);
second = second.withOffsetSameInstant(ZoneOffset.UTC);
Expand Down Expand Up @@ -291,7 +303,23 @@ public static boolean isDateInTheFuture(final LocalDate localDate) {
}

public static int compare(LocalDate first, LocalDate second) {
return first == null ? (second == null ? 0 : -1) : (second == null ? 1 : first.compareTo(second));
return compare(first, second, true);
}

/**
* Comparing dates. Null will be considered as last elements
*
* @param first
* @param second
* @return
*/
public static int compareWithNullsLast(LocalDate first, LocalDate second) {
return compare(first, second, false);
}

public static int compare(LocalDate first, LocalDate second, boolean nullFirst) {
return first == null ? (second == null ? 0 : (nullFirst ? -1 : 1))
: (second == null ? (nullFirst ? 1 : -1) : first.compareTo(second));
}

public static boolean isEqual(LocalDate first, LocalDate second) {
Expand Down Expand Up @@ -426,23 +454,4 @@ private static DateTimeFormatter getDateTimeFormatter(String format, Locale loca
}
return formatter;
}

/**
* Comparing dates. Null will be considered as last elements
*
* @param first
* @param second
* @return
*/
public static int compareWithNullsLast(LocalDate first, LocalDate second) {
return first == null ? (second == null ? 0 : 1) : (second == null ? -1 : first.compareTo(second));
}

public static int compareWithNullsLast(@NotNull Optional<OffsetDateTime> first, @NotNull Optional<OffsetDateTime> second) {
return DateUtils.compareWithNullsLast(first.orElse(null), second.orElse(null));
}

public static int compareWithNullsLast(OffsetDateTime first, OffsetDateTime second) {
return first == null ? (second == null ? 0 : 1) : (second == null ? -1 : first.compareTo(second));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ public static BigDecimal subtract(BigDecimal first, BigDecimal second) {
return subtract(first, second, MoneyHelper.getMathContext());
}

/** @return first minus the others considering null values, maybe negative */
public static BigDecimal subtract(BigDecimal first, BigDecimal second, BigDecimal third) {
return subtract(subtract(first, second), third);
}

/** @return first minus second considering null values, maybe negative */
public static BigDecimal subtract(BigDecimal first, BigDecimal second, MathContext mc) {
return first == null ? null : second == null ? first : first.subtract(second, mc);
Expand Down Expand Up @@ -336,6 +341,10 @@ public static String formatToSql(BigDecimal amount) {
return amount == null ? null : amount.toPlainString();
}

public static Money toMoney(BigDecimal amount, @NotNull MonetaryCurrency currency) {
return amount == null ? null : Money.of(currency, amount);
}

// ----------------- Money -----------------

public static BigDecimal toBigDecimal(Money value) {
Expand Down Expand Up @@ -454,6 +463,16 @@ public static Money min(Money first, Money second, Money third, boolean notNull)
return min(min(first, second, notNull), third, notNull);
}

/** @return Money null safe negate */
public static Money negate(Money amount) {
return negate(amount, MoneyHelper.getMathContext());
}

/** @return Money null safe negate */
public static Money negate(Money amount, MathContext mc) {
return isEmpty(amount) ? amount : amount.negated(mc);
}

/**
* Calculate percentage of a value
*
Expand Down
Loading

0 comments on commit af92749

Please sign in to comment.