src-db/database/model/functions/BOM_PRICELIMIT.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION BOM_PRICELIMIT">
adrian@94
     3
    <function name="BOM_PRICELIMIT" type="NUMERIC">
juanpablo@1605
     4
      <parameter name="p_product_id" type="VARCHAR" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
juanpablo@1605
     7
      <parameter name="p_pricelist_version_id" type="VARCHAR" mode="in">
antonio@735
     8
        <default/>
antonio@735
     9
      </parameter>
gorkaion@239
    10
      <body><![CDATA[/******************************************************************************
carlos@0
    11
* The contents of this file are subject to the   Compiere License  Version 1.1
carlos@0
    12
* ("License"); You may not use this file except in compliance with the License
carlos@0
    13
* You may obtain a copy of the License at http://www.compiere.org/license.html
carlos@0
    14
* Software distributed under the License is distributed on an  "AS IS"  basis,
carlos@0
    15
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
carlos@0
    16
* the specific language governing rights and limitations under the License.
gorkaion@239
    17
* The Original Code is                  Compiere  ERP &  Business Solution
carlos@0
    18
* The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
carlos@0
    19
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
carlos@0
    20
* created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
carlos@0
    21
* Contributor(s): Openbravo SL
carlos@0
    22
* Contributions are Copyright (C) 2001-2006 Openbravo S.L.
carlos@0
    23
******************************************************************************/
carlos@0
    24
  v_Price        NUMBER;
carlos@0
    25
  v_ProductPrice NUMBER;
carlos@0
    26
  -- Get BOM Product info
carlos@0
    27
  TYPE RECORD IS REF CURSOR;
carlos@0
    28
    CUR_BOM RECORD;
carlos@0
    29
    --
carlos@0
    30
  BEGIN
carlos@0
    31
    -- Try to get price from PriceList directly
carlos@0
    32
    SELECT COALESCE(SUM(PriceLimit), 0)
carlos@0
    33
    INTO v_Price
carlos@0
    34
    FROM M_ProductPrice
carlos@0
    35
    WHERE M_PriceList_Version_ID = p_PriceList_Version_ID
carlos@0
    36
      AND M_Product_ID = p_Product_ID;
carlos@0
    37
    -- DBMS_OUTPUT.PUT_LINE('Price=' || v_Price);
carlos@0
    38
    -- No Price - Check if BOM
carlos@0
    39
    IF(v_Price = 0) THEN
carlos@0
    40
      FOR CUR_BOM IN
carlos@0
    41
        (SELECT b.M_ProductBOM_ID,
carlos@0
    42
          b.BOMQty,
carlos@0
    43
          p.IsBOM
carlos@0
    44
        FROM M_Product_BOM b,
carlos@0
    45
          M_Product p
carlos@0
    46
        WHERE b.M_ProductBOM_ID = p.M_Product_ID
carlos@0
    47
          AND b.M_Product_ID = p_Product_ID
carlos@0
    48
        )
carlos@0
    49
      LOOP
carlos@0
    50
        v_ProductPrice := BOM_PriceLimit(CUR_BOM.M_ProductBOM_ID, p_PriceList_Version_ID) ;
carlos@0
    51
        v_Price := v_Price +(CUR_BOM.BOMQty * v_ProductPrice) ;
carlos@0
    52
      END LOOP;
carlos@0
    53
    END IF;
carlos@0
    54
    --
carlos@0
    55
    RETURN v_Price;
antonio@735
    56
END BOM_PRICELIMIT
gorkaion@239
    57
]]></body>
adrian@94
    58
    </function>
adrian@94
    59
  </database>