adamsaghy commented on code in PR #5861:
URL: https://github.com/apache/fineract/pull/5861#discussion_r3318026516


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDiscountFeeAmortizationServiceImpl.java:
##########
@@ -84,4 +90,18 @@ private BigDecimal calculateAlreadyPostedAmount(final 
WorkingCapitalLoan loan) {
                 .filter(txn -> txn.getTypeOf() == 
LoanTransactionType.DISCOUNT_FEE_AMORTIZATION && !txn.isReversed())
                 
.map(WorkingCapitalLoanTransaction::getTransactionAmount).reduce(BigDecimal.ZERO,
 BigDecimal::add);
     }
+
+    private void syncIncomeBalances(final WorkingCapitalLoan loan, final 
BigDecimal scheduleAmortization) {
+        final BigDecimal discount = loan.getLoanProductRelatedDetails() != 
null && loan.getLoanProductRelatedDetails().getDiscount() != null
+                ? loan.getLoanProductRelatedDetails().getDiscount()
+                : BigDecimal.ZERO;
+        final BigDecimal realizedIncome = 
scheduleAmortization.max(BigDecimal.ZERO).min(discount);
+        final BigDecimal unrealizedIncome = 
discount.subtract(realizedIncome).max(BigDecimal.ZERO);
+
+        final WorkingCapitalLoanBalance balance = 
balanceRepository.findByWcLoan_Id(loan.getId())
+                .orElseGet(() -> WorkingCapitalLoanBalance.createFor(loan));
+        balance.setRealizedIncome(realizedIncome);
+        balance.setUnrealizedIncome(unrealizedIncome);
+        balanceRepository.saveAndFlush(balance);

Review Comment:
   no need for explicit flush



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