/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2010 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 Query Tagged People
  --
  l_sql :=
'        SELECT t.pk_id person_id
              ,xxas_util_pkg.get_formatted_name
                (papf.full_name
                ,papf.global_name
                ,papf.local_name
                ,papf.first_name
                ,papf.last_name) short_name
              ,null free_busy
              ,null avail_color
              ,null avail
              ,null avail_desc
              ,null avail_update
              ,null avail_icon
        FROM   xxas_com_tags t
              ,per_all_people_f papf
        WHERE  t.tag_id = :pTagId
        AND    t.entity_name = ''PERSON''
        AND    t.pk_id = papf.person_id
        AND    :pEffectiveDate BETWEEN
               papf.effective_start_date AND papf.effective_end_date
        AND  ((papf.current_employee_flag IS NOT NULL AND
               papf.current_employee_flag = ''Y'') OR
              (papf.current_npw_flag IS NOT NULL AND
               papf.current_npw_flag = ''Y''))
        ORDER BY 2 ';

  xxas_com_sr_pkg.seed_query_service
    (p_service_name      => 'QueryTaggedPeople'
    ,p_securing_function => 'XXAS_SRV_Q_TAGGED_PER_PERM'
    ,p_sql               => l_sql
    ,p_parameters        => xxas_com_sr_param_varray
                              (xxas_com_sr_param_type('pEffectiveDateTime' , xxas_com_sr_pkg.g_DATE)
                              ,xxas_com_sr_param_type('pEffectiveDate'     , xxas_com_sr_pkg.g_DATE)
                              ,xxas_com_sr_param_type('pTagId'             , xxas_com_sr_pkg.g_NUMBER)));

END;
/
COMMIT;
EXIT;
