<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: mumu  
    $Date: 2013-10-17 下午04:25:28  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="con_contract_rp_ln">
    <bm:fields>
        <bm:field name="rp_agreement_line_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RP_AGREEMENT_LINE_ID"/>
        <bm:field name="rp_agreement_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RP_AGREEMENT_ID"/>
        <bm:field name="due_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DUE_AMOUNT"/>
        <bm:field name="amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="AMOUNT"/>
        <bm:field name="cf_type" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_TYPE"/>
        <bm:field name="cf_item" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_ITEM"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION"/>
        <bm:field name="cf_item_desc" datatype="java.lang.String" expression="(select a.description from hls_cashflow_item a where a.cf_item=t1.cf_item and a.cf_type=t1.cf_type)" forInsert="false" forUpdate="false"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="rp_agreement_line_id"/>
    </bm:primary-key>
    <bm:order-by>
        <bm:order-field name="rp_agreement_line_id"/>
    </bm:order-by>
    <bm:query-fields>
        <bm:query-field field="rp_agreement_id" queryOperator="="/>
    </bm:query-fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
		   select a.rp_agreement_line_id,a.rp_agreement_id,
		       a.cf_item,a.cf_type,a.description,b.description as cf_item_desc,
		       nvl(a.due_amount,0) due_amount,nvl(a.amount,0) amount
		       from con_contract_rp_ln a, hls_cashflow_item b
		       where a.cf_item=b.cf_item
		         and a.cf_type=b.cf_type
		         and b.enabled_flag = 'Y'
		         and a.rp_agreement_id=${@rp_agreement_id}
		       order by rp_agreement_line_id   
         ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
        		update con_contract_rp_ln a 
        			set a.amount = ${@amount},
        				a.last_updated_by = ${/session/user_id},
        				a.last_update_date = sysdate
        		where a.rp_agreement_line_id = ${@rp_agreement_line_id}	
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
