<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-4-15 下午01:13:07  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" xmlns:s="leaf.plugin.script">
    <bm:fields>
        <bm:field name="bp_id" prompt="HLS_BP_MASTER_V.BP_ID"/>
        <bm:field name="bp_code" displayWidth="242" forDisplay="true" forQuery="true" prompt="HLS.BP_CODE"/>
        <bm:field name="bp_name" displayWidth="242" forDisplay="true" forQuery="true" prompt="HLS.BP_NAME"/>
        <bm:field name="bp_category"/>
        <bm:field name="bp_category_name" displayWidth="80" forDisplay="true" prompt="商业伙伴类别"/>
        <bm:field name="bp_class"/>
        <bm:field name="bp_class_name" displayWidth="80" forDisplay="true" prompt="商业伙伴分类"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
    		SELECT bp_id,
			       bp_code,
			       bp_name,
			       bp_category,
			       bp_type,
			       (SELECT description FROM hls_bp_category WHERE bp_category = t1.bp_category) bp_category_name,
			       bp_class,
			       (SELECT code_value_name
			          FROM sys_code_values_v
			         WHERE code_value = t1.bp_class
			               AND code = 'HLS211_BP_CLASS') bp_class_name
			  FROM hls_bp_master t1
    		#WHERE_CLAUSE#
    		order by bp_code
    	]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="bp_code" queryExpression="t1.bp_code like &apos;%&apos; || upper(${@bp_code}) || &apos;%&apos;"/>
        <bm:query-field field="bp_name" queryExpression="t1.bp_name like &apos;%&apos; || ${@bp_name} || &apos;%&apos;"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="query" expression="t1.bp_category = ${@bp_category} and exists
        (select 1
           from aut_trx_user_authorize a1, aut_owner_user_authorize a2
          where a1.trx_category = 'BP'
            and a1.trx_id = t1.bp_id
            and trunc(sysdate) between a1.start_date and
                nvl(a1.end_date, trunc(sysdate))
            and a1.user_id = a2.owner_user_id
            and a1.trx_category = a2.trx_category
            and a2.authorized_user_id = ${/session/@user_id}
            and trunc(sysdate) between a2.start_date and
                nvl(a2.end_date, trunc(sysdate))) "/>
        <bm:data-filter name="query" expression="t1.bp_type not in (&apos;RENTER&apos;,&apos;MAN_FACTURER&apos;,&apos;ASSET_REGULATOR&apos;)"/>
    </bm:data-filters>
</bm:model>
