SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

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

CREATE PROCEDURE WPOSS_Articulo_GetGrid
	@descripcion  varchar(100),
	@Opcion varchar(50),
	@vEliminado BIT
AS
BEGIN

DECLARE @MensajeError VARCHAR(255) = ''

IF(@Opcion = 0)
BEGIN
	IF NOT EXISTS(select Desc_arti from RestArti where Desc_arti LIKE '%'+@descripcion+'%')
		BEGIN
			SET @MensajeError = 'ERR_POS_ART_EXI'
			--SET @MensajeError = 'Descripion No Existe'
			--descripcion no existe
			GOTO ERROR
		END

--select * from stokarti
	IF (@descripcion != '')
		BEGIN
				select top 300 id_arti,LTRIM(RTRIM(cod_arti)) codigo, LTRIM(RTRIM(Desc_arti))descripcion from RestArti
				where Desc_arti LIKE '%'+@descripcion+'%' and eliminado = 0
				ORDER BY codigo ASC
				
				--Select * From RestArti Order by cod_Arti
		END
END
ELSE
BEGIN
	IF NOT EXISTS(select LTRIM(RTRIM(cod_arti)) from RestArti where cod_arti LIKE '%'+@descripcion+'%')
		BEGIN
			SET @MensajeError = 'ERR_POS_ART_EXI'
			--SET @MensajeError = 'Descripion No Existe'
			--descripcion no existe
			GOTO ERROR
		END

--select * from stokarti
	IF (@descripcion != '')
		BEGIN
				select top 300 id_arti,LTRIM(RTRIM(cod_arti)) codigo, LTRIM(RTRIM(Desc_arti))descripcion from RestArti
				where cod_arti LIKE '%'+@descripcion+'%' and eliminado = 0
				ORDER BY codigo ASC
				
				--Select * From RestArti Order by cod_Arti
		END
END
	
	ERROR:
		RAISERROR (@MensajeError, 16, 1)
END
GO

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