src-db/database/model/triggers/AD_PROCESS_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_PROCESS_TRG">
adrian@94
     3
    <trigger name="AD_PROCESS_TRG" table="AD_PROCESS" 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
* $Id: AD_Process_Trg.sql,v 1.3 2002/09/16 04:14:40 jjanke Exp $
adrian@94
    26
***
adrian@94
    27
* Title: Process Trigger
adrian@94
    28
* Description:
adrian@94
    29
*   Synchronize Names and Translation
adrian@94
    30
*   Sync IsActive with Menu / Field
adrian@94
    31
************************************************************************/
adrian@94
    32
BEGIN
adrian@94
    33
  -- Insert AD_Process Trigger
adrian@94
    34
  --  for Translation
adrian@94
    35
  --  add Access
adrian@94
    36
  IF INSERTING
adrian@94
    37
  THEN
adrian@94
    38
    --  Create Translation Row
adrian@94
    39
    INSERT INTO AD_Process_Trl
juanpablo@1605
    40
                (AD_Process_Trl_ID, AD_Process_ID, AD_Language, AD_Client_ID, AD_Org_ID,
adrian@94
    41
                 IsActive, Created, CreatedBy, Updated, UpdatedBy, NAME,
adrian@94
    42
                 Description, HELP, IsTranslated)
juanpablo@1605
    43
      SELECT get_uuid(), :NEW.AD_Process_ID, AD_Language, :NEW.AD_Client_ID,
adrian@94
    44
             :NEW.AD_Org_ID, :NEW.IsActive, :NEW.Created, :NEW.CreatedBy,
adrian@94
    45
             :NEW.Updated, :NEW.UpdatedBy, :NEW.NAME, :NEW.Description,
adrian@94
    46
             :NEW.HELP, 'N'
adrian@94
    47
        FROM AD_Language
adrian@94
    48
       WHERE IsActive = 'Y' AND IsSystemLanguage = 'Y';
adrian@94
    49
adrian@94
    50
    -- Add Access for all Roles
adrian@94
    51
    INSERT INTO AD_Process_Access
juanpablo@1605
    52
                (AD_Process_Access_ID, AD_Process_ID, AD_Role_ID, AD_Client_ID, AD_Org_ID,
adrian@94
    53
                 IsActive, Created, CreatedBy, Updated, UpdatedBy,
adrian@94
    54
                 IsReadWrite)
juanpablo@1605
    55
      SELECT get_uuid(), :NEW.AD_Process_ID, r.AD_Role_ID, r.AD_CLIENT_ID, r.AD_ORG_ID,
juanpablo@1605
    56
             'Y', now(), '0', now(), '0', 'Y'
adrian@94
    57
        FROM AD_Role r
adrian@94
    58
       where isManual='N';
adrian@94
    59
  END IF;
adrian@94
    60
adrian@94
    61
-- Inserting
adrian@94
    62
-- AD_Process update trigger
adrian@94
    63
--  synchronize name,...
adrian@94
    64
--      update AD_Column/AD_Field Name
adrian@94
    65
  IF UPDATING
adrian@94
    66
  THEN
antonio@737
    67
gorka@367
    68
    IF(    COALESCE (:OLD.NAME, '.') <> COALESCE (:NEW.NAME, '.')
gorka@367
    69
        OR COALESCE (:OLD.Description, '.') <> COALESCE (:NEW.Description, '.')
gorka@367
    70
        OR COALESCE (:OLD.HELP, '.') <> COALESCE (:NEW.HELP, '.') )
adrian@94
    71
    THEN
gorka@367
    72
        UPDATE AD_Process_Trl
gorka@367
    73
             SET IsTranslated = 'N',
antonio@735
    74
            Updated = now()
gorka@367
    75
         WHERE AD_Process_ID = :NEW.AD_Process_ID;
adrian@94
    76
adrian@94
    77
      UPDATE AD_Column
adrian@94
    78
         SET NAME = :NEW.NAME,
adrian@94
    79
             Description = :NEW.Description,
adrian@94
    80
             HELP = :NEW.HELP,
antonio@735
    81
             Updated = now()
adrian@94
    82
       WHERE AD_Process_ID = :NEW.AD_Process_ID;
adrian@94
    83
adrian@94
    84
      UPDATE AD_Field
adrian@94
    85
         SET NAME = :NEW.NAME,
adrian@94
    86
             Description = :NEW.Description,
adrian@94
    87
             HELP = :NEW.HELP,
antonio@735
    88
             Updated = now()
adrian@94
    89
       WHERE EXISTS (
adrian@94
    90
               SELECT *
adrian@94
    91
                 FROM AD_Column c
adrian@94
    92
                WHERE AD_Field.AD_Column_ID = c.AD_Column_ID
adrian@94
    93
                  AND c.AD_Process_ID = :NEW.AD_Process_ID
adrian@94
    94
                  AND AD_Field.IsCentrallyMaintained = 'Y');
adrian@94
    95
    END IF;
adrian@94
    96
  END IF;
adrian@94
    97
adrian@94
    98
-- Updating
adrian@94
    99
-- Changed  IsActive
adrian@94
   100
  IF UPDATING
adrian@94
   101
  THEN
gorkaion@239
   102
    IF (   COALESCE (:OLD.NAME, '.') <> COALESCE (:NEW.NAME, '.')
gorkaion@239
   103
        OR COALESCE (:OLD.Description, '.') <>
adrian@94
   104
                                              COALESCE (:NEW.Description, '.')
gorkaion@239
   105
        OR COALESCE (:OLD.HELP, '.') <> COALESCE (:NEW.HELP, '.')
gorkaion@239
   106
        OR COALESCE (:OLD.IsActive, '.') <> COALESCE (:NEW.IsActive, '.')
adrian@94
   107
       )
adrian@94
   108
    THEN
gorkaion@239
   109
      IF :NEW.IsActive <> :OLD.IsActive
adrian@94
   110
      THEN
adrian@94
   111
        -- Menu
adrian@94
   112
        UPDATE AD_Menu
adrian@94
   113
           SET IsActive = :NEW.IsActive
adrian@94
   114
         WHERE AD_Process_ID = :NEW.AD_Process_ID;
adrian@94
   115
gorkaion@239
   116
        -- AD_Column -> Field
adrian@94
   117
        UPDATE AD_Field
adrian@94
   118
           SET IsActive = :NEW.IsActive
adrian@94
   119
         WHERE AD_Column_ID = (SELECT AD_Column_ID
adrian@94
   120
                                 FROM AD_Column
adrian@94
   121
                                WHERE AD_Process_ID = :NEW.AD_Process_ID);
adrian@94
   122
      -- AD_WF_Node
adrian@94
   123
      END IF;
adrian@94
   124
    END IF;
adrian@94
   125
  END IF;
antonio@735
   126
END AD_PROCESS_TRG
gorkaion@239
   127
]]></body>
adrian@94
   128
    </trigger>
adrian@94
   129
  </database>