/* $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

  --
  -- Local constants and variables
  --
  l_SERVICE CONSTANT xxas_com_service_repository.service_name%TYPE
                       := 'TimeTypes';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Types of time entry'
    ,p_path               => '/time-types'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
   
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetTimeTypes'
    ,p_description        => 'Get a list of time types'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
          SELECT XMLElement
                   ("data"
                   ,XMLAttributes
                     ('true' as "json:force-array"
                     ,'http://json.org/' as "xmlns:json")
                   ,XMLAgg
                     (XMLElement
                       ("timeType"
                       ,XMLForest
                         (rslt.element_type_id "id"
                         ,nvl(eit.eei_information3, rslt.element_name) "title")
                       ,xxas_tcm_config_pkg.fields_xml(rslt.element_type_id)
                       ) ORDER BY nvl(to_number(eit.eei_information18), 999)
                                 ,nvl(eit.eei_information3, rslt.element_name)
                     )
                   ) "data"
          FROM   pay_element_types_f_vl rslt
                ,fnd_currencies_vl cur
                ,pay_element_type_extra_info eit
          WHERE  rslt.element_type_id = eit.element_type_id
          AND    rslt.input_currency_code = cur.currency_code(+)
          AND    eit.information_type = 'XXAS_TCM_ENTRY_MAP'
          AND    eit.eei_information1 IS NOT NULL
          AND    eit.eei_information1 = 'Y'
          AND    trunc(sysdate) BETWEEN
                 rslt.effective_start_date AND rslt.effective_end_date
          AND    {authFunctionPredicate.XXAS_TIME_TYPES_VIEW}
      ]'
    );
    
END;
/
COMMIT;
EXIT;
