-----------------------------------------------------------------------------
--
--  Logical unit: ProjBudgetControlRules
--  Component:    PROJBF
--
--  IFS Developer Studio Template Version 3.0
--
--  Date    Sign    History
--  ------  ------  ---------------------------------------------------------
-----------------------------------------------------------------------------

layer Cust;

-------------------- PUBLIC DECLARATIONS ------------------------------------


-------------------- PRIVATE DECLARATIONS -----------------------------------


-------------------- LU SPECIFIC IMPLEMENTATION METHODS ---------------------


-------------------- LU SPECIFIC PRIVATE METHODS ----------------------------


-------------------- LU SPECIFIC PROTECTED METHODS --------------------------


-------------------- LU SPECIFIC PUBLIC METHODS -----------------------------


-------------------- LU CUST NEW METHODS -------------------------------------


PROCEDURE C_Update_Project_Rule_List (
   project_id_ IN VARCHAR2)   
IS
   
   combination_id_ NUMBER;

   CURSOR combination_id_cur IS
      SELECT proj_bud_conf_rule_comb_id.NEXTVAL
      FROM   DUAL;

   CURSOR get_budget_line IS
      SELECT a.project_id, a.sub_project_id, a.activity_seq, a.project_cost_element, a.proj_cost_struct_item_type, a.currency_code,
             a.account, a.code_b, a.code_c, a.code_d, a.code_e, a.code_f, a.code_g,
             a.code_h, a.code_i, a.code_j, a.codestring
      FROM   project_forecast_item_tab a, project_forecast_tab b
      WHERE  a.forecast_id         = b.forecast_id
      AND    a.created_by_snapshot = 'FALSE'
      AND    b.active_budget       = 'TRUE'
      AND    a.item_type           = 'COST'
      AND    a.project_id          = project_id_;
   
BEGIN
   
   DELETE FROM proj_budget_control_rules_tab
   WHERE project_id = project_id_;
   
   FOR newrec_ IN get_budget_line LOOP
      OPEN combination_id_cur;
      FETCH combination_id_cur INTO combination_id_;
      CLOSE combination_id_cur;
      
      
      INSERT
         INTO proj_budget_control_rules_tab (
            combination_id,
            project_id,
            sub_project_id,
            activity_seq,
            project_cost_element,
            proj_cost_struct_item_type,
            currency_code,           
            account,
            code_b,
            code_c,
            code_d,
            code_e,
            code_f,
            code_g,
            code_h,
            code_i,
            code_j,
            codestring,
            rowversion)
         VALUES (
            combination_id_,
            newrec_.project_id,
            newrec_.sub_project_id,
            newrec_.activity_seq,
            newrec_.project_cost_element,
            newrec_.proj_cost_struct_item_type,
            newrec_.currency_code,
            newrec_.account,
            newrec_.code_b,
            newrec_.code_c,
            newrec_.code_d,
            newrec_.code_e,
            newrec_.code_f,
            newrec_.code_g,
            newrec_.code_h,
            newrec_.code_i,
            newrec_.code_j,
            newrec_.codestring,
            SYSDATE);
   END LOOP;
END C_Update_Project_Rule_List;