2 -- run a whole itemsite
3 -- at present looks like the best way to update
8 -- alternative approaches.
10 --> PO 's value as is.
11 --> transfers ... push active location to the one
12 --> loop through find all sales of it.. (or transfer outs..)
21 CREATE OR REPLACE FUNCTION invfifo_update_from_invdetail_all_force(integer)
25 i_itemsite_id ALIAS FOR $1;
28 DELETE FROM invfifopos WHERE invfifopos_itemsite_id = i_itemsite_id ;
30 SELECT invfifo_update_from_invdetail_all(i_itemsite_id) INTO v_ret;
35 LANGUAGE plpgsql VOLATILE
38 ALTER FUNCTION invfifo_update_from_invdetail_all_force(integer)
42 DROP FUNCTION IF EXISTS invfifo_update_from_invdetail_all(integer);
44 CREATE OR REPLACE FUNCTION invfifo_update_from_invdetail_all(integer)
48 i_itemsite_id ALIAS FOR $1;
49 v_last_invdetail_id INTEGER;
50 v_last_checked_id INTEGER;
53 -- do we need to do this...
55 -- it basically check to see if the last run resulted in '0.0' adjustment.
56 -- if so, no need to run again..
59 COALESCE(max(invdetail_id),0)
65 invhist_itemsite_id = i_itemsite_id;
69 COALESCE(invfifopos_last_invdetail_id,0 )
75 invfifopos_itemsite_id= i_itemsite_id
77 invfifopos_lastadjustment = 0.0;
79 IF v_last_checked_id = v_last_invdetail_id OR v_last_invdetail_id = 0 THEN
80 RAISE NOTICE 'skipping - max tx matches last run';
84 -- the transfer out must appear before the transfer in..
85 -- the other way to handle this is to NOOP the transfer out
87 SELECT SUM(ABS(invfifo_update_from_invdetail(invdetail_id, false)))
95 invhist_itemsite_id = i_itemsite_id
99 -- real recieved stock first..
101 -- CASE WHEN invdetail_qty >0 and (invhist_transtype = 'RP' OR invhist_transtype = 'AD' OR invhist_transtype = 'RS' ) THEN 1
103 invhist_transdate ASC,
109 --- finall balancing occurs by running RL a few times??? with update on??
110 PERFORM invfifopos_update(
112 COALESCE( (SELECT max(invdetail_id) FROM invdetailview where invhist_itemsite_id = i_itemsite_id), 0),
119 LANGUAGE plpgsql VOLATILE
122 ALTER FUNCTION invfifo_update_from_invdetail_all(integer)