diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java index 10fe6b8b8..8115f66ea 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java @@ -105,7 +105,18 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat .append(" journalEntry.currency_code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ") .append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf, ") .append(" eao.external_id as externalAssetOwner, ") + // entity_type_enum=2 (PortfolioProductType.SAVING) is written for BOTH savings and + // current-account entries -- current products deliberately share SAVING's GL type + // space (see PortfolioProductType.CURRENT's own comment) -- so it cannot tell the two + // apart on its own, and m_savings_account/m_current_account each have their own id + // sequence: an entity_id can be a real row in both, making a plain + // COALESCE(ca.account_no, sa.account_no) pick the current account's number even for + // an entry that is genuinely a savings one. savings_transaction_id is the one + // unambiguous signal available here -- only a real savings transaction sets it -- so + // it decides first; only when it's absent (a current-account entry, or a savings + // entry with no linked transaction row) does the current-account guess apply. .append(" CASE ") + .append(" WHEN journalEntry.entity_type_enum = 2 AND journalEntry.savings_transaction_id IS NOT NULL THEN sa.account_no ") .append(" WHEN journalEntry.entity_type_enum = 2 THEN COALESCE(ca.account_no, sa.account_no) ") .append(" ELSE NULL ") .append(" END as savingsAccountNo ");