<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2014-12-11 下午2:59:09  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="CON_CONTRACT_ADD_APPLY">
    <bm:fields>
        <bm:field name="apply_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="APPLY_ID" prompt="CON_CONTRACT_ADD_APPLY.APPLY_ID"/>
        <bm:field name="apply_number" databaseType="VARCHAR2" datatype="java.lang.String" insertExpression="(select fnd_code_rule_pkg.get_rule_next_auto_num(&apos;CONTRACT&apos;,&apos;ADDITIONAL CONTRACT&apos;,${/session/@company_id},&apos;&apos;,sysdate,&apos;&apos;,${/session/@user_id}) from dual)" physicalName="APPLY_NUMBER" prompt="CON_CONTRACT_ADD_APPLY.APPLY_NUMBER"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CON_CONTRACT_ADD_APPLY.CONTRACT_ID"/>
        <bm:field name="apply_time" databaseType="DATE" datatype="java.util.Date" insertExpression="sysdate" physicalName="APPLY_TIME" prompt="CON_CONTRACT_ADD_APPLY.APPLY_TIME"/>
        <bm:field name="apply_person" databaseType="VARCHAR2" datatype="java.lang.String" insertExpression="${/session/@user_id}" physicalName="APPLY_PERSON" prompt="CON_CONTRACT_ADD_APPLY.APPLY_PERSON"/>
        <bm:field name="apply_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="APPLY_DESC" prompt="CON_CONTRACT_ADD_APPLY.APPLY_DESC"/>
        <bm:field name="apply_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="APPLY_STATUS" prompt="CON_CONTRACT_ADD_APPLY.APPLY_STATUS"/>
        <bm:field name="legal_opinion" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LEGAL_OPINION" prompt="CON_CONTRACT_ADD_APPLY.LEGAL_OPINION"/>
        <bm:field name="cdd_list_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_LIST_ID" prompt="CON_CONTRACT_ADD_APPLY.CDD_LIST_ID"/>
        <bm:field name="contract_number" forInsert="false" forUpdate="false"/>
        <bm:field name="contract_name" forInsert="false" forUpdate="false"/>
        <bm:field name="apply_person_des" forInsert="false" forUpdate="false"/>
        <bm:field name="apply_status_des" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_code" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_name" forInsert="false" forUpdate="false"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
        <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:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            select * from (
    			select ca.*,
    			(select cc.contract_number from con_contract_v cc where cc.contract_id=ca.contract_id) contract_number,
    			(select cc.contract_name from con_contract_v cc where cc.contract_id=ca.contract_id) contract_name,
    			(select v.description from sys_user_v v where v.user_id=ca.apply_person) apply_person_des,
    			(select v.code_value_name from sys_code_values_v v where v.code='CON571_ADD_APPLY_STATUS' and v.code_value=ca.apply_status) apply_status_des,
    			(select v.bp_code from hls_bp_master_v v where v.bp_id= (select bp.bp_id from con_contract_bp bp where bp.contract_id=ca.contract_id and bp.bp_category='TENANT'))bp_code,
    			(select v.bp_name from hls_bp_master_v v where v.bp_id= (select bp.bp_id from con_contract_bp bp where bp.contract_id=ca.contract_id and bp.bp_category='TENANT'))bp_name
    			 from con_contract_add_apply ca order by ca.last_update_date desc) t1 
    			 #WHERE_CLAUSE#
    		]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="apply_id" queryOperator="="/>
        <bm:query-field field="apply_number" queryOperator="like"/>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field name="apply_time_from" dataType="java.util.Date" queryExpression="t1.apply_time &gt;= ${@apply_time_from}"/>
        <bm:query-field name="apply_time_to" dataType="java.util.Date" queryExpression="t1.apply_time &lt;= ${@apply_time_to}"/>
        <bm:query-field field="apply_status" queryOperator="="/>
    </bm:query-fields>
    <bm:primary-key>
        <bm:pk-field name="apply_id"/>
    </bm:primary-key>
</bm:model>
