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