
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_cnt_configContrato]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_cnt_configContrato]
GO
CREATE PROCEDURE [reg_cnt_configContrato]
	@p_id INT
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[configContrato] AS [configContrato],
		[id_contratoEquipo] AS [id_contratoEquipo],
		[id_catalogo.tempario] AS [id_catalogo.tempario],
		[id_tercero_proveedor] AS [id_tercero_proveedor],
		[frecuencia] AS [frecuencia],
		[cadaN] AS [cadaN],
		[dia] AS [dia],
		[estrategia] AS [estrategia],
		[porTrabajo] AS [porTrabajo],
		[incluirMenores] AS [incluirMenores],
		[aproximarA] AS [aproximarA],
		[fecha_ff] AS [fecha_ff],
		[diaHabil] AS [diaHabil]
	FROM [cnt_configContrato]
	WHERE	(id = @p_id)

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_cnt_configContrato]')) DROP VIEW [dbo].[view_cnt_configContrato]
GO
CREATE  VIEW [view_cnt_configContrato] AS
SELECT 	[cnt_configContrato].[id] AS [id],
		[cnt_configContrato].[uid] AS [uid],
		[cnt_configContrato].[eid] AS [eid],
		[cnt_configContrato].[id_usuario_modifico] AS [id_usuario_modifico],
		[cnt_configContrato].[id_usuario_creo] AS [id_usuario_creo],
		[cnt_configContrato].[fechaModificacion] AS [fechaModificacion],
		[cnt_configContrato].[fechaCreacion] AS [fechaCreacion],
		[cnt_configContrato].[active] AS [active],
		[cnt_configContrato].[configContrato] AS [configContrato],
		[cnt_configContrato].[id_contratoEquipo] AS [id_contratoEquipo],
[cnt_contratoEquipo].[contratoEquipo] as [cnt_contratoEquipo_contratoEquipo],
[cnt_contratoEquipo].[contratoEquipo_codigo] as [cnt_contratoEquipo_contratoEquipo_codigo],
[cnt_contratoEquipo].[precioVisita] as [cnt_contratoEquipo_precioVisita],
[cnt_contratoEquipo].[precioServicio] as [cnt_contratoEquipo_precioServicio],
[cnt_contratoEquipo].[fecha_ff] as [cnt_contratoEquipo_fecha_ff],
[cnt_contratoEquipo].[promedio] as [cnt_contratoEquipo_promedio],
[cnt_contratoEquipo].[id_equipo] as [cnt_contratoEquipo_id_equipo],
[cnt_contratoEquipo].[id_contrato] as [cnt_contratoEquipo_id_contrato],
[cnt_contratoEquipo].[id_contratoDetalleVisita] as [cnt_contratoEquipo_id_contratoDetalleVisita],
		[cnt_configContrato].[id_catalogo.tempario] AS [id_catalogo.tempario],
[cat_catalogo.tempario].[catalogo.tempario] as [cat_catalogo.tempario_catalogo.tempario],
[cat_catalogo.tempario].[duracionEstimada] as [cat_catalogo.tempario_duracionEstimada],
[cat_catalogo.tempario].[enTaller] as [cat_catalogo.tempario_enTaller],
[cat_catalogo.tempario].[esCiclico] as [cat_catalogo.tempario_esCiclico],
[cat_catalogo.tempario].[detieneEquipos] as [cat_catalogo.tempario_detieneEquipos],
[cat_catalogo.tempario].[horasDetencion] as [cat_catalogo.tempario_horasDetencion],
[cat_catalogo.tempario].[periodoHoras] as [cat_catalogo.tempario_periodoHoras],
[cat_catalogo.tempario].[facturaTodo] as [cat_catalogo.tempario_facturaTodo],
[cat_catalogo.tempario].[periodoDias] as [cat_catalogo.tempario_periodoDias],
[cat_catalogo.tempario].[porcGarantia] as [cat_catalogo.tempario_porcGarantia],
[cat_catalogo.tempario].[porcTropicalizacion] as [cat_catalogo.tempario_porcTropicalizacion],
[cat_catalogo.tempario].[id_tipoServicio] as [cat_catalogo.tempario_id_tipoServicio],
[cat_catalogo.tempario].[proyectar] as [cat_catalogo.tempario_proyectar],
[cat_catalogo.tempario].[incluirMenores] as [cat_catalogo.tempario_incluirMenores],
[cat_catalogo.tempario].[modoAjuste] as [cat_catalogo.tempario_modoAjuste],
		[cat_catalogo_tempario].[catalogo_codigo] AS [cat_catalogo_tempario_catalogo_codigo],
		[cat_catalogo_tempario].[codigoInventario] AS [cat_catalogo_tempario_codigoInventario],
		[cat_catalogo_tempario].[precioVenta] AS [cat_catalogo_tempario_precioVenta],
		[cat_catalogo_tempario].[tiempoConsecucion] AS [cat_catalogo_tempario_tiempoConsecucion],
		[cat_catalogo_tempario].[esNacional] AS [cat_catalogo_tempario_esNacional],
		[cat_catalogo_tempario].[id_familia] AS [cat_catalogo_tempario_id_familia],
		[cat_catalogo_tempario].[id_subtipoCatalogo] AS [cat_catalogo_tempario_id_subtipoCatalogo],
		[cat_catalogo_tempario].[id_unidad] AS [cat_catalogo_tempario_id_unidad],
		[cat_catalogo_tempario].[id_impuesto] AS [cat_catalogo_tempario_id_impuesto],
		[cat_catalogo_tempario].[descripcion] AS [cat_catalogo_tempario_descripcion],
		[cat_catalogo_tempario].[bloquearCostear] AS [cat_catalogo_tempario_bloquearCostear],
		[cnt_configContrato].[id_tercero_proveedor] AS [id_tercero_proveedor],
