database/model/triggers/AD_ACCOUNTINGRPT_ELEMENT_TRG.xml
author Adrián Romero <adrian.romero@openbravo.com>
Tue, 20 Nov 2007 16:27:14 +0000
changeset 94 4e7ba7b8a4ad
parent 59 85aab40b7d24
child 132 33c5ca45fcff
permissions -rw-r--r--
fix: Changed check constraint names and foreign key names to fit in to
30 characteres.
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER AD_ACCOUNTINGRPT_ELEMENT_TRG">
adrian@94
     3
    <trigger name="AD_ACCOUNTINGRPT_ELEMENT_TRG" table="AD_ACCOUNTINGRPT_ELEMENT" fires="after" insert="true" update="true" delete="false" foreach="row">
adrian@94
     4
      <body>
adrian@94
     5
adrian@94
     6
adrian@94
     7
/*************************************************************************
adrian@94
     8
* The contents of this file are subject to the Openbravo  Public  License
adrian@94
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    11
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    12
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    15
* License for the specific  language  governing  rights  and  limitations
adrian@94
    16
* under the License.
adrian@94
    17
* The Original Code is Openbravo ERP.
adrian@94
    18
* The Initial Developer of the Original Code is Openbravo SL
adrian@94
    19
* All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    20
* All Rights Reserved.
adrian@94
    21
* Contributor(s):  ______________________________________.
adrian@94
    22
************************************************************************/
adrian@94
    23
  v_xTree_ID NUMBER;
adrian@94
    24
  v_xParent_ID NUMBER;
adrian@94
    25
  v_NextNo     NUMBER;
adrian@94
    26
BEGIN
adrian@94
    27
  -- Insert AD_Menu Trigger
adrian@94
    28
  --  for Translation
adrian@94
    29
  --  and TreeNode
adrian@94
    30
  IF INSERTING THEN
adrian@94
    31
    --  Create TreeNode --
adrian@94
    32
    --  get AD_Tree_ID + ParentID
adrian@94
    33
    --SELECT  c.AD_Tree_Menu_ID, n.Node_ID
adrian@94
    34
    -- INTO  v_xTree_ID, v_xParent_ID
adrian@94
    35
    -- FROM    AD_CLIENTINFO c, AD_TREENODE n -- AD_TreeNodeMM n
adrian@94
    36
    --  WHERE   c.AD_Tree_Menu_ID=n.AD_Tree_ID
adrian@94
    37
    --    AND n.Parent_ID IS NULL
adrian@94
    38
    --AND c.AD_Client_ID=:NEW.AD_Client_ID;
adrian@94
    39
    SELECT AD_TREE_ID,
adrian@94
    40
      0
adrian@94
    41
    INTO v_xTree_ID,
adrian@94
    42
      v_xParent_ID
adrian@94
    43
    FROM AD_TREE
adrian@94
    44
    WHERE treetype='AR'
adrian@94
    45
      AND AD_Client_ID=:NEW.AD_Client_ID;
adrian@94
    46
    --  DBMS_OUTPUT.PUT_LINE('Tree='||v_xTree_ID||'  Node='||:new.AD_Menu_ID||'  Parent='||v_xParent_ID);
adrian@94
    47
    --  Insert into TreeNode
adrian@94
    48
    INSERT
adrian@94
    49
    INTO AD_TREENODE
adrian@94
    50
      -- AD_TreeNodeMM
adrian@94
    51
      (
adrian@94
    52
        AD_Client_ID, AD_Org_ID, IsActive,
adrian@94
    53
        Created, CreatedBy, Updated,
adrian@94
    54
        UpdatedBy, AD_Tree_ID, Node_ID,
adrian@94
    55
        Parent_ID, SeqNo
adrian@94
    56
      )
adrian@94
    57
      VALUES
adrian@94
    58
      (
adrian@94
    59
        :NEW.AD_Client_ID, :NEW.AD_Org_ID, :NEW.IsActive,
adrian@94
    60
        :NEW.Created, :NEW.CreatedBy, :NEW.Updated,
adrian@94
    61
        :NEW.UpdatedBy, v_xTree_ID, :NEW.AD_Accountingrpt_Element_ID,
adrian@94
    62
        v_xParent_ID,(
adrian@94
    63
        CASE :NEW.IsSummary
adrian@94
    64
          WHEN 'Y'
adrian@94
    65
          THEN 100
adrian@94
    66
          ELSE 999
adrian@94
    67
        END
adrian@94
    68
        )
adrian@94
    69
      )
adrian@94
    70
      ;
adrian@94
    71
    -- Summary Nodes first
adrian@94
    72
  END IF;
adrian@94
    73
  -- Inserting
adrian@94
    74
  -- AD_Ref_List update trigger
adrian@94
    75
  --  synchronize name,...
adrian@94
    76
  IF UPDATING THEN
adrian@94
    77
    IF((COALESCE(:old.Name, '.') &lt;&gt; COALESCE(:NEW.Name, '.')
adrian@94
    78
   OR COALESCE(:old.Description, '.') &lt;&gt; COALESCE(:NEW.Description, '.')
adrian@94
    79
   OR COALESCE(:old.IsActive, '.') &lt;&gt; COALESCE(:NEW.IsActive, '.')))
adrian@94
    80
  THEN
adrian@94
    81
      IF(:OLD.IsActive!=:NEW.IsActive) THEN
adrian@94
    82
        --  get AD_Tree_ID + ParentID
adrian@94
    83
        --SELECT  c.AD_Tree_Menu_ID, n.Node_ID
adrian@94
    84
        --INTO  v_xTree_ID, v_xParent_ID
adrian@94
    85
        --FROM    AD_CLIENTINFO c, AD_TREENODE n -- AD_TreeNodeMM n
adrian@94
    86
        --WHERE   c.AD_Tree_Menu_ID=n.AD_Tree_ID
adrian@94
    87
        --  AND n.Parent_ID IS NULL
adrian@94
    88
        --AND c.AD_Client_ID=:NEW.AD_Client_ID;
adrian@94
    89
        -- Update
adrian@94
    90
        UPDATE AD_TREENODE
adrian@94
    91
          -- AD_TreeNodeMM
adrian@94
    92
          SET IsActive=:NEW.IsActive
adrian@94
    93
        WHERE AD_Tree_ID=v_xTree_ID
adrian@94
    94
          AND Node_ID=:NEW.AD_Accountingrpt_Element_ID;
adrian@94
    95
      END IF;
adrian@94
    96
    END IF;
adrian@94
    97
  END IF;
adrian@94
    98
  -- Updating
adrian@94
    99
/*EXCEPTION
adrian@94
   100
WHEN NO_DATA_FOUND THEN
adrian@94
   101
  RAISE_APPLICATION_ERROR(-20002, 'AD_AccountingRpt_Element InsertTrigger Error: No ClientInfo or parent TreeNode') ;
adrian@94
   102
  */
adrian@94
   103
END AD_Accountingrpt_Element_Trg
adrian@94
   104
</body>
adrian@94
   105
    </trigger>
adrian@94
   106
  </database>