src-db/database/model/triggers/C_PROJECTLINE_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Mon, 28 Apr 2008 09:28:08 +0000
changeset 785 8dba91261590
parent 781 d68cf344696f
child 2078 cf88ca44cdd2
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_PROJECTLINE_TRG">
adrian@94
     3
    <trigger name="C_PROJECTLINE_TRG" table="C_PROJECTLINE" fires="before" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
    /*************************************************************************
juanpablo@771
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@771
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
    * the legal folder of your Openbravo installation.
adrian@94
    10
    * Software distributed under the License is distributed on an
adrian@94
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    12
    * implied. See the License for the specific language governing rights
adrian@94
    13
    * and limitations under the License.
juanpablo@778
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
adrian@94
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    18
    * All Rights Reserved.
adrian@94
    19
    * Contributor(s): Openbravo SL
juanpablo@785
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    21
    *
juanpablo@771
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
    * file and version.
adrian@94
    24
    *************************************************************************
adrian@94
    25
    * $Id: C_ProjectLine_Trg.sql,v 1.3 2003/09/05 04:58:07 jjanke Exp $
adrian@94
    26
    ***
adrian@94
    27
    * Title:       Update Planned Line Totals
adrian@94
    28
    * Description:
adrian@94
    29
    *      Set Line PlannedAmt, PlannedMarginAmt
adrian@94
    30
    ************************************************************************/
adrian@94
    31
    v_PriceLimit NUMBER:=NULL;
antonio@735
    32
  v_PriceStd NUMBER:=NULL;
adrian@94
    33
  v_PlannedMargin NUMBER:=NULL;
adrian@94
    34
BEGIN
adrian@94
    35
  -- Calculate PlannedAmt
gorkaion@239
    36
  IF(:new.PlannedQty <> 0 AND :new.PlannedPrice <> 0) THEN
adrian@94
    37
    :new.PlannedAmt:=:new.PlannedQty * :new.PlannedPrice;
adrian@94
    38
  END IF;
adrian@94
    39
  -- Get Margin from Product
gorkaion@239
    40
  IF(:new.M_Product_ID IS NOT NULL AND :new.PlannedPrice <> 0) THEN
adrian@94
    41
    SELECT COALESCE(MAX(PriceLimit), 0),
adrian@94
    42
      COALESCE(MAX(PriceStd), 0)
adrian@94
    43
    INTO v_PriceLimit,
adrian@94
    44
      v_PriceStd
adrian@94
    45
    FROM M_ProductPrice
adrian@94
    46
    WHERE M_Product_ID=:new.M_Product_ID
adrian@94
    47
      AND M_PriceList_Version_ID=
adrian@94
    48
      (
adrian@94
    49
      SELECT M_PriceList_Version_ID
adrian@94
    50
      FROM C_Project
adrian@94
    51
      WHERE C_Project_ID=:new.C_Project_ID
adrian@94
    52
      )
adrian@94
    53
      ;
gorkaion@239
    54
    IF(v_PriceLimit <> 0) THEN
adrian@94
    55
      :new.PlannedMarginAmt:=:new.PlannedQty *(:new.PlannedPrice - v_PriceLimit) ;
adrian@94
    56
    END IF;
adrian@94
    57
    -- Get Margin from Product Category
gorkaion@239
    58
  ELSIF(:new.M_Product_Category_ID IS NOT NULL AND :new.PlannedPrice <> 0) THEN
adrian@94
    59
    SELECT COALESCE(MAX(PlannedMargin), 0)
adrian@94
    60
    INTO v_PlannedMargin
adrian@94
    61
    FROM M_Product_Category
adrian@94
    62
    WHERE M_Product_Category_ID=:new.M_Product_Category_ID;
gorkaion@239
    63
    IF(v_PlannedMargin <> 0) THEN
adrian@94
    64
      :new.PlannedMarginAmt:=:new.PlannedAmt * v_PlannedMargin;
adrian@94
    65
    END IF;
adrian@94
    66
  END IF;
antonio@735
    67
END C_PROJECTLINE_TRG
gorkaion@239
    68
]]></body>
adrian@94
    69
    </trigger>
adrian@94
    70
  </database>