<?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.outstanding_prin_tax_incld, 'FM999,999,999,990.00') rental_incld,
                    TO_CHAR(ccc.net_principal, 'FM999,999,999,990.00') principal,
                    TO_CHAR(ccc.net_interest, 'FM999,999,999,990.00') interest,
                    TO_CHAR(ccc.due_amount, 'FM999,999,999,990.00') rental,
                    nvl((select to_char(nvl(t.due_amount, 0), 'FM999,999,999,990.00')
             from con_contract_cashflow t
            where t.contract_id = ccc.contract_id
              and t.times = ccc.times
              and t.cf_item = 3),
           0) lease_charge,
       to_char(ccc.due_amount + nvl((select t.due_amount
                                      from con_contract_cashflow t
                                     where t.contract_id = ccc.contract_id
                                       and t.times = ccc.times
                                       and t.cf_item = 3),
                                    0),
               'FM999,999,999,990.00') sum_due_amount
                FROM
                    con_contract_cashflow ccc
                WHERE
                    ccc.cf_item      = 1 AND
                    ccc.cf_direction = 'INFLOW' AND
                    ccc.cf_status    = 'RELEASE'
                    ) t1
                    #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
