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

SET VERIFY OFF
SET FEEDBACK OFF
SET ESCAPE '\'
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  e_no_bg_id          EXCEPTION;
  e_bg_not_exists     EXCEPTION;
  e_ff_type_not_found EXCEPTION;
  l_BG_ID   CONSTANT  NUMBER        := to_number('&1');
  l_USER_ID CONSTANT  NUMBER        := to_number('&2');
  l_START   CONSTANT  DATE          := to_date('1900-01-01','YYYY-MM-DD');
  l_END     CONSTANT  DATE          := xxas_util_pkg.eot;
  l_FF_NAME CONSTANT  VARCHAR2(80)  := 'XXAS_EMP_ASG_EIT_VIEW';
  l_FF_DESC CONSTANT  VARCHAR2(240) := 'ASG EIT View';
  l_FF_TYPE CONSTANT  varchar2(30)  := 'Applaud Assignment';
  l_formula_text      LONG;
  l_formula_type_id   NUMBER;
  l_ff_id             NUMBER;
  l_bg_exists         VARCHAR2(1);

  --
  -- Tests if the Business Group already exists
  --
  CURSOR csr_bg_exists IS
  SELECT 'Y'
  FROM   per_business_groups_perf bg
  WHERE  bg.business_group_id = l_BG_ID;

  --
  -- Gets the FF Id
  --
  CURSOR csr_ff_id IS
  SELECT ff.formula_id
  FROM   ff_formulas_f ff
  WHERE  ff.business_group_id = l_BG_ID
  AND    ff.formula_name = l_FF_NAME;

  --
  -- Gets the Formula Type Id
  --
  CURSOR csr_ff_type IS
  SELECT fft.formula_type_id
  FROM   ff_formula_types fft
  WHERE  fft.formula_type_name = l_FF_TYPE;

BEGIN

  --
  -- Check that the Business Group Id was passed in
  --
  IF l_BG_ID IS NULL THEN
    RAISE e_no_bg_id;
  END IF;

  --
  -- Check the Business Group exists
  --
  OPEN  csr_bg_exists;
  FETCH csr_bg_exists INTO l_bg_exists;
  CLOSE csr_bg_exists;

  IF l_bg_exists IS NULL THEN
    RAISE e_bg_not_exists;
  END IF;

  --
  -- Fetch the Fast Formula Id
  --
  OPEN  csr_ff_id;
  FETCH csr_ff_id INTO l_ff_id;
  CLOSE csr_ff_id;

  --
  -- Get the Formula Type; error if it cannot be found
  --
  OPEN  csr_ff_type;
  FETCH csr_ff_type INTO l_formula_type_id;
  CLOSE csr_ff_type;

  IF l_formula_type_id IS NULL THEN
    RAISE e_ff_type_not_found;
  END IF;

  --
  -- Set the Formula Text
  --
  l_formula_text := '
