<?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 * from (
                SELECT
                    ccc.contract_id,
                    ccc.cashflow_id,
                    ccc.times,
                    TO_CHAR(ccc.due_date,'YYYY-MM-DD') due_date,
                    TO_CHAR(ccc.calc_date,'YYYY-MM-DD') calc_date,
                    ccc.due_amount,
                    nvl(ccc.principal,0) principal,
                    ccc.interest,
                    ccc.outstanding_prin_tax_incld,
                    NVL(
                    (SELECT
                        cct.due_amount
                    FROM
                        con_contract_cashflow cct
                    WHERE
                        cct.contract_id = ccc.contract_id AND
                        cct.times       = ccc.times AND
                        cct.cf_item     = 3
                    ), 0) lease_charge,
                    NVL(
                    (SELECT
                        cct.due_amount
                    FROM
                        con_contract_cashflow cct
                    WHERE
                        cct.contract_id = ccc.contract_id AND
                        cct.times       = ccc.times AND
                        cct.cf_item     = 15
                    ), 0) other_fee2,
                    NVL(
                    (SELECT
                        cct.due_amount
                    FROM
                        con_contract_cashflow cct
                    WHERE
                        cct.contract_id = ccc.contract_id AND
                        cct.times       = ccc.times AND
                        cct.cf_item     = 8
                    ), 0) residual_value
                FROM
                    con_contract_cashflow ccc
                    where ccc.cf_item in (0,1)
                    and ccc.cf_direction <> 'NONCASH'
                    ) t1
                    #WHERE_CLAUSE#
                    ORDER BY t1.times
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="contract_id" queryExpression="t1.contract_id=${@contract_id}"/>
    </bm:query-fields>
</bm:model>
