<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        h.loan_contract_id,
                        (SELECT
                            t.loan_contract_number
                        FROM
                            tre_loan_contract t
                        WHERE
                            t.loan_contract_id = h.loan_contract_id
                        ) loan_contract_number,
                        (SELECT
                            t.loan_contract_name
                        FROM
                            tre_loan_contract t
                        WHERE
                            t.loan_contract_id = h.loan_contract_id
                        ) loan_contract_name,
                        (SELECT
                            t.loan_con_bp_n
                        FROM
                            tre_loan_contract_lv t
                        WHERE
                            t.loan_contract_id = h.loan_contract_id
                        ) loan_con_bp_n,
                        h.withdrawal_num,
                        h.ref_v01,
                        h.ref_v02,
                        h.times,
                        h.repayment_date,
                        h.rental,
                        h.principal,
                        h.interest,
                        h.ref_n01,
                        h.ref_n02,
                        h.repayment_wfl_status_n,
                        h.repayment_status_n,
                        h.ref_v03_n
                    FROM
                        tre_loan_con_repayment_plan_lv h
                    WHERE
                        h.repayment_date BETWEEN NVL(to_date(${@repayment_date_from},'yyyy-mm-dd'),h.repayment_date) AND NVL(to_date(${@repayment_date_to},'yyyy-mm-dd'),h.repayment_date)
                    )t #WHERE_CLAUSE#
                    order by loan_contract_number desc
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="loan_contract_number"/>
        <bm:field name="loan_contract_name"/>
        <bm:field name="loan_con_bp_n"/>
        <bm:field name="withdrawal_num"/>
        <bm:field name="ref_v01"/>
        <bm:field name="ref_v02"/>
        <bm:field name="times"/>
        <bm:field name="rental"/>
        <bm:field name="repayment_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="principal"/>
        <bm:field name="interest"/>
        <bm:field name="ref_n01"/>
        <bm:field name="ref_n02"/>
        <bm:field name="repayment_wfl_status_n"/>
        <bm:field name="repayment_status_n"/>
        <bm:field name="ref_v03_n"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="loan_con_bp_n" queryExpression="t.loan_con_bp_n=${@loan_con_bp_n}"/>
    </bm:query-fields>
</bm:model>
