From e5e7ae34814f0f70cae208e3fac57a5c5eb2b0b2 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 16 Jan 2009 05:27:56 +0000 Subject: [PATCH] Fix ID: [2478307] -CurrencyRound pgsql function not working in 353 seed https://sourceforge.net/tracker2/index.php?func=detail&aid=2478307&group_id=176962&atid=879332 ** Another function missing in 342 postgresql seed CurrencyRound --- .../353a-trunk/oracle/398_currencyround.sql | 1 + .../postgresql/398_currencyround.sql | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 migration/353a-trunk/oracle/398_currencyround.sql create mode 100644 migration/353a-trunk/postgresql/398_currencyround.sql diff --git a/migration/353a-trunk/oracle/398_currencyround.sql b/migration/353a-trunk/oracle/398_currencyround.sql new file mode 100644 index 0000000000..8d61dca7e9 --- /dev/null +++ b/migration/353a-trunk/oracle/398_currencyround.sql @@ -0,0 +1 @@ +-- just for postgresql diff --git a/migration/353a-trunk/postgresql/398_currencyround.sql b/migration/353a-trunk/postgresql/398_currencyround.sql new file mode 100644 index 0000000000..984d91ade1 --- /dev/null +++ b/migration/353a-trunk/postgresql/398_currencyround.sql @@ -0,0 +1,60 @@ +CREATE OR REPLACE FUNCTION currencyRound( + p_Amount NUMERIC, + p_CurTo_ID NUMERIC, + p_Costing VARCHAR -- Default 'N' +) + +RETURNS numeric AS $body$ + +/************************************************************************* + * The contents of this file are subject to the Compiere License. You may + * obtain a copy of the License at http://www.compiere.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: Compiere ERP+CRM + * Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved. + * + * converted to postgreSQL by Karsten Thiemann (Schaeffer AG), + * kthiemann@adempiere.org + ************************************************************************* + *** + * Title: Round amount for Traget Currency + * Description: + * Round Amount using Costing or Standard Precision + * Returns unmodified amount if currency not found + * Test: + * SELECT currencyRound(currencyConvert(100,116,100,null,null),100,null) FROM AD_System => 64.72 + ************************************************************************/ + + +DECLARE + v_StdPrecision NUMERIC; + v_CostPrecision NUMERIC; + +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; + +$body$ LANGUAGE plpgsql; + + +