This is an automated email from the ASF dual-hosted git repository.

adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 09bacb8827 FINERACT-2348: Accounting mismatch in case amortization and 
amortization adjustment occurs at the same time
09bacb8827 is described below

commit 09bacb88278c85cfc58f91c3db27e6599dbd198b
Author: mariiaKraievska <[email protected]>
AuthorDate: Fri Oct 3 18:17:15 2025 +0300

    FINERACT-2348: Accounting mismatch in case amortization and amortization 
adjustment occurs at the same time
---
 .../fineract/test/stepdef/loan/LoanStepDef.java    |  37 +++++
 .../resources/features/LoanBuyDownFees.feature     | 181 +++++++++++++++++++++
 .../features/LoanCapitalizedIncome.feature         | 177 ++++++++++++++++++++
 .../AccrualBasedAccountingProcessorForLoan.java    | 105 +++++++++---
 ...EntryWritePlatformServiceJpaRepositoryImpl.java |  12 +-
 5 files changed, 487 insertions(+), 25 deletions(-)

diff --git 
a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java
 
b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java
index dbaa1bc6ba..dd89703266 100644
--- 
a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java
+++ 
b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java
@@ -5821,6 +5821,43 @@ public class LoanStepDef extends AbstractStepDef {
         checkLoanAmortizationAllocationMappingData(resourceId, 
loanAmortizationAllocationResponse.body(), table);
     }
 
