<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-10-30 上午10:59:57  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:e="leaf.service.exception" xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="CON_CONTRACT_PAYMENT_TERMS" defaultOrderBy="t1.payment_terms_id desc">
    <bm:fields>
        <bm:field name="payment_terms_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PAYMENT_TERMS_ID" prompt="CON_CONTRACT_PAYMENT_TERMS.PAYMENT_TERMS_ID"/>
        <bm:field name="cashflow_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CASHFLOW_ID" prompt="CON_CONTRACT_PAYMENT_TERMS.CASHFLOW_ID"/>
        <bm:field name="cdd_item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_ITEM_ID" prompt="CON_CONTRACT_PAYMENT_TERMS.CDD_ITEM_ID"/>
        <bm:field name="required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REQUIRED_FLAG" prompt="CON_CONTRACT_PAYMENT_TERMS.REQUIRED_FLAG"/>
        <bm:field name="cdd_item" expression="(select d.cdd_item from prj_cdd_item d where d.cdd_item_id=t1.cdd_item_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="cdd_item_name" expression="(select d.description from prj_cdd_item d where d.cdd_item_id=t1.cdd_item_id)" forInsert="false" forUpdate="false"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
             begin
            	con_contract_payment_terms_pkg.insert_cdd_payment_terms(
        			 p_payment_terms_id =>${@payment_terms_id},
                     p_cashflow_id      =>${@cashflow_id},
                     p_cdd_item         =>${@cdd_item},
                     p_cdd_item_name    =>${@cdd_item_name},
                     p_cdd_item_id      =>${@cdd_item_id},
                     p_required_flag    =>${@required_flag},
                     p_user_id          =>${/session/@user_id}
                 );
              end;
    		]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="payment_terms_id" dataType="java.lang.Long" input="false" output="true" outputPath="@payment_terms_id"/>
                <bm:parameter name="cdd_item_id" dataType="java.lang.Long" input="true" output="true" outputPath="@cdd_item_id"/>
                <bm:parameter name="cdd_item" dataType="java.lang.String" input="true" output="true" outputPath="@cdd_item"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
            begin
            	con_contract_payment_terms_pkg.delete_con_payment_terms(
        			 p_payment_terms_id =>${@payment_terms_id},
                     p_user_id          =>${/session/@user_id}
                 );
            end;
    		]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="payment_terms_id"/>
    </bm:primary-key>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.cashflow_id=${@cashflow_id}"/>
    </bm:data-filters>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="CON210.CDD_ITEM_DISTINCT"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
</bm:model>
