<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm
    $Date: 2013-12-28 下午1:31:12
    $Revision: 1.0
    $Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="CON_UNEARNED_FINANCE_INCOME">
    <bm:fields>
        <bm:field name="seq" databaseType="NUMBER" datatype="java.lang.Long" expression="(row_number() over(order by t1.contract_id))"/>
        <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)" forInsert="false" forUpdate="false"/>
        <bm:field name="interest" databaseType="NUMBER" datatype="java.lang.Double" expression="(select c.interest from con_contract_cashflow c where c.cashflow_id = t1.cashflow_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="int_rate_implicit" databaseType="NUMBER" datatype="java.lang.Double" expression="round((select nvl(c.int_rate,c.annual_mean_rate) from con_contract c where c.contract_id = t1.contract_id),4)" forInsert="false" forUpdate="false"/>
        <bm:field name="calc_period" databaseType="VARCHAR2" datatype="java.lang.String" expression="(to_char(t1.calc_start_date,&apos;yyyy/mm/dd&apos;)||&apos;-&apos;||to_char(t1.calc_end_date,&apos;yyyy/mm/dd&apos;))" forInsert="false" forUpdate="false"/>
        <bm:field name="calc_date_count" databaseType="NUMBER" datatype="java.lang.Long" expression="(t1.calc_end_date-t1.calc_start_date+1)" forInsert="false" forUpdate="false"/>
        <bm:field name="vat_unearned_finance_income" databaseType="NUMBER" datatype="java.lang.Double" expression="(t1.unearned_finance_income*(select decode(t.tax_type_id,1,1,1+(select c.tax_type_rate   from fnd_tax_type_codes c  where c.tax_type_id = t.tax_type_id))  from con_contract t           where t.contract_id = t1.contract_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="unearned_finance_income" databaseType="NUMBER" datatype="java.lang.Double" physicalName="UNEARNED_FINANCE_INCOME" prompt="CON_UNEARNED_FINANCE_INCOME.UNEARNED_FINANCE_INCOME"/>
        <bm:field name="finance_income_recognized" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FINANCE_INCOME_RECOGNIZED" prompt="CON_UNEARNED_FINANCE_INCOME.FINANCE_INCOME_RECOGNIZED"/>
        <bm:field name="record_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID" prompt="CON_UNEARNED_FINANCE_INCOME.RECORD_ID"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" prompt="CON_UNEARNED_FINANCE_INCOME.COMPANY_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CON_UNEARNED_FINANCE_INCOME.CONTRACT_ID"/>

        <bm:field name="net_unearned_finance_income" expression="(t1.unearned_finance_income *        (select decode(t.tax_type_id,                        1,                        1,                        1 + (select c.tax_type_rate                               from fnd_tax_type_codes c                              where c.tax_type_id = t.tax_type_id))            from con_contract t           where t.contract_id = t1.contract_id)-t1.unearned_finance_income)" forInsert="false" forUpdate="false"/>
        <!-- <bm:field name="internal_period_num" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INTERNAL_PERIOD_NUM" prompt="CON_UNEARNED_FINANCE_INCOME.INTERNAL_PERIOD_NUM"/>
        <bm:field name="cf_item" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_ITEM" prompt="CON_UNEARNED_FINANCE_INCOME.CF_ITEM"/>
        <bm:field name="seq_in_period" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SEQ_IN_PERIOD" prompt="CON_UNEARNED_FINANCE_INCOME.SEQ_IN_PERIOD"/>
        <bm:field name="financing_cost" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FINANCING_COST" prompt="CON_UNEARNED_FINANCE_INCOME.FINANCING_COST"/>
        <bm:field name="main_business_income" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MAIN_BUSINESS_INCOME" prompt="CON_UNEARNED_FINANCE_INCOME.MAIN_BUSINESS_INCOME"/>
        <bm:field name="main_business_cost" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MAIN_BUSINESS_COST" prompt="CON_UNEARNED_FINANCE_INCOME.MAIN_BUSINESS_COST"/>
        <bm:field name="unearned_finance_income_balanc" databaseType="NUMBER" datatype="java.lang.Long" physicalName="UNEARNED_FINANCE_INCOME_BALANC" prompt="CON_UNEARNED_FINANCE_INCOME.UNEARNED_FINANCE_INCOME_BALANC"/>
        <bm:field name="weight_factor" databaseType="NUMBER" datatype="java.lang.Long" physicalName="WEIGHT_FACTOR" prompt="CON_UNEARNED_FINANCE_INCOME.WEIGHT_FACTOR"/>
        <bm:field name="total_weight" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TOTAL_WEIGHT" prompt="CON_UNEARNED_FINANCE_INCOME.TOTAL_WEIGHT"/>
        <bm:field name="factor_days" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_DAYS" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_DAYS"/>
        <bm:field name="factor_outstanding_principal" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_OUTSTANDING_PRINCIPAL" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_OUTSTANDING_PRINCIPAL"/>
        <bm:field name="factor_interest_accrual_balanc" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_INTEREST_ACCRUAL_BALANC" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_INTEREST_ACCRUAL_BALANC"/>
        <bm:field name="factor_reserved1" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_RESERVED1" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_RESERVED1"/>
        <bm:field name="factor_reserved2" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_RESERVED2" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_RESERVED2"/>
        <bm:field name="factor_reserved3" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_RESERVED3" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_RESERVED3"/>
        <bm:field name="cashflow_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CASHFLOW_ID" prompt="CON_UNEARNED_FINANCE_INCOME.CASHFLOW_ID"/>
        <bm:field name="times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TIMES" prompt="CON_UNEARNED_FINANCE_INCOME.TIMES"/>
        <bm:field name="cf_type" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_TYPE" prompt="CON_UNEARNED_FINANCE_INCOME.CF_TYPE"/>
        <bm:field name="calc_start_date" databaseType="DATE" datatype="java.util.Date" physicalName="CALC_START_DATE" prompt="CON_UNEARNED_FINANCE_INCOME.CALC_START_DATE"/> -->
        <!-- <bm:field name="calc_end_date" databaseType="DATE" datatype="java.util.Date" physicalName="CALC_END_DATE" prompt="CON_UNEARNED_FINANCE_INCOME.CALC_END_DATE"/> -->
        <!-- <bm:field name="project_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select p.project_name from prj_project p ,con_contract c where c.contract_id = t1.contract_id and p.project_id = c.project_id)" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="period" databaseType="VARCHAR2" datatype="java.lang.String" expression="((SELECT TO_CHAR(cf1.due_date + 1, &apos;yyyy/mm/dd&apos;) FROM con_contract_cashflow cf1 WHERE cf1.contract_id = t1.contract_id AND cf1.cf_item = t1.cf_item AND cf1.times  = (SELECT cf.times - 1 FROM con_contract_cashflow cf WHERE  cf.cashflow_id = t1.cashflow_id )) || &apos;-&apos;||(SELECT TO_CHAR(cf.due_date, &apos;yyyy/mm/dd&apos;) FROM con_contract_cashflow cf WHERE cf.cashflow_id = t1.cashflow_id))" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="current_month_vat_income" databaseType="NUMBER" datatype="java.lang.Double" expression="ROUND((select sum(t.unearned_finance_income*(select decode(t.tax_type_id,1,1,1+(select c.tax_type_rate from fnd_tax_type_codes c where c.tax_type_id = t.tax_type_id)) from con_contract t where t.contract_id = t1.contract_id)) from con_unearned_finance_income t where t.contract_id =t1.contract_id and t.internal_period_num =${@internal_period_num} ),(select c.PRECISION from gld_currency c,con_contract ct where c.currency_code = ct.currency and ct.contract_id = t1.contract_id))" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="current_month_income" databaseType="NUMBER" datatype="java.lang.Double" expression="(select sum(t.unearned_finance_income) from con_unearned_finance_income t where t.contract_id =t1.contract_id and t.internal_period_num =${@internal_period_num})" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select t.contract_name from con_contract t where t.contract_id =t1.contract_id )" forInsert="false" forUpdate="false"/> -->
        <!-- <bm:field name="search_term_1" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select t.search_term_1 from con_contract t where t.contract_id =t1.contract_id)" forInsert="false" forUpdate="false"/> -->
       <bm:field name="vat_interest" />

        <!-- <bm:field name="interest"/>-->
