src-db/database/model/functions/C_CURRENCY_CONVERT.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 1829 60bba62cd855
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION C_CURRENCY_CONVERT">
adrian@94
     3
    <function name="C_CURRENCY_CONVERT" type="NUMERIC">
antonio@735
     4
      <parameter name="p_amount" type="NUMERIC" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
juanpablo@1605
     7
      <parameter name="p_curfrom_id" type="VARCHAR" mode="in">
antonio@735
     8
        <default/>
antonio@735
     9
      </parameter>
juanpablo@1605
    10
      <parameter name="p_curto_id" type="VARCHAR" mode="in">
antonio@735
    11
        <default/>
antonio@735
    12
      </parameter>
antonio@735
    13
      <parameter name="p_convdate" type="TIMESTAMP" mode="in">
antonio@735
    14
        <default/>
antonio@735
    15
      </parameter>
antonio@735
    16
      <parameter name="p_ratetype" type="CHAR" mode="in">
antonio@735
    17
        <default/>
antonio@735
    18
      </parameter>
juanpablo@1605
    19
      <parameter name="p_client_id" type="VARCHAR" mode="in">
antonio@735
    20
        <default><![CDATA[0]]></default>
antonio@735
    21
      </parameter>
juanpablo@1605
    22
      <parameter name="p_org_id" type="VARCHAR" mode="in">
antonio@735
    23
        <default><![CDATA[0]]></default>
antonio@735
    24
      </parameter>
gorkaion@239
    25
      <body><![CDATA[/*************************************************************************
juanpablo@771
    26
* The contents of this file are subject to the Compiere Public
juanpablo@771
    27
* License 1.1 ("License"); You may not use this file except in
juanpablo@771
    28
* compliance with the License. You may obtain a copy of the License in
juanpablo@771
    29
* the legal folder of your Openbravo installation.
carlos@0
    30
* Software distributed under the License is distributed on an
carlos@0
    31
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    32
* implied. See the License for the specific language governing rights
carlos@0
    33
* and limitations under the License.
juanpablo@778
    34
* The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    35
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
carlos@0
    36
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
carlos@0
    37
* parts created by ComPiere are Copyright (C) ComPiere, Inc.;
carlos@0
    38
* All Rights Reserved.
carlos@0
    39
* Contributor(s): Openbravo SL
juanpablo@785
    40
* Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    41
*
juanpablo@771
    42
* Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    43
* file and version.
carlos@0
    44
*************************************************************************
carlos@0
    45
* $Id: C_Currency_Convert.sql,v 1.8 2003/03/17 20:32:24 jjanke Exp $
carlos@0
    46
***
carlos@0
    47
* Title: Convert Amount (using IDs)
carlos@0
    48
* Description:
carlos@0
    49
*  from CurrencyFrom_ID to CurrencyTo_ID
carlos@0
    50
*  Returns NULL, if conversion not found
carlos@0
    51
*  Standard Rounding
carlos@0
    52
* Test:
gorkaion@239
    53
*  SELECT C_Currency_Convert(100,116,100,null,null) FROM DUAL => 64.72
carlos@0
    54
************************************************************************/
carlos@0
    55
  v_Rate NUMBER;
carlos@0
    56
BEGIN
carlos@0
    57
  -- Return Amount
carlos@0
    58
  IF(p_Amount=0 OR p_CurFrom_ID=p_CurTo_ID) THEN
carlos@0
    59
    RETURN p_Amount;
carlos@0
    60
  END IF;
carlos@0
    61
  -- Return NULL
carlos@0
    62
  IF(p_Amount IS NULL OR p_CurFrom_ID IS NULL OR p_CurTo_ID IS NULL) THEN
carlos@0
    63
    RETURN NULL;
carlos@0
    64
  END IF;
carlos@0
    65
  -- Get Rate
carlos@0
    66
  v_Rate:=C_Currency_Rate(p_CurFrom_ID, p_CurTo_ID, p_ConvDate, p_RateType, p_Client_ID, p_Org_ID) ;
carlos@0
    67
  IF(v_Rate IS NULL) THEN
carlos@0
    68
    RETURN NULL;
carlos@0
    69
  END IF;
carlos@0
    70
  -- Standard Precision
carlos@0
    71
  RETURN C_Currency_Round(p_Amount * v_Rate, p_CurTo_ID, null) ;
antonio@735
    72
END C_CURRENCY_CONVERT
gorkaion@239
    73
]]></body>
adrian@94
    74
    </function>
adrian@94
    75
  </database>