[ter_tercero_proveedor].[tercero] as [ter_tercero_proveedor_tercero],
[ter_tercero_proveedor].[tercero_codigo] as [ter_tercero_proveedor_tercero_codigo],
[ter_tercero_proveedor].[tercero_nit] as [ter_tercero_proveedor_tercero_nit],
[ter_tercero_proveedor].[direccion] as [ter_tercero_proveedor_direccion],
[ter_tercero_proveedor].[contacto] as [ter_tercero_proveedor_contacto],
[ter_tercero_proveedor].[telefono] as [ter_tercero_proveedor_telefono],
[ter_tercero_proveedor].[fax] as [ter_tercero_proveedor_fax],
[ter_tercero_proveedor].[email] as [ter_tercero_proveedor_email],
[ter_tercero_proveedor].[website] as [ter_tercero_proveedor_website],
[ter_tercero_proveedor].[representante] as [ter_tercero_proveedor_representante],
[ter_tercero_proveedor].[notas] as [ter_tercero_proveedor_notas],
[ter_tercero_proveedor].[tercero_nombreCorto] as [ter_tercero_proveedor_tercero_nombreCorto],
[ter_tercero_proveedor].[esCliente] as [ter_tercero_proveedor_esCliente],
[ter_tercero_proveedor].[esProveedor] as [ter_tercero_proveedor_esProveedor],
[ter_tercero_proveedor].[esTransportador] as [ter_tercero_proveedor_esTransportador],
[ter_tercero_proveedor].[esFabricante] as [ter_tercero_proveedor_esFabricante],
[ter_tercero_proveedor].[esEmpresaPropia] as [ter_tercero_proveedor_esEmpresaPropia],
[ter_tercero_proveedor].[clasificacion] as [ter_tercero_proveedor_clasificacion],
[ter_tercero_proveedor].[id_zona] as [ter_tercero_proveedor_id_zona],
[ter_tercero_proveedor].[id_estadoTercero] as [ter_tercero_proveedor_id_estadoTercero],
[ter_tercero_proveedor].[id_naturalezaTercero] as [ter_tercero_proveedor_id_naturalezaTercero],
[ter_tercero_proveedor].[esProspecto] as [ter_tercero_proveedor_esProspecto],
		[cnt_configContrato].[frecuencia] AS [frecuencia],
		[cnt_configContrato].[cadaN] AS [cadaN],
		[cnt_configContrato].[dia] AS [dia],
		[cnt_configContrato].[estrategia] AS [estrategia],
		[cnt_configContrato].[porTrabajo] AS [porTrabajo],
		[cnt_configContrato].[incluirMenores] AS [incluirMenores],
		[cnt_configContrato].[aproximarA] AS [aproximarA],
		[cnt_configContrato].[fecha_ff] AS [fecha_ff],
		[cnt_configContrato].[diaHabil] AS [diaHabil],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [cnt_configContrato]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[cnt_configContrato].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[cnt_configContrato].[id_usuario_creo]
	INNER JOIN [cnt_contratoEquipo] ON [cnt_contratoEquipo].id=[cnt_configContrato].[id_contratoEquipo]
	INNER JOIN [cat_catalogo.tempario] ON [cat_catalogo.tempario].id=[cnt_configContrato].[id_catalogo.tempario]
	INNER JOIN [cat_catalogo] aS [cat_catalogo_tempario] ON [cat_catalogo.tempario].id = [cat_catalogo_tempario].id
	INNER JOIN [ter_tercero] AS [ter_tercero_proveedor] ON [ter_tercero_proveedor].id=[cnt_configContrato].[id_tercero_proveedor]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [cnt_configContrato].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [cnt_configContrato].active=1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXusuario_modifico]
