src-db/database/model/triggers/C_ORDERLINE2_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Mon, 28 Apr 2008 09:28:08 +0000
changeset 785 8dba91261590
parent 756 ae11e4610537
child 1605 8a0fe0193bef
permissions -rw-r--r--
Fix last update of copyright years in database files
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_ORDERLINE2_TRG">
adrian@94
     3
    <trigger name="C_ORDERLINE2_TRG" table="C_ORDERLINE" fires="before" insert="false" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
gorkaion@239
     5
adrian@170
     6
carlos@59
     7
adrian@94
     8
adrian@94
     9
/*************************************************************************
adrian@94
    10
* The contents of this file are subject to the Openbravo  Public  License
adrian@94
    11
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    12
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    13
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    14
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    15
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    17
* License for the specific  language  governing  rights  and  limitations
adrian@94
    18
* under the License.
adrian@94
    19
* The Original Code is Openbravo ERP.
adrian@94
    20
* The Initial Developer of the Original Code is Openbravo SL
adrian@94
    21
* All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    22
* All Rights Reserved.
adrian@94
    23
* Contributor(s):  ______________________________________.
adrian@94
    24
************************************************************************/
adrian@94
    25
  v_ID NUMBER;
adrian@94
    26
  v_QtyReserved      NUMBER;
adrian@94
    27
  v_QtyOrderReserved NUMBER;
adrian@94
    28
  V_STOCKED          NUMBER;
adrian@94
    29
BEGIN
adrian@94
    30
  IF(UPDATING) THEN
adrian@94
    31
    IF(:NEW.M_PRODUCT_ID IS NOT NULL) THEN
gorkaion@239
    32
      IF((COALESCE(:old.QtyDelivered, 0) <> COALESCE(:NEW.QtyDelivered, 0))) THEN
adrian@94
    33
        -- Get ID
adrian@94
    34
        v_ID:=:new.C_Order_ID;
adrian@94
    35
        v_QtyReserved:=-(:new.qtydelivered - :old.qtydelivered) ;
adrian@94
    36
        IF :old.qtydelivered=0 AND :new.qtydelivered=:new.qtyordered THEN
adrian@94
    37
          v_QtyOrderReserved:=-:new.QuantityOrder;
adrian@94
    38
        ELSIF :new.M_Product_UOM_ID IS NOT NULL THEN
adrian@94
    39
          v_QtyOrderReserved:=C_Uom_Convert(v_QtyReserved, :new.C_UOM_ID, :new.m_product_uom_id, 'Y') ;
adrian@94
    40
        END IF;
adrian@94
    41
        SELECT COUNT(*)
adrian@94
    42
        INTO V_STOCKED
adrian@94
    43
        FROM M_PRODUCT
adrian@94
    44
        WHERE M_Product_ID=:NEW.M_PRODUCT_ID
adrian@94
    45
          AND IsStocked='Y'
adrian@94
    46
          AND ProductType='I';
gorkaion@239
    47
        IF V_STOCKED > 0 THEN
adrian@94
    48
          M_UPDATE_STORAGE_PENDING(:new.AD_Client_ID, :new.AD_Org_ID, :new.UpdatedBy, :new.M_Product_ID, :new.M_Warehouse_ID, :new.M_AttributeSetInstance_ID, :new.C_UOM_ID, :new.M_PRODUCT_UOM_ID, v_QtyReserved, v_QtyOrderReserved, 0, NULL) ;
adrian@94
    49
        END IF;
adrian@94
    50
      END IF;
adrian@94
    51
    END IF;
adrian@94
    52
  END IF;
antonio@735
    53
END C_ORDERLINE2_TRG
gorkaion@239
    54
]]></body>
adrian@94
    55
    </trigger>
adrian@94
    56
  </database>