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


##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -2015,26 +2010,86 @@ private void createJournalEntriesForAccruals(final 
LoanDTO loanDTO, final LoanTr
         }
         // create journal entries for the fees application
         if (MathUtil.isGreaterThanZero(feesAmount)) {
-            if (transactionType.isAccrualAdjustment()) {
-                this.helper.createJournalEntriesForLoanCharges(office, 
currencyCode, AccrualAccountsForLoan.INCOME_FROM_FEES.getValue(),
-                        AccrualAccountsForLoan.FEES_RECEIVABLE.getValue(), 
loanProductId, loanId, transactionId, transactionDate,
-                        feesAmount, loanTransactionDTO.getFeePayments());
+            final List<ChargeTaxPaymentDTO> feeTaxPayments = 
loanCommonAccountingHelper.filterTaxPayments(loanTransactionDTO, false);
+            final BigDecimal feeTaxTotal = 
loanCommonAccountingHelper.sumTaxAmounts(feeTaxPayments);
+            if (feeTaxTotal.compareTo(BigDecimal.ZERO) > 0) {
+                final BigDecimal netFees = feesAmount.subtract(feeTaxTotal);
+                if (transactionType.isAccrualAdjustment()) {
+                    // Reversal: CR Fees Receivable (full), DR Income from 
Fees (net), DR Tax Liability
+                    this.helper.createCreditJournalEntryForLoanCharges(office, 
currencyCode,
+                            AccrualAccountsForLoan.FEES_RECEIVABLE.getValue(), 
loanProductId, loanId, transactionId, transactionDate,
+                            feesAmount, loanTransactionDTO.getFeePayments());
+                    this.helper.createDebitJournalEntryForLoanCharges(office, 
currencyCode,
+                            
AccrualAccountsForLoan.INCOME_FROM_FEES.getValue(), loanProductId, loanId, 
transactionId, transactionDate,
+                            netFees,
+                            
loanCommonAccountingHelper.computeNetChargePayments(loanTransactionDTO.getFeePayments(),
 feeTaxPayments));
+                    
loanCommonAccountingHelper.createTaxLiabilityDebitEntries(office, currencyCode, 
loanId, transactionId, transactionDate,
+                            feeTaxPayments);
+                } else {
+                    // Normal: DR Fees Receivable (full), CR Income from Fees 
(net), CR Tax Liability
+                    this.helper.createDebitJournalEntryForLoanCharges(office, 
currencyCode,
+                            AccrualAccountsForLoan.FEES_RECEIVABLE.getValue(), 
loanProductId, loanId, transactionId, transactionDate,
+                            feesAmount, loanTransactionDTO.getFeePayments());
+                    this.helper.createCreditJournalEntryForLoanCharges(office, 
currencyCode,
+                            
AccrualAccountsForLoan.INCOME_FROM_FEES.getValue(), loanProductId, loanId, 
transactionId, transactionDate,
+                            netFees,
+                            
loanCommonAccountingHelper.computeNetChargePayments(loanTransactionDTO.getFeePayments(),
 feeTaxPayments));
+                    
loanCommonAccountingHelper.createTaxLiabilityCreditEntries(office, 
currencyCode, loanId, transactionId, transactionDate,
+                            feeTaxPayments);
+                }
             } else {
-                this.helper.createJournalEntriesForLoanCharges(office, 
currencyCode, AccrualAccountsForLoan.FEES_RECEIVABLE.getValue(),
-                        AccrualAccountsForLoan.INCOME_FROM_FEES.getValue(), 
loanProductId, loanId, transactionId, transactionDate,
-                        feesAmount, loanTransactionDTO.getFeePayments());
+                if (transactionType.isAccrualAdjustment()) {
+                    this.helper.createJournalEntriesForLoanCharges(office, 
currencyCode, AccrualAccountsForLoan.INCOME_FROM_FEES.getValue(),
+                            AccrualAccountsForLoan.FEES_RECEIVABLE.getValue(), 
loanProductId, loanId, transactionId, transactionDate,
+                            feesAmount, loanTransactionDTO.getFeePayments());
+                } else {
+                    this.helper.createJournalEntriesForLoanCharges(office, 
currencyCode, AccrualAccountsForLoan.FEES_RECEIVABLE.getValue(),
+                            
AccrualAccountsForLoan.INCOME_FROM_FEES.getValue(), loanProductId, loanId, 
transactionId, transactionDate,
+                            feesAmount, loanTransactionDTO.getFeePayments());
+                }
             }
         }
         // create journal entries for the penalties application
         if (MathUtil.isGreaterThanZero(penaltiesAmount)) {
-            if (transactionType.isAccrualAdjustment()) {
-                this.helper.createJournalEntriesForLoanCharges(office, 
currencyCode,
-                        
AccrualAccountsForLoan.INCOME_FROM_PENALTIES.getValue(), 
AccrualAccountsForLoan.PENALTIES_RECEIVABLE.getValue(),
-                        loanProductId, loanId, transactionId, transactionDate, 
penaltiesAmount, loanTransactionDTO.getPenaltyPayments());
+            final List<ChargeTaxPaymentDTO> penaltyTaxPayments = 
loanCommonAccountingHelper.filterTaxPayments(loanTransactionDTO, true);
+            final BigDecimal penaltyTaxTotal = 
loanCommonAccountingHelper.sumTaxAmounts(penaltyTaxPayments);
+            if (penaltyTaxTotal.compareTo(BigDecimal.ZERO) > 0) {
+                final BigDecimal netPenalties = 
penaltiesAmount.subtract(penaltyTaxTotal);
+                if (transactionType.isAccrualAdjustment()) {
+                    // Reversal: CR Penalties Receivable (full), DR Income 
from Penalties (net), DR Tax Liability
+                    this.helper.createCreditJournalEntryForLoanCharges(office, 
currencyCode,
+                            
AccrualAccountsForLoan.PENALTIES_RECEIVABLE.getValue(), loanProductId, loanId, 
transactionId, transactionDate,
+                            penaltiesAmount, 
loanTransactionDTO.getPenaltyPayments());
+                    this.helper.createDebitJournalEntryForLoanCharges(office, 
currencyCode,
+                            
AccrualAccountsForLoan.INCOME_FROM_PENALTIES.getValue(), loanProductId, loanId, 
transactionId, transactionDate,
+                            netPenalties, 
loanCommonAccountingHelper.computeNetChargePayments(loanTransactionDTO.getPenaltyPayments(),
+                                    penaltyTaxPayments));
+                    
loanCommonAccountingHelper.createTaxLiabilityDebitEntries(office, currencyCode, 
loanId, transactionId, transactionDate,
+                            penaltyTaxPayments);
+                } else {
+                    // Normal: DR Penalties Receivable (full), CR Income from 
Penalties (net), CR Tax Liability
+                    this.helper.createDebitJournalEntryForLoanCharges(office, 
currencyCode,
+                            
AccrualAccountsForLoan.PENALTIES_RECEIVABLE.getValue(), loanProductId, loanId, 
transactionId, transactionDate,
+                            penaltiesAmount, 
loanTransactionDTO.getPenaltyPayments());
+                    this.helper.createCreditJournalEntryForLoanCharges(office, 
currencyCode,

Review Comment:
   Duplicates? Common operations can be extracted... the whole logic would be 
less complex!



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