<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2013-4-2 上午9:39:16  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="FND_SCORE_TEMPLATE_LINE">
    <bm:fields>
        <bm:field name="score_template_line_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SCORE_TEMPLATE_LINE_ID"/>
        <bm:field name="score_template_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SCORE_TEMPLATE_ID"/>
        <bm:field name="score_target_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SCORE_TARGET_ID"/>
        <bm:field name="weight_value" databaseType="NUMBER" datatype="java.lang.Long" physicalName="WEIGHT_VALUE" prompt="FND713.FND_SCORE_TEMPLATE_LINE.WEIGHT_VALUE"/>
        <bm:field name="parent_line_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PARENT_LINE_ID"/>
        <bm:field name="score_target_code" forInsert="false" forUpdate="false" prompt="FND713.SCORE_TARGET_CODE.SCORE_TARGET_CODE"/>
        <bm:field name="score_target_name" forInsert="false" forUpdate="false" prompt="FND713.SCORE_TARGET_CODE.SCORE_TARGET_NAME"/>
        <bm:field name="summary_flag" forInsert="false" forUpdate="false" prompt="FND713.SCORE_TARGET_CODE.SUMMARY_FLAG"/>
        <bm:field name="display_flag" prompt="FND713.SCORE_TARGET_CODE.DISPLAY_FLAG"/>
        <bm:field name="data_value_from" forInsert="false" forUpdate="false"/>
        <bm:field name="target_object_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TARGET_OBJECT_TYPE" prompt="FND713.SCORE_TARGET_CODE.TARGET_OBJECT_TYPE"/>
        <bm:field name="multiple_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="MULTIPLE_FLAG" prompt="FND713.SCORE_TARGET_CODE.MULTIPLE_FLAG"/>
        <bm:field name="data_value_from_display" forInsert="false" forUpdate="false" prompt="FND713.SCORE_TARGET_CODE.DATA_VALUE_FROM"/>
        <bm:field name="score_value" databaseType="NUMBER" datatype="java.lang.Double" physicalName="SCORE_VALUE" prompt="FND713.SCORE_TARGET_CODE.SCORE_VALUE"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    t1.score_template_line_id,
                    t1.score_template_id,
                    t1.score_target_id,
                    t1.target_object_type,
                    t1.multiple_flag,
                    t.score_target_code,
                    t.score_target_name,
                    t.summary_flag,
                    t.data_value_from,
                    (SELECT
                        v.code_value_name
                    FROM
                        sys_code_values_v v
                    WHERE
                        v.code       = 'FND_SCORE_TARGET_DATA_VALUE_FROM' AND
                        v.code_value = t.data_value_from
                    ) AS data_value_from_display,
                    t1.weight_value,
                    t1.parent_line_id,
                    t1.score_value,
                    t1.display_flag
                FROM
                    fnd_score_template_line t1,
                    fnd_score_target t #WHERE_CLAUSE#
                    order by t.score_target_code asc
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
        		begin
				   fnd_score_define_pkg.tplt_line_delete_cascade(p_score_template_line_id => ${@score_template_line_id},
										                         p_score_template_id  	  => ${@score_template_id},
										                         p_user_id                => ${/session/@user_id});
				end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="score_template_line_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="score_template_line_id" queryOperator="="/>
        <bm:query-field field="parent_line_id" queryExpression=" ((${@parent_line_id} = 0 and t1.parent_line_id is null ) or t1.parent_line_id = ${@parent_line_id}) "/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="score_template_id" enforceOperations="query" expression="score_template_id=${@score_template_id} and t.score_target_id = t1.score_target_id"/>
    </bm:data-filters>
</bm:model>
