<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: feng
    $Date: 2013-9-11 下午15:13:20
    $Revision: 1.0
    $Purpose:
-->
<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 c.contract_id,
                c.contract_number,
                c.contract_name,
                decode(c.business_type,'LEASE','直租') business_type,
                c.search_term_1,
                (SELECT description
                FROM HLS_BUSINESS_TYPE_V a
                WHERE a.business_type = c.business_type) business_type_n,
                (select pp.project_number
                from PRJ_PROJECT pp, prj_project_lease_item t2
                where t2.source_project_id = pp.project_id
                and c.project_id = t2.project_id) project_number,
                (select bp.bp_name
                from hls_bp_master bp
                where bp.bp_id =
                (SELECT pp.bp_id_tenant
                FROM PRJ_PROJECT            pp,
                prj_project_lease_item t2
                WHERE t2.source_project_id = pp.project_id
                and c.project_id = t2.project_id)) bp_id_tenant_n
                from con_contract c
                where c.data_class = 'NORMAL'
                and c.contract_status IN
                ('REPURING', 'ETING', 'INCEPT', 'PENDING')
                and c.business_type not in ('LEASEBACK', 'LEASEOPERAT')
                and not exists
                (select 1
                from acp_invoice_ln an
                where an.contract_id = c.contract_id
                and an.confirmation_status in
                ('APPROVING', 'APPROVED'))
                union
                select c.contract_id,
                c.contract_number,
                ' ' contract_name,
                decode(c.business_type, 'OTHERS', '经营性租赁') business_type,
                c.search_term_1,
                (SELECT description
                FROM HLS_BUSINESS_TYPE_V a
                WHERE a.business_type = c.business_type) business_type_n,
                c.contract_number project_number,
                (select bp.bp_name
                from hls_bp_master bp
                where bp.bp_id = (SELECT pp.bp_id_tenant
                FROM PRJ_PROJECT pp, prj_project_lease_item t2
                WHERE t2.source_project_id = pp.project_id
                and c.project_id = t2.project_id)) bp_id_tenant_n
                from con_contract c, con_contract_cashflow ccc, prj_project pp
                where pp.project_id = c.project_id
                and c.contract_id = ccc.contract_id
                and c.data_class = 'NORMAL'
                and c.business_type = 'OTHERS'
                and pp.purchase_type = 'RENTING'
                and not exists
                (select 1
                from acp_invoice_ln an
                where an.contract_id = c.contract_id
                and an.confirmation_status in ('APPROVING', 'APPROVED'))) V

                #WHERE_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>

    </bm:operations>
    <bm:fields>
<!--        <bm:field name="project_number" forDisplay="true" forQuery="true" prompt="采购单编号"/>-->
        <bm:field name="contract_number" forDisplay="true"  forQuery="true" prompt="合同编号/采购单编号"/>
        <bm:field name="contract_name"  forDisplay="true" forQuery="true" prompt="ACR310.CONTRACT_NAME"/>
        <bm:field name="contract_id"/>
<!--        <bm:field name="bp_id_tenant_n" forDisplay="true" forQuery="true" prompt="厂商"/>-->
<!--        <bm:field name="search_term_1" forDisplay="true" forQuery="true" prompt="厂商合同编号"/>-->
        <bm:field name="business_type" forDisplay="true" forQuery="true" prompt="业务类型"/>
<!--        <bm:field name="business_type" forDisplay="true" forQuery="true" prompt="业务类型"/>-->

    </bm:fields>
<!--    <bm:fields>-->
<!--        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" physicalName="contract_number" prompt="ACR310.CONTRACT_NUMBER"/>-->
<!--        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" physicalName="contract_name" prompt="ACR310.CONTRACT_NAME"/>-->
<!--        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="contract_id" />-->
<!--    </bm:fields>-->
    <bm:query-fields>
<!--        <bm:query-field field="project_number" queryOperator="like"/>-->
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field field="contract_name" queryOperator="like"/>
<!--        <bm:query-field field="bp_id_tenant_n" queryOperator="like"/>-->
<!--        <bm:query-field field="search_term_1" queryOperator="like"/>-->
        <bm:query-field field="business_type" queryOperator="like"/>
<!--        <bm:query-field field="business_type" queryOperator="like"/>-->


    </bm:query-fields>
</bm:model>