+    @And("Loan Amortization Allocation Mapping for the {string}th {string} 
transaction created on {string} contains the following data:")
+    public void checkLoanAmortizationAllocationMapping(final String 
nthTransactionStr, final String transactionType,
+            final String transactionDate, DataTable table) throws IOException {
+        final DateTimeFormatter formatter = 
DateTimeFormatter.ofPattern(DATE_FORMAT);
+        final Response<PostLoansResponse> loanCreateResponse = 
testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
+        final long loanId = loanCreateResponse.body().getLoanId();
+        final String resourceId = String.valueOf(loanId);
+
+        final Response<GetLoansLoanIdResponse> loanDetailsResponse = 
loansApi.retrieveLoan(loanId, false, "transactions", "", "").execute();
+        ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
+
+        final TransactionType transactionType1 = 
TransactionType.valueOf(transactionType);
+        final String transactionTypeExpected = transactionType1.getValue();
+
+        assert loanDetailsResponse.body() != null;
+        final List<GetLoansLoanIdTransactions> transactions = 
loanDetailsResponse.body().getTransactions();
+        assert transactions != null;
+        final int nthTransaction = Integer.parseInt(nthTransactionStr) - 1;
+        final GetLoansLoanIdTransactions transactionMatch = 
transactions.stream().filter(t -> {
+            assert t.getDate() != null;
+            if (!transactionDate.equals(formatter.format(t.getDate()))) {
+                return false;
+            }
+            assert t.getType() != null;
+            assert t.getType().getCode() != null;
+            return 
transactionTypeExpected.equals(t.getType().getCode().substring(20));
+        }).toList().get(nthTransaction);
+
+        final Response<LoanAmortizationAllocationResponse> 
loanAmortizationAllocationResponse = transactionMatch.getType().getCode()
+                
.substring(20).equals(GetLoansLoanIdLoanTransactionEnumData.SERIALIZED_NAME_CAPITALIZED_INCOME)
+                        ? 
loanCapitalizedIncomeApi.retrieveCapitalizedIncomeAllocationData(loanId, 
transactionMatch.getId()).execute()
+                        : 
loanBuyDownFeesApi.retrieveBuyDownFeesAllocationData(loanId, 
transactionMatch.getId()).execute();
+        ErrorHelper.checkSuccessfulApiCall(loanAmortizationAllocationResponse);
+
+        checkLoanAmortizationAllocationMappingData(resourceId, 
loanAmortizationAllocationResponse.body(), table);
+    }
+
     private void checkLoanAmortizationAllocationMappingData(final String 
resourceId,
             final LoanAmortizationAllocationResponse 
amortizationAllocationResponse, final DataTable table) {
         final List<List<String>> data = table.asLists();
diff --git 
a/fineract-e2e-tests-runner/src/test/resources/features/LoanBuyDownFees.feature 
b/fineract-e2e-tests-runner/src/test/resources/features/LoanBuyDownFees.feature
index 6cff314888..8cfeeb2140 100644
--- 
a/fineract-e2e-tests-runner/src/test/resources/features/LoanBuyDownFees.feature
+++ 
b/fineract-e2e-tests-runner/src/test/resources/features/LoanBuyDownFees.feature
@@ -3847,3 +3847,184 @@ Feature:Feature: Buy Down Fees
       | INCOME    | 404007       | Fee Income                  |       | 0.22  
 |
       | INCOME    | 450281       | Income From Buy Down        |       | 0.55  
 |
       | LIABILITY | 145024       | Deferred Capitalized Income | 0.77  |       
 |
+
+  @TestRailId:C4116
+  Scenario: Verify Buy Down Fee journal entries values when backdated new buy 
down fee with no classification and buy down fee adjustment for existing one 
with classification occurs on the same day
+    When Admin sets the business date to "01 January 2024"
+    And Admin creates a client with random data
+    And Admin creates a fully customized loan with the following data:
+      | LoanProduct                                                            
            | submitted on date | with Principal | ANNUAL interest rate % | 
interest type     | interest calculation period | amortization type  | 
loanTermFrequency | loanTermFrequencyType | repaymentEvery | 
repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | 
graceOnInterestPayment | interest free period | Payment strategy            |
+      | 
LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_CLASSIFICATION_INCOME_MAP
 | 01 January 2024   | 100            | 7                      | 
DECLINING_BALANCE | DAILY                       | EQUAL_INSTALLMENTS | 3        
         | MONTHS                | 1              | MONTHS                 | 3  
                | 0                       | 0                      | 0          
          | ADVANCED_PAYMENT_ALLOCATION |
+    And Admin successfully approves the loan on "01 January 2024" with "100" 
amount and expected disbursement date on "01 January 2024"
+    And Admin successfully disburse the loan on "01 January 2024" with "100" 
EUR transaction amount
+    Then Loan status will be "ACTIVE"
+    When Admin adds buy down fee with "AUTOPAY" payment type to the loan on 
"01 January 2024" with "50" EUR transaction amount and classification: 
pending_bankruptcy
+    Then Loan Repayment schedule has 3 periods, with the following data for 
periods:
+      | Nr | Days | Date             | Paid date | Balance of loan | Principal 
due | Interest | Fees | Penalties | Due   | Paid | In advance | Late | 
Outstanding |
+      |    |      | 01 January 2024  |           | 100.0           |           
    |          | 0.0  |           | 0.0   | 0.0  |            |      |          
   |
+      | 1  | 31   | 01 February 2024 |           | 66.86           | 33.14     
    | 0.58     | 0.0  | 0.0       | 33.72 | 0.0  | 0.0        | 0.0  | 33.72    
   |
+      | 2  | 29   | 01 March 2024    |           | 33.53           | 33.33     
    | 0.39     | 0.0  | 0.0       | 33.72 | 0.0  | 0.0        | 0.0  | 33.72    
   |
+      | 3  | 31   | 01 April 2024    |           | 0.0             | 33.53     
    | 0.2      | 0.0  | 0.0       | 33.73 | 0.0  | 0.0        | 0.0  | 33.73    
   |
+    And Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due    | Paid | In 
advance | Late | Outstanding |
+      | 100.0         | 1.17     | 0.0  | 0.0       | 101.17 | 0.0  | 0.0      
  | 0.0  | 101.17      |
+    And Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type | Amount | Principal | Interest | 
Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement     | 100.0  | 0.0       | 0.0      | 
0.0  | 0.0       | 100.0        | false    |
+      | 01 January 2024  | Buy Down Fee     | 50.0   | 0.0       | 0.0      | 
0.0  | 0.0       | 0.0          | false    |
+    And Loan Transactions tab has a "BUY_DOWN_FEE" transaction with date "01 
January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | EXPENSE   | 450280       | Buy Down Expense            | 50.0  |       
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 50.0  
 |
+    And Loan Transactions tab has a "Buy Down Fee" transaction with date "01 
January 2024" which has classification code value "pending_bankruptcy"
+    And Buy down fee contains the following data:
+      | Date            | Fee Amount | Amortized Amount | Not Yet Amortized 
Amount | Adjusted Amount | Charged Off Amount |
+      | 01 January 2024 | 50.0       | 0.0              | 50.0                 
    | 0.0             | 0.0                |
+    And LoanBuyDownFeeTransactionCreatedBusinessEvent is created on "01 
January 2024"
+    And Admin adds buy down fee adjustment with "AUTOPAY" payment type to the 
loan on "01 January 2024" with "25" EUR transaction amount
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type          | Amount | Principal | 
Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement              | 100.0  | 0.0       | 
0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 50.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 25.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+    Then Loan Transactions tab has a "BUY_DOWN_FEE" transaction with date "01 
January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                 | Debit | 
Credit |
+      | EXPENSE   | 450280       | Buy Down Expense             | 50.0  |      
  |
+      | LIABILITY | 145024       | Deferred Capitalized Income  |       | 50.0 
  |
+    And Loan Transactions tab has a "BUY_DOWN_FEE_ADJUSTMENT" transaction with 
date "01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | EXPENSE   | 450280       | Buy Down Expense            |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    When Admin sets the business date to "15 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type          | Amount | Principal | 
Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement              | 100.0  | 0.0       | 
0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 50.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 25.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 April 2024    | Accrual                   | 1.55   | 0.0       | 
1.55     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Buy Down Fee Amortization | 25.0   | 0.0       | 
25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Transactions tab has a "BUY_DOWN_FEE_AMORTIZATION" transaction 
with date "14 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 404007       | Fee Income                  |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    And Loan Amortization Allocation Mapping for "BUY_DOWN_FEE" transaction 
created on "01 January 2024" contains the following data:
+      | Date          | Type | Amount |
+      | 14 April 2024 | AM   | 25.0   |
+    And Admin adds buy down fee with "AUTOPAY" payment type to the loan on "1 
January 2024" with "30" EUR transaction amount
+    When Admin adds buy down fee adjustment with "AUTOPAY" payment type to the 
loan on "01 January 2024" with "5" EUR transaction amount
+    When Admin sets the business date to "16 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type          | Amount | Principal | 
Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement              | 100.0  | 0.0       | 
0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 50.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 25.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 30.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 5.0    | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 April 2024    | Accrual                   | 1.55   | 0.0       | 
1.55     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Buy Down Fee Amortization | 25.0   | 0.0       | 
25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 15 April 2024    | Buy Down Fee Amortization | 25.0   | 0.0       | 
25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Amortization Allocation Mapping for the "1"th "BUY_DOWN_FEE" 
transaction created on "01 January 2024" contains the following data:
+      | Date          | Type   | Amount |
+      | 14 April 2024 | AM     | 25.0   |
+      | 15 April 2024 | AM_ADJ | 5.0    |
+    And Loan Amortization Allocation Mapping for the "2"th "BUY_DOWN_FEE" 
transaction created on "01 January 2024" contains the following data:
+      | Date          | Type   | Amount |
+      | 15 April 2024 | AM     | 30.0   |
+    And Loan Transactions tab has a "BUY_DOWN_FEE_AMORTIZATION" transaction 
with date "15 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 450281       | Income From Buy Down        |       | 30.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 5.0   
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 30.0  |       
 |
+      | INCOME    | 404007       | Fee Income                  | 5.0   |       
 |
+
+  @TestRailId:C4117
+  Scenario: Verify Buy Down Fee journal entries values when backdated new buy 
down fee and buy down fee adjustment for existing one occurs on the same day, 
no classification
+    When Admin sets the business date to "01 January 2024"
+    And Admin creates a client with random data
+    And Admin creates a fully customized loan with the following data:
+      | LoanProduct                                              | submitted 
on date | with Principal | ANNUAL interest rate % | interest type     | 
interest calculation period | amortization type  | loanTermFrequency | 
loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | 
numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | 
interest free period | Payment strategy            |
+      | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | 01 January 
2024   | 100            | 7                      | DECLINING_BALANCE | DAILY    
                   | EQUAL_INSTALLMENTS | 3                 | MONTHS            
    | 1              | MONTHS                 | 3                  | 0          
             | 0                      | 0                    | 
ADVANCED_PAYMENT_ALLOCATION |
+    And Admin successfully approves the loan on "01 January 2024" with "100" 
amount and expected disbursement date on "01 January 2024"
+    And Admin successfully disburse the loan on "01 January 2024" with "100" 
EUR transaction amount
+    Then Loan status will be "ACTIVE"
+    When Admin adds buy down fee with "AUTOPAY" payment type to the loan on 
"01 January 2024" with "50" EUR transaction amount
+    Then Loan Repayment schedule has 3 periods, with the following data for 
periods:
+      | Nr | Days | Date             | Paid date | Balance of loan | Principal 
due | Interest | Fees | Penalties | Due   | Paid | In advance | Late | 
Outstanding |
+      |    |      | 01 January 2024  |           | 100.0           |           
    |          | 0.0  |           | 0.0   | 0.0  |            |      |          
   |
+      | 1  | 31   | 01 February 2024 |           | 66.86           | 33.14     
    | 0.58     | 0.0  | 0.0       | 33.72 | 0.0  | 0.0        | 0.0  | 33.72    
   |
+      | 2  | 29   | 01 March 2024    |           | 33.53           | 33.33     
    | 0.39     | 0.0  | 0.0       | 33.72 | 0.0  | 0.0        | 0.0  | 33.72    
   |
+      | 3  | 31   | 01 April 2024    |           | 0.0             | 33.53     
    | 0.2      | 0.0  | 0.0       | 33.73 | 0.0  | 0.0        | 0.0  | 33.73    
   |
+    And Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due    | Paid | In 
advance | Late | Outstanding |
+      | 100.0         | 1.17     | 0.0  | 0.0       | 101.17 | 0.0  | 0.0      
  | 0.0  | 101.17      |
+    And Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type | Amount | Principal | Interest | 
Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement     | 100.0  | 0.0       | 0.0      | 
0.0  | 0.0       | 100.0        | false    |
+      | 01 January 2024  | Buy Down Fee     | 50.0   | 0.0       | 0.0      | 
0.0  | 0.0       | 0.0          | false    |
+    And Loan Transactions tab has a "BUY_DOWN_FEE" transaction with date "01 
January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | EXPENSE   | 450280       | Buy Down Expense            | 50.0  |       
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 50.0  
 |
+    And Buy down fee contains the following data:
+      | Date            | Fee Amount | Amortized Amount | Not Yet Amortized 
Amount | Adjusted Amount | Charged Off Amount |
+      | 01 January 2024 | 50.0       | 0.0              | 50.0                 
    | 0.0             | 0.0                |
+    And LoanBuyDownFeeTransactionCreatedBusinessEvent is created on "01 
January 2024"
+    And Admin adds buy down fee adjustment with "AUTOPAY" payment type to the 
loan on "01 January 2024" with "25" EUR transaction amount
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type          | Amount | Principal | 
Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement              | 100.0  | 0.0       | 
0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 50.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 25.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+    Then Loan Transactions tab has a "BUY_DOWN_FEE" transaction with date "01 
January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                 | Debit | 
Credit |
+      | EXPENSE   | 450280       | Buy Down Expense             | 50.0  |      
  |
+      | LIABILITY | 145024       | Deferred Capitalized Income  |       | 50.0 
  |
+    And Loan Transactions tab has a "BUY_DOWN_FEE_ADJUSTMENT" transaction with 
date "01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | EXPENSE   | 450280       | Buy Down Expense            |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    When Admin sets the business date to "15 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type          | Amount | Principal | 
Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement              | 100.0  | 0.0       | 
0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 50.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 25.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 April 2024    | Accrual                   | 1.55   | 0.0       | 
1.55     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Buy Down Fee Amortization | 25.0   | 0.0       | 
25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Transactions tab has a "BUY_DOWN_FEE_AMORTIZATION" transaction 
with date "14 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 450281       | Income From Buy Down        |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    And Loan Amortization Allocation Mapping for "BUY_DOWN_FEE" transaction 
created on "01 January 2024" contains the following data:
+      | Date          | Type | Amount |
+      | 14 April 2024 | AM   | 25.0   |
+    And Admin adds buy down fee with "AUTOPAY" payment type to the loan on "1 
January 2024" with "30" EUR transaction amount
+    When Admin adds buy down fee adjustment with "AUTOPAY" payment type to the 
loan on "01 January 2024" with "5" EUR transaction amount
+    When Admin sets the business date to "16 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type          | Amount | Principal | 
Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement              | 100.0  | 0.0       | 
0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 50.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 25.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee              | 30.0   | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 January 2024  | Buy Down Fee Adjustment   | 5.0    | 0.0       | 
0.0      | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 01 April 2024    | Accrual                   | 1.55   | 0.0       | 
1.55     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Buy Down Fee Amortization | 25.0   | 0.0       | 
25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 15 April 2024    | Buy Down Fee Amortization | 25.0   | 0.0       | 
25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Amortization Allocation Mapping for the "1"th "BUY_DOWN_FEE" 
transaction created on "01 January 2024" contains the following data:
+      | Date          | Type   | Amount |
+      | 14 April 2024 | AM     | 25.0   |
+      | 15 April 2024 | AM_ADJ | 5.0    |
+    And Loan Amortization Allocation Mapping for the "2"th "BUY_DOWN_FEE" 
transaction created on "01 January 2024" contains the following data:
+      | Date          | Type   | Amount |
+      | 15 April 2024 | AM     | 30.0   |
+    And Loan Transactions tab has a "BUY_DOWN_FEE_AMORTIZATION" transaction 
with date "15 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 450281       | Income From Buy Down        |       | 30.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 5.0   
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 30.0  |       
 |
+      | INCOME    | 450281       | Income From Buy Down        | 5.0   |       
 |
diff --git 
a/fineract-e2e-tests-runner/src/test/resources/features/LoanCapitalizedIncome.feature
 
b/fineract-e2e-tests-runner/src/test/resources/features/LoanCapitalizedIncome.feature
index 09cef0ae6b..007a5fed6c 100644
--- 
a/fineract-e2e-tests-runner/src/test/resources/features/LoanCapitalizedIncome.feature
+++ 
b/fineract-e2e-tests-runner/src/test/resources/features/LoanCapitalizedIncome.feature
@@ -8176,3 +8176,180 @@ Feature: Capitalized Income
       | INCOME    | 744008       | Recoveries                  |       | 0.22  
 |
       | INCOME    | 404000       | Interest Income             |       | 0.55  
 |
       | LIABILITY | 145024       | Deferred Capitalized Income | 0.77  |       
 |
+
+  @TestRailId:C4114
+  Scenario: Verify Capitalized Income journal entries values when backdated 
new capitalized income with no classification and capitalized income adjustment 
for existing one with classification occurs on the same day
+    When Admin sets the business date to "01 January 2024"
+    And Admin creates a client with random data
+    And Admin creates a fully customized loan with the following data:
+      | LoanProduct                                                            
                           | submitted on date | with Principal | ANNUAL 
interest rate % | interest type     | interest calculation period | 
amortization type  | loanTermFrequency | loanTermFrequencyType | repaymentEvery 
| repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | 
graceOnInterestPayment | interest free period | Payment strategy            |
+      | 
LP2_PROGRESSIVE_ADV_PMNT_ALLOCATION_CAPITALIZED_INCOME_ADJ_CUSTOM_ALLOC_CLASSIFICATION_INCOME_MAP
 | 01 January 2024   | 200            | 7                      | 
DECLINING_BALANCE | DAILY                       | EQUAL_INSTALLMENTS | 3        
         | MONTHS                | 1              | MONTHS                 | 3  
                | 0                       | 0                      | 0          
          | ADVANCED_PAYMENT_ALLOCATION |
+    And Admin successfully approves the loan on "01 January 2024" with "200" 
amount and expected disbursement date on "01 January 2024"
+    And Admin successfully disburse the loan on "01 January 2024" with "100" 
EUR transaction amount
+    Then Loan status will be "ACTIVE"
+    And Admin adds capitalized income with "AUTOPAY" payment type to the loan 
on "01 January 2024" with "50" EUR transaction amount and classification: 
scheduled_payment
+    Then Loan Repayment schedule has 3 periods, with the following data for 
periods:
+      | Nr | Days | Date             | Paid date | Balance of loan | Principal 
due | Interest | Fees | Penalties | Due   | Paid | In advance | Late | 
Outstanding |
+      |    |      | 01 January 2024  |           | 100.0           |           
    |          | 0.0  |           | 0.0   | 0.0  |            |      |          
   |
+      |    |      | 01 January 2024  |           | 50.0            |           
    |          | 0.0  |           | 0.0   | 0.0  |            |      |          
   |
+      | 1  | 31   | 01 February 2024 |           | 100.29          | 49.71     
    | 0.87     | 0.0  | 0.0       | 50.58 | 0.0  | 0.0        | 0.0  | 50.58    
   |
+      | 2  | 29   | 01 March 2024    |           | 50.3            | 49.99     
    | 0.59     | 0.0  | 0.0       | 50.58 | 0.0  | 0.0        | 0.0  | 50.58    
   |
+      | 3  | 31   | 01 April 2024    |           | 0.0             | 50.3      
    | 0.29     | 0.0  | 0.0       | 50.59 | 0.0  | 0.0        | 0.0  | 50.59    
   |
+    Then Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due     | Paid  | In 
advance | Late | Outstanding |
+      | 150.0         | 1.75     | 0.0  | 0.0       | 151.75  | 0.0   | 0.0    
    | 0.0  | 151.75      |
+    And Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type   | Amount | Principal | Interest 
| Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement       | 100.0  | 0.0       | 0.0      
| 0.0  | 0.0       | 100.0        | false    |
+      | 01 January 2024  | Capitalized Income | 50.0   | 50.0      | 0.0      
| 0.0  | 0.0       | 150.0        | false    |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME" transaction with date 
"01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | ASSET     | 112601       | Loans Receivable            | 50.0  |       
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 50.0  
 |
+    And Loan Transactions tab has a "Capitalized Income" transaction with date 
"01 January 2024" which has classification code value "scheduled_payment"
+    Then LoanCapitalizedIncomeTransactionCreatedBusinessEvent is raised on "01 
January 2024"
+    And Admin adds capitalized income adjustment with "AUTOPAY" payment type 
to the loan on "01 January 2024" with "25" EUR transaction amount
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type              | Amount | Principal 
| Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement                  | 100.0  | 0.0       
| 0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income            | 50.0   | 50.0      
| 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment | 25.0   | 25.0      
| 0.0      | 0.0  | 0.0       | 125.0        | false    | false    |
+    Then Loan Transactions tab has a "CAPITALIZED_INCOME" transaction with 
date "01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                 | Debit | 
Credit |
+      | ASSET     | 112601       | Loans Receivable             | 50.0  |      
  |
+      | LIABILITY | 145024       | Deferred Capitalized Income  |       | 50.0 
  |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME_ADJUSTMENT" 
transaction with date "01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | ASSET     | 112601       | Loans Receivable            |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    When Admin sets the business date to "15 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type                | Amount | 
Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement                    | 100.0  | 0.0      
 | 0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income              | 50.0   | 50.0     
 | 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment   | 25.0   | 25.0     
 | 0.0      | 0.0  | 0.0       | 125.0        | false    | false    |
+      | 01 April 2024    | Accrual                         | 2.04   | 0.0      
 | 2.04     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Capitalized Income Amortization | 25.0   | 0.0      
 | 25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME_AMORTIZATION" 
transaction with date "14 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 744008       | Recoveries                  |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    And Loan Amortization Allocation Mapping for "CAPITALIZED_INCOME" 
transaction created on "01 January 2024" contains the following data:
+      | Date          | Type | Amount |
+      | 14 April 2024 | AM   | 25.0   |
+    And Admin adds capitalized income with "AUTOPAY" payment type to the loan 
on "1 January 2024" with "30" EUR transaction amount
+    When Admin adds capitalized income adjustment with "AUTOPAY" payment type 
to the loan on "01 January 2024" with "5" EUR transaction amount
+    When Admin sets the business date to "16 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type                | Amount | 
Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement                    | 100.0  | 0.0      
 | 0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income              | 50.0   | 50.0     
 | 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment   | 25.0   | 25.0     
 | 0.0      | 0.0  | 0.0       | 125.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income              | 30.0   | 30.0     
 | 0.0      | 0.0  | 0.0       | 155.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment   | 5.0    | 5.0      
 | 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 April 2024    | Accrual                         | 2.04   | 0.0      
 | 2.04     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Capitalized Income Amortization | 25.0   | 0.0      
 | 25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 15 April 2024    | Capitalized Income Amortization | 25.0   | 0.0      
 | 25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Amortization Allocation Mapping for the "1"th 
"CAPITALIZED_INCOME" transaction created on "01 January 2024" contains the 
following data:
+      | Date          | Type   | Amount |
+      | 14 April 2024 | AM     | 25.0   |
+      | 15 April 2024 | AM_ADJ | 5.0    |
+    And Loan Amortization Allocation Mapping for the "2"th 
"CAPITALIZED_INCOME" transaction created on "01 January 2024" contains the 
following data:
+      | Date          | Type   | Amount |
+      | 15 April 2024 | AM     | 30.0   |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME_AMORTIZATION" 
transaction with date "15 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 404000       | Interest Income             |       | 30.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 5.0   
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 30.0  |       
 |
+      | INCOME    | 744008       | Recoveries                  | 5.0   |       
 |
+
+  @TestRailId:C4115
+  Scenario: Verify Capitalized Income journal entries values when backdated 
new capitalized income and capitalized income adjustment for existing one 
occurs on the same day, no classification
+    When Admin sets the business date to "01 January 2024"
+    And Admin creates a client with random data
+    And Admin creates a fully customized loan with the following data:
+      | LoanProduct                                                            
                           | submitted on date | with Principal | ANNUAL 
interest rate % | interest type     | interest calculation period | 
amortization type  | loanTermFrequency | loanTermFrequencyType | repaymentEvery 
| repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | 
graceOnInterestPayment | interest free period | Payment strategy            |
+      | 
LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_RECALC_DAILY_CAPITALIZED_INCOME_ADJ_CUSTOM_ALLOC
 | 01 January 2024   | 200            | 7                      | 
DECLINING_BALANCE | DAILY                       | EQUAL_INSTALLMENTS | 3        
         | MONTHS                | 1              | MONTHS                 | 3  
                | 0                       | 0                      | 0          
          | ADVANCED_PAYMENT_ALLOCATION |
+    And Admin successfully approves the loan on "01 January 2024" with "200" 
amount and expected disbursement date on "01 January 2024"
+    And Admin successfully disburse the loan on "01 January 2024" with "100" 
EUR transaction amount
+    Then Loan status will be "ACTIVE"
+    When Admin adds capitalized income with "AUTOPAY" payment type to the loan 
on "01 January 2024" with "50" EUR transaction amount
+    Then Loan Repayment schedule has 3 periods, with the following data for 
periods:
+      | Nr | Days | Date             | Paid date | Balance of loan | Principal 
due | Interest | Fees | Penalties | Due   | Paid | In advance | Late | 
Outstanding |
+      |    |      | 01 January 2024  |           | 100.0           |           
    |          | 0.0  |           | 0.0   | 0.0  |            |      |          
   |
+      |    |      | 01 January 2024  |           | 50.0            |           
    |          | 0.0  |           | 0.0   | 0.0  |            |      |          
   |
+      | 1  | 31   | 01 February 2024 |           | 100.29          | 49.71     
    | 0.87     | 0.0  | 0.0       | 50.58 | 0.0  | 0.0        | 0.0  | 50.58    
   |
+      | 2  | 29   | 01 March 2024    |           | 50.3            | 49.99     
    | 0.59     | 0.0  | 0.0       | 50.58 | 0.0  | 0.0        | 0.0  | 50.58    
   |
+      | 3  | 31   | 01 April 2024    |           | 0.0             | 50.3      
    | 0.29     | 0.0  | 0.0       | 50.59 | 0.0  | 0.0        | 0.0  | 50.59    
   |
+    Then Loan Repayment schedule has the following data in Total row:
+      | Principal due | Interest | Fees | Penalties | Due     | Paid  | In 
advance | Late | Outstanding |
+      | 150.0         | 1.75     | 0.0  | 0.0       | 151.75  | 0.0   | 0.0    
    | 0.0  | 151.75      |
+    And Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type   | Amount | Principal | Interest 
| Fees | Penalties | Loan Balance | Reverted |
+      | 01 January 2024  | Disbursement       | 100.0  | 0.0       | 0.0      
| 0.0  | 0.0       | 100.0        | false    |
+      | 01 January 2024  | Capitalized Income | 50.0   | 50.0      | 0.0      
| 0.0  | 0.0       | 150.0        | false    |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME" transaction with date 
"01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | ASSET     | 112601       | Loans Receivable            | 50.0  |       
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 50.0  
 |
+    Then LoanCapitalizedIncomeTransactionCreatedBusinessEvent is raised on "01 
January 2024"
+    And Admin adds capitalized income adjustment with "AUTOPAY" payment type 
to the loan on "01 January 2024" with "25" EUR transaction amount
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type              | Amount | Principal 
| Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement                  | 100.0  | 0.0       
| 0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income            | 50.0   | 50.0      
| 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment | 25.0   | 25.0      
| 0.0      | 0.0  | 0.0       | 125.0        | false    | false    |
+    Then Loan Transactions tab has a "CAPITALIZED_INCOME" transaction with 
date "01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                 | Debit | 
Credit |
+      | ASSET     | 112601       | Loans Receivable             | 50.0  |      
  |
+      | LIABILITY | 145024       | Deferred Capitalized Income  |       | 50.0 
  |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME_ADJUSTMENT" 
transaction with date "01 January 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | ASSET     | 112601       | Loans Receivable            |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    When Admin sets the business date to "15 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type                | Amount | 
Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement                    | 100.0  | 0.0      
 | 0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income              | 50.0   | 50.0     
 | 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment   | 25.0   | 25.0     
 | 0.0      | 0.0  | 0.0       | 125.0        | false    | false    |
+      | 01 April 2024    | Accrual                         | 2.04   | 0.0      
 | 2.04     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Capitalized Income Amortization | 25.0   | 0.0      
 | 25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME_AMORTIZATION" 
transaction with date "14 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 404000       | Interest Income             |       | 25.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 25.0  |       
 |
+    And Loan Amortization Allocation Mapping for "CAPITALIZED_INCOME" 
transaction created on "01 January 2024" contains the following data:
+      | Date          | Type | Amount |
+      | 14 April 2024 | AM   | 25.0   |
+    And Admin adds capitalized income with "AUTOPAY" payment type to the loan 
on "1 January 2024" with "30" EUR transaction amount
+    When Admin adds capitalized income adjustment with "AUTOPAY" payment type 
to the loan on "01 January 2024" with "5" EUR transaction amount
+    When Admin sets the business date to "16 April 2024"
+    And Admin runs inline COB job for Loan
+    Then Loan Transactions tab has the following data:
+      | Transaction date | Transaction Type                | Amount | 
Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
+      | 01 January 2024  | Disbursement                    | 100.0  | 0.0      
 | 0.0      | 0.0  | 0.0       | 100.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income              | 50.0   | 50.0     
 | 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment   | 25.0   | 25.0     
 | 0.0      | 0.0  | 0.0       | 125.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income              | 30.0   | 30.0     
 | 0.0      | 0.0  | 0.0       | 155.0        | false    | false    |
+      | 01 January 2024  | Capitalized Income Adjustment   | 5.0    | 5.0      
 | 0.0      | 0.0  | 0.0       | 150.0        | false    | false    |
+      | 01 April 2024    | Accrual                         | 2.04   | 0.0      
 | 2.04     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 14 April 2024    | Capitalized Income Amortization | 25.0   | 0.0      
 | 25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+      | 15 April 2024    | Capitalized Income Amortization | 25.0   | 0.0      
 | 25.0     | 0.0  | 0.0       | 0.0          | false    | false    |
+    And Loan Amortization Allocation Mapping for the "1"th 
"CAPITALIZED_INCOME" transaction created on "01 January 2024" contains the 
following data:
+      | Date          | Type   | Amount |
+      | 14 April 2024 | AM     | 25.0   |
+      | 15 April 2024 | AM_ADJ | 5.0    |
+    And Loan Amortization Allocation Mapping for the "2"th 
"CAPITALIZED_INCOME" transaction created on "01 January 2024" contains the 
following data:
+      | Date          | Type   | Amount |
+      | 15 April 2024 | AM     | 30.0   |
+    And Loan Transactions tab has a "CAPITALIZED_INCOME_AMORTIZATION" 
transaction with date "15 April 2024" which has the following Journal entries:
+      | Type      | Account code | Account name                | Debit | 
Credit |
+      | INCOME    | 404000       | Interest Income             |       | 30.0  
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income |       | 5.0   
 |
+      | LIABILITY | 145024       | Deferred Capitalized Income | 30.0  |       
 |
+      | INCOME    | 404000       | Interest Income             | 5.0   |       
 |
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java
index 18a91d5b8d..b81b40aab4 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java
@@ -316,12 +316,25 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
                     }
 
                     if (mapping == null) {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
-                                creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
-                                glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
creditAccountType.getValue(),
+                                    glAccountBalanceHolder);
+                        }
                     } else {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId, mapping.getGlAccount(),
-                                
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    mapping.getGlAccount(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
mapping.getGlAccount(),
+                                    glAccountBalanceHolder);
+                        }
                     }
                 });
             }
