<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-4-2 上午09:33:46  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm"
          xmlns:f="leaf.database.features" alias="t1" baseTable="HLS_LEASE_ITEM"
          defaultOrderBy="t1.lease_item_code desc">
    <bm:fields>
        <bm:field name="lease_item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LEASE_ITEM_ID"
                  prompt="HLS_LEASE_ITEM.LEASE_ITEM_ID"/>
        <bm:field name="lease_item_code" databaseType="VARCHAR2" datatype="java.lang.String"
                  physicalName="LEASE_ITEM_CODE" prompt="HLS.LEASE_ITEM_CODE"/>
        <bm:field name="short_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SHORT_NAME"
                  prompt="HLS_LEASE_ITEM.SHORT_NAME"/>
        <bm:field name="full_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FULL_NAME"
                  prompt="HLS_LEASE_ITEM.FULL_NAME"/>
        <bm:field name="lease_item_type" databaseType="VARCHAR2" datatype="java.lang.String"
                  physicalName="LEASE_ITEM_TYPE" prompt="HLS.LEASE_ITEM_TYPE"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG"
                  prompt="HLS.ENABLED_FLAG"/>
        <bm:field name="search_term" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SEARCH_TERM"
                  prompt="HLS_LEASE_ITEM.SEARCH_TERM"/>
        <bm:field name="serial_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SERIAL_NUMBER"
                  prompt="HLS_LEASE_ITEM.SERIAL_NUMBER"/>
        <bm:field name="pattern" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PATTERN"
                  prompt="HLS.PATTERN"/>
        <bm:field name="specification" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SPECIFICATION"
                  prompt="HLS.SPECIFICATION"/>
        <bm:field name="uom" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UOM" prompt="HLS.UOM"/>
        <bm:field name="quantity" databaseType="NUMBER" datatype="java.lang.Double" physicalName="QUANTITY"
                  prompt="HLS.QUANTITY"/>
        <bm:field name="currency" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CURRENCY"
                  prompt="HLS.CURRENCY"/>
        <bm:field name="price" databaseType="NUMBER" datatype="java.lang.Double" physicalName="PRICE"
                  prompt="HLS.AMOUNT"/>
        <bm:field name="original_asset_value" databaseType="NUMBER" datatype="java.lang.Double"
                  physicalName="ORIGINAL_ASSET_VALUE" prompt="HLS_LEASE_ITEM.ORIGINAL_ASSET_VALUE"/>
        <bm:field name="net_asset_value" databaseType="NUMBER" datatype="java.lang.Double"
                  physicalName="NET_ASSET_VALUE" prompt="HLS_LEASE_ITEM.NET_ASSET_VALUE"/>
        <bm:field name="accumulated_depreciation" databaseType="NUMBER" datatype="java.lang.Double"
                  physicalName="ACCUMULATED_DEPRECIATION" prompt="HLS_LEASE_ITEM.ACCUMULATED_DEPRECIATION"/>
        <bm:field name="detention" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DETENTION"
                  prompt="HLS_LEASE_ITEM.DETENTION"/>
        <bm:field name="manufacturer_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MANUFACTURER_ID"
                  prompt="HLS_LEASE_ITEM.MANUFACTURER_ID"/>
        <bm:field name="manufacturer_name" databaseType="VARCHAR2" datatype="java.lang.String"
                  physicalName="MANUFACTURER_NAME" prompt="HLS_LEASE_ITEM.MANUFACTURER_NAME"/>
        <bm:field name="manufacturing_date" databaseType="NUMBER" datatype="java.lang.Long"
                  physicalName="MANUFACTURING_DATE" prompt="HLS_LEASE_ITEM.MANUFACTURING_DATE"/>
        <bm:field name="vender_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="VENDER_ID"
                  prompt="HLS_LEASE_ITEM.VENDER_ID"/>
        <bm:field name="vender_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="VENDER_NAME"
                  prompt="HLS.VENDER"/>
        <bm:field name="vender_id_n" expression="(select m.bp_name from hls_bp_master m where  m.bp_id=t1.vender_id)"
                  forInsert="false" forUpdate="false" prompt="HLS.VENDER"/>
        <bm:field name="installation_site" databaseType="VARCHAR2" datatype="java.lang.String"
                  physicalName="INSTALLATION_SITE" prompt="HLS_LEASE_ITEM.INSTALLATION_SITE"/>
        <bm:field name="fixed_assets_site" databaseType="VARCHAR2" datatype="java.lang.String"
                  physicalName="FIXED_ASSETS_SITE" prompt="HLS_LEASE_ITEM.FIXED_ASSETS_SITE"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION"
                  prompt="HLS_LEASE_ITEM.DESCRIPTION"/>
        <bm:field name="ref_v01" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V01"
                  prompt="HLS_LEASE_ITEM.REF_V01"/>
        <bm:field name="ref_v02" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V02"
                  prompt="HLS_LEASE_ITEM.REF_V02"/>
        <bm:field name="ref_v03" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V03"
                  prompt="HLS_LEASE_ITEM.REF_V03"/>
        <bm:field name="ref_v04" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V04"
                  prompt="HLS_LEASE_ITEM.REF_V04"/>
        <bm:field name="ref_v05" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V05"
                  prompt="HLS_LEASE_ITEM.REF_V05"/>
        <bm:field name="ref_n01" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N01"
                  prompt="HLS_LEASE_ITEM.REF_N01"/>
        <bm:field name="ref_n02" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N02"
                  prompt="HLS_LEASE_ITEM.REF_N02"/>
        <bm:field name="ref_n03" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N03"
                  prompt="HLS_LEASE_ITEM.REF_N03"/>
        <bm:field name="ref_n04" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N04"
                  prompt="HLS_LEASE_ITEM.REF_N04"/>
        <bm:field name="ref_n05" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N05"
                  prompt="HLS_LEASE_ITEM.REF_N05"/>
        <bm:field name="ref_d01" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D01"
                  prompt="HLS_LEASE_ITEM.REF_D01"/>
        <bm:field name="ref_d02" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D02"
                  prompt="HLS_LEASE_ITEM.REF_D02"/>
        <bm:field name="ref_d03" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D03"
                  prompt="HLS_LEASE_ITEM.REF_D03"/>
        <bm:field name="ref_d04" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D04"
                  prompt="HLS_LEASE_ITEM.REF_D04"/>
        <bm:field name="ref_d05" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D05"
                  prompt="HLS_LEASE_ITEM.REF_D05"/>
        <bm:field name="lease_item_type_desc"
                  expression="(select l.description from hls_lease_item_type l where l.lease_item_type=t1.lease_item_type)"
                  forInsert="false" forUpdate="false" prompt="HLS.LEASE_ITEM_TYPE"/>
        <bm:field name="uom_name"
                  expression="(select d.description_text from fnd_uom_codes_vl d where d.uom_code=t1.uom)"
                  forInsert="false" forUpdate="false"/>
        <bm:field name="li_list_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LI_LIST_TYPE"
                  prompt="HLS_LEASE_ITEM.LI_LIST_TYPE"/>
        <bm:field name="division"
                  expression="(select  c.division　from hls_lease_item_company c where c.lease_item_id=t1.lease_item_id and c.company_id=${/session/@company_id})"
                  forInsert="false" forUpdate="false"/>
        <bm:field name="enabled_flag_company"
                  expression="(select c.enabled_flag from hls_lease_item_company c where c.lease_item_id=t1.lease_item_id and c.company_id=${/session/@company_id})"
                  forInsert="false" forUpdate="false" prompt="HLS.ENABLED_FLAG"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <s:bm-script><![CDATA[
            var cx = Packages.leaf.javascript.Context.getCurrentContext();
            Packages.leaf.plugin.script.engine.ScriptImportor.defineExternScript(cx, this, $ctx.getData(), "aut_authority_bm_validate.js");
        ]]></s:bm-script>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="lease_item_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="lease_item_id" queryOperator="="/>
        <bm:query-field field="short_name" queryOperator="like"/>
        <bm:query-field name="lease_item_name" queryExpression="t1.full_name like ${@lease_item_name}"/>
        <bm:query-field name="project_id"
                        queryExpression=" exists (select 1           from prj_project_lease_item pl          where pl.lease_item_id = t1.lease_item_id and pl.project_id=${@project_id})"/>
        <bm:query-field name="contract_id"
                        queryExpression="exists (select 1           from con_contract_lease_item cl          where cl.lease_item_id = t1.lease_item_id and cl.contract_id=${@contract_id})"/>
        <bm:query-field name="contract_name"
                        queryExpression="exists (select 1           from con_contract_lease_item cl, con_contract_v cv          where cl.contract_id = cv.contract_id            and cl.lease_item_id = t1.lease_item_id            and cv.contract_name like ${@contract_name})"/>
        <bm:query-field name="project_name"
                        queryExpression="exists (select 1           from prj_project_lease_item pl, prj_project_v pv          where pl.project_id=pv.project_id            and pl.lease_item_id = t1.lease_item_id            and pv.project_name like ${@project_name})"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="query"
                        expression="(exists(select 1 from hls_lease_item_company hic where hic.lease_item_id=t1.lease_item_id and hic.company_id=${/session/@company_id}))"/>
    </bm:data-filters>
    <bm:operations>
        <bm:operation name="update">
            <!--  <bm:parameters>
                  <bm:parameter name="xml" databaseType="VARCHAR2" datatype="java.lang.String" output="true"
                                outputPath="/parameter/@xml"/>
              </bm:parameters>-->
            <bm:update-sql><![CDATA[
                begin
                      hls_lease_item_pkg.dcs_lease_item_interface(
                        p_user_id               => ${/session/@user_id}
                    );
                end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>

</bm:model>
