core-jgi/db/database/Functions/C_Currency_Round.SQL

49 lines
1.7 KiB
Plaintext
Raw Normal View History

2006-11-17 10:06:54 +07:00
CREATE OR REPLACE FUNCTION currencyRound
(
p_Amount IN NUMBER,
p_CurTo_ID IN NUMBER,
p_Costing IN VARCHAR2 -- Default 'N'
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Currency_Round.SQL,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Round amount for Traget Currency
* Description:
* Round Amount using Costing or Standard Precision
* Returns unmodified amount if currency not found
* Test:
* SELECT C_Currency_Round(C_Currency_Convert(100,116,100,null,null),100,null) FROM DUAL => 64.72
************************************************************************/
AS
v_StdPrecision NUMBER;
v_CostPrecision NUMBER;
BEGIN
-- Nothing to convert
IF (p_Amount IS NULL OR p_CurTo_ID IS NULL) THEN
RETURN p_Amount;
END IF;
-- Ger Precision
SELECT MAX(StdPrecision), MAX(CostingPrecision)
INTO v_StdPrecision, v_CostPrecision
FROM C_Currency
WHERE C_Currency_ID = p_CurTo_ID;
-- Currency Not Found
IF (v_StdPrecision IS NULL) THEN
RETURN p_Amount;
END IF;
IF (p_Costing = 'Y') THEN
RETURN ROUND (p_Amount, v_CostPrecision);
END IF;
RETURN ROUND (p_Amount, v_StdPrecision);
END currencyRound;
/