<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="TRE_LOAN_CONTRACT_LV">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        tlc.loan_contract_id,
                        tlc.loan_contract_number,
                        tlc.loan_contract_name,
                        tlc.loan_con_bp,
                        tlc.original_con_num,
                        tlc.document_category,
                        tlc.document_type,
                        tlc.loan_con_bp_n,
                        p.document_number,
                        p.quotation_id,
                        p.lease_start_date,
                        p.lease_end_date,
                        tlc.loan_amount,
                        w.amount,
                        tlc.loan_date_from,
                        tlc.loan_date_to,
                        tlc.loan_contract_status,
                        tlc.loan_contract_status_display,
                        tlc.adjust_rate_type
                    FROM
                        tre_loan_contract_lv tlc,
                        tre_loan_con_withdrawal_plan w,
                        prj_quotation p
                    WHERE
                        tlc.loan_contract_id     = w.loan_contract_id AND
                        w.quotation_id           = p.quotation_id AND
                        p.main_contract_flag     = 'N' AND
                        p.wfl_status             = 'APPROVED' AND
                        tlc.loan_contract_status = 'REVIEWED'
                        and tlc.data_class='NORMAL'
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="(t1.loan_contract_status = &apos;REVIEWED&apos;)"/>
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field name="loan_contract_number" queryExpression="t1.loan_contract_number=${@loan_contract_number}"/>
        <bm:query-field name="loan_contract_name" queryExpression="t1.loan_contract_name like &apos;%&apos;||${@loan_contract_name}||&apos;%&apos;"/>
        <bm:query-field name="loan_con_bp_n" queryExpression="t1.loan_con_bp_n like &apos;%&apos;||${@loan_con_bp_n}||&apos;%&apos;"/>
        <bm:query-field name="loan_con_bp" queryExpression="t1.loan_con_bp_code=${@loan_con_bp}"/>
        <bm:query-field name="loan_date_from" queryExpression="t1.loan_date_from &gt;=${@loan_date_from}"/>
        <bm:query-field name="loan_date_to" queryExpression="t1.loan_date_to &lt;=${@loan_date_to}"/>
        <bm:query-field name="document_type" queryExpression="t1.document_type=${@document_type}"/>
        <bm:query-field name="loan_contract_status" queryExpression="t1.loan_contract_status=${@loan_contract_status}"/>
        <bm:query-field name="lease_start_date_from" queryExpression="t1.lease_start_date &gt;=to_date(${@lease_start_date_from},&apos;YYYY-MM-DD&apos;)"/>
        <bm:query-field name="lease_start_date_to" queryExpression="t1.lease_start_date &lt;=to_date(${@lease_start_date_to},&apos;YYYY-MM-DD&apos;)"/>
        <bm:query-field name="lease_end_date_from" queryExpression="t1.lease_end_date &gt;=to_date(${@lease_end_date_from},&apos;YYYY-MM-DD&apos;)"/>
        <bm:query-field name="lease_end_date_to" queryExpression="t1.lease_end_date &lt;=to_date(${@lease_end_date_to},&apos;YYYY-MM-DD&apos;)"/>
    </bm:query-fields>
</bm:model>
