
-- should not be needed anymore - is used to generate the intial data for invfifo


CREATE OR REPLACE FUNCTION invfifo_fill_all(integer, integer)
    RETURNS  boolean
AS $BODY$
DECLARE    
    i_location_id  ALIAS FOR $1;
    i_itemsite_id  ALIAS FOR $2;
 BEGIN   
     
    PERFORM  invfifo_fill(invdetail_id,true) FROM (
                    SELECT
                            invdetail_id
                        FROM
                            invdetailview
       
                        WHERE
                            invdetail_location_id = i_location_id
                            AND
                            invhist_itemsite_id = i_itemsite_id
                        ORDER BY
                            invhist_transdate ASC,
                            invdetail_id ASC
                        
                    ) x;
    RETURN true;
   END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
  
ALTER FUNCTION   invfifo_fill_all(integer, integer)
  OWNER TO admin;
          

CREATE OR REPLACE FUNCTION invfifo_fill_all_itemsite(i_itemsite_id integer)
    RETURNS  boolean
AS $BODY$
DECLARE    
    
 BEGIN   
     PERFORM  invfifo_fill_all(location_id,itemsite_id ) FROM (
        SELECT
                distinct(invdetail_location_id) as location_id ,
                i_itemsite_id as itemsite_id
            FROM
                invdetailview
            where
                invhist_itemsite_id = i_itemsite_id
    ) x;
    RETURN true;
   END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
  
ALTER FUNCTION   invfifo_fill_all(integer, integer)
  OWNER TO admin;
          