/*==============================================================================

Formula Name: XXAS_EMP_ASG_EIT_VIEW
Formula Type: Applaud Assignment
Description:  ASG EIT View
==============================================================================*/
  /**************************************************************************/
  /*  DEFAULTS BLOCK - Change to default Segments for your SIT/EIT          */
  /*                   You can remove segments that aren''t used             */
  /*                                                                        */
  /**************************************************************************/

  Default for Transaction_Type        is ''NONE''
  Default for Workflow_Status_Code    is ''NONE''
  Default for Workflow_Status_Meaning is ''None''

  Default for aei_Information1                is ''Unknown''
  Default for aei_Information1_p              is ''Unknown''
  Default for aei_Information1_Meaning        is ''Unknown''
  Default for aei_Information1_Meaning_p      is ''Unknown''

  Default for Date_From  is ''0001/01/01 00:00:00'' (date)

  /*******************************************************************/
  /* Use this Block for Date Based Fields                            */
  /* In these cases, Meaning is never needed                         */
  /*                                                                 */
  /* Default for aei_Information1    is ''0001/01/01 00:00:00'' (date) */
  /* Default for aei_Information1_p  is ''0001/01/01 00:00:00'' (date) */
  /*******************************************************************/

  Default for aei_Information2                is ''Unknown''
  Default for aei_Information2_p              is ''Unknown''
  Default for aei_Information2_Meaning        is ''Unknown''
  Default for aei_Information2_Meaning_p      is ''Unknown''

  Default for aei_Information3                is ''Unknown''
  Default for aei_Information3_p              is ''Unknown''
  Default for aei_Information3_Meaning        is ''Unknown''
  Default for aei_Information3_Meaning_p      is ''Unknown''

  Default for aei_Information4                is ''Unknown''
  Default for aei_Information4_p              is ''Unknown''
  Default for aei_Information4_Meaning        is ''Unknown''
  Default for aei_Information4_Meaning_p      is ''Unknown''

  Default for aei_Information5                is ''Unknown''
  Default for aei_Information5_p              is ''Unknown''
  Default for aei_Information5_Meaning        is ''Unknown''
  Default for aei_Information5_Meaning_p      is ''Unknown''

  Default for aei_Information6                is ''Unknown''
  Default for aei_Information6_p              is ''Unknown''
  Default for aei_Information6_Meaning        is ''Unknown''
  Default for aei_Information6_Meaning_p      is ''Unknown''

  Default for aei_Information7                is ''Unknown''
  Default for aei_Information7_p              is ''Unknown''
  Default for aei_Information7_Meaning        is ''Unknown''
  Default for aei_Information7_Meaning_p      is ''Unknown''

  Default for aei_Information8                is ''Unknown''
  Default for aei_Information8_p              is ''Unknown''
  Default for aei_Information8_Meaning        is ''Unknown''
  Default for aei_Information8_Meaning_p      is ''Unknown''

  Default for aei_Information9                is ''Unknown''
  Default for aei_Information9_p              is ''Unknown''
  Default for aei_Information9_Meaning        is ''Unknown''
  Default for aei_Information9_Meaning_p      is ''Unknown''

  Default for aei_Information10                is ''Unknown''
  Default for aei_Information10_p              is ''Unknown''
  Default for aei_Information10_Meaning        is ''Unknown''
  Default for aei_Information10_Meaning_p      is ''Unknown''

  Default for aei_Information11                is ''Unknown''
  Default for aei_Information11_p              is ''Unknown''
  Default for aei_Information11_Meaning        is ''Unknown''
  Default for aei_Information11_Meaning_p      is ''Unknown''

  Default for aei_Information12                is ''Unknown''
  Default for aei_Information12_p              is ''Unknown''
  Default for aei_Information12_Meaning        is ''Unknown''
  Default for aei_Information12_Meaning_p      is ''Unknown''

  Default for aei_Information13                is ''Unknown''
  Default for aei_Information13_p              is ''Unknown''
  Default for aei_Information13_Meaning        is ''Unknown''
  Default for aei_Information13_Meaning_p      is ''Unknown''

  Default for aei_Information14                is ''Unknown''
  Default for aei_Information14_p              is ''Unknown''
  Default for aei_Information14_Meaning        is ''Unknown''
  Default for aei_Information14_Meaning_p      is ''Unknown''

  Default for aei_Information15                is ''Unknown''
  Default for aei_Information15_p              is ''Unknown''
  Default for aei_Information15_Meaning        is ''Unknown''
  Default for aei_Information15_Meaning_p      is ''Unknown''

  Default for aei_Information16                is ''Unknown''
  Default for aei_Information16_p              is ''Unknown''
  Default for aei_Information16_Meaning        is ''Unknown''
  Default for aei_Information16_Meaning_p      is ''Unknown''

  Default for aei_Information17                is ''Unknown''
  Default for aei_Information17_p              is ''Unknown''
  Default for aei_Information17_Meaning        is ''Unknown''
  Default for aei_Information17_Meaning_p      is ''Unknown''

  Default for aei_Information18                is ''Unknown''
  Default for aei_Information18_p              is ''Unknown''
  Default for aei_Information18_Meaning        is ''Unknown''
  Default for aei_Information18_Meaning_p      is ''Unknown''

  Default for aei_Information19                 is ''Unknown''
  Default for aei_Information19_p               is ''Unknown''
  Default for aei_Information19_Meaning        is ''Unknown''
  Default for aei_Information19_Meaning_p      is ''Unknown''

  Default for aei_Information20                is ''Unknown''
  Default for aei_Information20_p              is ''Unknown''
  Default for aei_Information20_Meaning        is ''Unknown''
  Default for aei_Information20_Meaning_p      is ''Unknown''

  Default for aei_Information21                is ''Unknown''
  Default for aei_Information21_p              is ''Unknown''
  Default for aei_Information21_Meaning        is ''Unknown''
  Default for aei_Information21_Meaning_p      is ''Unknown''

  Default for aei_Information22                is ''Unknown''
  Default for aei_Information22_p              is ''Unknown''
  Default for aei_Information22_Meaning        is ''Unknown''
  Default for aei_Information22_Meaning_p      is ''Unknown''

  Default for aei_Information23                is ''Unknown''
  Default for aei_Information23_p              is ''Unknown''
  Default for aei_Information23_Meaning        is ''Unknown''
  Default for aei_Information23_Meaning_p      is ''Unknown''

  Default for aei_Information24                is ''Unknown''
  Default for aei_Information24_p              is ''Unknown''
  Default for aei_Information24_Meaning        is ''Unknown''
  Default for aei_Information24_Meaning_p      is ''Unknown''

  Default for aei_Information25                is ''Unknown''
  Default for aei_Information25_p              is ''Unknown''
  Default for aei_Information25_Meaning        is ''Unknown''
  Default for aei_Information25_Meaning_p      is ''Unknown''

  Default for aei_Information26                is ''Unknown''
  Default for aei_Information26_p              is ''Unknown''
  Default for aei_Information26_Meaning        is ''Unknown''
  Default for aei_Information26_Meaning_p      is ''Unknown''

  Default for aei_Information27                is ''Unknown''
  Default for aei_Information27_p              is ''Unknown''
  Default for aei_Information27_Meaning        is ''Unknown''
  Default for aei_Information27_Meaning_p      is ''Unknown''

  Default for aei_Information28                is ''Unknown''
  Default for aei_Information28_p              is ''Unknown''
  Default for aei_Information28_Meaning        is ''Unknown''
  Default for aei_Information28_Meaning_p      is ''Unknown''

  Default for aei_Information29                is ''Unknown''
  Default for aei_Information29_p              is ''Unknown''
  Default for aei_Information29_Meaning        is ''Unknown''
  Default for aei_Information29_Meaning_p      is ''Unknown''

  Default for aei_Information30                is ''Unknown''
  Default for aei_Information30_p              is ''Unknown''
  Default for aei_Information30_Meaning        is ''Unknown''
  Default for aei_Information30_Meaning_p      is ''Unknown''

  /**************************************************************************/
  /*  INPUTS BLOCK - Change to Pass in the correct Segments for your SIT/EIT*/
  /*                 You can remove Segments that aren''t used               */
  /**************************************************************************/
  Inputs are Transaction_Type, Workflow_Status_Code, Workflow_Status_Meaning,
             Date_From,
             aei_Information1, aei_Information1_Meaning, aei_Information1_p, aei_Information1_Meaning_P,
             aei_Information2, aei_Information2_Meaning, aei_Information2_p, aei_Information2_Meaning_P,
             aei_Information3, aei_Information3_Meaning, aei_Information3_p, aei_Information3_Meaning_P,
             aei_Information4, aei_Information4_Meaning, aei_Information4_p, aei_Information4_Meaning_P,
             aei_Information5, aei_Information5_Meaning, aei_Information5_p, aei_Information5_Meaning_P,
             aei_Information6, aei_Information6_Meaning, aei_Information6_p, aei_Information6_Meaning_P,
             aei_Information7, aei_Information7_Meaning, aei_Information7_p, aei_Information7_Meaning_P,
             aei_Information8, aei_Information8_Meaning, aei_Information8_p, aei_Information8_Meaning_P,
             aei_Information9, aei_Information9_Meaning, aei_Information9_p, aei_Information9_Meaning_P,
             aei_Information10, aei_Information10_Meaning, aei_Information10_p, aei_Information10_Meaning_P,
             aei_Information11, aei_Information11_Meaning, aei_Information11_p, aei_Information11_Meaning_P,
             aei_Information12, aei_Information12_Meaning, aei_Information12_p, aei_Information12_Meaning_P,
             aei_Information13, aei_Information13_Meaning, aei_Information13_p, aei_Information13_Meaning_P,
             aei_Information14, aei_Information14_Meaning, aei_Information14_p, aei_Information14_Meaning_P,
             aei_Information15, aei_Information15_Meaning, aei_Information15_p, aei_Information15_Meaning_P,
             aei_Information16, aei_Information16_Meaning, aei_Information16_p, aei_Information16_Meaning_P,
             aei_Information17, aei_Information17_Meaning, aei_Information17_p, aei_Information17_Meaning_P,
             aei_Information18, aei_Information18_Meaning, aei_Information18_p, aei_Information18_Meaning_P,
             aei_Information19, aei_Information19_Meaning, aei_Information19_p, aei_Information19_Meaning_P,
             aei_Information20, aei_Information20_Meaning, aei_Information20_p, aei_Information20_Meaning_P,
             aei_Information21, aei_Information21_Meaning, aei_Information21_p, aei_Information21_Meaning_P,
             aei_Information22, aei_Information22_Meaning, aei_Information22_p, aei_Information22_Meaning_P,
             aei_Information23, aei_Information23_Meaning, aei_Information23_p, aei_Information23_Meaning_P,
             aei_Information24, aei_Information24_Meaning, aei_Information24_p, aei_Information24_Meaning_P,
             aei_Information25, aei_Information25_Meaning, aei_Information25_p, aei_Information25_Meaning_P,
             aei_Information26, aei_Information26_Meaning, aei_Information26_p, aei_Information26_Meaning_P,
             aei_Information27, aei_Information27_Meaning, aei_Information27_p, aei_Information27_Meaning_P,
             aei_Information28, aei_Information28_Meaning, aei_Information28_p, aei_Information28_Meaning_P,
             aei_Information29, aei_Information29_Meaning, aei_Information29_p, aei_Information29_Meaning_P,
             aei_Information30, aei_Information30_Meaning, aei_Information30_p, aei_Information30_Meaning_P

  /*************************************************************************/
  /*  COLORS BLOCK - Do Not Change                                         */
  /*************************************************************************/
  COLOR_GREEN    = ''#499324''
  COLOR_AMBER    = ''#FF9900''
  COLOR_RED      = ''#CC0000''
  COLOR_DEEP_RED = ''#FF0000''
  COLOR_GREY     = ''#333333''
  COLOR_BLUE     = ''#3366CC''
  START_OF_TIME  = to_date(''0001/01/01 00:00:00'', ''YYYY/MM/DD HH24:MI:SS'')

  /*************************************************************************/
  /*  BLOCK #1                                                             */
  /*  Change this section to reflect the columns you wish to show          */
  /*                                                                       */
  /*************************************************************************/

  If Transaction_Type = ''INSERT'' Then
    (
     field1 = aei_Information1_p
     field2 = aei_Information2_p
     field3 = aei_Information3_p
     field4 = aei_Information4_p
     field5 = aei_Information5_p
     field6 = aei_Information6_p
     field7 = aei_Information7_p
     field8 = aei_Information8_p
     field9 = aei_Information9_p
     field10 = aei_Information10_p
     field11 = aei_Information11_p
     field12 = aei_Information12_p
     field13 = aei_Information13_p
     field14 = aei_Information14_p
     field15 = aei_Information15_p
     field16 = aei_Information16_p
     field17 = aei_Information17_p
     field18 = aei_Information18_p
     field19 = aei_Information19_p
     field20 = aei_Information20_p
     field21 = aei_Information21_p
     field22 = aei_Information22_p
     field23 = aei_Information23_p
     field24 = aei_Information24_p
     field25 = aei_Information25_p
     field26 = aei_Information26_p
     field27 = aei_Information27_p
     field28 = aei_Information28_p
     field29 = aei_Information29_p
     field30 = aei_Information30_p

    /**********************************************************/
    /* Use for Date fields                                    */
    /* field1 = to_char(aei_Information2_p, ''dd Month YYYY'')*/
    /**********************************************************/
    /* Use when meanings are needed     
     field1 = aei_Information1_Meaning_p
     field2 = aei_Information2_Meaning_p
     field3 = aei_Information3_Meaning_p
     field4 = aei_Information4_Meaning_p
     field5 = aei_Information5_Meaning_p
     field6 = aei_Information6_Meaning_p
     field7 = aei_Information7_Meaning_p
     field8 = aei_Information8_Meaning_p
     field9 = aei_Information9_Meaning_p
     field10 = aei_Information10_Meaning_p
     field11 = aei_Information11_Meaning_p
     field12 = aei_Information12_Meaning_p
     field13 = aei_Information13_Meaning_p
     field14 = aei_Information14_Meaning_p
     field15 = aei_Information15_Meaning_p
     field16 = aei_Information16_Meaning_p
     field17 = aei_Information17_Meaning_p
     field18 = aei_Information18_Meaning_p
     field19 = aei_Information19_Meaning_p
     field20 = aei_Information20_Meaning_p
     field21 = aei_Information21_Meaning_p
     field22 = aei_Information22_Meaning_p
     field23 = aei_Information23_Meaning_p
     field24 = aei_Information24_Meaning_p
     field25 = aei_Information25_Meaning_p
     field26 = aei_Information26_Meaning_p
     field27 = aei_Information27_Meaning_p
     field28 = aei_Information28_Meaning_p
     field29 = aei_Information29_Meaning_p
     field30 = aei_Information30_Meaning_p
    ************************************/
    )
  Else
    (
     field1 = aei_Information1
     field2 = aei_Information2
     field3 = aei_Information3
     field4 = aei_Information4
     field5 = aei_Information5
     field6 = aei_Information6
     field7 = aei_Information7
     field8 = aei_Information8
     field9 = aei_Information9
     field10 = aei_Information10
     field11 = aei_Information11
     field12 = aei_Information12
     field13 = aei_Information13
     field14 = aei_Information14
     field15 = aei_Information15
     field16 = aei_Information16
     field17 = aei_Information17
     field18 = aei_Information18
     field19 = aei_Information19
     field20 = aei_Information20
     field21 = aei_Information21
     field22 = aei_Information22
     field23 = aei_Information23
     field24 = aei_Information24
     field25 = aei_Information25
     field26 = aei_Information26
     field27 = aei_Information27
     field28 = aei_Information28
     field29 = aei_Information29
     field30 = aei_Information30

    /**********************************************************/
    /* Use for Date fields                                    */
    /* field1 = to_char(aei_Information2_p, ''dd Month YYYY'')*/
    /**********************************************************/
    /* Use when meanings are needed     
     field1 = aei_Information1_Meaning
     field2 = aei_Information2_Meaning
     field3 = aei_Information3_Meaning
     field4 = aei_Information4_Meaning
     field5 = aei_Information5_Meaning
     field6 = aei_Information6_Meaning
     field7 = aei_Information7_Meaning
     field8 = aei_Information8_Meaning
     field9 = aei_Information9_Meaning
     field10 = aei_Information10_Meaning
     field11 = aei_Information11_Meaning
     field12 = aei_Information12_Meaning
     field13 = aei_Information13_Meaning
     field14 = aei_Information14_Meaning
     field15 = aei_Information15_Meaning
     field16 = aei_Information16_Meaning
     field17 = aei_Information17_Meaning
     field18 = aei_Information18_Meaning
     field19 = aei_Information19_Meaning
     field20 = aei_Information20_Meaning
     field21 = aei_Information21_Meaning
     field22 = aei_Information22_Meaning
     field23 = aei_Information23_Meaning
     field24 = aei_Information24_Meaning
     field25 = aei_Information25_Meaning
     field26 = aei_Information26_Meaning
     field27 = aei_Information27_Meaning
     field28 = aei_Information28_Meaning
     field29 = aei_Information29_Meaning
     field30 = aei_Information30_Meaning
    ************************************/
    )

  /*************************************************************************/
  /*  End of BLOCK #1                                                      */
  /*************************************************************************/

  /*************************************************************************/
  /*  BLOCK #2 - Do Not Change                                             */
  /*************************************************************************/

  /* Set the status color based on its status */
