1 CREATE OR REPLACE FUNCTION itemCost(INTEGER) RETURNS NUMERIC STABLE AS $$
2 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
3 -- See www.xtuple.com/CPAL for the full text of the software license.
5 pItemsiteid ALIAS FOR $1;
8 SELECT CASE WHEN (itemsite_costmethod='A' AND itemsite_qtyonhand != 0.0) THEN (itemsite_value / itemsite_qtyonhand)
9 WHEN (itemsite_costmethod='A' AND itemsite_qtyonhand = 0.0) THEN 0.0
10 WHEN (itemsite_costmethod='N') THEN 0.0
11 ELSE stdCost(itemsite_item_id)
14 WHERE(itemsite_id=pItemsiteid);
17 $$ LANGUAGE 'plpgsql';