<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    pnb.contract_id,
                    ccc.times,
                    ccc.due_date,
                    TO_CHAR(ccc.principal, 'FM999,999,999,990.00') principal,
                    TO_CHAR(ccc.interest, 'FM999,999,999,990.00') interest,
                    NVL(
                    (SELECT
                        TO_CHAR(cct.due_amount, 'FM999,999,999,990.00')
                    FROM
                        con_contract_cashflow cct
                    WHERE
                        cct.contract_id = ccc.contract_id AND
                        cct.cf_item     = 3 AND
                        cct.times       = ccc.times
                    ), 0) lease_charge,
                    TO_CHAR(ccc.principal + ccc.interest +
                    nvl((SELECT
                        cct.due_amount
                    FROM
                        con_contract_cashflow cct
                    WHERE
                        cct.contract_id = ccc.contract_id AND
                        cct.cf_item     = 3 AND
                        cct.times       = ccc.times
                    ),0)+ NVL((SELECT cct.due_amount
                              FROM con_contract_cashflow cct
                             WHERE cct.contract_id = ccc.contract_id
                               AND cct.cf_item = 15
                               AND cct.times = ccc.times),
                            0), 'FM999,999,999,990.00') sum_amount
                FROM
                    con_contract_cashflow ccc,
                    hn_payment_notice_batch pnb
                WHERE
                    pnb.contract_id = ccc.contract_id AND
                    pnb.cashflow_id = ccc.cashflow_id and
                    -- ccc.cf_item     = 1 AND
                    pnb.session_id=${/session/@session_id}
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
