Migration from pl/java to native function postgreSQL

This commit is contained in:
vpj-cd 2008-10-29 20:28:55 +00:00
parent 36f89eb186
commit 4b9e4d3db9
1 changed files with 30 additions and 27 deletions

View File

@ -2,8 +2,7 @@
*This file is part of Adempiere ERP Bazaar *This file is part of Adempiere ERP Bazaar
*http://www.adempiere.org *http://www.adempiere.org
* *
*Copyright (C) 2006-2007 Timo Kontro *Copyright (C) 2006-2008 Antonio Cañaveral, e-Evolution
*Copyright (C) 1999-2006 ComPiere, inc
* *
*This program is free software; you can redistribute it and/or *This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License *modify it under the terms of the GNU General Public License
@ -19,30 +18,34 @@
*along with this program; if not, write to the Free Software *along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of
*/ */
CREATE OR REPLACE FUNCTION bompricelimit(p_product_id numeric, p_pricelist_version_id numeric)
/* RETURNS numeric AS
* Loops recursively through BOM and returns BOM's total limit price.
*/
CREATE OR REPLACE FUNCTION bompricelimit("numeric", "numeric")
RETURNS "numeric" AS
$BODY$ $BODY$
DECLARE DECLARE
price NUMERIC; v_Price numeric;
productprice NUMERIC; v_ProductPrice numeric;
boms RECORD; bom record;
BEGIN BEGIN
SELECT COALESCE(t.PriceLimit,0) INTO price FROM m_productprice t -- Try to get price from PriceList directly
WHERE t.m_pricelist_version_id = $2 AND t.m_product_id = $1; SELECT COALESCE (SUM(PriceLimit), 0)
IF price = 0 THEN INTO v_Price
FOR boms IN SELECT t.m_productbom_id, t.bomqty FROM M_PRODUCTPRICE
FROM m_product_bom t WHERE M_PriceList_Version_ID=p_PriceList_Version_ID AND M_Product_ID=p_Product_ID;
WHERE t.m_product_id = $1 IF (v_Price = 0) THEN
FOR bom in SELECT bl.M_Product_ID AS M_ProductBOM_ID,
CASE WHEN bl.IsQtyPercentage = 'N' THEN bl.QtyBOM ELSE bl.QtyBatch / 100 END AS BomQty , p.IsBOM
FROM PP_PRODUCT_BOM b
INNER JOIN M_PRODUCT p ON (p.M_Product_ID=b.M_Product_ID)
INNER JOIN PP_PRODUCT_BOMLINE bl ON (bl.PP_Product_BOM_ID=b.PP_Product_BOM_ID)
WHERE b.M_Product_ID = p_Product_ID
LOOP LOOP
productprice := bompricelimit(boms.m_productbom_id, $2); v_ProductPrice := Bompricelimit (bom.M_ProductBOM_ID, p_PriceList_Version_ID);
price := price + (boms.bomqty * productprice); v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
END LOOP; END LOOP;
END IF; END IF;
return price; --
END; RETURN v_Price;
END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' STABLE STRICT; LANGUAGE 'plpgsql' STABLE STRICT
COST 100;