Summary_Context = '' ''

  If Transaction_Type was not defaulted then
    (
     If Transaction_Type = ''INSERT'' then
       (Status_Text  = ''New: '')
     Else If Transaction_Type = ''UPDATE'' then
       (Status_Text  = ''Updated: '')
     Else
       (Status_Text  = ''Deleted: '')

     Status_Text = Status_Text + Workflow_Status_Meaning

     If Workflow_Status_Code = ''RFC'' Then
       (Status_Color = COLOR_RED)
     Else If Workflow_Status_Code = ''ERROR'' Then
       (Status_Color = COLOR_DEEP_RED)
     Else If Workflow_Status_Code = ''SFL'' Then
       (Status_Color = COLOR_GREY)
     Else If Workflow_Status_Code = ''APPROVED'' Then
       (Status_Color = COLOR_GREEN)
     Else
       (Status_Color = COLOR_AMBER)
       Summary_Context = ''<p><font color="'' + Status_Color + ''">'' + Status_Text + ''</font></p>''
    )

  Info_Type  =  ''INFO-TYPE'' 

  If Transaction_Type = ''INSERT'' Then
    (
       loc_num = 1
  loc_char = ''Y''
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION1'',aei_Information1_Meaning_P,''Y'',aei_Information1_Meaning_P,Status_Color)

       loc_num = 2
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION2'',aei_Information2_Meaning_P,''Y'',aei_Information2_Meaning_P,Status_Color)

       loc_num = 3
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION3'',aei_Information3_Meaning_P,''Y'',aei_Information3_Meaning_P,Status_Color)

       loc_num = 4
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION4'',aei_Information4_Meaning_P,''Y'',aei_Information4_Meaning_P,Status_Color)

       loc_num = 5
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION5'',aei_Information5_Meaning_P,''Y'',aei_Information5_Meaning_P,Status_Color)

       loc_num = 6
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION6'',aei_Information6_Meaning_P,''Y'',aei_Information6_Meaning_P,Status_Color)

       loc_num = 7
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION7'',aei_Information7_Meaning_P,''Y'',aei_Information7_Meaning_P,Status_Color)

       loc_num = 8
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION8'',aei_Information8_Meaning_P,''Y'',aei_Information8_Meaning_P,Status_Color)

       loc_num = 9
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION9'',aei_Information9_Meaning_P,''Y'',aei_Information9_Meaning_P,Status_Color)

