<?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
                    t.contract_id,
                    t.contract_number,
                    t.contract_name,
                    (select p.project_number
                        from prj_project p
                        where p.project_id = t.project_id) project_number,
                    (select h.bp_name
                          from hls_bp_master h
                         where h.bp_id = t.bp_id_tenant) bp_name,
                    t.finance_amount,
                    t.lease_execution_date,
                    t.finance_type,
                    t.deposit,
                    (Select bt.description
                          from hls_business_type bt
                         Where bt.business_type = t.business_type) business_type,
                    (SELECT NVL(SUM(NVL(ccc.due_amount, 0)), 0)
		                FROM con_contract_cashflow ccc
		               WHERE ccc.contract_id = t.contract_id
		                 AND ccc.cf_direction <> 'NONCASH'
		                 AND ccc.cf_item in (1,102,103,104)) amount_rent, --租金总额
		             (Select ch.lease_channel
                      from hls_lease_channel ch
                     Where ch.lease_channel =
                           (select cc.lease_channel
                              from con_contract cc
                             where cc.contract_id = t.contract_id)) As lease_channel,
                   (Select ch.description
                      from hls_lease_channel ch
                     Where ch.lease_channel =
                           (select cc.lease_channel
                              from con_contract cc
                             where cc.contract_id = t.contract_id)) As lease_channel_desc
                FROM
                    con_contract t
                    where t.data_class = 'NORMAL'
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="contract_id" forDisplay="false" forQuery="false" prompt="ID"/>
        <bm:field name="contract_number" displayWidth="150" forDisplay="true" forQuery="true" prompt="合同编号"/>
        <bm:field name="bp_name" displayWidth="200" forDisplay="true" forQuery="true" prompt="承租人"/>
        <bm:field name="contract_name" displayWidth="220" forDisplay="false" forQuery="false" prompt="合同名称"/>
        <bm:field name="project_number" displayWidth="100"  forDisplay="true" forQuery="true" prompt="商机编号"/>
        <bm:field name="finance_amount" displayWidth="100" forDisplay="false" forQuery="false" />
        <bm:field name="lease_execution_date" displayWidth="100" forDisplay="false" forQuery="false" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="business_type" displayWidth="100" forDisplay="false" forQuery="false"/>
        <bm:field name="deposit" forDisplay="false"/>
        <bm:field name="amount_rent" forDisplay="false"/>
        <bm:field name="lease_channel" forDisplay="false"/>
        <bm:field name="lease_channel_desc" forDisplay="false"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field field="bp_name" queryOperator="like"/>
        <bm:query-field field="project_number" queryOperator="like"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter expression="( exists (select 1 from aut_trx_user_authorize a1,aut_owner_user_authorize a2 where a1.trx_category = &apos;CONTRACT&apos; and a1.trx_id = t1.contract_id  and trunc(sysdate) between a1.start_date and nvl(a1.end_date,trunc(sysdate)) and a1.user_id = a2.owner_user_id and a1.trx_category = a2.trx_category  and a2.authorized_user_id = ${/session/@user_id} and trunc(sysdate) between a2.start_date and nvl(a2.end_date,trunc(sysdate))))"/>
    </bm:data-filters>
</bm:model>
