/* $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_block_contacts_v
AS
SELECT b.menu_id
      ,b.function_id
      ,b.function_name
	  ,b.seeded_block_flag
      ,b.entry_sequence
      ,b.prompt
      ,b.object_id
      ,b.obj_name
	  ,decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pHideIf'),null,'N','Y') RESTRICT_DEVICE
      ,(xxas_block_pkg.get_restrictions(b.function_parameters)) RESTRICTIONS
      ,b.description
      ,b.function_icon
      ,b.security_type type_of_security
      ,upper(b.block_type) block_type
      ,xxas_util_pkg.boolean_to_flag(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pStamp')) stamp
      ,xxas_util_pkg.boolean_to_flag(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pFullWidth')) full_width
      ,f.function_id data_function_id
      ,nvl(xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pOrderBy'),'nvl(transaction_step_id, -1) DESC, emrg_contact_flag DESC, emrg_contact_flag DESC, formatted_name') order_by
      ,xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pPersonIdColumnName') person_id_column_name
      ,xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pAssignmentIdColumnName') Assignment_Id_Column_Name
      ,xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pTransactionIdColumnName') transaction_id_column_name
      ,xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pPartyIdColumnName') party_Id_Column_Name
      ,nvl(o.object_id,xxas_rslt_cache_pkg.object_id('XXAS_PER_CONTACTS')) data_object_id
      ,xxas_com_sec_pkg.get_parameter_value(function_parameters, 'pFormulaName') view_formula_name
      ,xxas_com_msg_pkg.get_string(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pNoDataMessage')) no_data_text
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pNoDataMessage') no_data_message
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pBackgroundColor') background_color
      ,xxas_util_pkg.boolean_to_flag(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pLimitItems')) limit_list_items
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pDefaultItemsPerPage') items_per_page
      ,nvl(xxas_com_msg_pkg.get_string(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pMoreItemsAvailableLinkMessage')),xxas_com_msg_pkg.get_string('XXAS_COM_MORE_ITEMS_TEXT')) more_items_available_text
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pMoreItemsAvailableLinkMessage') more_items_available_message      
      ,p.context_handler page_object_handler
      ,p.object_id_format page_object_id_format
      ,CASE WHEN p.layout = 'columns2'
            THEN 'Y'
            WHEN p.layout = 'columns3'
            THEN 'Y'
            ELSE 'N'
       END  is_page_column_layout       
      ,p.layout page_layout
	  ,CASE WHEN p.layout = 'columns3' 
			THEN decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pBlockSize'),'two-third','Two-third','full-width','Full width','One-third') 
			ELSE NULL
		END BLOCK_SIZE
      ,CASE WHEN xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pPersonIdColumnName') IS NOT NULL 
              OR xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pAssignmentIdColumnName') IS NOT NULL 
              OR xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pTransactionIdColumnName') IS NOT NULL 
              OR xxas_com_sec_pkg.get_parameter_value(f.parameters, 'pPartyIdColumnName') IS NOT NULL 
            THEN 'Y'
            ELSE 'N'
       END  show_joining_columns
       FROM xxas_blocks_v b 
           ,fnd_objects_vl o 
           ,fnd_form_functions f
           , xxas_pages_v p
       WHERE  b.block_type = 'contacts'
          AND o.object_id (+) = f.object_id
          AND f.function_name(+) = xxas_com_sec_pkg.get_parameter_value(function_parameters, 'pDataFunction')
          AND    b.menu_id = p.menu_id;

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_BLOCK_CONTACTS_V'
   ,p_description            => 'Applaud Block Contacts');
END;
/

COMMIT;
EXIT;

