/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2015 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

l_partic_id number;
l_count_check number;
l_user_id number;
CURSOR csr_user
IS
  SELECT usr.user_id
  FROM   fnd_user usr
  WHERE  usr.user_name = 'XXAS';
BEGIN

OPEN  csr_user;
FETCH csr_user into l_user_id;
CLOSE csr_user;

  fnd_global.apps_initialize(l_user_id, -1, -1, 0);
--
-- Create Employee Participant
-- Check if Employee Participant exists
--
 SELECT count ( 1 )
   INTO l_count_check
   FROM xxas_perf_participants_v xpp
  WHERE xpp.PARTICIPANT = 'Employee'
    AND PROVIDER_FUNCTION = 'xxas_perf_participants_pkg.get_employee';

 IF l_count_check = 0 THEN 
  xxas_perf_participants_pkg.insert_row
  (p_role_name                     =>   'Employee'
  ,p_provider_function             =>   'xxas_perf_participants_pkg.get_employee'
  ,p_perf_participant_id           =>   l_partic_id
  );
 END IF;
--
-- Create Manager Participant
-- Check if Manager Participant exists
--
 SELECT count ( 1 )
   INTO l_count_check
   FROM xxas_perf_participants_v xpp
  WHERE xpp.PARTICIPANT = 'Manager'
    AND PROVIDER_FUNCTION = 'xxas_perf_participants_pkg.get_manager';

 IF l_count_check = 0 THEN 
  xxas_perf_participants_pkg.insert_row
  (p_role_name                     =>   'Manager'
  ,p_provider_function             =>   'xxas_perf_participants_pkg.get_manager'
  ,p_perf_participant_id           =>   l_partic_id
  );
 END IF;
--
-- Create Grantee Participant
-- Check if Grantee Participant exists
-- 
 SELECT count ( 1 )
   INTO l_count_check
   FROM xxas_perf_participants_v xpp
  WHERE xpp.PARTICIPANT = 'Grantee'
    AND PROVIDER_FUNCTION = 'xxas_perf_participants_pkg.get_grantee'; 
    
 IF l_count_check = 0 THEN 
  xxas_perf_participants_pkg.insert_row
  (p_role_name                     =>   'Grantee'
  ,p_provider_function             =>   'xxas_perf_participants_pkg.get_grantee'
  ,p_perf_participant_id           =>   l_partic_id
  );
 END IF;    

END;
/
COMMIT;
EXIT;