SELECT	r.codigo,
        r.denominacao,
        r.usuario_responsavel,
        SUM(r.saldo_disponivel) AS saldo_disponivel,
        SUM(r.saldo_conciliado) AS saldo_conciliado
    FROM	(
        SELECT cf.codigo,
            cf.denominacao,
            su.nome AS usuario_responsavel,
            SUM(mf.valor_movimento * (POSITION(CAST('1' AS CHAR) IN CAST(tmf.entrada_saida AS CHAR(1))) * 2 - 1)) AS saldo_disponivel,
            CAST(0 AS DECIMAL(12,2)) AS saldo_conciliado
        FROM	movimento_financeiro AS mf
            INNER JOIN tipo_movimento_financeiro AS tmf ON (tmf.id_tipo_movimento_financeiro = mf.id_tipo_movimento_financeiro)
            INNER JOIN conta_financeira AS cf ON (cf.id_conta_financeira = mf.id_conta_financeira)
            INNER JOIN sis_usuario AS su ON (su.id_usuario = cf.id_usuario_responsavel)
        WHERE	mf.data_movimento <= CURRENT_DATE
        AND cf.id_conta_financeira IN (:IdContaFinanceiraAtivaFluxo)

        GROUP BY 1,2,3

        UNION ALL

        SELECT	cf.codigo,
            cf.denominacao,
            su.nome AS usuario_responsavel,
            CAST(0 AS DECIMAL(12,2)) AS saldo_disponivel,
            SUM(mf.valor_movimento * (POSITION(CAST('1' AS CHAR) IN CAST(tmf.entrada_saida AS CHAR(1))) * 2 - 1)) AS saldo_conciliado
        FROM	movimento_financeiro AS mf
            INNER JOIN tipo_movimento_financeiro AS tmf ON (tmf.id_tipo_movimento_financeiro = mf.id_tipo_movimento_financeiro)
            INNER JOIN conta_financeira AS cf ON (cf.id_conta_financeira = mf.id_conta_financeira)
            INNER JOIN sis_usuario AS su ON (su.id_usuario = cf.id_usuario_responsavel)
        WHERE	mf.data_conciliacao <= CURRENT_DATE
        AND cf.id_conta_financeira IN (:IdContaFinanceiraAtivaFluxo)

        GROUP BY 1,2,3 ) AS r
    GROUP BY r.codigo,
        r.denominacao,
        r.usuario_responsavel
    ORDER BY r.codigo,
        r.denominacao