DROP PROCEDURE OP_CTRLFUELALLUpdProc
GO
CREATE PROCEDURE OP_CTRLFUELALLUpdProc
(	
	@SITEID		UD_IDSITE,
	@DATEPROCE	UD_FECHA,
	@CORRNBR	INT
)
AS
BEGIN
	BEGIN TRAN


	DELETE FROM OP_CTRLFUELDET
	WHERE  SITEID=@SITEID AND DATEPROCE=@DATEPROCE	

	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Eliminando Registros'
		RETURN(1)
	END 


	INSERT 	INTO OP_CTRLFUELDET(SITEID,DATEPROCE,INVTIDSKU,STOCKINITIAL,QTYIMPUT,QTYOUTPUT,QTYSALES,QTYAVAIL,STKUINITID,VALUEUNIMED,QTYPHISICAL,QTYDIFFERENCE,PORCENTDIFERENCE,REMARK)
	SELECT  SITEID,DATEPROCE,INVTIDSKU,STOCKINITIAL,QTYIMPUT,QTYOUTPUT,QTYSALES,QTYAVAIL,STKUINITID,VALUEUNIMED,QTYPHISICAL,QTYDIFFERENCE,PORCENTDIFERENCE,REMARK
	FROM 	TMP_OP_CTRLFUELDET
	WHERE 	CORRNBR=@CORRNBR
	
	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Insentando Registros'
		RETURN(1)
	END 

	COMMIT TRAN
	RETURN(0)
END 

