src-db/database/model/triggers/AD_ELEMENT_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 1929 ad0353d93b0f
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER AD_ELEMENT_TRG">
adrian@94
     3
    <trigger name="AD_ELEMENT_TRG" table="AD_ELEMENT" fires="after" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
    /*************************************************************************
juanpablo@771
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@771
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
    * the legal folder of your Openbravo installation.
adrian@94
    10
    * Software distributed under the License is distributed on an
adrian@94
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    12
    * implied. See the License for the specific language governing rights
adrian@94
    13
    * and limitations under the License.
juanpablo@778
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
adrian@94
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    18
    * All Rights Reserved.
adrian@94
    19
    * Contributor(s): Openbravo SL
juanpablo@785
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    21
    *
juanpablo@771
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
    * file and version.
adrian@94
    24
    *************************************************************************
adrian@94
    25
    * Insert AD_Element Trigger
adrian@94
    26
    *  for Translation
adrian@94
    27
    * Update AD_Element Trigger
adrian@94
    28
    *  synchronize Column
adrian@94
    29
    *  synchronize PrintInfo
adrian@94
    30
    *  reset Translation flag
adrian@94
    31
    ************************************************************************/
adrian@94
    32
    BEGIN
adrian@94
    33
    -- Insert AD_Element Trigger
adrian@94
    34
    IF INSERTING
adrian@94
    35
    THEN
adrian@94
    36
  INSERT
adrian@94
    37
  INTO AD_Element_Trl
adrian@94
    38
    (
juanpablo@1605
    39
      AD_Element_Trl_ID, AD_Element_ID, AD_Language, AD_Client_ID,
adrian@94
    40
      AD_Org_ID, IsActive, Created,
adrian@94
    41
      CreatedBy, Updated, UpdatedBy,
adrian@94
    42
      Name, PrintName, Description,
adrian@94
    43
      Help, PO_Name, PO_PrintName,
adrian@94
    44
      PO_Description, PO_Help, IsTranslated
adrian@94
    45
    )
juanpablo@1605
    46
  SELECT get_uuid(), :new.AD_Element_ID,
adrian@94
    47
    AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
adrian@94
    48
    :new.IsActive, :new.Created, :new.CreatedBy,
adrian@94
    49
    :new.Updated, :new.UpdatedBy, :new.Name,
adrian@94
    50
    :new.PrintName, :new.Description, :new.Help,
adrian@94
    51
    :new.PO_Name, :new.PO_PrintName, :new.PO_Description,
adrian@94
    52
    :new.PO_Help,  'N'
adrian@94
    53
  FROM AD_Language
adrian@94
    54
  WHERE IsActive='Y'
adrian@94
    55
    AND IsSystemLanguage='Y';
adrian@94
    56
 END IF;
adrian@94
    57
 -- INSERTING
adrian@94
    58
 -- Update AD_Element Trigger
adrian@94
    59
 IF UPDATING THEN
adrian@94
    60
  --  synchronize Column
adrian@94
    61
  UPDATE AD_Column
adrian@94
    62
    SET Name=:new.Name,
adrian@94
    63
    ColumnName=:new.ColumnName,
adrian@94
    64
    Description=:new.Description,
adrian@94
    65
    Help=:new.Help
adrian@94
    66
    --  Updated=:new.Updated
adrian@94
    67
  WHERE AD_Element_ID=:new.AD_Element_ID;
adrian@94
    68
  /**
adrian@94
    69
  --  synchronize System PrintInfo or unchanged elements
gorkaion@239
    70
  IF (:old.PrintName <> :new.PrintName) THEN
adrian@94
    71
  UPDATE AD_PrintInfo pi
adrian@94
    72
  SET  PrintName=:new.PrintName
adrian@94
    73
  WHERE EXISTS (SELECT * FROM AD_Column c
adrian@94
    74
  WHERE c.AD_Column_ID=pi.AD_Column_ID
adrian@94
    75
  AND c.AD_Element_ID=:new.AD_Element_ID)
juanpablo@1605
    76
  AND (AD_Client_ID='0' OR PrintName=:old.PrintName);
adrian@94
    77
  END IF;
adrian@94
    78
  **/
adrian@94
    79
  --  reset Translation flag
gorka@367
    80
  IF(COALESCE(:old.Name,'.') <> COALESCE(:new.Name,'.') OR COALESCE(:old.PO_Name,'.') <> COALESCE(:new.PO_Name,'.')  OR COALESCE(:old.PrintName,'.') <> COALESCE(:new.PrintName,'.') OR COALESCE(:old.PO_PrintName,'.') <> COALESCE(:new.PO_PrintName,'.')  OR COALESCE(:old.Description,'.') <> COALESCE(:new.Description,'.') OR COALESCE(:old.PO_Description,'.') <> COALESCE(:new.PO_Description,'.')  OR COALESCE(:old.Help,'.') <> COALESCE(:new.Help,'.') OR COALESCE(:old.PO_Help,'.') <> COALESCE(:new.PO_Help,'.')) THEN
adrian@94
    81
    UPDATE AD_Element_Trl
adrian@94
    82
      SET IsTranslated='N'
adrian@94
    83
    WHERE AD_Element_ID=:new.AD_Element_ID;
adrian@94
    84
  END IF;
adrian@94
    85
  --  synchronize Process Fields
adrian@94
    86
  UPDATE AD_Process_Para
adrian@94
    87
    SET Name=:new.Name,
adrian@94
    88
    Description=:new.Description,
adrian@94
    89
    Help=:new.Help,
adrian@94
    90
    ColumnName=:new.ColumnName
adrian@94
    91
    --  Updated=:new.Updated
adrian@94
    92
  WHERE UPPER(ColumnName)=UPPER(:new.ColumnName)
adrian@94
    93
    AND IsCentrallyMaintained='Y';
adrian@94
    94
 END IF;
adrian@94
    95
-- UPDATING
antonio@735
    96
END AD_ELEMENT_TRG
gorkaion@239
    97
]]></body>
adrian@94
    98
    </trigger>
adrian@94
    99
  </database>