/*****************************************************************************/
/*  Extend this as required 10 to 30                                         */
/*****************************************************************************/

       loc_num = 30
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION30'',aei_Information30_Meaning_P,''Y'',aei_Information30_Meaning_P,Status_Color)

    )
  Else 
  If Transaction_Type = ''UPDATE'' Then
  (
       loc_num = 1
  loc_char = ''Y''
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION1'',aei_Information1_Meaning,''Y'',aei_Information1_Meaning_P,Status_Color)

       loc_num = 2
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION2'',aei_Information2_Meaning,''Y'',aei_Information2_Meaning_P,Status_Color)

       loc_num = 3
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION3'',aei_Information3_Meaning,''Y'',aei_Information3_Meaning_P,Status_Color)

       loc_num = 4
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION4'',aei_Information4_Meaning,''Y'',aei_Information4_Meaning_P,Status_Color)

       loc_num = 5
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION5'',aei_Information5_Meaning,''Y'',aei_Information5_Meaning_P,Status_Color)

       loc_num = 6
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION6'',aei_Information6_Meaning,''Y'',aei_Information6_Meaning_P,Status_Color)

       loc_num = 7
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION7'',aei_Information7_Meaning,''Y'',aei_Information7_Meaning_P,Status_Color)

       loc_num = 8
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION8'',aei_Information8_Meaning,''Y'',aei_Information8_Meaning_P,Status_Color)

       loc_num = 9
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION9'',aei_Information9_Meaning,''Y'',aei_Information9_Meaning_P,Status_Color)

