/* $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

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('0001-01-01','YYYY-MM-DD');
  l_END     CONSTANT  DATE          := xxas_util_pkg.eot;
  l_FF_NAME CONSTANT  VARCHAR2(80)  := 'XXAS_EMP_PERSONEIT_TEMPL_FF';
  l_FF_DESC CONSTANT  VARCHAR2(240) := 'Template Person EIT Fast Formula';
  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);

  --
  -- 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;

  --
  -- 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 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 := q'[
  
  Default for Transaction_Type            is 'NONE'
  Default for Workflow_Status_Code        is 'NONE'
  Default for Workflow_Status_Meaning     is 'NONE'
  Default for Information_Type            is 'Unknown'
  Default for Pei_Information1_Meaning    is 'Unknown'
  Default for Pei_Information1_Meaning_p  is 'Unknown'
  Default for Pei_Information2_Meaning    is 'Unknown'
  Default for Pei_Information2_Meaning_p  is 'Unknown'
  Default for Pei_Information3_Meaning    is 'Unknown'
  Default for Pei_Information3_Meaning_p  is 'Unknown'
  Default for Pei_Information4_Meaning    is 'Unknown'
  Default for Pei_Information4_Meaning_p  is 'Unknown'
  Default for Pei_Information5_Meaning    is 'Unknown'
  Default for Pei_Information5_Meaning_p  is 'Unknown'
  Default for Pei_Information6_Meaning    is 'Unknown'
  Default for Pei_Information6_Meaning_p  is 'Unknown'
  Default for Pei_Information7_Meaning    is 'Unknown'
  Default for Pei_Information7_Meaning_p  is 'Unknown'
  Default for Pei_Information8_Meaning    is 'Unknown'
  Default for Pei_Information8_Meaning_p  is 'Unknown'
  Default for Pei_Information9_Meaning    is 'Unknown'
  Default for Pei_Information9_Meaning_p  is 'Unknown'
  Default for Pei_Information10_Meaning   is 'Unknown'
  Default for Pei_Information10_Meaning_p is 'Unknown'
  Default for Pei_Information11_Meaning   is 'Unknown'
  Default for Pei_Information11_Meaning_p is 'Unknown'
  Default for Pei_Information12_Meaning   is 'Unknown'
  Default for Pei_Information12_Meaning_p is 'Unknown'
  Default for Pei_Information13_Meaning   is 'Unknown'
  Default for Pei_Information13_Meaning_p is 'Unknown'
  Default for Pei_Information14_Meaning   is 'Unknown'
  Default for Pei_Information14_Meaning_p is 'Unknown'
  Default for Pei_Information15_Meaning   is 'Unknown'
  Default for Pei_Information15_Meaning_p is 'Unknown'
  Default for Pei_Information16_Meaning   is 'Unknown'
  Default for Pei_Information16_Meaning_p is 'Unknown'
  Default for Pei_Information17_Meaning   is 'Unknown'
  Default for Pei_Information17_Meaning_p is 'Unknown'
  Default for Pei_Information18_Meaning   is 'Unknown'
  Default for Pei_Information18_Meaning_p is 'Unknown'
  Default for Pei_Information19_Meaning   is 'Unknown'
  Default for Pei_Information19_Meaning_p is 'Unknown'
  Default for Pei_Information20_Meaning   is 'Unknown'
  Default for Pei_Information20_Meaning_p is 'Unknown'
  Default for Pei_Information21_Meaning   is 'Unknown'
  Default for Pei_Information21_Meaning_p is 'Unknown'
  Default for Pei_Information22_Meaning   is 'Unknown'
  Default for Pei_Information22_Meaning_p is 'Unknown'
  Default for Pei_Information23_Meaning   is 'Unknown'
  Default for Pei_Information23_Meaning_p is 'Unknown'
  Default for Pei_Information24_Meaning   is 'Unknown'
  Default for Pei_Information24_Meaning_p is 'Unknown'
  Default for Pei_Information25_Meaning   is 'Unknown'
  Default for Pei_Information25_Meaning_p is 'Unknown'
  Default for Pei_Information26_Meaning   is 'Unknown'
  Default for Pei_Information26_Meaning_p is 'Unknown'
  Default for Pei_Information27_Meaning   is 'Unknown'
  Default for Pei_Information27_Meaning_p is 'Unknown'
  Default for Pei_Information28_Meaning   is 'Unknown'
  Default for Pei_Information28_Meaning_p is 'Unknown'
  Default for Pei_Information29_Meaning   is 'Unknown'
  Default for Pei_Information29_Meaning_p is 'Unknown'
  Default for Pei_Information30_Meaning   is 'Unknown'
  Default for Pei_Information30_Meaning_p is 'Unknown'

  Inputs are Transaction_Type, Workflow_Status_Code, Workflow_Status_Meaning,
             Information_Type,
             Pei_Information1_Meaning, Pei_Information1_Meaning_p,
             Pei_Information2_Meaning, Pei_Information2_Meaning_p,
             Pei_Information3_Meaning, Pei_Information3_Meaning_p,
             Pei_Information4_Meaning, Pei_Information4_Meaning_p,
             Pei_Information5_Meaning, Pei_Information5_Meaning_p,
             Pei_Information6_Meaning, Pei_Information6_Meaning_p,
             Pei_Information7_Meaning, Pei_Information7_Meaning_p,
             Pei_Information8_Meaning, Pei_Information8_Meaning_p,
             Pei_Information9_Meaning, Pei_Information9_Meaning_p,
             Pei_Information10_Meaning, Pei_Information10_Meaning_p,
             Pei_Information11_Meaning, Pei_Information11_Meaning_p,
             Pei_Information12_Meaning, Pei_Information12_Meaning_p,
             Pei_Information13_Meaning, Pei_Information13_Meaning_p,
             Pei_Information14_Meaning, Pei_Information14_Meaning_p,
             Pei_Information15_Meaning, Pei_Information15_Meaning_p,
             Pei_Information16_Meaning, Pei_Information16_Meaning_p,
             Pei_Information17_Meaning, Pei_Information17_Meaning_p,
             Pei_Information18_Meaning, Pei_Information18_Meaning_p,
             Pei_Information19_Meaning, Pei_Information19_Meaning_p,
             Pei_Information20_Meaning, Pei_Information20_Meaning_p,
             Pei_Information21_Meaning, Pei_Information21_Meaning_p,
             Pei_Information22_Meaning, Pei_Information22_Meaning_p,
             Pei_Information23_Meaning, Pei_Information23_Meaning_p,
             Pei_Information24_Meaning, Pei_Information24_Meaning_p,
             Pei_Information25_Meaning, Pei_Information25_Meaning_p,
             Pei_Information26_Meaning, Pei_Information26_Meaning_p,
             Pei_Information27_Meaning, Pei_Information27_Meaning_p,
             Pei_Information28_Meaning, Pei_Information28_Meaning_p,
             Pei_Information29_Meaning, Pei_Information29_Meaning_p,
             Pei_Information30_Meaning, Pei_Information30_Meaning_p

  COLOR_GREEN    = xxas_get_color_by_name('green')
  COLOR_AMBER    = xxas_get_color_by_name('amber')
  COLOR_RED      = xxas_get_color_by_name('red')
  COLOR_GREY     = xxas_get_color_by_name('grey')
  COLOR_BLUE     = xxas_get_color_by_name('blue')
  START_OF_TIME  = to_date('0001/01/01 00:00:00', 'YYYY/MM/DD HH24:MI:SS')
  END_OF_TIME    = to_date('4712/12/31 00:00:00', 'YYYY/MM/DD HH24:MI:SS')

  /* Set the status color and row header based on the transaction status */
  Current_Field_Num = 1
  Pending           = 'N'
  Status_Color      = COLOR_BLUE

  If Transaction_Type was not defaulted then
    (
     Pending = 'Y'
     If Transaction_Type = 'INSERT' then
       (Status_Text  = xxas_get_message('XXAS','XXAS_EMP_NEW'))
     Else If Transaction_Type = 'UPDATE' then
       (Status_Text  = xxas_get_message('XXAS','XXAS_EMP_UPDATED'))
     Else
       (Status_Text  = xxas_get_message('XXAS','XXAS_EMP_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_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 = '<font color="' + Status_Color + '">' + Status_Text + '</font>'
    )
  
  /* PEI_INFORMATION1 */
  If Pei_Information1_Meaning was not defaulted or
     Pei_Information1_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION1'
      ,Pei_Information1_Meaning, Pending, Pei_Information1_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION2 */
  If Pei_Information2_Meaning was not defaulted or
     Pei_Information2_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION2'
      ,Pei_Information2_Meaning, Pending, Pei_Information2_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION3 */
  If Pei_Information3_Meaning was not defaulted or
     Pei_Information3_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION3'
      ,Pei_Information3_Meaning, Pending, Pei_Information3_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION4 */
  If Pei_Information4_Meaning was not defaulted or
     Pei_Information4_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION4'
      ,Pei_Information4_Meaning, Pending, Pei_Information4_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION5 */
  If Pei_Information5_Meaning was not defaulted or
     Pei_Information5_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION5'
      ,Pei_Information5_Meaning, Pending, Pei_Information5_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION6 */
  If Pei_Information6_Meaning was not defaulted or
     Pei_Information6_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION6'
      ,Pei_Information6_Meaning, Pending, Pei_Information6_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION7 */
  If Pei_Information7_Meaning was not defaulted or
     Pei_Information7_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION7'
      ,Pei_Information7_Meaning, Pending, Pei_Information7_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION8 */
  If Pei_Information8_Meaning was not defaulted or
     Pei_Information8_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION8'
      ,Pei_Information8_Meaning, Pending, Pei_Information8_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION9 */
  If Pei_Information9_Meaning was not defaulted or
     Pei_Information9_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION9'
      ,Pei_Information9_Meaning, Pending, Pei_Information9_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION10 */
  If Pei_Information10_Meaning was not defaulted or
     Pei_Information10_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION10'
      ,Pei_Information10_Meaning, Pending, Pei_Information10_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION11 */
  If Pei_Information11_Meaning was not defaulted or
     Pei_Information11_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION11'
      ,Pei_Information11_Meaning, Pending, Pei_Information11_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION12 */
  If Pei_Information12_Meaning was not defaulted or
     Pei_Information12_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION12'
      ,Pei_Information12_Meaning, Pending, Pei_Information12_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION13 */
  If Pei_Information13_Meaning was not defaulted or
     Pei_Information13_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION13'
      ,Pei_Information13_Meaning, Pending, Pei_Information13_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION14 */
  If Pei_Information14_Meaning was not defaulted or
     Pei_Information14_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION14'
      ,Pei_Information14_Meaning, Pending, Pei_Information14_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION15 */
  If Pei_Information15_Meaning was not defaulted or
     Pei_Information15_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION15'
      ,Pei_Information15_Meaning, Pending, Pei_Information15_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION16 */
  If Pei_Information16_Meaning was not defaulted or
     Pei_Information16_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION16'
      ,Pei_Information16_Meaning, Pending, Pei_Information16_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION17 */
  If Pei_Information17_Meaning was not defaulted or
     Pei_Information17_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION17'
      ,Pei_Information17_Meaning, Pending, Pei_Information17_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION18 */
  If Pei_Information18_Meaning was not defaulted or
     Pei_Information18_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION18'
      ,Pei_Information18_Meaning, Pending, Pei_Information18_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION19 */
  If Pei_Information19_Meaning was not defaulted or
     Pei_Information19_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION19'
      ,Pei_Information19_Meaning, Pending, Pei_Information19_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION20 */
  If Pei_Information20_Meaning was not defaulted or
     Pei_Information20_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION20'
      ,Pei_Information20_Meaning, Pending, Pei_Information20_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION21 */
  If Pei_Information21_Meaning was not defaulted or
     Pei_Information21_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION21'
      ,Pei_Information21_Meaning, Pending, Pei_Information21_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION22 */
  If Pei_Information22_Meaning was not defaulted or
     Pei_Information22_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION22'
      ,Pei_Information22_Meaning, Pending, Pei_Information22_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION23 */
  If Pei_Information23_Meaning was not defaulted or
     Pei_Information23_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION23'
      ,Pei_Information23_Meaning, Pending, Pei_Information23_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION24 */
  If Pei_Information24_Meaning was not defaulted or
     Pei_Information24_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION24'
      ,Pei_Information24_Meaning, Pending, Pei_Information24_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION25 */
  If Pei_Information25_Meaning was not defaulted or
     Pei_Information25_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION25'
      ,Pei_Information25_Meaning, Pending, Pei_Information25_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION26 */
  If Pei_Information26_Meaning was not defaulted or
     Pei_Information26_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION26'
      ,Pei_Information26_Meaning, Pending, Pei_Information26_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION27 */
  If Pei_Information27_Meaning was not defaulted or
     Pei_Information27_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION27'
      ,Pei_Information27_Meaning, Pending, Pei_Information27_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION28 */
  If Pei_Information28_Meaning was not defaulted or
     Pei_Information28_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION28'
      ,Pei_Information28_Meaning, Pending, Pei_Information28_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION29 */
  If Pei_Information29_Meaning was not defaulted or
     Pei_Information29_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION29'
      ,Pei_Information29_Meaning, Pending, Pei_Information29_Meaning_p
      ,Status_Color, 'Unknown')
      
  /* PEI_INFORMATION30 */
  If Pei_Information30_Meaning was not defaulted or
     Pei_Information30_Meaning_p was not defaulted then
    Func_Result = xxas_emp_set_person_eit_field
      (Current_Field_Num
      ,Information_Type, 'PEI_INFORMATION30'
      ,Pei_Information30_Meaning, Pending, Pei_Information30_Meaning_p
      ,Status_Color, 'Unknown')
  
  /* Set the summary text. This defaults to the first item''s value */
  Summary_Text = xxas_emp_get_long_output('ITEM1_HTML')
  
  /* Default permissions */
  ESS_Update_Allowed = 'N'
  ESS_Delete_Allowed = 'N'
  MSS_Update_Allowed = 'N'
  MSS_Delete_Allowed = 'N'
  
  /* Autoconfig permissions: start */
  
  /* Autoconfig permissions: end */
  
  /* If you wish to override the auto-config permissions, set them
     underneath the autoconfig permissions */
  /* ESS_Update_Allowed = 'N'
     ESS_Delete_Allowed = 'N'
     MSS_Update_Allowed = 'N'
     MSS_Delete_Allowed = 'N' */

  Update_Allowed = xxas_ess_mss_policy(ESS_Update_Allowed, MSS_Update_Allowed)
  Delete_Allowed = xxas_ess_mss_policy(ESS_Delete_Allowed, MSS_Delete_Allowed)

  Return Update_Allowed, Delete_Allowed,
         Status_Text, Status_Color,
         Summary_Context, Summary_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;
