<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ronghui.xu  
    $Date: 2012-3-27 上午11:03:08  
    $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 *
			  from (select fsb.responsibility_center_id,
			               fsb.responsibility_center_code,
			               fsb.responsibility_center_name_id,
			               fsb.set_of_books_id,
			               (select description_text
			                  from fnd_descriptions
			                 where description_id = fsb.responsibility_center_name_id
			                   and language = ${/session/@lang}) as responsibility_center_name,
			               fsb.responsibility_center_code || '-' ||
			               (select description_text
			                  from fnd_descriptions
			                 where description_id = fsb.responsibility_center_name_id
			                   and language = ${/session/@lang}) responsibility_code_name,
			               fsb.resp_center_type_code,
			               (select s.code_value_name 
							  from sys_code_values_vl s
							 where s.code_id = (select e.code_id
							                      from sys_codes_vl e
							                     where e.code = 'RESP_CENTER_TYPE')
							   and s.code_value=fsb.resp_center_type_code) resp_center_type_code_display,
			               fsb.summary_flag,
			               to_char(fsb.start_date_active, 'YYYY-MM-DD') as start_date_active,
			               to_char(fsb.end_date_active, 'YYYY-MM-DD') as end_date_active
			          from fnd_set_book_resp_centers fsb
			         order by fsb.responsibility_center_code) v
			  #WHERE_CLAUSE#
       
       
       ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
             
            begin

			  fnd_responsibility_center_pkg.insert_fnd_set_book_resp_cen(p_company_id => ${/session/@company_id},
			                                                             p_responsibility_center_code => ${@responsibility_center_code},
			                                                             p_responsibility_center_name => ${@responsibility_center_name},
			                                                             p_resp_center_type_code => ${@resp_center_type_code},
			                                                             p_summary_flag => ${@summary_flag},
			                                                             p_start_date_active => to_date(${@start_date_active},'YYYY-MM-DD'),
			                                                             p_end_date_active => to_date(${@end_date_active},'YYYY-MM-DD'),
			                                                             p_created_by => ${/session/@user_id},
			                                                             p_last_updated_by => ${/session/@user_id},
			                                                             p_responsibility_center_id => ${@responsibility_center_id},
			                                                             p_language_code         => ${/session/@lang});
			end;
            
           ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            begin
			  fnd_responsibility_center_pkg.update_fnd_set_book_resp_cen(p_responsibility_center_name => ${@responsibility_center_name},
			                                                             p_res_center_name_id => ${@responsibility_center_name_id},
			                                                             p_resp_center_type_code => ${@resp_center_type_code},
			                                                             p_start_date_active => to_date(${@start_date_active},'YYYY-MM-DD'),
			                                                             p_end_date_active => to_date(${@end_date_active},'YYYY-MM-DD'),
			                                                             p_created_by => ${/session/@user_id},
			                                                             p_last_updated_by => ${/session/@user_id},
			                                                             p_responsibility_center_id => ${@responsibility_center_id});
			                                                             
			  fnd_set_book_resp_centers_pkg.update_set_book_resp_centers(p_resp_center_id        => ${@responsibility_center_id},
			                                                             p_resp_center_code      => ${@responsibility_center_code},
			                                                             p_resp_center_type_code => ${@resp_center_type_code},
			                                                             p_summary_flag => ${@summary_flag},
			                                                             p_company_id => ${/session/@company_id},
			                                                             p_start_date_active     => to_date(${@start_date_active},'YYYY-MM-DD'),
			                                                             p_end_date_active       => to_date(${@end_date_active},'YYYY-MM-DD'),
			                                                             p_resp_center_name      => ${@responsibility_center_name},
			                                                             p_user_id               => ${/session/@user_id},
			                                                             p_language_code         => ${/session/@lang});
                                                             

            end;
           ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="responsibility_center_id"/>
        <bm:field name="responsibility_code_name"/>
        <bm:field name="resp_center_type_code_display"/>
        <bm:field name="resp_center_type_code"/>
        <bm:field name="start_date_active"/>
        <bm:field name="end_date_active"/>
        <bm:field name="summary_flag"/>
        <bm:field name="responsibility_center_name_id"/>
        <bm:field name="responsibility_center_code" displayWidth="200" forDisplay="true" forQuery="true" prompt="BGT_BUDGET_ITEM_MAPPING.RESPONSIBILITY_CENTER_CODE" queryWidth="120"/>
        <bm:field name="responsibility_center_name" displayWidth="200" forDisplay="true" forQuery="true" prompt="BGT_BUDGET_ITEM_MAPPING.RESPONSIBILITY_CENTER_DESC" queryWidth="120"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="set_of_books_id" queryExpression="v.set_of_books_id = ${@set_of_books_id}"/>
        <bm:query-field name="responsibility_center_code" queryExpression="v.responsibility_center_code like ${@responsibility_center_code}"/>
        <bm:query-field name="responsibility_center_name" queryExpression="v.responsibility_center_name like ${@responsibility_center_name}"/>
        <bm:query-field name="responsibility_center_id" queryExpression="v.responsibility_center_id = ${@responsibility_center_id}"/>
    </bm:query-fields>
</bm:model>
