<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-6-24 下午04:30:53  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:f="leaf.database.features" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="CON_CONTRACT_V" defaultOrderBy="t1.contract_number desc">
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CON301.CON_CONTRACT_V.CONTRACT_ID"/>
        <bm:field name="calc_session_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CALC_SESSION_ID" prompt="CON301.CON_CONTRACT_V.CALC_SESSION_ID"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" prompt="CON301.CON_CONTRACT_V.CONTRACT_NUMBER"/>
        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NAME" prompt="CON301.CON_CONTRACT_V.CONTRACT_NAME"/>
        <bm:field name="business_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BUSINESS_TYPE" prompt="CON301.CON_CONTRACT_V.BUSINESS_TYPE"/>
        <bm:field name="business_type_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BUSINESS_TYPE_DESC" prompt="CON301.CON_CONTRACT_V.BUSINESS_TYPE_DESC"/>
        <bm:field name="project_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PROJECT_ID" prompt="CON301.CON_CONTRACT_V.PROJECT_ID"/>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NUMBER" prompt="CON301.CON_CONTRACT_V.PROJECT_NUMBER"/>
        <bm:field name="project_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NAME" prompt="CON301.CON_CONTRACT_V.PROJECT_NAME"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" prompt="CON301.CON_CONTRACT_V.COMPANY_ID"/>
        <bm:field name="lease_organization" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LEASE_ORGANIZATION" prompt="CON301.CON_CONTRACT_V.LEASE_ORGANIZATION"/>
        <bm:field name="lease_organization_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LEASE_ORGANIZATION_DESC" prompt="CON301.CON_CONTRACT_V.LEASE_ORGANIZATION_DESC"/>
        <bm:field name="lease_channel" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LEASE_CHANNEL" prompt="CON301.CON_CONTRACT_V.LEASE_CHANNEL"/>
        <bm:field name="lease_channel_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LEASE_CHANNEL_DESC" prompt="CON301.CON_CONTRACT_V.LEASE_CHANNEL_DESC"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_TENANT" prompt="CON301.CON_CONTRACT_V.BP_ID_TENANT"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME" prompt="CON301.CON_CONTRACT_V.BP_NAME"/>
        <bm:field name="bp_tenant_class" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_TENANT_CLASS" prompt="CON301.CON_CONTRACT_V.BP_TENANT_CLASS"/>
        <bm:field name="bp_tenant_class_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_TENANT_CLASS_N" prompt="CON301.CON_CONTRACT_V.BP_TENANT_CLASS_N"/>
        <bm:field name="bp_id_agent_level1" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_AGENT_LEVEL1" prompt="CON301.CON_CONTRACT_V.BP_ID_AGENT_LEVEL1"/>
        <bm:field name="bp_id_agent_level2" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_AGENT_LEVEL2" prompt="CON301.CON_CONTRACT_V.BP_ID_AGENT_LEVEL2"/>
        <bm:field name="bp_id_agent_level3" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_AGENT_LEVEL3" prompt="CON301.CON_CONTRACT_V.BP_ID_AGENT_LEVEL3"/>
        <bm:field name="owner_user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="OWNER_USER_ID" prompt="CON301.CON_CONTRACT_V.OWNER_USER_ID"/>
        <!-- <bm:field name="owner_user_id_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="OWNER_USER_ID_N" prompt="CON301.CON_CONTRACT_V.OWNER_USER_ID_N"/> -->
        <bm:field name="employee_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EMPLOYEE_ID" prompt="CON301.CON_CONTRACT_V.EMPLOYEE_ID"/>
        <bm:field name="employee_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EMPLOYEE_CODE" prompt="CON301.CON_CONTRACT_V.EMPLOYEE_CODE"/>
        <bm:field name="employee_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EMPLOYEE_NAME" prompt="CON301.CON_CONTRACT_V.EMPLOYEE_NAME"/>
        <bm:field name="down_payment" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DOWN_PAYMENT" prompt="CON301.CON_CONTRACT_V.DOWN_PAYMENT"/>
        <bm:field name="contract_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_STATUS" prompt="CON301.CON_CONTRACT_V.CONTRACT_STATUS"/>
        <bm:field name="contract_status_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_STATUS_DESC" prompt="CON301.CON_CONTRACT_V.CONTRACT_STATUS_DESC"/>
        <bm:field name="user_status_1" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="USER_STATUS_1" prompt="CON301.CON_CONTRACT_V.USER_STATUS_1"/>
        <!-- <bm:field name="user_status_1_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="USER_STATUS_1_DESC" prompt="CON301.CON_CONTRACT_V.USER_STATUS_1_DESC"/> -->
        <bm:field name="user_status_2" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="USER_STATUS_2" prompt="CON301.CON_CONTRACT_V.USER_STATUS_2"/>
        <bm:field name="user_status_3" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="USER_STATUS_3" prompt="CON301.CON_CONTRACT_V.USER_STATUS_3"/>
        <bm:field name="lease_item_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="LEASE_ITEM_AMOUNT" prompt="CON301.CON_CONTRACT_V.LEASE_ITEM_AMOUNT"/>
        <bm:field name="company_id_n" expression="(select company_full_name from fnd_companies s where s.company_id =t1.company_id)"/>
        <bm:field name="signing_location" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SIGNING_LOCATION"/>
        <bm:field name="signing_user" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SIGNING_USER"/>
        <bm:field name="signing_user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SIGNING_USER_ID"/>
        <bm:field name="signing_date" databaseType="DATE" datatype="java.util.Date" physicalName="SIGNING_DATE"/>
        <bm:field name="zero_times_date" databaseType="DATE" datatype="java.util.Date" physicalName="ZERO_TIMES_DATE"/>
        <bm:field name="bp_vender" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_VENDER"/>
        <bm:field name="document_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE"/>
        <bm:field name="document_type_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE_DESC"/>
        <bm:field name="create_date" databaseType="DATE" datatype="java.util.Date" expression="(select t2.creation_date from con_contract_v t2 where t2.contract_id = t1.contract_id)" physicalName="CREATE_DATE"/>
        <bm:field name="lease_start_date" expression="(to_char(lease_start_date,&apos;yyyy-mm-dd&apos;))"/>
        <!-- <bm:field name="spv_company_name" expression="(select fc.company_short_name from fnd_companies fc where fc.company_id = nvl(t1.spv_company_id,t1.company_id))" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="overdue_status"/> -->
        <!-- <bm:field name="sale_conselor_id"/> -->
        <!-- <bm:field name="sign_name" expression="(select a.saleman_name from CWL_SALEMAN_DEFINE a where a.sale_conselor_id=t1.sale_conselor_id)" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="licenses"/> -->
        <!-- <bm:field name="cdd_list_id" expression="(select cdd_list_id from prj_project a where a.project_id=t1.project_id)"/> -->
        <bm:field name="cdd_list_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_LIST_ID"/>
        <bm:field name="ebank_id"/>
        <bm:field name="ebank_type"/>
        <bm:field name="ebank_account_name"/>
        <bm:field name="ebank_account_num"/>
        <bm:field name="ebank_id_n"/>
        <bm:field name="ebank_type_n"/>
        <bm:field name="division_desc"/>
        <bm:field name="division"/>
        <bm:field name="dd_agreement_status"/>
        <bm:field name="owner_user_id_n" expression="(select a.description from sys_user a where a.user_id=t1.owner_user_id)"/>
        <bm:field name="unit_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UNIT_CODE" prompt="CON301.CON_CONTRACT_V.UNIT_CODE"/>
        <bm:field name="unit_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UNIT_NAME" prompt="CON301.CON_CONTRACT_V.UNIT_NAME"/>
        <bm:field name="credit_status" expression="nvl((select credit_status from con_contract where contract_id = t1.contract_id),&apos;NEW&apos;)"/>
        <bm:field name="comment_text" expression="(select yonda_individual_pkg.string_combination(p_sql =&gt;&apos;select t.comment_text           from yonda_doc_status_history_vl t          where t.document_category = &apos;&apos;PROJECT&apos;&apos;            and t.status = &apos;&apos;290&apos;&apos;            and t.document_id =&apos; , p_compare_column_val =&gt;to_char(t1.project_id) , p_division_symbol =&gt;&apos;-&apos; ) from dual)"/>
        <bm:field name="contract_credit_back"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="contract_id"/>
    </bm:primary-key>
    <bm:features>
        <f:standard-who/>
        <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_id" queryOperator="="/>
        <bm:query-field field="contract_number" queryExpression="contract_number like upper(&apos;%&apos;||${@contract_number}||&apos;%&apos;)"/>
        <bm:query-field field="contract_name" queryExpression="contract_name like upper(&apos;%&apos;||${@contract_name}||&apos;%&apos;)"/>
        <bm:query-field field="project_number" queryExpression="project_number like upper(&apos;%&apos;||${@project_number}||&apos;%&apos;)"/>
        <bm:query-field field="bp_id_tenant" queryOperator="="/>
        <bm:query-field name="lease_item_amount_from" queryExpression="lease_item_amount &gt;= ${@lease_item_amount_from}"/>
        <bm:query-field name="lease_item_amount_to" queryExpression="lease_item_amount &lt;= ${@lease_item_amount_to}"/>
        <bm:query-field field="lease_channel" queryOperator="="/>
        <!--<bm:query-field field="business_type" queryOperator="="/>-->
        <bm:query-field field="lease_organization" queryOperator="="/>
        <bm:query-field field="contract_status" queryOperator="="/>
        <bm:query-field field="owner_user_id" queryOperator="="/>
        <bm:query-field field="division" queryOperator="="/>
        <bm:query-field name="unit_id" queryExpression="t1.unit_id=${@unit_id}"/>
        <bm:query-field name="contract_number_from" queryExpression="contract_number &gt;=${@contract_number_from}"/>
        <bm:query-field name="contract_number_to" queryExpression="contract_number &lt;=${@contract_number_to}"/>
        <bm:query-field field="contract_name" queryOperator="like"/>
        <bm:query-field name="lease_start_date_from" queryExpression="lease_start_date &gt;= to_date(${@lease_start_date_from},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="lease_start_date_to" queryExpression="lease_start_date &lt;= to_date(${@lease_start_date_to},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="down_payment_from" queryExpression="down_payment &gt;= ${@down_payment_from}"/>
        <bm:query-field name="down_payment_to" queryExpression="down_payment &lt;= ${@down_payment_to}"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.contract_status IN (&apos;NEW&apos;) and t1.data_class=&apos;NORMAL&apos; AND t1.print_status = &apos;PRINTED&apos; and t1.con_content_confirm_status = &apos;Y&apos;  and (nvl(t1.credit_status,&apos;NEW&apos;) not in ( &apos;SUBMIT&apos;,&apos;APPROVED&apos;) or nvl(t1.legal_status,&apos;NEW&apos;) not in ( &apos;SUBMIT&apos;,&apos;APPROVED&apos;))"/>
        <!-- <bm:data-filter enforceOperations="query" expression="exists (select 1 from con_contract where contract_id = t1.contract_id and nvl(credit_status,&apos;NEW&apos;) in (&apos;NEW&apos;,&apos;BACK&apos;,&apos;BACK1&apos;))"/> -->
    </bm:data-filters>
</bm:model>
