<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:fields>
        <bm:field name="contract_id"/>
        <bm:field name="contract_number" forDisplay="true" forQuery="true" prompt="HLS.CONTRACT_NUMBER"/>
        <bm:field name="contract_name" forDisplay="true" forQuery="true" prompt="HLS.CONTRACT_NAME" displayWidth="350"/>
        <bm:field name="bp_id_tenant"/>
        <bm:field name="bp_name"/>
        <bm:field name="bp_id_agent_level1"/>
        <bm:field name="bp_id_agent_level1_n"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                select *
                  from (select cc.contract_id,
                               cc.contract_number,
                               cc.contract_name,
                               cc.bp_id_agent_level1,
                                (SELECT hb.bp_name
                                          FROM hls_bp_master hb
                                         WHERE hb.bp_id = cc.bp_id_agent_level1) bp_id_agent_level1_n,
                                cc.bp_id_tenant,
                                (SELECT hb.bp_name
                                          FROM hls_bp_master hb
                                         WHERE hb.bp_id = cc.bp_id_tenant) bp_name
                          from con_contract            cc
                         where cc.data_class = 'NORMAL'
                           and acr_invoice_pkg.check_rl_flag(cc.contract_id) = 'Y') t1
                 #WHERE_CLAUSE# #ORDER_BY_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <!--<bm:query-field name="bp_id_agent_level1" queryExpression="((t1.bp_id_agent_level1=${@bp_id_agent_level1}) or exists (select 1 from con_contract_lease_item ccli,hls_lease_item hli where ccli.lease_item_id=hli.lease_item_id and hli.vender_id=${@bp_id_agent_level1} and t1.contract_id=ccli.contract_id))"/>-->
        <bm:query-field field="bp_id_tenant"  queryExpression="t1.bp_id_tenant=${@bp_id_tenant}" />
        <bm:query-field name="contract_name" queryExpression="t1.contract_name like &apos;%&apos;||${@contract_name}||&apos;%&apos;"/>
    </bm:query-fields>
</bm:model>
