src-db/database/model/functions/GET_PRODUCT_PRICE_DATE.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 GET_PRODUCT_PRICE_DATE">
adrian@94
     3
    <function name="GET_PRODUCT_PRICE_DATE" type="NUMERIC">
juanpablo@1605
     4
      <parameter name="p_ad_client_id" type="VARCHAR" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
juanpablo@1605
     7
      <parameter name="p_m_product_id" type="VARCHAR" mode="in">
antonio@735
     8
        <default/>
antonio@735
     9
      </parameter>
antonio@735
    10
      <parameter name="p_date" type="TIMESTAMP" mode="in">
antonio@735
    11
        <default/>
antonio@735
    12
      </parameter>
gorkaion@239
    13
      <body><![CDATA[/*************************************************************************
carlos@0
    14
* The contents of this file are subject to the Openbravo  Public  License
carlos@0
    15
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
    16
* Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
    17
* file except in compliance with the License. You  may  obtain  a copy of
carlos@0
    18
* the License at http://www.openbravo.com/legal/license.html
carlos@0
    19
* Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    20
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    21
* License for the specific  language  governing  rights  and  limitations
carlos@0
    22
* under the License.
carlos@0
    23
* The Original Code is Openbravo ERP.
carlos@0
    24
* The Initial Developer of the Original Code is Openbravo SL
carlos@0
    25
* All portions are Copyright (C) 2007 Openbravo SL
carlos@0
    26
* All Rights Reserved.
carlos@0
    27
* Contributor(s):  ______________________________________.
carlos@0
    28
************************************************************************/
juanpablo@1605
    29
  v_M_PriceList_Version_ID VARCHAR2(32);
carlos@0
    30
  v_Price                  NUMBER;
carlos@0
    31
BEGIN
carlos@0
    32
  SELECT MAX(M_PRICELIST_VERSION_ID)
carlos@0
    33
  INTO v_M_PriceList_Version_ID
carlos@0
    34
  FROM M_PRICELIST_VERSION
carlos@0
    35
  WHERE M_PRICELIST_ID IN
carlos@0
    36
    (SELECT M_PRICELIST_ID
carlos@0
    37
    FROM M_PRICELIST
carlos@0
    38
    WHERE ISDEFAULT = 'Y'
carlos@0
    39
      AND AD_CLIENT_ID = p_AD_Client_ID
carlos@0
    40
      AND ISACTIVE = 'Y'
carlos@0
    41
    )
carlos@0
    42
    AND VALIDFROM =
carlos@0
    43
    (SELECT max(VALIDFROM)
carlos@0
    44
    FROM M_PRICELIST_VERSION
carlos@0
    45
    WHERE M_PRICELIST_ID IN
carlos@0
    46
      (SELECT M_PRICELIST_ID
carlos@0
    47
      FROM M_PRICELIST
carlos@0
    48
      WHERE ISDEFAULT = 'Y'
carlos@0
    49
        AND AD_CLIENT_ID = p_AD_Client_ID
carlos@0
    50
        AND ISACTIVE = 'Y'
carlos@0
    51
      )
gorkaion@239
    52
      AND TO_DATE(VALIDFROM) <= TO_DATE(COALESCE(p_Date, now()))
carlos@0
    53
      AND EXISTS(SELECT 1
carlos@0
    54
                 FROM M_PRODUCTPRICE
carlos@0
    55
                 WHERE M_PRICELIST_VERSION_ID = M_PRICELIST_VERSION.M_PRICELIST_VERSION_ID
carlos@0
    56
                   AND M_PRODUCT_ID = p_M_Product_ID)
carlos@0
    57
    )
carlos@0
    58
    AND EXISTS(SELECT 1
carlos@0
    59
                 FROM M_PRODUCTPRICE
carlos@0
    60
                 WHERE M_PRICELIST_VERSION_ID = M_PRICELIST_VERSION.M_PRICELIST_VERSION_ID
carlos@0
    61
                   AND M_PRODUCT_ID = p_M_Product_ID)
carlos@0
    62
    ;
carlos@0
    63
  IF(v_M_PriceList_Version_ID IS NULL) THEN
carlos@0
    64
    RETURN 0;
carlos@0
    65
  ELSE
carlos@0
    66
    SELECT COALESCE(PRICESTD, 0)
carlos@0
    67
    INTO v_Price
carlos@0
    68
    FROM M_PRODUCTPRICE
carlos@0
    69
    WHERE M_PRICELIST_VERSION_ID = v_M_PriceList_Version_ID
carlos@0
    70
      AND AD_CLIENT_ID = p_AD_Client_ID
carlos@0
    71
      AND M_PRODUCT_ID = p_M_Product_ID;
carlos@0
    72
  END IF;
carlos@0
    73
  IF v_Price IS NULL THEN
carlos@0
    74
    v_Price := 0;
carlos@0
    75
  END IF;
carlos@0
    76
  RETURN v_Price;
antonio@735
    77
END GET_PRODUCT_PRICE_DATE
gorkaion@239
    78
]]></body>
adrian@94
    79
    </function>
adrian@94
    80
  </database>