Adam Saghy created FINERACT-2323:
------------------------------------

             Summary: Journal entry creation for loan charge should support 
multiple legs
                 Key: FINERACT-2323
                 URL: https://issues.apache.org/jira/browse/FINERACT-2323
             Project: Apache Fineract
          Issue Type: Bug
    Affects Versions: 1.11.0
            Reporter: Adam Saghy
            Assignee: Adam Saghy


The below code is fine for supporting multiple accounts for credit leg, but it 
does not support multiple accounts for debit leg:
{code:java}
public void createJournalEntriesForLoanCharges(final Office office, final 
String currencyCode, final Integer accountTypeToBeDebited,
            final Integer accountTypeToBeCredited, final Long loanProductId, 
final Long loanId, final String transactionId,
            final LocalDate transactionDate, final BigDecimal totalAmount, 
final List<ChargePaymentDTO> chargePaymentDTOs) {

        GLAccount receivableAccount = 
getLinkedGLAccountForLoanCharges(loanProductId, accountTypeToBeDebited, null);
        final Map<GLAccount, BigDecimal> creditDetailsMap = new 
LinkedHashMap<>();
        for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) {
            final Long chargeId = chargePaymentDTO.getChargeId();
            final GLAccount chargeSpecificAccount = 
getLinkedGLAccountForLoanCharges(loanProductId, accountTypeToBeCredited, 
chargeId);
            BigDecimal chargeSpecificAmount = chargePaymentDTO.getAmount();

            // adjust net credit amount if the account is already present in the
            // map
            if (creditDetailsMap.containsKey(chargeSpecificAccount)) {
                final BigDecimal existingAmount = 
creditDetailsMap.get(chargeSpecificAccount);
                chargeSpecificAmount = chargeSpecificAmount.add(existingAmount);
            }
            creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount);
        }

        BigDecimal totalCreditedAmount = BigDecimal.ZERO;
        for (final Map.Entry<GLAccount, BigDecimal> entry : 
creditDetailsMap.entrySet()) {
            final GLAccount account = entry.getKey();
            final BigDecimal amount = entry.getValue();
            totalCreditedAmount = totalCreditedAmount.add(amount);
            createDebitJournalEntryForLoan(office, currencyCode, 
receivableAccount, loanId, transactionId, transactionDate, amount);
            createCreditJournalEntryForLoan(office, currencyCode, account, 
loanId, transactionId, transactionDate, amount);
        }

        if (totalAmount.compareTo(totalCreditedAmount) != 0) {
            throw new PlatformDataIntegrityException(
                    "Meltdown in advanced accounting...sum of all charges is 
not equal to the fee charge for a transaction",
                    "Meltdown in advanced accounting...sum of all charges is 
not equal to the fee charge for a transaction",
                    totalCreditedAmount, totalAmount);
        }
    } {code}

This should be enhanced to support multiple accounts to be used as DEBIT 
account and aggregate the amounts.

Also GLAccount receivableAccount = 
getLinkedGLAccountForLoanCharges(loanProductId, accountTypeToBeDebited, null);` 
is a incorrect repository call, as we should never send null to a PK / FK key!

 
*Acceptance criteria*
 * Fix the GLAccount receivableAccount = 
getLinkedGLAccountForLoanCharges(loanProductId, accountTypeToBeDebited, null); 
call and avoid not sending charge id!

 * Rework to support multiple DEBIT gl accounts



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to