<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-7-17 下午3:30:53  
    $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_ET_HD">
    <bm:fields>
        <bm:field name="et_agreement_id" databaseType="NUMBER" datatype="java.lang.Double" physicalName="ET_AGREEMENT_ID" prompt="CON_CONTRACT_ET_HD.ET_AGREEMENT_ID"/>
        <bm:field name="et_agreement_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ET_AGREEMENT_NUMBER" prompt="CON_CONTRACT_ET_HD.ET_AGREEMENT_NUMBER"/>
        <bm:field name="business_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BUSINESS_TYPE" prompt="CON_CONTRACT_ET_HD.BUSINESS_TYPE"/>
        <bm:field name="document_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE" prompt="CON_CONTRACT_ET_HD.DOCUMENT_TYPE"/>
        <bm:field name="document_category" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_CATEGORY" prompt="CON_CONTRACT_ET_HD.DOCUMENT_CATEGORY"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMPANY_ID" prompt="CON_CONTRACT_ET_HD.COMPANY_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Double" physicalName="CONTRACT_ID" prompt="CON_CONTRACT_ET_HD.CONTRACT_ID"/>
        <!-- <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" prompt="CON_CONTRACT_ET_HD.CONTRACT_NUMBER"/> -->
        <bm:field name="status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="STATUS" prompt="CON_CONTRACT_ET_HD.STATUS"/>
        <bm:field name="termination_date" databaseType="DATE" datatype="java.util.Date" physicalName="TERMINATION_DATE" prompt="CON_CONTRACT_ET_HD.TERMINATION_DATE"/>
        <bm:field name="overdue_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="OVERDUE_AMOUNT" prompt="CON_CONTRACT_ET_HD.OVERDUE_AMOUNT"/>
        <bm:field name="penalty" databaseType="NUMBER" datatype="java.lang.Double" physicalName="PENALTY" prompt="CON_CONTRACT_ET_HD.PENALTY"/>
        <bm:field name="rentals_payable" databaseType="NUMBER" datatype="java.lang.Double" physicalName="RENTALS_PAYABLE" prompt="CON_CONTRACT_ET_HD.RENTALS_PAYABLE"/>
        <bm:field name="discount_total_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DISCOUNT_TOTAL_AMOUNT" prompt="CON_CONTRACT_ET_HD.DISCOUNT_TOTAL_AMOUNT"/>
        <bm:field name="undue_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="undue_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="undue_principal" databaseType="NUMBER" datatype="java.lang.Double" physicalName="UNDUE_PRINCIPAL" prompt="CON_CONTRACT_ET_HD.UNDUE_PRINCIPAL"/>
        <bm:field name="et_interest" databaseType="NUMBER" datatype="java.lang.Double" physicalName="ET_INTEREST" prompt="CON_CONTRACT_ET_HD.ET_INTEREST"/>
        <bm:field name="mgt_fee_after_discount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="MGT_FEE_AFTER_DISCOUNT" prompt="CON_CONTRACT_ET_HD.MGT_FEE_AFTER_DISCOUNT"/>
        <bm:field name="et_fee" databaseType="NUMBER" datatype="java.lang.Double" physicalName="ET_FEE" prompt="CON_CONTRACT_ET_HD.ET_FEE"/>
        <bm:field name="et_total_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="ET_TOTAL_AMOUNT" prompt="CON_CONTRACT_ET_HD.ET_TOTAL_AMOUNT"/>
        <bm:field name="last_paydue_date" databaseType="DATE" datatype="java.util.Date" physicalName="LAST_PAYDUE_DATE" prompt="CON_CONTRACT_ET_HD.LAST_PAYDUE_DATE"/>
        <bm:field name="last_paydue_times" databaseType="NUMBER" datatype="java.lang.Double" physicalName="LAST_PAYDUE_TIMES" prompt="CON_CONTRACT_ET_HD.LAST_PAYDUE_TIMES"/>
        <bm:field name="discount_days" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DISCOUNT_DAYS" prompt="CON_CONTRACT_ET_HD.DISCOUNT_DAYS"/>
        <bm:field name="submit_date" databaseType="DATE" datatype="java.util.Date" physicalName="SUBMIT_DATE" prompt="CON_CONTRACT_ET_HD.SUBMIT_DATE"/>
        <bm:field name="approved_date" databaseType="DATE" datatype="java.util.Date" physicalName="APPROVED_DATE" prompt="CON_CONTRACT_ET_HD.APPROVED_DATE"/>
        <bm:field name="ref_v01" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V01" prompt="CON_CONTRACT_ET_HD.REF_V01"/>
        <bm:field name="ref_v02" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V02" prompt="CON_CONTRACT_ET_HD.REF_V02"/>
        <bm:field name="ref_v03" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V03" prompt="CON_CONTRACT_ET_HD.REF_V03"/>
        <bm:field name="ref_v04" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V04" prompt="CON_CONTRACT_ET_HD.REF_V04"/>
        <bm:field name="ref_v05" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V05" prompt="CON_CONTRACT_ET_HD.REF_V05"/>
        <bm:field name="ref_n01" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N01" prompt="CON_CONTRACT_ET_HD.REF_N01"/>
        <bm:field name="ref_n02" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N02" prompt="CON_CONTRACT_ET_HD.REF_N02"/>
        <bm:field name="ref_n03" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N03" prompt="CON_CONTRACT_ET_HD.REF_N03"/>
        <bm:field name="ref_n04" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N04" prompt="CON_CONTRACT_ET_HD.REF_N04"/>
        <bm:field name="ref_n05" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N05" prompt="CON_CONTRACT_ET_HD.REF_N05"/>
        <bm:field name="ref_n06" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N06"/>
        <bm:field name="ref_n07" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N07"/>
        <bm:field name="ref_n08" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N08"/>
        <bm:field name="ref_n09" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N09"/>
        <bm:field name="ref_n10" databaseType="NUMBER" datatype="java.lang.Double" physicalName="REF_N10"/>
        <bm:field name="discount_exemption" databaseType="NUMBER" datatype="java.lang.Double" physicalName="discount_exemption"/>
        <bm:field name="final_et_fee" databaseType="NUMBER" datatype="java.lang.Double" physicalName="FINAL_ET_FEE"/>
        <bm:field name="ref_d01" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D01" prompt="CON_CONTRACT_ET_HD.REF_D01"/>
        <bm:field name="ref_d02" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D02" prompt="CON_CONTRACT_ET_HD.REF_D02"/>
        <bm:field name="ref_d03" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D03" prompt="CON_CONTRACT_ET_HD.REF_D03"/>
        <bm:field name="ref_d04" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D04" prompt="CON_CONTRACT_ET_HD.REF_D04"/>
        <bm:field name="ref_d05" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D05" prompt="CON_CONTRACT_ET_HD.REF_D05"/>
        <bm:field name="et_profile" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ET_PROFILE" prompt="CON_CONTRACT_ET_HD.ET_PROFILE"/>
        <bm:field name="overdue_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="overdue_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="others_fee" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="note" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="total_amount" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="lease_end_date" expression="(select due_date from con_contract tt1,con_contract_cashflow tt2 where tt1.contract_id = tt2.contract_id and t1.contract_id = tt1.contract_id and tt2.cf_item = 1 and tt2.cf_type = 1 and tt2.times = tt1.lease_times and tt2.cf_status = &apos;RELEASE&apos; and tt2.cf_direction = &apos;INFLOW&apos;)"/>
        <bm:field name="license_number" expression="(SELECT tt3.license_number FROM con_contract_lease_item  tt1,con_contract_item_detail tt2,ast_car_license tt3 WHERE tt1.contract_id = t1.contract_id AND tt1.contract_lease_item_id = tt2.contract_lease_item_id AND tt2.item_detail_id = tt3.item_detail_id AND tt1.enabled_flag = &apos;Y&apos; AND tt3.enabled_flag = &apos;Y&apos;)"/>
        <bm:field name="deposit_deduction_flag" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="balance_deduction_flag" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="debt_fee" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="unpay_insurance_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl((SELECT (ccc.due_amount - ccc.received_amount)           FROM con_contract_cashflow ccc          where ccc.cf_item = 62            and ccc.cf_type = 6            and ccc.times = 0            and ccc.cf_direction = &apos;OUTFLOW&apos;            and ccc.contract_id = t1.contract_id),0) from dual)"/>
        <bm:field name="unpay_travel_tax" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl((SELECT (ccc.due_amount - ccc.received_amount)           FROM con_contract_cashflow ccc          where ccc.cf_item = 83            and ccc.cf_type = 110            and ccc.times = 0            and ccc.cf_direction = &apos;OUTFLOW&apos;            and ccc.contract_id = t1.contract_id),0) from dual)"/>
        <bm:field name="unpay_gps_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl((select ccc.due_amount from con_contract_cashflow ccc where ccc.cf_item = 81 and ccc.cf_type = 110 and ccc.cf_direction = &apos;OUTFLOW&apos; and ccc.contract_id = t1.contract_id),0) from dual)"/>
        <bm:field name="defaults_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(0.05* t1.undue_principal)" insertExpression="(0.05* t1.undue_principal)"/>
        <bm:field name="month_interest_fee" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="test_employee" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select su.description from sys_user su where su.user_id = ${/session/@user_id})"/>
        <bm:field name="note_s" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="finance_amount" databaseType="NUMBER" datatype="java.lang.Double" expression="(select c.finance_amount from con_contract c where c.contract_id=t1.contract_id)"/>
        <bm:field name="collecting_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl(cce.collecting_fee,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="take_back_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl(cce.take_back_fee,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="damages_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl(cce.damages_fee,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="pay_method" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select nvl(cce.pay_method,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="assessment_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl(cce.assessment_fee,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="collection_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl(cce.collection_fee,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="loy_fee" databaseType="NUMBER" datatype="java.lang.Double" expression="(select nvl(cce.loy_fee,0) from con_contract_et_hd cce where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="current_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="write_off_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WRITE_OFF_DESC"/>
        <bm:field name="recovered_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="RECOVERED_AMOUNT"/>
        <bm:field name="loss_assets_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="LOSS_ASSETS_AMOUNT"/>
        <bm:field name="dealers_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DEALERS_AMOUNT"/>
        <bm:field name="risk_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="RISK_AMOUNT"/>
        <bm:field name="write_off_desc_loss" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="balance_amount" expression="(select nvl(a.transaction_amount, 0) - nvl(a.write_off_amount, 0) from csh_transaction a where a.bp_id = (select c.bp_id_agent_level1 from con_contract c where c.contract_id = t1.contract_id) and a.transaction_type = &apos;DEPOSIT&apos; and a.returned_flag != &apos;RETURN&apos;)" forInsert="false" forUpdate="false"/>
        <bm:field name="et_irr" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ET_IRR"/>
        <bm:field name="et_method" expression="(Select cce.et_method  From con_contract_et_hd cce  Where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="et_method_n" expression="(Select decode(cce.et_method,&apos;ET&apos;,&apos;提前结清&apos;,&apos;正常结清&apos;)   From con_contract_et_hd cce  Where cce.et_agreement_id = t1.et_agreement_id)"/>
        <bm:field name="deposit_deduction" expression="(Select t.deposit_deduction From con_contract t Where t.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))"/>
        <bm:field name="deposit_deduction_n" expression="(Select decode(t.deposit_deduction,&apos;1&apos;,&apos;退还&apos;,&apos;抵扣最后几期租金&apos;) From con_contract t Where t.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))"/>

        <bm:field name="deposit" expression="(Select t.deposit From con_contract t Where t.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="residual_value" expression="(Select t.residual_value From con_contract t Where t.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="deposit_deduction_flag_desc" expression="(select sv.code_value_name from sys_code_values_v sv where sv.code = 'YES_OR_NO' and sv.code_value = t1.deposit_deduction_flag)" forInsert="false" forUpdate="false"/>
        <bm:field name="overdue_amt"/>


        <bm:field name="int_rate_display" expression="(select c.int_rate_display from con_contract c where c.contract_id = t1.contract_id)" forInsert="false" forUpdate="false"/>


        <bm:field name="contract_number" expression="(select cc.contract_number from con_contract cc where cc.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_name" expression="(select hbm.bp_name from con_contract cc，hls_bp_master hbm where cc.bp_id_tenant = hbm.bp_id and cc.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_agent" expression="(select hbm.bp_name from con_contract cc，hls_bp_master hbm where cc.bp_id_agent_level1 = hbm.bp_id and  cc.contract_id = (Select contract_id From con_contract_et_hd  Where et_agreement_id =  t1.et_agreement_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="uncollected_charges"  expression="(select (nvl(ch.ref_n02,0)+nvl(ch.ref_n07,0)) from con_contract_et_hd ch where ch.et_agreement_id = t1.et_agreement_id)" prompt="未收手续费"/>
        <bm:field name="deferred_interest" expression="( select nvl(sum(nvl(ccc.due_amount, 0) - nvl(ccc.received_amount, 0)),0) from con_contract_cashflow ccc where ccc.overdue_status = 'N' and ccc.cf_direction = 'INFLOW' and ccc.cf_status = 'RELEASE' and ccc.cf_type in (102,103,104) and ccc.contract_id= (select ch.contract_id from con_contract_et_hd ch where ch.et_agreement_id = t1.et_agreement_id) )" />
        <bm:field name="remittance_amount" databaseType="NUMBER" datatype="java.lang.Double" prompt="CON_CONTRACT_ET_HD.REMITTANCE_AMOUNT"/>
        <bm:field name="remittance_date" databaseType="DATE" datatype="java.util.Date" prompt="CON_CONTRACT_ET_HD.REMITTANCE_DATE"/>
        <bm:field name="cost_reduction" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="reduce_period_interest" databaseType="NUMBER" datatype="java.lang.Double"  prompt="CON_CONTRACT_ET_HD.REDUCE_PERIOD_INTEREST"/>
        <bm:field name="reduce_residual_value" databaseType="NUMBER" datatype="java.lang.Double" prompt="CON_CONTRACT_ET_HD.REDUCE_RESIDUAL_VALUE"/>

        <bm:field name="deposit_by_agent" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="deposit_by_agent_n" expression="(select sv.code_value_name from sys_code_values_v sv where sv.code = 'YES_OR_NO' and sv.code_value = t1.deposit_by_agent)" forInsert="false" forUpdate="false"/>
        <bm:field name="third_party_deposit" expression="(Select nvl(t.third_party_deposit,0) From con_contract t Where t.contract_id = t1.contract_id)" forInsert="false" forUpdate="false"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="et_agreement_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field name="et_agreement_id" queryExpression="et_agreement_id = ${@et_agreement_id}"/>
    </bm:query-fields>
</bm:model>
