<?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
                        cc.contract_id,
                        ccc.cf_type,
                        ccc.cf_item,
                        ccc.times,
                        TO_CHAR(ccc.calc_date,'YYYY/MM/DD') due_date,
                        TO_CHAR(ccc.due_amount,'FM999,999,999,999.00') due_amount,
                        TO_CHAR(ccc.principal,'FM999,999,999,990.00') principal,
                        TO_CHAR(ccc.interest,'FM999,999,999,999.00') interest,
                        TO_CHAR(((ccc.outstanding_principal + ccc.principal) * (1+nvl(cc.compensation_ratio,0.08))), 'FM999,999,999,999.00') compensation_amount,
                        TO_CHAR((
                                CASE
                                    WHEN
                                        (
                                            cc.finance_amount - cc.finance_amount * (ccc.times * cc.annual_pay_times * 0.02)
                                        )
                                        <= 0
                                    THEN 0
                                    WHEN
                                        (
                                            cc.finance_amount - cc.finance_amount * (ccc.times * cc.annual_pay_times * 0.02)
                                        )
                                        > 0
                                    THEN (cc.finance_amount - cc.finance_amount * (ccc.times * cc.annual_pay_times * 0.02))
                                END),'FM999,999,999,990.00') lease_item_remain_value
                    FROM
                        con_contract cc,
                        con_contract_cashflow ccc
                    WHERE
                        cc.contract_id  = ccc.contract_id AND
                        cc.data_class   = 'NORMAL' AND
                        ccc.cf_type    IN (1, 12) AND
                        ccc.cf_item    IN (1, 12) AND
                        ccc.cf_direction='INFLOW' AND
                        ccc.cf_status   = 'RELEASE'
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.contract_id = ${@contract_id}"/>
    </bm:data-filters>
</bm:model>
