<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Icon  
    $Date: 2014-11-3 下午3:22:47  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="inception_of_lease" databaseType="DATE" datatype="java.util.Date"/>
        <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="bp_code" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="lease_item_amount" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="other_fee3" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="insurance_fee" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="pay_req_print_status" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="pay_req_print_status_des" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="cdd_list_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_LIST_ID"/>
        <bm:field name="document_category" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_CATEGORY"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID"/>
        <bm:field name="spv_company_code"/>
        <bm:field name="owner_user_id_n"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            	BEGIN
                    csh_payment_req_pkg.csh_payment_apply(p_contract_id =>${@contract_id}, p_user_id =>${/session/@user_id});
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
        	select * from (
            SELECT cc.contract_id,
               cc.contract_number,
               cc.contract_name,
               cc.inception_of_lease,
               (yonda_individual_pkg.string_combination(p_sql                => 'select b.bp_code from con_contract_bp ccb,hls_bp_master b where ccb.bp_category=''AGENT'' and ccb.bp_id=b.bp_id and ccb.contract_id=',
                                                        p_compare_column_val => cc.contract_id,
                                                        p_division_symbol    => ',')) bp_code,
               (yonda_individual_pkg.string_combination(p_sql                => 'select b.bp_name from con_contract_bp ccb,hls_bp_master b where ccb.bp_category=''AGENT'' and ccb.bp_id=b.bp_id and ccb.contract_id=',
                                                        p_compare_column_val => cc.contract_id,
                                                        p_division_symbol    => ',')) bp_name,
               cc.lease_item_amount,
               cc.other_fee3,
               cc.insurance_fee,
               cc.owner_user_id,
               (SELECT a.description FROM sys_user a WHERE a.user_id = cc.owner_user_id) owner_user_id_n,
               vv.cdd_list_id,
               vv.document_category,
               vv.company_id,
               vv.spv_company_code,
               NVL(cc.pay_req_print_status,'PRINT') pay_req_print_status,
               (SELECT v.code_value_name
                  FROM sys_code_values_v v
                 WHERE v.code = 'CSH506_PRINT_STATUS'
                       AND nvl(cc.pay_req_print_status,'PRINT') = v.code_value) pay_req_print_status_des
          FROM con_contract   cc,
               con_contract_v vv
         WHERE cc.contract_id = vv.contract_id
         ) t1 #WHERE_CLAUSE#
        	]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="contract_number_from" datatype="java.lang.String" queryExpression="t1.contract_number&gt;=${@contract_number_from}"/>
        <bm:query-field name="contract_number_to" datatype="java.lang.String" queryExpression="t1.contract_number&lt;=${@contract_number_to}"/>
        <bm:query-field name="req_date_from" dataType="java.util.Date" queryexpression="t1.inception_of_lease &gt;= ${@req_date_from}"/>
        <bm:query-field name="req_date_to" dataType="java.util.Date" queryexpression="t1.inception_of_lease &lt;= ${@req_date_to}"/>
        <bm:query-field name="amount_from" queryExpression="t1.lease_item_amount&gt;=${@amount_from}"/>
        <bm:query-field name="amount_to" queryExpression="t1.lease_item_amount&lt;=${@amount_to}"/>
        <bm:query-field name="bp_code_from" datatype="java.lang.String" queryExpression="t1.bp_code&gt;=${@bp_code_from}"/>
        <bm:query-field name="bp_code_to" datatype="java.lang.String" queryExpression="t1.bp_code&lt;=${@bp_code_to}"/>
        <bm:query-field name="owner_user_id_n" dataType="java.lang.String" queryExpression="t1.owner_user_id_n like ${@owner_user_id_n}"/>
        <bm:query-field name="pay_req_print_status" dataType="java.lang.String" queryExpression="t1.pay_req_print_status like ${@pay_req_print_status}"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="query" expression="t1.inception_of_lease is not null"/>
        <bm:data-filter enforceOperations="query" expression="exists (select 1               from yonda_doc_status_history t              where t.document_id = t1.contract_id                and t.document_category = &apos;CONTRACT&apos;                and t.status = &apos;280&apos;)"/>
    </bm:data-filters>
    <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:model>
