-- modified to allow dates to be set..


-- Function: enterporeturn(integer, numeric, integer)

-- DROP FUNCTION enterporeturn(integer, numeric, integer);

CREATE OR REPLACE FUNCTION enterporeturn(integer, numeric, integer, date)
  RETURNS integer AS
$BODY$
-- Copyright (c) 1999-2011 by OpenMFG LLC, d/b/a xTuple. 
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
  pPoitemid ALIAS FOR $1;
  pQty ALIAS FOR $2;
  pRjctcodeid ALIAS FOR $3;
  v_reject_date ALIAS FOR $4;
  _porejectid INTEGER;

BEGIN

    SELECT NEXTVAL('poreject_poreject_id_seq') INTO _porejectid;

    INSERT INTO poreject
    (
        poreject_id, poreject_date,
        poreject_ponumber, poreject_poitem_id,
        
        poreject_trans_username, poreject_agent_username,
        poreject_itemsite_id, poreject_vend_id,
        
        poreject_vend_item_number, poreject_vend_item_descrip,
        poreject_vend_uom,   poreject_qty,
        
        poreject_rjctcode_id, poreject_posted,
        poreject_invoiced
    ) SELECT
            _porejectid, v_reject_date,
            pohead_number, poitem_id,
            
            getEffectiveXtUser(),         pohead_agent_username,
            poitem_itemsite_id,         pohead_vend_id,
            
            poitem_vend_item_number, poitem_vend_item_descrip,
            poitem_vend_uom, pQty,
            
            pRjctcodeid, FALSE,
            FALSE
        FROM
            pohead, poitem
        WHERE
            (
                (poitem_pohead_id=pohead_id)
            AND
                (poitem_id=pPoitemid)
            );

    RETURN _porejectid;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION enterporeturn(integer, numeric, integer, date)
  OWNER TO admin;
