/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2012 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
SET SCAN OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  l_luby    number := fnd_load_util.owner_id('XXAS');
  l_ludate  date   := to_date('2012/12/12', 'YYYY/MM/DD');
  l_rule_id number;
  
BEGIN

  SELECT fnd_form_custom_rules_s.nextval
  INTO   l_rule_id
  FROM   dual;

  INSERT INTO fnd_form_custom_rules
    (id                 
    ,function_name     
    ,description       
    ,trigger_event      
    ,trigger_object     
    ,condition      
    ,sequence          
    ,created_by         
    ,creation_date      
    ,last_updated_by              
    ,last_update_date   
    ,last_update_login  
    ,enabled   
    ,fire_in_enter_query
    ,rule_key
    ,form_name
    ,rule_type)
  VALUES
    (l_rule_id
    ,'PAYWSDET'
    ,'Applaud Store Element Type Id Reference'
    ,'WHEN-NEW-RECORD-INSTANCE'
    ,'ELEMENT_TYPES'
    ,':ELEMENT_TYPES.ELEMENT_TYPE_ID IS NOT NULL'
    ,'90'
    ,l_luby
    ,l_ludate
    ,l_luby
    ,l_ludate
    ,0
    ,'Y'
    ,'N'
    ,null
    ,'PAYWSDET'
    ,'F');
    
  INSERT INTO fnd_form_custom_actions
    (sequence
    ,property_value
    ,argument_type
    ,created_by
    ,creation_date
    ,last_updated_by
    ,last_update_date
    ,last_update_login
    ,target_object
    ,action_type
    ,enabled
    ,object_type
    ,folder_prompt_block
    ,message_type
    ,message_text
    ,summary
    ,builtin_type
    ,builtin_arguments
    ,language
    ,rule_id
    ,property_name
    ,menu_entry
    ,menu_label
    ,menu_seperator
    ,menu_enabled_in
    ,menu_action
    ,menu_argument_long
    ,menu_argument_short
    ,action_id
    ,request_application_id)  
  VALUES
    ('5'
    ,null
    ,'C'
    ,l_luby
    ,l_ludate
    ,l_luby
    ,l_ludate
    ,0
    ,null
    ,'B'
    ,'Y'
    ,'ITEM'
    ,null
    ,'S'
    ,null
    ,'Store Element Type Id Reference'
    ,'P'
    ,'=''BEGIN
       fnd_profile.put (''''XXAS_ELEMENT_TYPE_ID'''', '' ||${item.ELEMENT_TYPES.ELEMENT_TYPE_ID.value}||'');
   end'''
    ,'*'
    ,l_rule_id
    ,'1550'
    ,null
    ,null
    ,'N'
    ,null
    ,null
    ,'${item.ELEMENT_TYPES.ELEMENT_TYPE_ID.value}'
    ,null
    ,fnd_form_custom_actions_s.nextval
    ,null);
    
  INSERT INTO fnd_form_custom_scopes
    (rule_id
    ,level_id
    ,level_value
    ,level_value_application_id
    ,last_updated_by
    ,last_update_date
    ,created_by
    ,creation_date
    ,last_update_login)
  VALUES
    (l_rule_id
    ,'20'
    ,null
    ,null
    ,l_luby
    ,l_ludate
    ,l_luby
    ,l_ludate          
    ,0);

END;
/
COMMIT;
EXIT;
