SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_com_comision]')) DROP VIEW [dbo].[view_com_comision]
GO
CREATE  VIEW [view_com_comision] AS
SELECT 	[com_comision].[id] AS [id],
		[com_comision].[uid] AS [uid],
		[com_comision].[eid] AS [eid],
		[com_comision].[id_usuario_modifico] AS [id_usuario_modifico],
		[com_comision].[id_usuario_creo] AS [id_usuario_creo],
		[com_comision].[fechaModificacion] AS [fechaModificacion],
		[com_comision].[fechaCreacion] AS [fechaCreacion],
		[com_comision].[active] AS [active],
		[com_comision].[comision] AS [comision],
		[com_comision].[comision_codigo] AS [comision_codigo],
		[com_comision].[descuentoMaximo] AS [descuentoMaximo],
		[com_comision].[descuentoMinimo] AS [descuentoMinimo],
		[com_comision].[id_cargo] AS [id_cargo],
[seg_cargo].[cargo] as [seg_cargo_cargo],
[seg_cargo].[cargo_codigo] as [seg_cargo_cargo_codigo],
[seg_cargo].[esTecnico] as [seg_cargo_esTecnico],
[seg_cargo].[esComercial] as [seg_cargo_esComercial],
[seg_cargo].[esCoordinador] as [seg_cargo_esCoordinador],
[seg_cargo].[valorHora] as [seg_cargo_valorHora],
[seg_cargo].[esAdministrativo] as [seg_cargo_esAdministrativo],
		[com_comision].[id_subTipoCatalogo] AS [id_subTipoCatalogo],
		[com_comision].[costear] AS [costear],
		[com_comision].[nivelnegocio] AS [nivelnegocio],
		[com_comision].[porc_comision] AS [porc_comision],
		[com_comision].[id_condicion] AS [id_condicion],
[doc_condicion].[condicion] as [doc_condicion_condicion],
[doc_condicion].[condicion_codigo] as [doc_condicion_condicion_codigo],
[doc_condicion].[textoLibre] as [doc_condicion_textoLibre],
		[com_comision].[id_opcionCondicion] AS [id_opcionCondicion],
[doc_opcionCondicion].[opcionCondicion] as [doc_opcionCondicion_opcionCondicion],
[doc_opcionCondicion].[opcionCondicion_codigo] as [doc_opcionCondicion_opcionCondicion_codigo],
[doc_opcionCondicion].[id_condicion] as [doc_opcionCondicion_id_condicion],
		[com_comision].[id_zona] AS [id_zona],
[gen_zona].[zona] as [gen_zona_zona],
[gen_zona].[zona_codigo] as [gen_zona_zona_codigo],
[gen_zona].[tiempoDesplazamiento] as [gen_zona_tiempoDesplazamiento],
[gen_zona].[nivel] as [gen_zona_nivel],
[gen_zona].[id_zona] as [gen_zona_id_zona],
[gen_zona].[codigoExterno] as [gen_zona_codigoExterno],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [com_comision]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[com_comision].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[com_comision].[id_usuario_creo]
	INNER JOIN [seg_cargo] ON [seg_cargo].id=[com_comision].[id_cargo]
	INNER JOIN [doc_condicion] ON [doc_condicion].id=[com_comision].[id_condicion]
	INNER JOIN [doc_opcionCondicion] ON [doc_opcionCondicion].id=[com_comision].[id_opcionCondicion]
	INNER JOIN [gen_zona] ON [gen_zona].id=[com_comision].[id_zona]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [com_comision].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [com_comision].active=1
GO
