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