adamsaghy commented on code in PR #4961:
URL: https://github.com/apache/fineract/pull/4961#discussion_r2332429592
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanDisbursementService.java:
##########
@@ -377,4 +420,64 @@ private Map<String, Object> parseDisbursementDetails(final
JsonObject jsonObject
return returnObject;
}
+ private boolean hasMultipleOrPreDefinedDisbursementDetails(final Loan loan,
+ final Collection<LoanDisbursementDetails> undisbursedDetails) {
+ Collection<LoanDisbursementDetails> allDisbursementDetails =
loan.getDisbursementDetails();
+
+ if (undisbursedDetails.size() > 1) {
+ return true;
+ }
+
+ if (allDisbursementDetails.size() > 1 &&
!undisbursedDetails.isEmpty()) {
+ return true;
+ }
+
+ if (undisbursedDetails.size() == 1) {
+ LoanDisbursementDetails singleDetail =
undisbursedDetails.iterator().next();
+ BigDecimal loanPrincipal =
loan.getLoanRepaymentScheduleDetail().getPrincipal().getAmount();
+
+ if (singleDetail.principal().compareTo(loanPrincipal) == 0) {
+ return false;
+ }
+ }
+
+ // Default to tranche behavior for safety in ambiguous cases
+ return true;
+ }
+
+ public static List<LoanDisbursementDetails>
sortDisbursementDetailsByBusinessRules(
+ Collection<LoanDisbursementDetails> disbursementDetails) {
+ if (disbursementDetails == null || disbursementDetails.isEmpty()) {
+ return List.of();
+ }
+
+ return disbursementDetails.stream()
+
.sorted(Comparator.comparing(LoanDisbursementDetails::expectedDisbursementDate)
+ .thenComparing((LoanDisbursementDetails d1,
LoanDisbursementDetails d2) -> d2.principal().compareTo(d1.principal()))
Review Comment:
I dont think we should order by amount. We should order by the expected
disbursement date and created date?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]