<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Mouse Chow  
    $Date: 2012-12-24 下午06:23:25  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="LCH_LEASE_CHANCE_RENT_CALC">
    <bm:fields>
        <bm:field name="process_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PROCESS_ID" prompt="LCH_LEASE_CHANCE_RENT_CALC.PROCESS_ID"/>
        <bm:field name="lease_chance_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LEASE_CHANCE_ID" prompt="LCH_LEASE_CHANCE_RENT_CALC.LEASE_CHANCE_ID"/>
        <bm:field name="sale_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SALE_AMOUNT" prompt="LCH_LEASE_CHANCE_RENT_CALC.SALE_AMOUNT"/>
        <bm:field name="downpay_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOWNPAY_AMOUNT" prompt="LCH_LEASE_CHANCE_RENT_CALC.DOWNPAY_AMOUNT"/>
        <bm:field name="lease_start_date" databaseType="DATE" datatype="java.util.Date" physicalName="LEASE_START_DATE" prompt="LCH_LEASE_CHANCE_RENT_CALC.LEASE_START_DATE"/>
        <bm:field name="payment_start_date" databaseType="DATE" datatype="java.util.Date" physicalName="PAYMENT_START_DATE" prompt="LCH_LEASE_CHANCE_RENT_CALC.PAYMENT_START_DATE"/>
        <bm:field name="periods_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PERIODS_COUNT" prompt="LCH_LEASE_CHANCE_RENT_CALC.PERIODS_COUNT"/>
        <bm:field name="payment_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PAYMENT_TYPE" prompt="LCH_LEASE_CHANCE_RENT_CALC.PAYMENT_TYPE"/>
        <bm:field name="fixed_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIXED_FLAG" prompt="LCH_LEASE_CHANCE_RENT_CALC.FIXED_FLAG"/>
        <bm:field name="year_interest_rate" databaseType="NUMBER" datatype="java.lang.Long" physicalName="YEAR_INTEREST_RATE" prompt="LCH_LEASE_CHANCE_RENT_CALC.YEAR_INTEREST_RATE"/>
        <bm:field name="version_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="VERSION_DESC" prompt="LCH_LEASE_CHANCE_RENT_CALC.VERSION_DESC"/>
        <bm:field name="interest_rate" physicalName="year_interest_rate"/>
        <bm:field name="irr"/>
        <bm:field name="npv"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="process_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="process_id" queryOperator="="/>
        <bm:query-field field="lease_chance_id" queryOperator="="/>
    </bm:query-fields>
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
    		
    			begin
    				delete from LCH_LEASE_CHANCE_RENT_CALC l where l.process_id = ${@process_id} and l.lease_chance_id = ${@lease_chance_id};
    				
    				insert into LCH_LEASE_CHANCE_RENT_CALC
    				(
	    				process_id,
    					lease_chance_id,
    					sale_amount,
    					downpay_amount,
    					lease_start_date,
    					payment_start_date,
    					periods_count,
    					payment_type,
    					fixed_flag,
    					year_interest_rate,
    					version_desc,
    					created_by,
    					creation_date,
    					last_updated_by,
    					last_update_date
    				)
    				values
    				(
    					${@process_id},
    					${@lease_chance_id},
    					${@sale_amount},
    					${@downpay_amount},
    					to_date(${@lease_start_date},'yyyy-mm-dd'),
    					to_date(${@payment_start_date},'yyyy-mm-dd'),
    					${@periods_count},
    					${@payment_type},
    					${@fixed_flag},
    					${@interest_rate},
    					${@version_desc},
    					${/session/@user_id},
    					sysdate,
    					${/session/@user_id},
    					sysdate
    				);
    			end;
    		
    		]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
