src-db/database/model/triggers/C_ELEMENTVALUE_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1414 1d5dbe3d9693
child 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_ELEMENTVALUE_TRG">
david@1414
     3
    <trigger name="C_ELEMENTVALUE_TRG" table="C_ELEMENTVALUE" 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 Openbravo  Public  License
asier@799
     7
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
asier@799
     8
* Version 1.1  with a permitted attribution clause; you may not  use this
asier@799
     9
* file except in compliance with the License. You  may  obtain  a copy of
asier@799
    10
* the License at http://www.openbravo.com/legal/license.html
asier@799
    11
* Software distributed under the License  is  distributed  on  an "AS IS"
asier@799
    12
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
asier@799
    13
* License for the specific  language  governing  rights  and  limitations
asier@799
    14
* under the License.
asier@799
    15
* The Original Code is Openbravo ERP.
asier@799
    16
* The Initial Developer of the Original Code is Openbravo SL
asier@799
    17
* All portions are Copyright (C) 2001-2008 Openbravo SL
asier@799
    18
* All Rights Reserved.
asier@799
    19
* Contributor(s):  ______________________________________.
asier@799
    20
************************************************************************/
gorkaion@239
    21
adrian@170
    22
carlos@59
    23
adrian@94
    24
juanpablo@1605
    25
  v_xTree_ID VARCHAR2(32);
juanpablo@1605
    26
  v_xParent_ID VARCHAR2(32);
juanpablo@1605
    27
  v_NextNo     VARCHAR2(32);
adrian@94
    28
BEGIN
adrian@94
    29
  -- Insert C_ElementValue Trigger
adrian@94
    30
  --  for Translation
adrian@94
    31
  --  and TreeNode
adrian@94
    32
  IF INSERTING THEN
adrian@94
    33
    --  Create Translation Row
adrian@94
    34
    INSERT
adrian@94
    35
    INTO C_ElementValue_Trl
adrian@94
    36
      (
juanpablo@1605
    37
        C_ElementValue_Trl_ID, C_ElementValue_ID, AD_Language, AD_Client_ID,
adrian@94
    38
        AD_Org_ID, IsActive, Created,
adrian@94
    39
        CreatedBy, Updated, UpdatedBy,
adrian@94
    40
        Name, IsTranslated
adrian@94
    41
      )
juanpablo@1605
    42
    SELECT get_uuid(), :new.C_ElementValue_ID,
adrian@94
    43
      AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
adrian@94
    44
      :new.IsActive, :new.Created, :new.CreatedBy,
adrian@94
    45
      :new.Updated, :new.UpdatedBy, :new.Name,
adrian@94
    46
       'N'
adrian@94
    47
    FROM AD_Language
adrian@94
    48
    WHERE IsActive='Y'
adrian@94
    49
      AND IsSystemLanguage='Y';
adrian@94
    50
    --  Create TreeNode --
adrian@94
    51
    --  get AD_Tree_ID + ParentID
adrian@94
    52
    SELECT e.AD_Tree_ID,
adrian@94
    53
      n.Node_ID
adrian@94
    54
    INTO v_xTree_ID,
adrian@94
    55
      v_xParent_ID
adrian@94
    56
    FROM C_Element e,
adrian@94
    57
      AD_TreeNode n
adrian@94
    58
    WHERE e.AD_Tree_ID=n.AD_Tree_ID
adrian@94
    59
      AND n.Parent_ID IS NULL
adrian@94
    60
      AND e.C_Element_ID=:new.C_Element_ID;
adrian@94
    61
    --  DBMS_OUTPUT.PUT_LINE('Tree='||v_xTree_ID||'  Node='||:new.C_ElementValue_ID||'  Parent='||v_xParent_ID);
adrian@94
    62
    --  Insert into TreeNode
adrian@94
    63
    INSERT
adrian@94
    64
    INTO AD_TreeNode
adrian@94
    65
      (
juanpablo@1605
    66
        AD_TreeNode_ID, AD_Client_ID, AD_Org_ID, IsActive,
adrian@94
    67
        Created, CreatedBy, Updated,
adrian@94
    68
        UpdatedBy, AD_Tree_ID, Node_ID,
adrian@94
    69
        Parent_ID, SeqNo
adrian@94
    70
      )
adrian@94
    71
      VALUES
adrian@94
    72
      (
juanpablo@1605
    73
        get_uuid(), :new.AD_Client_ID, :new.AD_Org_ID, :new.IsActive,
adrian@94
    74
        :new.Created, :new.CreatedBy, :new.Updated,
adrian@94
    75
        :new.UpdatedBy, v_xTree_ID, :new.C_ElementValue_ID,
adrian@94
    76
        v_xParent_ID,(
adrian@94
    77
        CASE :new.IsSummary
adrian@94
    78
          WHEN 'Y'
adrian@94
    79
          THEN 100
adrian@94
    80
          ELSE 999
adrian@94
    81
        END
adrian@94
    82
        )
adrian@94
    83
      )
adrian@94
    84
      ;
adrian@94
    85
    -- Summary Nodes first
adrian@94
    86
  END IF;
adrian@94
    87
  -- Inserting
adrian@94
    88
  -- C_ElementValue update trigger
adrian@94
    89
  --  synchronize name,...
adrian@94
    90
  IF UPDATING THEN
gorkaion@239
    91
    IF COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.') THEN
adrian@94
    92
      UPDATE C_ElementValue_Trl
adrian@94
    93
        SET IsTranslated='N',
antonio@735
    94
        Updated=now()
adrian@94
    95
      WHERE C_ElementValue_ID=:new.C_ElementValue_ID;
adrian@94
    96
      /** Mutating Trigger
adrian@94
    97
      --   Update Valid Combination Description
adrian@94
    98
      UPDATE    C_ValidCombination
antonio@735
    99
      SET    Updated=now()
adrian@94
   100
      WHERE    Account_ID=:new.C_ElementValue_ID
adrian@94
   101
      OR    User1_ID=:new.C_ElementValue_ID OR User2_ID=:new.C_ElementValue_ID;
adrian@94
   102
      **/
adrian@94
   103
    END IF;
adrian@94
   104
  END IF;
adrian@94
   105
  -- Updating
adrian@94
   106
  IF DELETING THEN
adrian@94
   107
    --  Delete TreeNode --
adrian@94
   108
    --  get AD_Tree_ID
adrian@94
   109
    SELECT e.AD_Tree_ID
adrian@94
   110
    INTO v_xTree_ID
adrian@94
   111
    FROM C_Element e
adrian@94
   112
    WHERE e.C_Element_ID=:old.C_Element_ID;
adrian@94
   113
    DELETE
adrian@94
   114
    FROM AD_TREENODE
adrian@94
   115
    WHERE AD_CLIENT_ID=:old.AD_Client_ID
adrian@94
   116
      AND AD_Tree_ID=v_xTree_ID
adrian@94
   117
      AND Node_ID=:old.C_ElementValue_ID;
adrian@94
   118
  END IF;
adrian@94
   119
  -- Deleting
adrian@94
   120
EXCEPTION
adrian@94
   121
WHEN NO_DATA_FOUND THEN
adrian@94
   122
  RAISE_APPLICATION_ERROR(-20013, 'C_ElementValue InsertTrigger Error: No ClientInfo or parent TreeNode') ;
antonio@735
   123
END C_ELEMENTVALUE_TRG
gorkaion@239
   124
]]></body>
adrian@94
   125
    </trigger>
adrian@94
   126
  </database>