ALTER TABLE tm_Liquida ALTER COLUMN tmLogPmdio VARCHAR(1500)
GO
ALTER TABLE tm_Nomina ALTER COLUMN tmLogPmdio VARCHAR(1500)
GO
ALTER TABLE Trn_NomLiqDet ALTER COLUMN LogPmdio VARCHAR(1500)
GO
ALTER TABLE Trn_NomRetDet ALTER COLUMN LogPmdio VARCHAR(1500)
GO
ALTER TABLE Trn_NomVac ALTER COLUMN LogPmdio VARCHAR(1500)
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsNomLiqDet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsNomLiqDet]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsNomRetDet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsNomRetDet]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsNomVac]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsNomVac]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Liquida]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_Liquida]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Nomina]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_Nomina]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryEmpleadosCon]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryEmpleadosCon]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpNomVac]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpNomVac]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUptm_Liquida]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUptm_Liquida]
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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(1500)
,@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmDiasAjuste INT,@pmLiqParcial BIT,@pmDiasDom INT,@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,DiasAjuste,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario,LiqParcial,DiasDom)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmFecInicial,@pmFecFinal,@pmCantidad,@pmVrLiquida,@pmVrBase,@pmFecIniPmd,@pmFecFinPmd,@pmDiasBase,@pmDiasNoRem,@pmDiasVac,@pmNNovedad,@pmNPeriodos,@pmCantRem,@pmVrRemndo,@pmVrTotDed,@pmVrSalario,@pmpVehiculo,@pmDiasAjuste
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmLogPmdio,@pmIdEstado,@pmAnulado,@pmTimeSys,@pmIdUsuario,@pmLiqParcial,@pmDiasDom)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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(1500),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmDiasAjuste INT,@pmLiqParcial BIT,@pmDiasDom INT,@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,DiasAjuste=@pmDiasAjuste,LiqParcial=@pmLiqParcial,DiasDom=@pmDiasDom,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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(1500),@pmtmVrPension MONEY,@pmtmVrSalud MONEY,@pmtmBasExceso MONEY,@pmtmNitTercero VARCHAR(16),@pmtmHoraInicial DATETIME,@pmtmHoraFinal DATETIME,@pmtmTipoInc VARCHAR(20),@pmtmVrIngNoSal 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,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal)
 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,@pmtmBasExceso,@pmtmNitTercero,@pmtmHoraInicial,@pmtmHoraFinal,@pmtmTipoInc,@pmtmVrIngNoSal)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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,C.IdConvCT
 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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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(1500),@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrParcial MONEY,@pmtmNitTercero VARCHAR(16)
 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,tmNitTercero)
 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,@pmtmNitTercero)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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(1500),@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16)
,@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrParcial MONEY,@pmtmNitTercero VARCHAR(16)
 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,tmNitTercero=@pmtmNitTercero
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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(1500),@pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmpVehiculo VARCHAR(10),@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrParcial MONEY,@pmNitTercero VARCHAR(16)
 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,NitTercero)
 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,@pmNitTercero)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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(1500)
,@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
