database/model/triggers/M_MATCHPO_TRG.xml
author Adrián Romero <adrian.romero@openbravo.com>
Tue, 20 Nov 2007 16:27:14 +0000
changeset 94 4e7ba7b8a4ad
parent 59 85aab40b7d24
child 132 33c5ca45fcff
permissions -rw-r--r--
fix: Changed check constraint names and foreign key names to fit in to
30 characteres.
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER M_MATCHPO_TRG">
adrian@94
     3
    <trigger name="M_MATCHPO_TRG" table="M_MATCHPO" fires="before" insert="true" update="true" delete="false" foreach="row">
adrian@94
     4
      <body>
carlos@59
     5
adrian@94
     6
adrian@94
     7
  v_QtyOrdered NUMBER;
adrian@94
     8
  v_QtyOrderOrdered NUMBER;
adrian@94
     9
  v_Product_UOM     NUMBER;
adrian@94
    10
  v_UOM             NUMBER;
adrian@94
    11
  v_Attribute       NUMBER;
adrian@94
    12
  v_Warehouse       NUMBER;
adrian@94
    13
  V_STOCKED         NUMBER;
adrian@94
    14
  /******************************************************************************
adrian@94
    15
  * The contents of this file are subject to the   Compiere License  Version 1.1
adrian@94
    16
  * ("License"); You may not use this file except in compliance with the License
adrian@94
    17
  * You may obtain a copy of the License at http://www.compiere.org/license.html
adrian@94
    18
  * Software distributed under the License is distributed on an  "AS IS"  basis,
adrian@94
    19
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
adrian@94
    20
  * the specific language governing rights and limitations under the License.
adrian@94
    21
  * The Original Code is                  Compiere  ERP &amp;  Business Solution
adrian@94
    22
  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
adrian@94
    23
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
adrian@94
    24
  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
adrian@94
    25
  * Contributor(s): Openbravo SL
adrian@94
    26
  * Contributions are Copyright (C) 2001-2006 Openbravo S.L.
adrian@94
    27
  ******************************************************************************/
adrian@94
    28
BEGIN
adrian@94
    29
  IF(UPDATING OR DELETING) THEN
adrian@94
    30
    IF :OLD.M_INOUTLINE_ID IS NOT NULL THEN
adrian@94
    31
      v_QtyOrdered:=:old.qty;
adrian@94
    32
      SELECT o.C_UOM_ID,
adrian@94
    33
        o.M_ATTRIBUTESETINSTANCE_ID,
adrian@94
    34
        o.M_PRODUCT_UOM_ID,
adrian@94
    35
        o.M_WAREHOUSE_ID
adrian@94
    36
      INTO v_UOM,
adrian@94
    37
        v_Attribute,
adrian@94
    38
        v_Product_UOM,
adrian@94
    39
        v_Warehouse
adrian@94
    40
      FROM C_ORDERLINE o
adrian@94
    41
      WHERE o.C_ORDERLINE_ID=:old.C_ORDERLINE_ID;
adrian@94
    42
      SELECT l.QUANTITYORDER
adrian@94
    43
      INTO v_QtyOrderOrdered
adrian@94
    44
      FROM M_INOUTLINE l
adrian@94
    45
      WHERE l.M_INOUTLINE_ID=:old.M_INOUTLINE_ID;
adrian@94
    46
      SELECT COUNT(*)
adrian@94
    47
      INTO V_STOCKED
adrian@94
    48
      FROM M_PRODUCT
adrian@94
    49
      WHERE M_Product_ID=:OLD.M_PRODUCT_ID
adrian@94
    50
        AND IsStocked='Y'
adrian@94
    51
        AND ProductType='I';
adrian@94
    52
      IF V_STOCKED &gt; 0 THEN
adrian@94
    53
        M_UPDATE_STORAGE_PENDING(:old.AD_Client_ID, :old.AD_Org_ID, :old.UpdatedBy, :old.M_Product_ID, v_Warehouse, v_Attribute, v_UOM, v_Product_UOM, 0, NULL, v_QtyOrdered, v_QtyOrderOrdered) ;
adrian@94
    54
      END IF;
adrian@94
    55
    END IF;
adrian@94
    56
  END IF;
adrian@94
    57
  IF(INSERTING OR UPDATING) THEN
adrian@94
    58
    IF :NEW.M_INOUTLINE_ID IS NOT NULL THEN
adrian@94
    59
      v_QtyOrdered:=-:new.qty;
adrian@94
    60
      SELECT o.C_UOM_ID,
adrian@94
    61
        o.M_ATTRIBUTESETINSTANCE_ID,
adrian@94
    62
        o.M_PRODUCT_UOM_ID,
adrian@94
    63
        o.M_WAREHOUSE_ID
adrian@94
    64
      INTO v_UOM,
adrian@94
    65
        v_Attribute,
adrian@94
    66
        v_Product_UOM,
adrian@94
    67
        v_Warehouse
adrian@94
    68
      FROM C_ORDERLINE o
adrian@94
    69
      WHERE o.C_ORDERLINE_ID=:new.C_ORDERLINE_ID;
adrian@94
    70
      SELECT -l.QUANTITYORDER
adrian@94
    71
      INTO v_QtyOrderOrdered
adrian@94
    72
      FROM M_INOUTLINE l
adrian@94
    73
      WHERE l.M_INOUTLINE_ID=:new.M_INOUTLINE_ID;
adrian@94
    74
      SELECT COUNT(*)
adrian@94
    75
      INTO V_STOCKED
adrian@94
    76
      FROM M_PRODUCT
adrian@94
    77
      WHERE M_Product_ID=:NEW.M_PRODUCT_ID
adrian@94
    78
        AND IsStocked='Y'
adrian@94
    79
        AND ProductType='I';
adrian@94
    80
      IF V_STOCKED &gt; 0 THEN
adrian@94
    81
        M_UPDATE_STORAGE_PENDING(:new.AD_Client_ID, :new.AD_Org_ID, :new.UpdatedBy, :new.M_Product_ID, v_Warehouse, v_Attribute, v_UOM, v_Product_UOM, 0, NULL, v_QtyOrdered, v_QtyOrderOrdered) ;
adrian@94
    82
      END IF;
adrian@94
    83
    END IF;
adrian@94
    84
  END IF;
adrian@94
    85
END M_MatchPO_Trg
adrian@94
    86
adrian@94
    87
</body>
adrian@94
    88
    </trigger>
adrian@94
    89
  </database>