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

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

CREATE OR REPLACE VIEW XXAS_PERF_PLAN_SWITCH_LIST_V
AS
SELECT  'flexible' "type"
       ,xppe.perf_plan_enrollment_id "id"
       ,xppe.person_id
       ,xppe.perf_plan_enrollment_id
       ,xpp.perf_plan_id
       ,xppe.start_date
       ,xppe.end_date
       ,CASE WHEN xppe.start_date > trunc(sysdate) THEN
                  'calendar'
             WHEN xppe.end_date < trunc(sysdate) THEN
                  'tick'
             ELSE 'spinner'
        END "icon"
       ,CASE WHEN xppe.start_date > trunc(sysdate) THEN
                  xxas_rslt_cache_pkg.resolve_color_name('grey')
             WHEN xppe.end_date < trunc(sysdate) THEN
                  xxas_rslt_cache_pkg.resolve_color_name('green')
             ELSE xxas_rslt_cache_pkg.resolve_color_name('orange')
        END "statusColor"
       ,xppe.title "line1"
       ,'<font color="'
     || xxas_rslt_cache_pkg.resolve_color_name('grey')
     || '">'
     || to_char(xppe.start_date,'Fmdd Mon YYYY')
     || ' to '
     || to_char(xppe.end_date,'Fmdd Mon YYYY')
     || '</font>' "line3"
       ,'performance' "pageId"
       ,xppe.person_id || '_' || xppe.perf_plan_enrollment_id "objectId"
  FROM  xxas_perf_plans_v xpp
       ,xxas_perf_plan_enrollments_v xppe
  WHERE xpp.perf_plan_id = xppe.perf_plan_id;

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_PERF_PLAN_SWITCH_LIST_V'
   ,p_description            => 'Applaud Performance Plan Switch List');
END;
/

COMMIT;
EXIT;