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