@@ -340,12 +353,25 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
                     }
 
                     if (mapping == null) {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
-                                creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
-                                glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
creditAccountType.getValue(),
+                                    glAccountBalanceHolder);
+                        }
                     } else {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId, mapping.getGlAccount(),
-                                
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    mapping.getGlAccount(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
mapping.getGlAccount(),
+                                    glAccountBalanceHolder);
+                        }
                     }
                 });
             }
@@ -550,7 +576,7 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
                 populateCreditDebitMaps(loanProductId, interestAmount, 
paymentTypeId, creditAccountType.getValue(),
                         
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
glAccountBalanceHolder);
             } else {
-                
classificationCodeValues.stream().forEach(classificationCodeValue -> {
+                classificationCodeValues.forEach(classificationCodeValue -> {
                     ProductToGLAccountMapping mapping = null;
                     if (classificationCodeValue.getReferenceValueId() != null) 
{
                         mapping = 
fetchAdvanceAccountingMappingForCodeValue(loanProductId, 
classificationCodeValue.getReferenceValueId(),
@@ -558,12 +584,25 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
                     }
 
                     if (mapping == null) {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
-                                creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
-                                glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
creditAccountType.getValue(),
+                                    glAccountBalanceHolder);
+                        }
                     } else {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId, mapping.getGlAccount(),
-                                
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    mapping.getGlAccount(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
mapping.getGlAccount(),
+                                    glAccountBalanceHolder);
+                        }
                     }
                 });
             }
