alberto-art3ch commented on code in PR #5428:
URL: https://github.com/apache/fineract/pull/5428#discussion_r2757161259


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeService.java:
##########
@@ -850,14 +850,20 @@ private void update(final LoanCharge loanCharge, final 
BigDecimal amount, final
         }
     }
 
-    private Money getTotalAllTrancheDisbursementAmount(final Loan loan) {
-        Money amount = Money.zero(loan.getCurrency());
+    private Money sumMultiDisbursementAmounts(final Loan loan) {
         if (loan.isMultiDisburmentLoan()) {
-            for (final LoanDisbursementDetails loanDisbursementDetail : 
loan.getDisbursementDetails()) {
-                amount = amount.plus(loanDisbursementDetail.principal());
+            final List<LoanDisbursementDetails> loanDisbursementDetails = 
loan.getDisbursementDetails();
+            if (loan.isSubmittedAndPendingApproval()) {
+                return Money.of(loan.getCurrency(), 
loan.getProposedPrincipal());
+            } else if (loan.isApproved()) {
+                return Money.of(loan.getCurrency(), 
loan.getApprovedPrincipal());
+            } else if (loan.isOpen() || !loanDisbursementDetails.isEmpty()) {
+                return Money.of(loan.getCurrency(), 
loanDisbursementDetails.stream() //
+                        .map(LoanDisbursementDetails::principal) //
+                        .reduce(BigDecimal.ZERO, BigDecimal::add));
             }
         }
-        return amount;
+        return Money.zero(loan.getCurrency());
     }

Review Comment:
   Done! code updated



-- 
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]

Reply via email to