src-db/database/model/triggers/AD_MENU_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 799 fef2c5e2feb7
child 1616 000fac210549
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER AD_MENU_TRG">
adrian@94
     3
    <trigger name="AD_MENU_TRG" table="AD_MENU" fires="after" insert="true" update="true" delete="true" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
asier@799
     5
/*************************************************************************
asier@799
     6
  * The contents of this file are subject to the Compiere Public
asier@799
     7
  * License 1.1 ("License"); You may not use this file except in
asier@799
     8
  * compliance with the License. You may obtain a copy of the License in
asier@799
     9
  * the legal folder of your Openbravo installation.
asier@799
    10
  * Software distributed under the License is distributed on an
asier@799
    11
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
asier@799
    12
  * implied. See the License for the specific language governing rights
asier@799
    13
  * and limitations under the License.
asier@799
    14
  * The Original Code is  Compiere  ERP &  Business Solution
asier@799
    15
  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
asier@799
    16
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
asier@799
    17
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
asier@799
    18
  * All Rights Reserved.
asier@799
    19
  * Contributor(s): Openbravo SL
asier@799
    20
  * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
asier@799
    21
  *
asier@799
    22
  * Specifically, this derivative work is based upon the following Compiere
asier@799
    23
  * file and version.
asier@799
    24
  *************************************************************************/
adrian@170
    25
adrian@94
    26
adrian@94
    27
juanpablo@1605
    28
  v_xTree_ID VARCHAR2(32);
juanpablo@1605
    29
  v_xParent_ID VARCHAR2(32);
juanpablo@1605
    30
  v_NextNo     VARCHAR2(32);
carlos@0
    31
BEGIN
carlos@0
    32
  -- Insert AD_Menu Trigger
carlos@0
    33
  --  for Translation
carlos@0
    34
  --  and TreeNode
carlos@0
    35
  IF INSERTING THEN
carlos@0
    36
    --  Create Translation Row
carlos@0
    37
    INSERT
carlos@0
    38
    INTO AD_Menu_Trl
carlos@0
    39
      (
juanpablo@1605
    40
        AD_Menu_Trl_ID, AD_Menu_ID, AD_Language, AD_Client_ID,
carlos@0
    41
        AD_Org_ID, IsActive, Created,
carlos@0
    42
        CreatedBy, Updated, UpdatedBy,
carlos@0
    43
        Name, Description, IsTranslated
carlos@0
    44
      )
juanpablo@1605
    45
    SELECT get_uuid(), :new.AD_Menu_ID,
carlos@0
    46
      AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
carlos@0
    47
      :new.IsActive, :new.Created, :new.CreatedBy,
carlos@0
    48
      :new.Updated, :new.UpdatedBy, :new.Name,
carlos@0
    49
      :new.Description,
carlos@0
    50
       'N'
carlos@0
    51
    FROM AD_Language
carlos@0
    52
    WHERE IsActive='Y'
carlos@0
    53
      AND IsSystemLanguage='Y';
carlos@0
    54
    --  Create TreeNode --
carlos@0
    55
    --  get AD_Tree_ID + ParentID
carlos@0
    56
    SELECT c.AD_Tree_Menu_ID,
carlos@0
    57
      n.Node_ID
carlos@0
    58
    INTO v_xTree_ID,
carlos@0
    59
      v_xParent_ID
carlos@0
    60
    FROM AD_ClientInfo c,
carlos@0
    61
      AD_TreeNode n
carlos@0
    62
      -- AD_TreeNodeMM n
carlos@0
    63
    WHERE c.AD_Tree_Menu_ID=n.AD_Tree_ID
carlos@0
    64
      AND n.Parent_ID IS NULL
carlos@0
    65
      AND c.AD_Client_ID=:new.AD_Client_ID;
carlos@0
    66
    --  DBMS_OUTPUT.PUT_LINE('Tree='||v_xTree_ID||'  Node='||:new.AD_Menu_ID||'  Parent='||v_xParent_ID);
carlos@0
    67
    --  Insert into TreeNode
carlos@0
    68
    INSERT
carlos@0
    69
    INTO AD_TreeNode
carlos@0
    70
      -- AD_TreeNodeMM
carlos@0
    71
      (
carlos@0
    72
        AD_Client_ID, AD_Org_ID, IsActive,
carlos@0
    73
        Created, CreatedBy, Updated,
carlos@0
    74
        UpdatedBy, AD_Tree_ID, Node_ID,
carlos@0
    75
        Parent_ID, SeqNo
carlos@0
    76
      )
carlos@0
    77
      VALUES
