<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-5-22 下午01:53:57  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    t1.*
                FROM
                    (SELECT
                        t.bp_id_tenant,
                        t.contract_id,
                        t.project_id,
                        t.business_type,
                        t.contract_number,
                        t.contract_name,
                        (SELECT
                            p1.project_number
                        FROM
                            prj_project p1
                        WHERE
                            p1.project_id = t.project_id
                        ) project_number,
                        (SELECT
                            p2.project_name
                        FROM
                            prj_project p2
                        WHERE
                            p2.project_id = t.project_id
                        ) project_name,
                        t.currency,
                        (SELECT
                            g.currency_name
                        FROM
                            gld_currency_vl g
                        WHERE
                            g.currency_code = t.currency
                        ) AS currency_desc
                    FROM
                        con_contract t
                    WHERE
                        t.contract_status NOT IN ('PENDING','CLOSED') AND
                        t.data_class           = 'NORMAL'
                    ORDER BY
                        t.contract_number DESC
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="bp_id_tenant"/>
        <bm:field name="contract_id"/>
        <bm:field name="project_id"/>
        <bm:field name="business_type"/>
        <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"/>
        <bm:field name="project_number" forDisplay="true" forQuery="true" prompt="HLS.PROJECT_NUMBER"/>
        <bm:field name="project_name" forDisplay="true" forQuery="true" prompt="HLS.PROJECT_NAME"/>
        <bm:field name="currency"/>
        <bm:field name="currency_desc"/>
    </bm:fields>
    <bm:features>
        <s:bm-script><![CDATA[
        	var cx = Packages.leaf.javascript.Context.getCurrentContext();
        	Packages.leaf.plugin.script.engine.ScriptImportor.defineExternScript(cx, this, $ctx.getData(), "aut_authority_bm_validate.js");
    	]]></s:bm-script>
    </bm:features>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field field="project_number" queryOperator="like"/>
        <bm:query-field name="bp_id_tenant" queryExpression="(t1.bp_id_tenant =  (decode(nvl(${@bp_limit_flag},&apos;N&apos;),&apos;N&apos;,${@bp_id_tenant},&apos;Y&apos;,t1.bp_id_tenant)))"/>
        <bm:query-field name="document_type" queryExpression="t1.document_type = ${@document_type}"/>
        <bm:query-field name="project_name" queryExpression="t1.project_name like &apos;%&apos; || ${@project_name} || &apos;%&apos; "/>
        <bm:query-field name="contract_name" queryExpression="t1.contract_name like &apos;%&apos; || ${@contract_name} || &apos;%&apos; "/>
        <bm:query-field name="not_master_contract_flag" queryExpression="${@not_master_contract_flag}=&apos;Y&apos; and t1.business_type!=&apos;MASTER_CONTRACT&apos;"/>
        <bm:query-field name="inception_flag" queryExpression="(${@inception_flag}=&apos;N&apos; and t1.contract_status !=&apos;INCEPT&apos;)"/>
        <bm:query-field name="sign_flag" queryExpression="(${@sign_flag}=&apos;Y&apos; and t1.contract_status =&apos;NEW&apos;)"/>
        <!--  <ns1:query-field name="con_writeoff_flag" queryExpression="(${@con_writeoff_flag}=&apos;Y&apos; and t1.contract_status not in(&apos;PENDING&apos;))"/> -->
        <bm:query-field name="change_req_flag" queryExpression="(${@change_req_flag}=&apos;Y&apos; and t1.contract_status in(&apos;NEW&apos;,&apos;SIGN&apos;,&apos;PAID&apos;,&apos;INCEPT&apos;))"/>
        <!-- <ns1:query-field name="transaction_id" queryExpression="exists(select 1 from csh_transaction t,con_contract_bp b where t.transaction_id=${@transaction_id} and t.bp_id=b.bp_id and b.contract_id=t1.contract_id)"/> -->
        <bm:query-field name="review_flag" queryExpression="(${@review_flag}=&apos;Y&apos; and t1.contract_status =&apos;SIGN&apos;)"/>
    </bm:query-fields>
    <bm:data-filters><![CDATA[
    ]]></bm:data-filters>
</bm:model>
