<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-6-3 下午12:38:12  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="CSH_WRITE_OFF">
    <bm:fields>
        <bm:field name="write_off_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="WRITE_OFF_ID" prompt="CSH_WRITE_OFF.WRITE_OFF_ID"/>
        <bm:field name="write_off_type" databaseType="VARCHAR2" datatype="java.lang.String" lookupCode="CSH513_WRITE_OFF_TYPE" lookupField="write_off_type_name" physicalName="WRITE_OFF_TYPE" prompt="CSH_WRITE_OFF.WRITE_OFF_TYPE"/>
        <bm:field name="write_off_date" databaseType="DATE" datatype="java.util.Date" physicalName="WRITE_OFF_DATE" prompt="HLS.WRITE_OFF_DATE"/>
        <bm:field name="journal_date" databaseType="DATE" datatype="java.util.Date" physicalName="JOURNAL_DATE" prompt="CSH_WRITE_OFF.JOURNAL_DATE"/>
        <bm:field name="internal_period_num" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INTERNAL_PERIOD_NUM" prompt="CSH_WRITE_OFF.INTERNAL_PERIOD_NUM"/>
        <bm:field name="period_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PERIOD_NAME" prompt="CSH_WRITE_OFF.PERIOD_NAME"/>
        <bm:field name="csh_transaction_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CSH_TRANSACTION_ID" prompt="CSH_WRITE_OFF.CSH_TRANSACTION_ID"/>
        <bm:field name="csh_write_off_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="CSH_WRITE_OFF_AMOUNT" prompt="HLS.CSH_WRITE_OFF_AMOUNT"/>
        <bm:field name="subsequent_csh_trx_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SUBSEQUENT_CSH_TRX_ID" prompt="CSH_WRITE_OFF.SUBSEQUENT_CSH_TRX_ID"/>
        <bm:field name="subseq_csh_write_off_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="SUBSEQ_CSH_WRITE_OFF_AMOUNT" prompt="CSH_WRITE_OFF.SUBSEQ_CSH_WRITE_OFF_AMOUNT"/>
        <bm:field name="reversed_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REVERSED_FLAG" prompt="CSH_WRITE_OFF.REVERSED_FLAG"/>
        <bm:field name="reversed_write_off_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REVERSED_WRITE_OFF_ID" prompt="CSH_WRITE_OFF.REVERSED_WRITE_OFF_ID"/>
        <bm:field name="reversed_date" databaseType="DATE" datatype="java.util.Date" physicalName="REVERSED_DATE" prompt="CSH_WRITE_OFF.REVERSED_DATE"/>
        <bm:field name="cashflow_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CASHFLOW_ID" prompt="CSH_WRITE_OFF.CASHFLOW_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CSH_WRITE_OFF.CONTRACT_ID"/>
        <bm:field name="times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TIMES" prompt="CSH_WRITE_OFF.TIMES"/>
        <bm:field name="cf_item" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_ITEM" prompt="CSH_WRITE_OFF.CF_ITEM"/>
        <bm:field name="cf_type" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_TYPE" prompt="CSH_WRITE_OFF.CF_TYPE"/>
        <bm:field name="penalty_calc_date" databaseType="DATE" datatype="java.util.Date" physicalName="PENALTY_CALC_DATE" prompt="CSH_WRITE_OFF.PENALTY_CALC_DATE"/>
        <bm:field name="write_off_due_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="WRITE_OFF_DUE_AMOUNT" prompt="HLS.WRITEOFF_DUE_AMOUNT"/>
        <bm:field name="write_off_principal" databaseType="NUMBER" datatype="java.lang.Double" physicalName="WRITE_OFF_PRINCIPAL" prompt="CSH513.WRITE_OFF_PRINCIPAL"/>
        <bm:field name="write_off_interest" databaseType="NUMBER" datatype="java.lang.Double" physicalName="WRITE_OFF_INTEREST" prompt="CSH513.WRITE_OFF_INTEREST"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION" prompt="CSH_WRITE_OFF.DESCRIPTION"/>
        <bm:field name="opposite_doc_category" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="OPPOSITE_DOC_CATEGORY" prompt="CSH_WRITE_OFF.OPPOSITE_DOC_CATEGORY"/>
        <bm:field name="opposite_doc_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="OPPOSITE_DOC_TYPE" prompt="CSH_WRITE_OFF.OPPOSITE_DOC_TYPE"/>
        <bm:field name="opposite_doc_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="OPPOSITE_DOC_ID" prompt="CSH_WRITE_OFF.OPPOSITE_DOC_ID"/>
        <bm:field name="opposite_doc_line_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="OPPOSITE_DOC_LINE_ID" prompt="CSH_WRITE_OFF.OPPOSITE_DOC_LINE_ID"/>
        <bm:field name="opposite_doc_detail_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="OPPOSITE_DOC_DETAIL_ID" prompt="CSH_WRITE_OFF.OPPOSITE_DOC_DETAIL_ID"/>
        <bm:field name="opposite_write_off_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="OPPOSITE_WRITE_OFF_AMOUNT" prompt="CSH_WRITE_OFF.OPPOSITE_WRITE_OFF_AMOUNT"/>
        <bm:field name="create_je_mothed" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CREATE_JE_MOTHED" prompt="CSH_WRITE_OFF.CREATE_JE_MOTHED"/>
        <bm:field name="create_je_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CREATE_JE_FLAG" prompt="CSH_WRITE_OFF.CREATE_JE_FLAG"/>
        <bm:field name="gld_interface_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="GLD_INTERFACE_FLAG" prompt="CSH_WRITE_OFF.GLD_INTERFACE_FLAG"/>
        <bm:field name="write_off_type_name" forInsert="false" forUpdate="false" prompt="HLS.WRITE_OFF_TYPE"/>
        <bm:field name="write_off_classification" lookupField="write_off_classification_desc" lookupCode="DS_CSH_WRITE_OFF_CLASSIFICATION" databaseType="VARCHAR2" datatype="java.lang.String" />
        <bm:field name="write_off_classification_desc" forInsert="false" forUpdate="false"/>

        <bm:field name="journal_num" expression="(SELECT h.journal_num FROM hls_journal_header h, hls_journal_detail d WHERE d.source_table = 'CSH_WRITE_OFF' AND d.source_id = t1.write_off_id AND h.journal_header_id = d.journal_header_id AND h.reversed_flag = 'N'  AND rownum = 1)" forInsert="false" forUpdate="false"/>
        <bm:field name="journal_user" expression="(SELECT u.description FROM hls_journal_detail d, sys_user u WHERE d.source_table = 'CSH_WRITE_OFF' AND d.source_id = t1.write_off_id AND d.created_by = u.user_id AND rownum = 1)" forInsert="false" forUpdate="false"/>
        <bm:field name="history_flag" expression="(SELECT ct.history_flag FROM csh_transaction ct WHERE ct.transaction_id = t1.csh_transaction_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="ref_bp_name" expression="(select cc.bp_name from con_contract_v cc where cc.contract_id = nvl(t1.contract_id,t1.ASSIGNS_CONTRACT_ID))" forInsert="false" forUpdate="false"/>
        <bm:field name="ref_contract_number"  expression="(select cc.contract_number from con_contract cc where cc.contract_id = nvl(t1.contract_id,t1.ASSIGNS_CONTRACT_ID))" forInsert="false" forUpdate="false"/>
