SELECT 
    jel.id,
    je.entry_date as date,
    je.entry_number,
    je.id as journal_entry_id,
    je.description as journal_description,
    coa.account_code,
    coa.account_name,
    jel.description,
    jel.debit,
    jel.credit,
    CASE WHEN jel.debit > 0 THEN "debit" ELSE "credit" END as entry_type,
    CASE WHEN jel.debit > 0 THEN jel.debit ELSE jel.credit END as amount
FROM journal_entry_lines jel
JOIN journal_entries je ON jel.entry_id = je.id
JOIN chart_of_accounts coa ON jel.account_id = coa.id
WHERE je.status = "posted"