src-db/database/model/triggers/C_ACCTSCHEMA_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 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_ACCTSCHEMA_ELEMENT_TRG">
adrian@94
     3
    <trigger name="C_ACCTSCHEMA_ELEMENT_TRG" table="C_ACCTSCHEMA_ELEMENT" fires="after" insert="true" update="true" delete="true" 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
    * Update Valid Combination
adrian@94
    26
    * when element becomes mandatory
adrian@94
    27
    **/
adrian@94
    28
    v_UpdateIt BOOLEAN:=FALSE;
adrian@94
    29
BEGIN
adrian@95
    30
  -- Do we have to update
adrian@94
    31
  IF(INSERTING OR UPDATING) THEN
adrian@94
    32
    IF(:new.IsMandatory='Y') THEN
adrian@94
    33
      v_UpdateIt:=TRUE;
adrian@94
    34
    END IF;
adrian@94
    35
  END IF;
adrian@94
    36
  --
adrian@94
    37
  IF(v_UpdateIt) THEN
adrian@94
    38
    IF(:new.ElementType IN('OO', 'AC')) THEN
adrian@94
    39
      NULL;
adrian@94
    40
      -- Mandatory - no need
adrian@94
    41
    ELSIF(:new.ElementType='PR' AND :new.M_Product_ID IS NOT NULL) THEN
adrian@94
    42
      UPDATE C_ValidCombination
adrian@94
    43
        SET M_Product_ID=:new.M_Product_ID
adrian@94
    44
      WHERE M_Product_ID IS NULL;
adrian@94
    45
    ELSIF(:new.ElementType='BP' AND :new.C_BPartner_ID IS NOT NULL) THEN
adrian@94
    46
      UPDATE C_ValidCombination
adrian@94
    47
        SET C_BPartner_ID=:new.C_BPartner_ID
adrian@94
    48
      WHERE C_BPartner_ID IS NULL;
adrian@94
    49
    ELSIF(:new.ElementType='PJ' AND :new.C_Project_ID IS NOT NULL) THEN
adrian@94
    50
      UPDATE C_ValidCombination
adrian@94
    51
        SET C_Project_ID=:new.C_Project_ID
adrian@94
    52
      WHERE C_Project_ID IS NULL;
adrian@94
    53
    ELSIF(:new.ElementType='OT' AND :new.Org_ID IS NOT NULL) THEN
adrian@94
    54
      UPDATE C_ValidCombination
adrian@94
    55
        SET AD_OrgTrx_ID=:new.Org_ID
adrian@94
    56
      WHERE AD_OrgTrx_ID IS NULL;
adrian@94
    57
    ELSIF(:new.ElementType='LT' AND :new.C_Location_ID IS NOT NULL) THEN
adrian@94
    58
      UPDATE C_ValidCombination
adrian@94
    59
        SET C_LocTo_ID=:new.C_Location_ID
adrian@94
    60
      WHERE C_LocTo_ID IS NULL;
adrian@94
    61
    ELSIF(:new.ElementType='LF' AND :new.C_Location_ID IS NOT NULL) THEN
adrian@94
    62
      UPDATE C_ValidCombination
adrian@94
    63
        SET C_LocFrom_ID=:new.C_Location_ID
adrian@94
    64
      WHERE C_LocFrom_ID IS NULL;
adrian@94
    65
    ELSIF(:new.ElementType='SR' AND :new.C_SalesRegion_ID IS NOT NULL) THEN
adrian@94
    66
      UPDATE C_ValidCombination
adrian@94
    67
        SET C_SalesRegion_ID=:new.C_SalesRegion_ID
adrian@94
    68
      WHERE C_SalesRegion_ID IS NULL;
adrian@94
    69
    ELSIF(:new.ElementType='MC' AND :new.C_Campaign_ID IS NOT NULL) THEN
adrian@94
    70
      UPDATE C_ValidCombination
adrian@94
    71
        SET C_Campaign_ID=:new.C_Campaign_ID
adrian@94
    72
      WHERE C_Campaign_ID IS NULL;
adrian@94
    73
    ELSIF(:new.ElementType='AY' AND :new.C_Activity_ID IS NOT NULL) THEN
adrian@94
    74
      UPDATE C_ValidCombination
adrian@94
    75
        SET C_Activity_ID=:new.C_Activity_ID
adrian@94
    76
      WHERE C_Activity_ID IS NULL;
adrian@94
    77
    ELSIF(:new.ElementType='U1' AND :new.C_ElementValue_ID IS NOT NULL) THEN
adrian@94
    78
      UPDATE C_ValidCombination
adrian@94
    79
        SET User1_ID=:new.C_ElementValue_ID
adrian@94
    80
      WHERE User1_ID IS NULL;
adrian@94
    81
    ELSIF(:new.ElementType='U2' AND :new.C_ElementValue_ID IS NOT NULL) THEN
adrian@94
    82
      UPDATE C_ValidCombination
adrian@94
    83
        SET User2_ID=:new.C_ElementValue_ID
adrian@94
    84
      WHERE User2_ID IS NULL;
adrian@94
    85
    END IF;
adrian@94
    86
  END IF;
adrian@94
    87
  --
antonio@735
    88
END C_ACCTSCHEMA_ELEMENT_TRG
gorkaion@239
    89
]]></body>
adrian@94
    90
    </trigger>
adrian@94
    91
  </database>