<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2014-11-24 下午06:07:14  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:o="leaf.database.local.oracle" xmlns:f="leaf.database.features" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="YONDA_DOCUMENT_LEND_RECORD_LN" needAccessControl="false">
    <bm:fields>
        <bm:field name="lend_line_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LEND_LINE_ID" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.LEND_LINE_ID"/>
        <bm:field name="lend_header_id" databaseType="NUMBER" datatype="java.lang.Long" insertExpression="${../../@lend_header_id}" physicalName="LEND_HEADER_ID" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.LEND_HEADER_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.CONTRACT_ID"/>
        <bm:field name="cdd_item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_ITEM_ID" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.CDD_ITEM_ID"/>
        <bm:field name="cdd_item_desc" expression="(select ci.description from prj_cdd_item ci where ci.cdd_item_id=t1.cdd_item_id )" forInsert="false" forUpdate="false"/>
        <bm:field name="return_date" databaseType="DATE" datatype="java.util.Date" physicalName="RETURN_DATE"/>
        <bm:field name="lend_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LEND_FLAG"/>
        <bm:field name="return_flag" expression="(case when t1.return_date is null then &apos;N&apos; else &apos;Y&apos; end)" forInsert="false" forUpdate="false"/>
        <bm:field name="ref_v01" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V01" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_V01"/>
        <bm:field name="ref_v02" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V02" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_V02"/>
        <bm:field name="ref_v03" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V03" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_V03"/>
        <bm:field name="ref_v04" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V04" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_V04"/>
        <bm:field name="ref_v05" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V05" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_V05"/>
        <bm:field name="ref_n01" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N01" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_N01"/>
        <bm:field name="ref_n02" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N02" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_N02"/>
        <bm:field name="ref_n03" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N03" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_N03"/>
        <bm:field name="ref_n04" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N04" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_N04"/>
        <bm:field name="ref_n05" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N05" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_N05"/>
        <bm:field name="ref_d01" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D01" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_D01"/>
        <bm:field name="ref_d02" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D02" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_D02"/>
        <bm:field name="ref_d03" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D03" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_D03"/>
        <bm:field name="ref_d04" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D04" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_D04"/>
        <bm:field name="ref_d05" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D05" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.REF_D05"/>
        <bm:field name="doc_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOC_TYPE" prompt="YONDA_DOCUMENT_LEND_RECORD_LN.DOC_TYPE"/>
        <bm:field name="chest_number" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="CHEST_NUMBER"/>
        <bm:field name="docu_number" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="DOCU_NUMBER"/>
        <bm:field name="doc_type_n" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="DOC_TYPE_N"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                    IF ${@judge_lend}='Y' THEN
                        INSERT
                        INTO
                            LEND_CONTENT_LIST
                            (
                                LEND_CONTENT_LIST_ID,
                                LEND_HEADER_ID,
                                CDD_ITEM_ID,
                                CONTRACT_ID,
                                CREATED_BY,
                                CREATION_DATE,
                                LAST_UPDATED_BY,
                                LAST_UPDATE_DATE
                            )
                            VALUES
                            (
                                lend_content_list_s.NEXTVAL,
                                ${../../@lend_header_id},
                                ${@cdd_item_id},
                                ${@contract_id},
                                ${/session/@user_id},
                                sysdate,
                                ${/session/@user_id},
                                sysdate
                            );
                    END IF;
                    
                    UPDATE
                        prj_cdd_item p
                    SET
                        LEND_FLAG= ${@lend_flag}
                    WHERE
                        p.cdd_item_id=${@cdd_item_id} ;
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            	BEGIN
            	  contract_read_workflow_strat.contract_workflow_start(p_lend_header_id =>${@lend_header_id},
                                                       p_user_id => ${/session/@user_id});
            	END;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk sequenceName="yonda_document_lend_ln_s"/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="lend_line_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="contract_id" queryOperator="="/>
        <bm:query-field field="lend_header_id" queryOperator="="/>
    </bm:query-fields>
</bm:model>
