<?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,
                    '第'
                    || change_number_to_cn(ccc.times)
                    || '期租息' times_n,
                    ccc.due_date,
                    ccc.principal,
                    ccc.outstanding_prin_tax_incld,
                    NVL(ccc.interest, 0) interest,
                    NVL(
                    (SELECT
                        NVL(ccct.due_amount, 0)
                    FROM
                        con_contract_cashflow ccct
                    WHERE
                        ccct.contract_id = ccc.contract_id AND
                        ccct.times       = ccc.times AND
                        ccct.cf_item     = 3
                    ), 0) lease_charge,
                    NVL(ccc.interest, 0) + NVL(
                    (SELECT
                        NVL(ccct.due_amount, 0)
                    FROM
                        con_contract_cashflow ccct
                    WHERE
                        ccct.contract_id = ccc.contract_id AND
                        ccct.times       = ccc.times AND
                        ccct.cf_item     = 3
                    ), 0) lease_charge_interest,
                    ccc.billing_status,
                    (SELECT
                        v.code_value_name
                    FROM
                        sys_code_values_v v
                    WHERE
                        v.code       = 'CON_BILLING_STATUS' AND
                        v.code_value = ccc.billing_status
                    ) billing_status_n
                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:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.times in (select cwo.times from csh_write_off cwo where cwo.contract_id =t1.contract_id and nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos;)"/>
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field name="contract_id" queryExpression="t1.contract_id =${@contract_id}"/>
    </bm:query-fields>
</bm:model>
