<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hand  
    $Date: 2016-5-2 上午10:15:46  
    $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="CON_CONTRACT_LOCATION_LN">
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
                BEGIN
                    INSERT
                    INTO
                        CON_CONTRACT_LOCATION_LN
                        (
                            CON_CONTRACT_LOCATION_LN,
                            LOCATION_ID,
                            STORAGE,
                            CHEST_NUMBER,
                            CHEST_FLOORS,
                            DOCU_NUMBER,
                            DOCU_AMOUNT,
                            NOTE,
                            DOC_TYPE,
                            doc_number,
                            STORAGE_DATE,
                            CONTRACT_ID,
                            CREATED_BY,
                            CREATION_DATE,
                            LAST_UPDATED_BY,
                            LAST_UPDATE_DATE,
                            LOCATION_CON_STATUS
                        )
                        VALUES
                        (
                            CON_CONTRACT_LOCATION_LN_S.NEXTVAL,
                            ${@location_id},
                            ${@storage},
                            ${@chest_number},
                            ${@chest_floors},
                            ${@docu_number},
                            ${@docu_amount},
                            ${@note},
                            ${@doc_type},
                            ${@doc_number},
                            to_date(${@storage_date},'yyyy-mm-dd'),
                            ${@contract_id},
                            ${/session/@user_id},
                            sysdate,
                            ${/session/@user_id},
                            sysdate,
                            ${@location_con_status}
                        )
                        RETURNING CON_CONTRACT_LOCATION_LN
                    INTO
                        ${@con_contract_location_ln};
                    IF ${@doc_type}='10' THEN
                        UPDATE
                            CON_CONTRACT
                        SET
                            ARCHIVE_STATUS='30'
                        WHERE
                            CONTRACT_ID= ${@contract_id} ;
                    ELSE
                        UPDATE CON_CONTRACT SET REG_STATUS='30' WHERE CONTRACT_ID= ${@contract_id};
                    END IF;
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                BEGIN
                    UPDATE
                        CON_CONTRACT_LOCATION_LN ccll
                    SET
                        ccll.LOCATION_CON_STATUS='history'
                    WHERE
                        ccll.CONTRACT_ID= ${@contract_id} AND
                        ccll.DOC_TYPE   =${@doc_type};
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                    UPDATE
                        CON_CONTRACT_LOCATION_LN t1
                    SET
                        t1.LOCATION_ID        =${@location_id},
                        t1.STORAGE            =${@storage},
                        t1.CHEST_NUMBER       =${@chest_number},
                        t1.CHEST_FLOORS       =${@chest_floors},
                        t1.DOCU_NUMBER        =${@docu_number},
                        t1.DOCU_AMOUNT        =${@docu_amount},
                        t1.NOTE               =${@note},
                        t1.DOC_TYPE           =${@doc_type},
                        t1.STORAGE_DATE       =to_date(${@storage_date},'yyyy-mm-dd'),
                        t1.CONTRACT_ID        =${@contract_id},
                        t1.LOCATION_CON_STATUS=${@location_con_status},
                        t1.DOC_NUMBER         =${@doc_number},
                        t1.LAST_UPDATED_BY    =${/session/@user_id},
                        t1.LAST_UPDATE_DATE   =sysdate
                    WHERE
                        t1.CON_CONTRACT_LOCATION_LN = ${@con_contract_location_ln} AND
                        t1.contract_id              =${@contract_id} AND
                        t1.doc_type                 =${@doc_type};
                        
                    IF ${@doc_type}                 ='10' THEN
                        UPDATE
                            CON_CONTRACT
                        SET
                            ARCHIVE_STATUS='30'
                        WHERE
                            CONTRACT_ID= ${@contract_id} ;
                    ELSE
                        UPDATE CON_CONTRACT SET REG_STATUS='30' WHERE CONTRACT_ID= ${@contract_id};
                    END IF;
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <!--  <bm:operation name="query"><![CDATA[
        SELECT
    t1.CON_CONTRACT_LOCATION_LN,
    t1.LOCATION_ID,
    t1.STORAGE,
    t1.CHEST_NUMBER,
    t1.CHEST_FLOORS,
    t1.DOCU_NUMBER,
    t1.DOCU_AMOUNT,
    t1.NOTE,
    t1.DOC_TYPE,
    t1.STORAGE_DATE,
    t1.CONTRACT_ID,
    t1.LOCATION_CON_STATUS
FROM
    CON_CONTRACT_LOCATION_LN t1  where  t1.CONTRACT_ID= ${@CONTRACT_ID} and  t1.DOC_TYPE=${@doc_type};
        ]]></bm:operation> -->
    </bm:operations>
    <bm:fields>
        <bm:field name="con_contract_location_ln" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CON_CONTRACT_LOCATION_LN" prompt="CON_CONTRACT_LOCATION_LN.CON_CONTRACT_LOCATION_LN"/>
        <bm:field name="location_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LOCATION_ID" prompt="CON_CONTRACT_LOCATION_LN.LOCATION_ID"/>
        <bm:field name="storage" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="STORAGE" prompt="CON_CONTRACT_LOCATION_LN.STORAGE"/>
        <bm:field name="chest_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CHEST_NUMBER" prompt="CON_CONTRACT_LOCATION_LN.CHEST_NUMBER"/>
        <bm:field name="chest_floors" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CHEST_FLOORS" prompt="CON_CONTRACT_LOCATION_LN.CHEST_FLOORS"/>
        <bm:field name="docu_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCU_NUMBER" prompt="CON_CONTRACT_LOCATION_LN.DOCU_NUMBER"/>
        <bm:field name="docu_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOCU_AMOUNT" prompt="CON_CONTRACT_LOCATION_LN.DOCU_AMOUNT"/>
        <bm:field name="note" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="NOTE" prompt="CON_CONTRACT_LOCATION_LN.NOTE"/>
        <bm:field name="doc_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOC_TYPE" prompt="CON_CONTRACT_LOCATION_LN.DOC_TYPE"/>
        <bm:field name="storage_date" databaseType="DATE" datatype="java.util.Date" physicalName="STORAGE_DATE" prompt="CON_CONTRACT_LOCATION_LN.STORAGE_DATE"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CON_CONTRACT_LOCATION_LN.CONTRACT_ID"/>
        <bm:field name="location_con_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LOCATION_CON_STATUS" prompt="CON_CONTRACT_LOCATION_LN.LOCATION_CON_STATUS"/>
        <bm:field name="doc_number" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOC_NUMBER" prompt="CON_CONTRACT_LOCATION_LN.DOC_NUMBER"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="con_contract_location_ln"/>
    </bm:primary-key>
    <bm:data-filters>
        <bm:data-filter name="contract_id" expression="t1.contract_id=${@contract_id}"/>
        <bm:data-filter name="doc_type" expression="t1.doc_type=${@doc_type}"/>
        <bm:data-filter name="location_con_status" expression="t1.location_con_status=&apos;normal&apos;"/>
    </bm:data-filters>
</bm:model>