GO
CREATE PROCEDURE [sel_cnt_configContratosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_cnt_configContrato]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXusuario_creo]
GO
CREATE PROCEDURE [sel_cnt_configContratosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_cnt_configContrato]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXcontratoEquipo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXcontratoEquipo]
GO
CREATE PROCEDURE [sel_cnt_configContratosXcontratoEquipo]
	@p_id_contratoEquipo INT
AS
BEGIN
	SELECT * 
	FROM [view_cnt_configContrato]
	WHERE ([id_contratoEquipo]= @p_id_contratoEquipo)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXcatalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXcatalogo_tempario]
GO
CREATE PROCEDURE [sel_cnt_configContratosXcatalogo_tempario]
	@p_id_catalogo_tempario INT
AS
BEGIN
	SELECT * 
	FROM [view_cnt_configContrato]
	WHERE ([id_catalogo.tempario]= @p_id_catalogo_tempario)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXtercero_proveedor]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXtercero_proveedor]
GO
CREATE PROCEDURE [sel_cnt_configContratosXtercero_proveedor]
	@p_id_tercero_proveedor INT
AS
BEGIN
	SELECT * 
	FROM [view_cnt_configContrato]
	WHERE ([id_tercero_proveedor]= @p_id_tercero_proveedor)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratos]
GO
CREATE PROCEDURE [sel_cnt_configContratos]
	
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_cnt_configContrato]
WHERE (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_cnt_configContratos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_cnt_configContratos]
GO
CREATE PROCEDURE [lis_cnt_configContratos]
	AS
BEGIN
	SELECT id AS id,
[configContrato] AS [cnt_configContrato]
	FROM [cnt_configContrato]
	WHERE active = 1
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_cnt_configContrato]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_cnt_configContrato]
GO
CREATE PROCEDURE [upd_cnt_configContrato]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_configContrato varchar(300) = null,
		@p_id_contratoEquipo int = null,
		@p_id_catalogo_tempario int = null,
		@p_id_tercero_proveedor int = null,
		@p_frecuencia int = null,
		@p_cadaN float = null,
		@p_dia int = null,
		@p_estrategia int = null,
		@p_porTrabajo bit = null,
		@p_incluirMenores bit = null,
		@p_aproximarA int = null,
		@p_fecha_ff smalldatetime = null,
		@p_diaHabil int = null
AS
BEGIN
		UPDATE [cnt_configContrato]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[configContrato] = isnull(@p_configContrato,[configContrato]),
			[id_contratoEquipo] = isnull(@p_id_contratoEquipo,[id_contratoEquipo]),
			[id_catalogo.tempario] = isnull(@p_id_catalogo_tempario,[id_catalogo.tempario]),
			[id_tercero_proveedor] = isnull(@p_id_tercero_proveedor,[id_tercero_proveedor]),
			[frecuencia] = isnull(@p_frecuencia,[frecuencia]),
			[cadaN] = isnull(@p_cadaN,[cadaN]),
			[dia] = isnull(@p_dia,[dia]),
			[estrategia] = isnull(@p_estrategia,[estrategia]),
			[porTrabajo] = isnull(@p_porTrabajo,[porTrabajo]),
			[incluirMenores] = isnull(@p_incluirMenores,[incluirMenores]),
			[aproximarA] = isnull(@p_aproximarA,[aproximarA]),
			[fecha_ff] = isnull(@p_fecha_ff,[fecha_ff]),
			[diaHabil] = isnull(@p_diaHabil,[diaHabil])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_cnt_configContrato]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_cnt_configContrato]
