[ 1840219 ] Migration from pl/java to pl/pgSQL for PostgreSQL
http://sourceforge.net/tracker/index.php?func=detail&aid=1840219&group_id=176962&atid=879335
This commit is contained in:
parent
c9155532a7
commit
c978848d17
|
@ -1,10 +1,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-2008 victor.perez@e-evolution.com, e-Evolution
|
||||||
*Copyright (C) 2006 Timo Kontro
|
|
||||||
*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
|
||||||
*as published by the Free Software Foundation; either version 2
|
*as published by the Free Software Foundation; either version 2
|
||||||
|
@ -18,31 +15,46 @@
|
||||||
*You should have received a copy of the GNU General Public License
|
*You should have received a copy of the GNU General Public License
|
||||||
*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
|
||||||
|
* Title: Return List Price of Product/BOM
|
||||||
|
* Description:
|
||||||
*/
|
*/
|
||||||
|
CREATE OR REPLACE FUNCTION Bompricelist
|
||||||
|
(
|
||||||
|
Product_ID numeric,
|
||||||
|
PriceList_Version_ID numeric
|
||||||
|
)
|
||||||
|
RETURNS numeric
|
||||||
|
AS
|
||||||
|
$BODY$
|
||||||
|
DECLARE
|
||||||
|
v_Price numeric;
|
||||||
|
v_ProductPrice numeric;
|
||||||
|
bom record;
|
||||||
|
BEGIN
|
||||||
|
-- Try to get price from pricelist directly
|
||||||
|
SELECT COALESCE (SUM(PriceList), 0)
|
||||||
|
INTO v_Price
|
||||||
|
FROM M_PRODUCTPRICE
|
||||||
|
WHERE M_PriceList_Version_ID=PriceList_Version_ID AND M_Product_ID=Product_ID;
|
||||||
|
-- DBMS_OUTPUT.PUT_LINE('Price=' || Price);
|
||||||
|
|
||||||
/*
|
-- No Price - Check if BOM
|
||||||
* Loops recursively through bom and returns sum of list prices (pricelist).
|
IF (v_Price = 0) THEN
|
||||||
*/
|
FOR bom IN
|
||||||
CREATE OR REPLACE FUNCTION bompricelist(
|
--Get BOM Product info
|
||||||
IN NUMERIC, -- $1 product id
|
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
|
||||||
IN NUMERIC -- $2 pricelist version id
|
FROM PP_PRODUCT_BOM b
|
||||||
) RETURNS NUMERIC AS
|
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)
|
||||||
DECLARE
|
WHERE b.M_Product_ID = Product_ID
|
||||||
price NUMERIC;
|
LOOP
|
||||||
productprice NUMERIC;
|
v_ProductPrice := Bompricelist (bom.M_ProductBOM_ID, PriceList_Version_ID);
|
||||||
boms RECORD;
|
v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
|
||||||
BEGIN
|
-- DBMS_OUTPUT.PUT_LINE('Qry=' || bom.BOMQty || ' @ ' || v_ProductPrice || ', Price=' || v_Price);
|
||||||
SELECT COALESCE(t.PriceList, 0) INTO price FROM m_productprice as t
|
END LOOP; -- BOM
|
||||||
WHERE t.m_pricelist_version_id = $2 AND t.m_product_id = $1;
|
|
||||||
IF price = 0 THEN
|
|
||||||
FOR boms IN SELECT t.m_productbom_id, t.bomqty
|
|
||||||
FROM m_product_bom as t
|
|
||||||
WHERE t.m_product_id = $1 LOOP
|
|
||||||
productprice := bompricelist(boms.m_productbom_id, $2);
|
|
||||||
price := price + (boms.bomqty * productprice);
|
|
||||||
END LOOP;
|
|
||||||
END IF;
|
END IF;
|
||||||
return price;
|
--
|
||||||
END;
|
RETURN v_Price;
|
||||||
$$ LANGUAGE plpgsql STABLE STRICT;
|
END;
|
||||||
|
$BODY$
|
||||||
|
LANGUAGE 'plpgsql' STABLE STRICT
|
||||||
|
|
|
@ -1,10 +1,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-2008 victor.perez@e-evolution.com, e-Evolution
|
||||||
*Copyright (C) 2006-2007 Timo Kontro
|
|
||||||
*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
|
||||||
*as published by the Free Software Foundation; either version 2
|
*as published by the Free Software Foundation; either version 2
|
||||||
|
@ -18,31 +15,45 @@
|
||||||
*You should have received a copy of the GNU General Public License
|
*You should have received a copy of the GNU General Public License
|
||||||
*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
|
||||||
|
* Title: Return Standard Price of Product/BOM
|
||||||
|
* Description:
|
||||||
*/
|
*/
|
||||||
|
CREATE OR REPLACE FUNCTION Bompricestd
|
||||||
|
(
|
||||||
|
Product_ID numeric,
|
||||||
|
PriceList_Version_ID numeric
|
||||||
|
)
|
||||||
|
RETURNS numeric
|
||||||
|
AS
|
||||||
|
$BODY$
|
||||||
|
DECLARE
|
||||||
|
v_Price numeric;
|
||||||
|
v_ProductPrice numeric;
|
||||||
|
bom record;
|
||||||
|
BEGIN
|
||||||
|
-- Try to get price from pricelist directly
|
||||||
|
SELECT COALESCE(SUM(PriceStd), 0)
|
||||||
|
INTO v_Price
|
||||||
|
FROM M_PRODUCTPRICE
|
||||||
|
WHERE M_PriceList_Version_ID=PriceList_Version_ID AND M_Product_ID=Product_ID;
|
||||||
|
-- DBMS_OUTPUT.PUT_LINE('Price=' || v_Price);
|
||||||
|
|
||||||
/*
|
-- No Price - Check if BOM
|
||||||
* Loops recursively through BOM and returns sum of the pricestd fields.
|
IF (v_Price = 0) THEN
|
||||||
*/
|
FOR bom IN -- Get BOM Product info
|
||||||
CREATE OR REPLACE FUNCTION bompricestd(
|
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
|
||||||
IN NUMERIC, -- $1 product id
|
FROM PP_PRODUCT_BOM b
|
||||||
IN NUMERIC -- $2 pricelist version id
|
INNER JOIN M_PRODUCT p ON (p.M_Product_ID=b.M_Product_ID)
|
||||||
) RETURNS NUMERIC AS
|
INNER JOIN PP_PRODUCT_BOMLINE bl ON (bl.PP_Product_BOM_ID=b.PP_Product_BOM_ID)
|
||||||
$$
|
WHERE b.M_Product_ID = Product_ID
|
||||||
DECLARE
|
LOOP
|
||||||
price NUMERIC; --used to store total sum
|
v_ProductPrice := Bompricestd (bom.M_ProductBOM_ID, PriceList_Version_ID);
|
||||||
productprice NUMERIC;
|
v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
|
||||||
boms RECORD;
|
-- DBMS_OUTPUT.PUT_LINE('Price=' || v_Price);
|
||||||
BEGIN
|
END LOOP; -- BOM
|
||||||
SELECT COALESCE(t.Pricestd, 0) INTO price FROM m_productprice as t
|
|
||||||
WHERE t.m_pricelist_version_id = $2 AND t.m_product_id = $1;
|
|
||||||
IF price = 0 THEN
|
|
||||||
FOR boms IN SELECT t.m_productbom_id, t.bomqty
|
|
||||||
FROM m_product_bom as t
|
|
||||||
WHERE t.m_product_id = $1 LOOP
|
|
||||||
productprice := bompricestd(boms.m_productbom_id, $2);
|
|
||||||
price := price + (boms.bomqty * productprice);
|
|
||||||
END LOOP;
|
|
||||||
END IF;
|
END IF;
|
||||||
return price;
|
--
|
||||||
END;
|
RETURN v_Price;
|
||||||
$$ LANGUAGE plpgsql STABLE STRICT;
|
END;
|
||||||
|
$BODY$
|
||||||
|
LANGUAGE 'plpgsql' STABLE STRICT
|
||||||
|
|
Loading…
Reference in New Issue