<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-11-26 下午04:47:02  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features">
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CON_INCOME_CASHFLOW_V.CONTRACT_ID"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" prompt="CON_INCOME_CASHFLOW_V.CONTRACT_NUMBER"/>
        <bm:field name="contract_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_STATUS" prompt="CON_INCOME_CASHFLOW_V.CONTRACT_STATUS"/>
        <bm:field name="currency" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CURRENCY" prompt="CON_INCOME_CASHFLOW_V.CURRENCY"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" prompt="CON_INCOME_CASHFLOW_V.COMPANY_ID"/>
        <bm:field name="spv_company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SPV_COMPANY_ID" prompt="CON_INCOME_CASHFLOW_V.SPV_COMPANY_ID"/>
        <bm:field name="cf_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CF_TYPE" prompt="CON_INCOME_CASHFLOW_V.CF_TYPE"/>
        <bm:field name="cf_type_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CF_TYPE_NAME" prompt="CON_INCOME_CASHFLOW_V.CF_TYPE_NAME"/>
        <bm:field name="cashflow_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CASHFLOW_ID" prompt="CON_INCOME_CASHFLOW_V.CASHFLOW_ID"/>
        <bm:field name="times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TIMES" prompt="CON_INCOME_CASHFLOW_V.TIMES"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_TENANT" prompt="CON_INCOME_CASHFLOW_V.BP_ID_TENANT"/>
        <bm:field name="bp_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_CODE" prompt="CON_INCOME_CASHFLOW_V.BP_CODE"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME" prompt="CON_INCOME_CASHFLOW_V.BP_NAME"/>
        <bm:field name="prj_short_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PRJ_SHORT_NAME" prompt="CON_INCOME_CASHFLOW_V.PRJ_SHORT_NAME"/>
        <bm:field name="cf_item" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_ITEM" prompt="CON_INCOME_CASHFLOW_V.CF_ITEM"/>
        <bm:field name="cf_item_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CF_ITEM_NAME" prompt="CON_INCOME_CASHFLOW_V.CF_ITEM_NAME"/>
        <bm:field name="recognize_method" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="RECOGNIZE_METHOD" prompt="CON_INCOME_CASHFLOW_V.CF_ITEM_NAME"/>
        <bm:field name="due_date" databaseType="DATE" datatype="java.util.Date" physicalName="DUE_DATE" prompt="CON_INCOME_CASHFLOW_V.DUE_DATE"/>
        <bm:field name="max_accounting_date" databaseType="DATE" datatype="java.util.Date" physicalName="MAX_ACCOUNTING_DATE" prompt="CON_INCOME_CASHFLOW_V.MAX_ACCOUNTING_DATE"/>
        <bm:field name="net_due_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="NET_DUE_AMOUNT" prompt="CON_INCOME_CASHFLOW_V.NET_DUE_AMOUNT"/>
        <bm:field name="already_finance_income" databaseType="NUMBER" datatype="java.lang.Double" physicalName="ALREADY_NET_DUE_AMOUNT" prompt="CON_INCOME_CASHFLOW_V.ALREADY_NET_DUE_AMOUNT"/>
        <bm:field name="already_finance_income_percent" databaseType="NUMBER" datatype="java.lang.Double" physicalName="ALREADY_FINANCE_INCOME_PERCENT"/>
        <bm:field name="un_finance_income" databaseType="NUMBER" datatype="java.lang.Double" physicalName="UN_FINANCE_INCOME"/>
        <bm:field name="current_finance_income_percent" databaseType="NUMBER" datatype="java.lang.Double" physicalName="CURRENT_FINANCE_INCOME_PERCENT"/>
        <bm:field name="current_finance_income" databaseType="NUMBER" datatype="java.lang.Double" physicalName="CURRENT_FINANCE_INCOME"/>
        <bm:field name="seq_in_period" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SEQ_IN_PERIOD"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    t1.CONTRACT_ID,
                    t1.CONTRACT_NUMBER,
                    t1.CONTRACT_STATUS,
                    t1.CURRENCY,
                    t1.COMPANY_ID,
                    t1.SPV_COMPANY_ID,
                    t1.CF_TYPE,
                    t1.CF_TYPE_NAME,
                    t1.CASHFLOW_ID,
                    t1.TIMES,
                    t1.BP_ID_TENANT,
                    t1.BP_CODE,
                    t1.BP_NAME,
                    t1.PRJ_SHORT_NAME,
                    t1.CF_ITEM,
                    t1.CF_ITEM_NAME,
                    t1.DUE_DATE,
                    t1.MAX_ACCOUNTING_DATE,
                    t1.NET_DUE_AMOUNT,
                    t1.already_finance_income,
                    ROUND(t1.already_finance_income/t1.net_due_amount,2) AS already_finance_income_percent,
                    ROUND((t1.net_due_amount-t1.already_finance_income),2) AS un_finance_income,
                    ROUND(DECODE(t1.already_finance_income,0,0.8,(1-t1.already_finance_income/t1.net_due_amount)),2) AS current_finance_income_percent,
                    ROUND(DECODE(t1.already_finance_income,0,0.8*t1.net_due_amount,(t1.net_due_amount-t1.already_finance_income)),2) AS current_finance_income,
                    'CASH_BASIS' recognize_method,
                    1 seq_in_period
                FROM
                    CON_INCOME_CASHFLOW_V t1 #WHERE_CLAUSE#
                ORDER BY
                    t1.cf_item,
                    t1.due_date
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            	begin
            		con_finance_income_pkg.insert_cash_basis_fin_income(
            					  p_company_id          =>${@company_id}, 
                                  p_contract_id         =>${@contract_id}, 
                                  p_internal_period_num =>${@internal_period_num}, 
                                  p_cf_item             =>${@cf_item},
                                  p_exchange_rate_type  =>${@exchange_rate_type},
                                  p_exchange_rate       =>${@exchange_rate},
                                  p_exchange_rate_quotation => ${@exchange_rate_quotation},
                                  p_seq_in_period       =>${@seq_in_period}, 
                                  p_accounting_date     =>to_date(${@accounting_date},'yyyy-mm-dd'), 
                                  p_recognize_method    =>${@recognize_method}, 
                                  p_reversed_flag       =>'N', 
                                  p_reversed_date       =>'', 
                                  p_finance_income      =>${@current_finance_income}, 
                                  p_financing_cost      =>'', 
                                  p_main_business_income =>'', 
                                  p_main_business_cost   =>'', 
                                  p_cashflow_id          =>${@cashflow_id}, 
                                  p_times                =>${@times}, 
                                  p_cf_type              =>${@cf_type},
                                  p_user_id              =>${/session/@user_id});
            	end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="contract_id" queryOperator="="/>
        <bm:query-field field="bp_id_tenant" queryOperator="="/>
        <bm:query-field field="cf_item" queryOperator="="/>
        <bm:query-field field="due_date" queryExpression="t1.due_date &lt;= ${@due_date}"/>
        <bm:query-field name="currency_code" queryExpression="t1.currency=${@currency_code}"/>
        <bm:query-field name="ignore_income_sure_flag" queryExpression="((${@ignore_income_sure_flag}=&apos;Y&apos; and t1.net_due_amount!=t1.already_finance_income) or nvl(${@ignore_income_sure_flag},&apos;N&apos;)=&apos;N&apos;)"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="(t1.cf_item in (3,4) and nvl(t1.spv_company_id,t1.company_id) = ${@je_company_id})"/>
    </bm:data-filters>
</bm:model>