GO
CREATE PROCEDURE [ins_cnt_configContrato]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_configContrato varchar(300),
		@p_id_contratoEquipo int,
		@p_id_catalogo_tempario int,
		@p_id_tercero_proveedor int,
		@p_frecuencia int,
		@p_cadaN float,
		@p_dia int,
		@p_estrategia int,
		@p_porTrabajo bit,
		@p_incluirMenores bit,
		@p_aproximarA int,
		@p_fecha_ff smalldatetime,
		@p_diaHabil int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [cnt_configContrato]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[configContrato],
			[id_contratoEquipo],
			[id_catalogo.tempario],
			[id_tercero_proveedor],
			[frecuencia],
			[cadaN],
			[dia],
			[estrategia],
			[porTrabajo],
			[incluirMenores],
			[aproximarA],
			[fecha_ff],
			[diaHabil])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_configContrato,
			@p_id_contratoEquipo,
			@p_id_catalogo_tempario,
			@p_id_tercero_proveedor,
			@p_frecuencia,
			@p_cadaN,
			@p_dia,
			@p_estrategia,
			@p_porTrabajo,
			@p_incluirMenores,
			@p_aproximarA,
			@p_fecha_ff,
			@p_diaHabil)
		SET @v_id = scope_identity()
UPDATE [cnt_configContrato] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[act_cnt_configContrato]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_cnt_configContrato]
GO
CREATE PROCEDURE [act_cnt_configContrato]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [cnt_configContrato]
	SET active=@p_active,
	[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
	[fechaModificacion] = GETDATE()
	WHERE	(id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_cnt_configContrato_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_cnt_configContrato_m]
GO
CREATE PROCEDURE [reg_cnt_configContrato_m]
	@p_id INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[configContrato] AS [configContrato],
		[id_contratoEquipo] AS [id_contratoEquipo],
		[id_catalogo.tempario] AS [id_catalogo.tempario],
		[id_tercero_proveedor] AS [id_tercero_proveedor],
		[frecuencia] AS [frecuencia],
		[cadaN] AS [cadaN],
		[dia] AS [dia],
		[estrategia] AS [estrategia],
		[porTrabajo] AS [porTrabajo],
		[incluirMenores] AS [incluirMenores],
		[aproximarA] AS [aproximarA],
		[fecha_ff] AS [fecha_ff],
		[diaHabil] AS [diaHabil]
	FROM [cnt_configContrato]
	WHERE	(id = @p_id)
	AND	(eid LIKE @p_eid+'%')

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_cnt_configContratosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cnt_configContrato]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_cnt_configContratosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cnt_configContrato]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXcontratoEquipo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXcontratoEquipo_m]
GO
CREATE PROCEDURE [sel_cnt_configContratosXcontratoEquipo_m]
	@p_id_contratoEquipo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cnt_configContrato]
	WHERE ([id_contratoEquipo]= @p_id_contratoEquipo)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXcatalogo_tempario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXcatalogo_tempario_m]
GO
CREATE PROCEDURE [sel_cnt_configContratosXcatalogo_tempario_m]
	@p_id_catalogo_tempario INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cnt_configContrato]
	WHERE ([id_catalogo.tempario]= @p_id_catalogo_tempario)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratosXtercero_proveedor_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratosXtercero_proveedor_m]
GO
CREATE PROCEDURE [sel_cnt_configContratosXtercero_proveedor_m]
	@p_id_tercero_proveedor INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cnt_configContrato]
	WHERE ([id_tercero_proveedor]= @p_id_tercero_proveedor)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cnt_configContratos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cnt_configContratos_m]
GO
CREATE PROCEDURE [sel_cnt_configContratos_m]
	@p_eid as varchar (50)='',
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_cnt_configContrato]
WHERE  (eid like '''+@p_eid+'%'+''' ) AND (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_cnt_configContratos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_cnt_configContratos_m]
GO
CREATE PROCEDURE [lis_cnt_configContratos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[configContrato] AS [cnt_configContrato]
	FROM [cnt_configContrato]
	WHERE active = 1
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aud_cnt_configContrato]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_cnt_configContrato]
GO
CREATE PROCEDURE [aud_cnt_configContrato]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [cnt_configContrato].id as id_tabla,
	[cnt_configContrato].id_usuario_modifico as id_usuario_modifico,
	[cnt_configContrato].id_usuario_creo as id_usuario_creo,
	[cnt_configContrato].fechaModificacion as fechaModificacion,
	[cnt_configContrato].fechaCreacion as fechaCreacion,
	[cnt_configContrato].active as active,
	[cnt_configContrato].[configContrato] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [cnt_configContrato]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[cnt_configContrato].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[cnt_configContrato].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'cnt_configContrato'
-----------------------------------20/11/2019 14:28:36