<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-9-12 下午04:13:41  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:e="leaf.service.exception" xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="RSC_FC_ESTIMATE_RESULT">
    <bm:fields>
        <bm:field name="result_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RESULT_ID" prompt="RSC_FC_ESTIMATE_RESULT.RESULT_ID"/>
        <bm:field name="fc_estimate_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FC_ESTIMATE_ID" prompt="RSC_FC_ESTIMATE_RESULT.FC_ESTIMATE_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="RSC_FC_ESTIMATE_RESULT.CONTRACT_ID"/>
        <bm:field name="lamp_color_by_system" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LAMP_COLOR_BY_SYSTEM" prompt="RSC_FC_ESTIMATE_RESULT.LAMP_COLOR_BY_SYSTEM"/>
        <bm:field name="lamp_color" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LAMP_COLOR" prompt="RSC_FC_ESTIMATE_RESULT.LAMP_COLOR"/>
        <bm:field name="lamp_color_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select rsl.description from rsc_signal_lamp rsl where rsl.lamp_color=t1.lamp_color)" forInsert="false" forUpdate="false"/>
        <bm:field name="five_class_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIVE_CLASS_CODE" prompt="RSC_FC_ESTIMATE_RESULT.FIVE_CLASS_CODE"/>
        <bm:field name="five_class_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select rfc.description from RSC_FIVE_CLASS_CODE rfc where rfc.five_class_code=t1.five_class_code)" forInsert="false" forUpdate="false"/>
        <bm:field name="original_five_class_code" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select rfc.description from RSC_FIVE_CLASS_CODE rfc where rfc.five_class_code in (select c.five_class_code from con_contract c where c.contract_id=t1.contract_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION" prompt="RSC_FC_ESTIMATE_RESULT.DESCRIPTION"/>
        <bm:field name="estimate_date" databaseType="VARCHAR2" datatype="java.lang.String" expression="to_char(t1.estimate_date,&apos;yyyy-mm-dd&apos;)" forInsert="true" forUpdate="false" insertExpression="sysdate" physicalName="ESTIMATE_DATE" prompt="RSC_FC_ESTIMATE_RESULT.ESTIMATE_DATE"/>
        <bm:field name="status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="STATUS" prompt="RSC_FC_ESTIMATE_RESULT.STATUS"/>
        <bm:field name="status_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(SELECT sv.code_value_name FROM sys_code_values_v sv WHERE sv.code = &apos;RSC_FIVE_CLASS_REMOVAL_APPROVAL_STATUS&apos; AND sv.code_value =t1.status )" forInsert="false" forUpdate="false"/>
        <bm:field name="ref_v01" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V01" prompt="RSC_FC_ESTIMATE_RESULT.REF_V01"/>
        <bm:field name="ref_v02" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V02" prompt="RSC_FC_ESTIMATE_RESULT.REF_V02"/>
        <bm:field name="ref_v03" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V03" prompt="RSC_FC_ESTIMATE_RESULT.REF_V03"/>
        <bm:field name="ref_v04" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V04" prompt="RSC_FC_ESTIMATE_RESULT.REF_V04"/>
        <bm:field name="ref_v05" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V05" prompt="RSC_FC_ESTIMATE_RESULT.REF_V05"/>
        <bm:field name="ref_n01" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N01" prompt="RSC_FC_ESTIMATE_RESULT.REF_N01"/>
        <bm:field name="ref_n02" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N02" prompt="RSC_FC_ESTIMATE_RESULT.REF_N02"/>
        <bm:field name="ref_n03" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N03" prompt="RSC_FC_ESTIMATE_RESULT.REF_N03"/>
        <bm:field name="ref_n04" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N04" prompt="RSC_FC_ESTIMATE_RESULT.REF_N04"/>
        <bm:field name="ref_n05" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N05" prompt="RSC_FC_ESTIMATE_RESULT.REF_N05"/>
        <bm:field name="ref_d01" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D01" prompt="RSC_FC_ESTIMATE_RESULT.REF_D01"/>
        <bm:field name="ref_d02" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D02" prompt="RSC_FC_ESTIMATE_RESULT.REF_D02"/>
        <bm:field name="ref_d03" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D03" prompt="RSC_FC_ESTIMATE_RESULT.REF_D03"/>
        <bm:field name="ref_d04" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D04" prompt="RSC_FC_ESTIMATE_RESULT.REF_D04"/>
        <bm:field name="ref_d05" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D05" prompt="RSC_FC_ESTIMATE_RESULT.REF_D05"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
    		begin
    		  update rsc_fc_estimate_result set five_class_code=${@five_class_code} where result_id = ${@result_id};
    		  end;
    		
    		]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
        		BEGIN
        		    rsc_fc_estimate_pkg.rsc_fc_estimate_result_init(p_result_id       =>${@result_id},
                                                  p_five_class_plan =>${@five_class_plan},
                                                  p_contract_id     =>${@contract_id},
                                                  p_user_id         =>${/session/@user_id});
        		END;
    		]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:relations>
        <bm:relation name="ref" joinType="LEFT OUTER" refAlias="c" refModel="cont.CON500.con_contract_v">
            <bm:reference foreignField="contract_id" localField="contract_id"/>
        </bm:relation>
    </bm:relations>
    <bm:ref-fields>
        <bm:ref-field name="contract_number" relationName="ref" sourceField="contract_number"/>
        <bm:ref-field name="contract_name" relationName="ref" sourceField="contract_name"/>
        <bm:ref-field name="bp_id" relationName="ref" sourceField="bp_id_tenant"/>
    </bm:ref-fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="result_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="result_id" queryOperator="="/>
        <bm:query-field name="contract_number" queryExpression="c.contract_number=${@contract_numbers}"/>
        <bm:query-field name="contract_name" queryExpression="c.contract_name like ${@contract_name}"/>
        <bm:query-field name="estimate_date_t" queryExpression="t1.estimate_date&gt;to_date(${@estimate_date_t},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="estimate_date_f" queryExpression="t1.estimate_date&lt;to_date(${@estimate_date_f},&apos;yyyy-mm-dd&apos;)"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.fc_estimate_id=${@fc_estimate_id}"/>
    </bm:data-filters>
</bm:model>
