SELECT
o.ops_assignee_decision_id AS decision_id,
o.id AS charge_operation_id,
t.id AS transaction_id,
dat.mnemonics AS debit_account_type,
ca.id AS credit_account_id,
cat.mnemonics AS credit_account_type,
t.value AS charged_value,
b.start_date,
b.end_date,
b.total_credit - b.total_debit AS current_account_balance
FROM back_office.operation o
JOIN back_office.transaction t
ON t.operation_id = o.id
JOIN back_office.account da
ON da.id = t.debit_account_id
JOIN back_office.account_type dat
ON dat.id = da.account_type_id
JOIN back_office.account ca
ON ca.id = t.credit_account_id
JOIN back_office.account_type cat
ON cat.id = ca.account_type_id
LEFT JOIN back_office.balance b
ON b.account_id = ca.id
AND current_date BETWEEN b.start_date AND b.end_date
WHERE o.id = 79737584
ORDER BY t.id;