SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Actualizar (@pmTabla VARCHAR(50),@pmCampos VARCHAR(2000),@pmCriterio VARCHAR(1000))
AS

BEGIN
 Declare @pmQry VARCHAR(2000)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'UPDATE '+ @pmTabla+' SET ' + @pmCampos
 IF LEN(@pmCriterio)>0 
  BEGIN
   SET  @pmQry=@pmQry + ' WHERE ' + @pmCriterio
  END

EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Agregar (@pmTabla VARCHAR(50),@pmCampos VARCHAR(1000),@pmValores VARCHAR(2000))
AS

BEGIN
 Declare @pmQry VARCHAR(2000)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'INSERT INTO '+ @pmTabla+' '
 SET @pmQry=@pmQry + '('+ @pmCampos+') VALUES '
 SET @pmQry=@pmQry + '('+ @pmValores+')'
 EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Eliminar (@pmTabla VARCHAR(50),@pmCriterio VARCHAR(500))
AS

BEGIN
 Declare @pmQry VARCHAR(500)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'DELETE FROM '+ @pmTabla
 IF LEN(@pmCriterio)>0 
  BEGIN
   SET @pmQry=@pmQry +'  WHERE ' + @pmCriterio
  END

EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_InsertSelect  
(@pmDB VARCHAR(50),
@pmOwn VARCHAR(50),
@pmTabla VARCHAR(50),
@pmCampos VARCHAR(1000),
@pmQuery VARCHAR(2000))

AS

BEGIN
 Declare @pmQry VARCHAR(2500)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'INSERT INTO '+ @pmDB + '.'+ @pmOwn +'.'+@pmTabla
 SET @pmQry=@pmQry + ' ('+ @pmCampos+') '+ @pmQuery
 EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Query 
(@pmCampos VARCHAR(3500),
 @pmTabla VARCHAR(1500),
@pmCriterio VARCHAR(2000),
@pmOrden VARCHAR(200),
@pmGroup VARCHAR(500),
@pmHaving VARCHAR(100))

AS

BEGIN
 Declare @pmQry VARCHAR(7800)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'SELECT '+ @pmCampos + '  FROM ' + @pmTabla
 IF Len(@pmCriterio)>0
 BEGIN
  SET @pmQry=@pmQry + '  WHERE '+ @pmCriterio
 END
 IF Len(@pmGroup)>0 
 BEGIN
  SET @pmQry=@pmQry + ' GROUP BY ' + @pmGroup
 END
 IF Len(@pmHaving)>0 
 BEGIN
  SET @pmQry=@pmQry + ' HAVING '+ @pmHaving
 END
 IF Len(@pmOrden)>0 
 BEGIN
  SET @pmQry=@pmQry + ' ORDER BY '+ @pmOrden
 END
EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelAreas @pmIdArea VARCHAR(4)
 AS 
 DELETE FROM Areas
 WHERE IdArea=@pmIdArea

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelBancos @pmIdBanco VARCHAR(4)
 AS 
 DELETE FROM Bancos
 WHERE IdBanco=@pmIdBanco

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelCalndario @pmFechaDia SMALLDATETIME
 AS 
 DELETE FROM Calndario
 WHERE FechaDia=@pmFechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelCalndarioMes @pmMes INT,@pmAnno INT
 AS 
 DELETE FROM Calndario
 WHERE Month(FechaDia)=@pmMes AND Year(FechaDia)=@pmAnno

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelCargos @pmIdCargo VARCHAR(4)
 AS 
 DELETE FROM Cargos
 WHERE IdCargo=@pmIdCargo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelCentroCosto @pmIdCCosto VARCHAR(16)
 AS 
 DELETE FROM CentroCosto
 WHERE IdCCosto=@pmIdCCosto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelClaseBan @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseBan
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelClaseCta @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseCta
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelClaseFon @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseFon
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelClaseRie @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseRie
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelCnxextna @pmIdReg INT
 AS 
 DELETE FROM Sys_Cnxextna
 WHERE IdReg=@pmIdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelComDetalle @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT=Null
 AS 
 DELETE FROM Trn_ComDetalle
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelComFactura @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmIdProveedor VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia 
 AND IdProveedor=@pmIdProveedor   AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelComFacturaCmp @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItemCom INT=Null
AS
 DELETE FROM  Trn_ComFactura  
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia 
 AND (ItemCom>=ISNULL(@pmItemCom,0)  AND ItemCom<=ISNULL(@pmItemCom,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelComFacturaDoc @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFactura VARCHAR(15)
 AS 
 DELETE FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND  Factura LIKE ISNULL(@pmFactura,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE paDelCompanias @pmIdCia CHAR(2)
 AS 
 DELETE FROM Companias
 WHERE IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelComprobantes @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Comprobantes
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelCtasCorrientes @pmIdCta VARCHAR(4)
 AS 
 DELETE FROM CtasCorrientes
 WHERE IdCta=@pmIdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelDepartamentos @pmIdDep VARCHAR(8)
 AS 
 DELETE FROM Departamentos
 WHERE IdDep=@pmIdDep


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelDependencias @pmIdDep VARCHAR(4)
 AS 
 DELETE FROM Dependencias
 WHERE IdDep=@pmIdDep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelDiarios @pmIdDiario VARCHAR(4)
 AS 
 DELETE FROM Diarios
 WHERE IdDiario=@pmIdDiario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEgrFactura @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT=Null
 AS 
 DELETE FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

 

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEgrFacturaDoc @pmTipDev VARCHAR(3),@pmNumDev INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EgrFactura
 WHERE TipCom=@pmTipDev AND Comprobante=@pmNumDev AND IdCia=@pmIdCia
 AND TipDev=@pmTipDev AND NumDev=@pmNumDev AND EsEgreso=0


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEmp_Contrato @pmNContrato INT
 AS 
 DELETE FROM Emp_Contrato
 WHERE NContrato=@pmNContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEmp_Estudios @pmIdEmpleado VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Emp_Estudios
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEmp_ExpLaboral @pmIdEmpleado VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Emp_ExpLaboral
 WHERE IdEmpleado=@pmIdEmpleado
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEmp_Parientes @pmIdEmpleado VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Emp_Parientes
 WHERE IdEmpleado=@pmIdEmpleado   AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEmpleados @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEntidades @pmIdTabla VARCHAR(20)
 AS 
 DELETE FROM Sys_Entidades
 WHERE IdTabla=@pmIdTabla

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEstaciones @pmIdEstacion CHAR(2)
 AS 
 DELETE FROM Sys_Estaciones
 WHERE IdEstacion=@pmIdEstacion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEstadoCiv @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoCiv
 WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEstadoDoc @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoDoc
 WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelEstadoTer @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoTer
 WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelExpLicencias @pmIdLugar VARCHAR(8)
 AS 
 DELETE FROM ExpLicencias
 WHERE IdLugar=@pmIdLugar

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelFields @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20)=Null
 AS 
 DELETE FROM Sys_Fields
 WHERE IdEntidad=@pmIdEntidad AND IdCampo LIKE ISNULL(@pmIdCampo,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelFmtDoc @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2)
 AS 
 DELETE FROM Sys_FmtDoc
 WHERE IdDoc=@pmIdDoc AND IdForma LIKE ISNULL(@pmIdForma,'%%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelFondos @pmIdFondo VARCHAR(8)
 AS 
 DELETE FROM Fondos
 WHERE IdFondo=@pmIdFondo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelGruposAR @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM GruposAR
 WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelGruposObj @pmIdGrupo VARCHAR(6)
 AS 
 DELETE FROM Sys_GruposObj
 WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelGruposUsu @pmIdGrupo INT
 AS 
 DELETE FROM Sys_GruposUsu
 WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelInstalaciones @pmIdInstala VARCHAR(4)
 AS 
 DELETE FROM Instalaciones
 WHERE IdInstala=@pmIdInstala

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelJornadas @pmIdJornada VARCHAR(4)
 AS 
 DELETE FROM Jornadas
 WHERE IdJornada=@pmIdJornada

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelLocalidades @pmIdLocal VARCHAR(8)
 AS 
 DELETE FROM Localidades
 WHERE IdLocal=@pmIdLocal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelLog_Nomina @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8)
 AS 
 DELETE FROM Log_Nomina
 WHERE IdNom LIKE ISNULL(@pmIdNom,'%') AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelLog_Periodos @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Log_Periodos
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelModulos @pmIdMod VARCHAR(3)
 AS 
 DELETE FROM Sys_Modulos
 WHERE IdMod LIKE ISNULL(@pmIdMod,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAbonos @pmNPrestamo INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAbonosLiq @pmDscto VARCHAR(3),@pmNLiquida INT,@pmIdEmpleado VARCHAR(16)=Null
AS 
 DELETE FROM  Trn_NomAbonos
 WHERE Dscto=@pmDscto AND NLiquida=@pmNLiquida AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAbonosPer @pmIdPeriodo VARCHAR(8),@pmDscto VARCHAR(3),@pmIdEmpleado VARCHAR(16)=Null
AS 
 DELETE FROM  Trn_NomAbonos
 WHERE IdPeriodo=@pmIdPeriodo AND Dscto LIKE ISNULL(@pmDscto,'%')  
 AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAlqDet @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 DELETE FROM Trn_NomAlqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAlqNov @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 DELETE FROM Trn_NomAlqNov
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAlqTot @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 DELETE FROM Trn_NomAlqTot
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAportante @pmIdAportnte VARCHAR(16)
 AS 
 DELETE FROM NomAportante
 WHERE IdAportnte=@pmIdAportnte

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAstncia @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME
 AS 
 DELETE FROM Trn_NomAstncia
 WHERE IdEmpleado=@pmIdEmpleado AND FechaDia=ISNULL(@pmFechaDia,FechaDia)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomAutoliq @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20)=Null
 AS 
 DELETE FROM Trn_NomAutoliq
 WHERE TipoLiq=@pmTipoLiq AND Numero LIKE ISNULL(@pmNumero,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomCAdmon @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomCausalesRet @pmIdCausa VARCHAR(4)
 AS 
 DELETE FROM NomCausalesRet
 WHERE IdCausa=@pmIdCausa

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomCertf @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20)
 AS 
 DELETE FROM Trn_NomCertf
 WHERE IdEmpleado=@pmIdEmpleado AND NumCertf LIKE ISNULL(@pmNumCertf,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomConAuto @pmIdReg INT
 AS 
 DELETE FROM Trn_NomConAuto
 WHERE IdReg=@pmIdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomConCuentas @pmIdConcepto VARCHAR(4),@pmItem INT
 AS 
 DELETE FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomConOpciones @pmIdConcepto VARCHAR(4),@pmIdOpc INT
 AS 
 DELETE FROM NomConOpciones
 WHERE IdConcepto=@pmIdConcepto 
  AND (IdOpc>=ISNULL(@pmIdOpc,0)  AND IdOpc<=ISNULL(@pmIdOpc,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomConceptos @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM NomConceptos
 WHERE IdConcepto=@pmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomDefault @pmnAnno INT,@pmIdOpc VARCHAR(3)
 AS 
 DELETE FROM NomDefault
 WHERE nAnno=@pmnAnno AND IdOpc LIKE ISNULL(@pmIdOpc,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomDetalle @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmItem INT
 AS 
 DELETE FROM Trn_NomDetalle
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomDetalleEmp @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomDetalle 
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomDetallePer @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null,@pmEsRetiro BIT=Null
 AS 
 DELETE Trn_NomDetalle 
 FROM Trn_NomDetalle AS D INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdPeriodo=@pmIdPeriodo AND EsRetiro=@pmEsRetiro
 AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomFijos @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT
 AS 
 DELETE FROM Trn_NomFijos
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomLiqDet @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomLiquida @pmTipoLiq VARCHAR(3),@pmNumero INT
 AS 
 DELETE FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomLogVeh @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 DELETE FROM Trn_NomLogVeh
 WHERE IdEmpleado=@pmIdEmpleado AND NumReg=@pmNumReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomNov @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomNovCar @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 DELETE FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND OrigCargue='AUTO'
 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado ,'%')




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomNovedad @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomPrest @pmNPrestamo INT
 AS 
 DELETE FROM Trn_NomPrest
 WHERE NPrestamo=@pmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomProrrogas @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 DELETE FROM Trn_NomProrrogas
 WHERE IdEmpleado=@pmIdEmpleado
 AND (NumReg>=ISNULL(@pmNumReg,0)  AND NumReg<=ISNULL(@pmNumReg,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomRangosFsu @pmIdRango INT
 AS 
 DELETE FROM NomRangosFsu
 WHERE IdRango=@pmIdRango

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomRet @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomRetDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomRetDetEmp @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomRetEmp @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomSueldos @pmNumero INT,@pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomSueldos
 WHERE Numero=@pmNumero AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomTablaRet @pmnAnno INT,@pmnIntrvalo INT
 AS 
 DELETE FROM NomTablaRet
 WHERE nAnno=@pmnAnno 
 AND (nIntrvalo>=ISNULL(@pmnIntrvalo,0)  AND nIntrvalo<=ISNULL(@pmnIntrvalo,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomVac @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomVacDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomVacDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomVacDetEmp @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomVacDet
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomVacEmp @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomVehiculos @pmIdVehiculo VARCHAR(10)
 AS 
 DELETE FROM NomVehiculos
 WHERE IdVehiculo=@pmIdVehiculo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNomina @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)
 AS 
 DELETE FROM Trn_Nomina
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro like ISNULL(@pmKeyRegistro,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNominaEmp @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelNominaPer @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmEsRetiro BIT
 AS 
 DELETE FROM Trn_Nomina
 WHERE IdPeriodo=@pmIdPeriodo AND EsRetiro=@pmEsRetiro AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelObjetosApp @pmIdObj VARCHAR(10)
 AS 
 DELETE FROM Sys_ObjetosApp
 WHERE IdObj=@pmIdObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelOpciones @pmIdOpc VARCHAR(3)
 AS 
 DELETE FROM adm_Opciones
 WHERE IdOpc LIKE ISNULL(@pmIdOpc,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelPaises @pmIdPais VARCHAR(8)
 AS 
 DELETE FROM adm_Paises
 WHERE IdPais=@pmIdPais

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelPermisos @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null
 AS 
 DELETE FROM adm_Permisos
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelPermisosRoles @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null,@pmIdRole VARCHAR(3)=Null
 AS 
 DELETE FROM adm_PermisosRoles
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%')  AND IdRole LIKE ISNULL(@pmIdRole,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelProfesiones @pmIdProf VARCHAR(4)
 AS 
 DELETE FROM Profesiones
 WHERE IdProf=@pmIdProf

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelPuc @pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM Puc
 WHERE IdCuenta=@pmIdCuenta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelRegimenDian @pmIdRegimen VARCHAR(4)
 AS 
 DELETE FROM RegimenDian
 WHERE IdRegimen=@pmIdRegimen


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelRegistro @pmIdCia CHAR(2)
 AS 
 DELETE FROM adm_Registro
 WHERE IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelRelaciones @pmIdTabla VARCHAR(20),@pmTablaForanea VARCHAR(20)=Null,@pmCampoForaneo VARCHAR(20)=Null
 AS 
 DELETE FROM Sys_Relaciones
 WHERE IdTabla=@pmIdTabla AND TablaForanea LIKE ISNULL(@pmTablaForanea,'%')
  AND CampoForaneo LIKE ISNULL(@pmCampoForaneo,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelReport @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2)=Null
 AS 
 DELETE FROM Sys_Report
 WHERE TipoRep=@pmTipoRep AND IdRep LIKE ISNULL(@pmIdRep,'%%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelRoles @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3)=Null
 AS 
 DELETE FROM Sys_Roles
 WHERE IdObj=@pmIdObj AND IdRole LIKE ISNULL(@pmIdRole,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelSectoresEco @pmIdSector VARCHAR(8)
 AS 
 DELETE FROM SectoresEco
 WHERE IdSector=@pmIdSector

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelSecurity @pmIdLla INT
 AS 
 DELETE FROM Sys_Security
 WHERE IdLla=@pmIdLla

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelSubCentros @pmIdSubCos VARCHAR(16)
 AS 
 DELETE FROM SubCentros
 WHERE IdSubCos=@pmIdSubCos

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTerceros @pmIdTercero VARCHAR(16)
 AS 
 DELETE FROM Terceros
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposCom @pmIdCom VARCHAR(3)
 AS 
 DELETE FROM TiposCom
 WHERE IdCom=@pmIdCom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposComCons @pmIdCom VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 DELETE FROM TiposComCons
 WHERE IdCom=@pmIdCom AND IdCia LIKE ISNULL(@pmIdCia,'%%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposCon @pmIdTipCon VARCHAR(4)
 AS 
 DELETE FROM TiposCon
 WHERE IdTipCon=@pmIdTipCon

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposCot @pmIdCot VARCHAR(4)
 AS 
 DELETE FROM TiposCot
 WHERE IdCot=@pmIdCot

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposDoc @pmIdDoc VARCHAR(3)
 AS 
 DELETE FROM Sys_TiposDoc
 WHERE IdDoc=@pmIdDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposDocCons @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 DELETE FROM TiposDocCons
 WHERE IdDoc=@pmIdDoc AND IdCia LIKE ISNULL(@pmIdCia,'%%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposDocCue @pmIdDoc VARCHAR(3),@pmIdClase INT
 AS 
 DELETE FROM Sys_TiposDocCue
 WHERE IdDoc=@pmIdDoc  AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposNom @pmIdNom VARCHAR(4)
 AS 
 DELETE FROM TiposNom
 WHERE IdNom=@pmIdNom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelTiposNov @pmIdNov VARCHAR(4)
 AS 
 DELETE FROM TiposNov
 WHERE IdNov=@pmIdNov

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelUOpciones @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20)=Null
 AS 
 DELETE FROM adm_UOpciones
 WHERE IdUsuario=@pmIdUsuario AND NomOpcion LIKE ISNULL(@pmNomOpcion,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelUm @pmUndMed VARCHAR(10)
 AS 
 DELETE FROM Sys_Um
 WHERE UndMed=@pmUndMed

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelUsuarios @pmIdUsuario VARCHAR(11)
AS
BEGIN
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnUsuarios'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM adm_PermisosRoles WHERE IdUsuario=@pmIdUsuario
  DELETE FROM adm_Permisos WHERE IdUsuario=@pmIdUsuario 
  DELETE FROM  adm_UOpciones  WHERE  IdUsuario=@pmIdUsuario
  DELETE FROM adm_Usuarios WHERE IdUsuario=@pmIdUsuario
 COMMIT TRANSACTION  @TrnNombre
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDelmonedas @pmIdMneda VARCHAR(5)
 AS 
 DELETE FROM adm_monedas
 WHERE IdMneda=@pmIdMneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_Aportes @pmtmEst  VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
,@pmtmItem INT=Null
 AS 
 DELETE FROM tm_Aportes
 WHERE tmEst=@pmtmEst AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_AutTot @pmtmEst VARCHAR(5),@pmtmItem INT=Null
 AS 
 DELETE FROM tm_AutTot
 WHERE tmEst=@pmtmEst 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_Comp @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_Ingresos @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Ingresos  WHERE tmEst=@pmtmEst

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_Liquida @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_NomHoras
 AS 
 DELETE FROM tm_NomHoras

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_NomRes @pmtmNumero VARCHAR(5)
 AS 
 DELETE FROM tm_NomRes
 WHERE tmNumero=@pmtmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_Nomina @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_NominaApo @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq IN ('APORTE','PROVISION')
 AND tmItem>=1000  AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_NominaCon @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4),@pmtmClaseLiq VARCHAR(10)=Null
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdConcepto=@pmtmIdConcepto
 AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%') AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_NominaNom @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmNContto INT
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq<>'NOVEDAD'
 AND  tmIdEmpleado=@pmtmIdEmpleado  AND tmNContto=@pmtmNContto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paDeltm_Plasueldos @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30)
 AS 
 DELETE FROM tm_Plasueldos
 WHERE tmIdPeriodo LIKE ISNULL(@pmtmIdPeriodo,'%')
 AND tmKeyRegistro LIKE ISNULL(@pmtmKeyRegistro,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsAreas @pmIdArea VARCHAR(4),@pmArea VARCHAR(50),@pmJefeArea VARCHAR(50)
,@pmIdCCosto VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO Areas (IdArea,Area,JefeArea,IdCCosto,Inactivo)
 VALUES (@pmIdArea,@pmArea,@pmJefeArea,@pmIdCCosto,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsBancos @pmIdBanco VARCHAR(4),@pmBanco VARCHAR(50),@pmIdClase VARCHAR(4),@pmCodEntidad VARCHAR(20)
,@pmDireccion VARCHAR(50),@pmContacto VARCHAR(50),@pmComision DECIMAL(10,4),@pmInactivo BIT
 AS 
 INSERT INTO Bancos (IdBanco,Banco,IdClase,CodEntidad,Direccion,Contacto,Comision,Inactivo)
 VALUES (@pmIdBanco,@pmBanco,@pmIdClase,@pmCodEntidad,@pmDireccion,@pmContacto,@pmComision,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsCalndario @pmFechaDia SMALLDATETIME,@pmTipoFtvo VARCHAR(3)
 AS 
 INSERT INTO Calndario (FechaDia,TipoFtvo)
 VALUES (@pmFechaDia,@pmTipoFtvo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsCargos @pmIdCargo VARCHAR(4),@pmCargo VARCHAR(50),@pmFunciones VARCHAR(3000),@pmInactivo BIT
 AS 
 INSERT INTO Cargos (IdCargo,Cargo,Funciones,Inactivo)
 VALUES (@pmIdCargo,@pmCargo,@pmFunciones,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsCentroCosto @pmIdCCosto VARCHAR(16),@pmCCosto VARCHAR(100),@pmFechaAdd SMALLDATETIME
,@pmInactivo BIT
 AS 
 INSERT INTO CentroCosto (IdCCosto,CCosto,FechaAdd,Inactivo)
 VALUES (@pmIdCCosto,@pmCCosto,@pmFechaAdd,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsClaseBan @pmIdClase VARCHAR(4),@pmClaseBanco VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseBan (IdClase,ClaseBanco,Inactivo)
 VALUES (@pmIdClase,@pmClaseBanco,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsClaseCta @pmIdClase VARCHAR(4),@pmClaseCuenta VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseCta (IdClase,ClaseCuenta,Inactivo)
 VALUES (@pmIdClase,@pmClaseCuenta,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsClaseFon @pmIdClase VARCHAR(4),@pmClaseFondo VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseFon (IdClase,ClaseFondo,Inactivo)
 VALUES (@pmIdClase,@pmClaseFondo,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsClaseRie @pmIdClase VARCHAR(4),@pmClaseRiesgo VARCHAR(50),@pmTarifa DECIMAL(10,4),@pmInactivo BIT
 AS 
 INSERT INTO ClaseRie (IdClase,ClaseRiesgo,Tarifa,Inactivo)
 VALUES (@pmIdClase,@pmClaseRiesgo,@pmTarifa,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsCnxextna @pmIdReg INT,@pmCnxEngine VARCHAR(3),@pmCnxDso VARCHAR(250),@pmCnxDbname VARCHAR(50),@pmCnxAutentic VARCHAR(3)
,@pmCnxUid VARCHAR(50),@pmCnxPwd VARCHAR(50),@pmCnxOwner VARCHAR(20),@pmCnxObserv VARCHAR(250),@pmCnxTipo VARCHAR(10),@pmCnxPpties VARCHAR(250)
 AS 
 INSERT INTO Sys_Cnxextna (IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxPpties,CnxObserv)
 VALUES (@pmIdReg,@pmCnxTipo,@pmCnxEngine,@pmCnxDso,@pmCnxDbname,@pmCnxAutentic,@pmCnxUid,@pmCnxPwd,@pmCnxOwner,@pmCnxPpties,@pmCnxObserv)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsComDetalle @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmVehPropio BIT,@pmVrBase MONEY,@pmTarifaBase DECIMAL(10,4),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4),@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmReferncia VARCHAR(50)
,@pmNitDoc VARCHAR(16),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_ComDetalle (TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,IdSubCos,CodAgncia,Referncia,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmIdCuenta,@pmDetalle,@pmVrDebito,@pmVrCredito,@pmIdTercero,@pmIdVehiculo,@pmIdCCosto,@pmVehPropio,@pmVrBase,@pmTarifaBase,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmCodConce,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmCodCta,@pmNumCheque,@pmIntegrado,@pmTipoAplica,@pmConsolida,@pmCodCargo
,@pmNitOtros,@pmCodSubgpo,@pmCiuOrigen,@pmIdSubCos,@pmCodAgncia,@pmReferncia,@pmNitDoc ,@pmTipDocRef,@pmDocRef,@pmIdCiaRef,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsComFactura @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmItem INT,@pmIdProveedor VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecEmision SMALLDATETIME
,@pmFecVence SMALLDATETIME,@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmItemCom INT,@pmReferencia VARCHAR(50),@pmDetalle VARCHAR(100),@pmpVehiculo VARCHAR(10),@pmVehPropio BIT
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
 AS 
 INSERT INTO Trn_ComFactura (TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef)
 VALUES (@pmTipFac,@pmFactura,@pmIdCia,@pmItem,@pmIdProveedor,@pmIdCuenta,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmFecEmision,@pmFecVence,@pmVrFactura,@pmVrAbonado,@pmTipCom,@pmComprobante,@pmItemCom
,@pmReferencia,@pmDetalle,@pmpVehiculo,@pmVehPropio,@pmTipRef,@pmDocRef,@pmIdCiaRef)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE paInsCompanias @pmIdCia CHAR(2),@pmCompania VARCHAR(50),@pmDirInterface VARCHAR(255),@pmFechaActual SMALLDATETIME
,@pmPeriodoActual SMALLDATETIME,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdTercero VARCHAR(16)
,@pmCodSucsal VARCHAR(10),@pmDireccSuc VARCHAR(250),@pmTelefSuc VARCHAR(20),@pmFaxSuc VARCHAR(20),@pmIdLocal VARCHAR(8)
,@pmFechaAdd SMALLDATETIME,@pmInactivo BIT
 AS 
 INSERT INTO Companias (IdCia,Compania,DirInterface,FechaActual,PeriodoActual,IdCCosto,IdSubCos,IdTercero
,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,FechaAdd,Inactivo)
 VALUES (@pmIdCia,@pmCompania,@pmDirInterface,@pmFechaActual,@pmPeriodoActual,@pmIdCCosto,@pmIdSubCos,@pmIdTercero
,@pmCodSucsal,@pmDireccSuc,@pmTelefSuc,@pmFaxSuc,@pmIdLocal,@pmFechaAdd,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsComprobantes @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrTotal MONEY,@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmTipEgr VARCHAR(3),@pmNEgreso INT,@pmpVehiculo VARCHAR(10),@pmVehPropio BIT,@pmCedCondtor VARCHAR(16),@pmCodConce VARCHAR(4),@pmBeneficiario VARCHAR(150),@pmVrDivisa1 MONEY,@pmVrDivisa2 MONEY,@pmVrDivisa3 MONEY, @pmPermEditar BIT,@pmIntegrado BIT,@pmEsEgreso BIT,@pmAnticipo BIT,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmPropddes VARCHAR(50),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Comprobantes (TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,PermEditar,Integrado,EsEgreso,Anticipo,VrDivisa1,VrDivisa2,VrDivisa3,Observacion,IdEstado,Propddes,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmFecha,@pmIdTercero,@pmVrTotal,@pmIdCta,@pmEnEfectivo,@pmNumCheque,@pmFecCheque,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmAnulado,@pmNumDev,@pmFecDev,@pmTipEgr,@pmNEgreso,@pmpVehiculo,@pmVehPropio,@pmCedCondtor,@pmCodConce,@pmBeneficiario,@pmPermEditar,@pmIntegrado,@pmEsEgreso
,@pmAnticipo,@pmVrDivisa1,@pmVrDivisa2,@pmVrDivisa3,@pmObservacion,@pmIdEstado,@pmPropddes,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsCtasCorrientes @pmIdCta VARCHAR(4),@pmNumeroCta VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmConsCheques BIT,@pmRangoCons VARCHAR(20)
,@pmConsActual INT,@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmInactivo BIT,@pmIdCiaDef CHAR(2)
 AS 
 INSERT INTO CtasCorrientes (IdCta,NumeroCta,IdBanco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,IdCiaDef,Inactivo)
 VALUES (@pmIdCta,@pmNumeroCta,@pmIdBanco,@pmIdCuenta,@pmConsCheques,@pmRangoCons,@pmConsActual,@pmFormato,@pmTipoPapel,@pmOrientacion
,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmIdCiaDef,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsDepartamentos @pmIdDep VARCHAR(8),@pmDepartamento VARCHAR(50)
,@pmCodigo VARCHAR(4), @pmIdPais VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO Departamentos (IdDep,Departamento,Codigo,IdPais,Inactivo)
 VALUES (@pmIdDep,@pmDepartamento,@pmCodigo,@pmIdPais,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsDependencias @pmIdDep VARCHAR(4),@pmDependencia VARCHAR(50),@pmJefeDep VARCHAR(50),@pmIdArea VARCHAR(4)
,@pmTipRiesgo DECIMAL(10,4),@pmIdSubCos VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO Dependencias (IdDep,Dependencia,JefeDep,IdArea,IdSubCos,TipRiesgo,Inactivo)
 VALUES (@pmIdDep,@pmDependencia,@pmJefeDep,@pmIdArea,@pmIdSubCos,@pmTipRiesgo,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsDiarios @pmIdDiario VARCHAR(4),@pmDiario VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO Diarios (IdDiario,Diario,Inactivo)
 VALUES (@pmIdDiario,@pmDiario,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEgrFactura @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16)
,@pmIdCuenta VARCHAR(16),@pmVrAbono MONEY,@pmEsEgreso BIT,@pmItemCom INT,@pmpVehiculo VARCHAR(10),@pmVehPropio BIT,@pmTipDev VARCHAR(3),@pmNumDev INT,@pmDetAbono VARCHAR(100)
 AS 
 INSERT INTO Trn_EgrFactura (TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmIdProveedor,@pmIdCuenta,@pmVrAbono
,@pmEsEgreso,@pmItemCom,@pmpVehiculo,@pmVehPropio,@pmTipDev,@pmNumDev,@pmDetAbono)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEmp_Contrato @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmIndefinido BIT,@pmIdCargo VARCHAR(4),@pmIdJornada VARCHAR(4)
,@pmIdDep VARCHAR(4),@pmIdArea VARCHAR(4),@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCia CHAR(2),@pmIdNom VARCHAR(4),@pmTipoLiquida CHAR(1),@pmModPromdio CHAR(1),@pmVrSalario MONEY,@pmVrAuxTrans MONEY,@pmSalMinimo BIT,@pmSalIntegral BIT
,@pmFPnomina VARCHAR(10),@pmModoRet INT,@pmFecAfiSeg SMALLDATETIME,@pmATFinMes BIT,@pmSegFinMes BIT,@pmDenyPEN BIT,@pmDenyEPS BIT,@pmDenyARP BIT,@pmDenyCaj BIT,@pmDenyCes BIT,@pmDenyPri BIT,@pmDenyVac BIT,@pmDenyHex BIT,@pmBasePrest CHAR(2)
,@pmBaseSeg CHAR(2),@pmDchDotacion BIT,@pmDchCafeteria BIT,@pmReclmto VARCHAR(50),@pmNotas VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmIdClase VARCHAR(4),@pmTipoTrabj INT,@pmIdCot VARCHAR(4),@pmVrUpc MONEY,@pmIdGrupo VARCHAR(4)
,@pmDenyDcto BIT,@pmSubTipoCot VARCHAR(3),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Emp_Contrato (NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,IdCargo,IdJornada,IdDep,IdArea,IdInstala,IdCCosto,IdCia,IdNom,TipoLiquida,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS
,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,IdEstado,Inactivo,IdSubCos,IdClase,TipoTrabj,FecAdd,IdUsuario,IdCot,VrUpc,IdGrupo,DenyDcto,SubTipoCot)
 VALUES (@pmNContrato,@pmIdEmpleado,@pmIdTipCon,@pmFecIngreso,@pmFecVigencia,@pmFecRetiro,@pmIndefinido,@pmIdCargo,@pmIdJornada,@pmIdDep,@pmIdArea,@pmIdInstala,@pmIdCCosto,@pmIdCia,@pmIdNom,@pmTipoLiquida,@pmModPromdio,@pmVrSalario,@pmVrAuxTrans,@pmSalMinimo
,@pmSalIntegral,@pmFPnomina,@pmModoRet,@pmFecAfiSeg,@pmATFinMes,@pmSegFinMes,@pmDenyPEN,@pmDenyEPS,@pmDenyARP,@pmDenyCaj,@pmDenyCes,@pmDenyPri,@pmDenyVac,@pmDenyHex,@pmBasePrest,@pmBaseSeg,@pmDchDotacion,@pmDchCafeteria,@pmReclmto,@pmNotas
,@pmIdEstado,@pmInactivo,@pmIdSubCos,@pmIdClase,@pmTipoTrabj,@pmFecAdd,@pmIdUsuario,@pmIdCot,@pmVrUpc,@pmIdGrupo,@pmDenyDcto,@pmSubTipoCot)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEmp_Estudios @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEstblecmto VARCHAR(50)
,@pmTitulo VARCHAR(50),@pmFecha SMALLDATETIME
 AS 
 INSERT INTO Emp_Estudios (IdEmpleado,Item,Estblecmto,Titulo,Fecha)
 VALUES (@pmIdEmpleado,@pmItem,@pmEstblecmto,@pmTitulo,@pmFecha)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEmp_ExpLaboral @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEmpresa VARCHAR(50),@pmCargo VARCHAR(20)
,@pmFecInicio SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmDirEmpresa VARCHAR(100),@pmTelEmpresa VARCHAR(20)
 AS 
 INSERT INTO Emp_ExpLaboral (IdEmpleado,Item,Empresa,Cargo,FecInicio,FecRetiro,DirEmpresa,TelEmpresa)
 VALUES (@pmIdEmpleado,@pmItem,@pmEmpresa,@pmCargo,@pmFecInicio,@pmFecRetiro,@pmDirEmpresa,@pmTelEmpresa)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEmp_Parientes @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmParntsco VARCHAR(10),@pmNombre VARCHAR(50)
,@pmFecNacmto SMALLDATETIME,@pmUltGrado VARCHAR(20),@pmDirccion VARCHAR(100),@pmTelefno VARCHAR(20)
 AS 
 INSERT INTO Emp_Parientes (IdEmpleado,Item,Parntsco,Nombre,FecNacmto,UltGrado,Dirccion,Telefno)
 VALUES (@pmIdEmpleado,@pmItem,@pmParntsco,@pmNombre,@pmFecNacmto,@pmUltGrado,@pmDirccion,@pmTelefno)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEmpleados @pmIdEmpleado VARCHAR(16),@pmApellidos VARCHAR(80),@pmNombres VARCHAR(70),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmIdLugarCed VARCHAR(8),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmTelMovil VARCHAR(20),@pme_mail VARCHAR(100),@pmVvdaPropia BIT, @pmFecNacmto SMALLDATETIME,@pmLugarNacmto VARCHAR(30)
,@pmTipoSangre CHAR(2),@pmFactorRh CHAR(1),@pmSexo CHAR(1),@pmIdEstCivil VARCHAR(4),@pmNHijos INT,@pmLibMilitar VARCHAR(25),@pmClaseLib INT,@pmFechaLib SMALLDATETIME,@pmDistMil VARCHAR(10),@pmCertJudicial VARCHAR(25),@pmFecJudicial SMALLDATETIME,@pmVigJudicial SMALLDATETIME,@pmPasporte VARCHAR(25),@pmVigPaspte SMALLDATETIME,@pmLicencia VARCHAR(25),@pmIdLugar VARCHAR(8)
,@pmCatLicencia INT,@pmFecLicencia SMALLDATETIME,@pmVigLicencia SMALLDATETIME,@pmIdProf VARCHAR(4),@pmTallaCam CHAR(2),@pmTallaPan CHAR(2),@pmTallaZap CHAR(2),@pmUsaGafas BIT,@pmConyugue VARCHAR(50),@pmConyFecNac SMALLDATETIME,@pmConyTrabaja BIT,@pmConyEmpresa VARCHAR(50),@pmConyCargo VARCHAR(20),@pmConyFing SMALLDATETIME,@pmConyTel VARCHAR(20),@pmIdFonPen VARCHAR(8)
,@pmIdFonEps VARCHAR(8),@pmIdFonArp VARCHAR(8),@pmIdFonCes VARCHAR(8),@pmIdCajaCom VARCHAR(8),@pmCdFonAvp VARCHAR(8),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(25),@pmIdBanco VARCHAR(4),@pmNContrato INT,@pmFecVincula SMALLDATETIME,@pmFecUltAum SMALLDATETIME,@pmFecUltCes SMALLDATETIME,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME,@pmFecUltDot SMALLDATETIME
,@pmFecUltExm SMALLDATETIME,@pmFecUltCap SMALLDATETIME,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME,@pmFecRetAnt SMALLDATETIME,@pmFotoEmp VARCHAR(30),@pmFotoLic VARCHAR(30),@pmFotoFirma VARCHAR(30),@pmEsCondtor BIT,@pmpVehiculo VARCHAR(10),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCdLocCue VARCHAR(8),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Empleados (IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen
,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,IdClase,NumCuenta,IdBanco,NContrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FotoEmp,FotoLic,FotoFirma,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,Observacion,CdFonAvp,IdEstado,Inactivo,CdLocCue,FechaAdd,IdUsuario)
 VALUES (@pmIdEmpleado,@pmApellidos,@pmNombres,@pmCodigo,@pmTipoId,@pmDv,@pmIdLugarCed,@pmDireccion,@pmIdLocal,@pmTelefono,@pmTelMovil,@pme_mail,@pmVvdaPropia,@pmFecNacmto,@pmLugarNacmto,@pmTipoSangre,@pmFactorRh,@pmSexo,@pmIdEstCivil,@pmNHijos,@pmLibMilitar,@pmClaseLib,@pmFechaLib,@pmDistMil,@pmCertJudicial,@pmFecJudicial,@pmVigJudicial,@pmPasporte,@pmVigPaspte,@pmLicencia,@pmIdLugar,@pmCatLicencia,@pmFecLicencia,@pmVigLicencia
,@pmIdProf,@pmTallaCam,@pmTallaPan,@pmTallaZap,@pmUsaGafas,@pmConyugue,@pmConyFecNac,@pmConyTrabaja,@pmConyEmpresa,@pmConyCargo,@pmConyFing,@pmConyTel,@pmIdFonPen,@pmIdFonEps,@pmIdFonArp,@pmIdFonCes,@pmIdCajaCom,@pmIdClase,@pmNumCuenta,@pmIdBanco,@pmNContrato,@pmFecVincula,@pmFecUltAum,@pmFecUltCes,@pmFecUltPri,@pmFecUltVac,@pmFecUltIng,@pmFecUltRet,@pmFecUltDot,@pmFecUltExm,@pmFecUltCap,@pmFotoEmp,@pmFotoLic
,@pmFotoFirma,@pmNCAnterior,@pmFecIngAnt,@pmFecRetAnt,@pmEsCondtor,@pmpVehiculo,@pmObservacion,@pmCdFonAvp,@pmIdEstado,@pmInactivo,@pmCdLocCue,@pmFechaAdd,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEmpleados_Sel @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16),@pmNewCodigo VARCHAR(16)
,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Empleados (IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen
,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,IdClase,NumCuenta,IdBanco,NContrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FotoEmp,FotoLic,FotoFirma,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,Observacion,IdEstado,CdFonAvp,Inactivo,CdLocCue,FechaAdd,IdUsuario)
 SELECT  @pmNewCedula,Apellidos,Nombres,@pmNewCodigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen
,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,IdClase,NumCuenta,IdBanco,NContrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FotoEmp,FotoLic,FotoFirma,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,Observacion,IdEstado,CdFonAvp,Inactivo,CdLocCue,@pmFechaAdd,@pmIdUsuario
 FROM   Empleados WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEntidades @pmIdTabla VARCHAR(20),@pmNivelRel INT,@pmCamposPK VARCHAR(50),@pmFngKey BIT
,@pmSp_Qry VARCHAR(30),@pmSp_Qpmt VARCHAR(50),@pmSp_Ins VARCHAR(30),@pmSp_Upd VARCHAR(30),@pmSp_Del VARCHAR(30)
 AS 
 INSERT INTO Sys_Entidades (IdTabla,NivelRel,CamposPK,FngKey,Sp_Qry,Sp_Qpmt,Sp_Ins,Sp_Upd,Sp_Del)
 VALUES (@pmIdTabla,@pmNivelRel,@pmCamposPK,@pmFngKey,@pmSp_Qry,@pmSp_Qpmt,@pmSp_Ins,@pmSp_Upd,@pmSp_Del)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEstaciones @pmIdEstacion CHAR(2),@pmEstacion VARCHAR(50)
 AS 
 INSERT INTO Sys_Estaciones (IdEstacion,Estacion)
 VALUES (@pmIdEstacion,@pmEstacion)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEstadoCiv @pmIdEstado VARCHAR(4),@pmEstCivil VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO EstadoCiv (IdEstado,EstCivil,Inactivo)
 VALUES (@pmIdEstado,@pmEstCivil,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEstadoDoc @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT
,@pmCodDcmto VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO EstadoDoc (IdEstado,Estado,NColor,CodDcmto,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmCodDcmto,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsEstadoTer @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoTer (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsExpLicencias @pmIdLugar VARCHAR(8),@pmLugarLic VARCHAR(50),@pmCodDpto VARCHAR(8)
,@pmDpto VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ExpLicencias (IdLugar,LugarLic,CodDpto,Dpto,Inactivo)
 VALUES (@pmIdLugar,@pmLugarLic,@pmCodDpto,@pmDpto,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsFields @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20),@pmDescripcion VARCHAR(50),@pmTipoDato VARCHAR(15),@pmLongMax INT,@pmRequerido BIT,@pmPmryKey BIT
,@pmFmtValue VARCHAR(20),@pmDftValue VARCHAR(20),@pmAliasFld VARCHAR(20),@pmAliasQry2 VARCHAR(20),@pmIndField INT,@pmTipoEntidad VARCHAR(5),@pmLstTipo VARCHAR(5),@pmLstClnaValor VARCHAR(20)
,@pmLstClnaLista VARCHAR(50),@pmLstQuery VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO Sys_Fields (IdEntidad,IdCampo,Descripcion,TipoDato,LongMax,Requerido,PmryKey,FmtValue,DftValue,AliasFld,AliasQry2,IndField,TipoEntidad,LstTipo,LstClnaValor,LstClnaLista,LstQuery,Inactivo)
 VALUES (@pmIdEntidad,@pmIdCampo,@pmDescripcion,@pmTipoDato,@pmLongMax,@pmRequerido,@pmPmryKey,@pmFmtValue,@pmDftValue,@pmAliasFld,@pmAliasQry2,@pmIndField,@pmTipoEntidad
,@pmLstTipo,@pmLstClnaValor,@pmLstClnaLista,@pmLstQuery,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsFmtDoc @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmPredtmnado BIT,@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT
,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 INSERT INTO Sys_FmtDoc (IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location)
 VALUES (@pmIdDoc,@pmIdForma,@pmDescripcion,@pmFormato,@pmPredtmnado,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmsp_Nombre,@pmInd_Location)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsFondos @pmIdFondo VARCHAR(8),@pmFondo VARCHAR(100),@pmIdClase VARCHAR(4)
,@pmIdTercero VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO Fondos (IdFondo,Fondo,IdClase,IdTercero,Inactivo)
 VALUES (@pmIdFondo,@pmFondo,@pmIdClase,@pmIdTercero,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsGruposAR @pmIdGrupo VARCHAR(4),@pmAltoRiesgo VARCHAR(50),@pmTarfaTrab DECIMAL(10,4),@pmTarfaEmp DECIMAL(10,4),@pmInactivo BIT
 AS 
 INSERT INTO GruposAR (IdGrupo,AltoRiesgo,TarfaTrab,TarfaEmp,Inactivo)
 VALUES (@pmIdGrupo,@pmAltoRiesgo,@pmTarfaTrab,@pmTarfaEmp,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsGruposObj @pmIdGrupo VARCHAR(6),@pmGrupoObjeto VARCHAR(50),@pmnModulo VARCHAR(10)
 AS 
 INSERT INTO Sys_GruposObj (IdGrupo,GrupoObjeto,nModulo)
 VALUES (@pmIdGrupo,@pmGrupoObjeto,@pmnModulo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsGruposUsu @pmIdGrupo INT,@pmGrupo VARCHAR(50),@pmDescripcion VARCHAR(100)
 AS 
 INSERT INTO Sys_GruposUsu (IdGrupo,Grupo,Descripcion)
 VALUES (@pmIdGrupo,@pmGrupo,@pmDescripcion)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsInstalaciones @pmIdInstala VARCHAR(4),@pmInstlacion VARCHAR(50),@pmDirInstala VARCHAR(100)
,@pmCodCiu VARCHAR(8),@pmCodCia CHAR(2),@pmIdClase VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO Instalaciones (IdInstala,Instlacion,DirInstala,CodCia,CodCiu,IdClase,Inactivo)
 VALUES (@pmIdInstala,@pmInstlacion,@pmDirInstala,@pmCodCia,@pmCodCiu,@pmIdClase,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsJornadas @pmIdJornada VARCHAR(4),@pmJornada VARCHAR(50),@pmHorasDia INT
,@pmRangos VARCHAR(25),@pmInactivo BIT
 AS 
 INSERT INTO Jornadas (IdJornada,Jornada,HorasDia,Rangos,Inactivo)
 VALUES (@pmIdJornada,@pmJornada,@pmHorasDia,@pmRangos,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsLocalidades @pmIdLocal VARCHAR(8),@pmLocalidad VARCHAR(50),@pmIdDep VARCHAR(8),@pmTipLocal VARCHAR(20),@pmDist_Kmt DECIMAL(10,4)
,@pmTime_hh VARCHAR(8),@pmCelRow DECIMAL(14,4),@pmCelCol DECIMAL(14,4),@pmInactivo BIT,@pmDistSede DECIMAL(10,4),@pmTimeSede VARCHAR(8),@pmCodAlias VARCHAR(10)
 AS 
 INSERT INTO Localidades (IdLocal,Localidad,IdDep,TipLocal,Dist_Kmt,Time_hh,CelRow,CelCol,DistSede,TimeSede,CodAlias,Inactivo)
 VALUES (@pmIdLocal,@pmLocalidad,@pmIdDep,@pmTipLocal,@pmDist_Kmt,@pmTime_hh,@pmCelRow,@pmCelCol,@pmDistSede,@pmTimeSede,@pmCodAlias,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsLog_Nomina @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmCerrado BIT
,@pmIntCtaCte BIT,@pmLogCtaCte VARCHAR(100)
 AS 
 INSERT INTO Log_Nomina (IdNom,IdPeriodo,Cerrado,IntCtaCte,LogCtaCte)
 VALUES (@pmIdNom,@pmIdPeriodo,@pmCerrado,@pmIntCtaCte,@pmLogCtaCte)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsLog_Periodos @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO Log_Periodos (Anno,IdCia,Ene,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic,CierreAnno)
 VALUES (@pmAnno,@pmIdCia,0,0,0,0,0,0,0,0,0,0,0,0,0)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsModulos @pmIdMod VARCHAR(3),@pmConsecutivo INT,@pmDescripcion VARCHAR(50)
,@pmValor BIT,@pmnModulo VARCHAR(10)
 AS 
 INSERT INTO Sys_Modulos (IdMod,Consecutivo,Descripcion,Valor,nModulo)
 VALUES (@pmIdMod,@pmConsecutivo,@pmDescripcion,@pmValor,@pmnModulo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAbonos @pmNPrestamo INT,@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmFechaAbo SMALLDATETIME
,@pmVrAbono MONEY,@pmnCuotas INT,@pmIdPeriodo VARCHAR(8),@pmDscto VARCHAR(3),@pmDetalle VARCHAR(50),@pmNLiquida INT
 AS 
 INSERT INTO Trn_NomAbonos (NPrestamo,Item,IdEmpleado,FechaAbo,VrAbono,nCuotas,IdPeriodo,Dscto,Detalle,NLiquida)
 VALUES (@pmNPrestamo,@pmItem,@pmIdEmpleado,@pmFechaAbo,@pmVrAbono,@pmnCuotas,@pmIdPeriodo,@pmDscto,@pmDetalle,@pmNLiquida)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAlqDet @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmApellido1 VARCHAR(50),@pmApellido2 VARCHAR(50),@pmNombre1 VARCHAR(50),@pmNombre2 VARCHAR(50),@pmIdFonPen VARCHAR(8),@pmIdFonSal VARCHAR(8),@pmIdFonRie VARCHAR(8),@pmIdCajCom VARCHAR(8),@pmSalBasico MONEY
,@pmVrIBCPen MONEY,@pmDiasPen DECIMAL(10,4),@pmTarifPen DECIMAL(10,4),@pmVrPension MONEY,@pmVrApoFsp MONEY,@pmVrApoFsu MONEY,@pmVrApoVolAfi MONEY,@pmVrApoVolApt MONEY,@pmVrNoReten MONEY,@pmVrIBCSal MONEY,@pmDiasSal DECIMAL(10,4),@pmTarifSal DECIMAL(10,4),@pmVrSalud MONEY,@pmVrUpc MONEY,@pmVrIncap MONEY,@pmVrLicencia MONEY,@pmNumAutInc VARCHAR(30)
,@pmNumAutLic VARCHAR(30),@pmVrIBCRie MONEY,@pmDiasRie DECIMAL(10,4),@pmTarifRie DECIMAL(10,4),@pmVrRiesgos MONEY,@pmVrIncIrp MONEY,@pmNumAutIrp VARCHAR(30),@pmIdInstala VARCHAR(4),@pmVrIBCRef MONEY,@pmVrIBCCajas MONEY,@pmDiasCom DECIMAL(10,4),@pmTarifCom DECIMAL(10,4),@pmVrCajas MONEY,@pmTarifSen DECIMAL(10,4),@pmVrSena MONEY,@pmTarifIcb DECIMAL(10,4),@pmVrICBF MONEY
,@pmTarifEsap DECIMAL(10,4),@pmVrESAP MONEY,@pmTarifEdu DECIMAL(10,4),@pmVrMinEdu MONEY,@pmTarifFsp DECIMAL(10,4),@pmTarifFsu DECIMAL(10,4),@pmCdFonAvp VARCHAR(8)
 AS 
 INSERT INTO Trn_NomAlqDet (TipoLiq,Numero,Item,IdEmpleado,NContrato,Apellido1,Apellido2,Nombre1,Nombre2,IdFonPen,IdFonSal,IdFonRie,IdCajCom,SalBasico,VrIBCPen,DiasPen,TarifPen,VrPension,VrApoFsp,VrApoFsu,VrApoVolAfi,VrApoVolApt,VrNoReten,VrIBCSal,DiasSal,TarifSal,VrSalud,VrUpc,VrIncap,VrLicencia,NumAutInc,NumAutLic,VrIBCRie,DiasRie,TarifRie,VrRiesgos,VrIncIrp,NumAutIrp,IdInstala,VrIBCRef,VrIBCCajas,DiasCom,TarifCom,VrCajas
,TarifSen,VrSena,TarifIcb,VrICBF,TarifEsap,VrESAP,TarifEdu,VrMinEdu,TarifFsp,TarifFsu,CdFonAvp)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmIdEmpleado,@pmNContrato,@pmApellido1,@pmApellido2,@pmNombre1,@pmNombre2,@pmIdFonPen,@pmIdFonSal,@pmIdFonRie,@pmIdCajCom,@pmSalBasico,@pmVrIBCPen,@pmDiasPen,@pmTarifPen,@pmVrPension,@pmVrApoFsp,@pmVrApoFsu,@pmVrApoVolAfi,@pmVrApoVolApt,@pmVrNoReten,@pmVrIBCSal,@pmDiasSal,@pmTarifSal,@pmVrSalud,@pmVrUpc,@pmVrIncap,@pmVrLicencia
,@pmNumAutInc,@pmNumAutLic,@pmVrIBCRie,@pmDiasRie,@pmTarifRie,@pmVrRiesgos,@pmVrIncIrp,@pmNumAutIrp,@pmIdInstala,@pmVrIBCRef,@pmVrIBCCajas,@pmDiasCom,@pmTarifCom,@pmVrCajas,@pmTarifSen,@pmVrSena,@pmTarifIcb,@pmVrICBF,@pmTarifEsap,@pmVrESAP,@pmTarifEdu,@pmVrMinEdu,@pmTarifFsp,@pmTarifFsu,@pmCdFonAvp)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAlqNov @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNovIng INT,@pmNovRet INT,@pmNovTde INT,@pmNovTae INT,@pmNovTdp INT,@pmNovTap INT
,@pmNovVsp INT,@pmNovVte INT,@pmNovVst INT,@pmNovSln INT,@pmNovIge INT,@pmNovLma INT,@pmNovVac INT,@pmNovAvp INT,@pmNovVct INT,@pmNovIrp INT,@pmCodNewPen VARCHAR(8),@pmCodNewSal VARCHAR(8),@pmCodNewIns VARCHAR(4)
,@pmCodNewRie VARCHAR(4),@pmCodNewGru VARCHAR(4),@pmDiasNov INT
 AS 
 INSERT INTO Trn_NomAlqNov (TipoLiq,Numero,Item,IdEmpleado,NovIng,NovRet,NovTde,NovTae,NovTdp,NovTap,NovVsp,NovVte,NovVst,NovSln,NovIge,NovLma,NovVac,NovAvp,NovVct,NovIrp,CodNewPen,CodNewSal,CodNewIns,CodNewRie,CodNewGru,DiasNov)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmIdEmpleado,@pmNovIng,@pmNovRet,@pmNovTde,@pmNovTae,@pmNovTdp,@pmNovTap,@pmNovVsp,@pmNovVte,@pmNovVst,@pmNovSln,@pmNovIge,@pmNovLma,@pmNovVac,@pmNovAvp,@pmNovVct
,@pmNovIrp,@pmCodNewPen,@pmCodNewSal,@pmCodNewIns,@pmCodNewRie,@pmCodNewGru,@pmDiasNov)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAlqTot @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmTipAdm VARCHAR(3),@pmIdFondo VARCHAR(8),@pmCodTipoApo CHAR(2),@pmVrTotalCot MONEY,@pmVrTotalFsp MONEY,@pmVrTotalFsu MONEY
,@pmVrTotalAva MONEY,@pmVrTotalAve MONEY,@pmVrTotalUpc MONEY,@pmVrTotalLic MONEY,@pmVrTotalInc MONEY,@pmVrTotalOtr MONEY,@pmDiasMora INT,@pmTarifMora DECIMAL(10,4),@pmVrIntMora MONEY,@pmVrIMoraOtr MONEY,@pmVrTotalSAF MONEY
,@pmVrSAFUpc MONEY,@pmVrTotalPagar MONEY,@pmVrTotalFon MONEY,@pmTotalAfi INT,@pmNumAutLic VARCHAR(30),@pmNumAutInc VARCHAR(30),@pmNumPlaSAF VARCHAR(20),@pmTipoReg INT
 AS 
 INSERT INTO Trn_NomAlqTot (TipoLiq,Numero,Item,TipAdm,IdFondo,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF,TipoReg)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmTipAdm,@pmIdFondo,@pmCodTipoApo,@pmVrTotalCot,@pmVrTotalFsp,@pmVrTotalFsu,@pmVrTotalAva,@pmVrTotalAve,@pmVrTotalUpc,@pmVrTotalLic,@pmVrTotalInc,@pmVrTotalOtr,@pmDiasMora,@pmTarifMora,@pmVrIntMora,@pmVrIMoraOtr,@pmVrTotalSAF
,@pmVrSAFUpc,@pmVrTotalPagar,@pmVrTotalFon,@pmTotalAfi,@pmNumAutLic,@pmNumAutInc,@pmNumPlaSAF,@pmTipoReg)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAportante @pmIdAportnte VARCHAR(16),@pmRazonSocial VARCHAR(200),@pmTipoId CHAR(1),@pmDvNit CHAR(1),@pmIdRepLegal VARCHAR(16),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pme_mail VARCHAR(100)
,@pmClaseApo CHAR(1),@pmTipoEco CHAR(1),@pmTipoPersna CHAR(1),@pmCIIUDane VARCHAR(8),@pmFecIniCndato SMALLDATETIME,@pmTipAccCndato INT,@pmFecFinCndato SMALLDATETIME,@pmCodOperInfo VARCHAR(10),@pmTipoApo CHAR(1),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO NomAportante (IdAportnte,RazonSocial,TipoId,DvNit,IdRepLegal,Direccion,IdLocal,Telefono,Fax,e_mail,ClaseApo,TipoEco,TipoPersna,CIIUDane,FecIniCndato,TipAccCndato,FecFinCndato,CodOperInfo,TipoApo,FecAdd,IdUsuario)
 VALUES (@pmIdAportnte,@pmRazonSocial,@pmTipoId,@pmDvNit,@pmIdRepLegal,@pmDireccion,@pmIdLocal,@pmTelefono,@pmFax,@pme_mail,@pmClaseApo,@pmTipoEco,@pmTipoPersna,@pmCIIUDane,@pmFecIniCndato,@pmTipAccCndato
,@pmFecFinCndato,@pmCodOperInfo,@pmTipoApo,@pmFecAdd,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAstncia @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME,@pmHHDiurno DECIMAL(10,4),@pmHHNocturno DECIMAL(10,4),@pmHEDiurno DECIMAL(10,4),@pmHENocturno DECIMAL(10,4),@pmTipoJrnada VARCHAR(10)
,@pmEsDmncal BIT,@pmHorario VARCHAR(30),@pmTimeSys SMALLDATETIME, @pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomAstncia (IdEmpleado,FechaDia,HHDiurno,HHNocturno,HEDiurno,HENocturno,TipoJrnada,EsDmncal,Horario,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmFechaDia,@pmHHDiurno,@pmHHNocturno,@pmHEDiurno,@pmHENocturno,@pmTipoJrnada,@pmEsDmncal,@pmHorario,@pmTimeSys,@pmIdUsuario)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomAutoliq @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmFecha SMALLDATETIME,@pmPerAutoliq VARCHAR(6),@pmPerAutoSal VARCHAR(6),@pmFechaPago SMALLDATETIME,@pmIdAportnte VARCHAR(16),@pmPresentacion CHAR(1),@pmCodCia CHAR(2),@pmCodFondo VARCHAR(8),@pmCodArp VARCHAR(8),@pmCodOper VARCHAR(10),@pmEsCorr BIT,@pmPerCorr VARCHAR(6)
,@pmNumCorr VARCHAR(20),@pmTotalEmp INT,@pmVrNomina MONEY,@pmVrPension MONEY,@pmVrSalud MONEY,@pmVrRiesgos MONEY,@pmVrCajas MONEY,@pmVrSena MONEY,@pmVrIcbf MONEY,@pmVrEsap MONEY,@pmVrMinEduc MONEY,@pmTotalAfipen INT,@pmTotalAfiSal INT,@pmTotalAfiRie INT,@pmTotalAfiCaj INT,@pmTotalAfiSen INT,@pmTotalAfiIcb INT,@pmTotalAfiEsa INT,@pmTotalAfiEduc INT,@pmTotAdmPen INT
,@pmTotAdmSal INT,@pmTotAdmRie INT,@pmTotAdmCom INT,@pmObservacion VARCHAR(250),@pmLogAdmon VARCHAR(250),@pmRedoMiles BIT,@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmTipoPlanilla VARCHAR(3)
 AS 
 INSERT INTO Trn_NomAutoliq (TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,IdAportnte,Presentacion,CodCia,CodFondo,CodArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,VrPension,VrSalud,VrRiesgos,VrCajas,VrSena,VrIcbf,VrEsap,VrMinEduc,TotalAfipen,TotalAfiSal,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,Observacion,LogAdmon,RedoMiles,Anulado,IdEstado,TimeSys,IdUsuario,TipoPlanilla)
 VALUES (@pmTipoLiq,@pmNumero,@pmFecha,@pmPerAutoliq,@pmPerAutoSal,@pmFechaPago,@pmIdAportnte,@pmPresentacion,@pmCodCia,@pmCodFondo,@pmCodArp,@pmCodOper,@pmEsCorr,@pmPerCorr,@pmNumCorr,@pmTotalEmp,@pmVrNomina,@pmVrPension,@pmVrSalud,@pmVrRiesgos,@pmVrCajas,@pmVrSena,@pmVrIcbf,@pmVrEsap,@pmVrMinEduc,@pmTotalAfipen,@pmTotalAfiSal,@pmTotalAfiRie,@pmTotalAfiCaj,@pmTotalAfiSen,@pmTotalAfiIcb
,@pmTotalAfiEsa,@pmTotalAfiEduc,@pmTotAdmPen,@pmTotAdmSal,@pmTotAdmRie,@pmTotAdmCom,@pmObservacion,@pmLogAdmon,@pmRedoMiles,@pmAnulado,@pmIdEstado,@pmTimeSys,@pmIdUsuario,@pmTipoPlanilla)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomCAdmon @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmClaseAdmon VARCHAR(10)
,@pmFecIniNov SMALLDATETIME,@pmNNovedad INT,@pmIdFondo VARCHAR(8),@pmIdFonNew VARCHAR(8),@pmObservacion VARCHAR(100),@pmAnulado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomCAdmon (IdEmpleado,Numero,Fecha,NContrato,ClaseAdmon,FecIniNov,NNovedad,IdFondo,IdFonNew,Observacion,Anulado,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmClaseAdmon,@pmFecIniNov,@pmNNovedad,@pmIdFondo,@pmIdFonNew,@pmObservacion,@pmAnulado,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomCausalesRet @pmIdCausa VARCHAR(4),@pmCausalRet VARCHAR(100),@pmIndmnizar BIT,@pmInactivo BIT
 AS 
 INSERT INTO NomCausalesRet (IdCausa,CausalRet,Indmnizar,Inactivo)
 VALUES (@pmIdCausa,@pmCausalRet,@pmIndmnizar,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomCertf @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20),@pmnAnno INT,@pmnMes INT,@pmVrCertf MONEY
,@pmObservacion VARCHAR(100),@pmClaseCert VARCHAR(10),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomCertf (IdEmpleado,NumCertf,nAnno,nMes,VrCertf,Observacion,FecAdd,IdUsuario,ClaseCert)
 VALUES (@pmIdEmpleado,@pmNumCertf,@pmnAnno,@pmnMes,@pmVrCertf,@pmObservacion,@pmFecAdd,@pmIdUsuario,@pmClaseCert)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomConAuto @pmIdReg INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmVrAplicar MONEY,@pmModalidad CHAR(1)
,@pmOrigenBase CHAR(2),@pmFrecAplica VARCHAR(10),@pmCedEmpleado VARCHAR(16),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodCcto VARCHAR(16)
,@pmCritSelect VARCHAR(4000),@pmFecFinal SMALLDATETIME,@pmExceptuar VARCHAR(8),@pmObservacion VARCHAR(50),@pmCodSubCos VARCHAR(16),@pmInactivo BIT
,@pmNumPerMes INT,@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomConAuto (IdReg,IdConcepto,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,CodNom,CodDep,CodCcto,CritSelect,FecFinal,Exceptuar,Observacion,CodSubCos,Inactivo,NumPerMes,FecAdd,IdUsuario)
 VALUES (@pmIdReg,@pmIdConcepto,@pmFecInicio,@pmVrAplicar,@pmModalidad,@pmOrigenBase,@pmFrecAplica,@pmCedEmpleado,@pmCodNom,@pmCodDep,@pmCodCcto,@pmCritSelect,@pmFecFinal,@pmExceptuar
,@pmObservacion,@pmCodSubCos,@pmInactivo,@pmNumPerMes,@pmFecAdd,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomConCuentas @pmIdConcepto VARCHAR(4),@pmItem INT,@pmNClase INT,@pmIdCuenta VARCHAR(16)
,@pmTipoMov CHAR(1),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodFon VARCHAR(8),@pmNitTerc CHAR(1)
 AS 
 INSERT INTO NomConCuentas (IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc)
 VALUES (@pmIdConcepto,@pmItem,@pmNClase,@pmIdCuenta,@pmTipoMov,@pmCodNom,@pmCodDep,@pmCodFon,@pmNitTerc)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomConOpciones @pmIdConcepto VARCHAR(4),@pmIdOpc INT,@pmNomOpcion VARCHAR(50),@pmAsignado BIT
 AS 
 INSERT INTO NomConOpciones (IdConcepto,IdOpc,NomOpcion,Asignado)
 VALUES (@pmIdConcepto,@pmIdOpc,@pmNomOpcion,@pmAsignado)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomConceptos @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(100),@pmClaseCon VARCHAR(10),@pmUnidad VARCHAR(10),@pmTarifa DECIMAL(10,4)
,@pmBaseTrfa CHAR(2),@pmPdtermnado BIT,@pmInactivo BIT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO NomConceptos (IdConcepto,Concepto,ClaseCon,Unidad,Tarifa,BaseTrfa,Pdtermnado,Inactivo,FechaAdd,IdUsuario)
 VALUES (@pmIdConcepto,@pmConcepto,@pmClaseCon,@pmUnidad,@pmTarifa,@pmBaseTrfa,@pmPdtermnado,@pmInactivo,@pmFechaAdd,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomDefault @pmnAnno INT,@pmIdOpc VARCHAR(3),@pmDescripcion VARCHAR(100),@pmValor MONEY
 AS 
 INSERT INTO NomDefault (nAnno,IdOpc,Descripcion,Valor)
 VALUES (@pmnAnno,@pmIdOpc,@pmDescripcion,@pmValor)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomDetalle @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantDevg DECIMAL(10,4),@pmCantDed DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrTotDevg MONEY,@pmVrTotDed MONEY
,@pmUnidad VARCHAR(10),@pmClaseLiq VARCHAR(10),@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmDiasCalc DECIMAL(10,4),@pmDiasNov DECIMAL(10,4),@pmCodFondo VARCHAR(8),@pmNPrestamo INT,@pmNCuota INT,@pmOrigCargue VARCHAR(10),@pmVrBaseLiq MONEY
 AS 
 INSERT INTO Trn_NomDetalle (IdPeriodo,KeyRegistro,IdEmpleado,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq)
 VALUES (@pmIdPeriodo,@pmKeyRegistro,@pmIdEmpleado,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantDevg,@pmCantDed,@pmVrUnitario,@pmVrTotDevg,@pmVrTotDed,@pmUnidad,@pmClaseLiq,@pmVrOrigen,@pmTarifa
,@pmDiasCalc,@pmDiasNov,@pmCodFondo,@pmNPrestamo,@pmNCuota,@pmOrigCargue,@pmVrBaseLiq)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomDetalle_Sel @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomDetalle (IdPeriodo,KeyRegistro,IdEmpleado,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen
,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq)
 SELECT D.IdPeriodo,@pmNewCedula +CAST(NContrato AS VARCHAR(10)) +CASE EsRetiro WHEN 1 THEN '_1' ELSE '_0'  END
,@pmNewCedula,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen
,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq
 FROM  Trn_NomDetalle AS D INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomFijos @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT,@pmTarifa DECIMAL(10,4),@pmVrBase MONEY,@pmVrSalarios MONEY,@pmVrPrima MONEY,@pmVrVacacnes MONEY,@pmVrSIntExcto MONEY
,@pmVrOtrosIng MONEY,@pmVrIngresos MONEY,@pmVrPensiones MONEY,@pmVrDedcido MONEY,@pmVrExcento MONEY,@pmVrCertEdu MONEY,@pmVrCertVda MONEY,@pmVrCertAFC MONEY,@pmVrCertfcado MONEY,@pmPeriodos DECIMAL(10,4),@pmVrTotalBase MONEY
,@pmOrignPorc VARCHAR(10),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmVrSalud MONEY
 AS 
 INSERT INTO Trn_NomFijos (IdEmpleado,nAnno,nMes,Tarifa,VrBase,VrSalarios,VrPrima,VrVacacnes,VrSIntExcto,VrOtrosIng,VrIngresos,VrPensiones,VrDedcido,VrExcento,VrCertEdu,VrCertVda,VrCertAFC,VrCertfcado,Periodos,VrTotalBase,OrignPorc,FecAdd,IdUsuario,VrSalud)
 VALUES (@pmIdEmpleado,@pmnAnno,@pmnMes,@pmTarifa,@pmVrBase,@pmVrSalarios,@pmVrPrima,@pmVrVacacnes,@pmVrSIntExcto,@pmVrOtrosIng,@pmVrIngresos,@pmVrPensiones,@pmVrDedcido,@pmVrExcento,@pmVrCertEdu,@pmVrCertVda,@pmVrCertAFC
,@pmVrCertfcado,@pmPeriodos,@pmVrTotalBase,@pmOrignPorc,@pmFecAdd,@pmIdUsuario,@pmVrSalud)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsNomLiqDet @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmFecUltLiq SMALLDATETIME,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmVrBase MONEY,@pmCantidad INT
,@pmVrLiquida MONEY,@pmVrDeducido MONEY,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME,@pmDiasBase INT,@pmDiasNoRem INT,@pmTarifa DECIMAL(10,4),@pmNPrestamo INT,@pmNCuota INT,@pmLogPmdio VARCHAR(600),@pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmpVehiculo VARCHAR(10),@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrParcial MONEY
 AS 
 INSERT INTO Trn_NomLiqDet (TipoLiq,Numero,Item,IdConcepto,Detalle,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,Tarifa,NPrestamo,NCuota,LogPmdio,IdEmpleado,NContrato,pVehiculo,IdDep,IdCCosto,IdSubCos,IdNom,VrSalario,VrParcial)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmIdConcepto,@pmDetalle,@pmFecUltLiq,@pmFecInicial,@pmFecFinal,@pmVrBase,@pmCantidad,@pmVrLiquida,@pmVrDeducido,@pmFecIniPmd,@pmFecFinPmd,@pmDiasBase,@pmDiasNoRem,@pmTarifa,@pmNPrestamo,@pmNCuota,@pmLogPmdio
,@pmIdEmpleado,@pmNContrato,@pmpVehiculo,@pmIdDep,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmVrSalario,@pmVrParcial)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomLiquida @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME,@pmSemstre INT,@pmVrTotal MONEY,@pmVrTotDed MONEY,@pmVrAplicado MONEY,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomLiquida (TipoLiq,Numero,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,TimeSys,IdUsuario)
 VALUES (@pmTipoLiq,@pmNumero,@pmFecha,@pmSemstre,@pmVrTotal,@pmVrTotDed,@pmVrAplicado,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmIdEstado,@pmTimeSys,@pmIdUsuario)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomLogVeh @pmIdEmpleado VARCHAR(16),@pmNumReg INT,@pmFecha SMALLDATETIME,@pmpVehAnterior VARCHAR(10),@pmNitPropAnt VARCHAR(16)
,@pmpVehNew VARCHAR(10),@pmNitPropNew VARCHAR(16),@pmObservacion VARCHAR(100),@pmNitCondAnt VARCHAR(16),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomLogVeh (IdEmpleado,NumReg,Fecha,pVehAnterior,NitPropAnt,pVehNew,NitPropNew,Observacion,NitCondAnt,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumReg,@pmFecha,@pmpVehAnterior,@pmNitPropAnt,@pmpVehNew,@pmNitPropNew,@pmObservacion,@pmNitCondAnt,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomNov @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad DECIMAL(10,4),@pmVrUnitario MONEY
,@pmVrTotal MONEY,@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmOrigCargue VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomNov (IdPeriodo,IdEmpleado,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrTotal,VrOrigen,Tarifa,OrigCargue,TimeSys,IdUsuario)
 VALUES (@pmIdPeriodo,@pmIdEmpleado,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantidad,@pmVrUnitario,@pmVrTotal,@pmVrOrigen,@pmTarifa,@pmOrigCargue, @pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomNovedad @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantDias INT,@pmDiaInicio INT
,@pmModalidad VARCHAR(10),@pmIdNov VARCHAR(4),@pmRemnrado BIT,@pmObservacion VARCHAR(250),@pmCodInstla VARCHAR(4),@pmInactivo BIT,@pmCodClsRie VARCHAR(4),@pmNumAutza VARCHAR(30),@pmCodNewFon VARCHAR(8)
,@pmCodOldFon VARCHAR(8),@pmVrCotVolAfi MONEY,@pmVrCotVolApo MONEY,@pmVrNoRetenido MONEY,@pmTipoIncap CHAR(1),@pmFechaDcto SMALLDATETIME,@pmVrDescuento MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomNovedad (IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,Remnrado,Observacion,CodInstla,Inactivo,CodClsRie,NumAutza,CodOldFon,CodNewFon,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,FechaDcto,VrDescuento,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumero,@pmIdConcepto,@pmFecInicio,@pmFecFinal,@pmCantDias,@pmDiaInicio,@pmModalidad,@pmIdNov,@pmRemnrado,@pmObservacion,@pmCodInstla,@pmInactivo,@pmCodClsRie,@pmNumAutza,@pmCodOldFon,@pmCodNewFon
 ,@pmVrCotVolAfi,@pmVrCotVolApo,@pmVrNoRetenido,@pmTipoIncap,@pmFechaDcto,@pmVrDescuento,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE paInsNomPrest @pmNPrestamo INT,@pmFecha SMALLDATETIME,@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmVrPrestamo MONEY
,@pmNumCuotas INT,@pmVrCuota MONEY,@pmFecInicio SMALLDATETIME,@pmFrecDcto VARCHAR(10),@pmExceptuar VARCHAR(8),@pmTotPrestamo MONEY,@pmTotAbonado MONEY
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmCxpagar BIT
,@pmDsctNom INT,@pmDsctPri INT,@pmDsctVac INT,@pmDsctEspPer VARCHAR(8),@pmDsctEspVal MONEY,@pmVrTmAbono MONEY,@pmNumPerMes INT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomPrest (NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom
,Observacion,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal,VrTmAbono,TimeSys,IdUsuario,NumPerMes)
 VALUES (@pmNPrestamo,@pmFecha,@pmIdEmpleado,@pmIdConcepto,@pmVrPrestamo,@pmNumCuotas,@pmVrCuota,@pmFecInicio,@pmFrecDcto,@pmExceptuar,@pmTotPrestamo,@pmTotAbonado,@pmAnulado,@pmFecDev,@pmTipCom
,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmCxpagar,@pmDsctNom,@pmDsctPri,@pmDsctVac,@pmDsctEspPer,@pmDsctEspVal,@pmVrTmAbono,@pmTimeSys,@pmIdUsuario,@pmNumPerMes)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomProrrogas @pmIdEmpleado VARCHAR(16),@pmNumReg INT,@pmNContrato INT,@pmFecha SMALLDATETIME,@pmFecAnterior SMALLDATETIME,@pmIndefinido BIT,@pmCdTipCon VARCHAR(4)
,@pmCdCargo VARCHAR(4),@pmCdDep VARCHAR(4),@pmCdArea VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmIdCargo VARCHAR(4),@pmIdArea VARCHAR(4)
,@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmObservacion VARCHAR(150),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomProrrogas (IdEmpleado,NumReg,NContrato,Fecha,FecAnterior,Indefinido,CdTipCon,CdCargo,CdDep,CdArea,CdCCosto,CdSubCos,IdTipCon,IdCargo,IdArea,IdDep,IdCCosto,IdSubCos,Observacion,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumReg,@pmNContrato,@pmFecha,@pmFecAnterior,@pmIndefinido,@pmCdTipCon,@pmCdCargo,@pmCdDep,@pmCdArea,@pmCdCCosto,@pmCdSubCos,@pmIdTipCon,@pmIdCargo,@pmIdArea
,@pmIdDep,@pmIdCCosto,@pmIdSubCos,@pmObservacion,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomRangosFsu @pmIdRango INT,@pmVrInicial DECIMAL(12,2),@pmVrFinal DECIMAL(12,2),@pmTarifa DECIMAL(10,4)
 AS 
 INSERT INTO NomRangosFsu (IdRango,VrInicial,VrFinal,Tarifa)
 VALUES (@pmIdRango,@pmVrInicial,@pmVrFinal,@pmTarifa)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomRet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmIdCausa VARCHAR(4),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmDiasTrab INT
,@pmDiasNoRem INT,@pmVrTotDev MONEY,@pmVrTotDed MONEY,@pmVrTotCes MONEY,@pmVrTotPri MONEY,@pmVrTotVac MONEY,@pmVrTotInt MONEY,@pmVrTotInd MONEY,@pmVrNeto MONEY,@pmVrBaseCes MONEY,@pmVrBaseVac MONEY,@pmIdPeriodo VARCHAR(8)
,@pmKeyReg VARCHAR(30),@pmNPerVac INT,@pmVrSalario MONEY,@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmTipoLiq CHAR(1),@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmVrParCes MONEY,@pmVrParInt MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomRet (IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo
,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,VrParCes,VrParInt,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmIdCausa,@pmFecInicial,@pmFecFinal,@pmDiasTrab,@pmDiasNoRem,@pmVrTotDev,@pmVrTotDed,@pmVrTotCes,@pmVrTotPri,@pmVrTotVac,@pmVrTotInt,@pmVrTotInd,@pmVrNeto,@pmVrBaseCes,@pmVrBaseVac,@pmIdPeriodo,@pmKeyReg
,@pmNPerVac,@pmVrSalario,@pmIdDep,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmTipoLiq,@pmpVehiculo,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmIdEstado,@pmVrParCes,@pmVrParInt,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomRetDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrDevngado MONEY,@pmVrDeducido MONEY,@pmTarifa DECIMAL(10,4),@pmVrBase MONEY,@pmDiasBase DECIMAL(10,4)
,@pmDiasNoRem DECIMAL(10,4),@pmFecUltLiq SMALLDATETIME,@pmFecDesde SMALLDATETIME,@pmFecHasta SMALLDATETIME,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME,@pmGrupoLiq VARCHAR(15),@pmNPrestamo INT,@pmNCuota INT,@pmLogPmdio VARCHAR(600)
,@pmClaseLiq VARCHAR(10),@pmCodFondo VARCHAR(8),@pmVrBaseLiq MONEY
 AS 
 INSERT INTO Trn_NomRetDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq)
 VALUES (@pmIdEmpleado,@pmNumero,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantidad,@pmVrUnitario,@pmVrDevngado,@pmVrDeducido,@pmTarifa,@pmVrBase,@pmDiasBase,@pmDiasNoRem,@pmFecUltLiq,@pmFecDesde,@pmFecHasta,@pmFecIniPmd,@pmFecFinPmd,@pmGrupoLiq
,@pmNPrestamo,@pmNCuota,@pmLogPmdio,@pmClaseLiq,@pmCodFondo,@pmVrBaseLiq)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomRetDet_Sel @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomRetDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem
,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq)
 SELECT @pmNewCedula,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem
,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq
 FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomRet_Sel @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomRet (IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac
,VrTotInt,VrTotInd,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo
,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,VrParCes,VrParInt,TimeSys,IdUsuario)
 SELECT @pmNewCedula,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac
,VrTotInt,VrTotInd,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo
,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,VrParCes,VrParInt,TimeSys,IdUsuario
 FROM  Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomSueldos @pmNumero INT,@pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmNContrato INT,@pmVrSueAnterior MONEY,@pmVrSueNuevo MONEY,@pmVrAtAnterior MONEY,@pmVrAtNuevo MONEY
,@pmMetodoUp CHAR(1),@pmReemplzado BIT,@pmFecUltAumto SMALLDATETIME,@pmCritSelect VARCHAR(250),@pmObservacion VARCHAR(100),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomSueldos (Numero,IdEmpleado,Fecha,NContrato,VrSueAnterior,VrSueNuevo,VrAtAnterior,VrAtNuevo,MetodoUp,Reemplzado,FecUltAumto,CritSelect,Observacion,TimeSys,IdUsuario)
 VALUES (@pmNumero,@pmIdEmpleado,@pmFecha,@pmNContrato,@pmVrSueAnterior,@pmVrSueNuevo,@pmVrAtAnterior,@pmVrAtNuevo,@pmMetodoUp,@pmReemplzado,@pmFecUltAumto
,@pmCritSelect,@pmObservacion,@pmTimeSys,@pmIdUsuario)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomTablaRet @pmnAnno INT,@pmnIntrvalo INT,@pmVrInicial MONEY,@pmVrFinal MONEY,@pmTarifa DECIMAL(10,4),@pmVrRetncion MONEY
,@pmTarExcdnte DECIMAL(10,4),@pmVrBaseExc MONEY,@pmFechaAdd SMALLDATETIME, @pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO NomTablaRet (nAnno,nIntrvalo,VrInicial,VrFinal,Tarifa,VrRetncion,TarExcdnte,VrBaseExc,FechaAdd,IdUsuario)
 VALUES (@pmnAnno,@pmnIntrvalo,@pmVrInicial,@pmVrFinal,@pmTarifa,@pmVrRetncion,@pmTarExcdnte,@pmVrBaseExc,@pmFechaAdd,@pmIdUsuario)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomVac @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrLiquida MONEY,@pmVrBase MONEY,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME
,@pmDiasBase INT,@pmDiasNoRem INT,@pmDiasVac INT,@pmNNovedad INT,@pmNPeriodos INT,@pmCantRem INT,@pmVrRemndo MONEY,@pmVrTotDed MONEY,@pmVrSalario MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmLogPmdio VARCHAR(600)
,@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomVac (IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,VrSalario,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmFecInicial,@pmFecFinal,@pmCantidad,@pmVrLiquida,@pmVrBase,@pmFecIniPmd,@pmFecFinPmd,@pmDiasBase,@pmDiasNoRem,@pmDiasVac,@pmNNovedad,@pmNPeriodos,@pmCantRem,@pmVrRemndo,@pmVrTotDed,@pmVrSalario,@pmpVehiculo
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmLogPmdio,@pmIdEstado,@pmAnulado,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomVacDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad INT,@pmVrDevgado MONEY,@pmVrDeducido MONEY
,@pmTarifa DECIMAL(10,4),@pmVrBaseLiq MONEY,@pmVrCertfcado MONEY,@pmVrPension MONEY,@pmNPrestamo INT,@pmNCuota INT,@pmIdPeriodo VARCHAR(8),@pmVrSalud MONEY
 AS 
 INSERT INTO Trn_NomVacDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud)
 VALUES (@pmIdEmpleado,@pmNumero,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantidad,@pmVrDevgado,@pmVrDeducido,@pmTarifa,@pmVrBaseLiq,@pmVrCertfcado,@pmVrPension,@pmNPrestamo,@pmNCuota,@pmIdPeriodo,@pmVrSalud)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomVacDet_Sel @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomVacDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud)
 SELECT @pmNewCedula,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud
 FROM  Trn_NomVacDet 
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomVac_Sel @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomVac (IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase
,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,VrSalario,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario)
 SELECT @pmNewCedula,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase
,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,VrSalario,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario
 FROM  Trn_NomVac WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomVehiculos @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmClaseVeh VARCHAR(50),@pmTipoAdmon VARCHAR(50)
,@pmGrupoProp VARCHAR(50),@pmVehPropio BIT,@pmCedCond VARCHAR(16),@pmConductor VARCHAR(50)
 AS 
 INSERT INTO NomVehiculos (IdVehiculo,NumVeh,ClaseVeh,TipoAdmon,GrupoProp,VehPropio,CedCond,Conductor)
 VALUES (@pmIdVehiculo,@pmNumVeh,@pmClaseVeh,@pmTipoAdmon,@pmGrupoProp,@pmVehPropio,@pmCedCond,@pmConductor)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomina @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmNContrato INT,@pmIdDep VARCHAR(4)
,@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrATransMes MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmEsRetiro BIT,@pmNLiqRet INT
,@pmTipoLiq CHAR(1),@pmCantNoRem DECIMAL(10,4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Nomina (IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,Cantidad,VrDevengado,VrDeducido,NContrato,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,CantNoRem,TimeSys,IdUsuario)
 VALUES (@pmIdPeriodo,@pmKeyRegistro,@pmIdEmpleado,@pmFecInicial,@pmFecFinal,@pmCantidad,@pmVrDevengado,@pmVrDeducido,@pmNContrato,@pmIdDep,@pmIdInstala,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmVrSalario,@pmVrATransMes,@pmpVehiculo,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado
,@pmEsRetiro,@pmNLiqRet,@pmTipoLiq,@pmCantNoRem,@pmTimeSys,@pmIdUsuario)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsNomina_Sel  @pmIdEmpleado  VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_Nomina (IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,Cantidad,VrDevengado,VrDeducido,NContrato,IdDep
,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,CantNoRem,TimeSys,IdUsuario)
 SELECT  IdPeriodo,@pmNewCedula +CAST(NContrato AS VARCHAR(10)) +CASE EsRetiro WHEN 1 THEN '_1' ELSE '_0'  END,@pmNewCedula,FecInicial,FecFinal,Cantidad,VrDevengado
,VrDeducido,NContrato,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,CantNoRem,TimeSys,IdUsuario
 FROM Trn_Nomina 
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsObjetosApp @pmIdObj VARCHAR(10),@pmIdGrupo VARCHAR(6),@pmSubModulo VARCHAR(3),@pmIndObj INT,@pmNombre VARCHAR(100),@pmFormulario VARCHAR(10)
,@pmPermisos VARCHAR(20),@pmNivelMinimo INT,@pmNomArchivo VARCHAR(30)
 AS 
 INSERT INTO Sys_ObjetosApp (IdObj,IdGrupo,SubModulo,IndObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo)
 VALUES (@pmIdObj,@pmIdGrupo,@pmSubModulo,@pmIndObj,@pmNombre,@pmFormulario,@pmPermisos,@pmNivelMinimo,@pmNomArchivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsOpciones @pmIdOpc VARCHAR(3),@pmOpcion VARCHAR(100),@pmTipoDato VARCHAR(15)
,@pmValor VARCHAR(100),@pmNivUp INT,@pmnModulo VARCHAR(10)
 AS 
 INSERT INTO adm_Opciones (IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo)
 VALUES (@pmIdOpc,@pmOpcion,@pmTipoDato,@pmValor,@pmNivUp,@pmnModulo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsPaises @pmIdPais VARCHAR(8),@pmCodISO VARCHAR(3),@pmNombrePais VARCHAR(50),@pmIdMneda VARCHAR(5)
 AS 
 INSERT INTO adm_Paises (IdPais,CodISO,NombrePais,IdMneda)
 VALUES (@pmIdPais,@pmCodISO,@pmNombrePais,@pmIdMneda)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsPermisos @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmConsecutivo INT,@pmPerAdd BIT,@pmPerUpdate BIT
,@pmPerDelete BIT,@pmPerAnular BIT,@pmPerRead BIT,@pmPerRename BIT
 AS 
 INSERT INTO adm_Permisos (IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename)
 VALUES (@pmIdUsuario,@pmIdObj,@pmConsecutivo,@pmPerAdd,@pmPerUpdate,@pmPerDelete,@pmPerAnular,@pmPerRead,@pmPerRename)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsPermisosRoles @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmAsignado BIT
 AS 
 INSERT INTO adm_PermisosRoles (IdUsuario,IdObj,IdRole,Asignado)
 VALUES (@pmIdUsuario,@pmIdObj,@pmIdRole,@pmAsignado)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsProfesiones @pmIdProf VARCHAR(4),@pmProfesion VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO Profesiones (IdProf,Profesion,Inactivo)
 VALUES (@pmIdProf,@pmProfesion,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsPuc @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(100),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT,@pmSubCentro BIT,@pmVehiculo BIT,@pmCentroCosto BIT,@pmVencimiento BIT
,@pmBaseGravable BIT,@pmPorcntaje DECIMAL(10,4),@pmNaturaleza CHAR(1),@pmAjustable BIT,@pmCuentaAjuDeb VARCHAR(16),@pmCuentaAjuCre VARCHAR(16),@pmCheques BIT,@pmReferncias BIT
,@pmAgencia BIT,@pmFmtDian INT,@pmConDian INT,@pmRenDec INT,@pmCdTipDoc VARCHAR(3),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmInactivo BIT,@pmAfijos INT
 AS 
 INSERT INTO Puc (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,SubCentro,Vehiculo,CentroCosto,Vencimiento,BaseGravable,Porcntaje,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referncias
,Agencia,FmtDian,ConDian,RenDec,CdTipDoc,FechaAdd,IdUsuario,Inactivo,Afijos)
 VALUES (@pmIdCuenta,@pmNomCuenta,@pmMayor,@pmMovimiento,@pmTercero,@pmSubCentro,@pmVehiculo,@pmCentroCosto,@pmVencimiento,@pmBaseGravable,@pmPorcntaje,@pmNaturaleza,@pmAjustable,@pmCuentaAjuDeb,@pmCuentaAjuCre
,@pmCheques,@pmReferncias,@pmAgencia,@pmFmtDian,@pmConDian,@pmRenDec,@pmCdTipDoc,@pmFechaAdd,@pmIdUsuario,@pmInactivo,@pmAfijos)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsPuc_Sel @pmIdCuenta VARCHAR(16),@pmNewCuenta VARCHAR(16)
AS 
 INSERT INTO Puc (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,SubCentro,Vehiculo,CentroCosto,Vencimiento,BaseGravable,Porcntaje,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referncias
,Agencia,FmtDian,ConDian,RenDec,CdTipDoc,FechaAdd,IdUsuario,Inactivo,Afijos)
 SELECT @pmNewCuenta,NomCuenta,Mayor,Movimiento,Tercero,SubCentro,Vehiculo,CentroCosto,Vencimiento,BaseGravable,Porcntaje,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referncias
,Agencia,FmtDian,ConDian,RenDec,CdTipDoc,FechaAdd,IdUsuario,Inactivo,Afijos
 FROM Puc WHERE IdCuenta=@pmIdCuenta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsRegimenDian @pmIdRegimen VARCHAR(4),@pmRegimen VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO RegimenDian (IdRegimen,Regimen,Inactivo)
 VALUES (@pmIdRegimen,@pmRegimen,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsRegistro @pmIdCia CHAR(2),@pmIdEmpresa VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmDvNit CHAR(1),@pmRazonSocial VARCHAR(250)
,@pmDescripcion VARCHAR(250),@pmDireccion VARCHAR(250),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmIdLocal VARCHAR(8),@pmIdPais VARCHAR(8)
,@pme_mail VARCHAR(100),@pmArchivoLogo VARCHAR(30),@pmNumeroSerial VARCHAR(80),@pmRegimen VARCHAR(50),@pmLicencia VARCHAR(20),@pmVigenciaLic SMALLDATETIME
,@pmPersoneria VARCHAR(40),@pmLeyenda VARCHAR(250),@pmFechaRegistro SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmCurrtyDate SMALLDATETIME
,@pmTipoId CHAR(1),@pmNitRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150),@pmTipoPersna CHAR(1),@pmCIIUDane VARCHAR(8),@pmCurDate1 SMALLDATETIME
 AS 
 INSERT INTO adm_Registro (IdCia,IdEmpresa,NitEmpresa,DvNit,RazonSocial,Descripcion,Direccion,Telefono,Fax,IdLocal,IdPais,e_mail,ArchivoLogo,NumeroSerial,Regimen,Licencia,VigenciaLic
,Personeria,Leyenda,FechaRegistro,FechaVence,CurrtyDate,TipoId,NitRepLegal,RepLegal,TipoPersna,CIIUDane,CurDate1)
 VALUES (@pmIdCia,@pmIdEmpresa,@pmNitEmpresa,@pmDvNit,@pmRazonSocial,@pmDescripcion,@pmDireccion,@pmTelefono,@pmFax,@pmIdLocal,@pmIdPais,@pme_mail,@pmArchivoLogo
,@pmNumeroSerial,@pmRegimen,@pmLicencia,@pmVigenciaLic,@pmPersoneria,@pmLeyenda,@pmFechaRegistro,@pmFechaVence,@pmCurrtyDate,@pmTipoId,@pmNitRepLegal,@pmRepLegal,@pmTipoPersna,@pmCIIUDane,@pmCurDate1)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsRelaciones @pmIdTabla VARCHAR(20),@pmTablaForanea VARCHAR(20),@pmCampoForaneo VARCHAR(20)
,@pmBasedeDatos VARCHAR(10),@pmNoValidar BIT
 AS 
 INSERT INTO Sys_Relaciones (IdTabla,TablaForanea,CampoForaneo,BasedeDatos,NoValidar)
 VALUES (@pmIdTabla,@pmTablaForanea,@pmCampoForaneo,@pmBasedeDatos,@pmNoValidar)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsReport @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT
,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50),@pmNomRep VARCHAR(50)
 AS 
 INSERT INTO Sys_Report (TipoRep,IdRep,Descripcion,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location,NomRep)
 VALUES (@pmTipoRep,@pmIdRep,@pmDescripcion,@pmFormato,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmsp_Nombre,@pmInd_Location,@pmNomRep)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsRoles @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmFuncion VARCHAR(100)
 AS 
 INSERT INTO Sys_Roles (IdObj,IdRole,Funcion)
 VALUES (@pmIdObj,@pmIdRole,@pmFuncion)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsSectoresEco @pmIdSector VARCHAR(8),@pmSectorEco VARCHAR(250),@pmInactivo BIT
 AS 
 INSERT INTO SectoresEco (IdSector,SectorEco,Inactivo)
 VALUES (@pmIdSector,@pmSectorEco,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsSecurity @pmIdLla INT,@pmDescripcion VARCHAR(50),@pmPwd VARCHAR(10)
 AS 
 INSERT INTO Sys_Security (IdLla,Descripcion,Pwd)
 VALUES (@pmIdLla,@pmDescripcion,@pmPwd)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsSubCentros @pmIdSubCos VARCHAR(16),@pmSubCosto VARCHAR(100),@pmIdCCosto VARCHAR(16),@pmFecAdd SMALLDATETIME,@pmInactivo BIT
 AS 
 INSERT INTO SubCentros (IdSubCos,SubCosto,IdCCosto,FecAdd,Inactivo)
 VALUES (@pmIdSubCos,@pmSubCosto,@pmIdCCosto,@pmFecAdd,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTerceros @pmIdTercero VARCHAR(16),@pmRazonSocial VARCHAR(250),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8)
,@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmTelMovil VARCHAR(20),@pmSitioWeb VARCHAR(100),@pme_mail VARCHAR(100),@pmEsCliente BIT,@pmEsVendedor BIT,@pmEsConductor BIT
,@pmEsPropietario BIT,@pmEsProveedor BIT,@pmEsEmpleado BIT,@pmEsOperario BIT,@pmEsAccnista BIT,@pmEsCiaAseg BIT,@pmIdSector VARCHAR(8),@pmIdRegimen VARCHAR(4),@pmIdLugarCed VARCHAR(8),@pmObservacion VARCHAR(250)
,@pmIniStgNom INT,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmNomCial VARCHAR(250),@pmSiglaRaz VARCHAR(50),@pmIdProf VARCHAR(4),@pmTipEnte CHAR(1),@pmFecExpCed SMALLDATETIME
,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Terceros (IdTercero,RazonSocial,Codigo,TipoId,Dv,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,IdSector,IdRegimen
,IdLugarCed,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,IdUsuario,NomCial,SiglaRaz,IdProf,TipEnte,FecExpCed)
 VALUES (@pmIdTercero,@pmRazonSocial,@pmCodigo,@pmTipoId,@pmDv,@pmDireccion,@pmIdLocal,@pmTelefono,@pmFax,@pmTelMovil,@pmSitioWeb,@pme_mail,@pmEsCliente,@pmEsVendedor,@pmEsConductor,@pmEsPropietario,@pmEsProveedor
,@pmEsEmpleado,@pmEsOperario,@pmEsAccnista,@pmEsCiaAseg,@pmIdSector,@pmIdRegimen,@pmIdLugarCed,@pmObservacion,@pmIniStgNom,@pmIdEstado,@pmInactivo,@pmFechaAdd,@pmIdUsuario
,@pmNomCial,@pmSiglaRaz,@pmIdProf,@pmTipEnte,@pmFecExpCed)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposCom @pmIdCom VARCHAR(3),@pmTipoCom VARCHAR(50),@pmIdDiario VARCHAR(4)
,@pmEsEgreso BIT,@pmConsUnico BIT,@pmInactivo BIT,@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO TiposCom (IdCom,TipoCom,IdDiario,EsEgreso,ConsUnico,Inactivo,FechaAdd)
 VALUES (@pmIdCom,@pmTipoCom,@pmIdDiario,@pmEsEgreso,@pmConsUnico,@pmInactivo,@pmFechaAdd)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposComCons @pmIdCom VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT
,@pmNumero INT,@pmNumManual BIT,@pmFormato VARCHAR(20),@pmConfigFecha VARCHAR(10),@pmTipoPapel INT
,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO TiposComCons (IdCom,IdCia,LDesde,LHasta,Numero,NumManual,Formato,ConfigFecha
,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,FechaAdd)
 VALUES (@pmIdCom,@pmIdCia,@pmLDesde,@pmLHasta,@pmNumero,@pmNumManual,@pmFormato,@pmConfigFecha
,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmFechaAdd)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposCon @pmIdTipCon VARCHAR(4),@pmTipoContrato VARCHAR(100)
,@pmDuracion INT,@pmInactivo BIT
 AS 
 INSERT INTO TiposCon (IdTipCon,TipoContrato,Duracion,Inactivo)
 VALUES (@pmIdTipCon,@pmTipoContrato,@pmDuracion,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposCot @pmIdCot VARCHAR(4),@pmCotizante VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposCot (IdCot,Cotizante,Inactivo)
 VALUES (@pmIdCot,@pmCotizante,@pmInactivo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsTiposDoc @pmIdDoc VARCHAR(3),@pmTipoDoc VARCHAR(50),@pmConsUnico BIT
,@pmLeyenda VARCHAR(250),@pmInactivo BIT,@pmIntegraCias BIT
 AS 
 INSERT INTO Sys_TiposDoc (IdDoc,TipoDoc,ConsUnico,Leyenda,Inactivo,IntegraCias)
 VALUES (@pmIdDoc,@pmTipoDoc,@pmConsUnico,@pmLeyenda,@pmInactivo,@pmIntegraCias)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposDocCons @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT,@pmResolucion VARCHAR(30)
,@pmRangoNum VARCHAR(50),@pmFechaRes SMALLDATETIME,@pmPrefijo VARCHAR(5),@pmNumero INT,@pmNumManual BIT,@pmIntLotes BIT
,@pmConfigFecha VARCHAR(10),@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT
,@pmNumCopias INT,@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO TiposDocCons (IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero,NumManual,IntLotes,ConfigFecha
,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,FechaAdd)
 VALUES (@pmIdDoc,@pmIdCia,@pmLDesde,@pmLHasta,@pmResolucion,@pmRangoNum,@pmFechaRes,@pmPrefijo,@pmNumero
,@pmNumManual,@pmIntLotes,@pmConfigFecha,@pmFormato,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmFechaAdd)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposDocCue @pmIdDoc VARCHAR(3),@pmIdClase INT
,@pmClaseCuenta VARCHAR(50),@pmTipoMov CHAR(1)
 AS 
 INSERT INTO Sys_TiposDocCue (IdDoc,IdClase,ClaseCuenta,TipoMov)
 VALUES (@pmIdDoc,@pmIdClase,@pmClaseCuenta,@pmTipoMov)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposNom @pmIdNom VARCHAR(4),@pmTipoNomina VARCHAR(50),@pmAsistencia BIT,@pmNoDevenga BIT
,@pmTipoLiquida CHAR(1),@pmFechaActual SMALLDATETIME,@pmInactivo BIT,@pmCdCiaInt CHAR(2)
 AS 
 INSERT INTO TiposNom (IdNom,TipoNomina,Asistencia,NoDevenga,TipoLiquida,FechaActual,Inactivo,CdCiaInt )
 VALUES (@pmIdNom,@pmTipoNomina,@pmAsistencia,@pmNoDevenga,@pmTipoLiquida,@pmFechaActual,@pmInactivo,@pmCdCiaInt)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsTiposNov @pmIdNov VARCHAR(4),@pmNovedad VARCHAR(50),@pmAdmon VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO TiposNov (IdNov,Novedad,Admon,Inactivo)
 VALUES (@pmIdNov,@pmNovedad,@pmAdmon,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsUOpciones @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20),@pmValor VARCHAR(50)
 AS 
 INSERT INTO adm_UOpciones (IdUsuario,NomOpcion,Valor)
 VALUES (@pmIdUsuario,@pmNomOpcion,@pmValor)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsUm @pmUndMed VARCHAR(10),@pmUnidad VARCHAR(50)
 AS 
 INSERT INTO Sys_Um (UndMed,Unidad)
 VALUES (@pmUndMed,@pmUnidad)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsUsuarios @pmIdUsuario VARCHAR(11),@pmUsuario VARCHAR(50),@pmPwdLog VARCHAR(30),@pmIdGrupo INT,@pmIdEstacion CHAR(2),@pmIdCargo VARCHAR(4),@pmConectado BIT,@pmFechaAcc SMALLDATETIME
,@pmFechaClave SMALLDATETIME,@pmCaducidad INT,@pmLoginSQL VARCHAR(20),@pmPwdSQL VARCHAR(20),@pmModoSQL VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO adm_Usuarios (IdUsuario,Usuario,PwdLog,IdGrupo,IdEstacion,IdCargo,Conectado,FechaAcc,FechaClave,Caducidad,LoginSQL,PwdSQL,ModoSQL,Inactivo)
 VALUES (@pmIdUsuario,@pmUsuario,@pmPwdLog,@pmIdGrupo,@pmIdEstacion,@pmIdCargo,@pmConectado,@pmFechaAcc,@pmFechaClave,@pmCaducidad,@pmLoginSQL
,@pmPwdSQL,@pmModoSQL,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInsmonedas @pmIdMneda VARCHAR(5),@pmMneda VARCHAR(50),@pmSimbolo VARCHAR(10),@pmMneLocal BIT
,@pmVrCambio DECIMAL(12,6),@pmInactivo BIT
 AS 
 INSERT INTO adm_monedas (IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo)
 VALUES (@pmIdMneda,@pmMneda,@pmSimbolo,@pmMneLocal,@pmVrCambio,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Aportes @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmApellido1 VARCHAR(50),@pmtmApellido2 VARCHAR(50),@pmtmNombre1 VARCHAR(50),@pmtmNombre2 VARCHAR(50),@pmtmNContto INT,@pmtmDiasPen DECIMAL(10,4),@pmtmDiasSal DECIMAL(10,4),@pmtmDiasRie DECIMAL(10,4),@pmtmDiasCom DECIMAL(10,4),@pmtmBasePen MONEY,@pmtmBaseSal MONEY,@pmtmBaseRie MONEY,@pmtmBaseCom MONEY,@pmtmBaseRef MONEY,@pmtmValorPen MONEY,@pmtmValorSal MONEY,@pmtmValorRie MONEY,@pmtmValorCom MONEY,@pmtmValorSena MONEY
,@pmtmValorIcbf MONEY,@pmtmValorFsp MONEY,@pmtmValorFsu MONEY,@pmtmValorESAP MONEY,@pmtmValorMin MONEY,@pmtmTarfaPen DECIMAL(10,4),@pmtmTarfaSal DECIMAL(10,4),@pmtmTarfaRie DECIMAL(10,4),@pmtmTarfaFsp DECIMAL(10,4),@pmtmTarfaFsu DECIMAL(10,4),@pmtmTarfaEsa DECIMAL(10,4),@pmtmTarfaMin DECIMAL(10,4),@pmtmTarfaCom DECIMAL(10,4),@pmtmTarfaIcb DECIMAL(10,4),@pmtmTarfaSen DECIMAL(10,4),@pmtmNovIng INT,@pmtmNovRet INT,@pmtmNovTda INT,@pmtmNovTaa INT,@pmtmNovTdp INT,@pmtmNovTap INT,@pmtmNovVsp INT,@pmtmNovVte INT,@pmtmNovVst INT,@pmtmNovSln INT,@pmtmNovIge INT,@pmtmNovLma INT,@pmtmNovVac INT
,@pmtmNovAvp INT,@pmtmNovIrp INT,@pmtmNovVct INT,@pmtmCodNewEps VARCHAR(8),@pmtmCodNewPen VARCHAR(8),@pmtmCodNewRie VARCHAR(8),@pmtmCodNewIns VARCHAR(4),@pmtmCodNewTar VARCHAR(4),@pmtmCodNewGru VARCHAR(4),@pmtmVrIncap MONEY,@pmtmVrLicencia MONEY,@pmtmVrVolAfi MONEY,@pmtmVrVolApo MONEY,@pmtmVrNoReten MONEY,@pmtmVrUpc MONEY,@pmtmVrIncIrp MONEY,@pmtmNAutLic VARCHAR(30),@pmtmNAutInc VARCHAR(30),@pmtmNAutIrp VARCHAR(30),@pmtmIdFonPen VARCHAR(8),@pmtmIdFonSal VARCHAR(8),@pmtmIdFonRie VARCHAR(8),@pmtmIdFonCaj VARCHAR(8),@pmtmIdInstala VARCHAR(4)
,@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVehiculo VARCHAR(10),@pmtmVrBasico MONEY,@pmtmDiasNov DECIMAL(10,4),@pmtmCdFonAvp VARCHAR(8)
 AS 
 INSERT INTO tm_Aportes (tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNContto,tmDiasPen,tmDiasSal,tmDiasRie,tmDiasCom,tmBasePen,tmBaseSal,tmBaseRie,tmBaseCom,tmBaseRef,tmValorPen,tmValorSal,tmValorRie,tmValorCom,tmValorSena,tmValorIcbf,tmValorFsp,tmValorFsu,tmTarfaPen,tmTarfaSal,tmTarfaRie,tmTarfaFsp,tmTarfaFsu,tmTarfaEsa,tmTarfaMin,tmTarfaCom,tmTarfaIcb,tmTarfaSen,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmCodNewEps,tmCodNewPen,tmCodNewRie,tmCodNewIns,tmCodNewTar,tmCodNewGru
,tmVrIncap,tmVrLicencia,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp,tmNAutLic,tmNAutInc,tmNAutIrp,tmIdFonPen,tmIdFonSal,tmIdFonRie,tmIdFonCaj,tmIdInstala,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVehiculo,tmVrBasico,tmDiasNov,tmValorESAP,tmValorMin,tmCdFonAvp)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdEmpleado,@pmtmApellido1,@pmtmApellido2,@pmtmNombre1,@pmtmNombre2,@pmtmNContto,@pmtmDiasPen,@pmtmDiasSal,@pmtmDiasRie,@pmtmDiasCom,@pmtmBasePen,@pmtmBaseSal,@pmtmBaseRie,@pmtmBaseCom,@pmtmBaseRef,@pmtmValorPen,@pmtmValorSal,@pmtmValorRie,@pmtmValorCom,@pmtmValorSena,@pmtmValorIcbf,@pmtmValorFsp,@pmtmValorFsu,@pmtmTarfaPen,@pmtmTarfaSal,@pmtmTarfaRie,@pmtmTarfaFsp,@pmtmTarfaFsu,@pmtmTarfaEsa,@pmtmTarfaMin,@pmtmTarfaCom,@pmtmTarfaIcb,@pmtmTarfaSen,@pmtmNovIng,@pmtmNovRet,@pmtmNovTda,@pmtmNovTaa,@pmtmNovTdp,@pmtmNovTap
,@pmtmNovVsp,@pmtmNovVte,@pmtmNovVst,@pmtmNovSln,@pmtmNovIge,@pmtmNovLma,@pmtmNovVac,@pmtmNovAvp,@pmtmNovIrp,@pmtmNovVct,@pmtmCodNewEps,@pmtmCodNewPen,@pmtmCodNewRie,@pmtmCodNewIns,@pmtmCodNewTar,@pmtmCodNewGru,@pmtmVrIncap,@pmtmVrLicencia,@pmtmVrVolAfi,@pmtmVrVolApo,@pmtmVrNoReten,@pmtmVrUpc,@pmtmVrIncIrp,@pmtmNAutLic,@pmtmNAutInc,@pmtmNAutIrp,@pmtmIdFonPen,@pmtmIdFonSal,@pmtmIdFonRie,@pmtmIdFonCaj,@pmtmIdInstala,@pmtmIdDep,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmVehiculo,@pmtmVrBasico,@pmtmDiasNov,@pmtmValorESAP,@pmtmValorMin,@pmtmCdFonAvp)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Aportes_Sel  @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmtmEst VARCHAR(5)
 AS 
 INSERT INTO tm_Aportes (tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNContto,tmDiasPen,tmDiasSal,tmDiasRie,tmDiasCom,tmBasePen,tmBaseSal,tmBaseRie,tmBaseCom,tmBaseRef,tmValorPen,tmValorSal,tmValorRie,tmValorCom,tmValorSena,tmValorIcbf,tmValorFsp,tmValorFsu
,tmTarfaPen,tmTarfaSal,tmTarfaRie,tmTarfaFsp,tmTarfaFsu,tmTarfaEsa,tmTarfaMin,tmTarfaCom,tmTarfaIcb,tmTarfaSen,tmVrIncap,tmVrLicencia,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp,tmNAutLic,tmNAutInc,tmNAutIrp,tmIdFonPen,tmIdFonSal,tmIdFonRie,tmIdFonCaj,tmIdInstala,tmIdDep,tmIdCCosto
,tmIdSubCos,tmIdNom,tmVehiculo,tmVrBasico,tmValorESAP,tmValorMin,tmCdFonAvp)
 SELECT @pmtmEst,Item,IdEmpleado,Apellido1,Apellido2,Nombre1,Nombre2,NContrato,DiasPen,DiasSal,DiasRie,DiasCom,VrIBCPen,VrIBCSal,VrIBCRie,VrIBCCajas,VrIBCRef,VrPension,VrSalud,VrRiesgos,VrCajas,VrSena,VrICBF,VrApoFsp,VrApoFsu,TarifPen,TarifSal,TarifRie,TarifFsp,TarifFsu,TarifEsap,TarifEdu
,TarifCom,TarifIcb,TarifSen,VrIncap,VrLicencia,VrApoVolAfi,VrApoVolApt,VrNoReten,VrUpc,VrIncIrp,NumAutLic,NumAutInc,NumAutIrp,IdFonPen,IdFonSal,IdFonRie,IdCajCom,IdInstala,'0','0','0','0','',SalBasico,VrESAP,VrMinEdu,CdFonAvp
 FROM Trn_NomAlqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_AutTot @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmTipAdm VARCHAR(3),@pmtmIdFondo VARCHAR(8),@pmtmCodTipoApo CHAR(2),@pmtmTotalCot MONEY,@pmtmTotalFsp MONEY,@pmtmTotalFsu MONEY
,@pmtmTotalAva MONEY,@pmtmTotalAve MONEY,@pmtmTotalUpc MONEY,@pmtmTotalLic MONEY,@pmtmTotalInc MONEY,@pmtmTotalOtr MONEY,@pmtmDiasMora INT,@pmtmTarifMora DECIMAL(10,4),@pmtmIntMora MONEY,@pmtmIMoraOtr MONEY
,@pmtmTotalSAF MONEY,@pmtmSAFUpc MONEY,@pmtmTotalPagar MONEY,@pmtmTotalFon MONEY,@pmtmTotalAfi INT,@pmtmNumAutLic VARCHAR(30),@pmtmNumAutInc VARCHAR(30),@pmtmNumPlaSAF VARCHAR(20)
 AS 
 INSERT INTO tm_AutTot (tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar
,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF)
 VALUES (@pmtmEst,@pmtmItem,@pmtmTipAdm,@pmtmIdFondo,@pmtmCodTipoApo,@pmtmTotalCot,@pmtmTotalFsp,@pmtmTotalFsu,@pmtmTotalAva,@pmtmTotalAve,@pmtmTotalUpc,@pmtmTotalLic,@pmtmTotalInc,@pmtmTotalOtr,@pmtmDiasMora
,@pmtmTarifMora,@pmtmIntMora,@pmtmIMoraOtr,@pmtmTotalSAF,@pmtmSAFUpc,@pmtmTotalPagar,@pmtmTotalFon,@pmtmTotalAfi,@pmtmNumAutLic,@pmtmNumAutInc,@pmtmNumPlaSAF)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_AutTot_Sel @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmtmEst VARCHAR(5)
 AS 
 INSERT INTO tm_AutTot (tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar
,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF)
 SELECT @pmtmEst,Item,TipAdm,IdFondo,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar
,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF
 FROM Trn_NomAlqTot
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Comp @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdCuenta VARCHAR(16),@pmtmDetalle VARCHAR(250),@pmtmVrDebito MONEY,@pmtmVrCredito MONEY,@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16)
,@pmtmVrBase MONEY,@pmtmTarifaBase DECIMAL(10,4),@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCiaDoc CHAR(2),@pmtmCodConce VARCHAR(4),@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15),@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmFecVence SMALLDATETIME,@pmtmCodCta VARCHAR(4)
,@pmtmNumCheque VARCHAR(20),@pmtmIntegrado BIT,@pmtmTipoAplica CHAR(1),@pmtmConsolida BIT,@pmtmCodCargo VARCHAR(4),@pmtmNitOtros VARCHAR(16),@pmtmCodSubgpo VARCHAR(8),@pmtmCiuOrigen VARCHAR(8),@pmtmCodAgncia VARCHAR(16),@pmtmVehPropio BIT,@pmtmReferncia VARCHAR(50),@pmtmTipCom VARCHAR(3)
,@pmtmComprobante INT,@pmtmIdCia CHAR(2),@pmtmNombre VARCHAR(100),@pmtmCcosto VARCHAR(100),@pmtmSubcc VARCHAR(100),@pmtmTercero VARCHAR(150),@pmtmTipDocRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmNitDoc VARCHAR(16)
 AS 
 INSERT INTO tm_Comp (tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo
,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdCuenta,@pmtmDetalle,@pmtmVrDebito,@pmtmVrCredito,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmVrBase,@pmtmTarifaBase,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCiaDoc,@pmtmCodConce,@pmtmTipFac,@pmtmFactura,@pmtmIdCiaFac,@pmtmItemFac,@pmtmFecVence
,@pmtmCodCta,@pmtmNumCheque,@pmtmIntegrado,@pmtmTipoAplica,@pmtmConsolida,@pmtmCodCargo,@pmtmNitOtros,@pmtmCodSubgpo,@pmtmCiuOrigen,@pmtmCodAgncia,@pmtmVehPropio,@pmtmReferncia,@pmtmTipCom,@pmtmComprobante,@pmtmIdCia,@pmtmNombre,@pmtmCcosto,@pmtmSubcc,@pmtmTercero
,@pmtmTipDocRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmNitDoc)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Ingresos @pmtmEst CHAR(2),@pmtmItem INT,@pmtmNMes VARCHAR(6),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmDetalle VARCHAR(100),@pmtmVrBase MONEY,@pmtmCantDevg DECIMAL(10,4),@pmtmCantDed DECIMAL(10,4),@pmtmVrDevngado MONEY,@pmtmVrDeducido MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasBase INT,@pmtmDiasNoRem INT
,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmIdInstala VARCHAR(4),@pmtmVrSalario MONEY,@pmtmCodFondo VARCHAR(8),@pmtmClaseLiq VARCHAR(10),@pmtmOrigenLiq VARCHAR(10),@pmtmBaseRet BIT
,@pmtmEsPstamo BIT,@pmtmEsRetiro BIT,@pmtmNPrestamo INT
 AS 
 INSERT INTO tm_Ingresos (tmEst,tmItem,tmNMes,tmIdEmpleado,tmIdConcepto,tmDetalle,tmVrBase,tmCantDevg,tmCantDed,tmVrDevngado,tmVrDeducido,tmTarifa,tmDiasBase,tmDiasNoRem,tmFecInicial,tmFecFinal,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmIdInstala,tmVrSalario,tmCodFondo,tmClaseLiq,tmOrigenLiq,tmBaseRet,tmEsPstamo,tmEsRetiro,tmNPrestamo)
 VALUES (@pmtmEst,@pmtmItem,@pmtmNMes,@pmtmIdEmpleado,@pmtmIdConcepto,@pmtmDetalle,@pmtmVrBase,@pmtmCantDevg,@pmtmCantDed,@pmtmVrDevngado,@pmtmVrDeducido,@pmtmTarifa,@pmtmDiasBase,@pmtmDiasNoRem,@pmtmFecInicial,@pmtmFecFinal,@pmtmNContrato,@pmtmpVehiculo,@pmtmIdDep,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmIdInstala
,@pmtmVrSalario,@pmtmCodFondo,@pmtmClaseLiq,@pmtmOrigenLiq,@pmtmBaseRet,@pmtmEsPstamo,@pmtmEsRetiro,@pmtmNPrestamo)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Liquida @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmDetalle VARCHAR(100),@pmtmFecUltLiq SMALLDATETIME,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmVrBase MONEY,@pmtmCantidad INT,@pmtmVrLiquida MONEY,@pmtmVrDeducido MONEY,@pmtmFecIniPmd SMALLDATETIME,@pmtmFecFinPmd SMALLDATETIME,@pmtmDiasBase INT
,@pmtmDiasNoRem INT,@pmtmTarifa DECIMAL(10,4),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmLogPmdio VARCHAR(600),@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrParcial MONEY
 AS 
 INSERT INTO tm_Liquida (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,tmVrParcial)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdEmpleado,@pmtmIdConcepto,@pmtmDetalle,@pmtmFecUltLiq,@pmtmFecInicial,@pmtmFecFinal,@pmtmVrBase,@pmtmCantidad,@pmtmVrLiquida,@pmtmVrDeducido,@pmtmFecIniPmd,@pmtmFecFinPmd,@pmtmDiasBase,@pmtmDiasNoRem,@pmtmTarifa,@pmtmNPrestamo,@pmtmNCuota,@pmtmLogPmdio
,@pmtmNContrato,@pmtmpVehiculo,@pmtmIdDep,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmVrSalario,@pmtmVrParcial)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Liquida_Sel @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmtmNumero VARCHAR(5),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 INSERT INTO tm_Liquida (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd
,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,tmVrParcial)
 SELECT @pmtmNumero,Item,IdEmpleado,IdConcepto,Detalle,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd
 ,DiasBase,DiasNoRem,Tarifa,NPrestamo,NCuota,LogPmdio,NContrato,pVehiculo,IdDep,IdCCosto,IdSubCos,IdNom,VrSalario,VrParcial
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_NomHoras @pmtmIdEmpleado VARCHAR(16),@pmtmNContrato INT,@pmtmHorDiurno DECIMAL(14,4),@pmtmHorNocturno DECIMAL(14,4),@pmtmHorExtraDia DECIMAL(14,4),@pmtmHorExtraNoc DECIMAL(14,4),@pmtmHorRecNoc DECIMAL(14,4),@pmtmHorDomDia DECIMAL(14,4)
,@pmtmHorDomNoc DECIMAL(14,4),@pmtmHorExtDom DECIMAL(14,4),@pmtmHorExtDomNoc DECIMAL(14,4),@pmtmVrHoras1 DECIMAL(14,4),@pmtmVrHoras2 DECIMAL(14,4),@pmtmVrHoras3 DECIMAL(14,4),@pmtmVrHoras4 DECIMAL(14,4),@pmtmIdArea VARCHAR(4),@pmtmIdDep VARCHAR(4)
,@pmtmIdInstala VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrATrans MONEY,@pmtmpVehiculo VARCHAR(10),@pmtmTipoLiquida CHAR(1)
 AS 
 INSERT INTO tm_NomHoras (tmIdEmpleado,tmNContrato,tmHorDiurno,tmHorNocturno,tmHorExtraDia,tmHorExtraNoc,tmHorRecNoc,tmHorDomDia,tmHorDomNoc,tmHorExtDom,tmHorExtDomNoc,tmVrHoras1,tmVrHoras2,tmVrHoras3,tmVrHoras4,tmIdArea,tmIdDep,tmIdInstala,tmIdCCosto,tmIdSubCos
,tmIdNom,tmVrSalario,tmVrATrans,tmpVehiculo,tmTipoLiquida)
 VALUES (@pmtmIdEmpleado,@pmtmNContrato,@pmtmHorDiurno,@pmtmHorNocturno,@pmtmHorExtraDia,@pmtmHorExtraNoc,@pmtmHorRecNoc,@pmtmHorDomDia,@pmtmHorDomNoc,@pmtmHorExtDom,@pmtmHorExtDomNoc,@pmtmVrHoras1,@pmtmVrHoras2,@pmtmVrHoras3
,@pmtmVrHoras4,@pmtmIdArea,@pmtmIdDep,@pmtmIdInstala,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmVrSalario,@pmtmVrATrans,@pmtmpVehiculo,@pmtmTipoLiquida)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_NomRes @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmItem INT,@pmtmNContrato INT
,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmIdPeriodo VARCHAR(8),@pmtmIdArea VARCHAR(4),@pmtmIdDep VARCHAR(4),@pmtmIdInstala VARCHAR(4)
,@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrATrans MONEY,@pmtmpVehiculo VARCHAR(10)
,@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCiaCom CHAR(2),@pmtmObservacion VARCHAR(250),@pmtmEsRetiro BIT,@pmtmNLiqRet INT
,@pmtmTipoLiq CHAR(1),@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(14,4),@pmtmCantDed DECIMAL(14,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY
,@pmtmUnidad VARCHAR(10),@pmtmClaseLiq VARCHAR(10),@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(14,4),@pmtmDiasCalc DECIMAL(14,4),@pmtmDiasNov DECIMAL(14,4)
,@pmtmCodFondo VARCHAR(8),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmVrBaseLiq MONEY
 AS 
 INSERT INTO tm_NomRes (tmNumero,tmIdEmpleado,tmIdConcepto,tmItem,tmNContrato,tmFecInicial,tmFecFinal,tmIdPeriodo,tmIdArea,tmIdDep,tmIdInstala,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario
,tmVrATrans,tmpVehiculo,tmTipCom,tmComprobante,tmIdCiaCom,tmObservacion,tmEsRetiro,tmNLiqRet,tmTipoLiq,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmVrBaseLiq)
 VALUES (@pmtmNumero,@pmtmIdEmpleado,@pmtmIdConcepto,@pmtmItem,@pmtmNContrato,@pmtmFecInicial,@pmtmFecFinal,@pmtmIdPeriodo,@pmtmIdArea,@pmtmIdDep,@pmtmIdInstala,@pmtmIdCCosto
,@pmtmIdSubCos,@pmtmIdNom,@pmtmVrSalario,@pmtmVrATrans,@pmtmpVehiculo,@pmtmTipCom,@pmtmComprobante,@pmtmIdCiaCom,@pmtmObservacion,@pmtmEsRetiro,@pmtmNLiqRet,@pmtmTipoLiq
,@pmtmDetalle,@pmtmCantDevg,@pmtmCantDed,@pmtmVrUnitario,@pmtmVrTotDevg,@pmtmVrTotDed,@pmtmUnidad,@pmtmClaseLiq,@pmtmVrOrigen,@pmtmTarifa,@pmtmDiasCalc,@pmtmDiasNov,@pmtmCodFondo,@pmtmNPrestamo,@pmtmNCuota,@pmtmVrBaseLiq)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Nomina @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT,@pmtmIdConcepto VARCHAR(4),@pmtmClaseCon VARCHAR(10),@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(10,4),@pmtmCantDed DECIMAL(10,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY
,@pmtmUnidad VARCHAR(10),@pmtmClaseLiq VARCHAR(10),@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasCalc DECIMAL(10,4),@pmtmDiasNov DECIMAL(10,4),@pmtmCodFondo VARCHAR(8),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmOrigCargue VARCHAR(10),@pmtmVrBaseLiq MONEY,@pmtmNContto INT,@pmtmFecIni SMALLDATETIME
,@pmtmFecFin SMALLDATETIME,@pmtmIdPeriodo VARCHAR(8),@pmtmFecUltLiq SMALLDATETIME,@pmtmFecIniPmd SMALLDATETIME,@pmtmFecFinPmd SMALLDATETIME,@pmtmLogPmdio VARCHAR(600),@pmtmVrPension MONEY,@pmtmVrSalud MONEY
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmVrPension,tmVrSalud)
 VALUES (@pmtmNumero,@pmtmIdEmpleado,@pmtmItem,@pmtmIdConcepto,@pmtmClaseCon,@pmtmDetalle,@pmtmCantDevg,@pmtmCantDed,@pmtmVrUnitario,@pmtmVrTotDevg,@pmtmVrTotDed,@pmtmUnidad,@pmtmClaseLiq,@pmtmVrOrigen,@pmtmTarifa
,@pmtmDiasCalc,@pmtmDiasNov,@pmtmCodFondo,@pmtmNPrestamo,@pmtmNCuota,@pmtmOrigCargue,@pmtmVrBaseLiq,@pmtmNContto,@pmtmFecIni,@pmtmFecFin,@pmtmIdPeriodo,@pmtmFecUltLiq,@pmtmFecIniPmd,@pmtmFecFinPmd,@pmtmLogPmdio,@pmtmVrPension,@pmtmVrSalud)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Nomina_Liq  @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmFecUltLiq
,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmVrPension,tmVrSalud)
 SELECT @pmtmNumero,Item,D.IdEmpleado,D.IdConcepto,ClaseCon,Detalle
,'CntDev'= CASE  WHEN VrDeducido<=0 THEN Cantidad ELSE 0 END
,'CntDed'= CASE  WHEN VrDeducido>0 THEN Cantidad ELSE 0  END
,VrUnitario,VrDevngado,VrDeducido,Unidad,ClaseLiq,VrBase,D.Tarifa,DiasBase,D.DiasNoRem,CodFondo
,NPrestamo,NCuota,'LIQUDACION',VrBaseLiq,NContrato,FecDesde,FecHasta,IdPeriodo,FecUltLiq,FecIniPmd,FecFinPmd,LogPmdio,0,0
 FROM Trn_NomRetDet AS D INNER JOIN Trn_NomRet AS R ON D.IdEmpleado=R.IdEmpleado AND D.Numero=R.Numero
 INNER JOIN  NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 WHERE D.IdEmpleado=@pmIdEmpleado AND D.Numero=@pmNumero  AND  ClaseLiq NOT IN  ('APORTE','PROVISION')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Nomina_Sel @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmVrPension,tmVrSalud)
 SELECT @pmtmNumero,Item,D.IdEmpleado,D.IdConcepto,ClaseCon,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad,ClaseLiq,VrOrigen,D.Tarifa,DiasCalc
,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,NContrato,FecInicial,FecFinal,D.IdPeriodo,0,0
 FROM Trn_NomDetalle  AS D INNER JOIN NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdPeriodo=@pmIdPeriodo AND D.KeyRegistro=@pmKeyRegistro 
 AND  ClaseLiq  IN  ('NOMINA','NOVEDAD')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Nomina_Vac  @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmVrPension,tmVrSalud)
 SELECT @pmtmNumero,Item,IdEmpleado,D.IdConcepto,ClaseCon,Detalle,0,Cantidad,0,VrDevgado,VrDeducido,Unidad,'NOMINA',VrBaseLiq,D.Tarifa,0,0,'',NPrestamo,NCuota,'VAC',VrCertfcado
,0,getdate(),getdate(),IdPeriodo,VrPension,VrSalud
 FROM Trn_NomVacDet  AS D INNER JOIN NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paInstm_Plasueldos @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30),@pmtmDias DECIMAL(10,4),@pmtmVrBasico MONEY,@pmtmVrAuxtrans MONEY,@pmtmVrHextras MONEY,@pmtmVrRecargos MONEY
,@pmtmVrComision MONEY,@pmtmVrIncapac MONEY,@pmtmVrLicencia MONEY,@pmtmVrVacacnes MONEY,@pmtmVrOtrosDev MONEY,@pmtmVrDctoPen MONEY,@pmtmVrDctoSal MONEY,@pmtmVrDctoFsp MONEY,@pmtmVrRetencion MONEY
,@pmtmVrPrestmos MONEY,@pmtmVrSanciones MONEY,@pmtmVrOtrosDed MONEY,@pmtmObserv VARCHAR(1000),@pmtmVrVacLiquida MONEY,@pmtmVrVacPen MONEY,@pmtmVrVacSal MONEY,@pmtmVrVacFsp MONEY,@pmtmVrVacOtr MONEY
 AS 
 INSERT INTO tm_Plasueldos (tmIdPeriodo,tmKeyRegistro,tmDias,tmVrBasico,tmVrAuxtrans,tmVrHextras,tmVrRecargos,tmVrComision,tmVrIncapac,tmVrLicencia,tmVrVacacnes,tmVrOtrosDev,tmVrDctoPen,tmVrDctoSal,tmVrDctoFsp,tmVrRetencion
,tmVrPrestmos,tmVrSanciones,tmVrOtrosDed,tmObserv,tmVrVacLiquida,tmVrVacPen,tmVrVacSal,tmVrVacFsp,tmVrVacOtr)
 VALUES (@pmtmIdPeriodo,@pmtmKeyRegistro,@pmtmDias,@pmtmVrBasico,@pmtmVrAuxtrans,@pmtmVrHextras,@pmtmVrRecargos,@pmtmVrComision,@pmtmVrIncapac,@pmtmVrLicencia,@pmtmVrVacacnes,@pmtmVrOtrosDev,@pmtmVrDctoPen,@pmtmVrDctoSal,@pmtmVrDctoFsp
,@pmtmVrRetencion,@pmtmVrPrestmos,@pmtmVrSanciones,@pmtmVrOtrosDed,@pmtmObserv,@pmtmVrVacLiquida,@pmtmVrVacPen,@pmtmVrVacSal,@pmtmVrVacFsp,@pmtmVrVacOtr)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryAgenciasLta @pmIdClie VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdZona VARCHAR(4)=Null,@pmIdSzona VARCHAR(4)=Null,@pmIdEstrato VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdSector VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 SELECT A.IdClie AS NitCliente,RazonSocial,IdAgencia,CodAgencia,Agencia,DirAgncia,A.IdLocal AS CdCiuAgncia,L.Localidad AS CiudadAgncia
,L.IdDep AS CdDptoAgncia,D.Departamento AS DptoAgncia,TelAgncia,FaxAgncia,NitCont,NomCont,emlCont,CargoCont,VrCupoCre,VrSaldoAct,A.FecUpCupo AS FechaUpCupo,Referencia,IdProyecto
,A.FecIngreso AS Fec_Ingreso,NomCial,SiglaRaz,SZA.IdZona AS Age_CdZona,ZA.Zona AS Age_Zona,A.IdSzona AS Age_IdSubzona,SZA.Subzona AS Age_Subzona
,A.IdPlazo AS CdPlazo,Plazo,NVmto,A.IdForma AS CdForma,FormaPago,A.IdVend AS NitVend,A.CdCms AS CodCms,A.CdDct AS CodDct,IntMora,A.DiasGracia AS Dias_gracia,FactFletes,A.FactSold AS FacturaSold
,TipoId,Dv,Direccion,T.IdLocal AS CdCiuClie,LT.Localidad AS CiuClie,LT.IdDep AS CdDptoClie,DT.Departamento AS DptoClie
,NitRepLeg,NomRepLeg,NitContac,NomContac,C.IdGrupo AS CdGrupo,GrupoClie,SZ.IdZona AS CdZona,Z.Zona AS CliZona,C.IdSzona AS CdSubzona,SZ.Subzona AS CliSubZona
,A.CdBandera AS CodBandera,TipoBandera,C.IdEstrato AS CdEstrato,Estrato,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRgmen,Regimen,TipEnte,VrCupo,VrSaldo,Telefono,Fax
,TelMovil,e_mail,C.IdEstado AS CdEstado,Estado,C.Inactivo AS Clie_inactivo,A.IdEstado AS Age_Estado,A.Inactivo AS Age_inactivo,IniStgNom,A.FechaAdd AS FecAdd
,Comentarios,A.FechaUpdate AS FecUpd,A.IdUsuario AS IdUsuari,Usuario
 FROM Agencias AS A INNER JOIN Terceros AS T ON A.IdClie=T.IdTercero
 INNER JOIN TercCliente AS C ON A.IdClie=C.IdClie INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON A.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN Subzonas AS SZA ON A.IdSzona=SZA.IdSzona INNER JOIN Zonas AS ZA ON SZA.IdZona=ZA.IdZona
 INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal  INNER JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN Estratos AS EC ON C.IdEstrato=EC.IdEstrato
 INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS E ON C.IdEstado=E.IdEstado INNER JOIN Plazos AS PZ ON A.IdPlazo=PZ.IdPlazo
 INNER JOIN Formaspago AS FP ON A.IdForma=FP.IdForma
 LEFT JOIN TiposBan AS TB ON A.CdBandera=TB.IdBandera
 WHERE A.Inactivo=0 AND A.IdClie LIKE ISNULL(@pmIdClie,'%') AND A.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND C.IdGrupo LIKE ISNULL(@pmIdGrupo ,'%') AND SZA.IdZona LIKE ISNULL(@pmIdZona,'%') AND A.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND C.IdEstrato LIKE ISNULL(@pmIdEstrato,'%') AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND T.IdSector LIKE ISNULL(@pmIdSector,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY RazonSocial,Agencia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryAreas @pmIdArea VARCHAR(4)
 AS 
  SELECT IdArea,Area,JefeArea,IdCCosto,Inactivo
  FROM Areas
  WHERE IdArea=@pmIdArea



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryAreasLta
 AS 
  SELECT IdArea,Area,JefeArea,A.IdCCosto AS IdCcost,CCosto
  FROM Areas AS A INNER JOIN CentroCosto AS C ON A.IdCCosto=C.IdCCosto
  WHERE A.Inactivo=0
  ORDER BY Area

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryBancos @pmIdBanco VARCHAR(4)
 AS 
 IF @pmIdBanco IS NULL
  SELECT IdBanco,Banco,CodEntidad,B.IdClase AS CodClase,ClaseBanco,Direccion,Contacto,Comision
  FROM Bancos AS B INNER JOIN ClaseBan AS C ON B.IdClase=C.IdClase
  WHERE B.Inactivo=0
  ORDER BY IdBanco
 ELSE
  SELECT IdBanco,Banco,IdClase,CodEntidad,Direccion,Contacto,Comision,Inactivo
  FROM Bancos
  WHERE IdBanco=@pmIdBanco

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryBancosDso
AS
 SELECT  IdBanco,Banco,IdBanco+'  '+ Banco AS DsBan  
 FROM   Bancos  
 WHERE Inactivo=0   
 ORDER BY  IdBanco

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryBancosEnt @pmCodEntidad VARCHAR(20)
 AS 
  SELECT IdBanco,Banco,IdClase,CodEntidad,Direccion,Contacto,Comision,Inactivo
  FROM Bancos
  WHERE CodEntidad=@pmCodEntidad


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCalndario @pmFechaDia SMALLDATETIME
 AS 
 IF @pmFechaDia IS NULL
  SELECT FechaDia,TipoFtvo  FROM Calndario  ORDER BY FechaDia
 ELSE
  SELECT FechaDia,TipoFtvo
  FROM Calndario
  WHERE FechaDia=@pmFechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCalndarioMes @pmMes INT,@pmAnno INT
 AS 
 SELECT FechaDia,TipoFtvo  FROM Calndario 
 WHERE MONTH(FechaDia)=@pmMes AND YEAR(FechaDia)=@pmAnno
 ORDER BY FechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCargos @pmIdCargo VARCHAR(4)
 AS 
 IF @pmIdCargo IS NULL
   SELECT IdCargo,Cargo,Funciones
   FROM Cargos 
   WHERE  Inactivo=0
  ORDER BY Cargo
 ELSE
  SELECT IdCargo,Cargo,Funciones,Inactivo
  FROM Cargos 
  WHERE IdCargo=@pmIdCargo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCentroCosto @pmIdCCosto VARCHAR(16)
 AS 
 IF @pmIdCCosto IS NULL
  SELECT IdCCosto,CCosto,FechaAdd,FechaUpdate 
  FROM CentroCosto
  WHERE Inactivo=0
  ORDER BY CCosto
ELSE
  SELECT IdCCosto,CCosto,FechaAdd,FechaUpdate,Inactivo 
  FROM CentroCosto
  WHERE IdCCosto=@pmIdCCosto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCentroCostoDso @pmInactivo BIT=Null
 AS 
  SELECT IdCCosto,CCosto,CCosto+' '+IdCCosto AS DsCco 
  FROM CentroCosto
  WHERE   (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY CCosto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryClaseBan @pmIdClase VARCHAR(4)
 AS 
IF @pmIdClase IS NULL
  SELECT IdClase,ClaseBanco 
  FROM ClaseBan
  WHERE Inactivo=0
 ORDER BY ClaseBanco
ELSE 
  SELECT IdClase,ClaseBanco,Inactivo
  FROM ClaseBan
  WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryClaseCta @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,ClaseCuenta
  FROM ClaseCta
  WHERE Inactivo=0
  ORDER BY ClaseCuenta
 ELSE
  SELECT IdClase,ClaseCuenta,Inactivo
  FROM ClaseCta
  WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryClaseFon @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,ClaseFondo
  FROM ClaseFon
  WHERE  Inactivo=0
  ORDER BY  IdClase
 ELSE
  SELECT IdClase,ClaseFondo,Inactivo
  FROM ClaseFon
  WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryClaseRie @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,ClaseRiesgo,Tarifa
  FROM ClaseRie
  WHERE  Inactivo=0
  ORDER  BY IdClase
 ELSE
  SELECT IdClase,ClaseRiesgo,Tarifa,Inactivo
  FROM ClaseRie
  WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryClaseRieDso
 AS 
  SELECT IdClase,ClaseRiesgo,Tarifa,ClaseRiesgo+ ' ' + STR(Tarifa,5,3) AS DsRie
  FROM ClaseRie
  WHERE  Inactivo=0
  ORDER  BY IdClase


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCnxextna @pmIdReg INT
 AS 
 SELECT IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxObserv,CnxPpties
 FROM Sys_Cnxextna
 WHERE IdReg=@pmIdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCnxextnaItm 
 AS 
 SELECT MAX(IdReg) AS MXITM
 FROM Sys_Cnxextna

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCnxextnaLta @pmCnxTipo VARCHAR(10)=Null
 AS 
 SELECT IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxOwner,CnxObserv,CnxPpties,CnxPwd
 FROM Sys_Cnxextna
 WHERE  CnxTipo LIKE ISNULL(@pmCnxTipo,'%')
 ORDER BY IdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCnxextnaTip @pmCnxTipo VARCHAR(10)
 AS 
 SELECT IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxObserv,CnxPpties
 FROM Sys_Cnxextna
 WHERE  CnxTipo=@pmCnxTipo
 ORDER BY IdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComDetalle @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_ComDetalle
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComDetalleChe @pmNumCheque VARCHAR(20),@pmCodCta VARCHAR(4), @pmTipCom VARCHAR(3),@pmIdCia CHAR(2)
AS
 SELECT TipCom, Comprobante, IdCia, Item, Fecha,CodCta, NumCheque
 FROM    Trn_ComDetalle
 WHERE NumCheque=@pmNumCheque AND CodCta like ISNULL(@pmCodCta,'%') AND TipCom like ISNULL(@pmTipCom,'%') AND  IdCia like ISNULL(@pmIdCia,'%%')
 ORDER BY  TipCom,IdCia,Comprobante,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComDetalleDoc  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmIntegrado BIT=Null
 AS 
 IF @pmIntegrado IS NULL
  SELECT TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
 ,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
  FROM Trn_ComDetalle
  WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
  ORDER BY TipCom,Comprobante,Item
 ELSE
  SELECT TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
 ,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
  FROM Trn_ComDetalle
  WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
  AND Integrado=@pmIntegrado  AND IdCia=@pmIdCiaDoc
  ORDER BY TipCom,Comprobante,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComDetalleTot @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
AS
 SELECT SUM(VrDebito) AS TotalDeb,SUM(VrCredito) AS TotalCre,SUM(VrBase) AS TotalBaseGrav
 FROM  Trn_ComDetalle 
 WHERE TipCom=@pmTipCom 
 AND (Comprobante>=ISNULL(@pmComprobante,0)  AND Comprobante<=ISNULL(@pmComprobante,2147483647))
 AND IdCia like ISNULL(@pmIdCia,'%%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComDetalleVen @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,C.IdCuenta AS CodCuenta,Detalle,VrDebito,VrCredito,IdTercero,CodAgncia,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,Referncia,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea
 FROM Trn_ComDetalle AS C INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia 
 AND  Vencimiento<>0  AND (TipoAplica='A' OR TipoAplica='C' ) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComDetalleVis @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,D.IdCuenta AS CodCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,RazonSocial,IdVehiculo,D.IdCCosto AS IdCcsto,CCosto
,D.IdSubCos AS IdSbcosto,SubCosto,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado
,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia,NitDoc,TipDocRef,DocRef,IdCiaRef,D.IdUsuario AS IdUsuari,Usuario,TimeSys,D.FecUpdate AS FecUpdte,IdCiaCrea
 FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 INNER JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFactura @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmIdProveedor VARCHAR(16),@pmItem INT
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom
,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia AND IdProveedor=@pmIdProveedor
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFacturaCmp @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante
,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM Trn_ComFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 ORDER BY TipFac,Factura,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE  paQryComFacturaDab  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15)
 AS 
 SELECT C.Factura AS NumFact,C.Item AS NItem,C.IdProveedor AS NitProvee,C.ItemCom AS ItmComp
,VrFactura,VrAbonado,SUM(VrAbono) AS STOTABO
 FROM Trn_ComFactura AS C LEFT JOIN Trn_EgrFactura AS E ON C.TipFac=E.TipFac AND C.Factura=E.Factura
 AND C.IdCia=E.IdCiaFac AND C.Item=E.ItemFac AND C.IdProveedor=E.IdProveedor
 WHERE C.TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND C.IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND C.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  C.Factura LIKE ISNULL(@pmFactura,'%')
 GROUP BY  C.Factura,C.Item,C.IdProveedor,C.ItemCom,VrFactura,VrAbonado
 ORDER BY  C.Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE  paQryComFacturaDoc  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15),@pmItemCom INT
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante
,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  Factura LIKE ISNULL(@pmFactura,'%')
 AND (ItemCom>=ISNULL(@pmItemCom,-10)  AND ItemCom<=ISNULL(@pmItemCom,0)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFacturaDso @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null,@pmTipFac VARCHAR(3)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmIdProveedor VARCHAR(16)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmpVehiculo VARCHAR(10)=Null,@pmTipCom VARCHAR(3)=Null,@pmComprobante INT=Null
AS
 SELECT  TipFac, Factura, IdCia, Item,IdCuenta,IdProveedor,T.RazonSocial AS Proveedor,TipDoc, Documento, IdCiaDoc, FecEmision, FecVence, VrFactura,VrAbonado,VrFactura-VrAbonado AS ValorSaldo
,TipCom, Comprobante, ItemCom, Referencia, Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM   Trn_ComFactura   AS  V INNER JOIN Terceros AS T ON V.IdProveedor=T.IdTercero
 WHERE  FecVence BETWEEN @pmFechaIni AND @pmFechaFin AND (VrFactura-VrAbonado)>=@pmSaldo AND IdCia like ISNULL(@pmIdCia,'%%') AND TipFac like ISNULL(@pmTipFac,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND (Comprobante>=ISNULL(@pmComprobante,-1)  AND Comprobante<=ISNULL(@pmComprobante,2147483647)) 
ORDER BY TipFac,Factura,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFacturaDve @pmIdProveedor VARCHAR(16),@pmNitFletes VARCHAR(16)=Null
 AS 
 SELECT TipFac,Factura,IdCia,Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado,FecEmision,FecVence,TipDoc,Documento,IdCiaDoc
,Referencia,Detalle,IdProveedor,RazonSocial, F.IdCuenta AS IdCuent,NomCuenta,TipCom,Comprobante, ItemCom,TipRef,DocRef,IdCiaRef,pVehiculo,VehPropio
 FROM  Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 WHERE VrFactura>VrAbonado AND IdProveedor IN (@pmIdProveedor,ISNULL(@pmNitFletes,@pmIdProveedor))
 ORDER BY FecVence,TipFac,IdCia,Documento

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFacturaNit @pmIdProveedor VARCHAR(16),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmTipFac VARCHAR(3)=Null,@pmpVehiculo VARCHAR(10)=Null
 AS 
 SELECT TipFac,Factura,IdCia,Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado,FecEmision,FecVence,TipDoc,Documento,IdCiaDoc
,IdProveedor,RazonSocial, F.IdCuenta AS IdCuent,NomCuenta,TipCom,Comprobante, ItemCom, Referencia, Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM  Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 WHERE VrFactura>VrAbonado AND IdProveedor=@pmIdProveedor AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND TipFac LIKE ISNULL(@pmTipFac,'%') 
 --AND TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
ORDER BY FecVence,TipFac,IdCia,Factura

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE  paQryComFacturaRef  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15),@pmReferencia VARCHAR(50)
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante
,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND Referencia=@pmReferencia AND ItemCom=0
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  Factura LIKE ISNULL(@pmFactura,'%')
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFacturaSal @pmFechaAct SMALLDATETIME,@pmSaldo DECIMAL(14,2),@pmIdProveedor VARCHAR(16)=Null, @pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmTipFac VARCHAR(3)=Null,@pmDocumento INT=Null,@pmTipCom VARCHAR(3)=Null
AS
SELECT  TipFac, Factura, IdCia, Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado, FecEmision, FecVence,DATEDIFF(day,FecVence,@pmFechaAct) AS DiasMora,TipDoc, Documento, IdCiaDoc 
,F.IdProveedor AS NitProveedor,RazonSocial, F.IdCuenta AS IdCuent,NomCuenta,TipCom, Comprobante, ItemCom, Referencia, Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef
 FROM Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 WHERE (VrFactura-VrAbonado)>@pmSaldo AND F.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND TipFac LIKE ISNULL(@pmTipFac,'%')  AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND (Documento>=ISNULL(@pmDocumento,-1)  AND Documento<=ISNULL(@pmDocumento,2147483647)) 
ORDER BY RazonSocial,F.IdCuenta,FecVence,TipFac,IdCia,Factura

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComFacturaTnit @pmIdProveedor VARCHAR(16)
 AS 
 SELECT  COUNT(Documento) AS SCANT,SUM(VrFactura) AS STOTFAC,SUM(VrAbonado) AS STOTABO
 FROM Trn_ComFactura
 WHERE IdProveedor=@pmIdProveedor


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE paQryCompanias @pmIdCia CHAR(2)
 AS 
 SELECT IdCia,Compania,DirInterface,FechaActual,PeriodoActual,IdCCosto,IdSubCos,IdTercero
,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,FechaAdd,FechaUpdate,Inactivo
 FROM Companias
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCompaniasDso
AS
  SELECT  IdCia, Compania,IdCia+'  '+Compania AS DsCia
  FROM Companias WHERE  Inactivo=0 ORDER BY IdCia


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCompaniasLta @pmIdCia CHAR(2)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdCia,Compania,DirInterface,FechaActual,PeriodoActual,Inactivo,IdCCosto,IdSubCos,IdTercero
,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,FechaAdd,FechaUpdate
 FROM Companias
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCompanias_Cr @pmInactivo BIT=Null
 AS 
 SELECT IdCia,Compania,DirInterface,FechaActual,PeriodoActual,C.IdCCosto AS CodCcosto,CCosto,C.IdSubCos AS CodSubCosto,SubCosto
,IdTercero,CodSucsal,DireccSuc,TelefSuc,FaxSuc,C.IdLocal AS CodCiu,Localidad,C.FechaAdd AS Fecha_Add,C.FechaUpdate AS FecUpd,C.Inactivo AS Inactvo
 FROM Companias AS C INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto 
 INNER JOIN  SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 WHERE (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComprobantes @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr
,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,Observacion,IdEstado,Propddes,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Comprobantes
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComprobantesChe @pmNumCheque VARCHAR(20),@pmIdCta VARCHAR(4), @pmIdCia CHAR(2), @pmTipCom VARCHAR(3),@pmEsEgreso BIT
AS
 SELECT TipCom, Comprobante, IdCia, Fecha, IdCta, EnEfectivo, NumCheque,FecCheque,EsEgreso
 FROM  Trn_Comprobantes 
 WHERE NumCheque=@pmNumCheque AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCta LIKE ISNULL(@pmIdCta,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')  AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 ORDER BY  TipCom,IdCia,Comprobante

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComprobantesChx @pmNumCheque VARCHAR(20),@pmIdCta VARCHAR(4), @pmIdCia CHAR(2),@pmEsEgreso BIT
--CONSULTA : SI EXISTE EL CHEQUE EN LA CUENTA
AS
 SELECT TipCom, Comprobante, IdCia, Fecha, IdCta, EnEfectivo, NumCheque,EsEgreso
 FROM  Trn_Comprobantes  
 WHERE EnEfectivo=0 AND Anulado=0 AND NumCheque=@pmNumCheque AND IdCta=@pmIdCta AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 ORDER BY  TipCom,IdCia,Comprobante

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComprobantesDoc  @pmTipDoc VARCHAR(3), @pmDocumento INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr
,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,Observacion,IdEstado,Propddes,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Comprobantes
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento  AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY  TipCom,IdCia, Comprobante

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComprobantesDso @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME, @pmTipCom VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmAnulado BIT=Null,@pmIntegrado BIT=Null,@pmEsEgreso BIT=Null,@pmAnticipo BIT=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT TipCom,Comprobante,C.IdCia AS CodCia,Compania,Fecha,C.IdTercero AS NitTercero,RazonSocial,VrTotal,C.IdCta AS CodCta,NumeroCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr
,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,C.Observacion AS Observ,C.IdEstado AS IdEstad,Estado,Propddes,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Comprobantes AS C INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipCom LIKE ISNULL(@pmTipCom,'%') AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1)) 
AND (Anticipo=ISNULL(@pmAnticipo,0) or Anticipo=ISNULL(@pmAnticipo,1)) 
 ORDER BY TipCom,C.IdCia,Comprobante

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryComprobantesNom  @pmTipDoc VARCHAR(3), @pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4)
,@pmNEgreso INT=Null,@pmIdTercero VARCHAR(16)=Null
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,Integrado
 FROM Trn_Comprobantes
 WHERE Anulado=0 AND  Propddes='NOMINA'  AND TipDoc=@pmTipDoc AND Documento=@pmDocumento 
 AND CodConce=@pmCodConce AND NEgreso<=@pmNEgreso AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND  IdCiaDoc LIKE ISNULL(@pmIdCiaDoc,'%%')
 ORDER BY  TipCom,IdCia, Comprobante

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCtasCorrientes @pmIdCta VARCHAR(4)
 AS 
 SELECT IdCta,NumeroCta,IdBanco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato,TipoPapel,Orientacion
,VistaPrevia,VerSetup,NumCopias,IdCiaDef,Inactivo
 FROM CtasCorrientes
 WHERE IdCta=@pmIdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCtasCorrientesDso @pmIdBanco VARCHAR(4),@pmIdCiaDef CHAR(2)=Null
AS
  SELECT  IdCta,NumeroCta,IdCta+ ' ' +NumeroCta+' ' + Banco AS DsCta,C.IdBanco AS CodBanco,Banco
  FROM   CtasCorrientes AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
  WHERE C.Inactivo=0 AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
  AND (IdCiaDef LIKE ISNULL(@pmIdCiaDef,'%%') OR IdCiaDef='00')
  ORDER BY  IdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCtasCorrientesLta @pmIdBanco VARCHAR(4)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmInactivo BIT=Null,@pmIdCiaDef CHAR(2)=Null
 AS 
 SELECT IdCta,NumeroCta,C.IdBanco AS CodBco,Banco,C.IdCuenta AS IdCuent,NomCuenta,ConsCheques,RangoCons,ConsActual,Formato,TipoPapel,Orientacion
,VistaPrevia,VerSetup,NumCopias,IdCiaDef,C.Inactivo AS Inactvo
 FROM CtasCorrientes AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 WHERE C.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND  (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND IdCiaDef LIKE ISNULL(@pmIdCiaDef,'%%')
ORDER BY  IdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCtasCorrientesNum @pmNumeroCta VARCHAR(20),@pmOper VARCHAR(4)

AS
 IF  @pmOper ='LIKE'
 SELECT IdCta,NumeroCta,C.IdBanco AS CodBanco,Banco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato
 ,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,C.Inactivo AS Inactiv,IdCiaDef
  FROM   CtasCorrientes AS C INNER JOIN Bancos ON C.IdBanco=Bancos.IdBanco
  WHERE  NumeroCta LIKE @pmNumeroCta
  ORDER BY IdCta
 ELSE
  SELECT IdCta,NumeroCta,C.IdBanco AS CodBanco,Banco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato
 ,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,C.Inactivo AS Inactiv,IdCiaDef
  FROM   CtasCorrientes AS C INNER JOIN Bancos ON C.IdBanco=Bancos.IdBanco
   WHERE  NumeroCta=@pmNumeroCta
  ORDER BY IdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryCtasCorrientesPuc @pmIdCuenta VARCHAR(16)
AS
 SELECT IdCta,NumeroCta,C.IdBanco AS CodBanco,Banco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato
 ,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,C.Inactivo AS Inactiv,IdCiaDef
  FROM   CtasCorrientes AS C INNER JOIN Bancos ON C.IdBanco=Bancos.IdBanco
  WHERE  IdCuenta=@pmIdCuenta
  ORDER BY IdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryDepartamentos @pmIdDep VARCHAR(8)
 AS 
 IF @pmIdDep IS NULL
  SELECT IdDep,Departamento,Codigo,IdPais  FROM Departamentos
  WHERE Inactivo=0
  ORDER BY Departamento
 ELSE
  SELECT IdDep,Departamento,Codigo,IdPais,Inactivo
  FROM Departamentos
  WHERE IdDep=@pmIdDep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryDependencias @pmIdDep VARCHAR(4)
 AS 
 SELECT IdDep,Dependencia,JefeDep,IdArea,IdSubCos,TipRiesgo,Inactivo
 FROM Dependencias
 WHERE IdDep=@pmIdDep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryDependenciasLta @pmIdArea VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdDep,Dependencia,D.IdArea AS CodArea,Area,D.IdSubCos AS IdSubcc,SubCosto,JefeDep,D.Inactivo AS Inactvo
 FROM Dependencias AS D INNER JOIN Areas AS A ON D.IdArea=A.IdArea INNER JOIN SubCentros AS S ON D.IdSubCos=S.IdSubCos
 WHERE D.IdArea LIKE ISNULL(@pmIdArea,'%') 
 AND (D.Inactivo=ISNULL(@pmInactivo,0) or D.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Dependencia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryDeveloper
AS
 SELECT NitCia,Nombre,Direccion,Telefono,Fax,Ciudad,Internet,Email,RepLegal
 FROM Sys_Developer
 ORDER BY NitCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryDiarios @pmIdDiario VARCHAR(4)
 AS 
 IF @pmIdDiario IS NULL
  SELECT IdDiario,Diario
  FROM Diarios
  WHERE Inactivo=0
  ORDER BY IdDiario
 ELSE
  SELECT IdDiario,Diario,Inactivo
  FROM Diarios
  WHERE IdDiario=@pmIdDiario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFactura @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono
,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFacturaAbo @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15) ,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16)
 AS 
 SELECT  SUM(VrAbono) AS StotAbo
 FROM Trn_EgrFactura
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND  IdCiaFac=@pmIdCiaFac  AND IdProveedor=@pmIdProveedor 
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFacturaApl @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipFac, Factura, IdCiaFac, ItemFac,IdProveedor,SUM(VrAbono) AS STOTABO
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 GROUP BY TipFac, Factura, IdCiaFac, ItemFac,IdProveedor

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFacturaDap @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmFactura VARCHAR(15)=Null,@pmIdProveedor VARCHAR(16)=Null
 AS 
 SELECT TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,SUM(VrAbono) AS STOTABO
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND TipDev=@pmTipCom AND NumDev=@pmComprobante AND EsEgreso=0
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND Factura LIKE ISNULL(@pmFactura,'%')
 GROUP BY TipFac,Factura,IdCiaFac,ItemFac,IdProveedor

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFacturaDev @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmFactura VARCHAR(15)=Null,@pmIdProveedor VARCHAR(16)=Null
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono
,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND TipDev=@pmTipCom AND NumDev=@pmComprobante AND EsEgreso=0
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND Factura LIKE ISNULL(@pmFactura,'%')
ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFacturaDoc @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15) ,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16)
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura
 WHERE  TipFac=@pmTipFac AND Factura=@pmFactura AND  IdCiaFac=@pmIdCiaFac AND IdProveedor=@pmIdProveedor
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647)) 
 ORDER BY  TipCom, Comprobante, IdCia, Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEgrFacturaTnit  @pmIdProveedor VARCHAR(16)
 AS 
 SELECT SUM(VrAbono) AS STOTABO
 FROM Trn_EgrFactura
 WHERE IdProveedor=@pmIdProveedor

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_Contrato @pmNContrato INT
 AS 
 SELECT NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,IdCargo,IdJornada,IdDep,IdArea,IdInstala,IdCCosto,IdSubCos,IdCia,IdNom
,IdClase,TipoTrabj,IdCot,IdGrupo,VrUpc,TipoLiquida,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP
,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,IdEstado,Inactivo,SubTipoCot,FecAdd,FecUpdate,IdUsuario
 FROM Emp_Contrato
 WHERE NContrato=@pmNContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoAct @pmIdEmpleado VARCHAR(16),@pmInactivo BIT=Null
 AS 
 SELECT NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,TipoLiquida,VrSalario,VrAuxTrans,IdEstado,Inactivo,Notas
 FROM Emp_Contrato
 WHERE IdEmpleado=@pmIdEmpleado
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY FecIngreso,NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoAnt @pmIdEmpleado VARCHAR(16),@pmNContratoExc INT
 AS 
 SELECT NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,IdCargo,IdJornada,IdDep,IdArea,IdInstala,IdCCosto,IdSubCos,IdCia,IdNom
,TipoTrabj,IdCot,IdGrupo,VrUpc,TipoLiquida,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP
,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,IdEstado,Inactivo,SubTipoCot,FecAdd,FecUpdate,IdUsuario
 FROM Emp_Contrato
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato<>@pmNContratoExc
 ORDER BY FecIngreso,NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoDso @pmIdEmpleado VARCHAR(16)=Null,@pmIndefinido BIT=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmTipoLiquida CHAR(1)=Null
,@pmSalMinimo BIT=Null,@pmSalIntegral BIT=Null,@pmFPnomina VARCHAR(10)=Null,@pmModoRet INT=Null,@pmIdClase VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmNContrato INT=Null,@pmFecIngresoIni SMALLDATETIME=Null,@pmFecIngresoFin SMALLDATETIME=Null,@pmATFinMes BIT=Null,@pmSegFinMes BIT=Null,@pmDchDotacion BIT=Null
--parametros de empleados
,@pmTipoSangre CHAR(2)=Null,@pmFactorRh CHAR(1)=Null,@pmSexo CHAR(1)=Null,@pmIdEstCivil VARCHAR(4)=Null,@pmClaseLib INT=Null, @pmIdProf VARCHAR(4)=Null,@pmTallaCam CHAR(2)=Null
,@pmTallaPan CHAR(2)=Null,@pmTallaZap CHAR(2)=Null,@pmIdFonPen VARCHAR(8)=Null,@pmIdFonEps VARCHAR(8)=Null,@pmIdFonArp VARCHAR(8)=Null,@pmIdFonCes VARCHAR(8)=Null,@pmIdCajaCom VARCHAR(8)=Null
,@pmIdBanco VARCHAR(4)=Null,@pmEmp_IdEstado VARCHAR(4)=Null,@pmEmp_Inactivo BIT=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null
 AS 

 SELECT  C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo
,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania
,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP
,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,C.FecAdd AS Fec_Add,C.FecUpdate AS Fec_Update
,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,IdCot,C.IdGrupo AS GrupAR,VrUpc
--empleados
,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion
,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja
,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS Emp_IdEstado
,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,TipoId,Codigo,ET.NColor AS EmpEstcolor,E.FechaAdd AS EmpFecAdd,E.FechaUpdate AS EmpFecupd,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario,SubTipoCot
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE C.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND C.IdSubCos LIKE ISNULL(@pmIdSubCos,'%')  AND C.IdNom LIKE ISNULL(@pmIdNom,'%') 
 AND C.TipoLiquida LIKE ISNULL(@pmTipoLiquida,'%') AND FPnomina LIKE ISNULL(@pmFPnomina,'%')  AND C.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (C.NContrato>=ISNULL(@pmNContrato,0)  AND C.NContrato<=ISNULL(@pmNContrato,2147483647)) 
 AND (ModoRet>=ISNULL(@pmModoRet,0)  AND ModoRet<=ISNULL(@pmModoRet,2147483647)) 
 AND (SalMinimo=ISNULL(@pmSalMinimo,0) or SalMinimo=ISNULL(@pmSalMinimo,1))
 AND (Indefinido=ISNULL(@pmIndefinido,0) or Indefinido=ISNULL(@pmIndefinido,1))
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (ATFinMes=ISNULL(@pmATFinMes,0) or ATFinMes=ISNULL(@pmATFinMes,1))
 AND (SegFinMes=ISNULL(@pmSegFinMes,0) or SegFinMes=ISNULL(@pmSegFinMes,1))
 AND (DchDotacion=ISNULL(@pmDchDotacion,0) or DchDotacion=ISNULL(@pmDchDotacion,1))
 AND (FecIngreso>=ISNULL(@pmFecIngresoIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngresoFin,CAST('20781230' AS SMALLDATETIME)))
 AND TipoSangre LIKE ISNULL(@pmTipoSangre,'%%') AND FactorRh LIKE ISNULL(@pmFactorRh,'%') AND Sexo LIKE ISNULL(@pmSexo,'%')
 AND IdEstCivil LIKE ISNULL(@pmIdEstCivil,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%') AND TallaCam LIKE ISNULL(@pmTallaCam,'%%')
 AND TallaPan LIKE ISNULL(@pmTallaPan,'%%') AND TallaZap LIKE ISNULL(@pmTallaZap,'%%') AND IdFonPen LIKE ISNULL(@pmIdFonPen,'%')
 AND IdFonCes LIKE ISNULL(@pmIdFonCes,'%') AND IdFonArp LIKE ISNULL(@pmIdFonArp,'%') AND IdFonEps LIKE ISNULL(@pmIdFonEps,'%')
 AND IdCajaCom LIKE ISNULL(@pmIdCajaCom ,'%') AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND E.IdEstado LIKE ISNULL(@pmEmp_IdEstado,'%')
 AND (ClaseLib>=ISNULL(@pmClaseLib,0)  AND ClaseLib<=ISNULL(@pmClaseLib,2147483647)) 
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,C.NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoEca @pmIdCargo VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmIdProf VARCHAR(4)=Null,@pmSexo CHAR(1)=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null
AS 
 SELECT C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,TipoId,Codigo,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo
,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia
,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps
,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo
,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS Emp_IdEstado,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,ET.NColor AS EmpEstcolor,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario
--datos del contrato
,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion
,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,SubTipoCot
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE   C.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')  AND C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND Sexo LIKE ISNULL(@pmSexo,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,C.NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoId
 AS 
 SELECT MAX(NContrato) AS MXNCON
 FROM Emp_Contrato


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoLab @pmNContrato INT,@pmInactivo BIT=Null
 AS 
 SELECT  C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo
,C.IdJornada AS IdJrnada,Jornada,Rangos,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdClase AS CodCla,ClaseRiesgo,Tarifa,TipoTrabj,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdNom AS CodNom
,TipoNomina,Asistencia,NoDevenga,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac
,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,C.Inactivo AS Inactvo,IdCot,C.IdGrupo AS GrupAR,VrUpc,SubTipoCot
--datos del empleado
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp
,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo
,E.IdProf AS CodProf,Profesion,Observacion,E.IdEstado AS Emp_IdEstdo,ET.Estado AS Emp_Estdo,E.Inactivo AS Emp_Inactivo
,C.FecAdd AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdUsuario AS IdUsuari,Usuario
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado
 WHERE  C.NContrato=@pmNContrato  AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoNom @pmNContrato INT
 AS 
 SELECT  IdEmpleado,NContrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo
,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdClase AS CodClase,ClaseRiesgo,TipoTrabj,C.IdCCosto AS IdCCto,CCosto
,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdNom AS CodNom,TipoNomina,C.IdEstado AS IdEstdCon,Estado,C.Inactivo AS Inactvo,C.IdUsuario AS IdUsuari,Usuario
 FROM Emp_Contrato AS C  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE NContrato=@pmNContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ContratoVce @pmFecAct SMALLDATETIME,@pmIdTipCon VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmFecIngresoIni SMALLDATETIME=Null,@pmFecIngresoFin SMALLDATETIME=Null,@pmIndefinido BIT=Null,@pmSalIntegral BIT=Null,@pmInactivo BIT=Null
AS
 SELECT C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,Duracion,FecIngreso,FecVigencia,DATEDIFF(day,ISNULL(FecVigencia,@pmFecAct),@pmFecAct) AS DiasVig
,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,C.IdCCosto AS IdCCto,CCosto
,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,ModPromdio,VrSalario,VrAuxTrans,VrUpc,SalMinimo,SalIntegral,FPnomina,ModoRet
,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon
,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,FecRetiro,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,IdCot,C.IdGrupo AS GrupAR,C.IdJornada AS IdJrnada,Jornada
--empleados
,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion
,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja
,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS Emp_IdEstado
,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,TipoId,Codigo,ET.NColor AS EmpEstcolor,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE  C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (Indefinido=ISNULL(@pmIndefinido,0) or Indefinido=ISNULL(@pmIndefinido,1))
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (FecIngreso>=ISNULL(@pmFecIngresoIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngresoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,C.NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_Estudios @pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT IdEmpleado,Item,Estblecmto,Titulo,Fecha
 FROM Emp_Estudios
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_EstudiosDso @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT ER.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Item,Estblecmto,Titulo,Fecha
 FROM Emp_Estudios AS ER INNER JOIN Empleados AS E ON ER.IdEmpleado=E.IdEmpleado
 WHERE ER.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY ER.IdEmpleado,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ExpLaboral @pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT IdEmpleado,Item,Empresa,Cargo,FecInicio,FecRetiro,DirEmpresa,TelEmpresa
 FROM Emp_ExpLaboral
 WHERE IdEmpleado=@pmIdEmpleado  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ExpLaboralDso @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT L.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Item,Empresa,Cargo,FecInicio,FecRetiro,DirEmpresa,TelEmpresa
 FROM Emp_ExpLaboral AS L INNER JOIN Empleados AS E ON L.IdEmpleado=E.IdEmpleado
 WHERE L.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY L.IdEmpleado,Item


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_Parientes @pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT IdEmpleado,Item,Parntsco,Nombre,FecNacmto,UltGrado,Dirccion,Telefno
 FROM Emp_Parientes
 WHERE IdEmpleado=@pmIdEmpleado  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmp_ParientesDso @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT P.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Item,Parntsco,Nombre,P.FecNacmto AS FechaNaci,UltGrado,Dirccion,Telefno
 FROM Emp_Parientes AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado
 WHERE P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY P.IdEmpleado,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleados @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte
,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,CdFonAvp,IdClase,NumCuenta
,IdBanco,CdLocCue,NContrato,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic,FotoFirma,Observacion,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosBus @pmCodigo VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte
,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,CdFonAvp,IdClase,NumCuenta
,IdBanco,CdLocCue,NContrato,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,FotoEmp,FotoLic,FotoFirma,EsCondtor,pVehiculo,Observacion,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Empleados
 WHERE  Codigo=@pmCodigo
 ORDER BY IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosCna @pmIdNom VARCHAR(4),@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT E.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.NContrato AS NumContrato,IdArea,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
 WHERE E.Inactivo=0 AND  IdNom=@pmIdNom  AND IdArea LIKE ISNULL(@pmIdArea,'%') AND IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER  BY E.IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosCnt @pmIdNom VARCHAR(4),@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT E.IdEmpleado AS IdEmpledo,Apellidos,Nombres,IdLugarCed,LC.Localidad AS LugarCed,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom
,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,E.NContrato AS NumContrato,FecUltIng,FecUltRet,FecVincula,NCAnterior,FecIngAnt,FecRetAnt
,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,FecUltAum,FecUltCes
,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,EsCondtor,pVehiculo,E.IdEstado AS IdEst_Emp,ET.Estado AS Estad_Emp,E.Inactivo AS Inctivo,Codigo,E.IdUsuario  AS IdUsuar
--datos del contrato
,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,Rangos,C.IdArea AS CodArea,Area,C.IdDep AS CodDep
,Dependencia,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac
,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,TipoTrabj,IdCot,IdGrupo,VrUpc,Reclmto,Notas,C.IdEstado AS IdEst_Con,EC.Estado AS Estad_Con,C.Inactivo AS Inactvo,CdFonAvp
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
 INNER JOIN  Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado
 WHERE E.Inactivo=0 AND  C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER  BY E.IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosCod @pmIdEmpleado VARCHAR(16),@pmCodigo VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte
,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,CdFonAvp,IdClase,NumCuenta
,IdBanco,CdLocCue,NContrato,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,FotoEmp,FotoLic,FotoFirma,EsCondtor,pVehiculo,Observacion,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado or Codigo=@pmCodigo
 ORDER BY IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosCon @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT E.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.NContrato AS NContrto,Indefinido,IdDep,IdCCosto,IdNom,TipoLiquida,IdInstala,C.IdClase AS IdClaRie,ClaseRiesgo,Tarifa,TipoTrabj
,ModPromdio,VrSalario,FecVincula,NCAnterior,FecIngAnt,FecRetAnt,VrAuxTrans,SalMinimo,SalIntegral,E.IdEstado AS Emp_IdEstdo,E.Inactivo AS Emp_Inactivo,C.IdEstado AS Con_IdEstdo,C.Inactivo AS Con_Inactivo
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato AND E.IdEmpleado=C.IdEmpleado
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 WHERE E.IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosDso @pmTipoSangre CHAR(2)=Null,@pmFactorRh CHAR(1)=Null,@pmSexo CHAR(1)=Null,@pmIdEstCivil VARCHAR(4)=Null,@pmClaseLib INT=Null, @pmIdProf VARCHAR(4)=Null,@pmTallaCam CHAR(2)=Null
,@pmTallaPan CHAR(2)=Null,@pmTallaZap CHAR(2)=Null,@pmIdFonPen VARCHAR(8)=Null,@pmIdFonEps VARCHAR(8)=Null,@pmIdFonArp VARCHAR(8)=Null,@pmIdFonCes VARCHAR(8)=Null,@pmIdCajaCom VARCHAR(8)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmNContrato INT=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT Apellidos,Nombres,TipoId,IdEmpleado,IdLugarCed,LC.Localidad AS LugarCed,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,LibMilitar,ClaseLib
,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo
,ConyFing,ConyTel,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,NContrato,FecVincula
,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS IdEstdo,Estado,E.Inactivo AS Inctivo,Dv,Codigo,NColor,FechaAdd,FechaUpdate,E.IdUsuario AS IdUsuari,Usuario,CdFonAvp
 FROM Empleados AS E INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 WHERE IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND TipoSangre LIKE ISNULL(@pmTipoSangre,'%%') AND FactorRh LIKE ISNULL(@pmFactorRh,'%') AND Sexo LIKE ISNULL(@pmSexo,'%')
 AND IdEstCivil LIKE ISNULL(@pmIdEstCivil,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%') AND TallaCam LIKE ISNULL(@pmTallaCam,'%%')
 AND TallaPan LIKE ISNULL(@pmTallaPan,'%%') AND TallaZap LIKE ISNULL(@pmTallaZap,'%%') AND IdFonPen LIKE ISNULL(@pmIdFonPen,'%')
 AND IdFonCes LIKE ISNULL(@pmIdFonCes,'%') AND IdFonArp LIKE ISNULL(@pmIdFonArp,'%') AND IdFonEps LIKE ISNULL(@pmIdFonEps,'%')
 AND IdCajaCom LIKE ISNULL(@pmIdCajaCom ,'%') AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (ClaseLib>=ISNULL(@pmClaseLib,0)  AND ClaseLib<=ISNULL(@pmClaseLib,2147483647)) 
 AND (NContrato>=ISNULL(@pmNContrato,-1)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (E.Inactivo=ISNULL(@pmInactivo,0) or E.Inactivo=ISNULL(@pmInactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosLab @pmIdEmpleado VARCHAR(16),@pmCodigo VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,IdLugarCed,LC.Localidad AS LugarCed,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom
,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,NContrato,FecVincula
,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,FecUltAum,FecUltCes
,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,E.IdEstado AS IdEstdo,Estado,E.Inactivo AS Inctivo,Codigo,IdUsuario,CdFonAvp
 FROM Empleados AS E INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado
 WHERE IdEmpleado=@pmIdEmpleado OR Codigo=@pmCodigo
 ORDER  BY IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosReg @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,Direccion,IdLocal,Telefono,e_mail,NContrato,FecVincula
 FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosSue @pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null
,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmSalMinimo BIT=Null,@pmSalIntegral BIT=Null,@pmIdEmpleado VARCHAR(16),@pmInactivo BIT=Null
,@pmEmp_Inactivo BIT=Null,@pmEsCondtor BIT=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT E.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Codigo,FecNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,FecUltAum,FecVincula,FecUltDot,NCAnterior,FecIngAnt
,FecRetAnt,EsCondtor,pVehiculo,E.IdEstado AS Emp_IdEstdo,ET.Estado AS Emp_Estado,E.Inactivo AS Emp_Inactvo
--datos del contrato
,E.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion
,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina
,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor
,C.Inactivo AS Inactvo,C.FecAdd AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdUsuario AS IdUsuari,Usuario
 FROM Empleados  AS E INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo  INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo 
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado 
 INNER JOIN Emp_Contrato AS C  ON E.IdEmpleado=C.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 WHERE  C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')  AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')   AND  C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND  E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (SalMinimo=ISNULL(@pmSalMinimo,0) or SalMinimo=ISNULL(@pmSalMinimo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Apellidos,Nombres,E.NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosVac @pmDias INT,@pmFecVacIni SMALLDATETIME,@pmFecVacFin SMALLDATETIME,@pmIdProf VARCHAR(4)=Null
,@pmEmp_IdEstado VARCHAR(4)=Null,@pmEmp_Inactivo BIT=Null,@pmEsCondtor BIT=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmFecIngresoIni SMALLDATETIME=Null,@pmFecIngresoFin SMALLDATETIME=Null,@pmSalIntegral BIT=Null
 AS 
 SELECT E.IdEmpleado AS IdEmplado,Apellidos,Nombres,Codigo,TipoId,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,FecNacmto,LugarNacmto,TipoSangre
,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia
,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase
,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
,IdCajaCom,CC.Fondo AS CajaComp,E.NContrato AS NCntrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic
,FotoFirma,Observacion,E.IdEstado AS Emp_IdEstado,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,ET.NColor AS EmpEstcolor,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario
--Datos del contrato
,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto
,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina
,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyCes,DenyPri,DenyVac,DchDotacion,DchCafeteria,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,VrUpc
,IdCot,C.IdGrupo AS GrupAR
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo 
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep 
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala 
 INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom 
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado  INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 WHERE DATEADD(day,@pmDias,ISNULL(FecUltVac,FecIngreso)) BETWEEN @pmFecVacIni AND @pmFecVacFin AND E.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND E.IdEstado LIKE ISNULL(@pmEmp_IdEstado,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (FecIngreso>=ISNULL(@pmFecIngresoIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngresoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEmpleadosVeh  @pmpVehiculo VARCHAR(10),@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,NContrato,EsCondtor,pVehiculo
 FROM Empleados
 WHERE Inactivo=0 AND pVehiculo=@pmpVehiculo AND  IdEmpleado<>@pmIdEmpleado
 ORDER BY IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEntidades @pmIdTabla VARCHAR(20)
 AS 
 SELECT IdTabla,NivelRel,CamposPK,FngKey,Sp_Qry,Sp_Qpmt,Sp_Ins,Sp_Upd,Sp_Del
 FROM Sys_Entidades
 WHERE IdTabla LIKE ISNULL(@pmIdTabla,'%')
 ORDER BY IdTabla

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEstaciones @pmIdEstacion CHAR(2)
 AS 
 SELECT IdEstacion,Estacion
 FROM Sys_Estaciones
 WHERE IdEstacion LIKE ISNULL(@pmIdEstacion,'%%')
 ORDER BY IdEstacion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEstacionesDso
 AS 
 SELECT IdEstacion,Estacion,IdEstacion+' '+Estacion AS DsEst
 FROM Sys_Estaciones
 ORDER BY IdEstacion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEstadoCiv @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,EstCivil  FROM EstadoCiv
  WHERE  Inactivo=0
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,EstCivil,Inactivo
  FROM EstadoCiv
  WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEstadoDoc @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor,CodDcmto
  FROM EstadoDoc
  WHERE Inactivo=0
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,CodDcmto,Inactivo
  FROM EstadoDoc
  WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEstadoDocDso @pmCodDcmto VARCHAR(3)=Null
 AS 
 IF @pmCodDcmto IS NULL
  SELECT IdEstado,Estado,NColor,CodDcmto
  FROM EstadoDoc
  WHERE Inactivo=0 
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,CodDcmto
  FROM EstadoDoc
  WHERE Inactivo=0 AND ( CodDcmto=@pmCodDcmto OR CodDcmto='0' OR LEN(CodDcmto)=0)
  ORDER BY  IdEstado


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryEstadoTer @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor
  FROM EstadoTer
  WHERE Inactivo=0
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,Inactivo
  FROM EstadoTer
  WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryExpLicencias @pmIdLugar VARCHAR(8)
 AS 
 IF @pmIdLugar IS NULL
  SELECT IdLugar,LugarLic,CodDpto,Dpto  FROM ExpLicencias
  WHERE Inactivo=0
  ORDER BY LugarLic
 ELSE
  SELECT IdLugar,LugarLic,CodDpto,Dpto,Inactivo 
  FROM ExpLicencias
  WHERE IdLugar=@pmIdLugar

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryExpLicenciasDso
 AS 
 SELECT IdLugar,LugarLic,Dpto,LugarLic+' ('+ Dpto + ')' AS DsLug  FROM ExpLicencias
 WHERE Inactivo=0
 ORDER BY LugarLic


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFields @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20)=Null
 AS 
 SELECT IdEntidad,IdCampo,Descripcion,TipoDato,LongMax,Requerido,PmryKey,FmtValue,DftValue,AliasFld,AliasQry2,IndField
,TipoEntidad,LstTipo,LstClnaValor,LstClnaLista,LstQuery,Inactivo
 FROM Sys_Fields
 WHERE IdEntidad=@pmIdEntidad AND IdCampo LIKE ISNULL(@pmIdCampo,'%')
 ORDER BY IndField

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFieldsLta @pmIdEntidad VARCHAR(30),@pmTipoEntidad VARCHAR(5)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdEntidad,IdCampo,Descripcion,TipoDato,LongMax,Requerido,PmryKey,FmtValue,DftValue,AliasFld,AliasQry2,IndField
,TipoEntidad,LstTipo,LstClnaValor,LstClnaLista,LstQuery,Inactivo
 FROM Sys_Fields
 WHERE IdEntidad=@pmIdEntidad AND TipoEntidad LIKE ISNULL(@pmTipoEntidad,'%') 
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IndField

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFmtDoc @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2)
 AS 
 SELECT IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
 FROM Sys_FmtDoc
 WHERE IdDoc LIKE ISNULL(@pmIdDoc,'%')  AND IdForma LIKE ISNULL(@pmIdForma,'%%')
 ORDER BY IdDoc,IdForma

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFmtDocDft @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2)=Null,@pmDescripcion VARCHAR(100)=Null
AS 
 IF @pmIdForma IS NULL And @pmDescripcion IS NULL
  SELECT IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
  FROM Sys_FmtDoc
  WHERE IdDoc=@pmIdDoc AND Predtmnado<>0
  ORDER BY IdForma
 ELSE
  SELECT IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
  FROM Sys_FmtDoc
  WHERE IdDoc=@pmIdDoc AND IdForma LIKE ISNULL(@pmIdForma,'%%') AND Descripcion LIKE ISNULL(@pmDescripcion,'%')
  ORDER BY IdForma


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFmtDocDso @pmIdDoc VARCHAR(3)
 AS
  SELECT IdDoc,IdForma,Descripcion,Formato,IdForma + ' '+Descripcion AS DsFor
  FROM Sys_FmtDoc
  WHERE IdDoc=@pmIdDoc
 ORDER BY IdForma


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFondos @pmIdFondo VARCHAR(8)
 AS 
  SELECT IdFondo,Fondo,IdClase,IdTercero,Inactivo
  FROM Fondos
  WHERE IdFondo=@pmIdFondo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFondosCla @pmIdClase VARCHAR(4)
 AS 
  SELECT IdFondo,Fondo,IdClase,IdTercero,Inactivo
  FROM Fondos
  WHERE IdClase=@pmIdClase
  ORDER BY IdFondo


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFondosDso @pmIdClase VARCHAR(4)
 AS
 IF @pmIdClase IS NULL
  SELECT IdFondo,Fondo,IdTercero  FROM Fondos  WHERE Inactivo=0  ORDER BY Fondo
 ELSE
  SELECT IdFondo,Fondo,IdTercero  FROM Fondos
  WHERE Inactivo=0 AND (IdClase=@pmIdClase OR IdClase='0')
  ORDER BY Fondo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFondosLta @pmIdClase VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS
  SELECT IdFondo,Fondo,F.IdClase AS CodClase,ClaseFondo,IdTercero,F.Inactivo AS Inctivo
  FROM Fondos AS F INNER JOIN ClaseFon AS C ON F.IdClase=C.IdClase
  WHERE F.IdClase LIKE ISNULL(@pmIdClase,'%') 
  AND (F.Inactivo=ISNULL(@pmInactivo,0) or F.Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Fondo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryFondosPen @pmIdClase VARCHAR(4)
 AS
  SELECT IdFondo,Fondo,IdTercero  FROM Fondos
  WHERE Inactivo=0 AND (IdClase=@pmIdClase OR IdClase='0' OR IdClase='0008')
  ORDER BY Fondo



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposAR @pmIdGrupo VARCHAR(4)
 AS 
 IF @pmIdGrupo IS NULL
  SELECT IdGrupo,AltoRiesgo,TarfaTrab,TarfaEmp
  FROM GruposAR
  WHERE Inactivo=0
  ORDER BY IdGrupo
 ELSE
  SELECT IdGrupo,AltoRiesgo,TarfaTrab,TarfaEmp,Inactivo
  FROM GruposAR
  WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposDso  @pmIdLinea VARCHAR(8)=Null
 AS 
 SELECT IdGrupo,Grupo,Grupo+' '+IdGrupo + ' ('+Linea+')'  AS DsGru
 FROM Grupos AS G INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE G.Inactivo=0 AND  G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 ORDER BY Linea,Grupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposLin  @pmIdGrupo VARCHAR(8)=Null
 AS 
 SELECT IdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,G.Inactivo AS Inactiv
 FROM Grupos AS G INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY Linea,Grupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposLta  @pmIdLinea VARCHAR(8)=Null
 AS 
 SELECT IdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
 FROM Grupos AS G INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE G.Inactivo=0 AND  G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 ORDER BY Linea,Grupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposObj @pmIdGrupo VARCHAR(6),@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdGrupo,GrupoObjeto,nModulo
 FROM Sys_GruposObj
 WHERE IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY nModulo,IdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposUsu @pmIdGrupo INT
 AS 
 SELECT IdGrupo,Grupo,Descripcion
 FROM Sys_GruposUsu
 WHERE (IdGrupo>=ISNULL(@pmIdGrupo,0)  AND IdGrupo<=ISNULL(@pmIdGrupo,2147483647)) 
 ORDER BY IdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryGruposUsuDso @pmIdGrupo INT
 AS 
 SELECT IdGrupo,Grupo,Descripcion,STR(IdGrupo,2,0)+'  '+Grupo AS DsGru
 FROM Sys_GruposUsu
 WHERE  IdGrupo<=@pmIdGrupo
 ORDER BY IdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryInstalaciones @pmIdInstala VARCHAR(4)
 AS 
 SELECT IdInstala,Instlacion,DirInstala,CodCiu,CodCia,IdClase,Inactivo
 FROM Instalaciones
 WHERE IdInstala=@pmIdInstala

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryInstalacionesLta @pmCodCia CHAR(2)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdInstala,Instlacion,DirInstala,CodCiu,Localidad,CodCia,Compania,I.IdClase AS CodClase,ClaseRiesgo,Tarifa,I.Inactivo AS Inctivo
 FROM Instalaciones AS I INNER JOIN ClaseRie AS CR ON I.IdClase=CR.IdClase
 LEFT JOIN Localidades AS L ON I.CodCiu=L.IdLocal LEFT JOIN  Companias AS C ON I.CodCia=C.IdCia 
 WHERE CodCia LIKE ISNULL(@pmCodCia,'%%') 
 AND (I.Inactivo=ISNULL(@pmInactivo,0) or I.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Instlacion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryJornadas @pmIdJornada VARCHAR(4)
 AS 
 IF @pmIdJornada IS NULL
  SELECT IdJornada,Jornada,HorasDia,Rangos  FROM Jornadas
  WHERE Inactivo=0
  ORDER BY IdJornada
 ELSE
  SELECT IdJornada,Jornada,HorasDia,Rangos,Inactivo 
  FROM Jornadas
  WHERE IdJornada=@pmIdJornada

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryLocalidades @pmIdLocal VARCHAR(8)
 AS 
 SELECT IdLocal,Localidad,IdDep,TipLocal,Dist_Kmt,Time_hh,DistSede,TimeSede,CelRow,CelCol,CodAlias,Inactivo
 FROM Localidades
 WHERE IdLocal=@pmIdLocal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryLocalidadesDso @pmIdDep VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdLocal,Localidad,L.IdDep AS CodDep,Departamento,TipLocal
, Localidad+ '  ('+ Departamento + ')' AS NomCiudad 
 FROM Localidades AS L INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE  L.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND (L.Inactivo=ISNULL(@pmInactivo,0) or  L.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Localidad,Departamento

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryLocalidadesLta @pmIdDep VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdLocal,Localidad,L.IdDep AS CodDep,Departamento,TipLocal,Dist_Kmt,Time_hh
,DistSede,TimeSede,CelRow,CelCol,CodAlias,L.Inactivo AS Inactvo
 FROM Localidades AS L INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE  L.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND (L.Inactivo=ISNULL(@pmInactivo,0) or  L.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Localidad

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryLocalidadesNom @pmLocalidad VARCHAR(50)
 AS 
 SELECT IdLocal,Localidad,IdDep,TipLocal
 FROM Localidades
 WHERE Localidad=@pmLocalidad
 ORDER BY IdLocal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryLog_Nomina @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8)
 AS 
 SELECT IdPeriodo,IdNom,Cerrado,IntCtaCte,LogCtaCte
 FROM Log_Nomina
 WHERE IdNom LIKE ISNULL(@pmIdNom,'%') AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 ORDER BY IdPeriodo,IdNom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryLog_Periodos @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdCia,Anno,Ene,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic,CierreAnno
 FROM Log_Periodos
  WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))
 ORDER  BY IdCia,Anno

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryModulos @pmIdMod VARCHAR(3),@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdMod,Consecutivo,Descripcion,Valor,nModulo
 FROM Sys_Modulos
 WHERE IdMod LIKE ISNULL(@pmIdMod,'%') AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY Consecutivo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryModulosId @pmnModulo VARCHAR(10)=Null
 AS 
 SELECT MAX(Consecutivo) AS MXconce
 FROM Sys_Modulos
 WHERE nModulo LIKE ISNULL(@pmnModulo,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAbonos @pmNPrestamo INT,@pmItem INT
 AS 
 SELECT NPrestamo,Item,IdEmpleado,FechaAbo,VrAbono,nCuotas,Dscto,IdPeriodo,Detalle,NLiquida
 FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAbonosId @pmNPrestamo INT
 AS 
 SELECT MAX(Item) AS MXITEM
 FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAbonosLiq @pmDscto VARCHAR(3),@pmNLiquida INT,@pmIdEmpleado VARCHAR(16)=Null
AS 
 SELECT NPrestamo,SUM(VrAbono) AS SABONO,SUM(nCuotas) AS SCUOTAS
 FROM Trn_NomAbonos
 WHERE Dscto=@pmDscto AND NLiquida=@pmNLiquida  AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')
 GROUP BY NPrestamo


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAbonosPer @pmIdPeriodo VARCHAR(8),@pmDscto VARCHAR(3),@pmIdEmpleado VARCHAR(16)=Null
AS 
 SELECT NPrestamo,SUM(VrAbono) AS SABONO,SUM(nCuotas) AS SCUOTAS
 FROM Trn_NomAbonos
 WHERE IdPeriodo=@pmIdPeriodo AND Dscto LIKE ISNULL(@pmDscto,'%')  AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')
 GROUP BY NPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAbonosPre @pmNPrestamo INT,@pmIdPeriodo VARCHAR(8)=Null,@pmDscto VARCHAR(3)=Null
,@pmNLiquida INT=Null
AS 
 SELECT SUM(VrAbono) AS SABONO,SUM(nCuotas) AS SCUOTAS
 FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND Dscto LIKE ISNULL(@pmDscto,'%') 
 AND  (NLiquida>=ISNULL(@pmNLiquida,0)  AND NLiquida<=ISNULL(@pmNLiquida,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAlqDet @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,IdEmpleado,NContrato,Apellido1,Apellido2,Nombre1,Nombre2,IdFonPen,IdFonSal,IdFonRie,IdCajCom,SalBasico,VrIBCPen,DiasPen,TarifPen,VrPension,VrApoFsp,VrApoFsu,VrApoVolAfi,VrApoVolApt
,VrNoReten,VrIBCSal,DiasSal,TarifSal,VrSalud,VrUpc,VrIncap,VrLicencia,NumAutInc,NumAutLic,VrIBCRie,DiasRie,TarifRie,VrRiesgos,VrIncIrp,NumAutIrp,IdInstala,VrIBCRef,VrIBCCajas,DiasCom,TarifCom,VrCajas,TarifSen,VrSena,TarifIcb
,VrICBF,TarifEsap,VrESAP,TarifEdu,VrMinEdu,TarifFsp,TarifFsu,CdFonAvp
 FROM Trn_NomAlqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAlqNov @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,IdEmpleado,NovIng,NovRet,NovTde,NovTae,NovTdp,NovTap,NovVsp,NovVte,NovVst,NovSln,NovIge,NovLma,NovVac,NovAvp
,NovVct,NovIrp,CodNewPen,CodNewSal,CodNewIns,CodNewRie,CodNewGru,DiasNov
 FROM Trn_NomAlqNov
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAlqTot @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,TipAdm,IdFondo,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora
,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF,TipoReg
 FROM Trn_NomAlqTot
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAlqTot_Cr @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmTipAdm VARCHAR(3)=Null
,@pmIdFondo VARCHAR(8)=Null
 AS 
 SELECT TipoLiq,Numero,Item,TipAdm,T.IdFondo AS CodFondo,Fondo,F.IdTercero AS NitFondo,RazonSocial,TipoId,Dv,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc
,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF,TipoReg
 FROM Trn_NomAlqTot AS T LEFT JOIN Fondos AS F ON T.IdFondo=F.IdFondo
 LEFT JOIN Terceros AS TF ON F.IdTercero=TF.IdTercero
 WHERE TipoLiq=@pmTipoLiq AND Numero LIKE ISNULL(@pmNumero,'%') AND TipAdm LIKE ISNULL(@pmTipAdm,'%')
 AND T.IdFondo LIKE ISNULL(@pmIdFondo,'%')
 ORDER BY Numero,TipoReg,TipAdm,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAportante @pmIdAportnte VARCHAR(16)
 AS 
 SELECT IdAportnte,RazonSocial,TipoId,DvNit,IdRepLegal,Direccion,IdLocal,Telefono,Fax,e_mail,ClaseApo,TipoEco,TipoPersna,CIIUDane,FecIniCndato
,TipAccCndato,FecFinCndato,CodOperInfo,TipoApo,FecAdd,FecUpdate,IdUsuario
 FROM NomAportante
 WHERE IdAportnte LIKE ISNULL(@pmIdAportnte,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAportanteReg
 AS 
 SELECT COUNT(IdAportnte) AS SCanApo
 FROM NomAportante


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAstncia @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME
 AS 
 SELECT IdEmpleado,FechaDia,HHDiurno,HHNocturno,HEDiurno,HENocturno,TipoJrnada,EsDmncal,Horario,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomAstncia
 WHERE IdEmpleado=@pmIdEmpleado AND FechaDia=@pmFechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAstnciaLta @pmIdEmpleado VARCHAR(16)=Null,@pmFecInicio SMALLDATETIME=Null,@pmFecFinal SMALLDATETIME=Null
,@pmEsDmncal BIT=Null,@pmTipoJrnada VARCHAR(10)=Null
 AS 
 SELECT A.IdEmpleado AS IdEmplado,Apellidos,Nombres,FechaDia,HHDiurno,HHNocturno,HEDiurno,HENocturno,TipoJrnada,EsDmncal,Horario,TimeSys,A.FecUpdate AS FecUpd
,A.IdUsuario AS IdUsuari,Usuario,E.NContrato AS NumContrato,FecIngreso,FecRetiro,VrSalario,VrAuxTrans,C.IdNom AS CodNom,TipoNomina,pVehiculo
 FROM Trn_NomAstncia AS A INNER JOIN Empleados AS E ON A.IdEmpleado=E.IdEmpleado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 WHERE  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal AND A.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
  AND TipoJrnada LIKE ISNULL(@pmTipoJrnada,'%')
 AND (EsDmncal=ISNULL(@pmEsDmncal,0) or EsDmncal=ISNULL(@pmEsDmncal,1))
 ORDER BY Apellidos,Nombres,FechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAstnciaTip @pmTipo CHAR(1),@pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
 AS 
 IF @pmTipo='D' --descansos
  SELECT Count(FechaDia) AS Cant,SUM(HHDiurno) AS STotHHD,SUM(HHNocturno) AS STotHHN,SUM(HEDiurno) AS STotHED ,SUM(HENocturno) AS STotHEN
  FROM Trn_NomAstncia
  WHERE IdEmpleado=@pmIdEmpleado AND  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal 
   AND TipoJrnada IN ('DESCANSO','DSCSINCOMP')
 ELSE --SIN COMPENSATORIOS
  SELECT Count(FechaDia) AS Cant,SUM(HHDiurno) AS STotHHD,SUM(HHNocturno) AS STotHHN,SUM(HEDiurno) AS STotHED ,SUM(HENocturno) AS STotHEN
  FROM Trn_NomAstncia
  WHERE IdEmpleado=@pmIdEmpleado AND  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal 
   AND TipoJrnada IN ('SINCOMP','DSCSINCOMP')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAstnciaTot @pmIdEmpleado VARCHAR(16)=Null,@pmFecInicio SMALLDATETIME=Null,@pmFecFinal SMALLDATETIME=Null
,@pmEsDmncal BIT=Null,@pmTipoJrnada VARCHAR(10)=Null
 AS 
 SELECT Count(FechaDia) AS Cant,SUM(HHDiurno) AS STotHHD,SUM(HHNocturno) AS STotHHN,SUM(HEDiurno) AS STotHED ,SUM(HENocturno) AS STotHEN
 FROM Trn_NomAstncia
 WHERE  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND TipoJrnada LIKE ISNULL(@pmTipoJrnada,'%')
 AND (EsDmncal=ISNULL(@pmEsDmncal,0) or EsDmncal=ISNULL(@pmEsDmncal,1))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAutoliq @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20)
 AS 
 SELECT TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,IdAportnte,Presentacion,CodCia,CodFondo,CodArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,VrPension,VrSalud,VrRiesgos,VrCajas,VrSena,VrIcbf,VrEsap,VrMinEduc,TotalAfipen,TotalAfiSal
,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,Observacion,LogAdmon,RedoMiles,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario,TipoPlanilla
 FROM Trn_NomAutoliq
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAutoliqDso @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipoLiq VARCHAR(3)=Null,@pmNumero VARCHAR(20)=Null
,@pmPerAutoliq VARCHAR(6)=Null,@pmCodFondo VARCHAR(8)=Null,@pmEsCorr BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmPresentacion CHAR(1)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,A.IdAportnte AS NitAportnte,RazonSocial,Presentacion,CodCia,CodFondo,F.Fondo AS NomFondo,CodArp,FR.Fondo AS FondoArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,VrPension,VrSalud,VrRiesgos
,VrCajas,VrSena,VrIcbf,VrEsap,VrMinEduc,TotalAfipen,TotalAfiSal,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,Observacion
,LogAdmon,RedoMiles,Anulado,A.IdEstado AS IdEstdo,Estado,TipoPlanilla,TimeSys,A.FecUpdate AS Fec_Updte,A.IdUsuario AS IdUsuari,Usuario
 FROM Trn_NomAutoliq AS A INNER JOIN NomAportante AS NA ON A.IdAportnte=NA.IdAportnte
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Fondos AS F ON A.CodFondo=F.IdFondo LEFT JOIN Fondos AS FR ON A.CodArp=FR.IdFondo
 WHERE TipoLiq LIKE ISNULL(@pmTipoLiq,'%') AND Numero LIKE ISNULL(@pmNumero,'%') AND PerAutoliq LIKE ISNULL(@pmPerAutoliq,'%')
 AND CodFondo LIKE ISNULL(@pmCodFondo,'%') AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND Presentacion LIKE ISNULL(@pmPresentacion,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EsCorr=ISNULL(@pmEsCorr,0) or EsCorr=ISNULL(@pmEsCorr,1))
 ORDER BY TipoLiq,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAutoliqPer @pmTipoLiq VARCHAR(3),@pmPerAutoliq VARCHAR(6),@pmNumero VARCHAR(20),@pmPresentacion CHAR(1)=Null
,@pmCodCia CHAR(2)=Null,@pmCodFondo VARCHAR(8)=Null,@pmEsCorr BIT=Null
 AS 
 SELECT TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,Presentacion,CodCia,CodFondo,EsCorr
 FROM Trn_NomAutoliq
 WHERE TipoLiq=@pmTipoLiq AND PerAutoliq=@pmPerAutoliq AND Anulado=0 AND Numero<>@pmNumero AND Presentacion LIKE ISNULL(@pmPresentacion,'%')
 AND CodCia LIKE ISNULL(@pmCodCia,'%%') AND CodFondo LIKE ISNULL(@pmCodFondo,'%')
 AND  (EsCorr=ISNULL(@pmEsCorr,0) or EsCorr=ISNULL(@pmEsCorr,1))
 ORDER BY  Fecha,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomAutoliq_Cr @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmPerAutoliq VARCHAR(6)=Null
AS
 SELECT  A.TipoLiq AS TipoPla,A.Numero AS NumPla,Fecha,PerAutoliq,PerAutoSal,FechaPago,A.IdAportnte AS NitAportnte,NA.RazonSocial AS NomAportante,Presentacion,A.CodCia AS CodSucur,Compania,CodSucsal,DireccSuc,TelefSuc,CI.IdLocal AS CodCiuSuc
,LC.Localidad AS CiudadSuc,LC.IdDep AS CodDepSuc,CodFondo,F.Fondo AS NomFondo,CodArp,FRP.Fondo AS FondoArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,A.VrPension AS Total_Pen,A.VrSalud AS Total_Sal,A.VrRiesgos AS Total_Rie,A.VrCajas AS Total_Caj
,A.VrSena AS Total_Sen,A.VrIcbf AS Total_ICB,A.VrEsap AS Total_ESA,VrMinEduc,TotalAfipen,TotalAfiSal,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,A.Observacion AS Observ,LogAdmon,RedoMiles
,Anulado,A.IdEstado AS IdEstdo,Estado,TimeSys,A.FecUpdate AS Fec_Update,A.IdUsuario AS IdUsuari,Usuario
--datos del aportante
,NA.TipoId AS Apo_TipID,DvNit,IdRepLegal,RLG.RazonSocial AS NomRepLegal,RLG.TipoId AS RLegTID,RLG.Dv AS RLegDV,NA.Direccion AS Apo_dirccion,NA.IdLocal AS Apo_CodCiu,LA.Localidad AS Apo_NomCiu,LA.IdDep AS Apo_CodDep,Departamento,NA.Telefono AS Apo_tel,NA.Fax AS Apo_Fax,NA.e_mail AS Apo_email
,ClaseApo,TipoEco,TipoPersna,CIIUDane,FecIniCndato,TipAccCndato,FecFinCndato,CodOperInfo,TipoApo
--datos del detalle
,D.Item AS DetItem,D.IdEmpleado AS IdEmpldo,D.NContrato AS NumContrato,Apellido1,Apellido2,Nombre1,Nombre2,D.IdFonPen AS IdFdoPen,FP.Fondo AS FondoPen,TFP.TipoId AS Pen_TipID,FP.IdTercero AS Pen_Nit,TFP.Dv AS Pen_DV,TFP.RazonSocial AS Pen_Nombre
,IdFonSal,FS.Fondo AS FondoSal,TFS.TipoId AS Sal_TipID,FS.IdTercero AS Sal_Nit,TFS.Dv AS Sal_Dv,TFS.RazonSocial AS Sal_Nombre,IdFonRie,FR.Fondo AS FondoRie,TFR.TipoId AS Rie_TipID,FR.IdTercero AS Rie_nit,TFR.Dv AS Rie_Dv,TFR.RazonSocial AS Rie_nombre
,IdCajCom,FC.Fondo AS FondoCc,TFC.TipoId AS CC_TipId,FC.IdTercero AS CC_Nit,TFC.Dv AS CC_DV,TFC.RazonSocial AS cc_Nombre,SalBasico,VrIBCPen,DiasPen,TarifPen,D.VrPension AS VlrPension,VrApoFsp,VrApoFsu,VrApoVolAfi,VrApoVolApt,VrNoReten,VrIBCSal,DiasSal,TarifSal,D.VrSalud AS VlrSalud,D.VrUpc AS VlrUpc
,VrIncap,VrLicencia,NumAutInc,NumAutLic,VrIBCRie,DiasRie,TarifRie,D.VrRiesgos AS VlrRiesgos,VrIncIrp,NumAutIrp,D.IdInstala AS CodInstla,I.Instlacion AS CentroTrabaj,I.CodCiu AS CiuInstala
,VrIBCRef,VrIBCCajas,DiasCom,TarifCom,D.VrCajas AS VlrCajas,TarifSen,D.VrSena AS VlrSena,TarifIcb,D.VrICBF AS Vlricbf,TarifEsap,D.VrESAP AS VlrESAP,TarifEdu,VrMinEdu,TarifFsp,TarifFsu
--datos de novedades
,NovIng,NovRet,NovTde,NovTae,NovTdp,NovTap,NovVsp,NovVte,NovVst,NovSln,NovIge,NovLma,NovVac,NovAvp,NovVct,NovIrp,CodNewPen,FNP.Fondo AS NewFonPen,CodNewSal,FNS.Fondo AS NewFonEPS,CodNewIns,NI.Instlacion AS NewCentroTrabj,CodNewRie,CRN.Tarifa AS New_TarRie,CodNewGru
,NGR.TarfaTrab AS NewTarfTrab,NGR.TarfaEmp AS NewTarfEmp,DiasNov
--datos del empleado
,Apellidos,Nombres,E.Codigo AS EmpCodigo,E.TipoId AS Emp_TipID,E.Dv AS Emp_Dv,E.IdLugarCed AS Emp_IdLugrCed,L.Localidad AS Lugar_Ced,L.IdDep AS Emp_CodDep,E.Direccion AS Dirccion,E.Telefono AS Emp_Telfono,E.TelMovil AS Emp_TelMovil,E.e_mail AS Emp_Email,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,NumCuenta
,E.IdBanco AS CodBanco,EsCondtor,pVehiculo,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,Licencia,CatLicencia,VigLicencia,TallaCam,TallaPan,TallaZap,IdEstCivil,EstCivil,NHijos,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDepe,Dependencia,C.IdCCosto AS CodCcto,CCosto,C.IdSubCos AS CodScost,SubCosto,C.IdNom AS CodTipNom,TipoNomina,C.IdClase AS CodClaRie,CR.ClaseRiesgo AS ClasRiesgo
,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,C.VrUpc AS Con_VrUpc,SalMinimo,SalIntegral,FPnomina,C.TipoLiquida AS TipLiq,FecAfiSeg,C.IdCot AS CodCotz,Cotizante,C.IdGrupo AS CodGrup,GAR.TarfaTrab AS Con_TrfaTrab,GAR.TarfaEmp AS TrfaEmp,TipoTrabj
,ATFinMes,SegFinMes,C.IdEstado AS Con_IdEstdo,C.Inactivo AS Con_inactivo,IdJornada,DenyPEN,DenyEPS,DenyARP,DenyCaj,D.CdFonAvp AS CodFondoAvp,E.CdFonAvp AS Emp_FondoAVP,TipoPlanilla,SubTipoCot
 FROM Trn_NomAutoliq AS A INNER JOIN Trn_NomAlqDet AS D ON A.TipoLiq=D.TipoLiq AND A.Numero=D.Numero 
 INNER JOIN  NomAportante AS NA ON A.IdAportnte=NA.IdAportnte  INNER JOIN Terceros AS RLG ON NA.IdRepLegal=RLG.IdTercero
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario INNER JOIN Localidades AS LA ON NA.IdLocal=LA.IdLocal
 INNER JOIN Departamentos AS DE ON LA.IdDep=DE.IdDep
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado INNER JOIN Fondos AS FP ON D.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON D.IdFonSal=FS.IdFondo INNER JOIN Fondos AS FR ON D.IdFonRie=FR.IdFondo
 INNER JOIN Fondos  AS FC ON D.IdCajCom=FC.IdFondo INNER JOIN Terceros AS TFP ON FP.IdTercero=TFP.IdTercero
 INNER JOIN Terceros AS TFS ON FS.IdTercero=TFS.IdTercero  INNER JOIN Terceros AS TFR ON FR.IdTercero=TFR.IdTercero
 INNER JOIN Terceros AS TFC ON FC.IdTercero=TFC.IdTercero  INNER JOIN Instalaciones AS I ON D.IdInstala=I.IdInstala
 INNER JOIN Emp_Contrato AS C ON D.NContrato=C.NContrato  INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep 
 INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom  INNER JOIN TiposCot AS TCZ ON C.IdCot=TCZ.IdCot
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 LEFT JOIN GruposAR AS GAR ON C.IdGrupo=GAR.IdGrupo
 LEFT JOIN Trn_NomAlqNov AS DN ON D.TipoLiq=DN.TipoLiq AND D.Numero=DN.Numero AND D.Item=DN.Item
 LEFT JOIN Fondos AS F ON A.CodFondo=F.IdFondo LEFT JOIN Fondos AS FRP ON A.CodArp=FRP.IdFondo
 LEFT JOIN Companias AS CI ON A.CodCia=CI.IdCia LEFT JOIN Localidades AS LC ON CI.IdLocal=LC.IdLocal
 LEFT JOIN Fondos AS FNP ON DN.CodNewPen=FNP.IdFondo  LEFT JOIN Fondos AS FNS ON DN.CodNewSal=FNS.IdFondo
 LEFT JOIN Instalaciones AS NI ON DN.CodNewIns=NI.IdInstala LEFT JOIN ClaseRie AS CRN ON DN.CodNewRie=CRN.IdClase
 LEFT JOIN GruposAR AS NGR ON DN.CodNewGru=NGR.IdGrupo
 WHERE A.TipoLiq=@pmTipoLiq AND A.Numero LIKE ISNULL(@pmNumero,'%') AND PerAutoliq LIKE ISNULL(@pmPerAutoliq,'%')
 ORDER BY A.Numero,Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCAdmon @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,ClaseAdmon,FecIniNov,NNovedad,IdFondo,IdFonNew,Observacion,Anulado,TimeSys,IdUsuario
 FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCAdmonCla @pmIdEmpleado VARCHAR(16),@pmClaseAdmon VARCHAR(10)
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,ClaseAdmon,FecIniNov,NNovedad,IdFondo,IdFonNew,Anulado
 FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado  AND Anulado=0 AND ClaseAdmon=@pmClaseAdmon
 ORDER BY Fecha

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCAdmonId @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCAdmon_Cr   @pmIdEmpleado VARCHAR(16)=Null,@pmNumero INT=Null,@pmClaseAdmon VARCHAR(10)=Null,@pmIdFondo VARCHAR(8)=Null
,@pmIdFonNew VARCHAR(8)=Null,@pmAnulado BIT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT CA.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Numero,Fecha,CA.NContrato AS NumCtrato,ClaseAdmon,FecIniNov,NNovedad,CA.IdFondo AS IdFonAnt,FAN.Fondo AS FondoAnt
,IdFonNew,FNE.Fondo AS FondoNuevo,CA.Observacion AS Observ,Anulado,TimeSys,CA.IdUsuario AS IdUsuari,Usuario
 --datos del empleado
,Codigo,E.IdProf AS CodProf,Profesion,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdFonCes,FC.Fondo AS FondoCes,IdCajaCom,CC.Fondo AS CajaComp
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion
,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo 
 FROM Trn_NomCAdmon AS CA INNER JOIN Empleados AS E ON CA.IdEmpleado=E.IdEmpleado INNER JOIN Fondos AS FAN ON CA.IdFondo=FAN.IdFondo
 INNER JOIN Fondos AS FNE ON CA.IdFonNew=FNE.IdFondo  INNER JOIN adm_Usuarios AS U ON CA.IdUsuario=U.IdUsuario
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo  INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo
 LEFT JOIN  Emp_Contrato AS C ON CA.NContrato=C.NContrato  LEFT JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 LEFT JOIN Dependencias AS DP ON C.IdDep=DP.IdDep  LEFT JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom LEFT JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado 
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo LEFT JOIN Areas AS AR ON C.IdArea=AR.IdArea
 LEFT JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 WHERE CA.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND ClaseAdmon LIKE ISNULL(@pmClaseAdmon,'%')
 AND CA.IdFondo LIKE ISNULL(@pmIdFondo,'%') AND IdFonNew LIKE ISNULL(@pmIdFonNew,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCausalesRet @pmIdCausa VARCHAR(4)
 AS 
 IF @pmIdCausa IS NULL
  SELECT IdCausa,CausalRet,Indmnizar
  FROM NomCausalesRet
  WHERE Inactivo=0
  ORDER BY  IdCausa
 ELSE
  SELECT IdCausa,CausalRet,Indmnizar,Inactivo
  FROM NomCausalesRet
  WHERE IdCausa=@pmIdCausa

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCertf @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20)
 AS 
 SELECT IdEmpleado,NumCertf,nAnno,nMes,ClaseCert,VrCertf,Observacion,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomCertf
 WHERE IdEmpleado=@pmIdEmpleado AND NumCertf=@pmNumCertf
 ORDER BY NumCertf

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCertfLta @pmnAnno INT,@pmnMes INT=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNumCertf VARCHAR(20)=Null,@pmObservacion VARCHAR(100)=Null,@pmClaseCert VARCHAR(10)=Null
 AS 
 SELECT C.IdEmpleado AS IdEmpledo,Apellidos,Nombres,NumCertf,nAnno,nMes,ClaseCert,VrCertf,C.Observacion AS Observ
,C.IdUsuario AS IdUsuari,Usuario,FecAdd,FecUpdate,NContrato
 FROM Trn_NomCertf AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE nAnno=@pmnAnno AND  C.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND NumCertf  LIKE ISNULL(@pmNumCertf ,'%') AND C.Observacion LIKE ISNULL(@pmObservacion,'%')
 AND ClaseCert LIKE ISNULL(@pmClaseCert,'%')
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 ORDER BY C.IdEmpleado,nMes,NumCertf

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomCertfMes @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT
,@pmClaseCert VARCHAR(10)=Null
 AS 
 SELECT ClaseCert,SUM(VrCertf) AS STOTCER
 FROM Trn_NomCertf
 WHERE IdEmpleado=@pmIdEmpleado AND nAnno=@pmnAnno AND nMes=@pmnMes
 AND ClaseCert LIKE ISNULL(@pmClaseCert,'%')
 GROUP BY ClaseCert

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConAuto @pmIdReg INT
 AS 
 SELECT IdReg,IdConcepto,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,CodNom,CodDep,CodCcto
,CodSubCos,CritSelect,FecFinal,Exceptuar,Observacion,Inactivo,NumPerMes,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomConAuto
 WHERE IdReg=@pmIdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConAutoId 
 AS 
 SELECT MAX(IdReg) AS MXIDREG
 FROM Trn_NomConAuto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConAutoLta @pmIdConcepto VARCHAR(4)=Null,@pmCedEmpleado VARCHAR(16)=Null,@pmCodNom VARCHAR(4)=Null,@pmCodDep VARCHAR(4)=Null
 ,@pmCodCcto VARCHAR(16)=Null,@pmCodSubCos VARCHAR(16)=Null,@pmInactivo BIT=Null,@pmFecInicioIni SMALLDATETIME=Null,@pmFecInicioFin SMALLDATETIME=Null
,@pmFrecAplica VARCHAR(10)=Null,@pmFecFinalIni SMALLDATETIME=Null,@pmFecFinalFin SMALLDATETIME=Null
 AS 
 SELECT IdReg,A.IdConcepto AS CodConcept,Concepto,ClaseCon,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,Apellidos,Nombres,NContrato,CodNom
,TipoNomina,CodDep,Dependencia,CodCcto,CCosto,CodSubCos,SubCosto,CritSelect,FecFinal,Exceptuar,A.Observacion AS Observ,A.Inactivo AS Inactvo,A.FecAdd AS Fecha_Add
,A.FecUpdate AS FecUpd,A.IdUsuario AS IdUsuari,Usuario,E.Inactivo AS Emp_Inactivo,NumPerMes
 FROM Trn_NomConAuto AS A INNER JOIN NomConceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Empleados AS E ON A.CedEmpleado=E.IdEmpleado  LEFT JOIN TiposNom AS TN ON A.CodNom=TN.IdNom
 LEFT JOIN Dependencias AS DP ON A.CodDep=DP.IdDep  LEFT JOIN CentroCosto AS CO ON A.CodCcto=CO.IdCCosto
 LEFT JOIN SubCentros AS SC ON A.CodSubCos=SC.IdSubCos
 WHERE A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND CedEmpleado LIKE ISNULL(@pmCedEmpleado,'%') AND CodNom LIKE ISNULL(@pmCodNom,'%')
 AND CodDep LIKE ISNULL(@pmCodDep,'%') AND CodCcto LIKE ISNULL(@pmCodCcto,'%') AND CodSubCos LIKE ISNULL(@pmCodSubCos,'%')
 AND FrecAplica LIKE ISNULL(@pmFrecAplica,'%')
 AND (A.Inactivo=ISNULL(@pmInactivo,0) or A.Inactivo=ISNULL(@pmInactivo,1))
 AND (FecInicio>=ISNULL(@pmFecInicioIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicio<=ISNULL(@pmFecInicioFin,CAST('20781230' AS SMALLDATETIME)))
-- AND (FecFinal>=ISNULL(@pmFecFinalIni,CAST('19100101' AS SMALLDATETIME)) AND FecFinal<=ISNULL(@pmFecFinalFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY IdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConAutoPen @pmFecFin SMALLDATETIME,@pmCedEmpleado VARCHAR(16),@pmCodNom VARCHAR(4)
,@pmCodDep VARCHAR(4),@pmCodCcto VARCHAR(16),@pmCodSubCos VARCHAR(16)
 AS 
 SELECT IdReg,IdConcepto,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,CodNom,CodDep,CodCcto
,CodSubCos,CritSelect,FecFinal,Exceptuar,Observacion,Inactivo,NumPerMes,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomConAuto
 WHERE Inactivo=0 AND FecInicio<=@pmFecFin
 AND ( CedEmpleado=@pmCedEmpleado OR CedEmpleado IS NULL OR LEN(CedEmpleado)=0)
 AND ( CodNom=@pmCodNom OR CodNom  IS NULL OR LEN(CodNom)=0)
 AND ( CodDep=@pmCodDep  OR CodDep  IS NULL OR LEN(CodDep)=0)
 AND ( CodCcto=@pmCodCcto  OR CodCcto  IS NULL OR LEN(CodCcto)=0)
 AND ( CodSubCos=@pmCodSubCos  OR CodSubCos  IS NULL OR LEN(CodSubCos)=0)
 ORDER BY IdConcepto,IdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConCuentas @pmIdConcepto VARCHAR(4),@pmItem INT
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConCuentasCla @pmIdConcepto VARCHAR(4),@pmNClase INT
,@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4)
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase 
 AND (CodNom=@pmCodNom OR CodNom IS NULL OR LEN(CodNom)=0 )
 AND (CodDep=@pmCodDep OR CodDep IS NULL OR LEN(CodDep)=0)
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConCuentasCls @pmIdConcepto VARCHAR(4),@pmNClase INT
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase 
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConCuentasFon @pmIdConcepto VARCHAR(4),@pmNClase INT,@pmCodFon VARCHAR(8)
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodFon,NitTerc
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase  AND CodFon=@pmCodFon
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConCuentasId @pmIdConcepto VARCHAR(4)
 AS 
 SELECT MAX(Item) AS MXITEM
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConCuentasLta @pmIdConcepto VARCHAR(4)=Null,@pmCodNom VARCHAR(4)=Null,@pmCodDep VARCHAR(4)=Null
,@pmInactivo BIT=Null
 AS 
 SELECT NC.IdConcepto  AS CodConcept,Concepto,Item,NClase,NC.IdCuenta AS CodCuenta,NomCuenta,TipoMov
,CodNom,TipoNomina,CodDep,Dependencia,CodFon,Fondo,ClaseCon,Unidad,Tarifa,Pdtermnado,NitTerc
 FROM NomConCuentas AS NC INNER JOIN NomConceptos AS C ON NC.IdConcepto=C.IdConcepto
 INNER JOIN Puc AS P ON NC.IdCuenta=P.IdCuenta 
 LEFT JOIN TiposNom AS TN ON NC.CodNom=TN.IdNom
 LEFT JOIN Dependencias AS D ON NC.CodDep=D.IdDep
 LEFT JOIN Fondos AS F ON NC.CodFon=F.IdFondo
 WHERE NC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND CodNom LIKE ISNULL(@pmCodNom,'%')
 AND CodDep LIKE ISNULL(@pmCodDep,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY NC.IdConcepto,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConOpciones @pmIdConcepto VARCHAR(4),@pmIdOpc INT=Null
 AS 
 SELECT IdConcepto,IdOpc,NomOpcion,Asignado
 FROM NomConOpciones
 WHERE IdConcepto=@pmIdConcepto 
 AND (IdOpc>=ISNULL(@pmIdOpc,0)  AND IdOpc<=ISNULL(@pmIdOpc,2147483647))
 ORDER BY IdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConOpcionesId @pmIdConcepto VARCHAR(4),@pmIdOpc INT,@pmAsignado BIT
 AS 
 SELECT count(IdOpc) AS SCANT -- IdConcepto,IdOpc,NomOpcion,Asignado
 FROM NomConOpciones
 WHERE IdConcepto=@pmIdConcepto  AND IdOpc=@pmIdOpc AND Asignado=@pmAsignado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptos @pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,ClaseCon,Unidad,Tarifa,BaseTrfa,Pdtermnado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM NomConceptos
 WHERE IdConcepto=@pmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptosDsc
 AS 
 SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
 FROM NomConceptos
 WHERE  Inactivo=0 AND ClaseCon IN ('DEVENGADO','DEDUCIDO')  
 AND IdConcepto NOT IN ('AXT','DNR','DSR','DCP','DCS','FSP','FSU','IGE','IRP','LIC','RET','BAS','VAC')
 ORDER BY Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptosDso @pmClaseCon VARCHAR(10)=Null,@pmPdtermnado BIT=Null,@pmInactivo BIT=Null
,@pmGrupo CHAR(1)=Null
 AS 
 IF @pmGrupo='N'--NOMINA
  SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
  FROM NomConceptos
  WHERE ClaseCon IN ('DEVENGADO','DEDUCIDO')  
  AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
  AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Concepto
 ELSE 
  BEGIN 
  IF @pmGrupo='V' --NOVEDADES
   SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
   FROM NomConceptos
   WHERE IdConcepto IN ('DNR','DSR','IGE','IRP','LIC','SAN','VAC','STC','AVP')  AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
   AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
   AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
   ORDER BY Concepto
  ELSE
   SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
   FROM NomConceptos
   WHERE ClaseCon LIKE ISNULL(@pmClaseCon,'%') 
   AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
   AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Concepto
  END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptosLiq @pmPdtermnado BIT=Null,@pmInactivo BIT=Null
 AS 
  SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
  FROM NomConceptos
  WHERE ( ClaseCon IN ('DEVENGADO','DEDUCIDO')  OR IdConcepto IN ('CES','PRI','VAC','INT') )
  AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
  AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptosLta @pmClaseCon VARCHAR(10)=Null,@pmPdtermnado BIT=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdConcepto,Concepto,ClaseCon,Unidad,Tarifa,BaseTrfa,Pdtermnado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM NomConceptos
 WHERE ClaseCon LIKE ISNULL(@pmClaseCon,'%')
  AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
  AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptosPre 
 AS 
  SELECT C.IdConcepto AS IdConcept,Concepto,Concepto + ' ' + C.IdConcepto  AS DsCon
  FROM NomConceptos AS C INNER JOIN NomConOpciones AS O ON C.IdConcepto=O.IdConcepto
  WHERE Inactivo=0 AND IdOpc=13 AND Asignado<>0
  ORDER BY Concepto


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomConceptosTar @pmIdConcepto VARCHAR(4)=Null,@pmPdtermnado BIT=Null
 AS 
 SELECT IdConcepto,Concepto,Tarifa,Pdtermnado
 FROM NomConceptos
 WHERE IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
 ORDER BY IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDefault @pmnAnno INT,@pmIdOpc VARCHAR(3)
 AS 
 SELECT nAnno,IdOpc,Descripcion,Valor
 FROM NomDefault
 WHERE nAnno=@pmnAnno AND IdOpc LIKE ISNULL(@pmIdOpc,'%')
 ORDER BY IdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalle @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmItem INT
 AS 
 SELECT IdPeriodo,KeyRegistro,Item,IdEmpleado,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen,Tarifa,DiasCalc
,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq
 FROM Trn_NomDetalle
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleAcu @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecIni SMALLDATETIME
,@pmFecFin SMALLDATETIME,@pmIdConcepto VARCHAR(4)=Null,@pmConcBas BIT=Null
 AS 
 IF @pmConcBas=1 --SOLO CONCEPTOS DEL BASICO
  SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
  FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
  WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
  AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0 AND IdConcepto IN ('BAS','LIC','IGE','IRP','DSR','VAC')
  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
  GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2)
 ELSE -- CONCEPTOS DEVENGADOS
  SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
  FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
  WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
  AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0 AND IdConcepto IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC','HFD','HFN')
  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
  GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleAux @pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
 AS 
    SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,VrATransMes
    ,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV
   ,SUM(VrBaseLiq) AS SBASELIQ
    FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
    WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
    AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
    AND IdConcepto='AXT' AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0
    GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),VrATransMes

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleBas @pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16)
,@pmIdConcepto VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmTipBas VARCHAR(3),@pmClaseLiq VARCHAR(10),@pmPerMax INT
 AS 
 IF @pmTipBas='SD' --SALARIO BASICO
 SELECT IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(CantDed) AS SCANDED,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED
 ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
 FROM Trn_NomDetalle 
 WHERE KeyRegistro=@pmKeyRegistro  AND IdEmpleado=@pmIdEmpleado AND SUBSTRING(IdPeriodo,1,6)=@pmMes
 AND IdPeriodo<>@pmIdPeriodo  AND CAST(SUBSTRING(IdPeriodo,7,2) AS INT)<@pmPerMax
 AND  IdConcepto NOT IN ('BAS','LIC','IGE','IRP','HHD','HHN','DSR','VAC')  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 GROUP BY IdConcepto

 ELSE --TOTAL DEVENGADO

 SELECT IdConcepto, SUM(CantDevg) AS SCANDEV,SUM(CantDed) AS SCANDED,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED
 ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
 FROM Trn_NomDetalle 
 WHERE KeyRegistro=@pmKeyRegistro  AND IdEmpleado=@pmIdEmpleado AND SUBSTRING(IdPeriodo,1,6)=@pmMes
 AND IdPeriodo<>@pmIdPeriodo  AND CAST(SUBSTRING(IdPeriodo,7,2) AS INT)<@pmPerMax
 AND ClaseLiq IN ('NOMINA','NOVEDAD')  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 GROUP BY IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleDia @pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4)
,@pmIdPeriodo VARCHAR(8),@pmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT SUM(DiasCalc) AS SDiasCalc,SUM(DiasNov) AS SDiasNov,SUM(DiasCalc-DiasNov) AS DiasNeto
 FROM Trn_NomDetalle
 WHERE  KeyRegistro=@pmKeyRegistro AND IdEmpleado=@pmIdEmpleado AND IdConcepto=@pmIdConcepto
 AND SUBSTRING(IdPeriodo,1,6)=@pmMes AND IdPeriodo<>@pmIdPeriodo AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleDsp @pmIdPeriodo VARCHAR(8)=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
-- listado de carga inicial de promedios
 SELECT D.IdEmpleado AS CodEmpleado,Apellidos,Nombres,D.IdPeriodo AS IdPerdo,Item,IdConcepto,Detalle,VrBaseLiq,N.NContrato AS NumCont
,FecInicial,FecFinal,N.KeyRegistro AS KeyRegtro,VrDevengado,TimeSys,N.IdUsuario AS IdUsuari
 FROM Trn_NomDetalle AS D INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado 
 WHERE NLiqRet=-1 AND  D.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,D.IdPeriodo,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleHex  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmIdEmpleado VARCHAR(16)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmEsRetiro BIT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdDep AS CodDepe,N.IdInstala AS CdInstala,N.IdCCosto AS CodCcosto
,N.IdSubCos AS CdSubcen,N.IdNom AS TipNom,N.VrSalario AS VrBasico,VrATransMes
,N.pVehiculo AS PlacaVeh,EsRetiro,IdArea,TipoLiq,D.IdConcepto AS CodConcepto,Concepto
,SUM(CantDevg) AS SCantDev,SUM(VrTotDevg) AS STotDev,SUM(CantDed) AS SCantDed,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc-DiasNov) AS TotalDias,SUM(VrBaseLiq) AS STotLiq
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE'  AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND ClaseCon='DEVENGADO'
 AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom like ISNULL(@pmIdNom,'%')  AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') 
 AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY N.IdEmpleado,Apellidos,Nombres,N.NContrato,N.IdDep,N.IdInstala,N.IdCCosto
,N.IdSubCos,N.IdNom,N.VrSalario,VrATransMes,N.pVehiculo,EsRetiro,IdArea,TipoLiq,D.IdConcepto,Concepto
 ORDER BY  N.IdEmpleado,N.NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetallePer @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)=Null,@pmIdNom VARCHAR(4)=Null
 AS 
 SELECT D.IdEmpleado AS CedEmpleado,Apellidos,Nombres,Item,D.IdConcepto AS IdConcept,Detalle,ClaseCon,CantDevg,VrUnitario,VrTotDevg,CantDed,VrTotDed
,D.Unidad AS Undad,VrOrigen,D.Tarifa AS Tarfa,VrBaseLiq,DiasCalc,DiasNov,DiasCalc-DiasNov AS DiasNeto,ClaseLiq,NPrestamo,NCuota,OrigCargue,CodFondo,D.KeyRegistro AS Kyregistro
 FROM Trn_NomDetalle AS D INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN  NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdPeriodo=@pmIdPeriodo AND D.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') AND IdNom like ISNULL(@pmIdNom,'%')
 ORDER BY Apellidos,Nombres,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetallePmd @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmModoPmd CHAR(1),@pmFecIni SMALLDATETIME
,@pmFecFin SMALLDATETIME,@pmIdConcepto VARCHAR(4)=Null
 AS 
 IF @pmModoPmd='F' --SALARIOS FIJO
  SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
  FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
  WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
  AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0 AND IdConcepto NOT IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC')
  GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),IdConcepto
 ELSE 
  BEGIN
   IF @pmModoPmd='B' --SALARIO BASICO
    SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
   ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
    FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
    WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
   AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0 AND IdConcepto IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC')
   GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),IdConcepto
  ELSE --SALARIO VARIABLE
   SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes, IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
  ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
   FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
   WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
   AND  ClaseLiq IN ('NOMINA','NOVEDAD') AND VrBaseLiq>0 AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
   GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),IdConcepto
  END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleRcon @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null,@pmNPrestamo INT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumCntrato,D.IdConcepto AS CodConcept,Concepto,ClaseCon,SUBSTRING(N.IdPeriodo,1,6)  AS nMES
 ,SUM(CantDevg) AS SCantDevg,SUM(VrTotDevg) AS STotDevg,SUM(CantDed) AS SCantDed,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc) AS SCanDia,SUM(DiasNov) AS SDiasNov,SUM(DiasCalc-DiasNov) AS SDiasNeto,SUM(VrBaseLiq) AS SBaseLiq
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,N.NContrato,D.IdConcepto,Concepto,ClaseCon,SUBSTRING(N.IdPeriodo,1,6)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleRes @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null,@pmNPrestamo INT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumCntrato,N.KeyRegistro AS KeyReg,N.IdPeriodo AS NumPeriodo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdNom AS CodNmna,TipoNomina,N.IdDep AS CodDep,Dependencia,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcos,SubCosto,N.IdInstala AS CodIstala,Instlacion
,N.VrSalario AS SalBasico,N.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS IdEstdo,ED.Estado AS Nom_Estado,EsRetiro,NLiqRet,TipoLiq,TimeSys
,N.FecUpdate AS Fec_Update,N.IdUsuario AS IdUsuari,Usuario
--datos del detalle
,Item,D.IdConcepto AS CodConcept,Concepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,ClaseCon,D.Unidad AS Undad,ClaseLiq,VrOrigen,D.Tarifa AS Tarfa,DiasCalc,DiasNov,CodFondo,FCO.Fondo AS NomFondo
,NPrestamo,NCuota,OrigCargue,VrBaseLiq
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,FC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS VlrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj,C.IdGrupo AS CodGrup
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala  INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom  LEFT JOIN Fondos AS FCO ON D.CodFondo=FCO.IdFondo
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 ORDER BY  N.IdEmpleado,N.IdPeriodo,D.IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleResN @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmEsRetiro BIT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null
 AS 
SELECT N.IdEmpleado AS IdEmple,N.NContrato AS NumContrato,FecInicial,FecFinal,N.IdPeriodo AS IdPerdo,IdArea,N.IdDep AS nDepe,N.IdInstala AS nInstala
,N.IdCCosto AS CodCcosto,N.IdSubCos AS CodSubcentro,N.IdNom AS CdNom,N.VrSalario AS vSalario,VrATransMes,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom
,N.Observacion AS Observ,EsRetiro,NLiqRet,TipoLiq
--Detales
,D.IdConcepto AS CdConcepto,Item,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad AS Und,ClaseLiq,VrOrigen,D.Tarifa AS Tarif,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,VrBaseLiq
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%')  AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY  FecInicial, N.IdEmpleado,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleRtot @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null,@pmNPrestamo INT=Null
 AS 
 SELECT SUM(CantDevg) AS SCantDevg,SUM(VrTotDevg) AS STotDevg,SUM(CantDed) AS SCantDevg,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc) AS SCantDias,SUM(DiasNov) AS SDiasNoRem,SUM(DiasCalc-DiasNov) AS SDiasNet,SUM(VrBaseLiq) AS STotLiq
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomDetalleTar @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT D.IdConcepto AS CodConcepto,Concepto,CN.Tarifa AS TrifaDft,D.Tarifa AS Tarfa,SUM(VrTotDevg) AS STotDev,SUM(VrTotDed) AS StotDed
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D  ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND NLiqRet>=0 AND D.IdConcepto IN ('DCP','DCS','PEN','RIE','SAL','FSP','FSU','SEN','ICB','COM')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 GROUP BY  D.IdConcepto,Concepto,CN.Tarifa,D.Tarifa

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomFijos @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT
 AS 
 SELECT IdEmpleado,nAnno,nMes,Tarifa,VrBase,VrSalarios,VrPrima,VrVacacnes,VrSIntExcto,VrOtrosIng,VrIngresos,VrPensiones,VrSalud,VrDedcido,VrExcento,VrCertEdu,VrCertVda
,VrCertAFC,VrCertfcado,VrTotalBase,Periodos,OrignPorc,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomFijos
 WHERE IdEmpleado=@pmIdEmpleado AND nAnno=@pmnAnno AND nMes=@pmnMes

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomFijosLta @pmIdEmpleado VARCHAR(16)=Null,@pmnAnno INT=Null,@pmnMes INT=Null
 AS 
 SELECT F.IdEmpleado AS IdEmpledo,Apellidos,Nombres,nAnno,nMes,Tarifa,VrBase,VrSalarios,VrPrima,VrVacacnes,VrSIntExcto,VrOtrosIng,VrIngresos,VrPensiones,VrSalud,VrDedcido,VrExcento
,VrCertEdu,VrCertVda,VrCertAFC,VrCertfcado,VrTotalBase,Periodos,OrignPorc,Codigo,NContrato,FecUltIng,F.IdUsuario AS IdUsuari,Usuario,FecAdd,FecUpdate
 FROM Trn_NomFijos AS F INNER JOIN Empleados AS E ON F.IdEmpleado=E.IdEmpleado
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 WHERE F.IdEmpleado like ISNULL(@pmIdEmpleado,'%')
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 ORDER BY Apellidos,Nombres,nAnno,nMes

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiqDet @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,IdConcepto,Detalle,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd
,FecFinPmd,DiasBase,DiasNoRem,Tarifa,NPrestamo,NCuota,LogPmdio,IdEmpleado,NContrato,pVehiculo,IdDep
,IdCCosto,IdSubCos,IdNom,VrSalario,VrParcial
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiqDetEmp @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT IdEmpleado,NContrato,FecUltLiq,FecInicial,FecFinal, COUNT(Item) AS SITEM,SUM(VrLiquida) AS SValLiq,SUM(VrDeducido) AS SValDed
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 GROUP BY  IdEmpleado,NContrato,FecUltLiq,FecInicial,FecFinal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiqDetTEmp @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdEmpleado VARCHAR(16)
,@pmNContrato INT
 AS 
 SELECT SUM(VrBase) AS SBASE,SUM(Cantidad) AS SCANT,SUM(VrLiquida) AS STOTLIQ,SUM(VrDeducido) AS STOTDED
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiqDetTnm  @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdNom VARCHAR(4)=Null
AS
 SELECT D.IdNom AS CodNom,TipoNomina,TipoLiquida,COUNT(Item) AS SITEM
 FROM Trn_NomLiqDet  AS D INNER JOIN TiposNom AS T ON D.IdNom=T.IdNom
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 GROUP BY D.IdNom,TipoNomina,TipoLiquida

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiqDet_Cr  @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNumero INT=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmSemstre INT=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT Q.TipoLiq AS Tip_Liqda,Q.Numero AS NumLiquida,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,Anulado,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--detalle de liquidaicion
,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.NContrato AS NumContrato,D.pVehiculo AS PlacaVeh,D.IdDep AS CodDep,Dependencia,D.IdCCosto AS CodCcto,CCosto,D.IdSubCos AS CodSubcen,SubCosto,D.IdNom AS CodNom,TipoNomina,D.VrSalario AS Liq_SalBasico
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,D.Tarifa AS Tarfa,NPrestamo,NCuota,LogPmdio,Unidad
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps
,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.IdJornada AS CodJnada,Jornada,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,TipoTrabj
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModPromdio,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,VrParcial
 FROM Trn_NomLiquida AS Q INNER JOIN Trn_NomLiqDet AS D ON Q.TipoLiq=D.TipoLiq AND Q.Numero=D.Numero
 INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN Dependencias AS DP ON D.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON D.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON D.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom 
 WHERE Q.TipoLiq=@pmTipoLiq  AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND D.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND Q.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Q.Numero>=ISNULL(@pmNumero,0)  AND Q.Numero<=ISNULL(@pmNumero,2147483647))
 AND (Semstre >=ISNULL(@pmSemstre ,0)  AND Semstre <=ISNULL(@pmSemstre,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (D.NContrato >=ISNULL(@pmNContrato ,0)  AND D.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY Q.Numero,Apellidos,Nombres,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquida @pmTipoLiq VARCHAR(3),@pmNumero INT
 AS 
 SELECT TipoLiq,Numero,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaBan @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
AS
SELECT L.TipoLiq AS Tliq,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,e_mail,Telefono,D.NContrato AS NumContrato,IdConcepto
,E.Direccion AS EmpDireccion,TelMovil,Cargo 
,SUM(VrLiquida) AS STOTLIQ,SUM(VrDeducido) AS STOTDED,SUM(VrParcial) AS STOTPARC,SUM(VrLiquida-VrDeducido) AS SNETLIQ
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0  AND FPnomina='TRANS' 
 AND IdConcepto IN ('CES','PRI','INT')
 AND L.TipoLiq LIKE ISNULL(@pmTipoLiq,'%')  AND D.IdNom LIKE ISNULL(@pmIdNom,'%') AND D.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') 
 GROUP BY L.TipoLiq,D.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
 ,E.IdBanco,Banco,CodEntidad,CdLocCue,e_mail,Telefono,D.NContrato,IdConcepto,E.Direccion,TelMovil,Cargo
 ORDER BY D.IdEmpleado,L.TipoLiq

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaCes @pmTipoLiq VARCHAR(3),@pmIdEmpleado VARCHAR(16),@pmFechLiq SMALLDATETIME
 AS 
 SELECT L.TipoLiq AS TipLiq,L.Numero AS NumLiq,Fecha,VrTotal,VrTotDed,VrAplicado,VrParcial,Anulado,IdEstado
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq  AND Anulado=0 AND IdEmpleado=@pmIdEmpleado
 AND Fecha>=@pmFechLiq
 ORDER BY L.Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaCmp @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT  TipCom,Comprobante,IdCiaCom,COUNT(Numero) AS SCANT 
 FROM  Trn_NomLiquida
 WHERE TipoLiq='PRI'  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Comprobante>0
 GROUP BY TipCom,Comprobante,IdCiaCom


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaEmp @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16),@pmNContrato INT=Null
 AS 
 SELECT L.TipoLiq AS TipLiq,L.Numero AS NumLiq,Fecha,IdEmpleado,NContrato,SUM(VrBase) AS STOTBASE,SUM(Cantidad) AS SDIAS,SUM(VrLiquida) AS SVLIQ
,SUM(VrDeducido) AS SVDED,SUM(DiasBase) AS SDiasBase,SUM(DiasNoRem) AS SDiasNoRem,SUM(VrParcial) AS SVRPAR
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 GROUP BY L.TipoLiq,L.Numero,Fecha,IdEmpleado,NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaFec @pmTipoLiq VARCHAR(3),@pmFecha SMALLDATETIME,@pmNumero INT
 AS 
 SELECT TipoLiq,Numero,Fecha,Semstre,IdEstado,TipCom,Comprobante,IdCiaCom
 FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq AND Anulado=0 AND Fecha>@pmFecha  AND Numero<>@pmNumero
 ORDER BY Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaId  @pmTipoLiq VARCHAR(3)
AS
 SELECT MAX(Numero) AS MXNUM FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaIng @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT Q.TipoLiq AS Tip_Liqda,Q.Numero AS NumLiquida,Fecha,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.NContrato AS NumContrato,D.pVehiculo AS PlacaVeh,D.IdDep AS CodDep
,D.IdCCosto AS CodCcto,D.IdSubCos AS CodSubcen,D.IdNom AS CodNom,D.VrSalario AS Liq_SalBasico,Item,D.IdConcepto AS CodConcepto,Concepto,CN.Tarifa AS TrfaDft,Detalle,ClaseCon,FecUltLiq,FecInicial,FecFinal
,VrBase,Cantidad,VrLiquida,VrDeducido,DiasBase,DiasNoRem,D.Tarifa AS Tarfa,NPrestamo,IdTipCon,IdArea,IdInstala,C.Inactivo AS Con_inactivo,E.Inactivo AS Emp_Inactvo,IdFonCes,VrParcial
 FROM Trn_NomLiquida AS Q INNER JOIN Trn_NomLiqDet AS D ON Q.TipoLiq=D.TipoLiq AND Q.Numero=D.Numero
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato
 WHERE  Fecha  BETWEEN @pmFecIni AND @pmFecFin AND Anulado=0 AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%')  AND D.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND IdInstala LIKE ISNULL(@pmIdInstala,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (D.NContrato >=ISNULL(@pmNContrato ,0)  AND D.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY D.IdEmpleado,Q.TipoLiq,Q.Numero,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaPar @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16),@pmNContrato INT=Null
 AS 
 SELECT IdConcepto,Detalle,SUM(VrBase) AS STOTBASE,SUM(Cantidad) AS SDIAS,SUM(VrLiquida) AS SVLIQ,SUM(VrDeducido) AS SVDED
,SUM(DiasBase) AS SDiasBase,SUM(DiasNoRem) AS SDiasNoRem,SUM(VrParcial) AS SVRPAR
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND VrTotal>VrAplicado
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 GROUP BY IdConcepto,Detalle

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaPtot @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16),@pmNContrato INT=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT IdConcepto,SUM(VrBase) AS STOTBASE,SUM(Cantidad) AS SDIAS,SUM(VrLiquida) AS SVLIQ,SUM(VrDeducido) AS SVDED
,SUM(DiasBase) AS SDiasBase,SUM(DiasNoRem) AS SDiasNoRem,SUM(VrParcial) AS SVRPAR
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 GROUP BY IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaTip  @pmTipoLiq VARCHAR(3),@pmFecha SMALLDATETIME,@pmSemstre INT=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
AS
 SELECT L.TipoLiq AS TLiq,L.Numero AS NumLiq,Fecha
  FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
  WHERE L.TipoLiq=@pmTipoLiq AND Fecha=@pmFecha AND Anulado=0 AND  IdDep LIKE ISNULL(@pmIdDep,'%') 
  AND IdNom LIKE ISNULL(@pmIdNom,'%')   AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (Semstre>=ISNULL(@pmSemstre,0)  AND Semstre<=ISNULL(@pmSemstre,2147483647))
 ORDER BY L.Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquidaUcp @pmTipoLiq VARCHAR(3),@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT L.TipoLiq AS TipLiq,L.Numero AS NumLiq,Fecha,VrTotal,VrTotDed,VrAplicado,Anulado,IdEstado,VrParcial
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq  AND Anulado=0 AND IdEmpleado=@pmIdEmpleado
 ORDER BY Fecha

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLiquida_Cr @pmTipoLiq VARCHAR(3),@pmNumero INT=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 SELECT Q.TipoLiq AS Tip_Liqda,Q.Numero AS NumLiquida,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,Anulado,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--detalle de liquidaicion
,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.NContrato AS NumContrato,D.pVehiculo AS PlacaVeh,D.IdDep AS CodDep,Dependencia,D.IdCCosto AS CodCcto,CCosto,D.IdSubCos AS CodSubcen,SubCosto,D.IdNom AS CodNom,TipoNomina,D.VrSalario AS Liq_SalBasico
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,D.Tarifa AS Tarfa,NPrestamo,NCuota,LogPmdio,Unidad
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,FecUltCes,FecUltPri,FecUltVac,NumVeh,TipoAdmon,VehPropio,VrParcial
 FROM Trn_NomLiquida AS Q INNER JOIN Trn_NomLiqDet AS D ON Q.TipoLiq=D.TipoLiq AND Q.Numero=D.Numero
 INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN Dependencias AS DP ON D.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON D.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON D.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom LEFT JOIN NomVehiculos AS VH ON D.pVehiculo=VH.IdVehiculo
 WHERE Q.TipoLiq=@pmTipoLiq 
 AND (Q.Numero>=ISNULL(@pmNumero,0)  AND Q.Numero<=ISNULL(@pmNumero,2147483647))
 AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND D.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Q.Numero,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLogVeh @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 SELECT IdEmpleado,NumReg,Fecha,pVehAnterior,NitPropAnt,NitCondAnt,pVehNew,NitPropNew,Observacion,TimeSys,IdUsuario
 FROM Trn_NomLogVeh
 WHERE IdEmpleado=@pmIdEmpleado
 AND (NumReg>=ISNULL(@pmNumReg,0)  AND NumReg<=ISNULL(@pmNumReg,2147483647))
 ORDER BY NumReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLogVehDso @pmIdEmpleado VARCHAR(16)=Null,@pmNumReg INT=Null,@pmFechaIni SMALLDATETIME=Null
,@pmFechaFin SMALLDATETIME=Null,@pmpVehNew VARCHAR(10)=Null
 AS 
 SELECT LV.IdEmpleado AS IdEmpldo,Apellidos,Nombres,NumReg,Fecha,pVehAnterior,NitPropAnt,NitCondAnt,pVehNew,NitPropNew,LV.Observacion AS Observ
,TimeSys,LV.IdUsuario AS IdUsuari,Usuario,NContrato
 FROM Trn_NomLogVeh AS LV INNER JOIN Empleados AS E ON LV.IdEmpleado=E.IdEmpleado INNER JOIN adm_Usuarios AS U ON LV.IdUsuario=U.IdUsuario
 WHERE LV.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND pVehNew LIKE ISNULL(@pmpVehNew,'%')
 AND (NumReg>=ISNULL(@pmNumReg,0)  AND NumReg<=ISNULL(@pmNumReg,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,NumReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomLogVehId @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(NumReg) AS MXNUM
 FROM Trn_NomLogVeh
 WHERE IdEmpleado=@pmIdEmpleado


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNov @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrTotal,Tarifa,VrOrigen,IdPeriodo,IdEmpleado,TimeSys,FecUpdate,IdUsuario,OrigCargue
 FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovCon @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16) 
,@pmIdConcepto VARCHAR(4),@pmOrigCargue VARCHAR(10)=Null
 AS 
 SELECT Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrTotal,Tarifa,VrOrigen,IdPeriodo,IdEmpleado
,TimeSys,FecUpdate,IdUsuario,OrigCargue
 FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado
 AND IdConcepto=@pmIdConcepto
 AND OrigCargue LIKE ISNULL(@pmOrigCargue,'%')
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovId @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Item) AS MXITEM
 FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovTot @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)
,@pmDeveng BIT
 AS 
 IF @pmDeveng <>0 --devengados 
  SELECT Count(Item) AS SITEM,SUM(Cantidad) AS SCANT,SUM(VrTotal) AS STOTAL,SUM(VrOrigen) AS SVBASE
  FROM Trn_NomNov AS N  INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
  WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado AND ClaseCon<>'DEDUCIDO'
 ELSE
  SELECT Count(Item) AS SITEM,SUM(Cantidad) AS SCANT,SUM(VrTotal) AS STOTAL,SUM(VrOrigen) AS SVBASE
  FROM Trn_NomNov AS N  INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
  WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado AND ClaseCon='DEDUCIDO'


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNov_Cr @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT IdPeriodo,N.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.NContrato AS NumContrato,Item,N.IdConcepto AS IdConcept,Concepto,Detalle,Cantidad,VrUnitario,VrTotal,N.Tarifa AS TrfaBase,VrOrigen,ClaseCon,Unidad,TimeSys
,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario,OrigCargue
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdCCosto AS CodCcto,CCosto
,C.IdSubCos AS CodSubcen,SubCosto,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
 FROM Trn_NomNov AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN  NomConceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 LEFT JOIN  Emp_Contrato AS C ON E.NContrato=C.NContrato  LEFT JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 LEFT JOIN Dependencias AS DP ON C.IdDep=DP.IdDep  LEFT JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 LEFT JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto  LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom LEFT JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado 
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo LEFT JOIN Areas AS AR ON C.IdArea=AR.IdArea
 LEFT JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase LEFT JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 WHERE IdPeriodo=@pmIdPeriodo AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY  N.IdEmpleado,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedad @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,Remnrado
,Observacion,CodInstla,CodClsRie,NumAutza,CodNewFon,CodOldFon,Inactivo,VrCotVolAfi,VrCotVolApo,VrNoRetenido
,TipoIncap,FechaDcto,VrDescuento,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadApo @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdNov VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT FecInicio,FecFinal,SUM(CantDias) AS SCanDia,SUM(VrCotVolAfi) AS SVolAfi,SUM(VrCotVolApo) AS SVolApo,SUM(VrNoRetenido) AS SNoReten
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado AND Inactivo=0  AND FecFinal>=@pmFecIni  AND  FecInicio<=@pmFecFin
 AND IdNov LIKE ISNULL(@pmIdNov,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 GROUP BY FecInicio,FecFinal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadCon @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmRemnrado BIT=Null,@pmIdOpc INT=Null
 AS 
 SELECT IdEmpleado,Numero,N.IdConcepto AS CodConcept,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla,CodClsRie,NumAutza,CodNewFon
,CodOldFon,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,Remnrado,Observacion,IdUsuario,Inactivo,FechaDcto,VrDescuento
 FROM Trn_NomNovedad AS N INNER JOIN NomConOpciones AS O ON N.IdConcepto=O.IdConcepto
 WHERE IdEmpleado=@pmIdEmpleado  AND Inactivo=0 AND CantDias>0 AND FecFinal>=@pmFecIni AND FecInicio<=@pmFecFin
 AND Asignado<>0 AND  (IdOpc>=ISNULL(@pmIdOpc,0)  AND IdOpc<=ISNULL(@pmIdOpc,2147483647))
 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadEmp @pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdNov VARCHAR(4)=Null,@pmRemnrado BIT=Null
 AS 
 SELECT IdEmpleado,Numero,N.IdConcepto AS CodConcepto,Concepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla
,CodClsRie,NumAutza,CodNewFon,CodOldFon,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,Remnrado,N.Inactivo AS Inactvo,FechaDcto,VrDescuento
 FROM Trn_NomNovedad AS N INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
 WHERE IdEmpleado=@pmIdEmpleado  AND N.Inactivo=0 AND CantDias>0 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND IdNov LIKE ISNULL(@pmIdNov,'%') 
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadFec @pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmModalidad VARCHAR(10)=Null
,@pmRemnrado BIT=Null
 AS 
 SELECT IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla,CodClsRie,NumAutza,CodNewFon,CodOldFon,Remnrado
,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,Observacion,FechaDcto,VrDescuento,Inactivo,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomNovedad
 WHERE Inactivo=0 AND CantDias>0 AND IdConcepto<>'AVP' AND IdEmpleado=@pmIdEmpleado AND @pmFecha BETWEEN FecInicio AND FecFinal 
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')   AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
ORDER BY Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadId @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNumero
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadLic @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
--total de incapacidad y licencias por descontar
 AS 
 SELECT Numero,IdConcepto,Modalidad,IdNov,VrDescuento,NumAutza,FechaDcto,TipoIncap
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado  AND Inactivo=0 AND FecInicio<=@pmFecFin AND CantDias>0
  AND  FechaDcto BETWEEN @pmFecIni AND @pmFecFin AND IdConcepto  IN ('IGE','IRP','LIC')
  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 ORDER BY IdConcepto,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadLta @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdEmpleado VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmModalidad VARCHAR(10)=Null,@pmNumero INT=Null,@pmIdNov VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmRemnrado BIT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpledo,Apellidos,Nombres,Numero,N.IdConcepto AS CodConcepto,Concepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,N.IdNov AS CodNov,Novedad,Remnrado
,N.Observacion AS Observ,CodInstla,CodClsRie,CR.Tarifa AS NewTarfARP,NumAutza,CodOldFon,CodNewFon,Fondo,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap
,N.Inactivo AS Inactvo,TimeSys,FecUpdate,N.IdUsuario AS IdUsuari,Usuario,FechaDcto,VrDescuento
 FROM Trn_NomNovedad AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN TiposNov AS TN ON N.IdNov=TN.IdNov INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 LEFT JOIN ClaseRie AS CR ON N.CodClsRie=CR.IdClase LEFT JOIN Fondos AS F ON N.CodNewFon=F.IdFondo
 WHERE FecInicio BETWEEN @pmFecInicio AND @pmFecFinal AND  N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')  AND N.IdNov LIKE ISNULL(@pmIdNov,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 AND (N.Inactivo=ISNULL(@pmInactivo,0) or N.Inactivo=ISNULL(@pmInactivo,1))
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Apellidos,Nombres,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadPen @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmRemnrado BIT=Null,@pmCantDias INT=0
 AS 
 SELECT IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla
,CodClsRie,NumAutza,CodOldFon,CodNewFon,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap
,Remnrado,FechaDcto,VrDescuento,Observacion,IdUsuario,Inactivo
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado  AND Inactivo=0 AND CantDias>@pmCantDias AND FecFinal>=@pmFecIni AND FecInicio<=@pmFecFin
 AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomNovedadTra @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT IdNov,CodOldFon,CodNewFon,SUM(CantDias) AS SCanDia
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado AND Inactivo=0 AND CantDias>0 AND  FecInicio BETWEEN @pmFecIni AND @pmFecFin
 AND IdNov IN ('TAE','TAP')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 GROUP BY IdNov,CodOldFon,CodNewFon

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrest @pmNPrestamo INT
 AS 
 SELECT NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal
,VrTmAbono,NumPerMes,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomPrest
 WHERE NPrestamo=@pmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestAbo @pmNPrestamo INT,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT NPrestamo,IdEmpleado,VrPrestamo,NumCuotas,VrCuota,TotPrestamo,TotAbonado,VrTmAbono
 FROM Trn_NomPrest
 WHERE IdEmpleado like ISNULL(@pmIdEmpleado,'%')
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestEmp @pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME,@pmDsctPri INT,@pmDsctVac INT
 AS 
 SELECT NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal
,VrTmAbono,NumPerMes,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomPrest
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND DsctNom>0  AND FecInicio<=@pmFecInicio AND DsctPri>=@pmDsctPri AND DsctVac>=@pmDsctVac
  AND (VrSaldo>=0.8 or (VrSaldo+VrTmAbono)>=0.8)
 ORDER BY FecInicio,NPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestId
 AS 
 SELECT MAX(NPrestamo) AS MXPSTM
 FROM Trn_NomPrest

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestLta @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmSaldoIni DECIMAL(14,2),@pmSaldoFin DECIMAL(14,2),@pmIdEmpleado VARCHAR(16)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmFrecDcto VARCHAR(10)=Null,@pmAnulado BIT=Null,@pmNPrestamo INT=Null
 AS 
 SELECT NPrestamo,Fecha,P.IdEmpleado AS IdEmpledo,Apellidos,Nombres,P.IdConcepto AS IdConcept,Concepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,TotPrestamo-TotAbonado AS VrSaldoAct,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,P.Observacion AS Observ,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal,TimeSys,P.FecUpdate AS FecUpd,P.IdUsuario AS IdUsuari,Usuario
,E.NContrato AS NumContrato,FecIngreso,FecRetiro,VrSalario,VrAuxTrans,CE.IdNom AS CodNom,TipoNomina,pVehiculo,NumPerMes
 FROM Trn_NomPrest AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado INNER JOIN NomConceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Emp_Contrato AS CE ON E.NContrato=CE.NContrato LEFT JOIN TiposNom AS TN ON CE.IdNom=TN.IdNom
 WHERE Fecha BETWEEN @pmFecInicio AND @pmFecFinal  AND VrSaldo BETWEEN @pmSaldoIni AND @pmSaldoFin AND P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND FrecDcto LIKE ISNULL(@pmFrecDcto,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 ORDER BY NPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestPen @pmIdEmpleado VARCHAR(16),@pmNPreExste INT
 AS 
 SELECT NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Cxpagar,NumPerMes
 FROM Trn_NomPrest
 WHERE Anulado=0 AND VrSaldo>=0.8  AND  IdEmpleado=@pmIdEmpleado  AND NPrestamo<>@pmNPreExste
 ORDER BY NPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestSal @pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT NPrestamo,Fecha,TotPrestamo,TotAbonado,VrSaldo,VrPrestamo,NumCuotas,VrCuota,DsctNom,FecInicio,FrecDcto
,P.IdConcepto AS CodConcepto,Concepto,Exceptuar,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,P.Observacion AS Observ,Cxpagar
,DsctPri,DsctVac,DsctEspPer,DsctEspVal,P.IdEmpleado AS CedEmpleado,Apellidos,Nombres,NumPerMes
 FROM Trn_NomPrest AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado
 INNER JOIN NomConceptos AS N ON P.IdConcepto=N.IdConcepto
 WHERE P.IdEmpleado=@pmIdEmpleado AND Anulado=0 AND DsctNom>0  AND FecInicio<=@pmFecInicio AND VrSaldo>=0.8
 AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY FecInicio,NPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrestSdo @pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME
 AS 
 SELECT COUNT(NPrestamo) AS CANPRE,SUM(VrPrestamo) AS SVALPRE,SUM(NumCuotas) AS Scuotas,SUM(TotPrestamo) AS STOTPRE
,SUM(TotAbonado) AS STOTABO
 FROM Trn_NomPrest
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND DsctNom>0  AND FecInicio<=@pmFecInicio
  AND (VrSaldo>=0.8 or (VrSaldo+VrTmAbono)>=0.8)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomPrest_Cra @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmSaldoIni DECIMAL(14,2),@pmSaldoFin DECIMAL(14,2),@pmIdEmpleado VARCHAR(16)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmFrecDcto VARCHAR(10)=Null,@pmAnulado BIT=Null,@pmNPrestamo INT=Null
 AS 
 SELECT P.NPrestamo AS NumPrest,Fecha,P.IdEmpleado AS IdEmpledo,Apellidos,Nombres,P.IdConcepto AS IdConcept,Concepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,TotPrestamo-TotAbonado AS VrSaldoAct,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,P.Observacion AS Observ,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal,TimeSys,P.FecUpdate AS FecUpd,P.IdUsuario AS IdUsuari,Usuario
,E.NContrato AS NumContrato,FecIngreso,FecRetiro,VrSalario,VrAuxTrans,CE.IdNom AS CodNom,TipoNomina,pVehiculo
,Item,FechaAbo,VrAbono,nCuotas,Dscto,IdPeriodo,Detalle,NLiquida,NumPerMes
 FROM Trn_NomPrest AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado INNER JOIN NomConceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario LEFT JOIN Trn_NomAbonos AS PA ON P.NPrestamo=PA.NPrestamo
 LEFT JOIN Emp_Contrato AS CE ON E.NContrato=CE.NContrato LEFT JOIN TiposNom AS TN ON CE.IdNom=TN.IdNom
 WHERE Fecha BETWEEN @pmFecInicio AND @pmFecFinal  AND VrSaldo BETWEEN @pmSaldoIni AND @pmSaldoFin AND P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND FrecDcto LIKE ISNULL(@pmFrecDcto,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (P.NPrestamo>=ISNULL(@pmNPrestamo,0)  AND P.NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 ORDER BY P.NPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomProrrogas @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 SELECT IdEmpleado,NumReg,NContrato,Fecha,FecAnterior,Indefinido,CdTipCon,CdCargo,CdDep,CdArea,CdCCosto,CdSubCos
,IdTipCon,IdCargo,IdArea,IdDep,IdCCosto,IdSubCos,Observacion,TimeSys,IdUsuario
 FROM Trn_NomProrrogas
 WHERE IdEmpleado=@pmIdEmpleado AND NumReg=@pmNumReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomProrrogasId @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(NumReg)  AS MXITM
 FROM Trn_NomProrrogas
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomProrrogasLta @pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmInactivo BIT=Null
,@pmEmp_Inactivo BIT=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT P.IdEmpleado AS IdEmplado,Apellidos,Nombres,NumReg,P.NContrato AS NumContrato,FecAnterior,Fecha,P.Indefinido AS Indefnido,CdTipCon,TCA.TipoContrato AS TipoConAnterior
,P.IdTipCon AS IdTcont,TC.TipoContrato AS TipoConNuevo,CdCargo,CGA.Cargo AS CargoAnterior,P.IdCargo AS IdCarg,CG.Cargo AS CargoNuevo,CdArea,ARA.Area AS AreaAnterior
,P.IdArea AS Id_Area,AR.Area AS AreaNueva,CdDep,DA.Dependencia AS DepeAnterior,P.IdDep AS IdDepe,D.Dependencia AS DepeNueva
,CdCCosto,COA.CCosto AS CentroAnterior,P.IdCCosto AS IdCenCost,CO.CCosto AS CentroNuevo,CdSubCos,SCA.SubCosto AS SubCenAnterior,P.IdSubCos AS IdSubCen,SC.SubCosto AS SubCenNuevo
,P.Observacion AS Observ,TimeSys,P.IdUsuario AS IdUsuari,Usuario
--inf. de contratos
,FecIngreso,C.Indefinido AS Con_Indefinido,C.IdJornada AS IdJrnada,Jornada,C.IdInstala AS IdInstla,Instlacion,C.IdCia AS CodCia,Compania
,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,C.Inactivo AS Inactvo
--empleados
--,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion
--,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja
--,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
--,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo
--,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,TipoId,Codigo,ET.NColor AS EmpEstcolor,E.FechaAdd AS EmpFecAdd,E.FechaUpdate AS EmpFecupd,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario

 FROM Trn_NomProrrogas AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado
 INNER JOIN Emp_Contrato AS C  ON P.NContrato=C.NContrato
 INNER JOIN TiposCon AS TC ON P.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON P.IdCargo=CG.IdCargo 
 INNER JOIN Dependencias AS D ON P.IdDep=D.IdDep
 INNER JOIN Areas AS AR ON P.IdArea=AR.IdArea
 INNER JOIN CentroCosto AS CO ON P.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON P.IdSubCos=SC.IdSubCos
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 LEFT JOIN TiposCon AS TCA ON P.CdTipCon=TCA.IdTipCon
 LEFT JOIN Cargos AS CGA ON P.CdCargo=CGA.IdCargo 
 LEFT JOIN Dependencias AS DA ON P.CdDep=DA.IdDep
 LEFT JOIN Areas AS ARA ON P.CdArea=ARA.IdArea
 LEFT JOIN CentroCosto AS COA ON P.CdCCosto=COA.IdCCosto
 LEFT JOIN SubCentros AS SCA ON P.CdSubCos=SCA.IdSubCos

-- INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
-- INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
-- INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 --INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 --INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 --INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
--INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  
 AND (P.NContrato>=ISNULL(@pmNContrato,0)  AND P.NContrato<=ISNULL(@pmNContrato,2147483647)) 
 AND P.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')  AND P.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY Apellidos,Nombres,NumReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRangosFsu @pmIdRango INT
AS
 SELECT     IdRango, VrInicial, VrFinal, Tarifa 
 FROM  NomRangosFsu
 WHERE IdRango=@pmIdRango


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRangosFsuId 
AS
 SELECT  MAX(IdRango) AS MXRANGO,MAX(VrFinal) AS MXFINAL
 FROM  NomRangosFsu

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRangosFsuLta 
AS
 SELECT   IdRango, VrInicial, VrFinal, Tarifa 
 FROM  NomRangosFsu
 ORDER BY IdRango


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRet @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes
,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRetAct @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem
 FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND Numero<>@pmNumero
 ORDER BY  Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE  paQryNomRetBan @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
AS
SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,R.NContrato AS NumContrato
,Cargo,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes,VrBaseVac
 FROM Trn_NomRet AS R INNER JOIN Empleados AS E ON R.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON R.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0  AND FPnomina='TRANS' 
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%') AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') 
 ORDER BY  Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRetCmp @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT  TipCom,Comprobante,IdCiaCom,COUNT(Numero) AS SCANT 
 FROM Trn_NomRet
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Comprobante>0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 GROUP BY TipCom,Comprobante,IdCiaCom


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRetDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 SELECT IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd
,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq
 FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRetDetLiq @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Item,IdConcepto,Detalle,FecUltLiq,FecDesde,FecHasta,ClaseLiq
 FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero AND ClaseLiq='LIQUDACION'
 ORDER BY IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRetId @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRetIng @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
 AS 
 SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,R.NContrato AS NumContto,MONTH(R.Fecha) AS Nmes,YEAR(R.Fecha) AS NumAnno,R.IdDep AS CodDep,C.IdInstala AS CodInstala
,R.IdCCosto AS CodCcto,R.IdSubCos AS CodSubcc,R.IdNom AS CodNom,R.pVehiculo AS PlacaVeh,R.VrSalario  AS Salbasico,TipoLiq,IdArea,IdTipCon
,D.IdConcepto AS CodConcepto,Concepto
,SUM(Cantidad) AS SCANT,SUM(VrDevngado) AS STotDev,SUM(VrDeducido) AS STotDed,SUM(VrBase) AS SValBase
,SUM(DiasBase) AS DIAS_BASE,SUM(D.DiasNoRem) AS SCanNoRem,SUM(DiasBase-D.DiasNoRem) AS DiasNeto
,SUM(VrBaseLiq) AS SbaseLiq
 FROM Trn_NomRet AS R INNER JOIN  Trn_NomRetDet AS  D ON R.IdEmpleado=D.IdEmpleado AND R.Numero=D.Numero
 INNER JOIN Empleados AS E ON R.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON R.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE Fecha BETWEEN @pmFecIni  AND @pmFecFin  AND ClaseLiq='LIQUDACION'
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND R.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')   AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND R.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  
 AND (R.NContrato>=ISNULL(@pmNContrato,0)  AND R.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 GROUP BY  R.IdEmpleado,Apellidos,Nombres,R.NContrato,MONTH(R.Fecha),YEAR(R.Fecha),R.IdDep,C.IdInstala
,R.IdCCosto,R.IdSubCos,R.IdNom,R.pVehiculo,R.VrSalario,TipoLiq,IdArea,IdTipCon,D.IdConcepto,Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRet_Cr @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdCausa VARCHAR(4)=Null
,@pmNumero INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdPeriodo VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null
 AS 
 SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,R.Numero AS NumLiquida,Fecha,R.NContrato AS Ncontrato,R.IdCausa AS IdCauRet,CausalRet,FecInicial,FecFinal,DiasTrab,R.DiasNoRem AS Dias_Norem,VrTotDev,VrTotDed,VrTotCes
,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,R.VrSalario AS Liq_Salbasico,R.IdDep AS CodDep,Dependencia,R.IdCCosto AS CodCcost,CCosto,R.IdSubCos AS CodSubcos,SubCosto
,R.IdNom AS CodNom,TipoNomina,TipoLiq,R.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,R.Observacion AS Observ,Anulado,R.IdEstado AS Liq_IdEstdo,ED.Estado AS Liq_Estado,TimeSys,R.FecUpdate AS FecUpd,R.IdUsuario AS IdUsuari,Usuario
,Item,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,Unidad,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,D.Tarifa  AS Tarfa,VrBase,DiasBase,D.DiasNoRem AS DiasNov,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd
,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,FD.Fondo AS Det_Fondo,VrBaseLiq
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar
,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,Duracion,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,ModPromdio,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio
 FROM Trn_NomRet AS R  INNER JOIN  Empleados AS E ON R.IdEmpleado=E.IdEmpleado  INNER JOIN NomCausalesRet AS CAR ON R.IdCausa=CAR.IdCausa
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON R.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON R.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo  INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON R.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN Trn_NomRetDet AS D ON R.IdEmpleado=D.IdEmpleado AND R.Numero=D.Numero
 LEFT JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom   LEFT JOIN NomVehiculos AS VH ON R.pVehiculo=VH.IdVehiculo
 WHERE R.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')   AND R.IdCausa LIKE ISNULL(@pmIdCausa,'%') AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (R.Numero>=ISNULL(@pmNumero,0)  AND  R.Numero<=ISNULL(@pmNumero,2147483647))
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
AND (R.NContrato>=ISNULL(@pmNContrato,0)  AND  R.NContrato<=ISNULL(@pmNContrato,2147483647))
ORDER BY R.IdEmpleado,R.Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomRet_Crr @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdCausa VARCHAR(4)=Null
,@pmNumero INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdPeriodo VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null
 AS 
 SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Numero,Fecha,R.NContrato AS Ncontrato,R.IdCausa AS IdCauRet,CausalRet,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes
,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,R.VrSalario AS Liq_Salbasico,R.IdDep AS CodDep,Dependencia,R.IdCCosto AS CodCcost,CCosto,R.IdSubCos AS CodSubcos,SubCosto
,R.IdNom AS CodNom,TipoNomina,TipoLiq,R.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,R.Observacion AS Observ,Anulado,R.IdEstado AS Liq_IdEstdo,ED.Estado AS Liq_Estado,TimeSys,R.FecUpdate AS FecUpd,R.IdUsuario AS IdUsuari,Usuario
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar
,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,Duracion,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,ModPromdio,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio
 FROM Trn_NomRet AS R  INNER JOIN  Empleados AS E ON R.IdEmpleado=E.IdEmpleado  INNER JOIN NomCausalesRet AS CAR ON R.IdCausa=CAR.IdCausa
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON R.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON R.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo  INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON R.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom  LEFT JOIN NomVehiculos AS VH ON  R.pVehiculo=VH.IdVehiculo
 WHERE R.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')   AND R.IdCausa LIKE ISNULL(@pmIdCausa,'%') AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND  Numero<=ISNULL(@pmNumero,2147483647))
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
AND (R.NContrato>=ISNULL(@pmNContrato,0)  AND  R.NContrato<=ISNULL(@pmNContrato,2147483647))
ORDER BY R.IdEmpleado,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomSueldos @pmNumero INT,@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT Numero,IdEmpleado,Fecha,NContrato,VrSueAnterior,VrSueNuevo,VrAtAnterior,VrAtNuevo,MetodoUp,Reemplzado
,FecUltAumto,CritSelect,Observacion,TimeSys,IdUsuario
 FROM Trn_NomSueldos
 WHERE Numero=@pmNumero AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomSueldosId @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomSueldos
 WHERE  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomSueldos_Cr  @pmIdEmpleado VARCHAR(16)=Null,@pmNumero INT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT Numero,Fecha,S.IdEmpleado AS IdEmpldo,Apellidos,Nombres,S.NContrato AS NumCtrato,VrSueAnterior,VrSueNuevo,VrAtAnterior,VrAtNuevo,MetodoUp,Reemplzado
,FecUltAumto,CritSelect,S.Observacion AS Observ,TimeSys,S.IdUsuario AS IdUsuari,Usuario
--datos del empleado
,E.IdProf AS CodProf,Profesion
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdNom AS CodNom,TipoNomina
,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,C.IdEstado AS Con_IdEstdo,Estado,C.Inactivo AS Con_inactivo
 FROM Trn_NomSueldos AS S INNER JOIN Empleados AS E ON S.IdEmpleado=E.IdEmpleado INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf 
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario 
 INNER JOIN  Emp_Contrato AS C ON S.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon 
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala 
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea 
 WHERE S.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND  Numero<=ISNULL(@pmNumero,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Numero,Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomTablaRet @pmnAnno INT,@pmnIntrvalo INT=Null
 AS 
 SELECT nAnno,nIntrvalo,VrInicial,VrFinal,Tarifa,VrRetncion,TarExcdnte,VrBaseExc,FechaAdd,FechaUpdate,IdUsuario
 FROM NomTablaRet
 WHERE nAnno=@pmnAnno  AND (nIntrvalo>=ISNULL(@pmnIntrvalo,0)  AND nIntrvalo<=ISNULL(@pmnIntrvalo,2147483647))
 ORDER BY nIntrvalo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomTablaRetInv @pmnAnno INT,@pmValbase MONEY
 AS 
 SELECT nAnno,nIntrvalo,VrInicial,VrFinal,Tarifa,VrRetncion,TarExcdnte,VrBaseExc
 FROM NomTablaRet
 WHERE nAnno=@pmnAnno AND @pmValbase>VrInicial AND @pmValbase<=VrFinal
 ORDER BY nIntrvalo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomTablaRetItm @pmnAnno INT
 AS 
 SELECT MAX(nIntrvalo) AS MXITM,MAX(VrFinal) AS MXFINAL
 FROM NomTablaRet
 WHERE nAnno=@pmnAnno

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVac @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem
,VrRemndo,VrTotDed,VrSalario,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacBan @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
AS
SELECT V.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,e_mail,Telefono,V.NContrato AS NumContrato
,E.Direccion AS EmpDireccion,TelMovil,Cargo
,Cantidad,VrLiquida,VrBase,VrRemndo,VrTotDed,(VrLiquida+VrRemndo)-VrTotDed  AS SNETVAC
 FROM Trn_NomVac AS V INNER JOIN Empleados AS E ON V.IdEmpleado=E.IdEmpleado  
 INNER JOIN  Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0  AND FPnomina='TRANS' 
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') 
 ORDER BY  Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacCmp @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT  TipCom,Comprobante,IdCiaCom,COUNT(Numero) AS SCANT 
 FROM  Trn_NomVac
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Comprobante>0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 GROUP BY TipCom,Comprobante,IdCiaCom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 SELECT IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension
,VrSalud,NPrestamo,NCuota,IdPeriodo
 FROM Trn_NomVacDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacDetCon @pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmMes VARCHAR(6)
,@pmIdPeriodo VARCHAR(8)=Null,@pmNContrato INT=Null
 AS 
 SELECT SUM(VD.Cantidad) AS SCANT,SUM(VrDevgado) AS SDEVNG,SUM(VrDeducido) AS STOTDED,SUM(VrBaseLiq) AS STOTBAS
,SUM(VrCertfcado) AS STOTCER,SUM(VrPension) AS STOTPEN,SUM(VrSalud) AS STOTSALUD
 FROM Trn_NomVacDet AS VD INNER JOIN Trn_NomVac AS V ON VD.IdEmpleado=V.IdEmpleado AND VD.Numero=V.Numero
 WHERE VD.IdEmpleado=@pmIdEmpleado AND  IdConcepto=@pmIdConcepto AND Anulado=0 AND SUBSTRING(IdPeriodo,1,6)=@pmMes
 AND  IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') 
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacDetRes @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmInactivo BIT=Null
,@pmEmp_Inactivo BIT=Null,@pmFecVacIni SMALLDATETIME=Null,@pmFecVacFin SMALLDATETIME=Null
 AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Q.Numero AS NumLiquida,Q.NContrato AS NumContrato,Fecha,FecInicial,FecFinal,Q.Cantidad AS CantDias
,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico
,Q.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,Q.Observacion AS Observ
--detalle de liq vac
,Item,IdConcepto,Detalle,D.Cantidad AS Cant,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud
--datos del contrato
,IdArea,IdDep,IdInstala,IdNom,TipoLiquida,IdCCosto,IdSubCos,C.VrSalario AS SalBasico,VrAuxTrans
 FROM Trn_NomVac AS Q  INNER JOIN  Empleados AS E ON Q.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato
 LEFT JOIN Trn_NomVacDet AS D ON Q.IdEmpleado=D.IdEmpleado AND Q.Numero=D.Numero
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND IdDep LIKE ISNULL(@pmIdDep,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdNom LIKE ISNULL(@pmIdNom,'%')
 AND IdInstala LIKE ISNULL(@pmIdInstala,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (Q.NContrato >=ISNULL(@pmNContrato ,0)  AND Q.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND (FecInicial>=ISNULL(@pmFecVacIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecVacFin,CAST('20781230' AS SMALLDATETIME)))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY IdEmpldo,Q.Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacDet_Cr @pmIdEmpleado VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNumero INT=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null,@pmFecVacIni SMALLDATETIME=Null
,@pmFecVacFin SMALLDATETIME=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Q.Numero AS NumLiquida,Fecha,Q.NContrato AS NumContrato,FecInicial,FecFinal,Q.Cantidad AS CantDias,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem
,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico,Q.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,LogPmdio,Anulado
,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--detalle de liq vac
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,D.Cantidad AS Cant,VrDevgado,VrDeducido,D.Tarifa AS Tarfa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps
,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdJornada AS CodJnada,Jornada
,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,C.IdCCosto AS CodCcto,CCosto,C.IdSubCos AS CodSubcen,SubCosto,Asistencia,NoDevenga,TipoTrabj
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModPromdio,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,VrSalud
 FROM Trn_NomVac AS Q INNER JOIN Trn_NomVacDet AS D ON Q.IdEmpleado=D.IdEmpleado AND Q.Numero=D.Numero
 INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado
 INNER JOIN  Empleados AS E ON Q.IdEmpleado=E.IdEmpleado  INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom 
 WHERE  Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND Q.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Q.Numero>=ISNULL(@pmNumero,0)  AND Q.Numero<=ISNULL(@pmNumero,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Q.NContrato >=ISNULL(@pmNContrato ,0)  AND Q.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (FecInicial>=ISNULL(@pmFecVacIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecVacFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,Q.Numero,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacId @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacIng @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Q.Numero AS NumLiquida,Fecha,Q.NContrato AS NumContrato,FecInicial,FecFinal,Q.Cantidad AS CantDias,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem
,DiasVac,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico,Q.pVehiculo AS PlacaVeh
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,CN.Tarifa AS TarifDft,D.Cantidad AS Cant,VrDevgado,VrDeducido,D.Tarifa AS Tarfa,VrBaseLiq,VrCertfcado,VrPension,VrSalud,NPrestamo
,IdTipCon,IdArea,IdDep,IdInstala,IdNom,TipoLiquida,IdCCosto,IdSubCos,C.VrSalario AS SalBasico,VrAuxTrans,E.Inactivo AS Emp_Inactvo,C.Inactivo AS Con_inactivo,IdFonPen,IdFonEps
 FROM Trn_NomVac AS Q INNER JOIN Empleados AS E ON Q.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato
 LEFT JOIN  Trn_NomVacDet AS D ON Q.IdEmpleado=D.IdEmpleado AND Q.Numero=D.Numero
 LEFT JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  
 WHERE  FecInicial  BETWEEN  @pmFecIni AND @pmFecFin
 AND IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdDep LIKE ISNULL(@pmIdDep,'%') AND IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')   AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND (Q.NContrato>=ISNULL(@pmNContrato,0)  AND Q.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY Q.IdEmpleado,Q.Numero,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVacNom @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmNContrato INT=Null
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase
 FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND FecInicial<=@pmFecFin AND FecFinal>=@pmFecIni
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 ORDER BY Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVac_Cr @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT V.IdEmpleado AS IdEmpldo,Apellidos,Nombres,V.Numero AS NumReg,Fecha,V.NContrato AS NumContrato,FecInicial,FecFinal,V.Cantidad AS DiasCal,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac
,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,V.VrSalario AS Vac_VrBasico,V.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,V.Observacion AS Observ,LogPmdio,Anulado,V.IdEstado AS Vac_IdEstdo,ED.Estado AS Vac_Estado
,TimeSys,V.FecUpdate AS FecUpd,V.IdUsuario AS IdUsuari,Usuario
--datos del detalle de liquidacion
,Item,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,Detalle,D.Cantidad AS Cant,Unidad,VrDevgado,VrDeducido,D.Tarifa AS Tarfa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo
--datos del empleado 
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdCCosto AS CodCcto,CCosto
,C.IdSubCos AS CodSubcen,SubCosto,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio,VrSalud
 FROM Trn_NomVac  AS V INNER JOIN  Empleados AS E ON V.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON V.IdEstado=ED.IdEstado
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom 
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 LEFT JOIN  Trn_NomVacDet  AS D ON V.IdEmpleado=D.IdEmpleado AND V.Numero=D.Numero  LEFT JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 LEFT JOIN TiposCom AS TM ON V.TipCom=TM.IdCom
 LEFT JOIN NomVehiculos AS VH ON V.pVehiculo=VH.IdVehiculo
 WHERE  V.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (V.Numero>=ISNULL(@pmNumero,0)  AND V.Numero<=ISNULL(@pmNumero,2147483647))
ORDER BY   V.Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVac_Crr @pmIdEmpleado VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNumero INT=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null,@pmFecVacIni SMALLDATETIME=Null,@pmFecVacFin SMALLDATETIME=Null
 AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Numero,Fecha,Q.NContrato AS NumContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem
,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico,Q.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,LogPmdio,Anulado
,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps
,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdJornada AS CodJnada,Jornada
,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,C.IdCCosto AS CodCcto,CCosto,C.IdSubCos AS CodSubcen,SubCosto,Asistencia,NoDevenga,TipoTrabj
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModPromdio,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo
 FROM Trn_NomVac AS Q INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  
 INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado  INNER JOIN  Empleados AS E ON Q.IdEmpleado=E.IdEmpleado  
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom 
 WHERE  Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND Q.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Q.NContrato >=ISNULL(@pmNContrato ,0)  AND Q.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (FecInicial>=ISNULL(@pmFecVacIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecVacFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,Numero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomVehiculos @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT IdVehiculo,NumVeh,ClaseVeh,TipoAdmon,GrupoProp,VehPropio,CedCond,Conductor
 FROM NomVehiculos
 WHERE IdVehiculo=@pmIdVehiculo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomina @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,NContrato,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom
,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,TimeSys,FecUpdate,IdUsuario
 FROM Trn_Nomina
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%')
 ORDER BY KeyRegistro

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaApo @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmCodFondo VARCHAR(8)=Null,@pmIdCia CHAR(2)=Null
AS 
 SELECT N.KeyRegistro AS KeyReg,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContto,FecInicial,FecFinal,N.IdDep AS CodDep,N.IdInstala AS CodInstala,N.IdCCosto AS CodCcto
,N.IdSubCos AS CodSubcc,N.IdNom AS CodNom,N.pVehiculo AS PlacaVeh,N.VrSalario AS Salbasico,EsRetiro,NLiqRet,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,FecIngreso,FecRetiro,IdArea,C.IdClase AS CodClaRie
,CR.Tarifa AS TarRie,TipoTrabj,VrAuxTrans,VrUpc,SalIntegral,SalMinimo,C.Inactivo AS Con_Inctivo,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,CN.Tarifa AS TarifDft,ClaseLiq,CantDevg,CantDed,VrTotDevg,VrTotDed,VrOrigen,D.Tarifa AS Tarfa
,DiasCalc,DiasNov,DiasCalc-DiasNov AS DiasNeto,CodFondo
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase  INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND NLiqRet>=0 AND D.IdConcepto IN ('PEN','RIE','SAL','FSP','FSU','SEN','ICB','COM','DCP','DCS','AVP','AVA')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND N.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')   AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND CodFondo LIKE ISNULL(@pmCodFondo,'%')
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY  N.IdEmpleado,N.NContrato,D.IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaAux @pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmnMes VARCHAR(2),@pmnAnno VARCHAR(4)
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,NContrato,VrSalario,VrATransMes
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
 AND SUBSTRING(IdPeriodo,5,2)=@pmnMes AND  SUBSTRING(IdPeriodo,1,4)=@pmnAnno 
 ORDER BY IdPeriodo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaBan @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,N.NContrato AS NumContrato,TipoLiq,Cargo
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN ClaseCta AS CTA ON E.IdClase=CTA.IdClase
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes  AND FPnomina='TRANS' AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,N.NContrato,TipoLiq,Cargo
 ORDER BY Apellidos,Nombres,N.IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaCa @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT KeyRegistro,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NCtto,TipCom,Comprobante,IdCiaCom,N.IdEstado AS IdEstdo
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 WHERE IdPeriodo=@pmIdPeriodo  AND IdNom=@pmIdNom AND EsRetiro=0 AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY  KeyRegistro

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaCed @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaCip @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecha SMALLDATETIME
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,NContrato,EsRetiro,NLiqRet
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND NLiqRet<>-1 AND FecFinal<=@pmFecha
 ORDER BY IdPeriodo,FecInicial

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaCon @pmIdEmpleado VARCHAR(16),@pmNContrato INT
 AS 
 SELECT IdPeriodo,IdEmpleado,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,NContrato
,TipCom,Comprobante,IdCiaCom,IdEstado,EsRetiro,NLiqRet
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
 ORDER BY IdPeriodo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaDia @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmnMes VARCHAR(6)
 AS 
 SELECT  SUM(Cantidad) AS SDIAS,SUM(CantNoRem) AS SNOREM,SUM(Cantidad-CantNoRem) AS SDIASNET
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato 
 AND SUBSTRING(IdPeriodo,1,6)=@pmnMes


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaDso @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdNom VARCHAR(4)=Null
 AS 
 SELECT KeyRegistro,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,IdPeriodo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,N.NContrato AS NumContrato,N.IdNom AS CodNom,TipoNomina
,N.IdDep AS CodDep,Dependencia,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcos,SubCosto,IdInstala
,VrSalario,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS  Observ,N.IdEstado AS IdEstdo,Estado,EsRetiro,NLiqRet,TipoLiq,VrATransMes,N.IdUsuario AS IdUsuari,Usuario,TimeSys,N.FecUpdate AS FecUpdte
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN Dependencias AS D ON N.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 WHERE IdPeriodo=@pmIdPeriodo AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND N.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 ORDER BY  N.IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaGcon  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT N.IdPeriodo AS NumPdo,N.KeyRegistro AS KeyReg,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,ClaseLiq
 ,SUM(CantDevg) AS SCantDev,SUM(VrTotDevg) AS STotDev,SUM(CantDed) AS SCantDed,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc-DiasNov) AS TotalDias,SUM(VrBaseLiq) AS STotLiq
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE'  AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%')
 AND N.IdNom like ISNULL(@pmIdNom,'%')  AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY N.IdPeriodo,N.KeyRegistro,N.IdEmpleado,Apellidos,Nombres,D.IdConcepto,Concepto,ClaseCon,ClaseLiq
 ORDER BY N.IdPeriodo,N.KeyRegistro,N.IdEmpleado,D.IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaIng @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null
AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContto,SUBSTRING(N.IdPeriodo,1,6) AS Nmes,N.IdDep AS CodDep,N.IdInstala AS CodInstala
,N.IdCCosto AS CodCcto,N.IdSubCos AS CodSubcc,N.IdNom AS CodNom,N.pVehiculo AS PlacaVeh,N.VrSalario AS Salbasico,NLiqRet,TipoLiq,IdArea,IdTipCon
,D.IdConcepto AS CodConcepto,Concepto,ClaseLiq,SUM(Cantidad) AS Scant,SUM(CantNoRem) AS SCanNoRem,SUM(VrBaseLiq) AS SbaseLiq
,SUM(CantDevg) AS SCanDev,SUM(CantDed) AS SCanDed,SUM(VrTotDevg) AS STotDev,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS SValBase,MAX(D.Tarifa) AS Tarfa
,SUM(DiasCalc) AS SDiasCalc, SUM(DiasNov) AS SDiasNov,SUM(DiasCalc-DiasNov) AS DiasNeto
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin  AND ClaseLiq IN ('NOMINA','NOVEDAD','LIQUDACION')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')   AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 GROUP BY N.IdEmpleado,Apellidos,Nombres,N.NContrato,SUBSTRING(N.IdPeriodo,1,6),N.IdDep,N.IdInstala,N.IdCCosto,N.IdSubCos
,N.IdNom,N.pVehiculo,N.VrSalario,NLiqRet,TipoLiq,IdArea,IdTipCon,D.IdConcepto,Concepto,ClaseLiq

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaInt @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4),@pmEsRetiro BIT=Null
 AS 
 SELECT N.IdPeriodo AS IdPdo,N.KeyRegistro AS IdKeyReg,N.IdEmpleado AS IdEmpldo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,N.NContrato AS NCntto,IdDep,IdInstala,IdCCosto
,IdSubCos,IdNom,VrSalario,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,EsRetiro,NLiqRet,TipoLiq,Apellidos,Nombres,EsCondtor,E.pVehiculo AS VehiculoDef
--detalle de la nomina
,Item,D.IdConcepto AS IdConcep,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,ClaseLiq,VrOrigen,D.Tarifa AS Tarfa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D  ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN  NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 WHERE N.IdPeriodo=@pmIdPeriodo AND IdNom like ISNULL(@pmIdNom,'%')
 AND  (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY N.IdEmpleado,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaNov @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmEsRetiro BIT=Null,@pmIdConcepto VARCHAR(4)=Null
AS 
 SELECT N.IdEmpleado AS IdEmpldo,IdConcepto, SUM(CantDevg) AS SCantDev,SUM(CantDed) AS SCantDed
,SUM(VrTotDevg) AS SValDev,SUM(VrTotDed) AS SValDed,SUM(VrOrigen) AS SValBase,SUM(VrBaseLiq) AS SValLiquida
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND NLiqRet>=0 AND IdConcepto IN ('IGE','IRP','LIC') AND ClaseLiq='NOVEDAD'
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY N.IdEmpleado,IdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaPag  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,Item,D.IdConcepto AS CodConcepto,Detalle,ClaseCon,CantDevg,D.Unidad AS Undad,VrUnitario,VrTotDevg,CantDed,VrTotDed,NPrestamo,NCuota
,VrOrigen,D.Tarifa AS TarifaBase,DiasCalc,DiasNov,DiasCalc-DiasNov AS TotalDias,CodFondo,FD.Fondo AS Det_Fondo,ClaseLiq,OrigCargue,Concepto,VrBaseLiq
,N.IdPeriodo AS IdPerdo,FecInicial,FecFinal,N.KeyRegistro AS KeyRegstro
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE' AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%')
 AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND N.IdNom like ISNULL(@pmIdNom,'%')  AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY Apellidos,Nombres,N.IdPeriodo,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaRes @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumCntrato,KeyRegistro,IdPeriodo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdNom AS CodNmna,TipoNomina,N.IdDep AS CodDep,Dependencia,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcos,SubCosto,N.IdInstala AS CodIstala,Instlacion
,N.VrSalario AS SalBasico,N.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS IdEstdo,ED.Estado AS Nom_Estado,EsRetiro,NLiqRet,TipoLiq,TimeSys
,N.FecUpdate AS Fec_Update,N.IdUsuario AS IdUsuari,Usuario
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,FC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS VlrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj,C.IdGrupo AS CodGrup
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN Dependencias AS D ON N.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala  INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom 
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY  N.IdEmpleado,IdPeriodo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaRtot @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
 AS 
 SELECT SUM(Cantidad) AS SCant,SUM(VrDevengado) AS TotalDev,SUM(VrDeducido) AS TotalDed,SUM(N.VrSalario) AS ToalSalBasico,SUM(VrAuxTrans) AS TotalAuxtrans
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaTEmp  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  Apellidos,Nombres,N.IdEmpleado AS IdEmpldo,N.NContrato AS NumContrato,sum(VrTotDevg) AS VrTotalDevg,sum(VrTotDed) AS VrTotalDed,sum(VrBaseLiq) AS VrTotOtros
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE' AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') 
 AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND N.IdNom like ISNULL(@pmIdNom,'%') AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY Apellidos,Nombres,N.IdEmpleado,N.NContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaVeha @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
 AS 
 SELECT N.pVehiculo AS PlacaVeh,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdCCosto AS CdCcosto,E.pVehiculo AS Emp_Veh,TipoLiq
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 WHERE N.IdPeriodo=@pmIdPeriodo AND FPnomina='OTRO' AND EsCondtor<>0 AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 GROUP BY   N.pVehiculo,N.IdEmpleado,Apellidos,Nombres,N.NContrato,N.IdCCosto,E.pVehiculo,TipoLiq
 ORDER BY  N.pVehiculo,N.IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNominaVehc @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
 AS 
 SELECT N.pVehiculo AS PlacaVeh,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdCCosto AS CdCcosto,E.pVehiculo AS Emp_Veh,TipoLiq
,ClaseLiq,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 WHERE N.IdPeriodo=@pmIdPeriodo AND TipoTrabj=3 AND EsCondtor<>0 AND ClaseLiq IN ('NOMINA','NOVEDAD','PROVISION','APORTE')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 GROUP BY   N.pVehiculo,N.IdEmpleado,Apellidos,Nombres,N.NContrato,N.IdCCosto,E.pVehiculo,TipoLiq,ClaseLiq
 ORDER BY  N.pVehiculo,N.IdEmpleado,ClaseLiq

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomina_Cpn  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdPeriodo AS IdPerdo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdDep AS CodDep,Dependencia,N.IdInstala AS CodInst,Instlacion,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcen,SubCosto,N.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,TipoLiq,N.VrSalario AS VrSalBasico,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS Nom_IdEstdo,EN.Estado AS Nom_Estado,EsRetiro,NLiqRet
,N.KeyRegistro AS KeyRegstro,TimeSys,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario
--datos detalle de nomina
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad AS Undad,ClaseLiq,VrOrigen,D.Tarifa AS TarifaBase,DiasCalc,DiasNov,CodFondo,FD.Fondo AS Det_Fondo
,NPrestamo,NCuota,OrigCargue,VrBaseLiq,ClaseCon
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj
,NumVeh,TipoAdmon,VehPropio,VrATransMes
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado 
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 LEFT JOIN NomVehiculos AS VH ON N.pVehiculo=VH.IdVehiculo
 WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND ClaseLiq IN ('NOMINA','NOVEDAD','LIQUDACION')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') 
 AND N.IdNom like ISNULL(@pmIdNom,'%') AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY N.KeyRegistro,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryNomina_Cr  @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdPeriodo AS IdPerdo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdDep AS CodDep,Dependencia,N.IdInstala AS CodInst,Instlacion,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcen,SubCosto,N.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,TipoLiq,N.VrSalario AS VrSalBasico,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS Nom_IdEstdo,EN.Estado AS Nom_Estado,EsRetiro,NLiqRet
,N.KeyRegistro AS KeyRegstro,TimeSys,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario
--datos detalle de nomina
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad AS Undad,ClaseLiq,VrOrigen,D.Tarifa AS TarifaBase,DiasCalc,DiasNov,CodFondo,FD.Fondo AS Det_Fondo
,NPrestamo,NCuota,OrigCargue,VrBaseLiq,ClaseCon
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj
,NumVeh,TipoAdmon,VehPropio,VrATransMes
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado 
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 LEFT JOIN NomVehiculos AS VH ON N.pVehiculo=VH.IdVehiculo
 WHERE N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') AND N.IdNom like ISNULL(@pmIdNom,'%')
 AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY N.KeyRegistro,Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryObjetosApp @pmIdObj VARCHAR(10)
 AS 
 SELECT IdObj,IdGrupo,SubModulo,IndObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo
 FROM Sys_ObjetosApp
 WHERE IdObj=@pmIdObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryObjetosAppLta @pmNivelMinimo INT,@pmIdGrupo VARCHAR(6)=Null
,@pmSubModulo VARCHAR(3)=Null,@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT O.IdGrupo AS IdGrup,GrupoObjeto,SubModulo,IndObj,IdObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo
 FROM Sys_ObjetosApp AS O INNER JOIN Sys_GruposObj AS G ON O.IdGrupo=G.IdGrupo
 WHERE NivelMinimo<=@pmNivelMinimo AND O.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') 
 AND SubModulo LIKE ISNULL(@pmSubModulo,'%') AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY nModulo,O.IdGrupo,SubModulo,IndObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryObjetosAppSub @pmIdGrupo VARCHAR(6)=Null
 AS
 SELECT   SubModulo,Count(IndObj) AS CantInd
 FROM     Sys_ObjetosApp 
 WHERE IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 GROUP BY SubModulo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryOpciones @pmIdOpc VARCHAR(3),@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo
 FROM adm_Opciones
 WHERE IdOpc LIKE ISNULL(@pmIdOpc,'%') AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY IdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryOpcionesLta @pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo
 FROM adm_Opciones
 WHERE nModulo='GENERAL' Or  nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY IdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPaises @pmIdPais VARCHAR(8)
 AS 
 SELECT IdPais,CodISO,NombrePais,IdMneda
 FROM adm_Paises
 WHERE IdPais=@pmIdPais

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPaisesIso @pmCodISO VARCHAR(3)
 AS 
 SELECT IdPais,CodISO,NombrePais,IdMneda
 FROM adm_Paises
 WHERE CodISO=@pmCodISO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPaisesLta @pmIdPais VARCHAR(8)=Null
 AS 
 SELECT IdPais,CodISO,NombrePais,P.IdMneda AS CodMneda,Mneda,Simbolo,MneLocal,VrCambio
 FROM adm_Paises AS P INNER JOIN adm_monedas AS M ON P.IdMneda=M.IdMneda
 WHERE IdPais LIKE ISNULL(@pmIdPais,'%')
 ORDER BY NombrePais



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPermisos @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null
 AS 
 SELECT IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename
 FROM adm_Permisos
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%')
 ORDER BY IdObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPermisosLta @pmIdUsuario VARCHAR(11),@pmIdGrupo VARCHAR(6)=Null,@pmSubModulo VARCHAR(3)=Null
,@pmnModulo VARCHAR(10)=Null
AS
 SELECT P.IdUsuario AS IdUsuari,Usuario,P.IdObj AS IdObjto,Nombre,IndObj,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename,O.IdGrupo AS IdGrup,GrupoObjeto
,SubModulo,Formulario,Permisos,NivelMinimo,Consecutivo,U.IdGrupo AS NivelUsu
 FROM adm_Permisos AS P  INNER JOIN Sys_ObjetosApp AS O ON P.IdObj =O.IdObj
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Sys_GruposObj AS G ON O.IdGrupo=G.IdGrupo
 WHERE  P.IdUsuario=@pmIdUsuario  AND O.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  AND SubModulo LIKE ISNULL(@pmSubmodulo,'%')
 AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY nModulo,O.IdGrupo,SubModulo,IndObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPermisosRoles @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null,@pmIdRole VARCHAR(3)=Null
 AS 
 SELECT IdUsuario,IdObj,IdRole,Asignado
 FROM adm_PermisosRoles
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%') AND IdRole LIKE ISNULL(@pmIdRole,'%')
 ORDER BY IdObj,IdRole

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPermisosRoles_Cr @pmIdUsuario VARCHAR(11)=Null,@pmIdObj VARCHAR(10)=Null
 AS 
 SELECT P.IdUsuario AS IdUsuari,Usuario,P.IdObj AS CodObj,Nombre,O.IdGrupo AS IdGrup,SubModulo,P.IdRole AS IdFuncion,Funcion,Asignado
 FROM adm_PermisosRoles AS P INNER JOIN Sys_ObjetosApp AS O ON P.IdObj=O.IdObj
 INNER JOIN Sys_Roles AS R ON  P.IdObj=R.IdObj AND P.IdRole=R.IdRole
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND P.IdObj LIKE ISNULL(@pmIdObj,'%') 
 ORDER BY Usuario,IndObj,P.IdRole

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPermisos_Cr @pmNivUsu INT,@pmIdUsuario VARCHAR(11)=Null,@pmIdGrupo VARCHAR(6)=Null
,@pmSubModulo VARCHAR(3)=Null,@pmnModulo VARCHAR(10)=Null
AS
 SELECT P.IdUsuario AS IdUsuari,Usuario,U.IdGrupo AS NivelUsu,IdEstacion,U.IdCargo AS CodCargo,Cargo,FechaAcc,U.Inactivo AS Inactvo
 ,P.IdObj AS IdObjto,Nombre,IndObj,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename,O.IdGrupo AS IdGrup,GrupoObjeto
,nModulo,SubModulo,Formulario,Permisos,NivelMinimo,Consecutivo
 FROM adm_Permisos AS P  INNER JOIN Sys_ObjetosApp AS O ON P.IdObj =O.IdObj
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Sys_GruposObj AS G ON O.IdGrupo=G.IdGrupo
 INNER JOIN Cargos AS C ON U.IdCargo=C.IdCargo
 WHERE U.Inactivo=0 AND U.IdGrupo<=@pmNivUsu AND P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')  AND O.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') 
 AND SubModulo LIKE ISNULL(@pmSubmodulo,'%')  AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY Usuario,nModulo,O.IdGrupo,SubModulo,IndObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryProfesiones @pmIdProf VARCHAR(4)
 AS 
 IF @pmIdProf IS NULL
  SELECT IdProf,Profesion
  FROM Profesiones
  WHERE Inactivo=0
  ORDER  BY Profesion
 ELSE
  SELECT IdProf,Profesion,Inactivo
  FROM Profesiones
  WHERE IdProf=@pmIdProf

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryPuc @pmIdCuenta VARCHAR(16)
 AS 
 IF @pmIdCuenta IS NULL
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,FechaAdd,FechaUpdate,IdUsuario,Afijos
  FROM Puc
  WHERE  Inactivo=0
  ORDER BY IdCuenta
 ELSE
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,FechaAdd,FechaUpdate,IdUsuario,Inactivo,Afijos
  FROM Puc
  WHERE IdCuenta=@pmIdCuenta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryPucAju @pmIdCuenta VARCHAR(16)=Null,@pmCueIni VARCHAR(16)=Null
,@pmCueFin VARCHAR(16)=Null
AS
 IF @pmCueIni IS NULL --NO RANGOS
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
 ,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,Afijos
  FROM  Puc
  WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta like ISNULL(@pmIdCuenta,'%')
  ORDER BY IdCuenta
 ELSE
  BEGIN
  IF @pmCueIni='LIKE'
   SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
   ,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,Afijos
   FROM  Puc
   WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta LIKE @pmIdCuenta
   ORDER BY IdCuenta
  ELSE
   SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
   ,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,Afijos
   FROM  Puc
   WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta BETWEEN @pmCueIni AND @pmCueFin
   ORDER BY IdCuenta
 END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryPucSub  @pmIdCuenta VARCHAR(16)

AS
  SELECT  IdCuenta,NomCuenta   FROM  Puc  
 WHERE  SUBSTRING(IdCuenta ,1,LEN(@pmIdCuenta) )=@pmIdCuenta AND IdCuenta<>@pmIdCuenta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryRegimenDian @pmIdRegimen VARCHAR(4)
 AS 
 IF @pmIdRegimen IS NULL
  SELECT IdRegimen,Regimen
  FROM RegimenDian
  WHERE Inactivo=0
 ORDER BY Regimen
 ELSE
  SELECT IdRegimen,Regimen,Inactivo
  FROM RegimenDian
  WHERE IdRegimen=@pmIdRegimen

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryRegistro @pmIdCia CHAR(2)=Null
 AS 
 SELECT IdCia,IdEmpresa,NitEmpresa,DvNit,RazonSocial,Descripcion,Direccion,Telefono,Fax,R.IdLocal AS CodCiu
,R.IdPais AS IdPai,e_mail,ArchivoLogo,NumeroSerial,Regimen,Licencia,VigenciaLic,Personeria,Leyenda,FechaRegistro,FechaVence,CurrtyDate
,CodISO,NombrePais,P.IdMneda AS CodMnda,Mneda,Simbolo,MneLocal,VrCambio,Localidad,TipoId,NitRepLegal,RepLegal,TipoPersna,CIIUDane,CurDate1
 FROM adm_Registro AS R INNER JOIN adm_Paises AS P ON R.IdPais=P.IdPais 
 INNER JOIN adm_monedas AS M ON P.IdMneda=M.IdMneda
 INNER JOIN Localidades AS  L ON R.IdLocal=L.IdLocal
 WHERE IdCia  LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryRelaciones @pmIdTabla VARCHAR(20)=Null,@pmTablaForanea VARCHAR(20)=Null,@pmCampoForaneo VARCHAR(20)=Null
 AS 
 SELECT IdTabla,TablaForanea,CampoForaneo,BasedeDatos,NoValidar
 FROM Sys_Relaciones
 WHERE IdTabla LIKE ISNULL(@pmIdTabla, '%') AND TablaForanea LIKE ISNULL(@pmTablaForanea,'%') 
 AND CampoForaneo LIKE ISNULL(@pmCampoForaneo,'%')
 ORDER BY IdTabla,TablaForanea,CampoForaneo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryRelacionesEnt @pmIdTabla VARCHAR(20), @pmNoValidar BIT=Null
AS
 SELECT R.IdTabla AS TablaPmry,TablaForanea,CampoForaneo,BasedeDatos,NoValidar
,NivelRel,CamposPK,FngKey,Sp_Qry,Sp_Qpmt,Sp_Ins, Sp_Upd, Sp_Del
 FROM Sys_Relaciones AS R INNER JOIN Sys_Entidades AS E ON  R.IdTabla=E.IdTabla
 WHERE  R.IdTabla=@pmIdTabla  
 AND (NoValidar=ISNULL(@pmNoValidar,0) or NoValidar=ISNULL(@pmNoValidar,1))
 ORDER BY TablaForanea,CampoForaneo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryRelacionesFor @pmIdTabla VARCHAR(20)
 AS 
 SELECT R.IdTabla AS NomTabla,TablaForanea,CampoForaneo,BasedeDatos,NoValidar,NivelRel
 FROM Sys_Relaciones AS R LEFT JOIN Sys_Entidades AS E ON R.TablaForanea=E.IdTabla
 WHERE R.IdTabla=@pmIdTabla
 ORDER BY  NivelRel

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryReport @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2)
 AS 
 SELECT TipoRep,NomRep,IdRep,Descripcion,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
 FROM Sys_Report
 WHERE TipoRep like ISNULL(@pmTipoRep,'%')  AND IdRep like ISNULL(@pmIdRep,'%%')
 ORDER BY TipoRep, IdRep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryReportDso @pmTipoRep VARCHAR(3)
AS
 SELECT  TipoRep, IdRep,Descripcion,IdRep+ '  '+Descripcion AS DsRep,Formato
 FROM   Sys_Report
 WHERE TipoRep=@pmTipoRep
 ORDER BY IdRep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryReportGru
AS
 SELECT TipoRep,NomRep,count(IdRep) AS Cuenta
 FROM   Sys_Report
 GROUP BY  TipoRep,NomRep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryRoles @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3)=Null
 AS 
 SELECT IdObj,IdRole,Funcion
 FROM Sys_Roles
 WHERE IdObj=@pmIdObj AND IdRole LIKE ISNULL(@pmIdRole,'%')
 ORDER BY IdRole

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrySectoresEco @pmIdSector VARCHAR(8)
 AS 
 IF @pmIdSector IS NULL
  SELECT IdSector,SectorEco
  FROM SectoresEco
  WHERE Inactivo=0
 ORDER BY SectorEco
 ELSE
  SELECT IdSector,SectorEco,Inactivo
  FROM SectoresEco
  WHERE IdSector=@pmIdSector

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrySecurity @pmIdLla INT
 AS 
 SELECT IdLla,Descripcion,Pwd
 FROM Sys_Security
 WHERE IdLla=ISNULL(@pmIdLla,IdLla)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrySubCentros @pmIdSubCos VARCHAR(16)
 AS 
 SELECT IdSubCos,SubCosto,IdCCosto,FecAdd,FecUpdate,Inactivo
 FROM SubCentros
 WHERE IdSubCos=@pmIdSubCos

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrySubCentrosDso @pmIdCCosto VARCHAR(16)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdSubCos,SubCosto,SubCosto+' '+IdSubCos AS DsSub,IdCCosto
 FROM SubCentros
 WHERE ( IdSubCos='0'  OR   IdCCosto LIKE ISNULL(@pmIdCCosto,'%') )
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdCCosto,SubCosto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrySubCentrosLta @pmIdCCosto VARCHAR(16)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdSubCos,SubCosto,S.IdCCosto AS CodCcosto,CCosto,FecAdd,FecUpdate,S.Inactivo AS Inactvo
 FROM SubCentros AS S INNER JOIN CentroCosto AS C ON S.IdCCosto=C.IdCCosto
 WHERE S.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (S.Inactivo=ISNULL(@pmInactivo,0) or S.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY CCosto,SubCosto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTercClienteLta @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdRegimen VARCHAR(4)=Null,@pmTipoId CHAR(1)=Null
,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmIdForma VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdZona VARCHAR(4)=Null
,@pmIdSzona VARCHAR(4)=Null,@pmIdPlazo VARCHAR(4)=Null,@pmIdEstrato VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdRuta VARCHAR(4)=Null
,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmInactivoTer BIT=Null
 AS 
 SELECT IdClie,T.RazonSocial AS RaznSocial,T.TipoId AS TipId,T.Dv AS DvNit,T.NomCial AS NombreCmcial,T.SiglaRaz AS SiglaRazSocial
,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,T.Direccion AS Dirccion,T.IdLocal AS CdCiudad,L.Localidad AS Ciudad,L.IdDep AS CdDpto
,D.Departamento AS Dpto,T.Telefono AS Tlefono,T.Fax AS NumFax,T.TelMovil AS TelCeluar,T.SitioWeb AS WebSite,T.e_mail AS Email,DirEnv,IdLocEnv,LE.Localidad AS CiuEnvio
,DE.Departamento AS Dptoenvio,DiasEntga,C.IdGrupo AS CdGrupo,GrupoClie,C.IdEstrato AS CdEstrato,Estrato,SZ.IdZona AS CdZona,Zona,C.IdSzona AS CdSubzona,Subzona
,C.IdRuta AS CdRuta,Ruta,C.IdPlazo AS CdPlazo,Plazo,NVmto,PlazosImp,C.IdForma AS CdFrma,FormaPago,T.IdSector AS CdSector,SectorEco,T.IdProf AS CdProf,Profesion,T.IdRegimen AS CdRgmen
,Regimen,T.TipEnte AS TipoEnte,IdVend,TV.RazonSocial AS NomVendedor,NitFact,C.IdClase AS CdClase,ClaseCuenta,NumCuenta,C.IdBanco AS CdBanco,Banco,B.Direccion AS Dirbanco
,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,Contrato,NContrato,FecIngreso,FecVigencia
,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,T.Observacion AS Observ,Cmntario1,Cmntario2,Cmntario3,CdBandera,PrendGarant,FecUpCupo,TipoCliente,C.IdEstado AS CdEst_clie,EC.Estado AS EstadoClie,C.Inactivo AS Clie_inactivo
,T.IdEstado AS CdEst_terc,ET.Estado AS Estad_terc,T.Inactivo AS Terc_inactivo,T.Codigo AS CodTerc,T.IdLugarCed AS IdLugCed,LC.Localidad AS LugarCed,T.FecExpCed AS FecExpCedula
,T.EsVendedor AS EsVend,T.EsConductor AS EsCond,T.EsPropietario AS EsProp,T.EsProveedor AS EsProvee,T.EsEmpleado AS EsEmpldo,T.EsOperario AS EsOper,T.EsAccnista AS EsAcc
,T.EsCiaAseg AS EsAseg,C.FechaAdd AS FecAdd,C.FechaUpdate AS FecUpd,C.IdUsuario AS IdUsuari,Usuario,T.IniStgNom AS PosNomb
 FROM TercCliente  AS C INNER JOIN Terceros AS T ON C.IdClie=T.IdTercero  INNER JOIN Terceros AS TV ON C.IdVend=TV.IdTercero
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN Estratos AS ETC ON C.IdEstrato=ETC.IdEstrato
 INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona  INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta
 INNER JOIN Formaspago AS F ON C.IdForma=F.IdForma
 INNER JOIN ClaseCta AS CTA ON  C.IdClase=CTA.IdClase
 INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco INNER JOIN EstadoTer AS EC ON C.IdEstado=EC.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario   INNER JOIN Localidades AS LE ON C.IdLocEnv=LE.IdLocal
 INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%')  AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND T.TipoId LIKE ISNULL(@pmTipoId,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%') AND C.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%') AND C.IdForma LIKE ISNULL(@pmIdForma,'%') AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND SZ.IdZona LIKE ISNULL(@pmIdZona,'%') AND C.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND C.IdPlazo LIKE ISNULL(@pmIdPlazo,'%') AND C.IdEstrato LIKE ISNULL(@pmIdEstrato,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTercProveeLta  @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdRegimen VARCHAR(4)=Null,@pmTipoId CHAR(1)=Null
,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLocOrd VARCHAR(8)=Null,@pmIdForma VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmInactivoTer BIT=Null
 AS 
 SELECT IdProv,Dv,TipoId,RazonSocial,T.Codigo AS Codtercero,NomCial,SiglaRaz,NitRepLeg,NomRepLeg,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto,Telefono,Fax,TelMovil
,DirOrdComp,IdLocOrd,LP.Localidad AS CiudadOrd,DP.Departamento AS DeptoOrd,SitioWeb,e_mail,TipEnte,T.IdSector AS CodSector,SectorEco,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,PV.IdGrupo AS CdGrupo,GrupoClie
,NitContac,NomContac,TelContac,emlContac,CargContac,DiasEntga,PV.IdPlazo AS CdPlazo,Plazo,PV.IdForma AS CdForma,FormaPago,PV.IdClase AS CdClase,ClaseCuenta,NumCuenta,PV.IdBanco AS CdBanco,Banco
,B.Direccion AS DirBanco,Contacto,CdMney,CdDct,Tarifa,Simbolo,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv,GartProd,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed
,Observacion,Cmntarios,ObsFinanc,ObsJuridica,PathFoto,PathFirma,T.IdEstado AS IdEstTerc,ET.Estado AS EstadTerc,T.Inactivo AS Ter_Inactvo,PV.IdEstado AS IdEstProv,EP.Estado AS EstadProv,PV.Inactivo AS Prv_Inactvo
,Contrato,NContrato,FecIngreso,FecVigencia,FecRetiro,EsCliente,EsProveedor,EsPropietario,EsAccnista,EsCiaAseg,PV.FechaAdd AS Fec_Add,PV.FechaUpdate AS Fec_Upd,PV.IdUsuario AS IdUsario,Usuario,IniStgNom,EP.NColor AS ClrEstado
 FROM TercProvee AS PV INNER JOIN Terceros AS T ON PV.IdProv=T.IdTercero
 INNER JOIN GruposCli AS G ON PV.IdGrupo=G.IdGrupo INNER JOIN Plazos AS PZ ON PV.IdPlazo=PZ.IdPlazo
 INNER JOIN Formaspago AS F ON PV.IdForma=F.IdForma INNER JOIN ClaseCta AS CTA ON  PV.IdClase=CTA.IdClase
 INNER JOIN Bancos AS B ON PV.IdBanco=B.IdBanco INNER JOIN EstadoTer AS EP ON PV.IdEstado=EP.IdEstado
 INNER JOIN adm_Usuarios AS U ON PV.IdUsuario=U.IdUsuario   INNER JOIN Localidades AS LP ON PV.IdLocOrd=LP.IdLocal
 INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep  INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN Tablapor AS TD ON PV.CdDct=TD.IdTarifa
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%')  AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND TipoId LIKE ISNULL(@pmTipoId,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%') AND PV.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdLocOrd LIKE ISNULL(@pmIdLocOrd,'%') AND PV.IdForma LIKE ISNULL(@pmIdForma,'%') AND PV.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND PV.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (PV.Inactivo=ISNULL(@pmInactivo,0) or PV.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY RazonSocial

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTerceros @pmIdTercero VARCHAR(16)
 AS 
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor
,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,IdSector,IdProf,IdRegimen,TipEnte,IdLugarCed,FecExpCed
,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Terceros
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTercerosBus @pmCodigo VARCHAR(16)=Null,@pmTelefono VARCHAR(20)=Null
 AS 
--consultar por codigo o por telefono
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor
,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,IdProf,IdSector,IdRegimen,IdLugarCed,TipEnte,FecExpCed
,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Terceros
 WHERE Codigo  LIKE ISNULL(@pmCodigo,'%') AND Telefono LIKE ISNULL(@pmTelefono,'%')
 ORDER BY RazonSocial

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTercerosCod @pmIdTercero VARCHAR(16),@pmCodigo VARCHAR(16)
 AS 
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor
,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,IdSector,IdRegimen,IdLugarCed,FecExpCed,TipEnte,IdProf
,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Terceros
 WHERE IdTercero=@pmIdTercero OR Codigo=@pmCodigo
 ORDER BY  IdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTercerosDso @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdRegimen VARCHAR(4)=Null
,@pmInactivo BIT=Null,@pmEsCliente BIT=Null,@pmEsVendedor BIT=Null,@pmEsProveedor BIT=Null,@pmEsConductor BIT=Null,@pmEsPropietario BIT=Null,@pmEsAccnista BIT=Null
,@pmEsCiaAseg BIT=Null,@pmEsEmpleado BIT=Null,@pmEsOperario BIT=Null,@pmTipoId CHAR(1)=Null,@pmIdProf VARCHAR(4)=Null
 AS 
 SELECT IdTercero,Dv,TipoId,RazonSocial,T.Codigo AS Codtercero,NomCial,SiglaRaz,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario
,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,TipEnte,T.IdSector AS CodSector,SectorEco,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed,Observacion,T.IdEstado AS IdEstdo,Estado
,T.Inactivo AS Inactvo,FechaAdd,FechaUpdate,T.IdUsuario AS IdUsario,Usuario,IniStgNom,NColor
 FROM Terceros AS T INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector 
 INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%') AND TipoId LIKE ISNULL(@pmTipoId,'%')
 AND T.IdProf LIKE ISNULL(@pmIdProf,'%')
AND (T.Inactivo=ISNULL(@pmInactivo,0) or T.Inactivo=ISNULL(@pmInactivo,1))
AND (EsCliente=ISNULL(@pmEsCliente,0) or EsCliente=ISNULL(@pmEsCliente,1))
AND (EsVendedor=ISNULL(@pmEsVendedor,0) or EsVendedor=ISNULL(@pmEsVendedor,1))
AND (EsProveedor=ISNULL(@pmEsProveedor,0) or EsProveedor=ISNULL(@pmEsProveedor,1))
AND (EsConductor=ISNULL(@pmEsConductor,0) or EsConductor=ISNULL(@pmEsConductor,1))
AND (EsPropietario=ISNULL(@pmEsPropietario,0) or EsPropietario=ISNULL(@pmEsPropietario,1))
AND (EsAccnista=ISNULL(@pmEsAccnista,0) or EsAccnista=ISNULL(@pmEsAccnista,1))
AND (EsCiaAseg=ISNULL(@pmEsCiaAseg,0) or EsCiaAseg=ISNULL(@pmEsCiaAseg,1))
AND (EsEmpleado=ISNULL(@pmEsEmpleado,0) or EsEmpleado=ISNULL(@pmEsEmpleado,1))
AND (EsOperario=ISNULL(@pmEsOperario,0) or EsOperario=ISNULL(@pmEsOperario,1))
ORDER BY RazonSocial

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTercerosReg @pmIdTercero VARCHAR(16)
 AS 
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,Direccion,IdLocal,Telefono,IdEstado,Inactivo
 FROM Terceros
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryTiposCom @pmIdCom VARCHAR(3)
 AS 
 SELECT IdCom,TipoCom,IdDiario,EsEgreso,ConsUnico,Inactivo,FechaAdd,FechaUpdate
 FROM TiposCom
 WHERE IdCom=@pmIdCom
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposComCons @pmIdCom VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT IdCom,IdCia,LDesde,LHasta,Numero,NumManual,Formato,ConfigFecha,TipoPapel
,Orientacion,VistaPrevia,VerSetup,NumCopias,FechaAdd,FechaUpdate
 FROM TiposComCons
 WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposComConsLta @pmIdCom VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT N.IdCom AS CdTipo,TipoCom,N.IdCia AS CdCia,Compania,LDesde,LHasta,Numero,NumManual,Formato
,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,ConfigFecha,EsEgreso,ConsUnico
,T.IdDiario AS CdDiario,Diario,N.FechaAdd AS Fec_Add,N.FechaUpdate AS Fec_Update
 FROM TiposComCons AS N INNER JOIN TiposCom AS T ON N.IdCom=T.IdCom
 INNER JOIN Diarios AS D ON T.IdDiario=D.IdDiario INNER JOIN Companias AS C ON N.IdCia=C.IdCia
 WHERE T.Inactivo=0  AND N.IdCom LIKE ISNULL(@pmIdCom,'%') AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY N.IdCom,N.IdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposComDso @pmEsEgreso BIT

AS
 SELECT   IdCom, TipoCom,TipoCom +'  ' + IdCom  AS DsTip  FROM  TiposCom 
 WHERE  Inactivo=0 AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 ORDER BY  TipoCom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposComLta @pmEsEgreso BIT=Null,@pmInactivo BIT=Null
 AS 
 SELECT TC.IdCom AS CdCom,TipoCom,TC.IdDiario AS CodDiario,Diario,EsEgreso,ConsUnico
,N.IdCia AS CdCia,Compania,LDesde,LHasta,Numero,NumManual,Formato
,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,ConfigFecha
,TC.Inactivo AS Inactvo,TC.FechaAdd AS Fec_Add,TC.FechaUpdate AS Fec_Update
 FROM TiposCom AS TC INNER JOIN Diarios AS  D ON TC.IdDiario=D.IdDiario
 LEFT JOIN  TiposComCons  AS N ON TC.IdCom=N.IdCom
 LEFT JOIN Companias AS C ON N.IdCia=C.IdCia 
 WHERE (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 AND  (TC.Inactivo=ISNULL(@pmInactivo,0) or TC.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY TipoCom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposCon @pmIdTipCon VARCHAR(4)
 AS 
 IF @pmIdTipCon IS NULL
  SELECT IdTipCon,TipoContrato,Duracion
  FROM TiposCon
  WHERE Inactivo=0
  ORDER BY IdTipCon
 ELSE
  SELECT IdTipCon,TipoContrato,Duracion,Inactivo
  FROM TiposCon
  WHERE IdTipCon=@pmIdTipCon

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposCot @pmIdCot VARCHAR(4)
 AS 
 IF @pmIdCot IS NULL
  SELECT IdCot,Cotizante 
  FROM TiposCot
  WHERE Inactivo=0
  ORDER BY IdCot
 ELSE
 SELECT IdCot,Cotizante,Inactivo
 FROM TiposCot
 WHERE IdCot=@pmIdCot

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposCotDso
 AS 
  SELECT IdCot,Cotizante,IdCot+ ' '+Cotizante AS DsCot
  FROM TiposCot
  WHERE Inactivo=0
  ORDER BY IdCot

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDoc @pmIdDoc VARCHAR(3)
 AS 
 IF @pmIdDoc IS NULL
  SELECT IdDoc,TipoDoc,ConsUnico,Leyenda,IntegraCias
  FROM Sys_TiposDoc
  WHERE Inactivo=0 
  ORDER BY IdDoc
 ELSE
  SELECT IdDoc,TipoDoc,ConsUnico,Leyenda,IntegraCias,Inactivo
  FROM Sys_TiposDoc
  WHERE IdDoc=@pmIdDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE  paQryTiposDocCmp 
 AS
 SELECT   IdDoc AS IdTipo, TipoDoc AS NomTipo,TipoDoc+ ' '+ IdDoc AS DsTip 
 FROM    Sys_TiposDoc
 WHERE Inactivo=0 
 UNION
 SELECT  IdCom AS IdTipo, TipoCom AS NomTipo,TipoCom+ ' '+IdCom AS DsTip
 FROM     TiposCom
 WHERE Inactivo=0

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDocCons @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero
,NumManual,IntLotes,ConfigFecha,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,FechaAdd,FechaUpdate
 FROM TiposDocCons
 WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDocConsLta @pmIdDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT N.IdDoc AS CdDoc,TipoDoc,N.IdCia AS CdCia,Compania,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero
,NumManual,IntLotes,ConfigFecha,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias
,ConsUnico,Leyenda,N.FechaAdd AS Fec_Add,N.FechaUpdate AS Fec_Update
 FROM TiposDocCons AS N INNER JOIN Sys_TiposDoc AS T ON N.IdDoc=T.IdDoc
 INNER JOIN Companias AS C ON N.IdCia=C.IdCia
 WHERE T.Inactivo=0 AND N.IdDoc LIKE ISNULL(@pmIdDoc,'%')  AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY N.IdDoc,N.IdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDocCue @pmIdDoc VARCHAR(3),@pmIdClase INT
 AS 
 SELECT IdDoc,IdClase,ClaseCuenta,TipoMov
 FROM Sys_TiposDocCue
 WHERE IdDoc=@pmIdDoc AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
 ORDER BY IdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDocCueDso @pmIdDoc VARCHAR(3)=Null
 AS 
 SELECT TC.IdDoc AS CdTipo,TipoDoc,IdClase,ClaseCuenta,TipoMov
 FROM Sys_TiposDocCue AS TC  INNER JOIN Sys_TiposDoc AS T ON TC.IdDoc=T.IdDoc
 WHERE TC.IdDoc LIKE ISNULL(@pmIdDoc,'%')  OR IdClase=99
 ORDER BY TipoDoc,IdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDocDso @pmInactivo BIT=Null
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip   FROM  Sys_TiposDoc 
 WHERE (Inactivo=ISNULL(@pmInactivo,0) or  Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposDocLta @pmInactivo BIT=Null
 AS 
 SELECT T.IdDoc AS CdDoc,TipoDoc,ConsUnico,Leyenda,N.IdCia AS CdCia,Compania
,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero
,NumManual,IntLotes,ConfigFecha,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias
,N.FechaAdd AS Fec_Add,N.FechaUpdate AS Fec_Update,T.Inactivo AS Inactiv
 FROM Sys_TiposDoc AS T LEFT JOIN TiposDocCons AS N ON T.IdDoc=N.IdDoc
 LEFT JOIN Companias AS C ON N.IdCia=C.IdCia 
 WHERE  (T.Inactivo=ISNULL(@pmInactivo,0) or T.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY T.IdDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposNom @pmIdNom VARCHAR(4)
 AS 
 IF @pmIdNom IS NULL
  SELECT IdNom,TipoNomina,Asistencia,NoDevenga,TipoLiquida,FechaActual,CdCiaInt  FROM TiposNom
  WHERE Inactivo=0
  ORDER BY IdNom
ELSE
  SELECT IdNom,TipoNomina,Asistencia,NoDevenga,TipoLiquida,FechaActual,CdCiaInt,Inactivo
  FROM TiposNom
  WHERE IdNom=@pmIdNom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposNov @pmIdNov VARCHAR(4)
 AS 
 IF @pmIdNov IS NULL
  SELECT IdNov,Novedad,Admon
  FROM TiposNov
  WHERE Inactivo =0
  ORDER BY IdNov
 ELSE
  SELECT IdNov,Novedad,Admon,Inactivo 
  FROM TiposNov
  WHERE IdNov=@pmIdNov

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTiposNovTra 
 AS 
  SELECT IdNov,Novedad,Admon  FROM TiposNov
  WHERE  IdNov IN ('TAE','TAP')
  ORDER BY IdNov

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryTpapers
AS
 SELECT Idpapel,Nombre,STR(Idpapel,3,0)+'  '+Nombre AS DsPap FROM Sys_Tpapers ORDER BY IdPapel

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUOpciones @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20)=Null
 AS 
 SELECT IdUsuario,NomOpcion,Valor
 FROM adm_UOpciones
 WHERE IdUsuario=@pmIdUsuario AND NomOpcion LIKE ISNULL(@pmNomOpcion,'%')
 ORDER BY NomOpcion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUm @pmUndMed VARCHAR(10)
 AS 
 SELECT UndMed,Unidad
 FROM Sys_Um
 WHERE UndMed LIKE ISNULL(@pmUndMed,'%')
 ORDER BY UndMed

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUsuarios @pmIdUsuario VARCHAR(11)
 AS 
 SELECT IdUsuario,Usuario,PwdLog,IdGrupo,IdEstacion,IdCargo,Conectado,FechaAcc,FechaClave
,Caducidad,LoginSQL,PwdSQL,ModoSQL,Inactivo
 FROM adm_Usuarios
 WHERE IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 ORDER BY IdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUsuariosCnn @pmIdUsuario VARCHAR(11)
AS
 SELECT IdUsuario,Usuario,Conectado,FechaAcc,Inactivo
 FROM adm_Usuarios
 WHERE Inactivo=0 AND Conectado<>0 AND IdGrupo<5 AND IdUsuario<>@pmIdUsuario
 ORDER BY IdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUsuariosDso @pmIdGrupo INT
AS
 SELECT IdUsuario,Usuario,IdGrupo,Usuario+' '+IdUsuario AS DsUsu,Inactivo
 FROM adm_Usuarios
 WHERE Inactivo=0  AND  IdGrupo<=@pmIdGrupo
 ORDER BY Usuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUsuariosEst @pmIdUsuario VARCHAR(11),@pmIdEstacion CHAR(2)
AS
 IF @pmIdUsuario IS NULL
  SELECT IdUsuario,Usuario,IdEstacion
  FROM adm_Usuarios WHERE  IdEstacion=@pmIdEstacion
 ELSE
  SELECT IdUsuario,Usuario,IdEstacion
  FROM adm_Usuarios WHERE  IdEstacion=@pmIdEstacion AND IdUsuario<>@pmIdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUsuariosGru  @pmIdUsuario VARCHAR(11)
AS
 IF @pmIdUsuario IS NULL
  SELECT IdUsuario,Usuario,PwdLog,IdGrupo
  FROM adm_Usuarios
  WHERE  IdUsuario<>'ADMIN' AND IdUsuario<>'SUPERVISOR'
 ORDER BY  IdUsuario
 ELSE
  SELECT IdUsuario,Usuario,PwdLog,IdGrupo
  FROM adm_Usuarios
  WHERE IdUsuario<>'ADMIN' AND IdUsuario<>'SUPERVISOR' AND IdUsuario<>@pmIdUsuario
  ORDER BY  IdUsuario


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQryUsuariosLta @pmIdGrupo INT,@pmInactivo BIT
AS
 SELECT IdUsuario,Usuario,IdGrupo,IdEstacion,Conectado,FechaAcc,Caducidad,FechaClave,LoginSQL,ModoSQL
,Inactivo,IdCargo,PwdLog,PwdSQL
 FROM adm_Usuarios 
 WHERE  IdGrupo<=@pmIdGrupo AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrymonedas @pmIdMneda VARCHAR(5)
 AS 
 SELECT IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo
 FROM adm_monedas
 WHERE IdMneda=@pmIdMneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrymonedasDso
 AS 
 SELECT IdMneda,Mneda,Mneda+' ('+Simbolo +') '+ IdMneda AS DsMon
 FROM adm_monedas
 WHERE  Inactivo=0
 ORDER BY Mneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrymonedasLoc
 AS 
 SELECT IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo
 FROM adm_monedas
 WHERE Inactivo=0 AND MneLocal<>0
 ORDER BY  IdMneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrymonedasLta @pmInactivo BIT=Null
 AS 
 SELECT IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo
 FROM adm_monedas
 WHERE  (Inactivo=ISNULL(@pmInactivo,0) or  Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Mneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Aportes @pmtmEst VARCHAR(5),@pmtmIdInstala VARCHAR(4)=Null,@pmtmIdDep VARCHAR(4)=Null,@pmtmIdNom VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContto,tmDiasPen,tmBasePen,tmTarfaPen,tmValorPen,tmTarfaFsp,tmValorFsp,tmTarfaFsu,tmValorFsu,tmDiasSal
,tmBaseSal,tmTarfaSal,tmValorSal,tmDiasRie,tmBaseRie,tmTarfaRie,tmValorRie,tmDiasCom,tmBaseCom,tmTarfaCom,tmValorCom,tmTarfaIcb,tmValorIcbf,tmTarfaSen,tmValorSena
,tmTarfaMin,tmValorMin,tmTarfaEsa,tmValorESAP,tmDiasNov,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmNAutInc,tmVrIncap,tmNAutLic,tmVrLicencia,tmNAutIrp,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp
,tmIdFonPen,FP.Fondo AS FondoPen,tmIdFonSal,FS.Fondo AS FondoEps,tmIdFonRie,FR.Fondo AS FondoArp,tmIdFonCaj,CC.Fondo AS CajaComp,tmIdInstala,Instlacion,tmIdDep,Dependencia,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmVehiculo,tmVrBasico
,tmCodNewEps,tmCodNewPen,tmCodNewRie,tmCodNewIns,tmCodNewTar,CRN.ClaseRiesgo AS NewClaseRie,CRN.Tarifa AS NewTarifa,tmCodNewGru,TarfaEmp,TarfaTrab,tmEst,tmItem,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmBaseRef
--Datos empleado
,Codigo,TipoId,Dv,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,EsCondtor,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,Licencia,CatLicencia,VigLicencia
,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,IdEstCivil,EstCivil,NHijos,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,CR.ClaseRiesgo AS ClasRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,C.TipoLiquida AS TipLiq,FecAfiSeg
,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj,tmCdFonAvp,CdFonAvp
 FROM tm_Aportes AS A INNER JOIN Empleados AS E ON A.tmIdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON A.tmNContto=C.NContrato
 INNER JOIN Dependencias AS DP ON A.tmIdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON A.tmIdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON A.tmIdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON A.tmIdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON A.tmIdNom=TN.IdNom INNER JOIN Fondos AS FP ON A.tmIdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON A.tmIdFonSal=FS.IdFondo  INNER JOIN Fondos AS FR ON A.tmIdFonRie=FR.IdFondo
 INNER JOIN Fondos AS CC ON A.tmIdFonCaj=CC.IdFondo INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN ClaseRie AS CRN ON A.tmCodNewTar=CRN.IdClase
 LEFT JOIN GruposAR AS GAR ON A.tmCodNewGru=GAR.IdGrupo
 WHERE tmEst=@pmtmEst AND tmIdInstala LIKE ISNULL(@pmtmIdInstala,'%') AND tmIdDep LIKE ISNULL(@pmtmIdDep,'%')
 AND tmIdNom LIKE ISNULL(@pmtmIdNom,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 ORDER BY Apellidos,Nombres,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesAdm @pmtmEst VARCHAR(5),@pmAdmon VARCHAR(3)
 AS 
 IF @pmAdmon='PEN'
  SELECT tmIdFonPen,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasPen>0 OR tmValorPen>0)
  GROUP BY  tmIdFonPen
 IF @pmAdmon='SAL'
  SELECT tmIdFonSal,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasSal>0 OR tmValorSal>0)
  GROUP BY tmIdFonSal
 IF @pmAdmon='RIE'
  SELECT tmIdFonRie,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst  AND (tmDiasRie>0 OR tmValorRie>0)
 GROUP BY  tmIdFonRie
 IF @pmAdmon='COM'
  SELECT tmIdFonCaj,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasCom>0 OR tmValorCom>0)
  GROUP BY tmIdFonCaj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesAfi @pmtmEst VARCHAR(5),@pmAdmon VARCHAR(3)
 AS 
 IF @pmAdmon='PEN'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasPen>0 OR tmValorPen>0)
 IF @pmAdmon='SAL'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasSal>0 OR tmValorSal>0)
 IF @pmAdmon='RIE'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasRie>0 OR tmValorRie>0)
 IF @pmAdmon='COM'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasCom>0 OR tmValorCom>0)
 IF @pmAdmon='SEN'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorSena>0
 IF @pmAdmon='ICB'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorIcbf>0
 IF @pmAdmon='ESA'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorESAP>0
 IF @pmAdmon='MIN'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorMin>0


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesAtz @pmtmEst VARCHAR(5),@pmtmIdFonSal VARCHAR(8)=Null,@pmtmIdFonRie VARCHAR(8)=Null
 AS 
 SELECT tmIdEmpleado,tmNAutInc,tmNAutLic,tmNAutIrp,tmVrIncIrp,tmVrIncap,tmVrLicencia
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst AND tmIdFonSal LIKE ISNULL(@pmtmIdFonSal,'%') AND tmIdFonRie LIKE ISNULL(@pmtmIdFonRie,'%')
 AND (tmVrIncIrp>0 OR tmVrIncap>0 OR tmVrLicencia>0)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesCed @pmtmEst VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 SELECT tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst AND tmIdEmpleado=@pmtmIdEmpleado  AND tmItem<>@pmtmItem
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesCom @pmtmEst VARCHAR(5)
 AS 
 SELECT SUM(tmBaseCom) AS SValBase
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst  AND (tmValorCom>0 OR tmValorSena>0 OR tmValorIcbf>0)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesDet @pmtmEst VARCHAR(5),@pmtmItem INT=Null
 AS 
 SELECT tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNContto,tmDiasPen,tmDiasSal,tmDiasRie,tmDiasCom,tmBasePen,tmBaseSal,tmBaseRie,tmBaseCom,tmBaseRef,tmValorPen,tmValorSal,tmValorRie,tmValorCom,tmValorSena
,tmValorIcbf,tmValorFsp,tmValorFsu,tmValorESAP,tmValorMin,tmTarfaPen,tmTarfaSal,tmTarfaRie,tmTarfaFsp,tmTarfaFsu,tmTarfaEsa,tmTarfaMin,tmTarfaCom,tmTarfaIcb,tmTarfaSen,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte
,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmCodNewEps,tmCodNewPen,tmCodNewRie,tmCodNewIns,tmCodNewTar,tmCodNewGru,tmVrIncap,tmVrLicencia,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp,tmNAutLic,tmNAutInc,tmNAutIrp
,tmIdFonPen,tmIdFonSal,tmIdFonRie,tmIdFonCaj,tmIdInstala,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVehiculo,tmVrBasico,tmDiasNov,tmCdFonAvp
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesDsn @pmtmEst VARCHAR(5)
 AS 
 SELECT tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte
,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmCodNewEps,FS.Fondo AS NuevaEps,tmCodNewPen,FP.Fondo AS NuevoFdoPen,tmCodNewIns,Instlacion
,tmCodNewTar,tmCodNewGru,tmDiasNov
 FROM tm_Aportes AS A LEFT JOIN Instalaciones AS I ON A.tmCodNewIns=I.IdInstala
 LEFT JOIN Fondos AS FP ON A.tmCodNewPen=FP.IdFondo LEFT JOIN Fondos AS FS ON A.tmCodNewEps=FS.IdFondo
 WHERE tmEst=@pmtmEst AND tmDiasNov>0
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesDso @pmtmEst VARCHAR(5)
 AS 
 SELECT tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmVrBasico,tmDiasPen,tmBasePen,tmTarfaPen,tmValorPen,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmValorFsp,tmValorFsu
,tmDiasSal,tmBaseSal,tmTarfaSal,tmValorSal,tmVrUpc,tmNAutInc,tmVrIncap,tmNAutLic,tmVrLicencia,tmDiasRie,tmBaseRie,tmTarfaRie,tmValorRie,tmVrIncIrp,tmNAutIrp
,tmDiasCom,tmBaseCom,tmTarfaCom,tmValorCom,tmTarfaIcb,tmValorIcbf,tmTarfaSen,tmValorSena,tmBaseRef,tmTarfaEsa,tmValorESAP,tmTarfaMin,tmValorMin
,tmTarfaFsp,tmTarfaFsu,tmIdFonPen,FP.Fondo AS FondoPen,tmIdFonSal,FS.Fondo AS FondoEps,tmIdFonRie,FR.Fondo AS FondoArp,tmIdFonCaj,CC.Fondo AS CajaComp,tmIdInstala,Instlacion,tmNContto,tmIdNom,tmCdFonAvp
 FROM tm_Aportes AS A INNER JOIN Instalaciones AS I ON A.tmIdInstala=I.IdInstala
 INNER JOIN Fondos AS FP ON A.tmIdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON A.tmIdFonSal=FS.IdFondo
 INNER JOIN Fondos AS FR ON A.tmIdFonRie=FR.IdFondo INNER JOIN Fondos AS CC ON A.tmIdFonCaj=CC.IdFondo
 WHERE tmEst=@pmtmEst
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesEmp @pmtmEst VARCHAR(5)
 AS 
 SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesItm @pmtmEst VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM,COUNT(tmItem) AS SCANITM
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesTCom @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonCaj,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBaseCom) AS TotalIBC,SUM(tmValorCom) AS TotalCajas
,SUM(tmValorSena) AS TotalSena,SUM(tmValorIcbf) AS TotalIcb,SUM(tmValorESAP) AS TotalESAP,SUM(tmValorMin) AS TotalMinEdu
,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst AND (tmDiasCom>0 OR tmValorCom>0 OR tmValorSena>0 OR tmValorIcbf>0 OR tmValorESAP>0 OR tmValorMin>0)
 GROUP BY  tmIdFonCaj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesTSal @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonSal,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBaseSal) AS TotalIBC,SUM(tmValorSal) AS TotalSalud,SUM(tmVrIncap) AS TotalIncap
,SUM(tmVrLicencia) AS TotalLicencias,SUM(tmVrUpc) AS TotalUpc,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst AND (tmDiasSal>0 OR tmValorSal>0 OR tmVrIncap>0 OR tmVrLicencia>0 OR tmVrUpc>0)
 GROUP BY  tmIdFonSal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesTot @pmtmEst VARCHAR(5),@pmtmIdInstala VARCHAR(4)=Null,@pmtmIdDep VARCHAR(4)=Null,@pmtmIdNom VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null
 AS 
 SELECT COUNT(tmIdEmpleado) AS Cantidad,SUM(tmValorPen) AS TotalPension,SUM(tmValorFsp) AS TotalFsp,SUM(tmValorFsu) AS TotalFsu,SUM(tmValorSal) AS TotalSalud
 ,SUM(tmValorRie) AS TotalRiesgos,SUM(tmValorCom) AS TotalCajas,SUM(tmValorIcbf) AS TotalICBF,SUM(tmValorSena) AS TotalSena,SUM(tmVrIncap) AS TotalIncap,SUM(tmVrLicencia) AS TotalLicencias
,SUM(tmVrVolAfi) AS TotalAfiVol,SUM(tmVrVolApo) AS TotalApoVol,SUM(tmVrNoReten) AS TotalNoRetnido,SUM(tmVrUpc) AS TotalUpc,SUM(tmVrIncIrp) AS TotalIncIrp,SUM(tmVrBasico) AS TotalSalarios
,SUM(tmValorESAP) AS TotalESAP,SUM(tmValorMin) AS TotalMinEdu
 FROM tm_Aportes AS A INNER JOIN  Emp_Contrato AS C ON A.tmNContto=C.NContrato
 WHERE tmEst=@pmtmEst AND tmIdInstala LIKE ISNULL(@pmtmIdInstala,'%') AND tmIdDep LIKE ISNULL(@pmtmIdDep,'%')
 AND tmIdNom LIKE ISNULL(@pmtmIdNom,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesTpen @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonPen,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBasePen) AS TotalIBC,SUM(tmValorPen) AS TotalPension,SUM(tmValorFsp) AS TotalFsp,SUM(tmValorFsu) AS TotalFsu
,SUM(tmVrVolAfi) AS TotalAfiVol,SUM(tmVrVolApo) AS TotalApoVol,SUM(tmVrNoReten) AS TotalNoRetnido,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst AND (tmDiasPen>0 OR tmValorPen>0 OR tmVrVolAfi>0 OR tmVrVolApo>0 OR tmValorFsp>0)
 GROUP BY  tmIdFonPen

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AportesTrie @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonRie,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBaseRie) AS TotalIBC, SUM(tmValorRie) AS TotalRiesgos,SUM(tmVrIncIrp) AS TotalIncIrp,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst  AND (tmDiasRie>0 OR tmValorRie>0 OR tmVrIncIrp>0)
 GROUP BY  tmIdFonRie

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AutTot @pmtmEst VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc
,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AutTotDso @pmtmEst VARCHAR(5)
 AS 
 SELECT tmItem,tmTipAdm,tmIdFondo,Fondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc
,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF
 FROM tm_AutTot AS A LEFT JOIN Fondos AS F ON A.tmIdFondo=F.IdFondo
 WHERE tmEst=@pmtmEst 
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AutTotFon @pmtmEst VARCHAR(5),@pmtmTipAdm VARCHAR(3),@pmtmIdFondo VARCHAR(8)
,@pmtmItem INT
 AS 
 SELECT tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst AND tmTipAdm=@pmtmTipAdm AND tmIdFondo=@pmtmIdFondo
 AND tmItem<>@pmtmItem
 ORDER BY tmItem


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AutTotItm @pmtmEst VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM,COUNT(tmItem) AS ScanItm
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_AutTotPag @pmtmEst VARCHAR(5)
 AS 
 SELECT tmTipAdm,COUNT(tmItem) AS Cantidad,SUM(tmTotalPagar)  AS StotPag,SUM(tmTotalAfi) AS TotalAfi
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst 
 GROUP BY tmTipAdm

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Comp @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura
,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante
,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_CompID @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITEM
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_CompItm @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT COUNT(tmItem) AS SCANT
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Ingresos @pmtmEst CHAR(2)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmNMes,tmIdConcepto,tmDetalle,tmCantDevg,tmVrDevngado,tmCantDed,tmVrDeducido,tmVrBase,tmTarifa,tmBaseRet,tmClaseLiq
,tmOrigenLiq,tmFecInicial,tmFecFinal,tmDiasBase,tmDiasNoRem,tmIdNom,TipoNomina,tmIdDep,Dependencia,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdInstala,Instlacion,tmVrSalario,tmpVehiculo
,Concepto,ClaseCon,CN.Tarifa AS TrfaDft,tmCodFondo,tmEsRetiro,tmNPrestamo,tmItem
--datos del empleado
,Codigo,TipoId,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,VvdaPropia,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,Sexo,FecNacmto,IdEstCivil,EstCivil,NHijos,Conyugue,TipoSangre,FactorRh,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
,EsCondtor,pVehiculo,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,FecUltCes,FecUltPri,FecUltVac
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.TipoLiquida AS TipLiq,C.IdJornada AS CodJnada,Jornada,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie
,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,TipoTrabj,IdCot,ModPromdio,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,ModoRet,FecAfiSeg,DenyCes,DenyPri,DenyVac,BasePrest,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdUsuario AS Con_IdUsuari,Usuario
 FROM tm_Ingresos  AS TI  INNER JOIN Empleados AS E ON TI.tmIdEmpleado=E.IdEmpleado  INNER JOIN NomConceptos AS CN ON TI.tmIdConcepto=CN.IdConcepto
 INNER JOIN  Emp_Contrato AS C ON TI.tmNContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON TI.tmIdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON TI.tmIdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON TI.tmIdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON TI.tmIdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON TI.tmIdNom=TN.IdNom
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar  INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN  EstadoCiv AS EV ON E.IdEstCivil=EV.IdEstado  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 WHERE tmEst=@pmtmEst 
 ORDER BY Apellidos,Nombres,tmNMes,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Liquida @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd
,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,tmVrParcial
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaCon @pmtmNumero VARCHAR(5),@pmtmIdConcepto VARCHAR(4),@pmtmIdEmpleado VARCHAR(16)
,@pmtmItem INT
 AS 
 SELECT Count(tmItem) AS SITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero  AND tmIdConcepto=@pmtmIdConcepto AND tmIdEmpleado=@pmtmIdEmpleado
 AND tmItem<>@pmtmItem


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaDed @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,EsCondtor,pVehiculo
,tmIdConcepto,Concepto,SUM(tmVrBase) AS tVrBase,SUM(tmCantidad) AS tCant,SUM(tmVrDeducido) AS tVrDeducido
,SUM(tmVrLiquida) AS tVrLiquida,MAX(tmTarifa) AS tTarifa
 FROM tm_Liquida AS L INNER JOIN NomConceptos AS C ON L.tmIdConcepto=C.IdConcepto
 INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero AND tmIdConcepto NOT IN ('CES','PRI','INT') AND tmVrDeducido>0
 GROUP BY tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,EsCondtor,pVehiculo
,tmIdConcepto,Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaDso @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmItem,tmIdConcepto,tmDetalle,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido
,tmFecUltLiq,tmFecInicial,tmFecFinal,tmFecIniPmd,tmFecFinPmd,tmDiasBase,tmDiasNoRem,tmNPrestamo,tmNCuota,tmTarifa
,tmLogPmdio,tmNContrato,tmVrSalario,tmVrParcial --tmNumero,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom
 FROM tm_Liquida AS L INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaEmp @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,SUM(tmVrLiquida) AS tVrLiquida,SUM(tmVrDeducido) AS tVrDeducido,sum(tmVrParcial) AS tVrParcial
 FROM tm_Liquida AS L INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 GROUP BY tmIdEmpleado,Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaId @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero 

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaItm @pmtmNumero VARCHAR(5),@pmtmItem INT, @pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT Count(tmItem) AS SITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero  AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaLpre @pmtmNumero VARCHAR(5),@pmtmIdConcepto VARCHAR(4)=Null,@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmCantidad,tmVrDeducido,tmNPrestamo,tmNCuota
,TotPrestamo,TotAbonado,VrPrestamo,NumCuotas
 FROM tm_Liquida AS  L  INNER JOIN Trn_NomPrest AS P ON L.tmNPrestamo=P.NPrestamo
 WHERE tmNumero=@pmtmNumero AND  tmNPrestamo>0 AND tmVrDeducido>0 AND  tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
  AND tmIdConcepto LIKE ISNULL(@pmtmIdConcepto,'%')
 ORDER BY tmNPrestamo


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaLta @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,Apellidos,Nombres,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd
,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,EsCondtor,pVehiculo,tmVrParcial
 FROM  tm_Liquida AS L INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmIdEmpleado,tmIdConcepto,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaPar @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmCantidad,tmVrDeducido
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero AND tmVrDeducido>0  AND  tmIdConcepto IN ('CES','INT')
 AND  tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaPre @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmNPrestamo INT
 AS 
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero AND tmNPrestamo=@pmtmNPrestamo AND  tmItem<>@pmtmItem


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_LiquidaTot @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT COUNT(tmItem) AS CANITM,SUM(tmVrBase) AS SBASE,SUM(tmCantidad) AS SCANTIDAD,SUM(tmVrLiquida) AS SVALLIQ
,SUM(tmVrDeducido) AS SDEDUCIDO,SUM(tmDiasBase) AS SDIASBASE,SUM(tmDiasNoRem) AS DIASNOREM,SUM(tmVrParcial) AS STOTPAR
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero  AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Liquida_Cr @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null,@pmtmIdDep VARCHAR(4)=Null,@pmtmIdNom VARCHAR(4)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,Apellidos,Nombres,tmIdConcepto,Concepto,tmDetalle,ClaseCon,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida
,tmVrDeducido,tmFecIniPmd,tmFecFinPmd,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,Dependencia,tmIdCCosto,CCosto
,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmVrSalario
--datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio,tmVrParcial
 FROM tm_Liquida AS T INNER JOIN NomConceptos AS CN ON T.tmIdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON T.tmIdEmpleado=E.IdEmpleado
 INNER JOIN Dependencias AS DP ON T.tmIdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON T.tmIdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON T.tmIdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON T.tmIdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON T.tmNContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN NomVehiculos AS VH ON  T.tmpVehiculo=VH.IdVehiculo
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND tmIdDep LIKE ISNULL(@pmtmIdDep,'%') AND tmIdNom LIKE ISNULL(@pmtmIdNom,'%')
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NomHoras 
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmHorDiurno,tmHorNocturno,tmHorExtraDia,tmHorExtraNoc,tmHorRecNoc,tmHorDomDia,tmHorDomNoc,tmHorExtDom,tmHorExtDomNoc
,tmVrHoras1,tmVrHoras2,tmVrHoras3,tmVrHoras4,tmVrSalario,tmVrATrans
,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmTipoLiquida,tmpVehiculo
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,E.Inactivo AS Emp_Inactvo
 FROM tm_NomHoras AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.tmNContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.tmIdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.tmIdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.tmIdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.tmIdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.tmIdNom=TN.IdNom  INNER JOIN Areas AS AR ON N.tmIdArea=AR.IdArea 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 ORDER BY Apellidos,Nombres

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NomRes @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmItem,tmIdConcepto,tmDetalle,tmFecInicial,tmFecFinal,tmIdPeriodo
,tmCantDevg,tmVrTotDevg,tmCantDed,tmVrTotDed,tmUnidad,tmVrOrigen,Concepto,tmClaseLiq,ClaseCon,tmTarifa,tmDiasCalc,tmDiasNov
,tmCodFondo,FCO.Fondo AS NomFondo,tmNPrestamo,tmNCuota,tmVrBaseLiq,tmVrUnitario
,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmTipoLiq,tmEsRetiro
,tmNLiqRet,tmVrSalario,tmVrATrans,tmpVehiculo,tmTipCom,tmComprobante,tmIdCiaCom,tmObservacion
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,FC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,E.Inactivo AS Emp_Inactvo
 FROM tm_NomRes AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN Areas AS AR ON N.tmIdArea=AR.IdArea INNER JOIN Dependencias AS DP ON N.tmIdDep=DP.IdDep
 INNER JOIN TiposNom AS TN ON N.tmIdNom=TN.IdNom 
 INNER JOIN CentroCosto AS CC ON N.tmIdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.tmIdSubCos=SC.IdSubCos
 INNER JOIN Instalaciones AS I ON N.tmIdInstala=I.IdInstala
 INNER JOIN NomConceptos AS NC ON N.tmIdConcepto=NC.IdConcepto
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 LEFT JOIN Fondos AS FCO ON N.tmCodFondo=FCO.IdFondo
 WHERE tmNumero=@pmtmNumero
 ORDER BY Apellidos,Nombres,tmFecInicial,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NomResCon @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmIdConcepto,Concepto,ClaseCon,tmDetalle
,SUM(tmCantDevg) AS CantDev,SUM(tmCantDed) AS CantDed,SUM(tmVrTotDevg) AS TotalDeveng
,SUM(tmVrTotDed) AS TotalDed,SUM(tmVrOrigen) AS VrOrigen,SUM(tmDiasCalc) AS CantDias,SUM(tmDiasNov) AS DiasNov
,SUM(tmVrBaseLiq) AS TotalBaseLiq
,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina
,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco
 FROM tm_NomRes AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN Areas AS AR ON N.tmIdArea=AR.IdArea INNER JOIN Dependencias AS DP ON N.tmIdDep=DP.IdDep
 INNER JOIN TiposNom AS TN ON N.tmIdNom=TN.IdNom 
 INNER JOIN CentroCosto AS CC ON N.tmIdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.tmIdSubCos=SC.IdSubCos
 INNER JOIN Instalaciones AS I ON N.tmIdInstala=I.IdInstala
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN NomConceptos AS NC ON N.tmIdConcepto=NC.IdConcepto
 WHERE tmNumero=@pmtmNumero
 GROUP BY  tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmIdConcepto,Concepto,ClaseCon,tmDetalle
 ,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina
,E.IdClase,ClaseCuenta,NumCuenta,E.IdBanco,Banco
 ORDER BY Apellidos,Nombres,Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Nomina @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 SELECT tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad,tmClaseLiq
,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo
,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmVrPension,tmVrSalud
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
ORDER BY tmIdEmpleado,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaBas @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmTipBas VARCHAR(3)
,@pmtmClaseLiq VARCHAR(10)
 AS 
 IF @pmTipBas ='SD' --SALARIO BASICO+EXTRAS
  SELECT tmIdConcepto,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmCantDed) AS SCANDED
,SUM(tmVrTotDed) AS STOTDED,SUM(tmVrBaseLiq) AS SBASLIQ
  FROM tm_Nomina 
  WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
  AND tmIdConcepto NOT IN ('BAS','LIC','IGE','IRP','HHD','HHN','DSR','VAC')
 GROUP BY tmIdConcepto
 ELSE --TOTAL DEVENGADO
  SELECT tmIdConcepto,SUM(tmCantDevg) AS SCANDEV ,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmCantDed) AS SCANDED
,SUM(tmVrTotDed) AS STOTDED,SUM(tmVrBaseLiq) AS SBASLIQ
  FROM tm_Nomina 
  WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmClaseLiq IN ('NOMINA','NOVEDAD')
  GROUP BY tmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaCau @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContto,tmFecIni,tmFecFin,Count(tmItem) AS SCANT,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV
,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDed) AS STOTDED,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET,SUM(tmVrBaseLiq) AS SVALLIQ
 FROM tm_Nomina AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero  AND tmItem>=@pmtmItem AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 GROUP BY  tmIdEmpleado,Apellidos,Nombres,tmNContto,tmFecIni,tmFecFin

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaCip @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmVrBaseLiq,tmIdEmpleado
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
ORDER BY tmIdEmpleado,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaCon @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4),@pmtmItem INT,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT Count(tmItem) AS SITEM
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto=@pmtmIdConcepto
 AND tmItem<>@pmtmItem  AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%') 


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaCpre @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT Count(tmItem) AS SITEM
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmNPrestamo>0
 AND  tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%') 



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaDia @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmTipo CHAR(1),@pmtmIdConcepto VARCHAR(4),@pmtmItem INT
AS 
 IF @pmTipo='B'
  SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV,SUM(tmVrTotDed) AS SVALDED
,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
  FROM tm_Nomina
  WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
  AND tmIdConcepto IN ('BAS','LIC','IGE','IRP','VAC','DSR')
 ELSE
 BEGIN
  IF  @pmTipo='H'
   SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV  ,SUM(tmVrTotDed) AS SVALDED
 ,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
   FROM tm_Nomina
   WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
   AND tmIdConcepto IN ('HHD','HHN','HFD','HFN')
  ELSE
   BEGIN
    IF  @pmTipo='E'
     SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV  ,SUM(tmVrTotDed) AS SVALDED
   ,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
     FROM tm_Nomina
     WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
     AND tmIdConcepto IN ('HED','HEN','HXD','HXN')
    ELSE
     SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV  ,SUM(tmVrTotDed) AS SVALDED
   ,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
     FROM tm_Nomina
     WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
     AND tmIdConcepto=@pmtmIdConcepto
   END
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaDsa @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias,tmCodFondo,tmVrBaseLiq
 FROM tm_Nomina AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero  AND tmItem>=@pmtmItem
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')  --AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 ORDER BY Apellidos,Nombres,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaDsl @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmFecUltLiq,tmFecIni,tmFecFin,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias
,tmLogPmdio,tmClaseLiq,tmFecIniPmd,tmFecFinPmd,tmIdEmpleado
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq NOT IN ('PROVISION','APORTE') AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaDso @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias,tmIdEmpleado
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
ORDER BY tmIdEmpleado,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaEdv @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmClaseLiq VARCHAR(10)
,@pmtmItem INT
--valida si existe el primer concepto devengado
AS 
  SELECT Count(tmItem) AS SITEM
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado
  AND tmIdConcepto IN ('BAS','LIC','IGE','IRP','HHD','HHN','HFD','HFN','DSR','VAC')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')  AND tmItem<>@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaEitm @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmItem INT,@pmtmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaGCon @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4)=Null,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT tmIdConcepto,tmClaseLiq,Count(tmItem) AS SITEM,SUM(tmVrBaseLiq) AS STOTBAS,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmVrTotDed) AS STOTDED
,SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrOrigen) AS SBASORIG
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto LIKE ISNULL(@pmtmIdConcepto,'%')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%') 
 GROUP BY tmIdConcepto,tmClaseLiq

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaId @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(tmItem) AS MXITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaItm @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND  tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaLInt @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad,tmClaseLiq
,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo
,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq IN ('NOMINA','PROVISION','APORTE','NOVEDAD',@pmClaseLiq)
 AND  tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaLpre @pmtmNumero VARCHAR(5),@pmtmIdConcepto VARCHAR(4)=Null,@pmtmIdEmpleado VARCHAR(16)=Null
,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmCantDed,tmVrUnitario,tmVrTotDed,tmNPrestamo,tmNCuota,TotPrestamo,TotAbonado,VrPrestamo,NumCuotas
  FROM tm_Nomina AS N  INNER JOIN Trn_NomPrest AS P ON N.tmNPrestamo=P.NPrestamo
 WHERE  tmNumero=@pmtmNumero AND  tmNPrestamo>0 AND  tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND  tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')  AND tmIdConcepto LIKE ISNULL(@pmtmIdConcepto,'%')
ORDER BY tmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaNov @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmNContto INT
 AS 
 SELECT Count(tmItem) AS SCANT,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV
,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDed) AS STOTDED
,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET,SUM(tmVrBaseLiq) AS SVALLIQ
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmItem>=0 AND tmClaseLiq='NOVEDAD' AND tmIdEmpleado=@pmtmIdEmpleado
 AND tmNContto=@pmtmNContto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaPre @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmItem INT,@pmtmNPrestamo INT
 AS 
 --VALIDA SI EXISTE EL PRESTAMO EN EL TEMPORAL
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq='NOMINA'  AND tmIdEmpleado=@pmtmIdEmpleado
 AND tmNPrestamo=@pmtmNPrestamo AND tmItem<>@pmtmItem



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaRet @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT COUNT(tmItem) AS SITEM,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq='NOMINA' AND tmIdConcepto='RET'
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaSBas @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmClaseLiq VARCHAR(10)
 AS 
 SELECT tmIdConcepto,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmCantDed) AS SCANDED
,SUM(tmVrTotDed) AS STOTDED,SUM(tmVrBaseLiq) AS SBASLIQ
 FROM tm_Nomina 
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado 
 AND tmIdConcepto IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
 GROUP BY tmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaTCon @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4),@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT Count(tmItem) AS SITEM,SUM(tmVrBaseLiq) AS STOTBAS,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmVrTotDed) AS STOTDED
,SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto=@pmtmIdConcepto
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%') 


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaTPen @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmIdPeriodo VARCHAR(8)=Null
 AS 
 SELECT COUNT(tmItem) AS SITEM,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN  ('NOMINA','NOVEDAD') AND tmIdConcepto IN ('DCP','FSP','FSU')
  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')  AND  tmIdPeriodo LIKE ISNULL(@pmtmIdPeriodo,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaTot @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT COUNT(tmItem) AS SITEM,SUM(tmCantDevg) AS tCantDevg,SUM(tmVrTotDevg) AS tVrTotDevg
 ,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed,SUM(tmVrBaseLiq) AS tVrBaseLiq
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN  ('NOMINA','NOVEDAD')
  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaVac @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDed,tmUnidad,tmVrUnitario,tmVrTotDed,tmVrOrigen,tmTarifa
,tmNPrestamo,tmNCuota,tmDiasCalc,tmVrPension AS VrApoPension,tmVrBaseLiq AS VrCertf,tmIdEmpleado,tmIdPeriodo
,tmVrSalud
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
ORDER BY tmIdEmpleado,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_NominaVint @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmIdConcepto,Concepto,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed,SUM(tmCantDevg) AS tCantDevg,SUM(tmVrTotDevg) AS tVrTotDevg
 ,SUM(tmVrBaseLiq) AS tVrBaseLiq,SUM(tmVrOrigen) AS tVrOrigen
 FROM  tm_Nomina AS N INNER JOIN NomConceptos AS C ON N.tmIdConcepto=C.IdConcepto
 WHERE  tmNumero=@pmtmNumero  AND tmClaseLiq IN  ('NOMINA','NOVEDAD')
  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 GROUP BY tmIdConcepto,Concepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Nomina_Cr @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmItem,tmIdConcepto,tmDetalle,Concepto,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias,tmCodFondo,FD.Fondo AS tm_Fondo,tmVrBaseLiq,tmFecIni,tmFecFin,tmIdPeriodo
,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmClaseLiq,tmOrigCargue
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,FecNacmto,EsCondtor,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,E.NContrato AS NumContrato,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdCCosto AS CodCcto,CCosto
,C.IdSubCos AS CodSubcen,SubCosto,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,ModoRet,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,C.IdUsuario AS Con_IdUsuari,Usuario
,pVehiculo,NumVeh,TipoAdmon,VehPropio
 FROM tm_Nomina AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN NomConceptos AS CN ON N.tmIdConcepto=CN.IdConcepto
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN  Emp_Contrato AS C ON E.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada  LEFT JOIN Fondos AS FD ON N.tmCodFondo=FD.IdFondo
 LEFT JOIN NomVehiculos AS VH ON E.pVehiculo=VH.IdVehiculo
 WHERE tmNumero=@pmtmNumero  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,tmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_Plasueldos @pmtmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmtmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.VrSalario AS VrSalBasico,tmDias,tmVrBasico,tmVrAuxtrans,tmVrHextras,tmVrRecargos,tmVrComision,tmVrIncapac,tmVrLicencia
,tmVrVacLiquida,tmVrOtrosDev,VrDevengado+tmVrVacLiquida AS Devengado,tmVrDctoPen,tmVrDctoSal,tmVrDctoFsp,tmVrRetencion,tmVrPrestmos,tmVrSanciones,tmVrOtrosDed,tmVrVacPen,tmVrVacSal,tmVrVacFsp,tmVrVacOtr
,VrDeducido+tmVrVacPen+tmVrVacSal+tmVrVacFsp+tmVrVacOtr AS Deducido
,(VrDevengado+tmVrVacLiquida) -(VrDeducido+tmVrVacPen+tmVrVacSal+tmVrVacFsp+tmVrVacOtr) AS VrNetoPagar,tmVrVacacnes,tmObserv,tmIdPeriodo,FecInicial,FecFinal,tmKeyRegistro
--datos nomina
,N.IdDep AS CodDep,Dependencia,N.IdInstala AS CodInst,Instlacion,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcen,SubCosto,N.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,TipoLiq,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS Nom_IdEstdo,EN.Estado AS Nom_Estado,EsRetiro,NLiqRet,Cantidad,CantNoRem
,TimeSys,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario
--datos del contrato
,N.NContrato AS NumContrato,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie
,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
,NumVeh,TipoAdmon,VehPropio
 FROM tm_Plasueldos AS PS INNER JOIN Trn_Nomina AS N ON PS.tmIdPeriodo=N.IdPeriodo AND PS.tmKeyRegistro=N.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado 
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado
 LEFT JOIN NomVehiculos AS VH ON N.pVehiculo=VH.IdVehiculo
 WHERE SUBSTRING(tmIdPeriodo,1,6)=@pmMes AND tmIdPeriodo LIKE ISNULL(@pmtmIdPeriodo,'%') 
 AND tmKeyRegistro LIKE ISNULL(@pmtmKeyRegistro,'%')  AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,N.IdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paQrytm_PlasueldosKey @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30)
 AS 
 SELECT tmIdPeriodo,tmKeyRegistro,tmDias
 FROM tm_Plasueldos 
 WHERE tmKeyRegistro=@pmtmKeyRegistro AND SUBSTRING(tmIdPeriodo,1,6)=@pmtmIdPeriodo
 ORDER BY tmIdPeriodo


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpAreas @pmIdArea VARCHAR(4),@pmArea VARCHAR(50),@pmJefeArea VARCHAR(50)
,@pmIdCCosto VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE Areas SET Area=@pmArea,JefeArea=@pmJefeArea,IdCCosto=@pmIdCCosto,Inactivo=@pmInactivo
 WHERE IdArea=@pmIdArea

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpBancos @pmIdBanco VARCHAR(4),@pmBanco VARCHAR(50),@pmIdClase VARCHAR(4),@pmCodEntidad VARCHAR(20),@pmDireccion VARCHAR(50)
,@pmContacto VARCHAR(50),@pmComision DECIMAL(10,4),@pmInactivo BIT
 AS 
 UPDATE Bancos SET Banco=@pmBanco,IdClase=@pmIdClase,CodEntidad=@pmCodEntidad,Direccion=@pmDireccion,Contacto=@pmContacto,Comision=@pmComision,Inactivo=@pmInactivo
 WHERE IdBanco=@pmIdBanco

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCalndario @pmFechaDia SMALLDATETIME,@pmTipoFtvo VARCHAR(3)
 AS 
 UPDATE Calndario SET TipoFtvo=@pmTipoFtvo
 WHERE FechaDia=@pmFechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCargos @pmIdCargo VARCHAR(4),@pmCargo VARCHAR(50),@pmFunciones VARCHAR(3000),@pmInactivo BIT
 AS 
 UPDATE Cargos SET Cargo=@pmCargo,Funciones=@pmFunciones,Inactivo=@pmInactivo
 WHERE IdCargo=@pmIdCargo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCentroCosto @pmIdCCosto VARCHAR(16),@pmCCosto VARCHAR(100)
,@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE CentroCosto SET CCosto=@pmCCosto,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo
 WHERE IdCCosto=@pmIdCCosto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpClaseBan @pmIdClase VARCHAR(4),@pmClaseBanco VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseBan SET ClaseBanco=@pmClaseBanco,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpClaseCta @pmIdClase VARCHAR(4),@pmClaseCuenta VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseCta SET ClaseCuenta=@pmClaseCuenta,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpClaseFon @pmIdClase VARCHAR(4),@pmClaseFondo VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseFon SET ClaseFondo=@pmClaseFondo,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpClaseRie @pmIdClase VARCHAR(4),@pmClaseRiesgo VARCHAR(50),@pmTarifa DECIMAL(10,4),@pmInactivo BIT
 AS 
 UPDATE ClaseRie SET ClaseRiesgo=@pmClaseRiesgo,Tarifa=@pmTarifa,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCnxextna @pmIdReg INT,@pmCnxEngine VARCHAR(3),@pmCnxDso VARCHAR(250),@pmCnxDbname VARCHAR(50),@pmCnxAutentic VARCHAR(3)
,@pmCnxUid VARCHAR(50),@pmCnxPwd VARCHAR(50),@pmCnxOwner VARCHAR(20),@pmCnxObserv VARCHAR(250),@pmCnxTipo VARCHAR(10),@pmCnxPpties VARCHAR(250)
 AS 
 UPDATE Sys_Cnxextna SET CnxEngine=@pmCnxEngine,CnxDso=@pmCnxDso,CnxDbname=@pmCnxDbname,CnxAutentic=@pmCnxAutentic,CnxUid=@pmCnxUid,CnxPwd=@pmCnxPwd
,CnxOwner=@pmCnxOwner,CnxObserv=@pmCnxObserv,CnxTipo=@pmCnxTipo,CnxPpties=@pmCnxPpties
 WHERE IdReg=@pmIdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComDetalle @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmVehPropio BIT,@pmVrBase MONEY,@pmTarifaBase DECIMAL(10,4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15)
,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4),@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmReferncia VARCHAR(50),@pmNitDoc VARCHAR(16),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_ComDetalle SET Fecha=@pmFecha,IdCuenta=@pmIdCuenta,Detalle=@pmDetalle,VrDebito=@pmVrDebito,VrCredito=@pmVrCredito,IdTercero=@pmIdTercero,CodAgncia=@pmCodAgncia,IdVehiculo=@pmIdVehiculo,IdCCosto=@pmIdCCosto,VehPropio=@pmVehPropio,VrBase=@pmVrBase,TarifaBase=@pmTarifaBase,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,CodConce=@pmCodConce,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,ItemFac=@pmItemFac,FecVence=@pmFecVence,CodCta=@pmCodCta,NumCheque=@pmNumCheque
,IdSubCos=@pmIdSubCos,Integrado=@pmIntegrado,TipoAplica=@pmTipoAplica,Consolida=@pmConsolida,CodCargo=@pmCodCargo,NitOtros=@pmNitOtros,CodSubgpo=@pmCodSubgpo,CiuOrigen=@pmCiuOrigen,Referncia=@pmReferncia,NitDoc=@pmNitDoc,TipDocRef=@pmTipDocRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef,FecUpdate=@pmFecUpdate
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComFactura @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmItem INT,@pmIdProveedor VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecEmision SMALLDATETIME,@pmFecVence SMALLDATETIME
,@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmItemCom INT,@pmReferencia VARCHAR(50),@pmDetalle VARCHAR(100),@pmpVehiculo VARCHAR(10),@pmVehPropio BIT
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
 AS 
 UPDATE Trn_ComFactura SET IdCuenta=@pmIdCuenta,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,FecEmision=@pmFecEmision,FecVence=@pmFecVence,VrFactura=@pmVrFactura,VrAbonado=@pmVrAbonado,TipCom=@pmTipCom,Comprobante=@pmComprobante,ItemCom=@pmItemCom
,Referencia=@pmReferencia,Detalle=@pmDetalle,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio,TipRef=@pmTipRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia AND Item=@pmItem AND IdProveedor=@pmIdProveedor

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComFacturaAbo @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmItem INT,@pmIdProveedor VARCHAR(16),@pmVrAbonado MONEY
AS
 UPDATE   Trn_ComFactura SET VrAbonado=@pmVrAbonado
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia AND Item=@pmItem
 AND IdProveedor=@pmIdProveedor


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComFacturaApl @pmIdProveedor VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmTipFac VARCHAR(3)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
  UPDATE  Trn_ComFactura  SET Trn_ComFactura.VrAbonado=(SELECT ISNULL(SUM(Trn_EgrFactura.VrAbono),0)
  FROM Trn_EgrFactura WHERE Trn_ComFactura.TipFac=Trn_EgrFactura.TipFac AND Trn_ComFactura.Factura=Trn_EgrFactura.Factura AND Trn_ComFactura.IdCia=Trn_EgrFactura.IdCiaFac
  AND Trn_ComFactura.Item=Trn_EgrFactura.ItemFac AND Trn_ComFactura.IdProveedor=Trn_EgrFactura.IdProveedor)
  WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND  IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  TipFac LIKE ISNULL(@pmTipFac,'%') 
 ELSE
  UPDATE  Trn_ComFactura  SET Trn_ComFactura.VrAbonado=(SELECT ISNULL(SUM(Trn_EgrFactura.VrAbono),0)
  FROM Trn_EgrFactura WHERE Trn_ComFactura.TipFac=Trn_EgrFactura.TipFac AND Trn_ComFactura.Factura=Trn_EgrFactura.Factura AND Trn_ComFactura.IdCia=Trn_EgrFactura.IdCiaFac
  AND Trn_ComFactura.Item=Trn_EgrFactura.ItemFac AND Trn_ComFactura.IdProveedor=Trn_EgrFactura.IdProveedor)
  WHERE IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  TipFac LIKE ISNULL(@pmTipFac,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComFacturaCero @pmIdProveedor VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmTipFac VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null

AS
IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
 UPDATE  Trn_ComFactura  SET  VrAbonado=0
 WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND  IdProveedor LIKE ISNULL(@pmIdProveedor,'%') 
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')  AND  TipFac LIKE ISNULL(@pmTipFac,'%')
 ELSE
 UPDATE  Trn_ComFactura  SET  VrAbonado=0
 WHERE IdProveedor LIKE ISNULL(@pmIdProveedor,'%')   AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')  AND  TipFac LIKE ISNULL(@pmTipFac,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE paUpCompanias @pmIdCia CHAR(2),@pmCompania VARCHAR(50),@pmDirInterface VARCHAR(255),@pmFechaActual SMALLDATETIME,@pmPeriodoActual SMALLDATETIME,@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmIdTercero VARCHAR(16),@pmCodSucsal VARCHAR(10),@pmDireccSuc VARCHAR(250),@pmTelefSuc VARCHAR(20),@pmFaxSuc VARCHAR(20),@pmIdLocal VARCHAR(8)
,@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE Companias SET Compania=@pmCompania,DirInterface=@pmDirInterface,FechaActual=@pmFechaActual,PeriodoActual=@pmPeriodoActual,IdCCosto=@pmIdCCosto
,IdSubCos=@pmIdSubCos,IdTercero=@pmIdTercero,CodSucsal=@pmCodSucsal,DireccSuc=@pmDireccSuc,TelefSuc=@pmTelefSuc,FaxSuc=@pmFaxSuc, IdLocal=@pmIdLocal
,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo
 WHERE IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCompaniasFec @pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmConta BIT
AS
IF @pmConta<>0 
  UPDATE Companias SET PeriodoActual=@pmFecha  WHERE IdCia=@pmIdCia
ELSE
 UPDATE Companias SET FechaActual=@pmFecha  WHERE IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComprobantes @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrTotal MONEY,@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmTipEgr VARCHAR(3),@pmNEgreso INT,@pmpVehiculo VARCHAR(10),@pmVehPropio BIT,@pmCedCondtor VARCHAR(16),@pmCodConce VARCHAR(4),@pmBeneficiario VARCHAR(150),@pmVrDivisa1 MONEY,@pmVrDivisa2 MONEY,@pmVrDivisa3 MONEY,@pmPermEditar BIT,@pmIntegrado BIT,@pmEsEgreso BIT,@pmAnticipo BIT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmPropddes VARCHAR(50),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Comprobantes SET Fecha=@pmFecha,IdTercero=@pmIdTercero,VrTotal=@pmVrTotal,IdCta=@pmIdCta,EnEfectivo=@pmEnEfectivo,NumCheque=@pmNumCheque,FecCheque=@pmFecCheque,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,TipEgr=@pmTipEgr,NEgreso=@pmNEgreso,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio
,CedCondtor=@pmCedCondtor,CodConce=@pmCodConce,Beneficiario=@pmBeneficiario,PermEditar=@pmPermEditar,Integrado=@pmIntegrado,EsEgreso=@pmEsEgreso,Anticipo=@pmAnticipo,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Propddes=@pmPropddes
,VrDivisa1=@pmVrDivisa1,VrDivisa2=@pmVrDivisa2,VrDivisa3=@pmVrDivisa3,FecUpdate=@pmFecUpdate
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpComprobantesAnu @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2), @pmAnulado BIT, @pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmIdEstado VARCHAR(4), @pmPermEditar BIT,@pmObservacion VARCHAR(250)
AS
 UPDATE  Trn_Comprobantes  SET  Anulado=@pmAnulado, NumDev=@pmNumDev,FecDev=@pmFecDev,IdEstado=@pmIdEstado,Observacion=@pmObservacion,PermEditar=@pmPermEditar
 WHERE TipCom=@pmTipCom AND  Comprobante=@pmComprobante AND  IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpConsDocNum @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmNumero INT
 AS
 IF @pmNumero IS NULL
  UPDATE Trn_ConsDoc SET Numero=Numero+1
  WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia
 ELSE
  UPDATE Trn_ConsDoc SET Numero=@pmNumero
  WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCtasCorrientes @pmIdCta VARCHAR(4),@pmNumeroCta VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmConsCheques BIT,@pmRangoCons VARCHAR(20)
,@pmConsActual INT,@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmInactivo BIT,@pmIdCiaDef CHAR(2)
 AS 
 UPDATE CtasCorrientes SET NumeroCta=@pmNumeroCta,IdBanco=@pmIdBanco,IdCuenta=@pmIdCuenta,ConsCheques=@pmConsCheques,RangoCons=@pmRangoCons,ConsActual=@pmConsActual,Formato=@pmFormato
,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,Inactivo=@pmInactivo,IdCiaDef=@pmIdCiaDef
 WHERE IdCta=@pmIdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpCtasCorrientesChe @pmIdCta VARCHAR(4),@pmConsActual INT=Null
AS
 IF @pmConsActual =Null
  UPDATE  CtasCorrientes SET ConsActual=(ConsActual+1)  WHERE  IdCta=@pmIdCta
 ELSE
  UPDATE  CtasCorrientes SET ConsActual=@pmConsActual  WHERE  IdCta=@pmIdCta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpDepartamentos @pmIdDep VARCHAR(8),@pmDepartamento VARCHAR(50)
,@pmCodigo VARCHAR(4),@pmIdPais VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE Departamentos SET Departamento=@pmDepartamento,Codigo=@pmCodigo,Inactivo=@pmInactivo
 ,IdPais=@pmIdPais
 WHERE IdDep=@pmIdDep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpDependencias @pmIdDep VARCHAR(4),@pmDependencia VARCHAR(50),@pmJefeDep VARCHAR(50),@pmIdArea VARCHAR(4)
,@pmTipRiesgo DECIMAL(10,4),@pmIdSubCos VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE Dependencias SET Dependencia=@pmDependencia,JefeDep=@pmJefeDep,IdArea=@pmIdArea,TipRiesgo=@pmTipRiesgo
,Inactivo=@pmInactivo,IdSubCos=@pmIdSubCos
 WHERE IdDep=@pmIdDep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpDiarios @pmIdDiario VARCHAR(4),@pmDiario VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE Diarios SET Diario=@pmDiario,Inactivo=@pmInactivo
 WHERE IdDiario=@pmIdDiario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEgrFactura @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16),@pmIdCuenta VARCHAR(16)
,@pmVrAbono MONEY,@pmEsEgreso BIT,@pmItemCom INT,@pmpVehiculo VARCHAR(10),@pmVehPropio BIT,@pmTipDev VARCHAR(3),@pmNumDev INT,@pmDetAbono VARCHAR(100)
 AS 
 UPDATE Trn_EgrFactura SET Fecha=@pmFecha,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,ItemFac=@pmItemFac,IdProveedor=@pmIdProveedor,IdCuenta=@pmIdCuenta,VrAbono=@pmVrAbono,EsEgreso=@pmEsEgreso
,ItemCom=@pmItemCom,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio,TipDev=@pmTipDev,NumDev=@pmNumDev,DetAbono=@pmDetAbono
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_Contrato @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmIndefinido BIT,@pmIdCargo VARCHAR(4),@pmIdJornada VARCHAR(4),@pmIdDep VARCHAR(4),@pmIdArea VARCHAR(4),@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdCia CHAR(2),@pmIdNom VARCHAR(4),@pmTipoLiquida CHAR(1),@pmModPromdio CHAR(1),@pmVrSalario MONEY,@pmVrAuxTrans MONEY,@pmSalMinimo BIT,@pmSalIntegral BIT,@pmFPnomina VARCHAR(10),@pmModoRet INT,@pmFecAfiSeg SMALLDATETIME,@pmATFinMes BIT,@pmSegFinMes BIT,@pmDenyPEN BIT,@pmDenyEPS BIT,@pmDenyARP BIT,@pmDenyCaj BIT,@pmDenyCes BIT,@pmDenyPri BIT
,@pmDenyVac BIT,@pmDenyHex BIT,@pmBasePrest CHAR(2),@pmBaseSeg CHAR(2),@pmDchDotacion BIT,@pmDchCafeteria BIT,@pmReclmto VARCHAR(50),@pmNotas VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmIdClase VARCHAR(4),@pmTipoTrabj INT,@pmIdCot VARCHAR(4),@pmVrUpc MONEY,@pmIdGrupo VARCHAR(4),@pmDenyDcto BIT,@pmSubTipoCot VARCHAR(3),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Emp_Contrato SET IdEmpleado=@pmIdEmpleado,IdTipCon=@pmIdTipCon,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,Indefinido=@pmIndefinido,IdCargo=@pmIdCargo,IdJornada=@pmIdJornada,IdDep=@pmIdDep,IdArea=@pmIdArea,IdInstala=@pmIdInstala,IdCCosto=@pmIdCCosto,IdCia=@pmIdCia,IdNom=@pmIdNom,TipoLiquida=@pmTipoLiquida,ModPromdio=@pmModPromdio
,VrSalario=@pmVrSalario,VrAuxTrans=@pmVrAuxTrans,SalMinimo=@pmSalMinimo,SalIntegral=@pmSalIntegral,FPnomina=@pmFPnomina,ModoRet=@pmModoRet,FecAfiSeg=@pmFecAfiSeg,ATFinMes=@pmATFinMes,SegFinMes=@pmSegFinMes,DenyPEN=@pmDenyPEN,DenyEPS=@pmDenyEPS,DenyARP=@pmDenyARP,DenyCaj=@pmDenyCaj,DenyCes=@pmDenyCes,DenyPri=@pmDenyPri,DenyVac=@pmDenyVac,DenyHex=@pmDenyHex
,BasePrest=@pmBasePrest,BaseSeg=@pmBaseSeg,DchDotacion=@pmDchDotacion,DchCafeteria=@pmDchCafeteria,Reclmto=@pmReclmto,Notas=@pmNotas,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate,IdSubCos=@pmIdSubCos,IdClase=@pmIdClase,TipoTrabj=@pmTipoTrabj ,IdCot=@pmIdCot,VrUpc=@pmVrUpc,IdGrupo=@pmIdGrupo,DenyDcto=@pmDenyDcto,SubTipoCot =@pmSubTipoCot
 WHERE NContrato=@pmNContrato

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ContratoAre @pmIdArea VARCHAR(4),@pmIdDep VARCHAR(4)
 AS 
 UPDATE Emp_Contrato SET IdArea=@pmIdArea
 WHERE IdDep=@pmIdDep


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ContratoAum @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmVrSalario MONEY,@pmVrAuxTrans MONEY,@pmSalMinimo BIT
,@pmFecUltAum SMALLDATETIME,@pmFecUpdate SMALLDATETIME
 AS 
 BEGIN
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnContrato'
 BEGIN TRANSACTION @TrnNombre
 UPDATE Emp_Contrato SET VrSalario=@pmVrSalario,VrAuxTrans=@pmVrAuxTrans,SalMinimo=@pmSalMinimo,FecUpdate=@pmFecUpdate
 WHERE NContrato=@pmNContrato AND IdEmpleado=@pmIdEmpleado
 UPDATE Empleados SET FecUltAum=@pmFecUltAum WHERE  IdEmpleado=@pmIdEmpleado
 COMMIT TRANSACTION  @TrnNombre
 END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ContratoCc  @pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
 AS 
 UPDATE Emp_Contrato SET IdCCosto=@pmIdCCosto
 WHERE IdSubCos=@pmIdSubCos


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ContratoIns @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmIdInstala VARCHAR(4),@pmIdClase VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Emp_Contrato SET IdInstala=@pmIdInstala,IdClase=@pmIdClase,FecUpdate=@pmFecUpdate
 WHERE NContrato=@pmNContrato AND IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ContratoRet @pmNContrato INT,@pmFecRetiro SMALLDATETIME,@pmIdEstado VARCHAR(4)
,@pmInactivo BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Emp_Contrato SET FecRetiro=@pmFecRetiro,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate
 WHERE NContrato=@pmNContrato


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ContratoTlq @pmIdNom VARCHAR(4),@pmTipoLiquida CHAR(1)
 AS 
 UPDATE Emp_Contrato SET TipoLiquida=@pmTipoLiquida
 WHERE IdNom=@pmIdNom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_Estudios @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEstblecmto VARCHAR(50)
,@pmTitulo VARCHAR(50),@pmFecha SMALLDATETIME
 AS 
 UPDATE Emp_Estudios SET Estblecmto=@pmEstblecmto,Titulo=@pmTitulo,Fecha=@pmFecha
 WHERE IdEmpleado=@pmIdEmpleado AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_ExpLaboral @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEmpresa VARCHAR(50),@pmCargo VARCHAR(20)
,@pmFecInicio SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmDirEmpresa VARCHAR(100),@pmTelEmpresa VARCHAR(20)
 AS 
 UPDATE Emp_ExpLaboral SET Empresa=@pmEmpresa,Cargo=@pmCargo,FecInicio=@pmFecInicio,FecRetiro=@pmFecRetiro,DirEmpresa=@pmDirEmpresa,TelEmpresa=@pmTelEmpresa
 WHERE IdEmpleado=@pmIdEmpleado AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmp_Parientes @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmParntsco VARCHAR(10),@pmNombre VARCHAR(50)
,@pmFecNacmto SMALLDATETIME,@pmUltGrado VARCHAR(20),@pmDirccion VARCHAR(100),@pmTelefno VARCHAR(20)
 AS 
 UPDATE Emp_Parientes SET Parntsco=@pmParntsco,Nombre=@pmNombre,FecNacmto=@pmFecNacmto,UltGrado=@pmUltGrado,Dirccion=@pmDirccion,Telefno=@pmTelefno
 WHERE IdEmpleado=@pmIdEmpleado AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleados @pmIdEmpleado VARCHAR(16),@pmApellidos VARCHAR(80),@pmNombres VARCHAR(70),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmIdLugarCed VARCHAR(8),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmTelMovil VARCHAR(20),@pme_mail VARCHAR(100),@pmVvdaPropia BIT,@pmFecNacmto SMALLDATETIME,@pmLugarNacmto VARCHAR(30),@pmTipoSangre CHAR(2),@pmFactorRh CHAR(1),@pmSexo CHAR(1)
,@pmIdEstCivil VARCHAR(4),@pmNHijos INT,@pmLibMilitar VARCHAR(25),@pmClaseLib INT,@pmFechaLib SMALLDATETIME,@pmDistMil VARCHAR(10),@pmCertJudicial VARCHAR(25),@pmFecJudicial SMALLDATETIME,@pmVigJudicial SMALLDATETIME,@pmPasporte VARCHAR(25),@pmVigPaspte SMALLDATETIME,@pmLicencia VARCHAR(25),@pmIdLugar VARCHAR(8),@pmCatLicencia INT,@pmFecLicencia SMALLDATETIME,@pmVigLicencia SMALLDATETIME,@pmIdProf VARCHAR(4),@pmTallaCam CHAR(2)
,@pmTallaPan CHAR(2),@pmTallaZap CHAR(2),@pmUsaGafas BIT,@pmConyugue VARCHAR(50),@pmConyFecNac SMALLDATETIME,@pmConyTrabaja BIT,@pmConyEmpresa VARCHAR(50),@pmConyCargo VARCHAR(20),@pmConyFing SMALLDATETIME,@pmConyTel VARCHAR(20),@pmIdFonPen VARCHAR(8),@pmIdFonEps VARCHAR(8),@pmIdFonArp VARCHAR(8),@pmIdFonCes VARCHAR(8),@pmIdCajaCom VARCHAR(8),@pmCdFonAvp VARCHAR(8),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(25),@pmIdBanco VARCHAR(4),@pmNContrato INT,@pmFecVincula SMALLDATETIME
,@pmFecUltAum SMALLDATETIME,@pmFecUltCes SMALLDATETIME,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME,@pmFecUltDot SMALLDATETIME,@pmFecUltExm SMALLDATETIME,@pmFecUltCap SMALLDATETIME,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME,@pmFecRetAnt SMALLDATETIME,@pmFotoEmp VARCHAR(30),@pmFotoLic VARCHAR(30),@pmFotoFirma VARCHAR(30),@pmEsCondtor BIT,@pmpVehiculo VARCHAR(10)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCdLocCue VARCHAR(8),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET Apellidos=@pmApellidos,Nombres=@pmNombres,Codigo=@pmCodigo,TipoId=@pmTipoId,Dv=@pmDv,IdLugarCed=@pmIdLugarCed,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,TelMovil=@pmTelMovil,e_mail=@pme_mail,VvdaPropia=@pmVvdaPropia,FecNacmto=@pmFecNacmto,LugarNacmto=@pmLugarNacmto,TipoSangre=@pmTipoSangre,FactorRh=@pmFactorRh,Sexo=@pmSexo,IdEstCivil=@pmIdEstCivil,NHijos=@pmNHijos,LibMilitar=@pmLibMilitar,ClaseLib=@pmClaseLib,FechaLib=@pmFechaLib,DistMil=@pmDistMil
,CertJudicial=@pmCertJudicial,FecJudicial=@pmFecJudicial,VigJudicial=@pmVigJudicial,Pasporte=@pmPasporte,VigPaspte=@pmVigPaspte,Licencia=@pmLicencia,IdLugar=@pmIdLugar,CatLicencia=@pmCatLicencia,FecLicencia=@pmFecLicencia,VigLicencia=@pmVigLicencia,IdProf=@pmIdProf,TallaCam=@pmTallaCam,TallaPan=@pmTallaPan,TallaZap=@pmTallaZap,UsaGafas=@pmUsaGafas,Conyugue=@pmConyugue,ConyFecNac=@pmConyFecNac,ConyTrabaja=@pmConyTrabaja,ConyEmpresa=@pmConyEmpresa,ConyCargo=@pmConyCargo,FecVincula=@pmFecVincula
,ConyFing=@pmConyFing,ConyTel=@pmConyTel,IdFonPen=@pmIdFonPen,IdFonEps=@pmIdFonEps,IdFonArp=@pmIdFonArp,IdFonCes=@pmIdFonCes,IdCajaCom=@pmIdCajaCom,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,NContrato=@pmNContrato,FecUltAum=@pmFecUltAum,FecUltCes=@pmFecUltCes,FecUltPri=@pmFecUltPri,FecUltVac=@pmFecUltVac,FecUltIng=@pmFecUltIng,FecUltRet=@pmFecUltRet,FecUltDot=@pmFecUltDot,FecUltExm=@pmFecUltExm,FecUltCap=@pmFecUltCap,FotoEmp=@pmFotoEmp,CdFonAvp=@pmCdFonAvp
,NCAnterior=@pmNCAnterior, FotoLic=@pmFotoLic,FotoFirma=@pmFotoFirma,pVehiculo=@pmpVehiculo,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,EsCondtor=@pmEsCondtor,FecIngAnt=@pmFecIngAnt,FecRetAnt=@pmFecRetAnt,CdLocCue=@pmCdLocCue,FechaUpdate=@pmFechaUpdate
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleadosCon @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmFecVincula SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET NContrato=@pmNContrato,FecUltIng=@pmFecUltIng,FecUltRet=@pmFecUltRet
,IdEstado=@pmIdEstado,FecVincula=@pmFecVincula,FechaUpdate=@pmFechaUpdate
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleadosFon @pmIdEmpleado VARCHAR(16),@pmTipo VARCHAR(3),@pmIdFondo VARCHAR(8),@pmFechaUpdate SMALLDATETIME
AS
IF @pmTipo='PEN'
 UPDATE Empleados SET IdFonPen=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='EPS'
 UPDATE Empleados SET IdFonEps=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='ARP' or @pmTipo='APR'
 UPDATE Empleados SET IdFonArp=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='CES'
 UPDATE Empleados SET IdFonCes=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='COM'
 UPDATE Empleados SET IdCajaCom=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleadosFul @pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='VAC'
  UPDATE Empleados SET FecUltVac=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='PRI'
  UPDATE Empleados SET FecUltPri=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='CES'
  UPDATE Empleados SET FecUltCes=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='SAL'
  UPDATE Empleados SET FecUltAum=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='DOT'
  UPDATE Empleados SET FecUltDot=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='EXM'
  UPDATE Empleados SET FecUltExm=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='CAP'
  UPDATE Empleados SET FecUltCap=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='RET'
   UPDATE Empleados SET FecUltCes=@pmFecha,FecUltPri=@pmFecha,FecUltVac=@pmFecha WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleadosRet @pmIdEmpleado VARCHAR(16),@pmFecUltRet SMALLDATETIME,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME
,@pmFecRetAnt SMALLDATETIME,@pmFecUltCes SMALLDATETIME,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME
 AS 
 UPDATE Empleados SET FecUltRet=@pmFecUltRet,NCAnterior=@pmNCAnterior,FecIngAnt=@pmFecIngAnt,FecRetAnt=@pmFecRetAnt
,FecUltCes=@pmFecUltCes,FecUltPri=@pmFecUltPri,FecUltVac=@pmFecUltVac,Inactivo=1,IdEstado='9999'
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleadosRint @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME
,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME,@pmFecRetAnt SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmFecUltCes SMALLDATETIME
,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET NContrato=@pmNContrato,FecUltIng=@pmFecUltIng,FecUltRet=@pmFecUltRet,NCAnterior=@pmNCAnterior,FecIngAnt=@pmFecIngAnt
,FecRetAnt=@pmFecRetAnt,IdEstado=@pmIdEstado,FecUltCes=@pmFecUltCes,FecUltPri=@pmFecUltPri,FecUltVac=@pmFecUltVac,FechaUpdate=@pmFechaUpdate
,Inactivo=0
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEmpleadosVeh @pmIdEmpleado VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET pVehiculo=@pmpVehiculo,FechaUpdate=@pmFechaUpdate
 WHERE IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEntidades @pmIdTabla VARCHAR(20),@pmNivelRel INT,@pmCamposPK VARCHAR(50),@pmFngKey BIT,@pmSp_Qry VARCHAR(30),@pmSp_Qpmt VARCHAR(50),@pmSp_Ins VARCHAR(30)
,@pmSp_Upd VARCHAR(30),@pmSp_Del VARCHAR(30)
 AS 
 UPDATE Sys_Entidades SET NivelRel=@pmNivelRel,CamposPK=@pmCamposPK,FngKey=@pmFngKey,Sp_Qry=@pmSp_Qry,Sp_Qpmt=@pmSp_Qpmt,Sp_Ins=@pmSp_Ins,Sp_Upd=@pmSp_Upd,Sp_Del=@pmSp_Del
 WHERE IdTabla=@pmIdTabla

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEstaciones @pmIdEstacion CHAR(2),@pmEstacion VARCHAR(50)
 AS 
 UPDATE Sys_Estaciones SET Estacion=@pmEstacion
 WHERE IdEstacion=@pmIdEstacion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEstadoCiv @pmIdEstado VARCHAR(4),@pmEstCivil VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE EstadoCiv SET EstCivil=@pmEstCivil,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEstadoDoc @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT
,@pmCodDcmto VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE EstadoDoc SET Estado=@pmEstado,NColor=@pmNColor,CodDcmto=@pmCodDcmto,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpEstadoTer @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE EstadoTer SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpExpLicencias @pmIdLugar VARCHAR(8),@pmLugarLic VARCHAR(50)
,@pmCodDpto VARCHAR(8),@pmDpto VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ExpLicencias SET LugarLic=@pmLugarLic,CodDpto=@pmCodDpto,Dpto=@pmDpto,Inactivo=@pmInactivo
 WHERE IdLugar=@pmIdLugar

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpFields @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20),@pmDescripcion VARCHAR(50),@pmTipoDato VARCHAR(15),@pmLongMax INT,@pmRequerido BIT,@pmPmryKey BIT,@pmFmtValue VARCHAR(20)
,@pmDftValue VARCHAR(20),@pmAliasFld VARCHAR(20),@pmAliasQry2 VARCHAR(20),@pmIndField INT,@pmTipoEntidad VARCHAR(5),@pmLstTipo VARCHAR(5),@pmLstClnaValor VARCHAR(20),@pmLstClnaLista VARCHAR(50),@pmLstQuery VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE Sys_Fields SET Descripcion=@pmDescripcion,TipoDato=@pmTipoDato,LongMax=@pmLongMax,Requerido=@pmRequerido,PmryKey=@pmPmryKey,FmtValue=@pmFmtValue,DftValue=@pmDftValue,AliasFld=@pmAliasFld,AliasQry2=@pmAliasQry2
,IndField=@pmIndField,TipoEntidad=@pmTipoEntidad,LstTipo=@pmLstTipo,LstClnaValor=@pmLstClnaValor,LstClnaLista=@pmLstClnaLista,LstQuery=@pmLstQuery,Inactivo=@pmInactivo
 WHERE IdEntidad=@pmIdEntidad AND IdCampo=@pmIdCampo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpFmtDoc @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmPredtmnado BIT,@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT
,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 UPDATE Sys_FmtDoc SET Descripcion=@pmDescripcion,Formato=@pmFormato,Predtmnado=@pmPredtmnado,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup
,NumCopias=@pmNumCopias,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location
 WHERE IdDoc=@pmIdDoc AND IdForma=@pmIdForma

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpFmtDocPre @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2),@pmPredtmnado BIT
 AS 
 UPDATE Sys_FmtDoc SET Predtmnado=@pmPredtmnado
 WHERE IdDoc=@pmIdDoc AND IdForma<>@pmIdForma


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpFondos @pmIdFondo VARCHAR(8),@pmFondo VARCHAR(100)
,@pmIdClase VARCHAR(4),@pmIdTercero VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE Fondos SET Fondo=@pmFondo,IdClase=@pmIdClase,IdTercero=@pmIdTercero,Inactivo=@pmInactivo
 WHERE IdFondo=@pmIdFondo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpGruposAR @pmIdGrupo VARCHAR(4),@pmAltoRiesgo VARCHAR(50),@pmTarfaTrab DECIMAL(10,4),@pmTarfaEmp DECIMAL(10,4),@pmInactivo BIT
 AS 
 UPDATE GruposAR SET AltoRiesgo=@pmAltoRiesgo,TarfaTrab=@pmTarfaTrab,TarfaEmp=@pmTarfaEmp,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpGruposObj @pmIdGrupo VARCHAR(6),@pmGrupoObjeto VARCHAR(50),@pmnModulo VARCHAR(10)
 AS 
 UPDATE Sys_GruposObj SET GrupoObjeto=@pmGrupoObjeto,nModulo=@pmnModulo
 WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpGruposUsu @pmIdGrupo INT,@pmGrupo VARCHAR(50),@pmDescripcion VARCHAR(100)
 AS 
 UPDATE Sys_GruposUsu SET Grupo=@pmGrupo,Descripcion=@pmDescripcion
 WHERE IdGrupo=@pmIdGrupo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpInstalaciones @pmIdInstala VARCHAR(4),@pmInstlacion VARCHAR(50),@pmDirInstala VARCHAR(100)
,@pmCodCiu VARCHAR(8),@pmCodCia CHAR(2),@pmIdClase VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE Instalaciones SET Instlacion=@pmInstlacion,DirInstala=@pmDirInstala,CodCia=@pmCodCia
,CodCiu=@pmCodCiu,IdClase=@pmIdClase,Inactivo=@pmInactivo
 WHERE IdInstala=@pmIdInstala

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpJornadas @pmIdJornada VARCHAR(4),@pmJornada VARCHAR(50),@pmHorasDia INT
,@pmRangos VARCHAR(25),@pmInactivo BIT
 AS 
 UPDATE Jornadas SET Jornada=@pmJornada,HorasDia=@pmHorasDia,Rangos=@pmRangos,Inactivo=@pmInactivo
 WHERE IdJornada=@pmIdJornada

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpLocalidades @pmIdLocal VARCHAR(8),@pmLocalidad VARCHAR(50),@pmIdDep VARCHAR(8),@pmTipLocal VARCHAR(20)
,@pmDist_Kmt DECIMAL(10,4),@pmTime_hh VARCHAR(8),@pmCelRow DECIMAL(14,4),@pmCelCol DECIMAL(14,4),@pmInactivo BIT
,@pmDistSede DECIMAL(10,4),@pmTimeSede VARCHAR(8),@pmCodAlias VARCHAR(10)
 AS 
 UPDATE Localidades SET Localidad=@pmLocalidad,IdDep=@pmIdDep,TipLocal=@pmTipLocal,Dist_Kmt=@pmDist_Kmt,Time_hh=@pmTime_hh,CelRow=@pmCelRow
,CelCol=@pmCelCol,Inactivo=@pmInactivo,DistSede=@pmDistSede,TimeSede=@pmTimeSede,CodAlias=@pmCodAlias
 WHERE IdLocal=@pmIdLocal

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpLog_Nomina @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmCerrado BIT
,@pmIntCtaCte BIT,@pmLogCtaCte VARCHAR(100)
 AS 
 UPDATE Log_Nomina SET Cerrado=@pmCerrado,IntCtaCte=@pmIntCtaCte,LogCtaCte=@pmLogCtaCte
 WHERE IdNom=@pmIdNom AND IdPeriodo=@pmIdPeriodo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpLog_Periodos  @pmAnno INT,@pmIdCia CHAR(2),@pmnMes INT,@pmLock BIT
AS
 IF @pmnMes=1
  UPDATE Log_Periodos  SET  Ene=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=2
  UPDATE Log_Periodos SET Feb=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=3
  UPDATE Log_Periodos SET  Mar=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=4
  UPDATE Log_Periodos SET  Abr=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=5
  UPDATE Log_Periodos SET  May=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=6
  UPDATE Log_Periodos SET Jun=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=7
  UPDATE Log_Periodos SET Jul=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=8
  UPDATE Log_Periodos  SET Ago=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=9
  UPDATE Log_Periodos  SET Sep=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=10
  UPDATE Log_Periodos  SET  Oct=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=11
  UPDATE Log_Periodos  SET  Nov=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=12
  UPDATE Log_Periodos  SET  Dic=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=13
  UPDATE Log_Periodos  SET  CierreAnno=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpModulos @pmIdMod VARCHAR(3),@pmConsecutivo INT,@pmDescripcion VARCHAR(50)
,@pmValor BIT,@pmnModulo VARCHAR(10)
 AS 
 IF @pmIdMod IS NULL
  UPDATE Sys_Modulos SET Valor=@pmValor WHERE nModulo LIKE ISNULL(@pmnModulo,'%')
 ELSE
  UPDATE Sys_Modulos SET Consecutivo=@pmConsecutivo,Descripcion=@pmDescripcion,Valor=@pmValor,nModulo=@pmnModulo
  WHERE IdMod=@pmIdMod

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAbonos @pmNPrestamo INT,@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmFechaAbo SMALLDATETIME,@pmVrAbono MONEY,@pmnCuotas INT,@pmIdPeriodo VARCHAR(8)
,@pmDscto VARCHAR(3),@pmDetalle VARCHAR(50),@pmNLiquida INT
 AS 
 UPDATE Trn_NomAbonos SET IdEmpleado=@pmIdEmpleado,FechaAbo=@pmFechaAbo,VrAbono=@pmVrAbono,nCuotas=@pmnCuotas,IdPeriodo=@pmIdPeriodo,Dscto=@pmDscto,Detalle=@pmDetalle,NLiquida=@pmNLiquida
 WHERE NPrestamo=@pmNPrestamo AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAlqDet @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmApellido1 VARCHAR(50),@pmApellido2 VARCHAR(50),@pmNombre1 VARCHAR(50),@pmNombre2 VARCHAR(50),@pmIdFonPen VARCHAR(8),@pmIdFonSal VARCHAR(8),@pmIdFonRie VARCHAR(8),@pmIdCajCom VARCHAR(8),@pmSalBasico MONEY,@pmVrIBCPen MONEY
,@pmDiasPen DECIMAL(10,4),@pmTarifPen DECIMAL(10,4),@pmVrPension MONEY,@pmVrApoFsp MONEY,@pmVrApoFsu MONEY,@pmVrApoVolAfi MONEY,@pmVrApoVolApt MONEY,@pmVrNoReten MONEY,@pmVrIBCSal MONEY,@pmDiasSal DECIMAL(10,4),@pmTarifSal DECIMAL(10,4),@pmVrSalud MONEY,@pmVrUpc MONEY,@pmVrIncap MONEY,@pmVrLicencia MONEY,@pmNumAutInc VARCHAR(30),@pmNumAutLic VARCHAR(30),@pmVrIBCRie MONEY
,@pmDiasRie DECIMAL(10,4),@pmTarifRie DECIMAL(10,4),@pmVrRiesgos MONEY,@pmVrIncIrp MONEY,@pmNumAutIrp VARCHAR(30),@pmIdInstala VARCHAR(4),@pmVrIBCRef MONEY,@pmVrIBCCajas MONEY,@pmDiasCom DECIMAL(10,4),@pmTarifCom DECIMAL(10,4),@pmVrCajas MONEY,@pmTarifSen DECIMAL(10,4),@pmVrSena MONEY,@pmTarifIcb DECIMAL(10,4),@pmVrICBF MONEY,@pmTarifEsap DECIMAL(10,4),@pmVrESAP MONEY
,@pmTarifEdu DECIMAL(10,4),@pmVrMinEdu MONEY,@pmTarifFsp DECIMAL(10,4),@pmTarifFsu DECIMAL(10,4),@pmCdFonAvp VARCHAR(8)
 AS 
 UPDATE Trn_NomAlqDet SET IdEmpleado=@pmIdEmpleado,NContrato=@pmNContrato,Apellido1=@pmApellido1,Apellido2=@pmApellido2,Nombre1=@pmNombre1,Nombre2=@pmNombre2,IdFonPen=@pmIdFonPen,IdFonSal=@pmIdFonSal,IdFonRie=@pmIdFonRie,IdCajCom=@pmIdCajCom,SalBasico=@pmSalBasico,VrIBCPen=@pmVrIBCPen,DiasPen=@pmDiasPen,TarifPen=@pmTarifPen,VrPension=@pmVrPension,VrApoFsp=@pmVrApoFsp,VrApoFsu=@pmVrApoFsu
,VrApoVolAfi=@pmVrApoVolAfi,VrApoVolApt=@pmVrApoVolApt,VrNoReten=@pmVrNoReten,VrIBCSal=@pmVrIBCSal,DiasSal=@pmDiasSal,TarifSal=@pmTarifSal,VrSalud=@pmVrSalud,VrUpc=@pmVrUpc,VrIncap=@pmVrIncap,VrLicencia=@pmVrLicencia,NumAutInc=@pmNumAutInc,NumAutLic=@pmNumAutLic,VrIBCRie=@pmVrIBCRie,DiasRie=@pmDiasRie,TarifRie=@pmTarifRie,VrRiesgos=@pmVrRiesgos,VrIncIrp=@pmVrIncIrp,NumAutIrp=@pmNumAutIrp,IdInstala=@pmIdInstala
,VrIBCRef=@pmVrIBCRef,VrIBCCajas=@pmVrIBCCajas,DiasCom=@pmDiasCom,TarifCom=@pmTarifCom,VrCajas=@pmVrCajas,TarifSen=@pmTarifSen,VrSena=@pmVrSena,TarifIcb=@pmTarifIcb,VrICBF=@pmVrICBF,TarifEsap=@pmTarifEsap,VrESAP=@pmVrESAP,TarifEdu=@pmTarifEdu,VrMinEdu=@pmVrMinEdu,TarifFsp=@pmTarifFsp,TarifFsu=@pmTarifFsu,CdFonAvp=@pmCdFonAvp
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAlqNov @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNovIng INT,@pmNovRet INT,@pmNovTde INT,@pmNovTae INT,@pmNovTdp INT,@pmNovTap INT
,@pmNovVsp INT,@pmNovVte INT,@pmNovVst INT,@pmNovSln INT,@pmNovIge INT,@pmNovLma INT,@pmNovVac INT,@pmNovAvp INT,@pmNovVct INT,@pmNovIrp INT,@pmCodNewPen VARCHAR(8),@pmCodNewSal VARCHAR(8)
,@pmCodNewIns VARCHAR(4),@pmCodNewRie VARCHAR(4),@pmCodNewGru VARCHAR(4),@pmDiasNov INT
 AS 
 UPDATE Trn_NomAlqNov SET IdEmpleado=@pmIdEmpleado,NovIng=@pmNovIng,NovRet=@pmNovRet,NovTde=@pmNovTde,NovTae=@pmNovTae,NovTdp=@pmNovTdp,NovTap=@pmNovTap,NovVsp=@pmNovVsp,NovVte=@pmNovVte
,NovVst=@pmNovVst,NovSln=@pmNovSln,NovIge=@pmNovIge,NovLma=@pmNovLma,NovVac=@pmNovVac,NovAvp=@pmNovAvp,NovVct=@pmNovVct,NovIrp=@pmNovIrp,CodNewPen=@pmCodNewPen,CodNewSal=@pmCodNewSal
,CodNewIns=@pmCodNewIns,CodNewRie=@pmCodNewRie,CodNewGru=@pmCodNewGru,DiasNov=@pmDiasNov
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAlqTot @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmTipAdm VARCHAR(3),@pmIdFondo VARCHAR(8),@pmCodTipoApo CHAR(2),@pmVrTotalCot MONEY,@pmVrTotalFsp MONEY,@pmVrTotalFsu MONEY,@pmVrTotalAva MONEY,@pmVrTotalAve MONEY,@pmVrTotalUpc MONEY
,@pmVrTotalLic MONEY,@pmVrTotalInc MONEY,@pmVrTotalOtr MONEY,@pmDiasMora INT,@pmTarifMora DECIMAL(10,4),@pmVrIntMora MONEY,@pmVrIMoraOtr MONEY,@pmVrTotalSAF MONEY,@pmVrSAFUpc MONEY,@pmVrTotalPagar MONEY,@pmVrTotalFon MONEY,@pmTotalAfi INT,@pmNumAutLic VARCHAR(30),@pmNumAutInc VARCHAR(30)
,@pmNumPlaSAF VARCHAR(20),@pmTipoReg INT
 AS 
 UPDATE Trn_NomAlqTot SET TipAdm=@pmTipAdm,IdFondo=@pmIdFondo,CodTipoApo=@pmCodTipoApo,VrTotalCot=@pmVrTotalCot,VrTotalFsp=@pmVrTotalFsp,VrTotalFsu=@pmVrTotalFsu,VrTotalAva=@pmVrTotalAva,VrTotalAve=@pmVrTotalAve,VrTotalUpc=@pmVrTotalUpc,VrTotalLic=@pmVrTotalLic,VrTotalInc=@pmVrTotalInc
,VrTotalOtr=@pmVrTotalOtr,DiasMora=@pmDiasMora,TarifMora=@pmTarifMora,VrIntMora=@pmVrIntMora,VrIMoraOtr=@pmVrIMoraOtr,VrTotalSAF=@pmVrTotalSAF,VrSAFUpc=@pmVrSAFUpc,VrTotalPagar=@pmVrTotalPagar,VrTotalFon=@pmVrTotalFon,TotalAfi=@pmTotalAfi,NumAutLic=@pmNumAutLic,NumAutInc=@pmNumAutInc,NumPlaSAF=@pmNumPlaSAF
,TipoReg=@pmTipoReg
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAportante @pmIdAportnte VARCHAR(16),@pmRazonSocial VARCHAR(200),@pmTipoId CHAR(1),@pmDvNit CHAR(1),@pmIdRepLegal VARCHAR(16),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pme_mail VARCHAR(100),@pmClaseApo CHAR(1),@pmTipoEco CHAR(1),@pmTipoPersna CHAR(1)
,@pmCIIUDane VARCHAR(8),@pmFecIniCndato SMALLDATETIME,@pmTipAccCndato INT,@pmFecFinCndato SMALLDATETIME,@pmCodOperInfo VARCHAR(10),@pmTipoApo CHAR(1),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE NomAportante SET RazonSocial=@pmRazonSocial,TipoId=@pmTipoId,DvNit=@pmDvNit,IdRepLegal=@pmIdRepLegal,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,Fax=@pmFax,e_mail=@pme_mail,ClaseApo=@pmClaseApo,TipoEco=@pmTipoEco,TipoPersna=@pmTipoPersna,CIIUDane=@pmCIIUDane,FecIniCndato=@pmFecIniCndato,TipAccCndato=@pmTipAccCndato
,FecFinCndato=@pmFecFinCndato,CodOperInfo=@pmCodOperInfo,FecUpdate=@pmFecUpdate,TipoApo=@pmTipoApo
 WHERE IdAportnte=@pmIdAportnte

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAstncia @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME,@pmHHDiurno DECIMAL(10,4),@pmHHNocturno DECIMAL(10,4),@pmHEDiurno DECIMAL(10,4),@pmHENocturno DECIMAL(10,4)
,@pmTipoJrnada VARCHAR(10),@pmEsDmncal BIT,@pmHorario VARCHAR(30),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomAstncia SET HHDiurno=@pmHHDiurno,HHNocturno=@pmHHNocturno,HEDiurno=@pmHEDiurno,HENocturno=@pmHENocturno,TipoJrnada=@pmTipoJrnada,EsDmncal=@pmEsDmncal,Horario=@pmHorario,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND FechaDia=@pmFechaDia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAutoliq @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmFecha SMALLDATETIME,@pmPerAutoliq VARCHAR(6),@pmPerAutoSal VARCHAR(6),@pmFechaPago SMALLDATETIME,@pmIdAportnte VARCHAR(16),@pmPresentacion CHAR(1),@pmCodCia CHAR(2),@pmCodFondo VARCHAR(8),@pmCodArp VARCHAR(8),@pmCodOper VARCHAR(10),@pmEsCorr BIT,@pmPerCorr VARCHAR(6),@pmNumCorr VARCHAR(20),@pmTotalEmp INT,@pmVrNomina MONEY,@pmVrPension MONEY,@pmVrSalud MONEY,@pmVrRiesgos MONEY,@pmVrCajas MONEY
,@pmVrSena MONEY,@pmVrIcbf MONEY,@pmVrEsap MONEY,@pmVrMinEduc MONEY,@pmTotalAfipen INT,@pmTotalAfiSal INT,@pmTotalAfiRie INT,@pmTotalAfiCaj INT,@pmTotalAfiSen INT,@pmTotalAfiIcb INT,@pmTotalAfiEsa INT,@pmTotalAfiEduc INT,@pmTotAdmPen INT,@pmTotAdmSal INT,@pmTotAdmRie INT,@pmTotAdmCom INT,@pmObservacion VARCHAR(250),@pmLogAdmon VARCHAR(250),@pmRedoMiles BIT,@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME,@pmTipoPlanilla VARCHAR(3)
 AS 
 UPDATE Trn_NomAutoliq SET Fecha=@pmFecha,PerAutoliq=@pmPerAutoliq,PerAutoSal=@pmPerAutoSal,FechaPago=@pmFechaPago,IdAportnte=@pmIdAportnte,Presentacion=@pmPresentacion,CodCia=@pmCodCia,CodFondo=@pmCodFondo,CodArp=@pmCodArp,CodOper=@pmCodOper,EsCorr=@pmEsCorr,PerCorr=@pmPerCorr,NumCorr=@pmNumCorr,TotalEmp=@pmTotalEmp,VrNomina=@pmVrNomina,VrPension=@pmVrPension,VrSalud=@pmVrSalud,VrRiesgos=@pmVrRiesgos,VrCajas=@pmVrCajas,VrSena=@pmVrSena,VrIcbf=@pmVrIcbf,VrEsap=@pmVrEsap,VrMinEduc=@pmVrMinEduc
,TotalAfipen=@pmTotalAfipen,TotalAfiSal=@pmTotalAfiSal,TotalAfiRie=@pmTotalAfiRie,TotalAfiCaj=@pmTotalAfiCaj,TotalAfiSen=@pmTotalAfiSen,TotalAfiIcb=@pmTotalAfiIcb,TotalAfiEsa=@pmTotalAfiEsa,TotalAfiEduc=@pmTotalAfiEduc,TotAdmPen=@pmTotAdmPen,TotAdmSal=@pmTotAdmSal,TotAdmRie=@pmTotAdmRie,TotAdmCom=@pmTotAdmCom,Observacion=@pmObservacion,LogAdmon=@pmLogAdmon,RedoMiles=@pmRedoMiles,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipoPlanilla=@pmTipoPlanilla
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomAutoliqAnu @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomAutoliq SET Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomCAdmon @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmClaseAdmon VARCHAR(10),@pmFecIniNov SMALLDATETIME,@pmNNovedad INT
,@pmIdFondo VARCHAR(8),@pmIdFonNew VARCHAR(8),@pmObservacion VARCHAR(100),@pmAnulado BIT
 AS 
 UPDATE Trn_NomCAdmon SET Fecha=@pmFecha,NContrato=@pmNContrato,ClaseAdmon=@pmClaseAdmon,FecIniNov=@pmFecIniNov,NNovedad=@pmNNovedad,IdFondo=@pmIdFondo,IdFonNew=@pmIdFonNew
,Observacion=@pmObservacion,Anulado=@pmAnulado
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomCAdmonAnu @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmAnulado BIT
,@pmObservacion VARCHAR(100)
 AS 
 UPDATE Trn_NomCAdmon SET Observacion=@pmObservacion,Anulado=@pmAnulado
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomCausalesRet @pmIdCausa VARCHAR(4),@pmCausalRet VARCHAR(100),@pmIndmnizar BIT,@pmInactivo BIT
 AS 
 UPDATE NomCausalesRet SET CausalRet=@pmCausalRet,Indmnizar=@pmIndmnizar,Inactivo=@pmInactivo
 WHERE IdCausa=@pmIdCausa

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomCertf @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20),@pmnAnno INT,@pmnMes INT,@pmVrCertf MONEY
,@pmObservacion VARCHAR(100),@pmClaseCert VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomCertf SET nAnno=@pmnAnno,nMes=@pmnMes,VrCertf=@pmVrCertf,Observacion=@pmObservacion,ClaseCert=@pmClaseCert,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND NumCertf=@pmNumCertf

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomConAuto @pmIdReg INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmVrAplicar MONEY,@pmModalidad CHAR(1),@pmOrigenBase CHAR(2),@pmFrecAplica VARCHAR(10)
,@pmCedEmpleado VARCHAR(16),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodCcto VARCHAR(16),@pmCritSelect VARCHAR(4000),@pmFecFinal SMALLDATETIME,@pmExceptuar VARCHAR(8),@pmObservacion VARCHAR(50)
,@pmCodSubCos VARCHAR(16),@pmInactivo BIT,@pmNumPerMes INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomConAuto SET IdConcepto=@pmIdConcepto,FecInicio=@pmFecInicio,VrAplicar=@pmVrAplicar,Modalidad=@pmModalidad,OrigenBase=@pmOrigenBase,FrecAplica=@pmFrecAplica,CedEmpleado=@pmCedEmpleado,CodNom=@pmCodNom
,CodDep=@pmCodDep,CodCcto=@pmCodCcto,CritSelect=@pmCritSelect,FecFinal=@pmFecFinal,Exceptuar=@pmExceptuar,Observacion=@pmObservacion,Inactivo=@pmInactivo,CodSubCos=@pmCodSubCos,NumPerMes=@pmNumPerMes, FecUpdate=@pmFecUpdate
 WHERE IdReg=@pmIdReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomConCuentas @pmIdConcepto VARCHAR(4),@pmItem INT,@pmNClase INT,@pmIdCuenta VARCHAR(16)
,@pmTipoMov CHAR(1),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodFon VARCHAR(8),@pmNitTerc CHAR(1)
 AS 
 UPDATE NomConCuentas SET NClase=@pmNClase,IdCuenta=@pmIdCuenta,TipoMov=@pmTipoMov,CodNom=@pmCodNom
,CodDep=@pmCodDep,CodFon=@pmCodFon,NitTerc=@pmNitTerc
 WHERE IdConcepto=@pmIdConcepto AND  Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomConOpciones @pmIdConcepto VARCHAR(4),@pmIdOpc INT,@pmNomOpcion VARCHAR(50),@pmAsignado BIT
 AS 
 UPDATE NomConOpciones SET NomOpcion=@pmNomOpcion,Asignado=@pmAsignado
 WHERE IdConcepto=@pmIdConcepto AND IdOpc=@pmIdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomConceptos @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(100),@pmClaseCon VARCHAR(10),@pmUnidad VARCHAR(10),@pmTarifa DECIMAL(10,4)
,@pmBaseTrfa CHAR(2),@pmPdtermnado BIT,@pmInactivo BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE NomConceptos SET Concepto=@pmConcepto,ClaseCon=@pmClaseCon,Unidad=@pmUnidad,Tarifa=@pmTarifa,BaseTrfa=@pmBaseTrfa,Pdtermnado=@pmPdtermnado,Inactivo=@pmInactivo
,FechaUpdate=@pmFechaUpdate
 WHERE IdConcepto=@pmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomDefault @pmnAnno INT,@pmIdOpc VARCHAR(3),@pmDescripcion VARCHAR(100),@pmValor MONEY
 AS 
 UPDATE NomDefault SET Descripcion=@pmDescripcion,Valor=@pmValor
 WHERE nAnno=@pmnAnno AND IdOpc=@pmIdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomDetalle @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantDevg DECIMAL(10,4),@pmCantDed DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrTotDevg MONEY
,@pmVrTotDed MONEY,@pmUnidad VARCHAR(10),@pmClaseLiq VARCHAR(10),@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmDiasCalc DECIMAL(10,4),@pmDiasNov DECIMAL(10,4),@pmCodFondo VARCHAR(8),@pmNPrestamo INT,@pmNCuota INT,@pmOrigCargue VARCHAR(10),@pmVrBaseLiq MONEY
 AS 
 UPDATE Trn_NomDetalle SET IdEmpleado=@pmIdEmpleado,IdConcepto=@pmIdConcepto,Detalle=@pmDetalle,CantDevg=@pmCantDevg,CantDed=@pmCantDed,VrUnitario=@pmVrUnitario,VrTotDevg=@pmVrTotDevg,VrTotDed=@pmVrTotDed,Unidad=@pmUnidad,ClaseLiq=@pmClaseLiq
,VrOrigen=@pmVrOrigen,Tarifa=@pmTarifa,DiasCalc=@pmDiasCalc,DiasNov=@pmDiasNov,CodFondo=@pmCodFondo,NPrestamo=@pmNPrestamo,NCuota=@pmNCuota,OrigCargue=@pmOrigCargue,VrBaseLiq=@pmVrBaseLiq
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomFijos @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT,@pmTarifa DECIMAL(10,4),@pmVrBase MONEY,@pmVrSalarios MONEY,@pmVrPrima MONEY,@pmVrVacacnes MONEY,@pmVrSIntExcto MONEY,@pmVrOtrosIng MONEY,@pmVrIngresos MONEY
,@pmVrPensiones MONEY,@pmVrDedcido MONEY,@pmVrExcento MONEY,@pmVrCertEdu MONEY,@pmVrCertVda MONEY,@pmVrCertAFC MONEY,@pmVrCertfcado MONEY,@pmPeriodos DECIMAL(10,4),@pmVrTotalBase MONEY,@pmOrignPorc VARCHAR(10),@pmFecUpdate SMALLDATETIME
,@pmVrSalud MONEY 
 AS 
 UPDATE Trn_NomFijos SET Tarifa=@pmTarifa,VrBase=@pmVrBase,VrSalarios=@pmVrSalarios,VrPrima=@pmVrPrima,VrVacacnes=@pmVrVacacnes,VrSIntExcto=@pmVrSIntExcto,VrOtrosIng=@pmVrOtrosIng,VrIngresos=@pmVrIngresos,VrPensiones=@pmVrPensiones,VrDedcido=@pmVrDedcido
,VrExcento=@pmVrExcento,VrCertEdu=@pmVrCertEdu,VrCertVda=@pmVrCertVda,VrCertAFC=@pmVrCertAFC,VrCertfcado=@pmVrCertfcado,Periodos=@pmPeriodos,VrTotalBase=@pmVrTotalBase,OrignPorc=@pmOrignPorc,FecUpdate=@pmFecUpdate
,VrSalud=@pmVrSalud
 WHERE IdEmpleado=@pmIdEmpleado AND nAnno=@pmnAnno AND nMes=@pmnMes

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomLiquida @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME,@pmSemstre INT,@pmVrTotal MONEY,@pmVrTotDed MONEY,@pmVrAplicado MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4), @pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomLiquida SET Fecha=@pmFecha,Semstre=@pmSemstre,VrTotal=@pmVrTotal,VrTotDed=@pmVrTotDed,VrAplicado=@pmVrAplicado,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomLiquidaAnu @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmAnulado BIT,@pmIdEstado VARCHAR(4), @pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomLiquida SET Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomLiquidaPar @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdEstado VARCHAR(4),@pmAplica BIT
 AS 
 IF @pmAplica<>0
  UPDATE Trn_NomLiquida SET VrAplicado=VrTotal,IdEstado=@pmIdEstado  WHERE  TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Anulado=0
 ELSE
  UPDATE Trn_NomLiquida SET VrAplicado=0,IdEstado=@pmIdEstado  WHERE  TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Anulado=0

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomLogVeh @pmIdEmpleado VARCHAR(16),@pmNumReg INT,@pmFecha SMALLDATETIME,@pmpVehAnterior VARCHAR(10)
,@pmNitPropAnt VARCHAR(16),@pmpVehNew VARCHAR(10),@pmNitPropNew VARCHAR(16),@pmObservacion VARCHAR(100),@pmNitCondAnt VARCHAR(16)
 AS 
 UPDATE Trn_NomLogVeh SET Fecha=@pmFecha,pVehAnterior=@pmpVehAnterior,NitPropAnt=@pmNitPropAnt,pVehNew=@pmpVehNew,NitPropNew=@pmNitPropNew
,Observacion=@pmObservacion,NitCondAnt=@pmNitCondAnt
 WHERE IdEmpleado=@pmIdEmpleado AND NumReg=@pmNumReg

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomNov @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad DECIMAL(10,4),@pmVrUnitario MONEY
,@pmVrTotal MONEY,@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmOrigCargue VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomNov SET IdConcepto=@pmIdConcepto,Detalle=@pmDetalle,Cantidad=@pmCantidad,VrUnitario=@pmVrUnitario,VrTotal=@pmVrTotal,VrOrigen=@pmVrOrigen
,Tarifa=@pmTarifa,OrigCargue=@pmOrigCargue,FecUpdate=@pmFecUpdate
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomNovedad @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantDias INT,@pmDiaInicio INT
,@pmModalidad VARCHAR(10),@pmIdNov VARCHAR(4),@pmRemnrado BIT,@pmObservacion VARCHAR(250),@pmCodInstla VARCHAR(4),@pmInactivo BIT,@pmCodClsRie VARCHAR(4),@pmNumAutza VARCHAR(30),@pmCodNewFon VARCHAR(8)
,@pmCodOldFon VARCHAR(8),@pmVrCotVolAfi MONEY,@pmVrCotVolApo MONEY,@pmVrNoRetenido MONEY,@pmTipoIncap CHAR(1),@pmFechaDcto SMALLDATETIME,@pmVrDescuento MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomNovedad SET IdConcepto=@pmIdConcepto,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,CantDias=@pmCantDias,DiaInicio=@pmDiaInicio,Modalidad=@pmModalidad,IdNov=@pmIdNov,Remnrado=@pmRemnrado
,Observacion=@pmObservacion,Inactivo=@pmInactivo,CodInstla=@pmCodInstla,CodClsRie=@pmCodClsRie,NumAutza=@pmNumAutza,CodNewFon=@pmCodNewFon,FecUpdate=@pmFecUpdate
,VrCotVolAfi=@pmVrCotVolAfi,VrCotVolApo=@pmVrCotVolApo,VrNoRetenido=@pmVrNoRetenido,TipoIncap=@pmTipoIncap,CodOldFon=@pmCodOldFon,FechaDcto=@pmFechaDcto,VrDescuento=@pmVrDescuento
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomNovedadAnu @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmInactivo BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomNovedad SET Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrest @pmNPrestamo INT,@pmFecha SMALLDATETIME,@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmVrPrestamo MONEY,@pmNumCuotas INT,@pmVrCuota MONEY
,@pmFecInicio SMALLDATETIME,@pmFrecDcto VARCHAR(10),@pmExceptuar VARCHAR(8),@pmTotPrestamo MONEY,@pmTotAbonado MONEY,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmCxpagar BIT,@pmDsctNom INT,@pmDsctPri INT,@pmDsctVac INT,@pmDsctEspPer VARCHAR(8),@pmDsctEspVal MONEY
,@pmVrTmAbono MONEY,@pmNumPerMes INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomPrest SET Fecha=@pmFecha,IdEmpleado=@pmIdEmpleado,IdConcepto=@pmIdConcepto,VrPrestamo=@pmVrPrestamo,NumCuotas=@pmNumCuotas,VrCuota=@pmVrCuota,FecInicio=@pmFecInicio
,FrecDcto=@pmFrecDcto,Exceptuar=@pmExceptuar,TotPrestamo=@pmTotPrestamo,TotAbonado=@pmTotAbonado,Anulado=@pmAnulado,FecDev=@pmFecDev,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Cxpagar=@pmCxpagar,DsctNom=@pmDsctNom,DsctPri=@pmDsctPri,DsctVac=@pmDsctVac,DsctEspPer=@pmDsctEspPer,DsctEspVal=@pmDsctEspVal
,NumPerMes=@pmNumPerMes,VrTmAbono=@pmVrTmAbono,FecUpdate=@pmFecUpdate
 WHERE NPrestamo=@pmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestAbn @pmNPrestamo INT,@pmTotAbonado MONEY
 AS 
 UPDATE Trn_NomPrest SET TotAbonado=@pmTotAbonado
 WHERE NPrestamo=@pmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestAbo @pmIdEmpleado VARCHAR(16)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest 
 SET TotAbonado=(SELECT ISNULL(SUM(VrAbono),0) 
 FROM Trn_NomAbonos  WHERE  Trn_NomPrest.NPrestamo=Trn_NomAbonos.NPrestamo)
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestAnu @pmNPrestamo INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomPrest SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=ISNULL(@pmObservacion,Observacion)
 ,FecUpdate=@pmFecUpdate
 WHERE NPrestamo=@pmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestCan @pmNPrestamo INT,@pmTotAbonado MONEY,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomPrest SET TotAbonado=@pmTotAbonado,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate
 WHERE NPrestamo=@pmNPrestamo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestCero @pmIdEmpleado VARCHAR(16)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest SET TotAbonado=0,VrTmAbono=0
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestTAbo @pmIdEmpleado VARCHAR(16)=Null,@pmIdPeriodo VARCHAR(8)=Null
,@pmDscto VARCHAR(3)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest 
 SET VrTmAbono=(SELECT ISNULL(SUM(VrAbono),0) 
           FROM Trn_NomAbonos
          WHERE Trn_NomPrest.NPrestamo=Trn_NomAbonos.NPrestamo
         AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND Dscto LIKE ISNULL(@pmDscto,'%') )
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomPrestTCero @pmIdEmpleado VARCHAR(16)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest SET VrTmAbono=0
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomRangosFsu @pmIdRango INT,@pmVrInicial DECIMAL(12,2),@pmVrFinal DECIMAL(12,2),@pmTarifa DECIMAL(10,4)
 AS 
 UPDATE NomRangosFsu SET VrInicial=@pmVrInicial,VrFinal=@pmVrFinal,Tarifa=@pmTarifa
 WHERE IdRango=@pmIdRango

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomRet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmIdCausa VARCHAR(4),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmDiasTrab INT,@pmDiasNoRem INT,@pmVrTotDev MONEY,@pmVrTotDed MONEY,@pmVrTotCes MONEY,@pmVrTotPri MONEY,@pmVrTotVac MONEY,@pmVrTotInt MONEY
,@pmVrTotInd MONEY,@pmVrNeto MONEY,@pmVrBaseCes MONEY,@pmVrBaseVac MONEY,@pmIdPeriodo VARCHAR(8),@pmKeyReg VARCHAR(30),@pmNPerVac INT,@pmVrSalario MONEY,@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmTipoLiq CHAR(1),@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmVrParCes MONEY,@pmVrParInt MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomRet SET Fecha=@pmFecha,NContrato=@pmNContrato,IdCausa=@pmIdCausa,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,DiasTrab=@pmDiasTrab,DiasNoRem=@pmDiasNoRem,VrTotDev=@pmVrTotDev,VrTotDed=@pmVrTotDed,VrTotCes=@pmVrTotCes,VrTotPri=@pmVrTotPri,VrTotVac=@pmVrTotVac,VrTotInt=@pmVrTotInt,VrTotInd=@pmVrTotInd,VrNeto=@pmVrNeto,VrBaseCes=@pmVrBaseCes,TipoLiq=@pmTipoLiq
,VrBaseVac=@pmVrBaseVac,IdPeriodo=@pmIdPeriodo,KeyReg=@pmKeyReg,NPerVac=@pmNPerVac,VrSalario=@pmVrSalario,IdDep=@pmIdDep,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdNom=@pmIdNom,pVehiculo=@pmpVehiculo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado
, VrParCes=@pmVrParCes,VrParInt=@pmVrParInt,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomRetAnu @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomRet SET Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomSueldos @pmNumero INT,@pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmNContrato INT,@pmVrSueAnterior MONEY,@pmVrSueNuevo MONEY,@pmVrAtAnterior MONEY,@pmVrAtNuevo MONEY
,@pmMetodoUp CHAR(1),@pmReemplzado BIT,@pmFecUltAumto SMALLDATETIME,@pmCritSelect VARCHAR(250),@pmObservacion VARCHAR(100),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 UPDATE Trn_NomSueldos SET Fecha=@pmFecha,NContrato=@pmNContrato,VrSueAnterior=@pmVrSueAnterior,VrSueNuevo=@pmVrSueNuevo,VrAtAnterior=@pmVrAtAnterior,VrAtNuevo=@pmVrAtNuevo,MetodoUp=@pmMetodoUp
,Reemplzado=@pmReemplzado,FecUltAumto=@pmFecUltAumto,CritSelect=@pmCritSelect,Observacion=@pmObservacion
 WHERE Numero=@pmNumero AND IdEmpleado=@pmIdEmpleado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomTablaRet @pmnAnno INT,@pmnIntrvalo INT,@pmVrInicial MONEY,@pmVrFinal MONEY,@pmTarifa DECIMAL(10,4),@pmVrRetncion MONEY
,@pmTarExcdnte DECIMAL(10,4),@pmVrBaseExc MONEY,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE NomTablaRet SET VrInicial=@pmVrInicial,VrFinal=@pmVrFinal,Tarifa=@pmTarifa,VrRetncion=@pmVrRetncion,TarExcdnte=@pmTarExcdnte,VrBaseExc=@pmVrBaseExc
,FechaUpdate=@pmFechaUpdate
 WHERE nAnno=@pmnAnno AND nIntrvalo=@pmnIntrvalo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomVac @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrLiquida MONEY,@pmVrBase MONEY,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME,@pmDiasBase INT,@pmDiasNoRem INT
,@pmDiasVac INT,@pmNNovedad INT,@pmNPeriodos INT,@pmCantRem INT,@pmVrRemndo MONEY,@pmVrTotDed MONEY,@pmVrSalario MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmLogPmdio VARCHAR(600),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomVac SET Fecha=@pmFecha,NContrato=@pmNContrato,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,Cantidad=@pmCantidad,VrLiquida=@pmVrLiquida,VrBase=@pmVrBase,FecIniPmd=@pmFecIniPmd,FecFinPmd=@pmFecFinPmd,DiasBase=@pmDiasBase,DiasNoRem=@pmDiasNoRem,DiasVac=@pmDiasVac,NNovedad=@pmNNovedad,NPeriodos=@pmNPeriodos
,CantRem=@pmCantRem,VrRemndo=@pmVrRemndo,VrTotDed=@pmVrTotDed,VrSalario=@pmVrSalario,pVehiculo=@pmpVehiculo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,LogPmdio=@pmLogPmdio,IdEstado=@pmIdEstado,Anulado=@pmAnulado,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomVacAnu @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomVac SET IdEstado=@pmIdEstado,Anulado=@pmAnulado,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomVacDet @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad INT,@pmVrDevgado MONEY,@pmVrDeducido MONEY
,@pmTarifa DECIMAL(10,4),@pmVrBaseLiq MONEY,@pmVrCertfcado MONEY,@pmVrPension MONEY,@pmNPrestamo INT,@pmNCuota INT,@pmIdPeriodo VARCHAR(8),@pmVrSalud MONEY
 AS 
 UPDATE Trn_NomVacDet SET IdConcepto=@pmIdConcepto,Detalle=@pmDetalle,Cantidad=@pmCantidad,VrDevgado=@pmVrDevgado,VrDeducido=@pmVrDeducido,Tarifa=@pmTarifa,VrBaseLiq=@pmVrBaseLiq,VrCertfcado=@pmVrCertfcado
,VrPension=@pmVrPension,VrSalud=@pmVrSalud,NPrestamo=@pmNPrestamo,NCuota=@pmNCuota,IdPeriodo=@pmIdPeriodo
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero AND Item=@pmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomVehiculos @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmClaseVeh VARCHAR(50),@pmTipoAdmon VARCHAR(50)
,@pmGrupoProp VARCHAR(50),@pmVehPropio BIT,@pmCedCond VARCHAR(16),@pmConductor VARCHAR(50)
 AS 
 UPDATE NomVehiculos SET NumVeh=@pmNumVeh,ClaseVeh=@pmClaseVeh,TipoAdmon=@pmTipoAdmon,GrupoProp=@pmGrupoProp
,VehPropio=@pmVehPropio,CedCond=@pmCedCond,Conductor=@pmConductor
 WHERE IdVehiculo=@pmIdVehiculo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNomina @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmNContrato INT,@pmIdDep VARCHAR(4)
,@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrATransMes MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmEsRetiro BIT,@pmNLiqRet INT,@pmTipoLiq CHAR(1),@pmCantNoRem DECIMAL(10,4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Nomina SET IdEmpleado=@pmIdEmpleado,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,Cantidad=@pmCantidad,VrDevengado=@pmVrDevengado,VrDeducido=@pmVrDeducido,NContrato=@pmNContrato,IdDep=@pmIdDep,IdInstala=@pmIdInstala,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdNom=@pmIdNom
,VrSalario=@pmVrSalario,VrATransMes=@pmVrATransMes,pVehiculo=@pmpVehiculo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,EsRetiro=@pmEsRetiro,FecUpdate=@pmFecUpdate,NLiqRet=@pmNLiqRet,TipoLiq=@pmTipoLiq,CantNoRem=@pmCantNoRem
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpNominaCmp @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4),@pmEsRetiro BIT,@pmIdEmpleado VARCHAR(16)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Nomina SET TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE IdPeriodo=@pmIdPeriodo  AND IdNom=@pmIdNom  AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND  (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpObjetosApp @pmIdObj VARCHAR(10),@pmIdGrupo VARCHAR(6),@pmSubModulo VARCHAR(3),@pmIndObj INT,@pmNombre VARCHAR(100)
,@pmFormulario VARCHAR(10),@pmPermisos VARCHAR(20),@pmNivelMinimo INT,@pmNomArchivo VARCHAR(30)
 AS 
 UPDATE Sys_ObjetosApp SET IdGrupo=@pmIdGrupo,SubModulo=@pmSubModulo,IndObj=@pmIndObj,Nombre=@pmNombre
,Formulario=@pmFormulario,Permisos=@pmPermisos,NivelMinimo=@pmNivelMinimo,NomArchivo=@pmNomArchivo
 WHERE IdObj=@pmIdObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpOpciones @pmIdOpc VARCHAR(3),@pmOpcion VARCHAR(100),@pmTipoDato VARCHAR(15)
,@pmValor VARCHAR(100),@pmNivUp INT,@pmnModulo VARCHAR(10)
 AS 
 UPDATE adm_Opciones SET Opcion=@pmOpcion,TipoDato=@pmTipoDato,Valor=@pmValor
,NivUp=@pmNivUp,nModulo=@pmnModulo
 WHERE IdOpc=@pmIdOpc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpPaises @pmIdPais VARCHAR(8),@pmCodISO VARCHAR(3),@pmNombrePais VARCHAR(50),@pmIdMneda VARCHAR(5)
 AS 
 UPDATE adm_Paises SET CodISO=@pmCodISO,NombrePais=@pmNombrePais,IdMneda=@pmIdMneda
 WHERE IdPais=@pmIdPais

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpPermisos @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmConsecutivo INT,@pmPerAdd BIT,@pmPerUpdate BIT
,@pmPerDelete BIT,@pmPerAnular BIT,@pmPerRead BIT,@pmPerRename BIT
 AS 
 UPDATE adm_Permisos SET PerAdd=@pmPerAdd,PerUpdate=@pmPerUpdate
,PerDelete=@pmPerDelete,PerAnular=@pmPerAnular,PerRead=@pmPerRead,PerRename=@pmPerRename
 ,Consecutivo=ISNULL(@pmConsecutivo,Consecutivo)
 WHERE IdUsuario=@pmIdUsuario AND IdObj=@pmIdObj

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpPermisosRoles @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmAsignado BIT
 AS 
 UPDATE adm_PermisosRoles SET Asignado=@pmAsignado
 WHERE IdUsuario=@pmIdUsuario AND IdObj=@pmIdObj AND IdRole LIKE ISNULL(@pmIdRole,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpProfesiones @pmIdProf VARCHAR(4),@pmProfesion VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE Profesiones SET Profesion=@pmProfesion,Inactivo=@pmInactivo
 WHERE IdProf=@pmIdProf

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paUpPuc @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(100),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT,@pmSubCentro BIT,@pmVehiculo BIT,@pmCentroCosto BIT,@pmVencimiento BIT,@pmBaseGravable BIT
,@pmPorcntaje DECIMAL(10,4),@pmNaturaleza CHAR(1),@pmAjustable BIT,@pmCuentaAjuDeb VARCHAR(16),@pmCuentaAjuCre VARCHAR(16),@pmCheques BIT,@pmReferncias BIT
,@pmAgencia BIT,@pmFmtDian INT,@pmConDian INT,@pmRenDec INT,@pmCdTipDoc VARCHAR(3),@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT,@pmAfijos INT
 AS 
 UPDATE Puc SET NomCuenta=@pmNomCuenta,Mayor=@pmMayor,Movimiento=@pmMovimiento,Tercero=@pmTercero,SubCentro=@pmSubCentro,Vehiculo=@pmVehiculo,CentroCosto=@pmCentroCosto,Vencimiento=@pmVencimiento,BaseGravable=@pmBaseGravable
,Porcntaje=@pmPorcntaje,Naturaleza=@pmNaturaleza,Ajustable=@pmAjustable,CuentaAjuDeb=@pmCuentaAjuDeb,CuentaAjuCre=@pmCuentaAjuCre,Cheques=@pmCheques,Referncias=@pmReferncias,Agencia=@pmAgencia
,FmtDian=@pmFmtDian,ConDian=@pmConDian,RenDec=@pmRenDec,CdTipDoc=@pmCdTipDoc,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo,Afijos=@pmAfijos
 WHERE IdCuenta=@pmIdCuenta

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpRegimenDian @pmIdRegimen VARCHAR(4),@pmRegimen VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE RegimenDian SET Regimen=@pmRegimen,Inactivo=@pmInactivo
 WHERE IdRegimen=@pmIdRegimen

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpRegistro @pmIdCia CHAR(2),@pmIdEmpresa VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmDvNit CHAR(1),@pmRazonSocial VARCHAR(250),@pmDescripcion VARCHAR(250)
,@pmDireccion VARCHAR(250),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmIdLocal VARCHAR(8),@pmIdPais VARCHAR(8),@pme_mail VARCHAR(100),@pmArchivoLogo VARCHAR(30),@pmNumeroSerial VARCHAR(80)
,@pmRegimen VARCHAR(50),@pmLicencia VARCHAR(20),@pmVigenciaLic SMALLDATETIME,@pmPersoneria VARCHAR(40),@pmLeyenda VARCHAR(250),@pmFechaRegistro SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmCurrtyDate SMALLDATETIME
,@pmTipoId CHAR(1),@pmNitRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150),@pmTipoPersna CHAR(1),@pmCIIUDane VARCHAR(8),@pmCurDate1 SMALLDATETIME
 AS 
 UPDATE adm_Registro SET IdEmpresa=@pmIdEmpresa,NitEmpresa=@pmNitEmpresa,DvNit=@pmDvNit,RazonSocial=@pmRazonSocial,Descripcion=@pmDescripcion,Direccion=@pmDireccion,Telefono=@pmTelefono
,Fax=@pmFax,IdLocal=@pmIdLocal,IdPais=@pmIdPais,e_mail=@pme_mail,ArchivoLogo=@pmArchivoLogo,NumeroSerial=@pmNumeroSerial,Regimen=@pmRegimen,Licencia=@pmLicencia,VigenciaLic=@pmVigenciaLic
,Personeria=@pmPersoneria,Leyenda=@pmLeyenda,FechaRegistro=@pmFechaRegistro,FechaVence=@pmFechaVence,CurrtyDate=@pmCurrtyDate
,TipoId=@pmTipoId,NitRepLegal=@pmNitRepLegal,RepLegal=@pmRepLegal,TipoPersna=@pmTipoPersna ,CIIUDane=@pmCIIUDane,CurDate1=@pmCurDate1

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpRegistroFec  @pmCurrtyDate SMALLDATETIME,@pmUpCia BIT,@pmIdCia CHAR(2)=Null
 AS 
 IF @pmUpCia=1  
  BEGIN
  DECLARE @TrnCias VARCHAR(20)
  SELECT @TrnCias = 'TrnFecha'
  BEGIN TRANSACTION @TrnCias
  UPDATE adm_Registro SET CurrtyDate=@pmCurrtyDate
  UPDATE Companias SET FechaActual=@pmCurrtyDate WHERE IdCia=@pmIdCia
  COMMIT TRANSACTION  @TrnCias  
  END
 ELSE
  UPDATE adm_Registro SET CurrtyDate=@pmCurrtyDate

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpRelaciones @pmIdTabla VARCHAR(20),@pmTablaForanea VARCHAR(20),@pmCampoForaneo VARCHAR(20)
,@pmBasedeDatos VARCHAR(10),@pmNoValidar BIT
 AS 
 UPDATE Sys_Relaciones SET BasedeDatos=@pmBasedeDatos,NoValidar=@pmNoValidar
 WHERE IdTabla=@pmIdTabla AND TablaForanea=@pmTablaForanea AND CampoForaneo=@pmCampoForaneo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpReport @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmTipoPapel INT
,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50),@pmNomRep VARCHAR(50)
 AS 
 UPDATE Sys_Report SET Descripcion=@pmDescripcion,Formato=@pmFormato,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup
,NumCopias=@pmNumCopias,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location,NomRep=@pmNomRep
 WHERE TipoRep=@pmTipoRep AND IdRep=@pmIdRep

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpRoles @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmFuncion VARCHAR(100)
 AS 
 UPDATE Sys_Roles SET Funcion=@pmFuncion
 WHERE IdObj=@pmIdObj AND IdRole=@pmIdRole

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpSectoresEco @pmIdSector VARCHAR(8),@pmSectorEco VARCHAR(250),@pmInactivo BIT
 AS 
 UPDATE SectoresEco SET SectorEco=@pmSectorEco,Inactivo=@pmInactivo
 WHERE IdSector=@pmIdSector

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpSecurity @pmIdLla INT,@pmDescripcion VARCHAR(50),@pmPwd VARCHAR(10)
 AS 
 UPDATE Sys_Security SET Descripcion=@pmDescripcion,Pwd=[REDACTED]
 WHERE IdLla=@pmIdLla

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpSubCentros @pmIdSubCos VARCHAR(16),@pmSubCosto VARCHAR(100),@pmIdCCosto VARCHAR(16),@pmFecUpdate SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE SubCentros SET SubCosto=@pmSubCosto,IdCCosto=@pmIdCCosto,FecUpdate=@pmFecUpdate,Inactivo=@pmInactivo
 WHERE IdSubCos=@pmIdSubCos

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTerceros @pmIdTercero VARCHAR(16),@pmRazonSocial VARCHAR(250),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8)
,@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmTelMovil VARCHAR(20),@pmSitioWeb VARCHAR(100),@pme_mail VARCHAR(100),@pmEsCliente BIT,@pmEsVendedor BIT,@pmEsConductor BIT
,@pmEsPropietario BIT,@pmEsProveedor BIT,@pmEsEmpleado BIT,@pmEsOperario BIT,@pmEsAccnista BIT,@pmEsCiaAseg BIT,@pmIdSector VARCHAR(8),@pmIdRegimen VARCHAR(4),@pmIdLugarCed VARCHAR(8),@pmObservacion VARCHAR(250)
,@pmIniStgNom INT,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmNomCial VARCHAR(250),@pmSiglaRaz VARCHAR(50),@pmIdProf VARCHAR(4),@pmTipEnte CHAR(1),@pmFecExpCed SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Terceros SET RazonSocial=@pmRazonSocial,Codigo=@pmCodigo,TipoId=@pmTipoId,Dv=@pmDv,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,Fax=@pmFax,TelMovil=@pmTelMovil,SitioWeb=@pmSitioWeb,e_mail=@pme_mail
,EsCliente=@pmEsCliente,EsVendedor=@pmEsVendedor,EsConductor=@pmEsConductor,EsPropietario=@pmEsPropietario,EsProveedor=@pmEsProveedor,EsEmpleado=@pmEsEmpleado,EsOperario=@pmEsOperario,EsAccnista=@pmEsAccnista,EsCiaAseg=@pmEsCiaAseg 
,IdSector=@pmIdSector,IdRegimen=@pmIdRegimen,IdLugarCed=@pmIdLugarCed,Observacion=@pmObservacion,IniStgNom=@pmIniStgNom,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate
,NomCial=@pmNomCial,SiglaRaz=@pmSiglaRaz,IdProf=@pmIdProf,TipEnte=@pmTipEnte,FecExpCed=@pmFecExpCed
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTercerosCdt  @pmIdTercero VARCHAR(16),@pmEsConductor BIT
 AS 
 UPDATE Terceros SET EsConductor=@pmEsConductor
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTercerosCli @pmIdTercero VARCHAR(16),@pmEsCliente BIT
 AS 
 UPDATE Terceros SET EsCliente=@pmEsCliente
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTercerosPrv @pmIdTercero VARCHAR(16),@pmEsProveedor BIT
 AS 
 UPDATE Terceros SET EsProveedor=@pmEsProveedor
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTercerosVen @pmIdTercero VARCHAR(16),@pmEsVendedor BIT
 AS 
 UPDATE Terceros SET EsVendedor=@pmEsVendedor
 WHERE IdTercero=@pmIdTercero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposCom @pmIdCom VARCHAR(3),@pmTipoCom VARCHAR(50),@pmIdDiario VARCHAR(4)
,@pmEsEgreso BIT,@pmConsUnico BIT,@pmInactivo BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TiposCom SET TipoCom=@pmTipoCom,IdDiario=@pmIdDiario,EsEgreso=@pmEsEgreso
,ConsUnico=@pmConsUnico,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate
 WHERE IdCom=@pmIdCom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposComCons @pmIdCom VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT,@pmNumero INT
,@pmNumManual BIT,@pmFormato VARCHAR(20),@pmConfigFecha VARCHAR(10),@pmTipoPapel INT,@pmOrientacion INT
,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TiposComCons SET LDesde=@pmLDesde,LHasta=@pmLHasta,Numero=@pmNumero,NumManual=@pmNumManual
,Formato=@pmFormato,ConfigFecha=@pmConfigFecha,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion
,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,FechaUpdate=@pmFechaUpdate
 WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposComConsNum @pmIdCom VARCHAR(3),@pmIdCia CHAR(2),@pmNumero INT
 AS 
 IF @pmNumero IS NULL
  UPDATE TiposComCons SET Numero=Numero+1
  WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia
 ELSE
  UPDATE TiposComCons SET Numero=@pmNumero
  WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposCon @pmIdTipCon VARCHAR(4),@pmTipoContrato VARCHAR(100)
,@pmDuracion INT,@pmInactivo BIT
 AS 
 UPDATE TiposCon SET TipoContrato=@pmTipoContrato,Duracion=@pmDuracion,Inactivo=@pmInactivo
 WHERE IdTipCon=@pmIdTipCon

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposCot @pmIdCot VARCHAR(4),@pmCotizante VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposCot SET Cotizante=@pmCotizante,Inactivo=@pmInactivo
 WHERE IdCot=@pmIdCot

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposDoc @pmIdDoc VARCHAR(3),@pmTipoDoc VARCHAR(50),@pmConsUnico BIT
,@pmLeyenda VARCHAR(250),@pmInactivo BIT,@pmIntegraCias BIT
 AS 
 UPDATE Sys_TiposDoc SET TipoDoc=@pmTipoDoc,ConsUnico=@pmConsUnico
,Leyenda=@pmLeyenda,Inactivo=@pmInactivo,IntegraCias=@pmIntegraCias
 WHERE IdDoc=@pmIdDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposDocCons @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT,@pmResolucion VARCHAR(30),@pmRangoNum VARCHAR(50),@pmFechaRes SMALLDATETIME
,@pmPrefijo VARCHAR(5),@pmNumero INT,@pmNumManual BIT,@pmIntLotes BIT,@pmConfigFecha VARCHAR(10),@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT
,@pmVerSetup BIT,@pmNumCopias INT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TiposDocCons SET LDesde=@pmLDesde,LHasta=@pmLHasta,Resolucion=@pmResolucion,RangoNum=@pmRangoNum,FechaRes=@pmFechaRes,Prefijo=@pmPrefijo
,Numero=@pmNumero,NumManual=@pmNumManual,IntLotes=@pmIntLotes,ConfigFecha=@pmConfigFecha,Formato=@pmFormato,TipoPapel=@pmTipoPapel
,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,FechaUpdate=@pmFechaUpdate
 WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposDocConsNum @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmNumero INT
 AS 
 IF @pmNumero IS NULL
  UPDATE TiposDocCons SET Numero=Numero+1
  WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia
 ELSE
  UPDATE TiposDocCons SET Numero=@pmNumero
  WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposDocCue @pmIdDoc VARCHAR(3),@pmIdClase INT
,@pmClaseCuenta VARCHAR(50),@pmTipoMov CHAR(1)
 AS 
 UPDATE Sys_TiposDocCue SET ClaseCuenta=@pmClaseCuenta,TipoMov=@pmTipoMov
 WHERE IdDoc=@pmIdDoc AND IdClase=@pmIdClase

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposNom @pmIdNom VARCHAR(4),@pmTipoNomina VARCHAR(50),@pmAsistencia BIT,@pmNoDevenga BIT
,@pmTipoLiquida CHAR(1),@pmFechaActual SMALLDATETIME,@pmInactivo BIT,@pmCdCiaInt CHAR(2)
 AS 
 UPDATE TiposNom SET TipoNomina=@pmTipoNomina,Asistencia=@pmAsistencia,NoDevenga=@pmNoDevenga,TipoLiquida=@pmTipoLiquida
,FechaActual=@pmFechaActual,Inactivo=@pmInactivo,CdCiaInt=@pmCdCiaInt
 WHERE IdNom=@pmIdNom

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpTiposNov @pmIdNov VARCHAR(4),@pmNovedad VARCHAR(50),@pmAdmon VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE TiposNov SET Novedad=@pmNovedad,Admon=@pmAdmon,Inactivo=@pmInactivo
 WHERE IdNov=@pmIdNov

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpUOpciones @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20),@pmValor VARCHAR(50)
 AS 
 UPDATE adm_UOpciones SET Valor=@pmValor
 WHERE IdUsuario=@pmIdUsuario AND NomOpcion=@pmNomOpcion

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpUm @pmUndMed VARCHAR(10),@pmUnidad VARCHAR(50)
 AS 
 UPDATE Sys_Um SET Unidad=@pmUnidad
 WHERE UndMed=@pmUndMed

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpUsuarios @pmIdUsuario VARCHAR(11),@pmUsuario VARCHAR(50),@pmPwdLog VARCHAR(30),@pmIdGrupo INT,@pmIdEstacion CHAR(2),@pmIdCargo VARCHAR(4),@pmConectado BIT,@pmFechaAcc SMALLDATETIME
,@pmFechaClave SMALLDATETIME,@pmCaducidad INT,@pmLoginSQL VARCHAR(20),@pmPwdSQL VARCHAR(20),@pmModoSQL VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE adm_Usuarios SET Usuario=@pmUsuario,PwdLog=@pmPwdLog,IdGrupo=@pmIdGrupo,IdEstacion=@pmIdEstacion,IdCargo=@pmIdCargo,Conectado=@pmConectado,FechaAcc=@pmFechaAcc,FechaClave=@pmFechaClave,Caducidad=@pmCaducidad
,LoginSQL=@pmLoginSQL,PwdSQL=@pmPwdSQL,ModoSQL=@pmModoSQL,Inactivo=@pmInactivo
 WHERE IdUsuario=@pmIdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpUsuariosCnn  @pmConectado BIT,@pmFechaAcc SMALLDATETIME,@pmIdUsuario VARCHAR(11)
AS
 IF @pmConectado<>0
 UPDATE adm_Usuarios SET Conectado=@pmConectado,FechaAcc=@pmFechaAcc WHERE IdUsuario=@pmIdUsuario
ELSE
 UPDATE adm_Usuarios SET Conectado=@pmConectado  WHERE IdUsuario=@pmIdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpUsuariosPwd  @pmPwdLog VARCHAR(30),@pmFechaClave SMALLDATETIME,@pmIdUsuario VARCHAR(11)
AS
UPDATE adm_Usuarios SET PwdLog=@pmPwdLog,FechaClave=@pmFechaClave
WHERE IdUsuario=@pmIdUsuario

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpmonedas @pmIdMneda VARCHAR(5),@pmMneda VARCHAR(50),@pmSimbolo VARCHAR(10)
,@pmMneLocal BIT,@pmVrCambio DECIMAL(12,6),@pmInactivo BIT
 AS 
 UPDATE adm_monedas SET Mneda=@pmMneda,Simbolo=@pmSimbolo,MneLocal=@pmMneLocal,VrCambio=@pmVrCambio,Inactivo=@pmInactivo
 WHERE IdMneda=@pmIdMneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUpmonedasLoc @pmMneLocal BIT,@pmIdMneda VARCHAR(5)
 AS 
 UPDATE adm_monedas SET MneLocal=@pmMneLocal
 WHERE IdMneda<>@pmIdMneda

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_AportesDet @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmApellido1 VARCHAR(50),@pmtmApellido2 VARCHAR(50),@pmtmNombre1 VARCHAR(50),@pmtmNombre2 VARCHAR(50),@pmtmNContto INT,@pmtmDiasPen DECIMAL(10,4),@pmtmDiasSal DECIMAL(10,4),@pmtmDiasRie DECIMAL(10,4),@pmtmDiasCom DECIMAL(10,4),@pmtmBasePen MONEY,@pmtmBaseSal MONEY,@pmtmBaseRie MONEY,@pmtmBaseCom MONEY,@pmtmBaseRef MONEY,@pmtmValorPen MONEY,@pmtmValorSal MONEY,@pmtmValorRie MONEY,@pmtmValorCom MONEY,@pmtmValorSena MONEY,@pmtmValorIcbf MONEY,@pmtmValorFsp MONEY,@pmtmValorFsu MONEY,@pmtmValorESAP MONEY,@pmtmValorMin MONEY,@pmtmTarfaPen DECIMAL(10,4),@pmtmTarfaSal DECIMAL(10,4),@pmtmTarfaRie DECIMAL(10,4)
,@pmtmTarfaFsp DECIMAL(10,4),@pmtmTarfaFsu DECIMAL(10,4),@pmtmTarfaEsa DECIMAL(10,4),@pmtmTarfaMin DECIMAL(10,4),@pmtmTarfaCom DECIMAL(10,4),@pmtmTarfaIcb DECIMAL(10,4),@pmtmTarfaSen DECIMAL(10,4),@pmtmVrIncap MONEY,@pmtmVrLicencia MONEY,@pmtmVrVolAfi MONEY,@pmtmVrVolApo MONEY,@pmtmVrNoReten MONEY
,@pmtmVrUpc MONEY,@pmtmVrIncIrp MONEY,@pmtmNAutLic VARCHAR(30),@pmtmNAutInc VARCHAR(30),@pmtmNAutIrp VARCHAR(30),@pmtmIdFonPen VARCHAR(8),@pmtmIdFonSal VARCHAR(8),@pmtmIdFonRie VARCHAR(8),@pmtmIdFonCaj VARCHAR(8),@pmtmIdInstala VARCHAR(4),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVehiculo VARCHAR(10),@pmtmVrBasico MONEY
,@pmtmCdFonAvp VARCHAR(8)
 AS 
 UPDATE tm_Aportes SET tmIdEmpleado=@pmtmIdEmpleado,tmApellido1=@pmtmApellido1,tmApellido2=@pmtmApellido2,tmNombre1=@pmtmNombre1,tmNombre2=@pmtmNombre2,tmNContto=@pmtmNContto,tmDiasPen=@pmtmDiasPen,tmDiasSal=@pmtmDiasSal,tmDiasRie=@pmtmDiasRie,tmDiasCom=@pmtmDiasCom,tmBasePen=@pmtmBasePen,tmBaseSal=@pmtmBaseSal,tmBaseRie=@pmtmBaseRie,tmBaseCom=@pmtmBaseCom,tmBaseRef=@pmtmBaseRef,tmValorPen=@pmtmValorPen,tmValorSal=@pmtmValorSal,tmValorRie=@pmtmValorRie,tmValorCom=@pmtmValorCom,tmValorSena=@pmtmValorSena,tmValorIcbf=@pmtmValorIcbf,tmValorFsp=@pmtmValorFsp,tmValorFsu=@pmtmValorFsu,tmValorESAP=@pmtmValorESAP
,tmValorMin=@pmtmValorMin,tmTarfaPen=@pmtmTarfaPen,tmTarfaSal=@pmtmTarfaSal,tmTarfaRie=@pmtmTarfaRie,tmTarfaFsp=@pmtmTarfaFsp,tmTarfaFsu=@pmtmTarfaFsu,tmTarfaEsa=@pmtmTarfaEsa,tmTarfaMin=@pmtmTarfaMin,tmTarfaCom=@pmtmTarfaCom,tmTarfaIcb=@pmtmTarfaIcb,tmTarfaSen=@pmtmTarfaSen,tmVrIncap=@pmtmVrIncap,tmVrLicencia=@pmtmVrLicencia,tmVrVolAfi=@pmtmVrVolAfi,tmVrVolApo=@pmtmVrVolApo,tmVrNoReten=@pmtmVrNoReten,tmVrUpc=@pmtmVrUpc,tmVrIncIrp=@pmtmVrIncIrp,tmNAutLic=@pmtmNAutLic,tmNAutInc=@pmtmNAutInc,tmNAutIrp=@pmtmNAutIrp,tmIdFonPen=@pmtmIdFonPen,tmIdFonSal=@pmtmIdFonSal,tmIdFonRie=@pmtmIdFonRie,tmIdFonCaj=@pmtmIdFonCaj,tmIdInstala=@pmtmIdInstala
,tmIdDep=@pmtmIdDep,tmIdCCosto=@pmtmIdCCosto,tmIdSubCos=@pmtmIdSubCos,tmIdNom=@pmtmIdNom,tmVehiculo=@pmtmVehiculo,tmVrBasico=@pmtmVrBasico,tmCdFonAvp=@pmtmCdFonAvp
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_AportesNov @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmNovIng INT,@pmtmNovRet INT,@pmtmNovTda INT,@pmtmNovTaa INT,@pmtmNovTdp INT,@pmtmNovTap INT
,@pmtmNovVsp INT,@pmtmNovVte INT,@pmtmNovVst INT,@pmtmNovSln INT,@pmtmNovIge INT,@pmtmNovLma INT,@pmtmNovVac INT,@pmtmNovAvp INT,@pmtmNovIrp INT,@pmtmNovVct INT
,@pmtmCodNewEps VARCHAR(8),@pmtmCodNewPen VARCHAR(8),@pmtmCodNewRie VARCHAR(8),@pmtmCodNewIns VARCHAR(4),@pmtmCodNewTar VARCHAR(4),@pmtmCodNewGru VARCHAR(4),@pmtmDiasNov DECIMAL(10,4)
 AS 
 UPDATE tm_Aportes SET tmNovIng=@pmtmNovIng,tmNovRet=@pmtmNovRet,tmNovTda=@pmtmNovTda,tmNovTaa=@pmtmNovTaa,tmNovTdp=@pmtmNovTdp,tmNovTap=@pmtmNovTap,tmNovVsp=@pmtmNovVsp,tmNovVte=@pmtmNovVte,tmNovVst=@pmtmNovVst,tmNovSln=@pmtmNovSln
,tmNovIge=@pmtmNovIge,tmNovLma=@pmtmNovLma,tmNovVac=@pmtmNovVac,tmNovAvp=@pmtmNovAvp,tmNovIrp=@pmtmNovIrp,tmNovVct=@pmtmNovVct,tmCodNewEps=@pmtmCodNewEps,tmCodNewPen=@pmtmCodNewPen,tmCodNewRie=@pmtmCodNewRie,tmCodNewIns=@pmtmCodNewIns
,tmCodNewTar=@pmtmCodNewTar,tmCodNewGru=@pmtmCodNewGru,tmDiasNov=@pmtmDiasNov
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_AutTot @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmTipAdm VARCHAR(3),@pmtmIdFondo VARCHAR(8),@pmtmCodTipoApo CHAR(2),@pmtmTotalCot MONEY,@pmtmTotalFsp MONEY,@pmtmTotalFsu MONEY,@pmtmTotalAva MONEY,@pmtmTotalAve MONEY
,@pmtmTotalUpc MONEY,@pmtmTotalLic MONEY,@pmtmTotalInc MONEY,@pmtmTotalOtr MONEY,@pmtmDiasMora INT,@pmtmTarifMora DECIMAL(10,4),@pmtmIntMora MONEY,@pmtmIMoraOtr MONEY,@pmtmTotalSAF MONEY,@pmtmSAFUpc MONEY,@pmtmTotalPagar MONEY,@pmtmTotalFon MONEY
,@pmtmTotalAfi INT,@pmtmNumAutLic VARCHAR(30),@pmtmNumAutInc VARCHAR(30),@pmtmNumPlaSAF VARCHAR(20)
 AS 
 UPDATE tm_AutTot SET tmTipAdm=@pmtmTipAdm,tmIdFondo=@pmtmIdFondo,tmCodTipoApo=@pmtmCodTipoApo,tmTotalCot=@pmtmTotalCot,tmTotalFsp=@pmtmTotalFsp,tmTotalFsu=@pmtmTotalFsu,tmTotalAva=@pmtmTotalAva,tmTotalAve=@pmtmTotalAve,tmTotalUpc=@pmtmTotalUpc,tmTotalLic=@pmtmTotalLic
,tmTotalInc=@pmtmTotalInc,tmTotalOtr=@pmtmTotalOtr,tmDiasMora=@pmtmDiasMora,tmTarifMora=@pmtmTarifMora,tmIntMora=@pmtmIntMora,tmIMoraOtr=@pmtmIMoraOtr,tmTotalSAF=@pmtmTotalSAF,tmSAFUpc=@pmtmSAFUpc,tmTotalPagar=@pmtmTotalPagar,tmTotalFon=@pmtmTotalFon,tmTotalAfi=@pmtmTotalAfi
,tmNumAutLic=@pmtmNumAutLic,tmNumAutInc=@pmtmNumAutInc,tmNumPlaSAF=@pmtmNumPlaSAF
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_Liquida @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmDetalle VARCHAR(100),@pmtmFecUltLiq SMALLDATETIME,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmVrBase MONEY,@pmtmCantidad INT,@pmtmVrLiquida MONEY
,@pmtmVrDeducido MONEY,@pmtmFecIniPmd SMALLDATETIME,@pmtmFecFinPmd SMALLDATETIME,@pmtmDiasBase INT,@pmtmDiasNoRem INT,@pmtmTarifa DECIMAL(10,4),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmLogPmdio VARCHAR(600),@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16)
,@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrParcial MONEY
 AS 
 UPDATE tm_Liquida SET tmIdEmpleado=@pmtmIdEmpleado,tmIdConcepto=@pmtmIdConcepto,tmDetalle=@pmtmDetalle,tmFecUltLiq=@pmtmFecUltLiq,tmFecInicial=@pmtmFecInicial,tmFecFinal=@pmtmFecFinal,tmVrBase=@pmtmVrBase,tmCantidad=@pmtmCantidad,tmVrLiquida=@pmtmVrLiquida,tmVrDeducido=@pmtmVrDeducido,tmFecIniPmd=@pmtmFecIniPmd
,tmFecFinPmd=@pmtmFecFinPmd,tmDiasBase=@pmtmDiasBase,tmDiasNoRem=@pmtmDiasNoRem,tmTarifa=@pmtmTarifa,tmNPrestamo=@pmtmNPrestamo,tmNCuota=@pmtmNCuota,tmLogPmdio=@pmtmLogPmdio,tmNContrato=@pmtmNContrato,tmpVehiculo=@pmtmpVehiculo,tmIdDep=@pmtmIdDep,tmIdCCosto=@pmtmIdCCosto,tmIdSubCos=@pmtmIdSubCos
,tmIdNom=@pmtmIdNom,tmVrSalario=@pmtmVrSalario,tmVrParcial=@pmtmVrParcial
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_LiquidaInt @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4) ,@pmtmVrBase MONEY
,@pmtmVrLiquida MONEY,@pmtmVrDeducido MONEY
 AS 
 UPDATE tm_Liquida SET tmVrBase=@pmtmVrBase,tmVrLiquida=@pmtmVrLiquida,tmVrDeducido=@pmtmVrDeducido
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto=@pmtmIdConcepto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_LiquidaPar @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmVrBase MONEY,@pmtmCantidad INT,@pmtmVrLiquida MONEY,@pmtmVrDeducido MONEY,@pmtmDiasBase INT,@pmtmDiasNoRem INT
,@pmtmTarifa DECIMAL(10,4),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmVrParcial MONEY
 AS 
 UPDATE tm_Liquida SET tmFecInicial=@pmtmFecInicial,tmFecFinal=@pmtmFecFinal,tmVrBase=@pmtmVrBase,tmCantidad=@pmtmCantidad,tmVrLiquida=@pmtmVrLiquida,tmVrDeducido=@pmtmVrDeducido,tmDiasBase=@pmtmDiasBase,tmDiasNoRem=@pmtmDiasNoRem
,tmTarifa=@pmtmTarifa,tmNPrestamo=@pmtmNPrestamo,tmNCuota=@pmtmNCuota,tmVrParcial=@pmtmVrParcial
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_Nomina @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT,@pmtmIdConcepto VARCHAR(4),@pmtmClaseCon VARCHAR(10),@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(10,4)
,@pmtmCantDed DECIMAL(10,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY,@pmtmUnidad VARCHAR(10),@pmtmClaseLiq VARCHAR(10),@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasCalc DECIMAL(10,4)
,@pmtmDiasNov DECIMAL(10,4),@pmtmCodFondo VARCHAR(8),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmOrigCargue VARCHAR(10),@pmtmVrBaseLiq MONEY,@pmtmNContto INT,@pmtmFecIni SMALLDATETIME,@pmtmFecFin SMALLDATETIME,@pmtmIdPeriodo VARCHAR(8)
,@pmtmVrPension MONEY,@pmtmVrSalud MONEY
 AS 
 UPDATE tm_Nomina SET tmIdConcepto=@pmtmIdConcepto,tmClaseCon=@pmtmClaseCon,tmDetalle=@pmtmDetalle,tmCantDevg=@pmtmCantDevg,tmCantDed=@pmtmCantDed,tmVrUnitario=@pmtmVrUnitario,tmVrTotDevg=@pmtmVrTotDevg,tmVrTotDed=@pmtmVrTotDed
,tmUnidad=@pmtmUnidad,tmClaseLiq=@pmtmClaseLiq,tmVrOrigen=@pmtmVrOrigen,tmTarifa=@pmtmTarifa,tmDiasCalc=@pmtmDiasCalc,tmDiasNov=@pmtmDiasNov,tmCodFondo=@pmtmCodFondo,tmNPrestamo=@pmtmNPrestamo,tmNCuota=@pmtmNCuota,tmOrigCargue=@pmtmOrigCargue
,tmVrBaseLiq=@pmtmVrBaseLiq,tmNContto=@pmtmNContto,tmFecIni=@pmtmFecIni,tmFecFin=@pmtmFecFin,tmIdPeriodo=@pmtmIdPeriodo,tmVrPension=@pmtmVrPension,tmVrSalud=@pmtmVrSalud
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_NominaPar @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT,@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(10,4),@pmtmCantDed DECIMAL(10,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY,@pmtmUnidad VARCHAR(10)
,@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasCalc DECIMAL(10,4),@pmtmDiasNov DECIMAL(10,4),@pmtmVrBaseLiq MONEY,@pmtmFecIni SMALLDATETIME,@pmtmFecFin SMALLDATETIME,@pmtmFecUltLiq SMALLDATETIME
 AS 
 UPDATE tm_Nomina SET tmDetalle=@pmtmDetalle,tmCantDevg=@pmtmCantDevg,tmCantDed=@pmtmCantDed,tmVrUnitario=@pmtmVrUnitario,tmVrTotDevg=@pmtmVrTotDevg,tmVrTotDed=@pmtmVrTotDed,tmUnidad=@pmtmUnidad,tmVrOrigen=@pmtmVrOrigen
,tmTarifa=@pmtmTarifa,tmDiasCalc=@pmtmDiasCalc,tmDiasNov=@pmtmDiasNov,tmVrBaseLiq=@pmtmVrBaseLiq,tmFecIni=@pmtmFecIni,tmFecFin=@pmtmFecFin,tmFecUltLiq=@pmtmFecUltLiq
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmItem=@pmtmItem

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_PlasueldosObs @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30),@pmtmObserv VARCHAR(1000)
 AS 
 UPDATE  tm_Plasueldos  SET tmObserv=@pmtmObserv
 WHERE tmIdPeriodo=@pmtmIdPeriodo AND tmKeyRegistro LIKE ISNULL(@pmtmKeyRegistro,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO


CREATE PROCEDURE paUptm_PlasueldosVac @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30)
,@pmtmVrVacLiquida MONEY,@pmtmVrVacPen MONEY,@pmtmVrVacSal MONEY,@pmtmVrVacFsp MONEY,@pmtmVrVacOtr MONEY
 AS 
 UPDATE  tm_Plasueldos  SET tmVrVacLiquida=@pmtmVrVacLiquida,tmVrVacPen=@pmtmVrVacPen
,tmVrVacSal=@pmtmVrVacSal,tmVrVacFsp=@pmtmVrVacFsp,tmVrVacOtr=@pmtmVrVacOtr
 WHERE tmIdPeriodo=@pmtmIdPeriodo  AND tmKeyRegistro=@pmtmKeyRegistro

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

