SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'WMAN_ConfiguracionUsuario_GetInfo') )
DROP PROCEDURE WMAN_ConfiguracionUsuario_GetInfo
GO

CREATE PROCEDURE WMAN_ConfiguracionUsuario_GetInfo
	@IdOperador  INT
AS
BEGIN

     IF NOT EXISTS (SELECT IdOperador FROM SECUCOUS WHERE IdOperador = @IdOperador)
     BEGIN
     
	   INSERT INTO SECUCOUS 
	   (
	       IdOperador, 
	       impresora,
	       impresora_cheq,
	       impresora_fact,
	       impresora_rec
	   )
	   VALUES
	   (
		  @IdOperador,
		  '',
		  '',
		  '',
		  ''
	   )
	   
     END

	SELECT IdOperador, 
	       impresora,
	       impresora_cheq,
	       impresora_fact,
	       impresora_rec
	FROM   SECUCOUS 
	WHERE  IdOperador = @IdOperador

	RETURN

END
GO

---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'WMAN_ConfiguracionUsuario_PutInfo') )
DROP PROCEDURE WMAN_ConfiguracionUsuario_PutInfo
GO

CREATE PROCEDURE WMAN_ConfiguracionUsuario_PutInfo
	@IdOperador INT,
	@impresora VARCHAR(500),
	@impresora_cheq VARCHAR(500),
	@impresora_fact VARCHAR(500),
	@impresora_rec VARCHAR(500)
AS
BEGIN
	DECLARE @MensajeError VARCHAR(255) = ''

	UPDATE SECUCOUS
	SET impresora = @impresora,
	    impresora_cheq = @impresora_cheq,
	    impresora_fact = @impresora_fact,
	    impresora_rec = @impresora_rec
	WHERE IdOperador = @IdOperador

	SELECT @IdOperador AS Id
	
	RETURN

	ERROR:
		RAISERROR (@MensajeError, 16, 1)

END
GO