/*****************************************************************************/
/*  Extend this as required 10 to 30                                         */
/*****************************************************************************/

       loc_num = 30
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION30'',aei_Information30_Meaning,''Y'',aei_Information30_Meaning_P,Status_Color)
  )
  Else
    (
       loc_num = 1
  loc_char = ''Y''
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION1'',aei_Information1_Meaning,''Y'',aei_Information1_Meaning)

       loc_num = 2
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION2'',aei_Information2_Meaning,''Y'',aei_Information2_Meaning)

       loc_num = 3
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION3'',aei_Information3_Meaning,''Y'',aei_Information3_Meaning)

       loc_num = 4
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION4'',aei_Information4_Meaning,''Y'',aei_Information4_Meaning)

       loc_num = 5
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION5'',aei_Information5_Meaning,''Y'',aei_Information5_Meaning)

       loc_num = 6
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION6'',aei_Information6_Meaning,''Y'',aei_Information6_Meaning)

       loc_num = 7
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION7'',aei_Information7_Meaning,''Y'',aei_Information7_Meaning)

       loc_num = 8
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION8'',aei_Information8_Meaning,''Y'',aei_Information8_Meaning)

       loc_num = 9
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION9'',aei_Information9_Meaning,''Y'',aei_Information9_Meaning)

