Aman-Mittal commented on code in PR #5816:
URL: https://github.com/apache/fineract/pull/5816#discussion_r3159397603


##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -52,10 +52,10 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
 
     @Override
     public void createJournalEntriesForLoan(final LoanDTO loanDTO) {
-        final Long officeId = loanDTO.getOfficeId();
-        final GLClosure latestGLClosure = 
this.helper.getLatestClosureByBranch(officeId);
-        final Office office = this.helper.getOfficeById(officeId);
         for (final LoanTransactionDTO loanTransactionDTO : 
loanDTO.getNewLoanTransactions()) {
+            final Long officeId = loanTransactionDTO.getOfficeId() == null ? 
loanDTO.getOfficeId() : loanTransactionDTO.getOfficeId();

Review Comment:
   Can you tell me what is the difference between loanTransactionDTO and loanDTO



##########
fineract-provider/src/test/java/org/apache/fineract/accounting/journalentry/CreateJournalEntriesForTransferLoanTest.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.accounting.journalentry;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.Collections;
+import java.util.List;
+import org.apache.fineract.accounting.closure.domain.GLClosure;
+import 
org.apache.fineract.accounting.common.AccountingConstants.AccrualAccountsForLoan;
+import org.apache.fineract.accounting.journalentry.data.LoanDTO;
+import org.apache.fineract.accounting.journalentry.data.LoanTransactionDTO;
+import 
org.apache.fineract.accounting.journalentry.service.AccountingProcessorHelper;
+import 
org.apache.fineract.accounting.journalentry.service.AccrualBasedAccountingProcessorForLoan;
+import org.apache.fineract.organisation.office.domain.Office;
+import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class CreateJournalEntriesForTransferLoanTest {
+
+    private static final Long LOAN_ID = 1L;
+    private static final Long LOAN_PRODUCT_ID = 1L;
+    private static final Long LOAN_OFFICE_ID = 1L;
+    private static final Long TRANSACTION_OFFICE_ID = 2L;
+    private static final String CURRENCY_CODE = "USD";
+    private static final String TRANSACTION_ID = "txn-transfer";
+    private static final LocalDate TRANSACTION_DATE = LocalDate.of(2021, 2, 
11);
+    private static final BigDecimal TRANSACTION_AMOUNT = new 
BigDecimal("600.00");
+    private static final BigDecimal PRINCIPAL_AMOUNT = new 
BigDecimal("500.00");
+
+    @Mock
+    private AccountingProcessorHelper helper;
+    @InjectMocks
+    private AccrualBasedAccountingProcessorForLoan processor;
+    private Office office;
+
+    @BeforeEach
+    void setUp() {
+        office = Office.headOffice("Transaction Office", TRANSACTION_DATE, 
null);
+        when(helper.getOfficeById(TRANSACTION_OFFICE_ID)).thenReturn(office);
+
+        GLClosure mockClosure = mock(GLClosure.class);
+        
when(helper.getLatestClosureByBranch(TRANSACTION_OFFICE_ID)).thenReturn(mockClosure);
+    }
+
+    @Test
+    void shouldCreateJournalEntriesForTransferInitiation() {
+        LoanTransactionEnumData transactionType = 
mock(LoanTransactionEnumData.class);
+        when(transactionType.isInitiateTransfer()).thenReturn(true);
+
+        processor.createJournalEntriesForLoan(createLoanDTO(transactionType));
+
+        verify(helper).createJournalEntriesForLoan(office, CURRENCY_CODE, 
AccrualAccountsForLoan.TRANSFERS_SUSPENSE.getValue(),
+                AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(), 
LOAN_PRODUCT_ID, null, LOAN_ID, TRANSACTION_ID, TRANSACTION_DATE,
+                PRINCIPAL_AMOUNT);
+    }
+
+    @Test
+    void shouldCreateJournalEntriesForTransferApproval() {
+        LoanTransactionEnumData transactionType = 
mock(LoanTransactionEnumData.class);
+        when(transactionType.isApproveTransfer()).thenReturn(true);
+
+        processor.createJournalEntriesForLoan(createLoanDTO(transactionType));
+
+        verify(helper).createJournalEntriesForLoan(office, CURRENCY_CODE, 
AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(),
+                AccrualAccountsForLoan.TRANSFERS_SUSPENSE.getValue(), 
LOAN_PRODUCT_ID, null, LOAN_ID, TRANSACTION_ID, TRANSACTION_DATE,
+                PRINCIPAL_AMOUNT);
+    }
+
+    @Test
+    void shouldCreateJournalEntriesForTransferWithdrawal() {
+        LoanTransactionEnumData transactionType = 
mock(LoanTransactionEnumData.class);
+        when(transactionType.isWithdrawTransfer()).thenReturn(true);
+
+        processor.createJournalEntriesForLoan(createLoanDTO(transactionType));
+
+        verify(helper).createJournalEntriesForLoan(office, CURRENCY_CODE, 
AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(),
+                AccrualAccountsForLoan.TRANSFERS_SUSPENSE.getValue(), 
LOAN_PRODUCT_ID, null, LOAN_ID, TRANSACTION_ID, TRANSACTION_DATE,
+                PRINCIPAL_AMOUNT);
+    }
+
+    private LoanDTO createLoanDTO(final LoanTransactionEnumData 
transactionType) {
+        LoanTransactionDTO loanTransactionDTO = new 
LoanTransactionDTO(TRANSACTION_OFFICE_ID, null, TRANSACTION_ID, 
TRANSACTION_DATE,
+                transactionType, TRANSACTION_AMOUNT, PRINCIPAL_AMOUNT, null, 
null, null, null, false, Collections.emptyList(),
+                Collections.emptyList(), false, "", null, null, null, null);
+
+        return new LoanDTO(LOAN_ID, LOAN_PRODUCT_ID, LOAN_OFFICE_ID, 
CURRENCY_CODE, false, true, true, List.of(loanTransactionDTO), false,

Review Comment:
   Seems like LoanDTO is superset of loanTransactionDTO



##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -52,10 +52,10 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
 
     @Override
     public void createJournalEntriesForLoan(final LoanDTO loanDTO) {
-        final Long officeId = loanDTO.getOfficeId();
-        final GLClosure latestGLClosure = 
this.helper.getLatestClosureByBranch(officeId);
-        final Office office = this.helper.getOfficeById(officeId);
         for (final LoanTransactionDTO loanTransactionDTO : 
loanDTO.getNewLoanTransactions()) {
+            final Long officeId = loanTransactionDTO.getOfficeId() == null ? 
loanDTO.getOfficeId() : loanTransactionDTO.getOfficeId();
+            final GLClosure latestGLClosure = 
this.helper.getLatestClosureByBranch(officeId);

Review Comment:
   Moving these values inside the loop can cause performance issue is it 
necessary



##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -159,6 +164,27 @@ else if (transactionType.isInterestPaymentWaiver() || 
transactionType.isInterest
         }
     }
 
+    private void createJournalEntriesForTransfers(final LoanDTO loanDTO, final 
LoanTransactionDTO loanTransactionDTO, final Office office) {
+        final Long loanProductId = loanDTO.getLoanProductId();
+        final Long loanId = loanDTO.getLoanId();
+        final String currencyCode = loanDTO.getCurrencyCode();
+
+        final String transactionId = loanTransactionDTO.getTransactionId();
+        final LocalDate transactionDate = 
loanTransactionDTO.getTransactionDate();
+        final BigDecimal principalAmount = loanTransactionDTO.getPrincipal();

Review Comment:
   Is this null safe?



##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -104,6 +104,11 @@ else if ((transactionType.isWriteOff() || 
transactionType.isWaiveInterest() || t
                 createJournalEntriesForWriteOffs(loanDTO, loanTransactionDTO, 
office);
             }
 
+            // Handle Transfers
+            else if (transactionType.isInitiateTransfer() || 
transactionType.isApproveTransfer() || transactionType.isWithdrawTransfer()) {
+                createJournalEntriesForTransfers(loanDTO, loanTransactionDTO, 
office);

Review Comment:
   does this also covers?
   
    if Transfer is cancelled: DR: Loan Portfolio (Office A) | CR: Transfers in 
suspense (Office A)
   
   can you explain your reasoning?



##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -159,6 +164,27 @@ else if (transactionType.isInterestPaymentWaiver() || 
transactionType.isInterest
         }
     }
 
+    private void createJournalEntriesForTransfers(final LoanDTO loanDTO, final 
LoanTransactionDTO loanTransactionDTO, final Office office) {
+        final Long loanProductId = loanDTO.getLoanProductId();
+        final Long loanId = loanDTO.getLoanId();
+        final String currencyCode = loanDTO.getCurrencyCode();
+
+        final String transactionId = loanTransactionDTO.getTransactionId();
+        final LocalDate transactionDate = 
loanTransactionDTO.getTransactionDate();
+        final BigDecimal principalAmount = loanTransactionDTO.getPrincipal();
+
+        if (loanTransactionDTO.getTransactionType().isInitiateTransfer()) {
+            this.helper.createJournalEntriesForLoan(office, currencyCode, 
AccrualAccountsForLoan.TRANSFERS_SUSPENSE.getValue(),
+                    AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(), 
loanProductId, null, loanId, transactionId, transactionDate,
+                    principalAmount);
+        } else if (loanTransactionDTO.getTransactionType().isApproveTransfer()

Review Comment:
   code in If and If Else seems identical, 



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