<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Administrator  
    $Date: 2014-8-26 上午9:57:16  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            	  select *
				  from (select a.contract_id,
				               a.virtual_con_number,
				               a.project_id,
				               a.contract_number,
				               a.contract_name,
				               a.finance_amount,
				               a.lease_aomunt_recevied_date,
				               a.pre_incept_date,
				               a.lease_start_date,
				               sign(a.pre_incept_date-sysdate)tag,
				               a.employee_id,
				               a.employee_name,
				               a.unit_id,
				               a.unit_name,
				               to_char(a.inception_of_lease,'yyyy-mm-dd')inception_of_lease,
				               a.lease_channel,
				               a.lease_channel_desc,
				               a.division,
				               a.division_desc,
				               a.bp_id_tenant,
				               a.bp_name,
				               a.owner_user_id,
				               a.lease_organization,
				               a.company_id,
				               a.inception_need_submit_flag,
				               a.incept_req_print_status,
				               nvl(a.incept_before_lend,'N') incept_before_lend,
				               nvl(a.incept_status,'NEW')incept_status,
				               a.contract_status_desc,
				               a.contract_status,
				               a.hn_industry_classification,
				               a.hn_industry_classification_n,
				               a.hn_adjust_review_flag
				          from con_contract_v a
				         where  a.contract_status in('SIGN','INCEPT')
				         ) t1 #WHERE_CLAUSE#
				         order by t1.contract_id desc
			]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:query-sql><![CDATA[
	            begin
	               con_contract_incept_apply_pkg.contract_print_status_update(p_contract_id =>${@contract_id},
	                                        									 p_user_id     =>${/session/@user_id});
	            end;
			]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:query-sql><![CDATA[
		            begin
		               con_contract_incept_apply_pkg.workflow_start(p_contract_id =>${@contract_id},
										                            p_user_id    =>${/session/@user_id});
		            end;
				]]></bm:query-sql>
            <bm:parameters>
                <bm:parameter name="contract_id" output="true" outputPath="@contract_id"/>
                <bm:parameter name="unit_id" input="true" inputPath="@unit_id"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="project_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="virtual_con_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="finance_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="pre_incept_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="lease_aomunt_recevied_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="employee_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="employee_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="lease_channel" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="lease_channel_desc" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="division" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="division_desc" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="incept_before_lend" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="unit_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="unit_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="incept_req_print_status" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="incept_status" databaseType="VARCHAR2" datatype="java.lang.String" lookupCode="CON_WFL_STATUS" lookupField="incept_status_des"/>
        <bm:field name="incept_status_des" forInsert="false" forUpdate="false"/>
        <bm:field name="tag" forInsert="false" forUpdate="false"/>
        <bm:field name="contract_status_desc"/>
        <bm:field name="contract_status"/>
        <bm:field name="inception_need_submit_flag"/>
        <bm:field name="inception_of_lease"/>
        <bm:field name="owner_user_id"/>
        <bm:field name="lease_start_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="lease_organization"/>
        <bm:field name="hn_industry_classification"/>
        <bm:field name="hn_industry_classification_n"/>
        <bm:field name="hn_adjust_review_flag"/>
    </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="incept_status" queryExpression=" nvl(t1.incept_status,&apos;NEW&apos;) in ${:@incept_status}"/>
        <!--         <bm:query-field field="inception_need_submit_flag" queryOperator="="/> -->
        <bm:query-field field="contract_id" queryOperator="="/>
        <bm:query-field field="contract_number" queryOperator="="/>
        <bm:query-field field="employee_id" queryOperator="="/>
        <bm:query-field field="unit_id" queryOperator="="/>
        <bm:query-field field="lease_channel" queryOperator="="/>
        <bm:query-field field="division" queryOperator="="/>
        <bm:query-field field="incept_before_lend" queryOperator="="/>
        <bm:query-field field="contract_status" queryOperator="="/>
        <bm:query-field field="bp_name" queryOperator="like"/>
        <bm:query-field field="contract_name" queryOperator="like"/>
        <bm:query-field name="loan_date_f" queryExpression="t1.loan_date &gt;=to_date(${@loan_date_f},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="loan_date_t" queryExpression="t1.loan_date &lt;=to_date(${@loan_date_t},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="incept_date_f" queryExpression="t1.inception_of_lease &gt;=${@incept_date_f}"/>
        <bm:query-field name="incept_date_t" queryExpression="t1.inception_of_lease &lt;=${@incept_date_t}"/>
        <bm:query-field name="pre_incept_date_f" queryExpression="t1.lease_aomunt_recevied_date &gt;=trunc(to_date(${@pre_incept_date_f},&apos;yyyy-mm-dd&apos;))"/>
        <bm:query-field name="pre_incept_date_t" queryExpression="trunc(t1.lease_aomunt_recevied_date) &lt;=to_date(${@pre_incept_date_t},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="check_flag" queryExpression="${@check_flag}=&apos;Y&apos; and exists(select 1 from con_contract_cashflow ccc  where ccc.contract_id=t1.contract_id and ccc.times=0 and ccc.cf_direction=&apos;OUTFLOW&apos;  and ccc.cf_status=&apos;RELEASE&apos; and ccc.write_off_flag=&apos;FULL&apos;)"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="1" enforceOperations="query" expression="t1.contract_status = ${@contract_status}"/>
        <!-- <bm:data-filter name="2" enforceOperations="query" expression="t.incept_status = ${@incept_status}" />
    	<bm:data-filter name="3" enforceOperations="query" expression="t.inception_need_submit_flag = ${@inception_need_submit_flag}" /> -->
        <!-- <bm:data-filter name="4" enforceOperations="query" expression="t1.owner_user_id = ${/session/@user_id}"/> -->
        <bm:data-filter name="5" enforceOperations="query" expression="t1.company_id = ${/session/@company_id}"/>
        <bm:data-filter name="6" enforceOperations="query" expression="nvl(t1.hn_adjust_review_flag,&apos;N&apos;)=&apos;Y&apos;"/>
    </bm:data-filters>
</bm:model>
