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