src-db/database/model/triggers/M_MATCHPO_TRG.xml
changeset 756 ae11e4610537
parent 735 daced7e311c9
child 1605 8a0fe0193bef
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/model/triggers/M_MATCHPO_TRG.xml	Wed Apr 23 17:34:12 2008 +0000
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+  <database name="TRIGGER M_MATCHPO_TRG">
+    <trigger name="M_MATCHPO_TRG" table="M_MATCHPO" fires="before" insert="true" update="true" delete="false" foreach="row">
+      <body><![CDATA[
+
+
+
+
+  v_QtyOrdered NUMBER;
+  v_QtyOrderOrdered NUMBER;
+  v_Product_UOM     NUMBER;
+  v_UOM             NUMBER;
+  v_Attribute       NUMBER;
+  v_Warehouse       NUMBER;
+  V_STOCKED         NUMBER;
+  /******************************************************************************
+  * The contents of this file are subject to the   Compiere License  Version 1.1
+  * ("License"); You may not use this file except in compliance with the License
+  * You may obtain a copy of the License at http://www.compiere.org/license.html
+  * Software distributed under the License is distributed on an  "AS IS"  basis,
+  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+  * the specific language governing rights and limitations under the License.
+  * The Original Code is                  Compiere  ERP &  Business Solution
+  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
+  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
+  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
+  * Contributor(s): Openbravo SL
+  * Contributions are Copyright (C) 2001-2006 Openbravo S.L.
+  ******************************************************************************/
+BEGIN
+  IF(UPDATING OR DELETING) THEN
+    IF :OLD.M_INOUTLINE_ID IS NOT NULL THEN
+      v_QtyOrdered:=:old.qty;
+      SELECT o.C_UOM_ID,
+        o.M_ATTRIBUTESETINSTANCE_ID,
+        o.M_PRODUCT_UOM_ID,
+        o.M_WAREHOUSE_ID
+      INTO v_UOM,
+        v_Attribute,
+        v_Product_UOM,
+        v_Warehouse
+      FROM C_ORDERLINE o
+      WHERE o.C_ORDERLINE_ID=:old.C_ORDERLINE_ID;
+      SELECT l.QUANTITYORDER
+      INTO v_QtyOrderOrdered
+      FROM M_INOUTLINE l
+      WHERE l.M_INOUTLINE_ID=:old.M_INOUTLINE_ID;
+      SELECT COUNT(*)
+      INTO V_STOCKED
+      FROM M_PRODUCT
+      WHERE M_Product_ID=:OLD.M_PRODUCT_ID
+        AND IsStocked='Y'
+        AND ProductType='I';
+      IF V_STOCKED > 0 THEN
+        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) ;
+      END IF;
+    END IF;
+  END IF;
+  IF(INSERTING OR UPDATING) THEN
+    IF :NEW.M_INOUTLINE_ID IS NOT NULL THEN
+      v_QtyOrdered:=-:new.qty;
+      SELECT o.C_UOM_ID,
+        o.M_ATTRIBUTESETINSTANCE_ID,
+        o.M_PRODUCT_UOM_ID,
+        o.M_WAREHOUSE_ID
+      INTO v_UOM,
+        v_Attribute,
+        v_Product_UOM,
+        v_Warehouse
+      FROM C_ORDERLINE o
+      WHERE o.C_ORDERLINE_ID=:new.C_ORDERLINE_ID;
+      SELECT -l.QUANTITYORDER
+      INTO v_QtyOrderOrdered
+      FROM M_INOUTLINE l
+      WHERE l.M_INOUTLINE_ID=:new.M_INOUTLINE_ID;
+      SELECT COUNT(*)
+      INTO V_STOCKED
+      FROM M_PRODUCT
+      WHERE M_Product_ID=:NEW.M_PRODUCT_ID
+        AND IsStocked='Y'
+        AND ProductType='I';
+      IF V_STOCKED > 0 THEN
+        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) ;
+      END IF;
+    END IF;
+  END IF;
+END M_MATCHPO_TRG
+]]></body>
+    </trigger>
+  </database>