<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129
    $Date: 2014-11-25 下午02:32:09  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT (select nvl(tc.comments, t.table_name)
				          from user_tab_comments tc
				         where tc.table_name = upper(t.table_name)) table_name,
				       t.column_name,
				       (SELECT c.prompt
				          FROM hls_doc_layout_config c
				         WHERE c.layout_code = t.layout_code
				           AND c.tab_code = t.tab_code
				           AND c.column_name = t.column_name) prompt,
				       hls_standard_history_pkg.get_default_value_name(p_base_table          => t.table_name,
				                                                       p_base_table_pk_value => t.table_pk_value,
				                                                       p_layout_code         => t.layout_code,
				                                                       p_tab_code            => t.tab_code,
				                                                       p_column_name         => t.column_name,
				                                                       p_column_value        => t.from_column_value,
				                                                       p_user_id             => ${/session/@user_id},
				                                                       p_session_id          => ${/session/@session_id}) from_column_value,
				       hls_standard_history_pkg.get_default_value_name(p_base_table          => t.table_name,
				                                                       p_base_table_pk_value => t.table_pk_value,
				                                                       p_layout_code         => t.layout_code,
				                                                       p_tab_code            => t.tab_code,
				                                                       p_column_name         => t.column_name,
				                                                       p_column_value        => t.to_column_value,
				                                                       p_user_id             => ${/session/@user_id},
				                                                       p_session_id          => ${/session/@session_id}) to_column_value
				  FROM hls_standard_history t
				 WHERE  t.confirm_flag='N' and t.source_table='CON_CONTRACT' and t.source_table_pk_value=${@contract_id} and
				  ((t.parent_Table = ${@table_name} AND t.parent_table_pk_value = ${@table_pk_value} AND 
				       t.operation_date =
				       (SELECT MAX(tt.operation_date)
				           FROM hls_standard_history tt
				          WHERE tt.column_name = t.column_name
				            AND tt.table_pk_value = t.table_pk_value
				            AND tt.table_name = t.table_name))
				    OR (t.table_name = ${@table_name} AND t.table_pk_value = ${@table_pk_value} AND 
				       t.operation_date =
				       (SELECT MAX(tt.operation_date)
				           FROM hls_standard_history tt
				          WHERE tt.column_name = t.column_name
				            AND tt.table_pk_value = t.table_pk_value
				            AND tt.table_name = t.table_name)))
                 union 
                 	SELECT (select nvl(tc.comments, t.table_name)
				          from user_tab_comments tc
				         where tc.table_name = upper(t.table_name)) table_name,
				       t.column_name,
				       (SELECT c.prompt
				          FROM hls_doc_layout_config c
				         WHERE c.layout_code = t.layout_code
				           AND c.tab_code = t.tab_code
				           AND c.column_name = t.column_name) prompt,
				       hls_standard_history_pkg.get_default_value_name(p_base_table          => t.table_name,
				                                                       p_base_table_pk_value => t.table_pk_value,
				                                                       p_layout_code         => t.layout_code,
				                                                       p_tab_code            => t.tab_code,
				                                                       p_column_name         => t.column_name,
				                                                       p_column_value        => t.from_column_value,
				                                                       p_user_id             => ${/session/@user_id},
				                                                       p_session_id          => ${/session/@session_id}) from_column_value,
				       hls_standard_history_pkg.get_default_value_name(p_base_table          => t.table_name,
				                                                       p_base_table_pk_value => t.table_pk_value,
				                                                       p_layout_code         => t.layout_code,
				                                                       p_tab_code            => t.tab_code,
				                                                       p_column_name         => t.column_name,
				                                                       p_column_value        => t.to_column_value,
				                                                       p_user_id             => ${/session/@user_id},
				                                                       p_session_id          => ${/session/@session_id}) to_column_value
				  FROM hls_standard_history t
				 WHERE  t.confirm_flag='N' and t.source_table='CON_CONTRACT_LEASE_ITEM' and t.source_table_pk_value=${@table_pk_value} and
				  ((t.parent_Table = ${@table_name} AND t.parent_table_pk_value = ${@table_pk_value} AND 
				       t.operation_date =
				       (SELECT MAX(tt.operation_date)
				           FROM hls_standard_history tt
				          WHERE tt.column_name = t.column_name
				            AND tt.table_pk_value = t.table_pk_value
				            AND tt.table_name = t.table_name))
				    OR (t.table_name = ${@table_name} AND t.table_pk_value = ${@table_pk_value} AND 
				       t.operation_date =
				       (SELECT MAX(tt.operation_date)
				           FROM hls_standard_history tt
				          WHERE tt.column_name = t.column_name
				            AND tt.table_pk_value = t.table_pk_value
				            AND tt.table_name = t.table_name)))
                    
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
