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