<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ouyangzhaochang2663 $
    $Date: 2011/01/19 08:11:25 $
    $Revision: 1.4 $
    $Purpose: “部门定义” 模块使用的查询bm
-->
<ns1:model xmlns:ns2="leaf.database.local.oracle" xmlns:f="leaf.database.features" xmlns:ns1="http://www.leaf-framework.org/schema/bm" alias="eou" baseTable="EXP_ORG_UNIT" defaultOrderBy="unit_code">
    <ns1:fields>
        <ns1:field name="unit_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="unit_code" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" prompt="EXP_ORG_UNIT.UNIT_CODE"/>
        <ns1:field name="description_id" databaseType="NUMBER" datatype="java.lang.Long" multiLanguage="true" multiLanguageDescField="org_unit_description"/>
        <ns1:field name="org_unit_description" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forInsert="false" forQuery="true" forUpdate="false" prompt="EXP_ORG_UNIT.ORG_UNIT_DESCRIPTION"/>
        <ns1:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="responsibility_center_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="responsibility_center_code" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select r.responsibility_center_code             from fnd_responsibility_centers r             where r.responsibility_center_id = eou.responsibility_center_id)" forInsert="false" forUpdate="false"/>
        <ns1:field name="parent_unit_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="operate_unit_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="parent_unit_code" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select u.unit_code             from exp_org_unit u             where u.unit_id = eou.parent_unit_id)" forInsert="false" forUpdate="false"/>
        <ns1:field name="unit_type_id" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select b.unit_type_id             from exp_org_unit_type_relations r, exp_org_unit_types b             where r.unit_type_id = b.unit_type_id             and r.unit_id = eou.unit_id)" forInsert="false" forUpdate="false"/>
        <ns1:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <ns1:field name="chief_position_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="org_unit_level_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="org_unit_type" databaseType="VARCHAR2" datatype="java.lang.String" prompt="EXP_ORG_UNIT.UNIT_TYPE"/>
        <ns1:field name="parent_unit_id_display" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select description_text             from fnd_descriptions fd             where fd.description_id = self.description_id             and Language = ${/session/@lang})" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.PARENT_UNIT"/>
        <ns1:field name="unit_display" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select description_text             from fnd_descriptions fd             where fd.description_id = ou.description_id             and Language = ${/session/@lang})" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.UNIT_DISPLAY"/>
        <ns1:field name="position_display" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select description_text             from fnd_descriptions fd             where fd.description_id = eop.description_id             and Language = ${/session/@lang})" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.CHIEF_POSITION"/>
        <ns1:field name="types_display" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select description_text             from fnd_descriptions fd,exp_org_unit_types b,exp_org_unit_type_relations a             where fd.description_id = b.description_id             and a.unit_id = eou.unit_id             and a.unit_type_id = b.unit_type_id             and Language = ${/session/@lang})" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.UNIT_TYPE"/>
        <ns1:field name="unit_level_display" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select description_text             from fnd_descriptions fd             where fd.description_id = eoul.description_id             and Language = ${/session/@lang})" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.UNIT_LEVEL"/>
        <ns1:field name="center_name_code_display" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select frc.responsibility_center_code || &apos;-&apos; || fd.description_text             from fnd_descriptions fd, fnd_responsibility_centers frc             where frc.responsibility_center_name_id = fd.description_id             and fd.language = ${/session/@lang}             and frc.responsibility_center_id = eou.responsibility_center_id)" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.RESPONSIBILITY_CENTER"/>
        <ns1:field name="yonda_organization_code" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <ns1:field name="yonda_organization_code_desc" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select organization_name from hls_car_organization t where t.organization_code = eou.yonda_organization_code)" forInsert="false" forUpdate="false"/>
        <ns1:field name="lease_organization" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <ns1:field name="lease_organization_n" databaseType="VARCHAR2" datatype="java.lang.String" expression="(Select hlo.description From hls_lease_organization hlo Where hlo.lease_organization  = eou.lease_organization)" forInsert="false" forUpdate="false"/>
        <ns1:field name="operate_postion" databaseType="NUMBER" datatype="java.lang.Long"/>
        <ns1:field name="operate_postion_n" databaseType="VARCHAR2" datatype="java.lang.String" expression=" (Select description_text           From fnd_descriptions fd          Where fd.description_id =                (Select e.description_id                   From exp_org_position e                  Where e.position_id = eou.operate_postion  )  and fd.language = ${/session/@lang})" forInsert="false" forUpdate="false" prompt="EXP_ORG_UNIT.CHIEF_POSITION"/>
    </ns1:fields>
    <ns1:primary-key>
        <ns1:pk-field name="unit_id"/>
    </ns1:primary-key>
    <ns1:query-fields>
        <ns1:query-field field="unit_code" queryOperator="like"/>
        <ns1:query-field field="org_unit_description" queryExpression="exists (select 1 from fnd_descriptions fd where eou.description_id=fd.description_id and fd.description_text like ${@org_unit_description} and fd.language = ${/session/@lang})"/>
        <ns1:query-field name="self_parent" queryExpression="parent_unit_id != ${/parameter/@self_parent}"/>
    </ns1:query-fields>
    <ns1:relations>
        <ns1:relation name="ou" joinType="LEFT OUTER" refModel="fnd.fnd_operation_units">
            <ns1:reference foreignField="operation_unit_id" localField="operate_unit_id"/>
        </ns1:relation>
        <ns1:relation name="self" joinType="LEFT OUTER" refModel="exp.exp_org_unit">
            <ns1:reference foreignField="unit_id" localField="parent_unit_id"/>
        </ns1:relation>
        <ns1:relation name="eop" joinType="LEFT OUTER" refModel="exp.exp_org_position">
            <ns1:reference foreignField="position_id" localField="chief_position_id"/>
        </ns1:relation>
        <ns1:relation name="eoul" joinType="LEFT OUTER" refModel="exp.exp_org_unit_levels">
            <ns1:reference foreignField="org_unit_level_id" localField="org_unit_level_id"/>
        </ns1:relation>
    </ns1:relations>
    <ns1:features>
        <ns2:sequence-pk/>
        <f:standard-who/>
        <f:multi-language-storage/>
    </ns1:features>
    <ns1:ref-fields>
        <ns1:ref-field name="operation_unit_id" relationName="ou" sourceField="operation_unit_id"/>
        <ns1:ref-field name="operation_unit_code" relationName="ou" sourceField="operation_unit_code"/>
        <ns1:ref-field name="position_id" relationName="eop" sourceField="position_id"/>
        <ns1:ref-field name="position_code" relationName="eop" sourceField="position_code"/>
        <ns1:ref-field name="org_unit_level_id_eoul" relationName="eoul" sourceField="org_unit_level_id"/>
        <ns1:ref-field name="org_unit_level_code" relationName="eoul" sourceField="org_unit_level_code"/>
        <ns1:ref-field name="description_id_eoul" relationName="eoul" sourceField="description_id"/>
        <ns1:ref-field name="unit_id_self" relationName="self" sourceField="unit_id"/>
    </ns1:ref-fields>
    <ns1:data-filters>
        <ns1:data-filter name="company_id" enforceOperations="query" expression="eou.company_id=${/session/@company_id}"/>
    </ns1:data-filters>
</ns1:model>
