<?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,
                        h.repayment_plan_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,
                        h.repayment_type,
                        h.repayment_type_desc
                    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) AND
                        NVL(h.repayment_wfl_status, 'WFL_NEW') IN ('WFL_NEW', 'WFL_REJECTED') AND
                        NVL(h.repayment_status, 'N')            = 'N'
                    )t #WHERE_CLAUSE#
                    order by loan_contract_number desc
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
    			begin
    				DELETE FROM tre_repayment_plan_imp;
				end;
    		]]></bm:update-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:field name="repayment_plan_id"/>
        <bm:field name="repayment_type"/>
        <bm:field name="repayment_type_desc"/>
    </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-field field="loan_contract_number" queryExpression="(SELECT h.loan_contract_number FROM tre_loan_contract h WHERE t.loan_contract_id = h.loan_contract_id )  like  &apos;%&apos; || ${@loan_contract_number} || &apos;%&apos;"/>
        <bm:query-field field="loan_contract_name" queryExpression="(SELECT h.loan_contract_name FROM tre_loan_contract h WHERE t.loan_contract_id = h.loan_contract_id )  like  &apos;%&apos; || ${@loan_contract_name} || &apos;%&apos;"/>
        <bm:query-field field="withdrawal_num" queryExpression="t.withdrawal_num  like  &apos;%&apos; || ${@withdrawal_num} || &apos;%&apos;"/>
    </bm:query-fields>
</bm:model>
