src-db/database/model/triggers/M_MOVEMENTLINE_TRG.xml
author Antonio Moreno <antonio.moreno@openbravo.com>
Wed, 23 Apr 2008 17:34:12 +0000
changeset 756 ae11e4610537
parent 735 database/model/triggers/M_MOVEMENTLINE_TRG.xml@daced7e311c9
child 1605 8a0fe0193bef
permissions -rw-r--r--
Moved database folder to src-db folder
<?xml version="1.0"?>
  <database name="TRIGGER M_MOVEMENTLINE_TRG">
    <trigger name="M_MOVEMENTLINE_TRG" table="M_MOVEMENTLINE" fires="after" insert="true" update="true" delete="true" foreach="row">
      <body><![CDATA[




  v_ID NUMBER;
  v_RO      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
  -- Get ID
  IF(UPDATING OR INSERTING) THEN
    v_ID:=:new.M_Movement_ID;
  ELSE
    v_ID:=:old.M_Movement_ID;
  END IF;
  -- ReadOnly Check
  SELECT COUNT(*)
  INTO v_RO
  FROM M_Movement
  WHERE M_Movement_ID=v_ID
    AND(Processed='Y'
    OR Posted='Y') ;
  IF(v_RO > 0) THEN
    RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
  END IF;
  -- Updating inventory
  IF UPDATING OR DELETING THEN
    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_INVENTORY(:OLD.AD_CLIENT_ID, :OLD.AD_ORG_ID, :OLD.UPDATEDBY, :OLD.M_PRODUCT_ID, :OLD.M_LOCATOR_ID, :OLD.M_ATTRIBUTESETINSTANCE_ID, :OLD.C_UOM_ID, :OLD.M_PRODUCT_UOM_ID, NULL, NULL, NULL, :OLD.MOVEMENTQTY, :OLD.QUANTITYORDER) ;
      M_UPDATE_INVENTORY(:OLD.AD_CLIENT_ID, :OLD.AD_ORG_ID, :OLD.UPDATEDBY, :OLD.M_PRODUCT_ID, :OLD.M_LOCATORTO_ID, :OLD.M_ATTRIBUTESETINSTANCE_ID, :OLD.C_UOM_ID, :OLD.M_PRODUCT_UOM_ID, NULL, NULL, NULL, -:OLD.MOVEMENTQTY, -:OLD.QUANTITYORDER) ;
    END IF;
  END IF;
  IF INSERTING OR UPDATING THEN
    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_INVENTORY(:NEW.AD_CLIENT_ID, :NEW.AD_ORG_ID, :NEW.UPDATEDBY, :NEW.M_PRODUCT_ID, :NEW.M_LOCATOR_ID, :NEW.M_ATTRIBUTESETINSTANCE_ID, :NEW.C_UOM_ID, :NEW.M_PRODUCT_UOM_ID, NULL, NULL, NULL, -:NEW.MOVEMENTQTY, -:NEW.QUANTITYORDER) ;
      M_UPDATE_INVENTORY(:NEW.AD_CLIENT_ID, :NEW.AD_ORG_ID, :NEW.UPDATEDBY, :NEW.M_PRODUCT_ID, :NEW.M_LOCATORTO_ID, :NEW.M_ATTRIBUTESETINSTANCE_ID, :NEW.C_UOM_ID, :NEW.M_PRODUCT_UOM_ID, NULL, NULL, NULL, :NEW.MOVEMENTQTY, :NEW.QUANTITYORDER) ;
    END IF;
  END IF;
END M_MOVEMENTLINE_TRG
]]></body>
    </trigger>
  </database>