2013-09-20 09:52:10 +07:00
|
|
|
CREATE OR REPLACE FUNCTION bompricestd (in product_id numeric, in pricelist_version_id numeric) RETURNS numeric AS
|
2008-10-30 08:54:12 +07:00
|
|
|
$BODY$
|
|
|
|
DECLARE
|
2013-09-20 09:52:10 +07:00
|
|
|
v_Price NUMERIC;
|
|
|
|
v_ProductPrice NUMERIC;
|
|
|
|
bom RECORD;
|
|
|
|
|
2008-10-30 08:54:12 +07:00
|
|
|
BEGIN
|
2013-09-20 09:52:10 +07:00
|
|
|
-- Try to get price from PriceList directly
|
2008-10-30 08:54:12 +07:00
|
|
|
SELECT COALESCE(SUM(PriceStd), 0)
|
|
|
|
INTO v_Price
|
2013-09-20 09:52:10 +07:00
|
|
|
FROM M_ProductPrice
|
2008-10-30 08:54:12 +07:00
|
|
|
WHERE M_PriceList_Version_ID=PriceList_Version_ID AND M_Product_ID=Product_ID;
|
2006-12-29 02:17:31 +07:00
|
|
|
|
2008-10-30 08:54:12 +07:00
|
|
|
-- No Price - Check if BOM
|
|
|
|
IF (v_Price = 0) THEN
|
2013-09-20 09:52:10 +07:00
|
|
|
FOR bom IN
|
|
|
|
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM
|
|
|
|
FROM M_Product_BOM b, M_Product p
|
|
|
|
WHERE b.M_ProductBOM_ID=p.M_Product_ID
|
|
|
|
AND b.M_Product_ID=Product_ID
|
2014-05-16 12:31:50 +07:00
|
|
|
AND b.M_ProductBOM_ID != Product_ID
|
2013-09-20 09:52:10 +07:00
|
|
|
AND p.IsBOM='Y'
|
|
|
|
AND p.IsVerified='Y'
|
2014-05-16 12:31:50 +07:00
|
|
|
AND b.IsActive='Y'
|
2008-10-30 08:54:12 +07:00
|
|
|
LOOP
|
2013-09-20 09:52:10 +07:00
|
|
|
v_ProductPrice := bomPriceStd (bom.M_ProductBOM_ID, PriceList_Version_ID);
|
2008-10-30 08:54:12 +07:00
|
|
|
v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
|
2013-09-20 09:52:10 +07:00
|
|
|
END LOOP;
|
2008-10-30 08:54:12 +07:00
|
|
|
END IF;
|
|
|
|
--
|
|
|
|
RETURN v_Price;
|
2013-09-20 09:52:10 +07:00
|
|
|
|
2008-10-30 08:54:12 +07:00
|
|
|
END;
|
2013-09-20 09:52:10 +07:00
|
|
|
|
2008-10-30 08:54:12 +07:00
|
|
|
$BODY$
|
2014-05-16 12:31:50 +07:00
|
|
|
LANGUAGE 'plpgsql' STABLE
|
2013-09-20 09:52:10 +07:00
|
|
|
;
|
|
|
|
|