src-db/database/model/triggers/M_MOVEMENTLINE_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_MOVEMENTLINE_TRG">
       
     3     <trigger name="M_MOVEMENTLINE_TRG" table="M_MOVEMENTLINE" fires="after" insert="true" update="true" delete="true" foreach="row">
       
     4       <body><![CDATA[
       
     5 
       
     6 
       
     7 
       
     8 
       
     9   v_ID NUMBER;
       
    10   v_RO      NUMBER;
       
    11   V_STOCKED NUMBER;
       
    12   /******************************************************************************
       
    13   * The contents of this file are subject to the   Compiere License  Version 1.1
       
    14   * ("License"); You may not use this file except in compliance with the License
       
    15   * You may obtain a copy of the License at http://www.compiere.org/license.html
       
    16   * Software distributed under the License is distributed on an  "AS IS"  basis,
       
    17   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
       
    18   * the specific language governing rights and limitations under the License.
       
    19   * The Original Code is                  Compiere  ERP &  Business Solution
       
    20   * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
       
    21   * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
       
    22   * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
       
    23   * Contributor(s): Openbravo SL
       
    24   * Contributions are Copyright (C) 2001-2006 Openbravo S.L.
       
    25   ******************************************************************************/
       
    26 BEGIN
       
    27   -- Get ID
       
    28   IF(UPDATING OR INSERTING) THEN
       
    29     v_ID:=:new.M_Movement_ID;
       
    30   ELSE
       
    31     v_ID:=:old.M_Movement_ID;
       
    32   END IF;
       
    33   -- ReadOnly Check
       
    34   SELECT COUNT(*)
       
    35   INTO v_RO
       
    36   FROM M_Movement
       
    37   WHERE M_Movement_ID=v_ID
       
    38     AND(Processed='Y'
       
    39     OR Posted='Y') ;
       
    40   IF(v_RO > 0) THEN
       
    41     RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
       
    42   END IF;
       
    43   -- Updating inventory
       
    44   IF UPDATING OR DELETING THEN
       
    45     SELECT COUNT(*)
       
    46     INTO V_STOCKED
       
    47     FROM M_PRODUCT
       
    48     WHERE M_Product_ID=:OLD.M_PRODUCT_ID
       
    49       AND IsStocked='Y'
       
    50       AND ProductType='I';
       
    51     IF V_STOCKED > 0 THEN
       
    52       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) ;
       
    53       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) ;
       
    54     END IF;
       
    55   END IF;
       
    56   IF INSERTING OR UPDATING THEN
       
    57     SELECT COUNT(*)
       
    58     INTO V_STOCKED
       
    59     FROM M_PRODUCT
       
    60     WHERE M_Product_ID=:NEW.M_PRODUCT_ID
       
    61       AND IsStocked='Y'
       
    62       AND ProductType='I';
       
    63     IF V_STOCKED > 0 THEN
       
    64       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) ;
       
    65       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) ;
       
    66     END IF;
       
    67   END IF;
       
    68 END M_MOVEMENTLINE_TRG
       
    69 ]]></body>
       
    70     </trigger>
       
    71   </database>