carlos@0
    78
      (
carlos@0
    79
        :new.AD_Client_ID, :new.AD_Org_ID, :new.IsActive,
carlos@0
    80
        :new.Created, :new.CreatedBy, :new.Updated,
carlos@0
    81
        :new.UpdatedBy, v_xTree_ID, :new.AD_Menu_ID,
carlos@0
    82
        v_xParent_ID,(
carlos@0
    83
        CASE :new.IsSummary
carlos@0
    84
          WHEN 'Y'
carlos@0
    85
          THEN 100
carlos@0
    86
          ELSE 999
carlos@0
    87
        END
carlos@0
    88
        )
carlos@0
    89
      )
carlos@0
    90
      ;
carlos@0
    91
    -- Summary Nodes first
carlos@0
    92
  END IF;
carlos@0
    93
  -- Inserting
carlos@0
    94
  -- AD_Ref_List update trigger
carlos@0
    95
  --  synchronize name,...
carlos@0
    96
  IF UPDATING THEN
gorkaion@239
    97
    IF(COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
gorkaion@239
    98
   OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
gorkaion@239
    99
   OR COALESCE(:old.IsActive, '.') <> COALESCE(:NEW.IsActive, '.'))
carlos@0
   100
  THEN
carlos@0
   101
      IF(:old.IsActive!=:new.IsActive) THEN
carlos@0
   102
        --  get AD_Tree_ID + ParentID
carlos@0
   103
        SELECT c.AD_Tree_Menu_ID,
carlos@0
   104
          n.Node_ID
carlos@0
   105
        INTO v_xTree_ID,
carlos@0
   106
          v_xParent_ID
carlos@0
   107
        FROM AD_ClientInfo c,
carlos@0
   108
          AD_TreeNode n
carlos@0
   109
          -- AD_TreeNodeMM n
carlos@0
   110
        WHERE c.AD_Tree_Menu_ID=n.AD_Tree_ID
carlos@0
   111
          AND n.Parent_ID IS NULL
carlos@0
   112
          AND c.AD_Client_ID=:new.AD_Client_ID;
carlos@0
   113
        -- Update
carlos@0
   114
        UPDATE AD_TreeNode
carlos@0
   115
          -- AD_TreeNodeMM
carlos@0
   116
          SET IsActive=:new.IsActive
carlos@0
   117
        WHERE AD_Tree_ID=v_xTree_ID
carlos@0
   118
          AND Node_ID=:new.AD_Menu_ID;
carlos@0
   119
      ELSE
carlos@0
   120
        UPDATE AD_Menu_Trl
carlos@0
   121
          SET IsTranslated='N',
antonio@735
   122
          Updated=now()
carlos@0
   123
        WHERE AD_Menu_ID=:new.AD_Menu_ID;
carlos@0
   124
      END IF;
carlos@0
   125
    END IF;
carlos@0
   126
  END IF;
antonio@737
   127
  -- Updating
carlos@0
   128
  IF DELETING THEN
carlos@0
   129
    --  Delete TreeNode
antonio@737
   130
    --  get AD_Tree_ID, AD_Menu_ID
carlos@0
   131
    SELECT c.AD_Tree_Menu_ID
carlos@0
   132
      INTO v_xTree_ID
carlos@0
   133
      FROM AD_ClientInfo c,
carlos@0
   134
        AD_TreeNode n
carlos@0
   135
      WHERE c.AD_Tree_Menu_ID=n.AD_Tree_ID
carlos@0
   136
        AND n.Parent_ID IS NULL
antonio@737
   137
        AND c.AD_Client_ID=:old.AD_Client_ID;
carlos@0
   138
    --Assign children to principal node
carlos@0
   139
    UPDATE AD_Treenode
juanpablo@1605
   140
      SET Parent_ID='0'
carlos@0
   141
    WHERE AD_Tree_ID=v_xTree_ID
carlos@0
   142
      AND Parent_ID=:old.AD_Menu_ID;
carlos@0
   143
    --Delete node
carlos@0
   144
    DELETE
carlos@0
   145
      FROM AD_Treenode
carlos@0
   146
      WHERE AD_Client_ID=:old.AD_Client_ID
carlos@0
   147
        AND AD_Tree_ID=v_xTree_ID
antonio@737
   148
        AND Node_ID=:old.AD_Menu_ID;
carlos@0
   149
  END IF;
carlos@0
   150
  -- Deleting
carlos@0
   151
EXCEPTION
carlos@0
   152
WHEN NO_DATA_FOUND THEN
carlos@0
   153
  RAISE_APPLICATION_ERROR(-20005, 'AD_Menu InsertTrigger Error: No ClientInfo or parent TreeNode') ;
antonio@735
   154
END AD_MENU_TRG
gorkaion@239
   155
]]></body>
adrian@94
   156
    </trigger>
adrian@94
   157
  </database>