# sql.py
GENERAL_LEDGER_SQL = """
SELECT
    j.journal_date,
    j.description,
    l.debit,
    l.credit
FROM journal_lines l
JOIN journal_entries j
  ON j.journal_id = l.journal_id
LEFT JOIN journal_entries child
  ON child.parent_entry_id = j.journal_id
WHERE l.account_id = %(account_id)s
  AND j.journal_date BETWEEN %(date_from)s AND %(date_to)s
  -- 逆仕訳を除外
  AND j.description NOT LIKE '[逆仕訳]%'
  -- 子仕訳（修正後仕訳）を持つ修正前の仕訳を除外
  AND child.journal_id IS NULL
ORDER BY j.journal_date, l.line_id;
"""
