/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2013 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_sql varchar2(32000);

BEGIN

  --
  -- Register QueryWorkflowRolesByName service
  --
  l_sql :=
'        SELECT r.name
              ,r.display_name
              ,r.description
              ,r.email_address
              ,r.orig_system
              ,r.orig_system_id
              ,r.parent_orig_system
              ,r.parent_orig_system_id
              ,r.start_date
              ,r.status
              ,r.expiration_date
        FROM TABLE(xxas_wf_role_util_pkg.roles_by_display_name_tbl(:pSearchText, :pEffectiveDate)) r
        WHERE  r.name NOT IN
                 (SELECT column_value role_name
                  FROM   TABLE(xxas_wf_role_util_pkg.person_roles_tbl
                                (fnd_global.employee_id, :pEffectiveDate)))
        ORDER BY r.display_name ';

  xxas_com_sr_pkg.seed_query_service
    (p_service_name      => 'QueryWorkflowRolesByName'
    ,p_securing_function => 'XXAS_SRV_Q_WFR_BY_NAME_PERM'
    ,p_sql               => l_sql
    ,p_page_size         => 25
    ,p_parameters        => xxas_com_sr_param_varray
                              (xxas_com_sr_param_type('pSearchText'   , xxas_com_sr_pkg.g_VARCHAR2)
                              ,xxas_com_sr_param_type('pEffectiveDate', xxas_com_sr_pkg.g_DATE)));

END;
/
COMMIT;
EXIT;