/*****************************************************************************/
/*  Extend this as required 10 to 30                                         */
/*****************************************************************************/

       loc_num = 30
  loc_char = XXAS_EMP_SET_ASG_EIT_FIELD(loc_num,Info_Type,
''AEI_INFORMATION30'',aei_Information30_Meaning,''Y'',aei_Information30_Meaning)
    )

  /*************************************************************************/
  /*  Modify the field as required.                                        */
  /*************************************************************************/
   IF aei_Information1_Meaning was not defaulted Then
   (
   Summary_Text = ''Field: '' + aei_Information1_Meaning
   )
   ELSE 
   (
   Summary_Text = ''Field: '' + aei_Information1_Meaning_p
   )
   IF aei_Information2_Meaning was not defaulted Then
   (
   Summary_Message =''Field: '' + aei_Information2_Meaning
   )
   ELSE 
   (
   Summary_Message =''Field: '' + aei_Information2_Meaning_p
   )

  /*************************************************************************/
  /*  End of BLOCK #3                                                      */
  /*************************************************************************/

  /*************************************************************************/
  /*  BLOCK #4 - No need to change if you want the Summary info repeated   */
  /*             on the header                                             */
  /*************************************************************************/
  /* Set the detail header to the summary header */

  Detail_Header_Context = Summary_Context
  Detail_Header_Text    = Summary_Text
  Detail_Header_Message = Summary_Message 