@@ -582,12 +621,25 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
                     }
 
                     if (mapping == null) {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
-                                creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
-                                glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    creditAccountType.getValue(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
creditAccountType.getValue(),
+                                    glAccountBalanceHolder);
+                        }
                     } else {
-                        populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId, mapping.getGlAccount(),
-                                
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
glAccountBalanceHolder);
+                        if 
(MathUtil.isGreaterThanZero(classificationCodeValue.getAmount())) {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount(), paymentTypeId,
+                                    mapping.getGlAccount(), 
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(),
+                                    glAccountBalanceHolder);
+                        } else {
+                            populateCreditDebitMaps(loanProductId, 
classificationCodeValue.getAmount().negate(), paymentTypeId,
+                                    
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), 
mapping.getGlAccount(),
+                                    glAccountBalanceHolder);
+                        }
                     }
                 });
             }
@@ -898,6 +950,17 @@ public class AccrualBasedAccountingProcessorForLoan 
implements AccountingProcess
         }
     }
 
+    private void populateCreditDebitMaps(final Long loanProductId, final 
BigDecimal transactionPartAmount, final Long paymentTypeId,
+            final Integer creditAccountType, final GLAccount accountDebit, 
final GLAccountBalanceHolder glAccountBalanceHolder) {
+        if (MathUtil.isGreaterThanZero(transactionPartAmount)) {
+            // Resolve Credit
+            final GLAccount accountCredit = 
this.helper.getLinkedGLAccountForLoanProduct(loanProductId, creditAccountType, 
paymentTypeId);
+            glAccountBalanceHolder.addToCredit(accountCredit, 
transactionPartAmount);
+            // Resolve Debit
+            glAccountBalanceHolder.addToDebit(accountDebit, 
transactionPartAmount);
+        }
+    }
+
     private void createJournalEntriesForChargeAdjustment(LoanDTO loanDTO, 
LoanTransactionDTO loanTransactionDTO, Office office) {
         final boolean isMarkedAsChargeOff = loanDTO.isMarkedAsChargeOff();
         if (isMarkedAsChargeOff) {
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
index 973a279441..c4f589c2fb 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
@@ -91,6 +91,7 @@ import org.apache.fineract.portfolio.PortfolioProductType;
 import org.apache.fineract.portfolio.loanaccount.data.AccountingBridgeDataDTO;
 import 
org.apache.fineract.portfolio.loanaccount.data.AccountingBridgeLoanTransactionDTO;
 import org.apache.fineract.portfolio.loanaccount.data.LoanChargePaidByDTO;
+import org.apache.fineract.portfolio.loanaccount.domain.AmortizationType;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
 import 
org.apache.fineract.portfolio.loanaccount.domain.LoanAmortizationAllocationMapping;
 import 
org.apache.fineract.portfolio.loanaccount.domain.LoanAmortizationAllocationMappingRepository;
@@ -881,18 +882,21 @@ public class 
JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
     }
 
     private List<AdvancedMappingtDTO> getLoanTransactionClassificationId(final 
LoanTransaction loanTransaction) {
-        List<AdvancedMappingtDTO> advancedMappingData = new 
ArrayList<AdvancedMappingtDTO>();
+        final List<AdvancedMappingtDTO> advancedMappingData = new 
ArrayList<AdvancedMappingtDTO>();
         if (loanTransaction.isCapitalizedIncomeAmortization() || 
loanTransaction.isBuyDownFeeAmortization()) {
             final List<LoanAmortizationAllocationMapping> 
loanTransactionAllocations = loanAmortizationAllocationMappingRepository
                     
.fetchLoanTransactionAllocationByAmortizationLoanTransactionId(loanTransaction.getId(),
                             loanTransaction.getLoan().getId());
-            
loanTransactionAllocations.stream().forEach(loanTransactionAllocation -> {
+            loanTransactionAllocations.forEach(loanTransactionAllocation -> {
                 final CodeValue classification = loanTransactionRepository
                         
.fetchClassificationCodeValueByTransactionId(loanTransactionAllocation.getBaseLoanTransactionId());
+                final BigDecimal allocationAmount = 
loanTransactionAllocation.getAmortizationType().equals(AmortizationType.AM)
+                        ? loanTransactionAllocation.getAmount()
+                        : loanTransactionAllocation.getAmount().negate();
                 if (classification != null) {
-                    advancedMappingData.add(new 
AdvancedMappingtDTO(classification.getId(), 
loanTransactionAllocation.getAmount()));
+                    advancedMappingData.add(new 
AdvancedMappingtDTO(classification.getId(), allocationAmount));
                 } else {
-                    advancedMappingData.add(new AdvancedMappingtDTO(null, 
loanTransactionAllocation.getAmount()));
+                    advancedMappingData.add(new AdvancedMappingtDTO(null, 
allocationAmount));
                 }
             });
         }

Reply via email to