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


##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java:
##########
@@ -477,13 +476,27 @@ private void 
createJournalEntriesForCreditBalanceRefund(final LoanDTO loanDTO, f
         // transaction properties
         final String transactionId = loanTransactionDTO.getTransactionId();
         final LocalDate transactionDate = 
loanTransactionDTO.getTransactionDate();
-        final BigDecimal refundAmount = loanTransactionDTO.getAmount();
         final boolean isReversal = loanTransactionDTO.isReversed();
         final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId();
 
-        this.helper.createJournalEntriesAndReversalsForLoan(office, 
currencyCode, CashAccountsForLoan.OVERPAYMENT.getValue(),
-                CashAccountsForLoan.FUND_SOURCE.getValue(), loanProductId, 
paymentTypeId, loanId, transactionId, transactionDate,
-                refundAmount, isReversal);
+        BigDecimal overpaymentAmount = loanTransactionDTO.getOverPayment();
+        BigDecimal principalAmount = loanTransactionDTO.getPrincipal();
+
+        BigDecimal totalAmount = BigDecimal.ZERO;
+        List<JournalAmountHolder> journalAmountHolders = new ArrayList<>();
+
+        if (principalAmount != null && 
principalAmount.compareTo(BigDecimal.ZERO) > 0) {
+            totalAmount = totalAmount.add(principalAmount);
+            journalAmountHolders.add(new 
JournalAmountHolder(AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(), 
principalAmount));
+        }
+        if (overpaymentAmount != null && 
overpaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
+            totalAmount = totalAmount.add(overpaymentAmount);
+            journalAmountHolders.add(new 
JournalAmountHolder(AccrualAccountsForLoan.OVERPAYMENT.getValue(), 
overpaymentAmount));
+        }
+
+        JournalAmountHolder totalAmountHolder = new 
JournalAmountHolder(AccrualAccountsForLoan.FUND_SOURCE.getValue(), totalAmount);

Review Comment:
   Use `CashAccountsForLoan` enum here



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