<!--        <bm:field name="ref_agent_name" expression="(select cc.extra_nam from con_contract_v cc where cc.contract_id = nvl(t1.contract_id,t1.ASSIGNS_CONTRACT_ID))" forInsert="false" forUpdate="false"/>-->
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="write_off_id"/>
    </bm:primary-key>
    <bm:relations>
        <bm:relation name="con_cashflow" joinType="left outer" refAlias="t2" refModel="cont.CON500.con_contract_cashflow_v">
            <bm:reference foreignField="cashflow_id" localField="cashflow_id"/>
        </bm:relation>
        <bm:relation name="hls_cf_type" joinType="left outer" refAlias="t3" refModel="hls.HLS005.hls_cashflow_type_v">
            <bm:reference foreignField="cf_type" localField="cf_type"/>
        </bm:relation>
        <bm:relation name="hls_cf_item" joinType="left outer" refAlias="t4" refModel="hls.HLS005.hls_cashflow_item_v">
            <bm:reference foreignField="cf_item" localField="cf_item"/>
        </bm:relation>
    </bm:relations>
    <bm:ref-fields>
        <bm:ref-field name="due_date" relationName="con_cashflow" sourceField="due_date"/>
        <bm:ref-field name="contract_number" relationName="con_cashflow" sourceField="contract_number"/>
        <bm:ref-field name="project_name" relationName="con_cashflow" sourceField="project_name"/>
        <bm:ref-field name="bp_name" relationName="con_cashflow" sourceField="bp_name"/>
        <bm:ref-field name="cf_type_name" relationName="hls_cf_type" sourceField="description"/>
        <bm:ref-field name="cf_item_name" relationName="hls_cf_item" sourceField="cf_item_desc"/>
    </bm:ref-fields>
    <bm:query-fields>
        <bm:query-field field="write_off_id" queryOperator="="/>
        <bm:query-field field="csh_transaction_id" queryOperator="="/>
        <bm:query-field field="reversed_flag" queryOperator="="/>
        <bm:query-field name="reverse_detail_flag" queryExpression="${@reverse_detail_flag}=&apos;Y&apos; and t1.write_off_type in (&apos;RECEIPT_CREDIT&apos;,&apos;RECEIPT_ADVANCE_RECEIPT&apos;,&apos;ADVANCE_RECEIPT_CREDIT&apos;,&apos;DEPOSIT&apos;,&apos;RISK&apos;,&apos;DEPOSIT_CUS&apos;,&apos;RECEIPT_NONBUSINESS&apos;)"/>
    </bm:query-fields>
</bm:model>
