Carlos Ruiz 2009-10-02 23:19:00 +00:00
parent 0b77aa9b3c
commit e613bc7461
2 changed files with 73 additions and 66 deletions

View File

@ -1,60 +1,62 @@
CREATE OR REPLACE FUNCTION currencyRound( -- DROP FUNCTION currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying);
p_Amount NUMERIC,
p_CurTo_ID NUMERIC, CREATE OR REPLACE FUNCTION currencyRound(
p_Costing VARCHAR -- Default 'N' p_Amount NUMERIC,
) p_CurTo_ID NUMERIC,
p_Costing character varying -- Default 'N'
RETURNS numeric AS $body$ )
/************************************************************************* 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 * The contents of this file are subject to the Compiere License. You may
* express or implied. See the License for details. Code: Compiere ERP+CRM * obtain a copy of the License at http://www.compiere.org/license.html
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved. * 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
* converted to postgreSQL by Karsten Thiemann (Schaeffer AG), * Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
* kthiemann@adempiere.org *
************************************************************************* * 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 * Title: Round amount for Traget Currency
* Returns unmodified amount if currency not found * Description:
* Test: * Round Amount using Costing or Standard Precision
* SELECT currencyRound(currencyConvert(100,116,100,null,null),100,null) FROM AD_System => 64.72 * 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; DECLARE
v_StdPrecision int;
BEGIN v_CostPrecision int;
-- Nothing to convert
IF (p_Amount IS NULL OR p_CurTo_ID IS NULL) THEN BEGIN
RETURN p_Amount; -- Nothing to convert
END IF; IF (p_Amount IS NULL OR p_CurTo_ID IS NULL) THEN
RETURN p_Amount;
-- Ger Precision END IF;
SELECT MAX(StdPrecision), MAX(CostingPrecision)
INTO v_StdPrecision, v_CostPrecision -- Ger Precision
FROM C_Currency SELECT MAX(StdPrecision), MAX(CostingPrecision)
WHERE C_Currency_ID = p_CurTo_ID; INTO v_StdPrecision, v_CostPrecision
-- Currency Not Found FROM C_Currency
IF (v_StdPrecision IS NULL) THEN WHERE C_Currency_ID = p_CurTo_ID;
RETURN p_Amount; -- Currency Not Found
END IF; IF (v_StdPrecision IS NULL) THEN
RETURN p_Amount;
IF (p_Costing = 'Y') THEN END IF;
RETURN ROUND (p_Amount, v_CostPrecision);
END IF; IF (p_Costing = 'Y') THEN
RETURN ROUND (p_Amount, v_CostPrecision);
RETURN ROUND (p_Amount, v_StdPrecision); END IF;
END; RETURN ROUND (p_Amount, v_StdPrecision);
$body$ LANGUAGE plpgsql; END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying) OWNER TO adempiere;

View File

@ -1,9 +1,13 @@
-- DROP FUNCTION adempiere.currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying); -- DROP FUNCTION currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying);
CREATE OR REPLACE FUNCTION currencyRound(
p_Amount NUMERIC,
p_CurTo_ID NUMERIC,
p_Costing character varying -- Default 'N'
)
RETURNS numeric AS $BODY$
CREATE OR REPLACE FUNCTION adempiere.currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying)
RETURNS numeric AS
$BODY$
/************************************************************************* /*************************************************************************
* The contents of this file are subject to the Compiere License. You may * 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 * obtain a copy of the License at http://www.compiere.org/license.html
@ -54,4 +58,5 @@ END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' VOLATILE; LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION adempiere.currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying) OWNER TO adempiere;
ALTER FUNCTION currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying) OWNER TO adempiere;