<?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
                    cl.contract_id,
                    cl.contract_number,
                    cl.contract_name,
                    cl.employee_id,
                    cl.employee_id_n,
                    cl.bp_id_tenant,
                    cl.bp_id_tenant_n,
                    cl.division_n,
                    cl.document_type,
                    cl.document_type_n,
                    cl.contract_status,
                    cl.contract_status_n,
                    to_char(cl.lease_start_date,'yyyy-mm-dd')lease_start_date,
                    cl.lease_organization,
                    cl.lease_organization_n,
                    cl.finance_amount,
                    cl.bp_id_agent_level1_n,
                    cl.bp_id_agent_level1,
                    cl.company_id,
                    cl.company_id_n,
                    cl.project_id,
                    cl.project_id_c,
                    decode((SELECT COUNT(*) FROM con_contract_cashflow cf WHERE cf.contract_id = cl.contract_id AND cf.cf_status = 'RELEASE' AND cf.write_off_flag != 'FULL'),0,'Y','N') settle_flag
                FROM
                    con_contract_lv cl where cl.data_class = 'NORMAL'
                    )v
                    #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="contract_id" queryExpression="v.contract_id = ${@contract_id}"/>
        <bm:query-field name="contract_number" queryExpression="v.contract_number like ${@contract_number}"/>
        <bm:query-field name="contract_name" queryExpression="v.contract_name like ${@contract_name}"/>
        <bm:query-field name="lease_start_date_from" queryExpression="v.lease_start_date &gt;= to_date(${@lease_start_date_from},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="lease_start_date_to" queryExpression="v.lease_start_date &lt;= to_date(${@lease_start_date_to},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="bp_id_tenant" queryExpression="v.bp_id_tenant = ${@bp_id_tenant}"/>
        <bm:query-field name="project_number" queryExpression="v.project_id_c = ${@project_number}"/>
        <bm:query-field name="employee_id" queryExpression="v.employee_id = ${@employee_id}"/>
        <bm:query-field name="lease_organization" queryExpression="v.lease_organization = ${@lease_organization}"/>
        <bm:query-field name="document_type" queryExpression="v.document_type = ${@document_type}"/>
        <bm:query-field name="contract_status" queryExpression="v.contract_status = ${@contract_status}"/>
        <bm:query-field name="finance_amount_from" queryExpression="v.finance_amount &gt;= to_number(${@finance_amount_from})"/>
        <bm:query-field name="finance_amount_to" queryExpression="v.finance_amount &lt; = to_number(${@finance_amount_to})"/>
        <bm:query-field name="vender_id" queryExpression="exists (select 1 from prj_project_lease_item_lv il where il.project_id = v.project_id and il.vender_id = ${@vender_id})"/>
        <bm:query-field name="settle_flag" queryExpression="v.settle_flag = ${@settle_flag}"/>
    </bm:query-fields>
</bm:model>
