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