DROP PROCEDURE CargaTMP_ControlTurnoProc
GO
CREATE PROCEDURE CargaTMP_ControlTurnoProc
(	@CORRNBR		INT,
	@SITEID		UD_IDSITE,
	@DATEPROCES	UD_FECHA,
	@NBRTUR	CHAR(1),
	@SALESPERID	UD_SALESPERSONID


)
AS
BEGIN
	BEGIN TRAN

	INSERT INTO TMP_OP_CTRLTURNDET(CORRNBR,SITEID,DATEPROCES,NBRTUR,SIDE,HOSENUMBER,INVTIDBARR,STARTREADING,ENDREADING,QTYSALES,QTYSERAF,QTYOTHER,TOTQTY)       
	SELECT @CORRNBR,@SITEID,@DATEPROCES,@NBRTUR,Cara,Manguera,INVTIDBARR,0 AS Inicial,0 as Final,0 as Venta,0 as Serafin,0 as Otros,0 as Total
        FROM VW_TURNOS_VENDEDOR 
        WHERE DATEPROCE=@DATEPROCES AND SITEID=@SITEID AND NUMBERTURN=@NBRTUR and SALESPERID=@SALESPERID

	IF(@@ERROR!=0 AND @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Insertando en TMP_OP_CTRLTURNDET'
		RETURN(1)
	END 

COMMIT TRAN
RETURN(0)

END 

