Skip to content

Commit

Permalink
fixed calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Jun 25, 2024
1 parent 99d2775 commit b51e768
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/folio/utils/CalculationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static Map<String, BigDecimal> calculate(Double dInitialAllocation,
BigDecimal unavailable = ensureNonNegative(encumbered.add(awaitingPayment).add(expended).subtract(credited));
BigDecimal totalFunding = allocated.add(netTransfers);
BigDecimal cashBalance = totalFunding.subtract(expended).add(credited);
BigDecimal available = totalFunding.subtract(encumbered.subtract(awaitingPayment).add(expended).subtract(credited));
BigDecimal available = totalFunding.subtract(encumbered.add(awaitingPayment).add(expended).subtract(credited));
BigDecimal overExpended = expended.subtract(credited).add(awaitingPayment).subtract(totalFunding.max(BigDecimal.ZERO)).max(BigDecimal.ZERO);
BigDecimal overCommitted = unavailable.subtract(totalFunding.max(BigDecimal.ZERO)).max(BigDecimal.ZERO);
BigDecimal overEncumbered = overCommitted.subtract(overExpended);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/folio/utils/MoneyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ public static Money ensureNonNegative(Money amount, String currency) {
}

public static BigDecimal ensureNonNegative(BigDecimal amount) {
return amount.compareTo(BigDecimal.ZERO) > 0 ? amount : BigDecimal.ZERO;
return amount.max(BigDecimal.ZERO);
}
}

0 comments on commit b51e768

Please sign in to comment.