src-db/database/model/triggers/AD_FORM_TRG2.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
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 AD_FORM_TRG2">
adrian@94
     3
    <trigger name="AD_FORM_TRG2" table="AD_FORM" fires="after" insert="true" update="true" delete="true" 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
************************************************************************/
juanpablo@1605
    25
  v_ID VARCHAR2(32) ;
juanpablo@1605
    26
  v_ID_MAP     VARCHAR2(32) ;
adrian@94
    27
  v_WindowName VARCHAR2(60):='ad_forms';
adrian@94
    28
  v_ClassName  VARCHAR2(60) ;
adrian@94
    29
BEGIN
adrian@94
    30
  IF(UPDATING) THEN
gorkaion@239
    31
    IF NOT(COALESCE(:old.NAME, '.') <> COALESCE(:NEW.NAME, '.')
gorkaion@239
    32
   OR COALESCE(:old.IsActive, '.') <> COALESCE(:NEW.IsActive, '.')
gorkaion@239
    33
   OR COALESCE(:old.CLASSNAME, '.') <> COALESCE(:NEW.CLASSNAME, '.'))
adrian@94
    34
  THEN
adrian@94
    35
      RETURN;
adrian@94
    36
    END IF;
adrian@94
    37
  END IF;
adrian@94
    38
  IF (UPDATING) THEN
adrian@94
    39
    UPDATE AD_MODEL_OBJECT_MAPPING
adrian@94
    40
    SET ISACTIVE = :new.isactive
adrian@94
    41
    WHERE AD_MODEL_OBJECT_ID IN
adrian@94
    42
      (
adrian@94
    43
      SELECT AD_MODEL_OBJECT_ID
adrian@94
    44
      FROM AD_MODEL_OBJECT
adrian@94
    45
      WHERE AD_MODEL_OBJECT.AD_FORM_ID=:old.AD_FORM_ID
adrian@94
    46
        AND ACTION='X'
adrian@94
    47
      );
adrian@94
    48
    UPDATE AD_MODEL_OBJECT
adrian@94
    49
    SET ISACTIVE = :new.isactive
adrian@94
    50
    WHERE ACTION='X'
adrian@94
    51
      AND AD_MODEL_OBJECT.AD_FORM_ID=:OLD.AD_FORM_ID;
adrian@94
    52
  END IF;
adrian@94
    53
  IF(DELETING) THEN
adrian@94
    54
    DELETE
adrian@94
    55
    FROM AD_MODEL_OBJECT_MAPPING
adrian@94
    56
    WHERE AD_MODEL_OBJECT_ID IN
adrian@94
    57
      (
adrian@94
    58
      SELECT AD_MODEL_OBJECT_ID
adrian@94
    59
      FROM AD_MODEL_OBJECT
adrian@94
    60
      WHERE AD_MODEL_OBJECT.AD_FORM_ID=:old.AD_FORM_ID
adrian@94
    61
        AND ACTION='X'
adrian@94
    62
      )
adrian@94
    63
      ;
adrian@94
    64
    DELETE
adrian@94
    65
    FROM AD_MODEL_OBJECT
adrian@94
    66
    WHERE ACTION='X'
adrian@94
    67
      AND AD_MODEL_OBJECT.AD_FORM_ID=:OLD.AD_FORM_ID;
adrian@94
    68
  END IF;
adrian@94
    69
  IF(INSERTING) THEN
adrian@94
    70
    v_ClassName:=:new.CLASSNAME;
adrian@94
    71
    Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID) ;
adrian@94
    72
    INSERT
adrian@94
    73
    INTO AD_MODEL_OBJECT
adrian@94
    74
      (
adrian@94
    75
        AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    76
        ISACTIVE, CREATED, CREATEDBY,
adrian@94
    77
        UPDATED, UPDATEDBY, ACTION,
adrian@94
    78
        AD_FORM_ID, CLASSNAME, ISDEFAULT
adrian@94
    79
      )
adrian@94
    80
      VALUES
adrian@94
    81
      (
adrian@94
    82
        v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
antonio@735
    83
        :new.ISACTIVE, now(), :new.CREATEDBY,
antonio@735
    84
        now(), :new.UPDATEDBY, 'X',
adrian@94
    85
        :new.AD_FORM_ID, v_ClassName, 'Y'
adrian@94
    86
      )
adrian@94
    87
      ;
adrian@94
    88
    Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP) ;
adrian@94
    89
    INSERT
adrian@94
    90
    INTO AD_MODEL_OBJECT_MAPPING
adrian@94
    91
      (
adrian@94
    92
        AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    93
        ISACTIVE, CREATED, CREATEDBY,
adrian@94
    94
        UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID,
adrian@94
    95
        MAPPINGNAME, ISDEFAULT
adrian@94
    96
      )
adrian@94
    97
      VALUES
adrian@94
    98
      (
adrian@94
    99
        v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
antonio@735
   100
        :new.ISACTIVE, now(), :new.CREATEDBY,
antonio@735
   101
        now(), :new.UPDATEDBY, v_ID,
adrian@94
   102
        ('/' || v_WindowName || '/' || AD_MAPPING_FORMAT(:NEW.NAME) || '.html'), 'Y'
adrian@94
   103
      )
adrian@94
   104
      ;
adrian@94
   105
  END IF;
antonio@735
   106
END AD_FORM_TRG2
gorkaion@239
   107
]]></body>
adrian@94
   108
    </trigger>
adrian@94
   109
  </database>