/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2017 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_cost_key_ff_v
AS
SELECT  pcak.cost_allocation_keyflex_id
       ,pcak.id_flex_num
       ,pcak.concatenated_segments
       ,pcak.segment1              segment1
       ,pcak_tbl.segment1_value    segment1_value
       ,pcak_tbl.segment1_meaning  segment1_meaning
       ,pcak.segment2              segment2
       ,pcak_tbl.segment2_value    segment2_value
       ,pcak_tbl.segment2_meaning  segment2_meaning
       ,pcak.segment3              segment3
       ,pcak_tbl.segment3_value    segment3_value
       ,pcak_tbl.segment3_meaning  segment3_meaning
       ,pcak.segment4              segment4
       ,pcak_tbl.segment4_value    segment4_value
       ,pcak_tbl.segment4_meaning  segment4_meaning
       ,pcak.segment5              segment5
       ,pcak_tbl.segment5_value    segment5_value
       ,pcak_tbl.segment5_meaning  segment5_meaning
       ,pcak.segment6              segment6
       ,pcak_tbl.segment6_value    segment6_value
       ,pcak_tbl.segment6_meaning  segment6_meaning
       ,pcak.segment7              segment7
       ,pcak_tbl.segment7_value    segment7_value
       ,pcak_tbl.segment7_meaning  segment7_meaning
       ,pcak.segment8              segment8
       ,pcak_tbl.segment8_value    segment8_value
       ,pcak_tbl.segment8_meaning  segment8_meaning
       ,pcak.segment9              segment9
       ,pcak_tbl.segment9_value    segment9_value
       ,pcak_tbl.segment9_meaning  segment9_meaning
       ,pcak.segment10             segment10
       ,pcak_tbl.segment10_value   segment10_value
       ,pcak_tbl.segment10_meaning segment10_meaning
       ,pcak.segment11             segment11
       ,pcak_tbl.segment11_value   segment11_value
       ,pcak_tbl.segment11_meaning segment11_meaning
       ,pcak.segment12             segment12
       ,pcak_tbl.segment12_value   segment12_value
       ,pcak_tbl.segment12_meaning segment12_meaning
       ,pcak.segment13             segment13
       ,pcak_tbl.segment13_value   segment13_value
       ,pcak_tbl.segment13_meaning segment13_meaning
       ,pcak.segment14             segment14
       ,pcak_tbl.segment14_value   segment14_value
       ,pcak_tbl.segment14_meaning segment14_meaning
       ,pcak.segment15             segment15
       ,pcak_tbl.segment15_value   segment15_value
       ,pcak_tbl.segment15_meaning segment15_meaning
       ,pcak.segment16             segment16
       ,pcak_tbl.segment16_value   segment16_value
       ,pcak_tbl.segment16_meaning segment16_meaning
       ,pcak.segment17             segment17
       ,pcak_tbl.segment17_value   segment17_value
       ,pcak_tbl.segment17_meaning segment17_meaning
       ,pcak.segment18             segment18
       ,pcak_tbl.segment18_value   segment18_value
       ,pcak_tbl.segment18_meaning segment18_meaning
       ,pcak.segment19             segment19
       ,pcak_tbl.segment19_value   segment19_value
       ,pcak_tbl.segment19_meaning segment19_meaning
       ,pcak.segment20             segment20
       ,pcak_tbl.segment20_value   segment20_value
       ,pcak_tbl.segment20_meaning segment20_meaning
       ,pcak.segment21             segment21
       ,pcak_tbl.segment21_value   segment21_value
       ,pcak_tbl.segment21_meaning segment21_meaning
       ,pcak.segment22             segment22
       ,pcak_tbl.segment22_value   segment22_value
       ,pcak_tbl.segment22_meaning segment22_meaning
       ,pcak.segment23             segment23
       ,pcak_tbl.segment23_value   segment23_value
       ,pcak_tbl.segment23_meaning segment23_meaning
       ,pcak.segment24             segment24
       ,pcak_tbl.segment24_value   segment24_value
       ,pcak_tbl.segment24_meaning segment24_meaning
       ,pcak.segment25             segment25
       ,pcak_tbl.segment25_value   segment25_value
       ,pcak_tbl.segment25_meaning segment25_meaning
       ,pcak.segment26             segment26
       ,pcak_tbl.segment26_value   segment26_value
       ,pcak_tbl.segment26_meaning segment26_meaning
       ,pcak.segment27             segment27
       ,pcak_tbl.segment27_value   segment27_value
       ,pcak_tbl.segment27_meaning segment27_meaning
       ,pcak.segment28             segment28
       ,pcak_tbl.segment28_value   segment28_value
       ,pcak_tbl.segment28_meaning segment28_meaning
       ,pcak.segment29             segment29
       ,pcak_tbl.segment29_value   segment29_value
       ,pcak_tbl.segment29_meaning segment29_meaning
       ,pcak.segment30             segment30
       ,pcak_tbl.segment30_value   segment30_value
       ,pcak_tbl.segment30_meaning segment30_meaning
FROM    pay_cost_allocation_keyflex pcak
       ,fnd_id_flex_structures fifs 
       ,table(xxas_com_flex_pkg.kff_value_set_details
                (xxas_util_pkg.get_app_id('PAY')
                ,'COST'
                ,fifs.id_flex_structure_code
                ,'SEGMENT1'
                ,pcak.segment1
                ,'SEGMENT2'
                ,pcak.segment2
                ,'SEGMENT3'
                ,pcak.segment3
                ,'SEGMENT4'
                ,pcak.segment4
                ,'SEGMENT5'
                ,pcak.segment5
                ,'SEGMENT6'
                ,pcak.segment6
                ,'SEGMENT7'
                ,pcak.segment7
                ,'SEGMENT8'
                ,pcak.segment8
                ,'SEGMENT9'
                ,pcak.segment9
                ,'SEGMENT10'
                ,pcak.segment10
                ,'SEGMENT11'
                ,pcak.segment11
                ,'SEGMENT12'
                ,pcak.segment12
                ,'SEGMENT13'
                ,pcak.segment13
                ,'SEGMENT14'
                ,pcak.segment14
                ,'SEGMENT15'
                ,pcak.segment15
                ,'SEGMENT16'
                ,pcak.segment16
                ,'SEGMENT17'
                ,pcak.segment17
                ,'SEGMENT18'
                ,pcak.segment18
                ,'SEGMENT19'
                ,pcak.segment19
                ,'SEGMENT20'
                ,pcak.segment20
                ,'SEGMENT21'
                ,pcak.segment21
                ,'SEGMENT22'
                ,pcak.segment22
                ,'SEGMENT23'
                ,pcak.segment23
                ,'SEGMENT24'
                ,pcak.segment24
                ,'SEGMENT25'
                ,pcak.segment25
                ,'SEGMENT26'
                ,pcak.segment26
                ,'SEGMENT27'
                ,pcak.segment27
                ,'SEGMENT28'
                ,pcak.segment28
                ,'SEGMENT29'
                ,pcak.segment29
                ,'SEGMENT30'
                ,pcak.segment30)) pcak_tbl
WHERE   pcak.id_flex_num    = fifs.id_flex_num
AND     fifs.application_id = xxas_util_pkg.get_app_id('PAY')
AND     fifs.id_flex_code   = 'COST';

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_COST_KEY_FF_V'
   ,p_description            => 'Applaud Cost Allocation Key Flex Field View');
END;
/

COMMIT;
EXIT;

