<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Guoxuezhao  
    $Date: 2013-6-3 下午2:21:36  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:ns2="leaf.database.local.oracle" xmlns:e="leaf.service.exception" xmlns:f="leaf.database.features" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="TRE_LOAN_CON_REPAYMENT_PLAN" defaultOrderBy="t1.times,t1.repayment_type" needAccessControl="false">
    <bm:fields>
        <bm:field name="repayment_plan_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REPAYMENT_PLAN_ID" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REPAYMENT_PLAN_ID"/>
        <bm:field name="loan_contract_id" databaseType="NUMBER" datatype="java.lang.Long" insertExpression="nvl(${@loan_contract_id},${../../@loan_contract_id})" physicalName="LOAN_CONTRACT_ID" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.LOAN_CONTRACT_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.CONTRACT_ID"/>
        <bm:field name="repayment_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REPAYMENT_TYPE" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REPAYMENT_TYPE"/>
        <bm:field name="cashflow_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CASHFLOW_ID" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.CASHFLOW_ID"/>
        <bm:field name="cashflow_amount" expression="(select d.due_amount from con_contract_cashflow d where d.cashflow_id=t1.cashflow_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TIMES" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.TIMES"/>
        <bm:field name="rental" databaseType="NUMBER" datatype="java.lang.Double" physicalName="RENTAL" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.RENTAL"/>
        <bm:field name="deposit_date" databaseType="DATE" datatype="java.util.Date" physicalName="DEPOSIT_DATE" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.DEPOSIT_DATE"/>
        <bm:field name="maturity_date" databaseType="DATE" datatype="java.util.Date" physicalName="MATURITY_DATE" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.MATURITY_DATE"/>
        <bm:field name="repayment_date" databaseType="DATE" datatype="java.util.Date" physicalName="REPAYMENT_DATE" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REPAYMENT_DATE"/>
        <bm:field name="expire_date" databaseType="DATE" datatype="java.util.Date" physicalName="EXPIRE_DATE" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.EXPIRE_DATE"/>
        <bm:field name="discount_days" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DISCOUNT_DAYS" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.DISCOUNT_DAYS"/>
        <bm:field name="amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="AMOUNT" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.AMOUNT"/>
        <bm:field name="principal" databaseType="NUMBER" datatype="java.lang.Double" physicalName="PRINCIPAL" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.PRINCIPAL"/>
        <bm:field name="interest" databaseType="NUMBER" datatype="java.lang.Double" physicalName="INTEREST" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.INTEREST"/>
        <bm:field name="amount_implicit_rt" databaseType="NUMBER" datatype="java.lang.Double" physicalName="AMOUNT_IMPLICIT_RT" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.AMOUNT_IMPLICIT_RT"/>
        <bm:field name="factoring_fee" databaseType="NUMBER" datatype="java.lang.Double" physicalName="FACTORING_FEE" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.FACTORING_FEE"/>
        <bm:field name="factoring_fee_pv" databaseType="NUMBER" datatype="java.lang.Double" physicalName="FACTORING_FEE_PV" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.FACTORING_FEE_PV"/>
        <bm:field name="residue_rental" databaseType="NUMBER" datatype="java.lang.Double" physicalName="RESIDUE_RENTAL" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.RESIDUE_RENTAL"/>
        <bm:field name="ref_v01" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V01" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_V01"/>
        <bm:field name="ref_v02" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V02" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_V02"/>
        <bm:field name="ref_v03" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V03" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_V03"/>
        <bm:field name="ref_v04" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V04" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_V04"/>
        <bm:field name="ref_v05" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V05" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_V05"/>
        <bm:field name="ref_n01" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N01" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_N01"/>
        <bm:field name="ref_n02" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N02" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_N02"/>
        <bm:field name="ref_n03" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N03" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_N03"/>
        <bm:field name="ref_n04" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N04" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_N04"/>
        <bm:field name="ref_n05" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N05" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_N05"/>
        <bm:field name="ref_d01" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D01" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_D01"/>
        <bm:field name="ref_d02" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D02" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_D02"/>
        <bm:field name="ref_d03" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D03" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_D03"/>
        <bm:field name="ref_d04" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D04" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_D04"/>
        <bm:field name="ref_d05" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D05" prompt="TRE_LOAN_CON_REPAYMENT_PLAN.REF_D05"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <ns2:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="repayment_plan_id"/>
    </bm:primary-key>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.loan_contract_id=${@loan_contract_id}"/>
    </bm:data-filters>
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
            begin
  				bgfl_loan_con_inter_cal_pkg.bgfl_loan_con_repayment_create(p_loan_contract_id =>${../../@loan_contract_id},
                                                      	                   p_user_id =>${/session/@user_id});
            end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="同一还款类型同一期数同一保理到期日的还款计划不能重复！"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
</bm:model>
