4 -- find the qty available..
5 CREATE OR REPLACE FUNCTION invfifo_unitcost_at_qty(integer, integer, numeric(18, 6))
10 i_itemsite_id ALIAS FOR $1;
11 i_location_id ALIAS FOR $2;
18 -- price at a specific qty.
20 invfifo_landedunitcost
27 invfifo_qty_after <= i_qty
29 invdetail_location_id = i_location_id
31 invhist_itemsite_id = i_itemsite_id
35 invhist_transtype = 'RP' -- purchases only!
50 LANGUAGE plpgsql VOLATILE
53 ALTER FUNCTION invfifo_unitcost_at_qty(integer, integer, numeric(18, 6))
56 -- find the qty available..
57 CREATE OR REPLACE FUNCTION invfifo_unitcost_at_date(integer, date)
58 RETURNS numeric(18, 6)
62 i_itemsite_id ALIAS FOR $1;
70 -- price at a specific qty.
72 invfifo_landedunitcost
79 invhist_transdate < i_date
81 invhist_itemsite_id = i_itemsite_id
83 invhist_transtype = 'RP' -- purchases only!
89 invhist_transdate DESC
100 -- not found, then try next purchase price..
103 invfifo_landedunitcost
110 invhist_transdate >= i_date
112 invhist_itemsite_id = i_itemsite_id
114 invhist_transtype = 'RP' -- purchases only!
120 invhist_transdate ASC
129 -- if we really can not find any purchases, then we should use the stdcost?
131 SELECT stdcost(itemsite_item_id) INTO v_ret FROM itemsite where itemsite_id = i_itemsite_id;
140 LANGUAGE plpgsql VOLATILE
143 ALTER FUNCTION invfifo_unitcost_at_date(integer, date)