DROP PROCEDURE TMP_IN_INTRAITEMUpdProc
GO
CREATE PROCEDURE TMP_IN_INTRAITEMUpdProc
(
    @INVTIDSKU         	UD_IDCORPORATIVO,
    @SEQUENCE		SMALLINT,
    @QTY              	UD_STOCK,
    @COSTO        	UD_COSTO                    = NULL,
    @CORRNBR           	int,
    @CURYID		UD_CURYID)
AS
BEGIN
    BEGIN TRAN
     
      DECLARE @MONEDABASE CHAR(3)
      SET @MONEDABASE =(SELECT CURYORIG FROM SETUP)


    UPDATE TMP_IN_INTRAITEM
    SET 	SEQUENCE = @SEQUENCE,
           	QTY  = @QTY,
		STDCOSTPEN= CASE @CURYID
				WHEN @MONEDABASE THEN @COSTO
				ELSE STDCOSTPEN
				END,
		STDCOSTUSD= CASE @CURYID
				WHEN @MONEDABASE THEN STDCOSTUSD
				ELSE @COSTO
				END
	
    WHERE INVTIDSKU=@INVTIDSKU AND CORRNBR=@CORRNBR

    IF (@@error!=0)
    BEGIN
        RAISERROR  20001 'No se puede actualizar la tabla TMP_IN_INTRAITEM '
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

    RETURN(0)
END