/*************************************************************************/
  /*  BLOCK #5 - Change to display Detail fields                           */
  /*************************************************************************/

  /*************************************************************************/
  /*  End of BLOCK #5                                                      */
  /*************************************************************************/

  /* Set the update/delete permissions */
  Update_Allowed = ''Y''
  Delete_Allowed = ''Y''
  
  /*************************************************************************/
  /*  RETURN BLOCK - Remove ItemX_Prompt/HTML attributes that aren''t used  */
  /*************************************************************************/

  Return Update_Allowed, Delete_Allowed,
  Status_Text, Status_Color,
  Detail_Header_Message,Summary_Context,
  Summary_Text, Summary_Message,
  Detail_Header_Context, Detail_Header_Text
';


  BEGIN

    IF l_ff_id IS NULL THEN
      --
      -- Create the Fast Formula
      --
      INSERT INTO ff_formulas_f
        (formula_id
        ,effective_start_date
        ,effective_end_date
        ,business_group_id
        ,formula_type_id
        ,formula_name
        ,description
        ,formula_text)
      VALUES
        (ff_formulas_s.nextval
        ,l_START
        ,l_END
        ,l_BG_ID
        ,l_formula_type_id
        ,l_FF_NAME
        ,l_FF_DESC
        ,l_formula_text);

    ELSE
      --
      -- Update the existing Fast Formula text
      -- (if it has multiple date-track versions the text of
      -- all versions is updated).
      --
      UPDATE ff_formulas_f
      SET    formula_text = l_formula_text
            ,description  = l_FF_DESC
      WHERE  formula_id = l_ff_id;

    END IF;

    COMMIT;

    EXCEPTION
      WHEN others THEN
        ROLLBACK;
        RAISE;
    END;

    --
    -- Compile the Fast Formula
    --
    xxas_util_pkg.compile_ff
      (p_user_id => l_USER_ID
      ,p_ff_type => l_FF_TYPE
      ,p_ff_name => l_FF_NAME);

EXCEPTION

  WHEN e_no_bg_id THEN
    RAISE no_data_found;

  WHEN e_bg_not_exists THEN
    RAISE no_data_found;

  WHEN e_ff_type_not_found THEN
    RAISE no_data_found;

END;
/
COMMIT;
EXIT;
