<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2013-4-2 上午9:39:38  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:f="leaf.database.features" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="FND_SCORE_TEMPLATE_LN_VALUE">
    <bm:fields>
        <bm:field name="score_template_line_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SCORE_TEMPLATE_LINE_ID"/>
        <bm:field name="score_target_value_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SCORE_TARGET_VALUE_ID"/>
        <bm:field name="score_value" databaseType="VARCHAR2" datatype="java.lang.String" displayWidth="50" forDisplay="true" forQuery="true" physicalName="SCORE_VALUE" prompt="FND713.FND_SCORE_TEMPLATE_LN_VALUE.SCORE_VALUE"/>
        <bm:field name="score_value_desc" displayWidth="380" forDisplay="true" forInsert="false" forQuery="true" forUpdate="false" prompt="FND713.FND_SCORE_TEMPLATE_LN_VALUE.SCORE_VALUE_DESC"/>
        <bm:field name="reference_score_value" forInsert="false" forUpdate="false" prompt="FND713.FND_SCORE_TEMPLATE_LN_VALUE.REFERENCE_SCORE_VALUE"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
               SELECT
                    tv.description AS score_value_desc,
                    lv.score_value,
                    tv.score_target_value_id,
                    l.score_template_line_id,
                    NVL(l.score_value, 0) * NVL(tv.scoring_value_per, 0) / 100 AS reference_score_value
                FROM
                    fnd_score_target_values tv
                LEFT OUTER JOIN fnd_score_template_line l
                ON
                    tv.score_target_id = l.score_target_id
                LEFT OUTER JOIN fnd_score_template_ln_value lv
                ON
                    lv.score_template_line_id = l.score_template_line_id AND
                    lv.score_target_value_id  = tv.score_target_value_id  #WHERE_CLAUSE#
                ORDER BY
                    tv.line_number
                   
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
        		begin
				  	  fnd_score_define_pkg.tplt_line_value_reset(p_score_template_line_id => ${@score_template_line_id},
										                         p_score_target_value_id  => ${@score_target_value_id},
										                         p_score_value            => ${@score_value},
										                         p_user_id                => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
        		begin
				  	  fnd_score_define_pkg.tplt_line_value_reset(p_score_template_line_id => ${@score_template_line_id},
										                         p_score_target_value_id  => ${@score_target_value_id},
										                         p_score_value            => ${@score_value},
										                         p_user_id                => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="score_target_value_id"/>
        <bm:pk-field name="score_template_line_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field name="score_value" queryExpression="lv.score_value=${@score_value}"/>
        <bm:query-field name="score_value_desc" queryExpression="tv.description like ${@score_value_desc}"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="score_template_line_id" enforceOperations="query" expression="l.score_template_line_id=${@score_template_line_id}"/>
    </bm:data-filters>
</bm:model>
