/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2015 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_product_list_v
AS
SELECT 'flexible' "type"
      ,fnd_global.employee_id person_id
      ,p.prod_key 
      ,p.product_name
      ,p.product_name
    || CASE WHEN p.license_tier IS NOT NULL
            THEN ' - ' || p.license_tier
       END
    || CASE WHEN p.license_expiry_date IS NOT NULL
            THEN ' (expires on '
              || xxas_util_pkg.format_date(p.license_expiry_date)
              || ')'
       END "line1"
      ,p.license_status "line2"      
      ,'<font color="'
     || xxas_rslt_cache_pkg.resolve_color_name('grey')
     || '">'
     || p.version || ' (' || p.latest_patch || ')'
     || '</font>' "line3"
      ,p.product_icon "icon"
      ,p.product_color "statusColor"
      ,xxas_util_pkg.get_serial(p.prod_key) serial_number
      ,XMLElement
         ("data"
          ,(XMLElement
             ("actions"
             ,XMLAttributes
               ('true' as "json:force-array"
               ,'http://json.org/' as "xmlns:json")
             ,XMLElement
                ("action"
                ,XMLForest
                  ('ACTIVATE'         "id"
                  ,CASE WHEN p.license_status_code = 'A'
                        THEN xxas_com_msg_pkg.get_string
                              ('XXAS_ACT_STATUS_UPD')
                        ELSE
                             xxas_com_msg_pkg.get_string
                              ('XXAS_ACT_STATUS_ACT')
                   END "title"
                  ,'LINK'             "operation"
                  ,'false'            "bulkActionEnabled"
                  ,'modal'            "target"
                  ,'activate-product' "pageId"
                  ,p.prod_key         "objectId"
                  )
                ,XMLElement
                  ("meta"
                  ,XMLElement
                    ("options"
                    ,XMLForest
                      ('balanced' as "color"
                      ,'null' as "weight"
                      )
                    )
                  )
                ) 
              )
            )
          ).extract('/data/*') AS "linked"
FROM xxas_products_details_v p;      

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_PRODUCT_LIST_V'
   ,p_description            => 'Applaud Products Lists');
END;
/

COMMIT;
EXIT;