<!--        <bm:field name="interest"  expression="(select t.contract_name from con_contract t where t.contract_id =t1.contract_id )" forInsert="false" forUpdate="false"/>-->

    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="record_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field name="company_id" queryExpression="t1.company_id = ${@company_id}"/>
        <bm:query-field name="finance_income_recognized" queryExpression="nvl(t1.finance_income_recognized,'N') = ${@finance_income_recognized}"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.internal_period_num = ${@internal_period_num} and  t1.company_id IN     (SELECT company_id FROM fnd_companies_vl WHERE (company_id = ${/session/@company_id} OR parent_biz_company_id = ${/session/@company_id}) AND enabled_flag = &apos;Y&apos;) and t2.data_class = &apos;NORMAL&apos; and t2.contract_status in( &apos;INCEPT&apos;,&apos;SIGN&apos;,&apos;TERMINATE&apos;,&apos;ET&apos;) and nvl(t1.unearned_finance_income,0) !=0 "/>
    </bm:data-filters>
    <bm:relations>
        <bm:relation name="con_ref" joinType="LEFT OUTER" refAlias="t2" refModel="cont.CON500.con_contract">
            <bm:reference foreignField="contract_id" localField="contract_id"/>
        </bm:relation>
    </bm:relations>
    <bm:ref-fields>
        <bm:ref-field name="contract_number" relationName="con_ref" sourceField="contract_number"/>
        <bm:ref-field name="contract_name" relationName="con_ref" sourceField="contract_name"/>
        <bm:ref-field name="contract_status" relationName="con_ref" sourceField="contract_status"/>
        <bm:ref-field name="data_class" relationName="con_ref" sourceField="data_class"/>
    </bm:ref-fields>
</bm:model>
