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
<?xml version="1.0"?>
  <database name="FUNCTION C_CURRENCY_CONVERT">
    <function name="C_CURRENCY_CONVERT" type="NUMERIC">
      <parameter name="p_amount" type="NUMERIC" mode="in">
        <default/>
      </parameter>
      <parameter name="p_curfrom_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <parameter name="p_curto_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <parameter name="p_convdate" type="TIMESTAMP" mode="in">
        <default/>
      </parameter>
      <parameter name="p_ratetype" type="CHAR" mode="in">
        <default/>
      </parameter>
      <parameter name="p_client_id" type="VARCHAR" mode="in">
        <default><![CDATA[0]]></default>
      </parameter>
      <parameter name="p_org_id" type="VARCHAR" mode="in">
        <default><![CDATA[0]]></default>
      </parameter>
      <body><![CDATA[/*************************************************************************
* The contents of this file are subject to the Compiere Public
* License 1.1 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License in
* the legal folder of your Openbravo installation.
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing rights
* and limitations under the License.
* The Original Code is  Compiere  ERP &  Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
* parts created by ComPiere are Copyright (C) ComPiere, Inc.;
* All Rights Reserved.
* Contributor(s): Openbravo SL
* Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
*
* Specifically, this derivative work is based upon the following Compiere
* file and version.
*************************************************************************
* $Id: C_Currency_Convert.sql,v 1.8 2003/03/17 20:32:24 jjanke Exp $
***
* Title: Convert Amount (using IDs)
* Description:
*  from CurrencyFrom_ID to CurrencyTo_ID
*  Returns NULL, if conversion not found
*  Standard Rounding
* Test:
*  SELECT C_Currency_Convert(100,116,100,null,null) FROM DUAL => 64.72
************************************************************************/
  v_Rate NUMBER;
BEGIN
  -- Return Amount
  IF(p_Amount=0 OR p_CurFrom_ID=p_CurTo_ID) THEN
    RETURN p_Amount;
  END IF;
  -- Return NULL
  IF(p_Amount IS NULL OR p_CurFrom_ID IS NULL OR p_CurTo_ID IS NULL) THEN
    RETURN NULL;
  END IF;
  -- Get Rate
  v_Rate:=C_Currency_Rate(p_CurFrom_ID, p_CurTo_ID, p_ConvDate, p_RateType, p_Client_ID, p_Org_ID) ;
  IF(v_Rate IS NULL) THEN
    RETURN NULL;
  END IF;
  -- Standard Precision
  RETURN C_Currency_Round(p_Amount * v_Rate, p_CurTo_ID, null) ;
END C_CURRENCY_CONVERT
]]></body>
    </function>
  </database>