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 OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelLogBusesAhorro @pmnAnno INT,@pmnMes INT
 AS 
 DELETE FROM LogBusesAhorro
 WHERE 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 paDelLogCierres @pmProceso VARCHAR(10),@pmAnno INT,@pmnMes INT,@pmnDia INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM LogCierres
 WHERE Proceso=@pmProceso AND Anno=@pmAnno AND nMes=@pmnMes
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (nDia>=ISNULL(@pmnDia,-1)  AND nDia<=ISNULL(@pmnDia,2147483647))
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelLogEgresos @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM LogEgresos
 WHERE IdLog=@pmIdLog 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 paDelLogMayLiquida @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM LogMayLiquida
 WHERE NLiquida=@pmNLiquida 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 paDelLogMayoriza @pmAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM LogMayoriza
 WHERE Anno=@pmAnno AND nMes=@pmnMes 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 paDelLogPrecios @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM LogPrecios
 WHERE IdLog=@pmIdLog 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 paDelLogPreciosDet @pmIdLog INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM LogPreciosDet
 WHERE IdLog=@pmIdLog 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 paDelLogPreciosDetPro @pmIdLog INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
 AS 
 DELETE FROM LogPreciosDet
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia  AND IdProducto=@pmIdProducto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelLogReloj @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME
 AS 
 DELETE FROM LogReloj
 WHERE IdEmpleado=@pmIdEmpleado AND 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 paDelLogSobTasas @pmIdDec VARCHAR(4),@pmIdLog INT
 AS 
 DELETE FROM LogSobTasas
 WHERE IdDec=@pmIdDec AND IdLog=@pmIdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogAfijos @pmTipoDoc VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME,@pmEstadoReg INT
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogAfijos (TipoDoc,Numero,Fecha,EstadoReg,TipCom,Comprobante,IdCiaCom,IdUsuario,Nombre)
 VALUES (@pmTipoDoc,@pmNumero,@pmFecha,@pmEstadoReg,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogAfijosDet @pmTipoDoc VARCHAR(3),@pmNumero INT,@pmItem INT,@pmIdActivo VARCHAR(30),@pmNomActivo VARCHAR(250),@pmTipo VARCHAR(10),@pmNumSerie VARCHAR(30),@pmCodInvent VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdInstala VARCHAR(4),@pmIdDep VARCHAR(4)
,@pmIdRespons VARCHAR(16),@pmIdTipDif VARCHAR(4),@pmIdProv VARCHAR(16),@pmFecCompra SMALLDATETIME,@pmFecActivacion SMALLDATETIME,@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmVrBaseDep MONEY,@pmVidaUtil INT,@pmMetodoDep VARCHAR(10),@pmAjustable BIT,@pmContable BIT,@pmCueEnGrupo BIT
,@pmNumPlaca VARCHAR(20),@pmNumDoc VARCHAR(20),@pmReferencia VARCHAR(50),@pmMarca VARCHAR(30),@pmIdCuenta VARCHAR(16),@pmIdCueDep VARCHAR(16),@pmIdCueGasto VARCHAR(16),@pmIdCueAjuste VARCHAR(16),@pmIdCueCorr VARCHAR(16),@pmIdEstado VARCHAR(4),@pmItemDoc INT,@pmTransaccion INT,@pmTipoValoriza INT
,@pmObservaciones VARCHAR(250),@pmTipoAmtza CHAR(1),@pmNitCliente VARCHAR(16),@pmAgenCliente VARCHAR(16),@pmCantGalones DECIMAL(14,4),@pmVrMejoras MONEY,@pmVrDisminuc MONEY
 AS 
 INSERT INTO LogAfijosDet (TipoDoc,Numero,Item,IdActivo,NomActivo,Tipo,NumSerie,CodInvent,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdTipDif,IdProv,FecCompra,FecActivacion,NumOrden,IdCiaOrden,NumEntrada,IdCiaEnt,VrBaseDep,VidaUtil,MetodoDep,Ajustable,Contable,CueEnGrupo,NumPlaca,NumDoc,Referencia,Marca,IdCuenta,IdCueDep,IdCueGasto,IdCueAjuste
,IdCueCorr,IdEstado,ItemDoc,Transaccion,TipoValoriza,Observaciones,TipoAmtza,NitCliente,AgenCliente,CantGalones,VrMejoras,VrDisminuc)
 VALUES (@pmTipoDoc,@pmNumero,@pmItem,@pmIdActivo,@pmNomActivo,@pmTipo,@pmNumSerie,@pmCodInvent,@pmIdGrupo,@pmIdCCosto,@pmIdSubCos,@pmIdInstala,@pmIdDep,@pmIdRespons,@pmIdTipDif,@pmIdProv,@pmFecCompra,@pmFecActivacion,@pmNumOrden,@pmIdCiaOrden,@pmNumEntrada,@pmIdCiaEnt,@pmVrBaseDep,@pmVidaUtil,@pmMetodoDep
,@pmAjustable,@pmContable,@pmCueEnGrupo,@pmNumPlaca,@pmNumDoc,@pmReferencia,@pmMarca,@pmIdCuenta,@pmIdCueDep,@pmIdCueGasto,@pmIdCueAjuste,@pmIdCueCorr,@pmIdEstado,@pmItemDoc,@pmTransaccion,@pmTipoValoriza,@pmObservaciones,@pmTipoAmtza,@pmNitCliente,@pmAgenCliente,@pmCantGalones,@pmVrMejoras,@pmVrDisminuc)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogBusesAhorro @pmnAnno INT,@pmnMes INT,@pmCalculado BIT,@pmObservacion VARCHAR(50)
 AS 
 INSERT INTO LogBusesAhorro (nAnno,nMes,Calculado,Observacion)
 VALUES (@pmnAnno,@pmnMes,@pmCalculado,@pmObservacion)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogBusesNomina @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmFecha SMALLDATETIME,@pmCerrado BIT,@pmObservacion VARCHAR(250)
,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO LogBusesNomina  (TipProc,CdNom,IdPeriodo,Fecha,Cerrado,Observacion,TimeSys,IdUsuario)
 VALUES (@pmTipProc,@pmCdNom,@pmIdPeriodo,@pmFecha,@pmCerrado,@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 paInsLogBusesRec @pmTipoProc VARCHAR(3),@pmNumero INT,@pmNomArchivo VARCHAR(50),@pmFechaRec SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmCantReg INT
,@pmCantRegErr INT,@pmEstadoProc INT,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogBusesRec (TipoProc,Numero,NomArchivo,FechaRec,FechaCrea,CantReg,CantRegErr,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre)
 VALUES (@pmTipoProc,@pmNumero,@pmNomArchivo,@pmFechaRec,@pmFechaCrea,@pmCantReg,@pmCantRegErr,@pmEstadoProc,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogBusesRecDet @pmTipoProc VARCHAR(3),@pmNumero INT,@pmItem INT,@pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmNomProp VARCHAR(150)
,@pmIdCond VARCHAR(16),@pmNomCond VARCHAR(150),@pmVehEsPropio BIT,@pmVrSaldoAnt MONEY,@pmValorRec MONEY,@pmVrDescuento MONEY,@pmEstado INT,@pmNumRecibo INT,@pmIdCiaRec CHAR(2)
,@pmFechaRec SMALLDATETIME,@pmNumCuenta VARCHAR(50),@pmReferencia VARCHAR(50),@pmCodSucursal VARCHAR(10),@pmDescRegistro VARCHAR(250),@pmComentario VARCHAR(250)
 AS 
 INSERT INTO LogBusesRecDet (TipoProc,Numero,Item,IdVehiculo,NumVeh,IdPropietario,NomProp,IdCond,NomCond,VehEsPropio,VrSaldoAnt,ValorRec,VrDescuento,Estado,NumRecibo,IdCiaRec,FechaRec,NumCuenta,Referencia,CodSucursal,DescRegistro,Comentario)
 VALUES (@pmTipoProc,@pmNumero,@pmItem,@pmIdVehiculo,@pmNumVeh,@pmIdPropietario,@pmNomProp,@pmIdCond,@pmNomCond,@pmVehEsPropio,@pmVrSaldoAnt,@pmValorRec,@pmVrDescuento,@pmEstado
,@pmNumRecibo,@pmIdCiaRec,@pmFechaRec,@pmNumCuenta,@pmReferencia,@pmCodSucursal,@pmDescRegistro,@pmComentario)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogCierres @pmProceso VARCHAR(10),@pmAnno INT,@pmnMes INT,@pmnDia INT,@pmIdCia CHAR(2),@pmEstado INT,@pmFecha SMALLDATETIME
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmCuenta INT,@pmProcessExt1 INT,@pmProcessExt2 INT,@pmProcessExt3 INT,@pmProcessExt4 INT,@pmProcessExt5 INT
 AS 
 INSERT INTO LogCierres (Proceso,Anno,nMes,nDia,IdCia,Estado,Fecha,IdUsuario,Nombre,Cuenta,ProcessExt1,ProcessExt2,ProcessExt3,ProcessExt4,ProcessExt5)
 VALUES (@pmProceso,@pmAnno,@pmnMes,@pmnDia,@pmIdCia,@pmEstado,@pmFecha,@pmIdUsuario,@pmNombre,@pmCuenta,@pmProcessExt1
,@pmProcessExt2,@pmProcessExt3,@pmProcessExt4,@pmProcessExt5)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogCortes @pmIdLog INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumCorte INT,@pmPlanilla INT,@pmIdCiaPla CHAR(2),@pmFecPlanilla SMALLDATETIME
,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmObservacion VARCHAR(250),@pmArchivo1 VARCHAR(50),@pmArchivo2 VARCHAR(50)
 AS 
 INSERT INTO LogCortes (IdLog,IdCia,Fecha,NumCorte,Planilla,IdCiaPla,FecPlanilla,TimeSys,IdUsuario,Nombre,Observacion,Archivo1,Archivo2)
 VALUES (@pmIdLog,@pmIdCia,@pmFecha,@pmNumCorte,@pmPlanilla,@pmIdCiaPla,@pmFecPlanilla,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmObservacion,@pmArchivo1,@pmArchivo2)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogCxpAprob @pmNumero INT,@pmItem INT,@pmFecha SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2)
,@pmItemFact INT,@pmIdCuenta VARCHAR(16),@pmIdProveedor VARCHAR(16),@pmNomProvee VARCHAR(150),@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmEstado INT,@pmDetalle VARCHAR(100)
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogCxpAprob (Numero,Item,Fecha,TimeSys,TipFac,Factura,IdCia,ItemFact,IdCuenta,IdProveedor,NomProvee,VrFactura,VrAbonado,Estado,Detalle,IdUsuario,Nombre)
 VALUES (@pmNumero,@pmItem,@pmFecha,@pmTimeSys,@pmTipFac,@pmFactura,@pmIdCia,@pmItemFact,@pmIdCuenta,@pmIdProveedor,@pmNomProvee,@pmVrFactura
,@pmVrAbonado,@pmEstado,@pmDetalle,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogEgresos @pmIdLog INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmNumCheque VARCHAR(20),@pmEnEfectivo BIT
,@pmVrEgreso MONEY,@pmIdTercero VARCHAR(16),@pmBeneficiario VARCHAR(150),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCuentaDeb VARCHAR(16)
,@pmTipoAplica CHAR(1),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmVrAbono MONEY,@pmReferencia VARCHAR(50),@pmTipDocRef VARCHAR(3)
,@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmNitOtros VARCHAR(16),@pmCodAgencia VARCHAR(16),@pmDetalles VARCHAR(250),@pmEsCorrecto BIT,@pmEstado INT,@pmTipoEgr VARCHAR(3)
,@pmEgreso INT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogEgresos (IdLog,IdCia,Item,IdCta,IdCuenta,NumCheque,EnEfectivo,VrEgreso,IdTercero,Beneficiario,IdVehiculo,IdCCosto,IdSubCos,IdCuentaDeb,TipoAplica,TipFac,Factura,IdCiaFac
,ItemFac,VrAbono,Referencia,TipDocRef,DocRef,IdCiaRef,NitOtros,CodAgencia,Detalles,EsCorrecto,Estado,TipoEgr,Egreso,TimeSys,IdUsuario,Nombre)
 VALUES (@pmIdLog,@pmIdCia,@pmItem,@pmIdCta,@pmIdCuenta,@pmNumCheque,@pmEnEfectivo,@pmVrEgreso,@pmIdTercero,@pmBeneficiario,@pmIdVehiculo,@pmIdCCosto,@pmIdSubCos,@pmIdCuentaDeb
,@pmTipoAplica,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmVrAbono,@pmReferencia,@pmTipDocRef,@pmDocRef,@pmIdCiaRef,@pmNitOtros,@pmCodAgencia,@pmDetalles,@pmEsCorrecto
,@pmEstado,@pmTipoEgr,@pmEgreso,@pmTimeSys,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogFactAuto @pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmCriterios VARCHAR(100)
,@pmConcepto VARCHAR(100),@pmPlazo VARCHAR(30),@pmVendedor VARCHAR(50),@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY
,@pmVrFletes MONEY,@pmVrNeto MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmObservacion VARCHAR(250)
 AS 
 INSERT INTO LogFactAuto (Numero,IdCia,Fecha,Criterios,Concepto,Plazo,Vendedor,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA
,VrCargos,VrOtrDcto,VrFletes,VrNeto,TimeSys,IdUsuario,Nombre,Observacion)
 VALUES (@pmNumero,@pmIdCia,@pmFecha,@pmCriterios,@pmConcepto,@pmPlazo,@pmVendedor,@pmVrSubTotal,@pmVrDescuento
,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCargos,@pmVrOtrDcto,@pmVrFletes,@pmVrNeto,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmObservacion)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogFactDetalle @pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaVence SMALLDATETIME
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCiudad VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmNomCiaFact VARCHAR(50),@pmNomCliente VARCHAR(150),@pmNomVend VARCHAR(150),@pmNomAgencia VARCHAR(50),@pmDetalles VARCHAR(100)
 AS 
 INSERT INTO LogFactDetalle (Numero,IdCia,Item,TipDoc,Factura,IdCiaFac,FechaVence,IdCliente,IdAgencia,IdVend,TarifaCom,Ciudad,TipCom,Comprobante,IdCiaCom,NomCiaFact,NomCliente,NomVend,NomAgencia,Detalles)
 VALUES (@pmNumero,@pmIdCia,@pmItem,@pmTipDoc,@pmFactura,@pmIdCiaFac,@pmFechaVence,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmTarifaCom,@pmCiudad
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmNomCiaFact,@pmNomCliente,@pmNomVend,@pmNomAgencia,@pmDetalles)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogFecVence @pmIdLog INT,@pmItem INT,@pmFecha SMALLDATETIME,@pmTipDoc VARCHAR(3)
,@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaAnt SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogFecVence (IdLog,Item,Fecha,TipDoc,Factura,IdCiaFac,FechaAnt,FechaVence,IdCliente,IdAgencia,IdVend,IdUsuario,Nombre)
 VALUES (@pmIdLog,@pmItem,@pmFecha,@pmTipDoc,@pmFactura,@pmIdCiaFac,@pmFechaAnt,@pmFechaVence,@pmIdCliente
,@pmIdAgencia,@pmIdVend,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntAhorros @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10),@pmNitPropietario VARCHAR(16)
,@pmNitConductor VARCHAR(16),@pmFecha SMALLDATETIME,@pmDocumento VARCHAR(50),@pmCerrado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO LogIntAhorros (nAnno,nMes,IdCia,IdVehiculo,NitPropietario,NitConductor,Fecha,Documento,Cerrado,TimeSys,IdUsuario)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdVehiculo,@pmNitPropietario,@pmNitConductor,@pmFecha,@pmDocumento,@pmCerrado,@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 paInsLogIntCias @pmTipProc VARCHAR(10),@pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmEstado INT,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
,@pmTimeSys SMALLDATETIME,@pmTipoInt INT,@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmDocumentos VARCHAR(100),@pmComprobantes VARCHAR(100),@pmConsolidado BIT
,@pmSobParam BIT
 AS 
 INSERT INTO LogIntCias (TipProc,Numero,IdCia,Fecha,Estado,IdUsuario,Nombre,TimeSys,TipoInt,FechaInicial,FechaFinal,Documentos,Comprobantes,Consolidado,SobParam)
 VALUES (@pmTipProc,@pmNumero,@pmIdCia,@pmFecha,@pmEstado,@pmIdUsuario,@pmNombre,@pmTimeSys,@pmTipoInt,@pmFechaInicial,@pmFechaFinal,@pmDocumentos,@pmComprobantes,@pmConsolidado,@pmSobParam)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntExporta @pmTipProc VARCHAR(10),@pmNumero INT,@pmNomTabla VARCHAR(20),@pmNumInicial INT,@pmNumFinal INT
,@pmCantidad INT,@pmEstadoDoc INT,@pmObservacion VARCHAR(250)
 AS 
 INSERT INTO LogIntExporta (TipProc,Numero,NomTabla,NumInicial,NumFinal,Cantidad,EstadoDoc,Observacion)
 VALUES (@pmTipProc,@pmNumero,@pmNomTabla,@pmNumInicial,@pmNumFinal,@pmCantidad,@pmEstadoDoc,@pmObservacion)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntImporta @pmTipProc VARCHAR(10),@pmNumero INT,@pmItem INT,@pmTipoReg INT,@pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCiaDoc CHAR(2)
,@pmNomTabla VARCHAR(20),@pmNivelRel INT,@pmEstValida INT,@pmEstadoReg INT,@pmObservacion VARCHAR(250),@pmPkFields VARCHAR(50),@pmPkTypes VARCHAR(50)
,@pmPkValues VARCHAR(100),@pmNuevoId VARCHAR(50),@pmReemplazar BIT
 AS 
 INSERT INTO LogIntImporta (TipProc,Numero,Item,TipoReg,TipDoc,NumDoc,IdCiaDoc,NomTabla,NivelRel,EstValida,EstadoReg,Observacion,PkFields,PkTypes,PkValues,NuevoId,Reemplazar)
 VALUES (@pmTipProc,@pmNumero,@pmItem,@pmTipoReg,@pmTipDoc,@pmNumDoc,@pmIdCiaDoc,@pmNomTabla,@pmNivelRel,@pmEstValida,@pmEstadoReg,@pmObservacion
,@pmPkFields,@pmPkTypes,@pmPkValues,@pmNuevoId,@pmReemplazar)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntMora @pmNumero INT,@pmFecha SMALLDATETIME,@pmIdCia CHAR(2),@pmEstado INT
,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmTipCom VARCHAR(3),@pmNombre VARCHAR(50),@pmNomCnia VARCHAR(50)
 AS 
 INSERT INTO LogIntMora (Numero,Fecha,IdCia,Estado,TimeSys,IdUsuario,TipCom,Nombre,NomCnia)
 VALUES (@pmNumero,@pmFecha,@pmIdCia,@pmEstado,@pmTimeSys,@pmIdUsuario,@pmTipCom,@pmNombre,@pmNomCnia)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntMoraDet @pmNumero INT,@pmItem INT,@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFechaVence SMALLDATETIME,@pmVrFactura MONEY
,@pmVrAbonado MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmFecUltLiq SMALLDATETIME,@pmFecIniLiq SMALLDATETIME,@pmFecFinLiq SMALLDATETIME
,@pmDiasLiquida INT,@pmDiasGracia INT,@pmVrBaseLiq MONEY,@pmTasaIntMora DECIMAL(14,4),@pmVrLiquida MONEY,@pmTarifIva DECIMAL(14,4),@pmVrIvaInt MONEY,@pmNumNota INT
,@pmIdCiaNot CHAR(2),@pmComprobante INT,@pmNomCiaFact VARCHAR(50),@pmNomCliente VARCHAR(150),@pmNomVend VARCHAR(150),@pmNomAgencia VARCHAR(50)
 AS 
 INSERT INTO LogIntMoraDet (Numero,Item,TipDoc,Factura,IdCiaFac,ItemFac,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,FecUltLiq,FecIniLiq,FecFinLiq,DiasLiquida,DiasGracia,VrBaseLiq,TasaIntMora
,VrLiquida,TarifIva,VrIvaInt,NumNota,IdCiaNot,Comprobante,NomCiaFact,NomCliente,NomVend,NomAgencia)
 VALUES (@pmNumero,@pmItem,@pmTipDoc,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFechaVence,@pmVrFactura,@pmVrAbonado,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmFecUltLiq
,@pmFecIniLiq,@pmFecFinLiq,@pmDiasLiquida,@pmDiasGracia,@pmVrBaseLiq,@pmTasaIntMora,@pmVrLiquida,@pmTarifIva,@pmVrIvaInt,@pmNumNota,@pmIdCiaNot,@pmComprobante,@pmNomCiaFact,@pmNomCliente,@pmNomVend,@pmNomAgencia)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntNomina @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10)
,@pmNitPropietario VARCHAR(16),@pmNitConductor VARCHAR(16),@pmFecha SMALLDATETIME,@pmDocumento VARCHAR(50),@pmCerrado BIT,@pmVrTotal MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO LogIntNomina (TipProc,CdNom,IdPeriodo,IdCia,IdVehiculo,NitPropietario,NitConductor,Fecha,Documento,Cerrado,VrTotal,TimeSys,IdUsuario)
 VALUES (@pmTipProc,@pmCdNom,@pmIdPeriodo,@pmIdCia,@pmIdVehiculo,@pmNitPropietario,@pmNitConductor,@pmFecha,@pmDocumento,@pmCerrado,@pmVrTotal,@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 paInsLogIntegra @pmNumero INT,@pmFecha SMALLDATETIME,@pmEstadoLog INT
,@pmComentarios VARCHAR(250),@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogIntegra (Numero,Fecha,EstadoLog,Comentarios,IdUsuario,Nombre)
 VALUES (@pmNumero,@pmFecha,@pmEstadoLog,@pmComentarios,@pmIdUsuario,@pmNombre)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntegraDet @pmNumero INT,@pmItem INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFechaDoc SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmEstado INT,@pmIdTercero VARCHAR(16)
,@pmNomCia VARCHAR(50),@pmNomTercero VARCHAR(150)
 AS 
 INSERT INTO LogIntegraDet (Numero,Item,TipDoc,Documento,IdCia,FechaDoc,TipCom,Comprobante,IdCiaCom,Observacion,Estado,IdTercero,NomCia,NomTercero)
 VALUES (@pmNumero,@pmItem,@pmTipDoc,@pmDocumento,@pmIdCia,@pmFechaDoc,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion
,@pmEstado,@pmIdTercero,@pmNomCia,@pmNomTercero)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogMayLiquida @pmNLiquida INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
,@pmFactura INT,@pmFecVence SMALLDATETIME,@pmModalidad VARCHAR(10),@pmCantidad DECIMAL(14,4),@pmValorTotal MONEY,@pmVrSaldo MONEY,@pmFecPago SMALLDATETIME
,@pmAnulado BIT,@pmNContrato INT,@pmIdCiaCon CHAR(2),@pmIdCliente VARCHAR(16),@pmNomCliente VARCHAR(150),@pmIdAgencia VARCHAR(16),@pmNomAgencia VARCHAR(150)
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogMayLiquida (NLiquida,IdCia,Item,Fecha,TipDoc,Documento,IdCiaDoc,Factura,FecVence,Modalidad,Cantidad,ValorTotal,VrSaldo,FecPago,Anulado,NContrato,IdCiaCon
,IdCliente,NomCliente,IdAgencia,NomAgencia,Observacion,TimeSys,IdUsuario,Nombre)
 VALUES (@pmNLiquida,@pmIdCia,@pmItem,@pmFecha,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmFactura,@pmFecVence,@pmModalidad,@pmCantidad,@pmValorTotal
,@pmVrSaldo,@pmFecPago,@pmAnulado,@pmNContrato,@pmIdCiaCon,@pmIdCliente,@pmNomCliente,@pmIdAgencia,@pmNomAgencia,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogMayoriza @pmAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmEstado INT
,@pmFecha SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmIdCiaCrea CHAR(2)
,@pmCantidad INT,@pmIdCuenta VARCHAR(16)
 AS 
 INSERT INTO LogMayoriza (Anno,nMes,IdCia,Estado,Fecha,IdUsuario,Nombre,IdCiaCrea,Cantidad,IdCuenta)
 VALUES (@pmAnno,@pmnMes,@pmIdCia,@pmEstado,@pmFecha,@pmIdUsuario,@pmNombre,@pmIdCiaCrea,@pmCantidad,@pmIdCuenta)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPrecios @pmIdLog INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipo VARCHAR(10),@pmListas VARCHAR(10),@pmSimbTarif CHAR(1)
,@pmVrTarifa DECIMAL(14,4),@pmBaseTarfa VARCHAR(10),@pmFecProg SMALLDATETIME,@pmIdCiaCie CHAR(2),@pmEstado INT,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME
 AS 
 INSERT INTO LogPrecios (IdLog,IdCia,Fecha,Tipo,Listas,SimbTarif,VrTarifa,BaseTarfa,FecProg,IdCiaCie,Estado,TimeSys,IdUsuario,Nombre,Observacion)
 VALUES (@pmIdLog,@pmIdCia,@pmFecha,@pmTipo,@pmListas,@pmSimbTarif,@pmVrTarifa,@pmBaseTarfa,@pmFecProg,@pmIdCiaCie,@pmEstado
,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmObservacion)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPreciosDet @pmIdLog INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmDescripProd VARCHAR(150),@pmVrCosto MONEY,@pmVrCostPmd MONEY,@pmPrecioAnt1 MONEY,@pmPrecioAnt2 MONEY
,@pmPrecioAnt3 MONEY,@pmPrecioAnt4 MONEY,@pmPrecioAnt5 MONEY,@pmPrecio1 MONEY,@pmPrecio2 MONEY,@pmPrecio3 MONEY,@pmPrecio4 MONEY,@pmPrecio5 MONEY,@pmIvaInc1 BIT,@pmIvaInc2 BIT,@pmIvaInc3 BIT,@pmIvaInc4 BIT
,@pmIvaInc5 BIT,@pmTarifIva DECIMAL(14,4),@pmBaseMgn1 CHAR(1),@pmBaseMgn2 CHAR(1),@pmBaseMgn3 CHAR(1),@pmBaseMgn4 CHAR(1),@pmBaseMgn5 CHAR(1),@pmCdMgn1 VARCHAR(4),@pmCdMgn2 VARCHAR(4),@pmCdMgn3 VARCHAR(4)
,@pmCdMgn4 VARCHAR(4),@pmCdMgn5 VARCHAR(4),@pmTarifMgn1 DECIMAL(14,4),@pmTarifMgn2 DECIMAL(14,4),@pmTarifMgn3 DECIMAL(14,4),@pmTarifMgn4 DECIMAL(14,4),@pmTarifMgn5 DECIMAL(14,4),@pmCdDct1 VARCHAR(4),@pmCdDct2 VARCHAR(4)
,@pmCdDct3 VARCHAR(4),@pmCdDct4 VARCHAR(4),@pmCdDct5 VARCHAR(4),@pmTarifDct1 DECIMAL(14,4),@pmTarifDct2 DECIMAL(14,4),@pmTarifDct3 DECIMAL(14,4),@pmTarifDct4 DECIMAL(14,4),@pmTarifDct5 DECIMAL(14,4)
,@pmCdMon1 VARCHAR(5),@pmCdMon2 VARCHAR(5),@pmCdMon3 VARCHAR(5),@pmCdMon4 VARCHAR(5),@pmCdMon5 VARCHAR(5),@pmIdCiaLta CHAR(2),@pmSobretasa  DECIMAL(14,4), @pmImpGlobal  DECIMAL(14,4), @pmSoldicom  DECIMAL(14,4)
, @pmIvaComb  DECIMAL(14,4), @pmPrecioRef  DECIMAL(14,4), @pmCostoRec  DECIMAL(14,4)
 AS 
 INSERT INTO LogPreciosDet (IdLog,IdCia,Item,IdProducto,DescripProd,VrCosto,VrCostPmd,PrecioAnt1,PrecioAnt2,PrecioAnt3,PrecioAnt4,PrecioAnt5,Precio1,Precio2,Precio3,Precio4,Precio5,IvaInc1,IvaInc2,IvaInc3,IvaInc4,IvaInc5,TarifIva,BaseMgn1,BaseMgn2,BaseMgn3
,BaseMgn4,BaseMgn5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,TarifMgn1,TarifMgn2,TarifMgn3,TarifMgn4,TarifMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,TarifDct1,TarifDct2,TarifDct3,TarifDct4,TarifDct5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,IdCiaLta,Sobretasa, ImpGlobal, Soldicom, IvaComb, PrecioRef, CostoRec)
 VALUES (@pmIdLog,@pmIdCia,@pmItem,@pmIdProducto,@pmDescripProd,@pmVrCosto,@pmVrCostPmd,@pmPrecioAnt1,@pmPrecioAnt2,@pmPrecioAnt3,@pmPrecioAnt4,@pmPrecioAnt5,@pmPrecio1,@pmPrecio2,@pmPrecio3,@pmPrecio4,@pmPrecio5
,@pmIvaInc1,@pmIvaInc2,@pmIvaInc3,@pmIvaInc4,@pmIvaInc5,@pmTarifIva,@pmBaseMgn1,@pmBaseMgn2,@pmBaseMgn3,@pmBaseMgn4,@pmBaseMgn5,@pmCdMgn1,@pmCdMgn2,@pmCdMgn3,@pmCdMgn4,@pmCdMgn5,@pmTarifMgn1,@pmTarifMgn2
,@pmTarifMgn3,@pmTarifMgn4,@pmTarifMgn5,@pmCdDct1,@pmCdDct2,@pmCdDct3,@pmCdDct4,@pmCdDct5,@pmTarifDct1,@pmTarifDct2,@pmTarifDct3,@pmTarifDct4,@pmTarifDct5,@pmCdMon1,@pmCdMon2,@pmCdMon3,@pmCdMon4,@pmCdMon5,@pmIdCiaLta
,@pmSobretasa, @pmImpGlobal, @pmSoldicom, @pmIvaComb, @pmPrecioRef,@pmCostoRec)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPrestFact @pmNumero INT,@pmFecha SMALLDATETIME,@pmTipoProc VARCHAR(10),@pmEstadoProc INT
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogPrestFact (Numero,Fecha,TipoProc,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre)
 VALUES (@pmNumero,@pmFecha,@pmTipoProc,@pmEstadoProc,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPrestFactDet @pmNumero INT,@pmItem INT,@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItemCuo INT,@pmNumCuota INT,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrTotal MONEY
,@pmTasaEfeMes DECIMAL(16,8),@pmTasaEfeDia DECIMAL(16,8),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmConcepto VARCHAR(10),@pmCodLinCred VARCHAR(4),@pmFecInicio SMALLDATETIME
,@pmFecFinal SMALLDATETIME,@pmDiasLiquida DECIMAL(14,4),@pmEstado INT,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmReferencia VARCHAR(50),@pmComentario VARCHAR(250),@pmNomCliente VARCHAR(150)
 AS 
 INSERT INTO LogPrestFactDet (Numero,Item,TipDoc,IdPrestamo,IdCia,ItemCuo,NumCuota,Fecha,FecVence,VrTotal,TasaEfeMes,TasaEfeDia,IdCliente,IdAgencia,IdVend,Concepto,CodLinCred,FecInicio,FecFinal,DiasLiquida,Estado,TipFac,Factura,IdCiaFac,FechaFac,Referencia,Comentario,NomCliente)
 VALUES (@pmNumero,@pmItem,@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItemCuo,@pmNumCuota,@pmFecha,@pmFecVence,@pmVrTotal,@pmTasaEfeMes,@pmTasaEfeDia,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmConcepto,@pmCodLinCred
,@pmFecInicio,@pmFecFinal,@pmDiasLiquida,@pmEstado,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFac,@pmReferencia,@pmComentario,@pmNomCliente)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsLogPro  @pmIdLog INT,@pmIdPro VARCHAR(20),@pmIdCia CHAR(2)
,@pmFecha SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
,@pmNomTabla VARCHAR(20), @pmObservacion VARCHAR(250),@pmnModulo VARCHAR(20),@pmDsname VARCHAR(20)
AS
INSERT INTO LogPro (IdLog,IdPro,IdCia,Fecha,TimeSys,IdUsuario,Nombre,NomTabla,Observacion,nModulo,Dsname)
VALUES (@pmIdLog,@pmIdPro,@pmIdCia,@pmFecha,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmNomTabla,@pmObservacion,@pmnModulo,@pmDsname)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogRecDetalle @pmNumero INT,@pmItem INT,@pmIdCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmTipoDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2),@pmValorRec MONEY,@pmReferencia VARCHAR(50),@pmEstado INT,@pmNumRecibo INT
,@pmIdCiaRec CHAR(2),@pmFechaRec SMALLDATETIME,@pmFechaFact SMALLDATETIME,@pmProcPago INT,@pmMedioPago INT,@pmSecRegistro INT,@pmCodEntidad VARCHAR(10),@pmCodSucursal VARCHAR(10),@pmNumOper VARCHAR(20),@pmNumAutoriza VARCHAR(20),@pmCodServicio VARCHAR(50)
,@pmNumLote VARCHAR(10),@pmDescRegistro VARCHAR(250),@pmComentario VARCHAR(250),@pmIdVend VARCHAR(16),@pmCodTarCom VARCHAR(4),@pmTarifaCom DECIMAL(14,4),@pmCdCiudad VARCHAR(8),@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmNomCliente VARCHAR(150)
 AS 
 INSERT INTO LogRecDetalle (Numero,Item,IdCliente,CdAgencia,TipoDoc,NumDoc,IdCia,ValorRec,Referencia,Estado,NumRecibo,IdCiaRec,FechaRec,FechaFact,ProcPago,MedioPago,SecRegistro,CodEntidad,CodSucursal,NumOper,NumAutoriza,CodServicio
,NumLote,DescRegistro,Comentario,IdVend,CodTarCom,TarifaCom,CdCiudad,VrFactura,VrAbonado,NomCliente)
 VALUES (@pmNumero,@pmItem,@pmIdCliente,@pmCdAgencia,@pmTipoDoc,@pmNumDoc,@pmIdCia,@pmValorRec,@pmReferencia,@pmEstado,@pmNumRecibo,@pmIdCiaRec,@pmFechaRec,@pmFechaFact,@pmProcPago,@pmMedioPago,@pmSecRegistro,@pmCodEntidad
,@pmCodSucursal,@pmNumOper,@pmNumAutoriza,@pmCodServicio,@pmNumLote,@pmDescRegistro,@pmComentario,@pmIdVend,@pmCodTarCom,@pmTarifaCom,@pmCdCiudad, @pmVrFactura,@pmVrAbonado,@pmNomCliente)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogRecaudo @pmNumero INT,@pmNitEmpresa VARCHAR(16),@pmFechaRec SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmHoraCrea VARCHAR(10)
,@pmSecuencia VARCHAR(3),@pmTipoCuenta INT,@pmNumCuenta VARCHAR(20),@pmTotalReg INT,@pmValorTotal MONEY,@pmEstadoProc INT,@pmObservacion VARCHAR(250)
,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmNomArchivo VARCHAR(100),@pmEntidadRec CHAR(2),@pmConvenio VARCHAR(20)
 AS 
 INSERT INTO LogRecaudo (Numero,NitEmpresa,FechaRec,FechaCrea,HoraCrea,Secuencia,TipoCuenta,NumCuenta,TotalReg,ValorTotal,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre,NomArchivo,EntidadRec,Convenio)
 VALUES (@pmNumero,@pmNitEmpresa,@pmFechaRec,@pmFechaCrea,@pmHoraCrea,@pmSecuencia,@pmTipoCuenta,@pmNumCuenta,@pmTotalReg,@pmValorTotal,@pmEstadoProc
,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmNomArchivo,@pmEntidadRec,@pmConvenio)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogReloj @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME,@pmIdConcepto VARCHAR(4)
,@pmCantidad DECIMAL(14,4),@pmHoras VARCHAR(20),@pmNomArchivo VARCHAR(50),@pmTimeSys SMALLDATETIME
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmNomEmpleado VARCHAR(200),@pmEstado INT,@pmObservacion VARCHAR(250)
 AS 
 INSERT INTO LogReloj (IdEmpleado,FechaDia,IdConcepto,Cantidad,Horas,NomArchivo,TimeSys,IdUsuario,Nombre,NomEmpleado,Estado,Observacion)
 VALUES (@pmIdEmpleado,@pmFechaDia,@pmIdConcepto,@pmCantidad,@pmHoras,@pmNomArchivo,@pmTimeSys,@pmIdUsuario
,@pmNombre,@pmNomEmpleado,@pmEstado,@pmObservacion)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogRetiros @pmTipoProc VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogRetiros (TipoProc,Numero,Fecha,Observacion,TimeSys,IdUsuario,Nombre)
 VALUES (@pmTipoProc,@pmNumero,@pmFecha,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogRetirosProd @pmTipoProc VARCHAR(3),@pmNumero INT,@pmItem INT,@pmIdProducto VARCHAR(16)
,@pmDescripcion VARCHAR(150),@pmFecUltCompra SMALLDATETIME,@pmFecUltVenta SMALLDATETIME,@pmEstado INT,@pmCantExist DECIMAL(14,4)
 AS 
 INSERT INTO LogRetirosProd (TipoProc,Numero,Item,IdProducto,Descripcion,FecUltCompra,FecUltVenta,Estado,CantExist)
 VALUES (@pmTipoProc,@pmNumero,@pmItem,@pmIdProducto,@pmDescripcion,@pmFecUltCompra,@pmFecUltVenta,@pmEstado,@pmCantExist)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogSobTasas @pmIdDec VARCHAR(4),@pmIdLog INT,@pmItem INT,@pmnAnno INT,@pmnMes INT,@pmTipoEntidad VARCHAR(10),@pmIdEnterr VARCHAR(8),@pmNomEntidad VARCHAR(50)
,@pmCdProducto VARCHAR(16),@pmDescripProd VARCHAR(150),@pmClaseProd VARCHAR(20),@pmCantVentas DECIMAL(14,4),@pmCantDev DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrTotalVentas MONEY
,@pmVrTotalDev MONEY,@pmTarifa DECIMAL(14,4),@pmVrSobVentas MONEY,@pmVrSobDev MONEY,@pmVrPrecio MONEY,@pmFormaPago VARCHAR(10),@pmCdClase VARCHAR(4)
,@pmNomClase VARCHAR(50),@pmNumCuenta VARCHAR(30),@pmCdBanco VARCHAR(4),@pmNomBanco VARCHAR(50),@pmVrPagado MONEY,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmEstado INT,@pmEsCorrecto BIT,@pmTarifGalon DECIMAL(14,4),@pmPorcBase DECIMAL(14,4)
 AS 
 INSERT INTO LogSobTasas (IdDec,IdLog,Item,nAnno,nMes,TipoEntidad,IdEnterr,NomEntidad,CdProducto,DescripProd,ClaseProd,CantVentas,CantDev,VrUnitario,VrTotalVentas,VrTotalDev,Tarifa,VrSobVentas,VrSobDev,VrPrecio
,FormaPago,CdClase,NomClase,NumCuenta,CdBanco,NomBanco,VrPagado,Observacion,TimeSys,IdUsuario,Nombre,Estado,EsCorrecto,TarifGalon,PorcBase)
 VALUES (@pmIdDec,@pmIdLog,@pmItem,@pmnAnno,@pmnMes,@pmTipoEntidad,@pmIdEnterr,@pmNomEntidad,@pmCdProducto,@pmDescripProd,@pmClaseProd,@pmCantVentas,@pmCantDev,@pmVrUnitario
,@pmVrTotalVentas,@pmVrTotalDev,@pmTarifa,@pmVrSobVentas,@pmVrSobDev,@pmVrPrecio,@pmFormaPago,@pmCdClase,@pmNomClase,@pmNumCuenta,@pmCdBanco,@pmNomBanco
,@pmVrPagado,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmEstado,@pmEsCorrecto,@pmTarifGalon,@pmPorcBase)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsLogSys @pmIdLog INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmFecha SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
,@pmObservacion VARCHAR(250),@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmEsCom BIT,@pmEliminado BIT,@pmModificado BIT
,@pmnModulo VARCHAR(20),@pmDsname VARCHAR(20)
AS
 INSERT INTO logSys (IdLog,TipDoc,Documento,IdCia,Fecha,TimeSys,IdUsuario,Nombre,Observacion,IdTercero,IdVehiculo,EsCom,Eliminado,Modificado,nModulo,Dsname)
 VALUES (@pmIdLog,@pmTipDoc,@pmDocumento,@pmIdCia,@pmFecha,@pmTimeSys,@pmIdUsuario,@pmNombre
,@pmObservacion,@pmIdTercero,@pmIdVehiculo,@pmEsCom,@pmEliminado,@pmModificado,@pmnModulo,@pmDsname)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogTmsAju @pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumDocAjs INT,@pmNumDocAjf INT
,@pmEstadoProc INT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogTmsAju (Numero,IdCia,Fecha,NumDocAjs,NumDocAjf,EstadoProc,TimeSys,IdUsuario,Nombre)
 VALUES (@pmNumero,@pmIdCia,@pmFecha,@pmNumDocAjs,@pmNumDocAjf,@pmEstadoProc,@pmTimeSys,@pmIdUsuario,@pmNombre)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogTmsAjuProd @pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmDescripProd VARCHAR(150),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2)
,@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmCdTanque VARCHAR(4),@pmCantFact DECIMAL(14,4),@pmCantGuia DECIMAL(14,4),@pmgalsbruto DECIMAL(14,4),@pmgalsneto DECIMAL(14,4),@pmTemperatura DECIMAL(14,4)
,@pmDensidad DECIMAL(14,4),@pmReferencia VARCHAR(50),@pmObservacion VARCHAR(250),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16)
 AS 
 INSERT INTO LogTmsAjuProd (Numero,IdCia,Item,IdProducto,DescripProd,TipFac,Factura,IdCiaFac,NumGuia,IdCiaGuia,CdTanque,CantFact,CantGuia,galsbruto,galsneto,Temperatura,Densidad,Referencia,Observacion,NitCliente,CdAgencia)
 VALUES (@pmNumero,@pmIdCia,@pmItem,@pmIdProducto,@pmDescripProd,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmNumGuia,@pmIdCiaGuia,@pmCdTanque,@pmCantFact,@pmCantGuia,@pmgalsbruto,@pmgalsneto
,@pmTemperatura,@pmDensidad,@pmReferencia,@pmObservacion,@pmNitCliente,@pmCdAgencia)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogTraTarifas @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4)
,@pmVolumen DECIMAL(14,4),@pmCases INT,@pmCajas INT,@pmPalets INT,@pmTarifClie MONEY,@pmTarifPago MONEY,@pmTarifTabla MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmTarifSeguro DECIMAL(14,4),@pmUndTarifa VARCHAR(10)
,@pmTipoTarifa VARCHAR(10),@pmUndTarPago VARCHAR(10),@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogTraTarifas (TipDoc,Numero,IdCia,Item,Fecha,IdMercancia,DescripMcias,Cantidad,PesoNeto,Volumen,Cases,Cajas,Palets,TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,UndTarifa,UndTarPago,TipoTarifa,IdUsuario,Nombre)
 VALUES (@pmTipDoc,@pmNumero,@pmIdCia,@pmItem,@pmFecha,@pmIdMercancia,@pmDescripMcias,@pmCantidad,@pmPesoNeto,@pmVolumen,@pmCases,@pmCajas,@pmPalets,@pmTarifClie,@pmTarifPago,@pmTarifTabla,@pmVrDeclarado
,@pmVrSeguro,@pmTarifSeguro,@pmUndTarifa,@pmUndTarPago,@pmTipoTarifa,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE  paInsLoginout  @pmIdLog INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11), @pmFecha SMALLDATETIME, @pmHoraEntrada SMALLDATETIME
,@pmFinalizo BIT,@pmNombre VARCHAR(50),@pmDsname VARCHAR(20)
AS 
 INSERT INTO LogInOut ( IdLog, IdCia, IdUsuario, Fecha, HoraEntrada,Finalizo,Nombre,Dsname)
 VALUES (@pmIdLog, @pmIdCia, @pmIdUsuario, @pmFecha, @pmHoraEntrada,@pmFinalizo,@pmNombre,@pmDsname)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogAfijosDet @pmTipoDoc VARCHAR(3),@pmNumero INT,@pmItem INT
 AS 
 SELECT TipoDoc,Numero,Item,IdActivo,NomActivo,Tipo,NumSerie,CodInvent,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdTipDif,IdProv,FecCompra,FecActivacion,NumOrden
,IdCiaOrden,NumEntrada,IdCiaEnt,VrBaseDep,VidaUtil,MetodoDep,Ajustable,Contable,CueEnGrupo,NumPlaca,NumDoc,Referencia,Marca,IdCuenta,IdCueDep,IdCueGasto,IdCueAjuste
,IdCueCorr,IdEstado,ItemDoc,Transaccion,TipoValoriza,Observaciones,TipoAmtza,NitCliente,AgenCliente,CantGalones,VrMejoras,VrDisminuc
 FROM LogAfijosDet
 WHERE TipoDoc=@pmTipoDoc 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 paQryLogBusesAhorro @pmnAnno INT,@pmnMes INT
 AS 
 SELECT nAnno,nMes,Calculado,Observacion
 FROM LogBusesAhorro
 WHERE 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 paQryLogBusesCias @pmIdCia CHAR(2),@pmFecha SMALLDATETIME
AS
 SELECT     IdCia, Fecha, Exportado, Importado  
 FROM  LogBusesCias
 WHERE  IdCia=@pmIdCia  AND Fecha=@pmFecha
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogBusesNomina @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8)
 AS 
 SELECT TipProc,CdNom,IdPeriodo,Fecha,Cerrado,Observacion,TimeSys,IdUsuario
 FROM LogBusesNomina
 WHERE TipProc=@pmTipProc AND CdNom=@pmCdNom 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 paQryLogBusesRecFmt @pmTipoProc VARCHAR(3),@pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT L.Numero AS NumProceso,NomArchivo,L.FechaRec AS FecRecaudo,FechaCrea,CantReg,CantRegErr,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre
--detalles
,Item,IdVehiculo,NumVeh,IdPropietario,NomProp,IdCond,NomCond,VehEsPropio,VrSaldoAnt,ValorRec,VrDescuento
,Estado,NumRecibo,IdCiaRec,D.FechaRec AS FecPago,NumCuenta,Referencia,CodSucursal,DescRegistro,Comentario
 FROM LogBusesRec AS L LEFT JOIN LogBusesRecDet AS D  ON L.TipoProc=D.TipoProc AND L.Numero=D.Numero
 WHERE L.TipoProc=@pmTipoProc AND L.Numero BETWEEN  ISNULL(@pmNumeroIni,0) AND ISNULL(@pmNumeroFin,2147483647)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogCierres @pmProceso VARCHAR(10),@pmAnno INT,@pmnMes INT,@pmnDia INT,@pmIdCia CHAR(2)
 AS 
 SELECT Proceso,Anno,nMes,nDia,IdCia,Estado,Fecha,IdUsuario,Nombre,Cuenta,ProcessExt1,ProcessExt2,ProcessExt3,ProcessExt4,ProcessExt5
 FROM LogCierres
 WHERE Proceso=@pmProceso AND Anno=@pmAnno AND nMes=@pmnMes AND nDia=@pmnDia 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 paQryLogCierresLta @pmProceso VARCHAR(10),@pmAnno INT=Null,@pmnMes INT=Null
,@pmnDiaIni INT=Null,@pmnDiaFin INT=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT IdCia,Anno,nMes,nDia,Fecha,Estado,IdUsuario,Nombre,Cuenta
,ProcessExt1,ProcessExt2,ProcessExt3,ProcessExt4,ProcessExt5
 FROM LogCierres
 WHERE Proceso=@pmProceso 
 AND (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 AND nDia BETWEEN ISNULL(@pmnDiaIni,0) AND ISNULL(@pmnDiaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,Anno,nMes,nDia
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogCierresMes @pmProceso VARCHAR(10)=Null,@pmAnno INT=Null,@pmnMes INT=Null
,@pmIdCia CHAR(2)=Null
 AS 
 SELECT IdCia,Anno,nMes,Fecha,Estado,IdUsuario,Nombre,Cuenta
--,ProcessExt1,ProcessExt2,ProcessExt3,ProcessExt4,ProcessExt5
 FROM LogCierres
 WHERE Proceso<>'CIERREDIA' AND Proceso LIKE ISNULL(@pmProceso,'%')
 AND (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,Anno,nMes,nDia
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogCortesFor @pmIdCia CHAR(2),@pmArchivo2  VARCHAR(50)
 AS 
 SELECT Fecha,NumCorte,Planilla,IdCiaPla,FecPlanilla
 FROM LogCortes
 WHERE Planilla>0 AND  IdCia=@pmIdCia AND Archivo2=@pmArchivo2
 ORDER BY FecPlanilla
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogCortesId @pmIdCia CHAR(2)
 AS 
 SELECT MAX(IdLog) AS MXITM
 FROM LogCortes
 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 paQryLogCortesLec @pmIdCia CHAR(2),@pmArchivo1 VARCHAR(50)
 AS 
 SELECT Fecha,NumCorte,Planilla,IdCiaPla,FecPlanilla
 FROM LogCortes
 WHERE Planilla>0 AND  IdCia=@pmIdCia AND Archivo1=@pmArchivo1
 ORDER BY FecPlanilla
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogCortesNum @pmIdCia CHAR(2),@pmFecha SMALLDATETIME
 AS 
 SELECT MAX(NumCorte) AS MXITM
 FROM LogCortes
 WHERE IdCia=@pmIdCia AND Fecha=@pmFecha AND Planilla>0
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogEgresos @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdTercero,Beneficiario,Item,IdCta,IdCuenta,NumCheque,EnEfectivo,VrEgreso
,IdCuentaDeb,TipFac,Factura,IdCiaFac,ItemFac,VrAbono,TipoAplica,Referencia,Detalles
,IdVehiculo,IdCCosto,IdSubCos,TipDocRef,DocRef,IdCiaRef,EsCorrecto,Estado
,TipoEgr,Egreso,TimeSys,IdUsuario,Nombre,IdLog,IdCia
 FROM LogEgresos
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia
 ORDER BY Beneficiario,IdTercero,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogEgresosAbi @pmIdCia CHAR(2)
 AS 
 SELECT MAX(IdLog) AS MXNUM 
 FROM LogEgresos
 WHERE IdCia=@pmIdCia AND Estado<=0
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogEgresosEst @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,IdCta,IdCuenta,NumCheque,EnEfectivo,VrEgreso,IdTercero,Beneficiario,IdVehiculo
,IdCCosto,IdSubCos,IdCuentaDeb,TipoAplica,TipFac,Factura,IdCiaFac,ItemFac,VrAbono
,Referencia,TipDocRef,DocRef,IdCiaRef,NitOtros,CodAgencia,Detalles,EsCorrecto
 FROM LogEgresos
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia AND  Estado<1 AND EsCorrecto<>0
 ORDER BY IdTercero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogEgresosId @pmIdCia CHAR(2)
 AS 
 SELECT MAX(IdLog) AS MXLOG
 FROM LogEgresos
 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 paQryLogEgresosTabo @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdTercero,SUM(VrAbono) AS STOTABO
 FROM LogEgresos
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia
 GROUP BY IdTercero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogEgresosVce @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdTercero,Beneficiario,IdCuentaDeb,TipFac,Factura,IdCiaFac,ItemFac,VrAbono
 FROM LogEgresos
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia AND  Estado<1 AND EsCorrecto<>0
 AND TipoAplica='A'
 ORDER BY IdTercero,Factura
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogFactAuto @pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT Numero,IdCia,Fecha,Criterios,Concepto,Plazo,Vendedor,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrFletes,VrNeto,TimeSys,IdUsuario,Nombre,Observacion
 FROM LogFactAuto
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryLogInOut @pmIdUsuario VARCHAR(11),@pmIdCia CHAR(2),@pmFinalizo BIT
AS
SELECT IdLog, IdCia, IdUsuario, Fecha, HoraEntrada, HoraSalida,Finalizo , Nombre,Dsname
FROM LogInOut 
WHERE IdUsuario=@pmIdUsuario AND IdCia=@pmIdCia AND Finalizo=@pmFinalizo
ORDER BY  IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryLogInOutMax @pmIdUsuario VARCHAR(11),@pmIdCia CHAR(2)
AS
SELECT MAX(IdLog) AS MXLOG FROM LogInOut WHERE IdUsuario=@pmIdUsuario 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 paQryLogInOut_Cr @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdUsuario VARCHAR(11)=Null,@pmIdCia CHAR(2)=Null
,@pmFinalizo BIT=Null,@pmPorHe BIT=Null,@pmDsname VARCHAR(20)=Null
AS
 IF @pmPorHe>0
  SELECT IdUsuario,Nombre,IdLog,IdCia,Fecha,HoraEntrada,HoraSalida,Finalizo,Dsname
  FROM LogInOut 
  WHERE HoraEntrada  BETWEEN @pmFechaIni AND @pmFechaFin AND  IdUsuario like ISNULL(@pmIdUsuario,'%')
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND Dsname LIKE ISNULL(@pmDsname,'%')
  AND  (Finalizo=ISNULL(@pmFinalizo,0) or Finalizo=ISNULL(@pmFinalizo,1))
  ORDER BY IdUsuario, HoraEntrada, IdCia
 ELSE
  SELECT IdUsuario,Nombre,IdLog,IdCia,Fecha,HoraEntrada,HoraSalida,Finalizo,Dsname
  FROM LogInOut 
  WHERE Fecha  BETWEEN @pmFechaIni AND @pmFechaFin AND  IdUsuario like ISNULL(@pmIdUsuario,'%')
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND Dsname LIKE ISNULL(@pmDsname,'%')
  AND  (Finalizo=ISNULL(@pmFinalizo,0) or Finalizo=ISNULL(@pmFinalizo,1))
  ORDER BY IdUsuario, HoraEntrada, IdCia
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogIntAhorros @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10)
 AS 
 SELECT nAnno,nMes,IdCia,IdVehiculo,NitPropietario,NitConductor,Fecha,Documento,Cerrado,TimeSys,IdUsuario
 FROM LogIntAhorros
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND 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 paQryLogIntMora @pmNumero INT
 AS 
 SELECT Numero,Fecha,IdCia,Estado,TimeSys,IdUsuario,TipCom,Nombre,NomCnia
 FROM LogIntMora
 WHERE 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 paQryLogIntMoraDet @pmNumero INT
 AS 
 SELECT Numero,Item,TipDoc,Factura,IdCiaFac,ItemFac,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia
,IdVend,FecUltLiq,FecIniLiq,FecFinLiq,DiasLiquida,DiasGracia,VrBaseLiq,TasaIntMora,VrLiquida,TarifIva
,VrIvaInt,NumNota,IdCiaNot,Comprobante,NomCiaFact,NomCliente,NomVend,NomAgencia
 FROM LogIntMoraDet
 WHERE Numero=@pmNumero
 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 paQryLogIntNomina @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10)
 AS 
 SELECT TipProc,CdNom,IdPeriodo,IdCia,IdVehiculo,NitPropietario,NitConductor,Fecha,Documento,Cerrado,VrTotal,TimeSys,IdUsuario
 FROM LogIntNomina
 WHERE TipProc=@pmTipProc AND CdNom=@pmCdNom AND IdPeriodo=@pmIdPeriodo AND IdCia=@pmIdCia AND IdVehiculo=@pmIdVehiculo

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogMayLiquida @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,Fecha,TipDoc,Documento,IdCiaDoc,Factura,FecVence,Modalidad,Cantidad,ValorTotal,VrSaldo,FecPago,Anulado,NContrato,IdCiaCon
,IdCliente,NomCliente,IdAgencia,NomAgencia,Observacion,TimeSys,IdUsuario,Nombre,NLiquida,IdCia
 FROM LogMayLiquida
 WHERE NLiquida=@pmNLiquida 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 paQryLogMayoriza @pmAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
 AS 
 SELECT Anno,nMes,IdCia,Estado,Fecha,IdUsuario,Nombre,IdCiaCrea,Cantidad,IdCuenta
 FROM LogMayoriza
 WHERE Anno=@pmAnno AND nMes=@pmnMes 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 paQryLogMayorizaLta @pmAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdCia,Anno,nMes,Fecha,Estado,IdUsuario,Nombre,Cantidad,IdCiaCrea,IdCuenta
 FROM LogMayoriza
 WHERE (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,Anno,nMes
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPrecios @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdLog,IdCia,Fecha,Tipo,Listas,SimbTarif,VrTarifa,BaseTarfa,FecProg,IdCiaCie,Estado
,TimeSys,FecUpdate,IdUsuario,Nombre,Observacion
 FROM LogPrecios
 WHERE IdLog=@pmIdLog 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 paQryLogPreciosCie @pmFecProg SMALLDATETIME,@pmIdCiaCie CHAR(2)
 AS 
 SELECT LP.IdLog AS NumLog,LP.IdCia AS CdCia,Fecha,Listas,SimbTarif,VrTarifa,BaseTarfa,FecProg,IdCiaCie,Estado
,Item,IdProducto,DescripProd,VrCosto,VrCostPmd,PrecioAnt1,PrecioAnt2,PrecioAnt3
,PrecioAnt4,PrecioAnt5,Precio1,Precio2,Precio3,Precio4,Precio5,IvaInc1,IvaInc2,IvaInc3,IvaInc4,IvaInc5
,TarifIva,BaseMgn1,BaseMgn2,BaseMgn3,BaseMgn4,BaseMgn5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5
,TarifMgn1,TarifMgn2,TarifMgn3,TarifMgn4,TarifMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,TarifDct1,TarifDct2,TarifDct3,TarifDct4,TarifDct5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,IdCiaLta
 FROM LogPrecios AS LP INNER JOIN  LogPreciosDet AS LD ON LP.IdLog=LD.IdLog AND LP.IdCia=LD.IdCia
 WHERE  Tipo='PROGRAMADO' AND FecProg=@pmFecProg AND Estado=0
 AND (IdCiaCie=@pmIdCiaCie OR IdCiaCie=' ' OR IdCiaCie='00' OR IdCiaCie IS NULL)
 ORDER BY LP.IdCia,LP.IdLog,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPreciosDet @pmIdLog INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT IdLog,IdCia,Item,IdProducto,DescripProd,VrCosto,VrCostPmd,PrecioAnt1,PrecioAnt2,PrecioAnt3
,PrecioAnt4,PrecioAnt5,Precio1,Precio2,Precio3,Precio4,Precio5,IvaInc1,IvaInc2,IvaInc3,IvaInc4,IvaInc5
,TarifIva,BaseMgn1,BaseMgn2,BaseMgn3,BaseMgn4,BaseMgn5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5
,TarifMgn1,TarifMgn2,TarifMgn3,TarifMgn4,TarifMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,TarifDct1,TarifDct2,TarifDct3,TarifDct4,TarifDct5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,IdCiaLta,Sobretasa, ImpGlobal, Soldicom, IvaComb, PrecioRef, CostoRec
 FROM LogPreciosDet
 WHERE IdLog=@pmIdLog 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 paQryLogPreciosDetCod @pmIdLog INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16),@pmIdCiaLta CHAR(2),@pmItem INT
 AS 
 SELECT COUNT(Item) AS CANT
 FROM LogPreciosDet
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia AND IdProducto=@pmIdProducto
 AND IdCiaLta=@pmIdCiaLta
 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 paQryLogPreciosDetDso @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,IdProducto,DescripProd,IdCiaLta,TarifIva
,PrecioAnt1,Precio1,CdMgn1,TarifMgn1,BaseMgn1,CdDct1,TarifDct1,CdMon1,IvaInc1
,PrecioAnt2,Precio2,CdMgn2,TarifMgn2,BaseMgn2,CdDct2,TarifDct2,CdMon2,IvaInc2
,PrecioAnt3,Precio3,CdMgn3,TarifMgn3,BaseMgn3,CdDct3,TarifDct3,CdMon3,IvaInc3
,PrecioAnt4,Precio4,CdMgn4,TarifMgn4,BaseMgn4,CdDct4,TarifDct4,CdMon4,IvaInc4
,PrecioAnt5,Precio5,CdMgn5,TarifMgn5,BaseMgn5,CdDct5,TarifDct5,CdMon5,IvaInc5
,VrCosto,VrCostPmd,Sobretasa,ImpGlobal,Soldicom,IvaComb,PrecioRef,CostoRec
 FROM LogPreciosDet
 WHERE IdLog=@pmIdLog 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 paQryLogPreciosDetItm @pmIdLog INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM LogPreciosDet
 WHERE IdLog=@pmIdLog 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 paQryLogPreciosDetLta @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmTipo VARCHAR(10)=Null,@pmEstado INT=Null,@pmIdLogIni INT=Null,@pmIdLogFin INT=Null
 AS 
 SELECT L.IdLog AS Id_log,L.IdCia AS CdCia,Fecha,Tipo,Listas,SimbTarif,VrTarifa,BaseTarfa,FecProg,IdCiaCie,Estado,IdUsuario,Nombre,Observacion
--Detalle de actualización
,Item,IdProducto,DescripProd,VrCosto,VrCostPmd,PrecioAnt1,PrecioAnt2,PrecioAnt3
,PrecioAnt4,PrecioAnt5,Precio1,Precio2,Precio3,Precio4,Precio5,IvaInc1,IvaInc2,IvaInc3,IvaInc4,IvaInc5
,TarifIva,BaseMgn1,BaseMgn2,BaseMgn3,BaseMgn4,BaseMgn5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5
,TarifMgn1,TarifMgn2,TarifMgn3,TarifMgn4,TarifMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,TarifDct1,TarifDct2,TarifDct3,TarifDct4,TarifDct5
,IdCiaLta,TimeSys,FecUpdate,Sobretasa, ImpGlobal, Soldicom, IvaComb, PrecioRef,CostoRec --CdMon1,CdMon2,CdMon3,CdMon4,CdMon5
 FROM LogPrecios AS L INNER JOIN LogPreciosDet AS D ON L.IdLog=D.IdLog AND L.IdCia=D.IdCia
 WHERE Fecha BETWEEN @pmFechaIni  AND @pmFechaFin AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND Tipo LIKE ISNULL(@pmTipo,'%')  
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647))
 AND L.IdLog BETWEEN  ISNULL(@pmIdLogIni,0)  AND ISNULL(@pmIdLogFin,2147483647)
 ORDER BY L.IdCia,L.IdLog,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPreciosId @pmIdCia CHAR(2)
 AS 
 SELECT MAX(IdLog) AS MXITM
 FROM LogPrecios
 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 paQryLogPreciosLta @pmTipo VARCHAR(10)=Null,@pmIdCia CHAR(2)=Null
,@pmEstado INT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT IdLog,IdCia,Fecha,Tipo,Listas,SimbTarif,VrTarifa,BaseTarfa,FecProg,IdCiaCie,Estado
,TimeSys,FecUpdate,IdUsuario,Nombre,Observacion
 FROM LogPrecios
 WHERE Tipo LIKE ISNULL(@pmTipo,'%')  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY IdCia,IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPreciosUlt @pmIdCia CHAR(2)
 AS 
 SELECT IdLog,IdCia,Fecha,Tipo,Estado
 FROM LogPrecios
 WHERE IdCia=@pmIdCia AND Estado=0
 ORDER BY IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPrestFactFmt @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT L.Numero AS NumReg,L.Fecha AS FecProc,TipoProc,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre
,Item,TipDoc,IdPrestamo,IdCia,ItemCuo,NumCuota,D.Fecha AS FecCausac,FecVence,VrTotal,TasaEfeMes,TasaEfeDia,IdCliente,IdAgencia,IdVend,Concepto,CodLinCred
,FecInicio,FecFinal,DiasLiquida,Estado,TipFac,Factura,IdCiaFac,FechaFac,Referencia,Comentario,NomCliente
 FROM LogPrestFact AS L LEFT JOIN LogPrestFactDet AS D ON L.Numero=D.Numero
 WHERE L.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPrestRecFmt @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT  R.Numero AS NumReg,Fecha,FechaArc,EstadoProc,Observacion,NomArchivo,TimeSys,IdUsuario,Nombre
,Item,FechaLiq,IdCliente,NomCliente,ValorRec,TipoPrest,Referencia,Estado,NumRecibo,IdCiaRec,FechaRec
,DescRegistro,Comentario 
 FROM   LogPrestRec AS R LEFT JOIN LogPrestRecDet AS D ON R.Numero=D.Numero
 WHERE R.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
 ORDER BY R.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 paQryLogProGTab
AS
  SELECT NomTabla,count(IdLog) AS Cuenta
  FROM LogPro
  GROUP BY NomTabla
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogProGpro 
AS
  SELECT IdPro,count(IdLog) AS Cuenta
  FROM LogPro
  GROUP BY IdPro
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogProLog @pmIdPro VARCHAR(20),@pmFecha SMALLDATETIME,@pmNomTabla VARCHAR(20)=Null,@pmIdCia CHAR(2)=Null
AS
 SELECT IdUsuario, Nombre, IdCia, IdLog,TimeSys,IdPro,NomTabla,Observacion,Fecha,nModulo,Dsname
 FROM LogPro
 WHERE  IdPro=@pmIdPro AND Fecha=@pmFecha AND NomTabla LIKE ISNULL(@pmNomTabla,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY Fecha,IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryLogProMax @pmIdPro VARCHAR(20),@pmIdCia CHAR(2)
AS
SELECT MAX(IdLog) AS MXLOG FROM LogPro WHERE IdPro=@pmIdPro 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 paQryLogProRec @pmIdPro VARCHAR(20),@pmNomTabla VARCHAR(20)
,@pmObservacion VARCHAR(250)
AS
 SELECT IdUsuario, Nombre, IdCia, IdLog,TimeSys,IdPro,NomTabla,Observacion,Fecha
 FROM LogPro
 WHERE  IdPro=@pmIdPro AND NomTabla=@pmNomTabla AND Observacion LIKE @pmObservacion+'%'
 ORDER BY Fecha,IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPro_Cr @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME, @pmIdUsuario VARCHAR(11)=Null
,@pmIdCia CHAR(2)=Null,@pmIdPro VARCHAR(20)=Null,@pmNomTabla VARCHAR(20)=Null,@pmnModulo VARCHAR(20)=Null,@pmPorTime BIT=Null
,@pmDsname VARCHAR(20)=Null
AS
 IF @pmPorTime>0 
  SELECT IdUsuario, Nombre, IdCia, IdLog,TimeSys,IdPro,NomTabla,Observacion,Fecha,nModulo,Dsname
  FROM LogPro
  WHERE TimeSys  BETWEEN @pmFechaIni AND @pmFechaFin AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdPro LIKE ISNULL(@pmIdPro,'%') AND NomTabla LIKE ISNULL(@pmNomTabla,'%')
 AND nModulo LIKE ISNULL(@pmnModulo,'%') AND Dsname LIKE ISNULL(@pmDsname,'%')
  ORDER BY IdUsuario, TimeSys, IdCia, IdPro, IdLog
 ELSE
  SELECT IdUsuario, Nombre, IdCia, IdLog,TimeSys,IdPro,NomTabla,Observacion,Fecha,nModulo,Dsname
  FROM LogPro
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdPro LIKE ISNULL(@pmIdPro,'%') AND NomTabla LIKE ISNULL(@pmNomTabla,'%')
 AND nModulo LIKE ISNULL(@pmnModulo,'%') AND Dsname LIKE ISNULL(@pmDsname,'%')
  ORDER BY IdUsuario, TimeSys, IdCia, IdPro, IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogRecDetalle @pmNumero INT 
 AS 
 SELECT Numero,Item,IdCliente,CdAgencia,TipoDoc,NumDoc,IdCia,ValorRec,Referencia,Estado,NumRecibo,IdCiaRec,FechaRec
,FechaFact,ProcPago,MedioPago,SecRegistro,CodEntidad,CodSucursal,NumOper,NumAutoriza,CodServicio,NumLote,DescRegistro
,Comentario,IdVend,CodTarCom,TarifaCom,CdCiudad,VrFactura,VrAbonado,NomCliente
 FROM LogRecDetalle
 WHERE 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 paQryLogRecaudo @pmNumero INT
 AS 
 SELECT Numero,NitEmpresa,FechaRec,FechaCrea,HoraCrea,Secuencia,TipoCuenta,NumCuenta,TotalReg
,ValorTotal,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre,NomArchivo,EntidadRec,Convenio
 FROM LogRecaudo
 WHERE 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 paQryLogRecaudoFmt @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT R.Numero AS NumeroReg,NitEmpresa,R.FechaRec AS FecRecaudo,FechaCrea,HoraCrea,Secuencia,TipoCuenta,NumCuenta,TotalReg
,ValorTotal,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre,NomArchivo,EntidadRec,Convenio
--detalles
,Item,IdCliente,CdAgencia,TipoDoc,NumDoc,IdCia,ValorRec,Referencia,Estado,NumRecibo,IdCiaRec,D.FechaRec AS FecRecibo
,FechaFact,ProcPago,MedioPago,SecRegistro,CodEntidad,CodSucursal,NumOper,NumAutoriza,CodServicio,NumLote,DescRegistro
,Comentario,IdVend,CodTarCom,TarifaCom,CdCiudad,VrFactura,VrAbonado,NomCliente
 FROM LogRecaudo AS R LEFT JOIN LogRecDetalle AS D ON R.Numero=D.Numero
 WHERE R.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
 ORDER BY R.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 paQryLogReloj @pmIdEmpleado VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmEstado INT=Null
 AS 
 SELECT IdEmpleado,NomEmpleado,FechaDia,IdConcepto,Cantidad,Horas,Estado,Observacion,NomArchivo,TimeSys,IdUsuario,Nombre
 FROM LogReloj
 WHERE IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (FechaDia>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FechaDia<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647))
 ORDER BY NomEmpleado,FechaDia,IdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogRelojDia @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME
 AS 
 SELECT IdEmpleado,FechaDia,NomArchivo,NomEmpleado,Estado
 FROM LogReloj
 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 paQryLogRetiros @pmTipoProc VARCHAR(3),@pmNumero INT
 AS 
 SELECT TipoProc,Numero,Fecha,Observacion,TimeSys,IdUsuario,Nombre
 FROM LogRetiros
 WHERE TipoProc=@pmTipoProc 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 paQryLogSobTasas @pmIdDec VARCHAR(4),@pmIdLog INT
 AS 
 SELECT IdDec,IdLog,Item,nAnno,nMes,TipoEntidad,IdEnterr,NomEntidad
,CdProducto,DescripProd,ClaseProd,CantVentas,CantDev,VrUnitario,VrTotalVentas
,VrTotalDev,Tarifa,VrSobVentas,VrSobDev,VrPrecio,FormaPago,CdClase,NomClase
,NumCuenta,CdBanco,NomBanco,VrPagado,Observacion,TarifGalon,PorcBase
 FROM LogSobTasas
 WHERE IdDec=@pmIdDec AND IdLog=@pmIdLog
 AND Estado<=0 AND EsCorrecto<>0
 ORDER BY TipoEntidad,IdEnterr,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogSobTasasAbi @pmIdDec VARCHAR(4)
 AS 
 SELECT  MAX(IdLog)  AS SCANT
 FROM LogSobTasas
 WHERE IdDec=@pmIdDec  AND Estado<=0
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogSobTasasEnt @pmIdDec VARCHAR(4),@pmIdLog INT
 AS 
 SELECT TipoEntidad,IdEnterr,NomEntidad,COUNT(Item) AS SCANT
 FROM LogSobTasas
 WHERE IdDec=@pmIdDec AND IdLog=@pmIdLog  AND Estado<=0 AND EsCorrecto<>0
 GROUP BY TipoEntidad,IdEnterr,NomEntidad

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogSobTasasId @pmIdDec VARCHAR(4)
 AS 
 SELECT MAX(IdLog) AS MXITM
 FROM LogSobTasas
 WHERE IdDec=@pmIdDec
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogSobTasasLta @pmIdDec VARCHAR(4),@pmIdLog INT
 AS 
 SELECT Item,IdEnterr,NomEntidad,ClaseProd,CdProducto,DescripProd,CantVentas,CantDev,CantVentas-CantDev AS CantNeto,VrPrecio,PorcBase
,CASE WHEN PorcBase>0 AND PorcBase<100 THEN (((CantVentas-CantDev)*VrPrecio)*PorcBase)/100   ELSE (CantVentas-CantDev)*VrPrecio END AS BaseSobTasa
,Tarifa,CASE WHEN PorcBase>0 AND PorcBase<100 THEN  (((((CantVentas-CantDev)*VrPrecio)*PorcBase)/100)*Tarifa)/100 ELSE (((CantVentas-CantDev)*VrPrecio)*Tarifa)/100 END AS TotalSobretasa
,VrTotalVentas,VrTotalDev,VrTotalVentas-VrTotalDev AS VentasNeto,TarifGalon,VrSobVentas,VrSobDev,VrSobVentas-VrSobDev AS SobtasaVentas
,VrUnitario,TipoEntidad,nAnno,nMes,FormaPago,CdClase,NomClase,NumCuenta,CdBanco,NomBanco,VrPagado,Estado,EsCorrecto,Observacion,TimeSys,IdUsuario,Nombre,IdDec,IdLog
 FROM LogSobTasas
 WHERE IdDec=@pmIdDec AND IdLog=@pmIdLog
 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 paQryLogSobTasasTot @pmIdDec VARCHAR(4),@pmIdLog INT
 AS 
 SELECT COUNT(Item) SCANT,SUM(CantVentas) AS SCANVEN,SUM(CantDev) AS SCANDEV
,SUM(VrTotalVentas) AS STOTVEN,SUM(VrTotalDev) AS STOTDEV
,SUM(VrSobVentas) AS STOTSOB,SUM(VrSobDev) AS STOTSDEV
,SUM((CantVentas-CantDev)*VrPrecio) AS BaseSobTasa
,SUM((((CantVentas-CantDev)*VrPrecio)*Tarifa)/100) AS TotalSobretasa
 FROM LogSobTasas
 WHERE IdDec=@pmIdDec AND IdLog=@pmIdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryLogSysMax @pmTipDoc VARCHAR(3),@pmDocumento INT, @pmIdCia CHAR(2)
AS
SELECT MAX(IdLog) AS MXLOG FROM LogSys WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento 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  paQryLogSys_Cr @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdUsuario VARCHAR(11)=Null
,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null,@pmDocumento INT=Null,@pmEsCom BIT=Null,@pmEliminado BIT=Null, @pmModificado BIT=Null
,@pmPorTime BIT=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmnModulo VARCHAR(20)=Null,@pmDsname VARCHAR(20)=Null
AS
 IF @pmPorTime>0 
  SELECT  IdUsuario, Nombre, TipDoc, Documento,IdCia, TimeSys, Observacion,IdTercero,IdVehiculo,IdLog, EsCom, Eliminado, Modificado, Fecha,nModulo,Dsname
  FROM   LogSys
  WHERE  TimeSys BETWEEN @pmFechaIni AND @pmFechaFin AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND TipDoc LIKE ISNULL(@pmTipDoc,'%')  AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND nModulo LIKE ISNULL(@pmnModulo,'%') AND Dsname LIKE ISNULL(@pmDsname,'%')
  AND (Documento>=ISNULL(@pmDocumento,-1)  AND Documento<=ISNULL(@pmDocumento,2147483647))
  AND (EsCom=ISNULL(@pmEsCom,0) or EsCom=ISNULL(@pmEsCom,1))
  AND (Eliminado=ISNULL(@pmEliminado,0) or Eliminado=ISNULL(@pmEliminado,1))
  AND (Modificado=ISNULL(@pmModificado,0) or Modificado=ISNULL(@pmModificado,1))
  ORDER BY IdUsuario,TimeSys, IdCia, TipDoc, Documento, IdLog
 ELSE
  SELECT  IdUsuario, Nombre, TipDoc, Documento,IdCia, TimeSys, Observacion,IdTercero,IdVehiculo,IdLog, EsCom, Eliminado, Modificado, Fecha,nModulo,Dsname
  FROM   LogSys
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND TipDoc LIKE ISNULL(@pmTipDoc,'%')  AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND nModulo LIKE ISNULL(@pmnModulo,'%') AND Dsname LIKE ISNULL(@pmDsname,'%')
  AND (Documento>=ISNULL(@pmDocumento,-1)  AND Documento<=ISNULL(@pmDocumento,2147483647))
  AND (EsCom=ISNULL(@pmEsCom,0) or EsCom=ISNULL(@pmEsCom,1))
  AND (Eliminado=ISNULL(@pmEliminado,0) or Eliminado=ISNULL(@pmEliminado,1))
  AND (Modificado=ISNULL(@pmModificado,0) or Modificado=ISNULL(@pmModificado,1))
 ORDER BY IdUsuario,TimeSys, IdCia, TipDoc, Documento, IdLog
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpLogBusesAhorro @pmnAnno INT,@pmnMes INT,@pmCalculado BIT,@pmObservacion VARCHAR(50)
 AS 
 UPDATE LogBusesAhorro SET Calculado=@pmCalculado,Observacion=@pmObservacion
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpLogBusesNomina @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmFecha SMALLDATETIME
,@pmCerrado BIT,@pmObservacion VARCHAR(250)
 AS 
 UPDATE LogBusesNomina SET Fecha=@pmFecha,Cerrado=@pmCerrado,Observacion=@pmObservacion
 WHERE TipProc=@pmTipProc AND CdNom=@pmCdNom AND IdPeriodo=@pmIdPeriodo
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpLogCierres @pmProceso VARCHAR(10),@pmAnno INT,@pmnMes INT,@pmnDia INT,@pmIdCia CHAR(2),@pmEstado INT,@pmFecha SMALLDATETIME
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmCuenta INT,@pmProcessExt1 INT,@pmProcessExt2 INT,@pmProcessExt3 INT,@pmProcessExt4 INT,@pmProcessExt5 INT
 AS 
 UPDATE LogCierres SET Estado=@pmEstado,Fecha=@pmFecha,IdUsuario=@pmIdUsuario,Nombre=@pmNombre,Cuenta=@pmCuenta
,ProcessExt1=@pmProcessExt1,ProcessExt2=@pmProcessExt2,ProcessExt3=@pmProcessExt3,ProcessExt4=@pmProcessExt4,ProcessExt5=@pmProcessExt5
 WHERE Proceso=@pmProceso AND Anno=@pmAnno AND nMes=@pmnMes AND nDia=@pmnDia 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 paUpLogCortesAnu @pmFecha SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2)
 AS 
 UPDATE LogCortes SET Planilla=0,IdCiaPla='00'
 WHERE Fecha=@pmFecha AND NumCorte=@pmNumCorte  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 paUpLogEgresosEst @pmIdLog INT,@pmIdCia CHAR(2)
,@pmEstado INT,@pmTipoEgr VARCHAR(3),@pmEgreso INT
 AS 
 UPDATE LogEgresos SET Estado=@pmEstado,TipoEgr=@pmTipoEgr,Egreso=@pmEgreso
 WHERE IdLog=@pmIdLog 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 paUpLogEgresosTot @pmIdLog INT,@pmIdCia CHAR(2)
,@pmIdTercero VARCHAR(16),@pmVrEgreso MONEY,@pmNumCheque VARCHAR(20)
 AS 
 UPDATE LogEgresos SET  VrEgreso=@pmVrEgreso,NumCheque=@pmNumCheque
 WHERE IdLog=@pmIdLog AND IdCia=@pmIdCia AND 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 paUpLogIntAhorros @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10),@pmNitPropietario VARCHAR(16),@pmNitConductor VARCHAR(16),@pmFecha SMALLDATETIME
,@pmDocumento VARCHAR(50),@pmCerrado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 UPDATE LogIntAhorros SET NitPropietario=@pmNitPropietario,NitConductor=@pmNitConductor,Fecha=@pmFecha,Documento=@pmDocumento,Cerrado=@pmCerrado,TimeSys=@pmTimeSys,IdUsuario=@pmIdUsuario
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdVehiculo=@pmIdVehiculo
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpLogIntAhorrosCie @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmCerrado BIT
 AS 
 UPDATE LogIntAhorros SET Cerrado=@pmCerrado
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes 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 paUpLogIntMora @pmNumero INT,@pmFecha SMALLDATETIME,@pmIdCia CHAR(2),@pmEstado INT
,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmTipCom VARCHAR(3),@pmNombre VARCHAR(50),@pmNomCnia VARCHAR(50)
 AS 
 UPDATE LogIntMora SET Fecha=@pmFecha,IdCia=@pmIdCia,Estado=@pmEstado,TimeSys=@pmTimeSys
,IdUsuario=@pmIdUsuario,TipCom=@pmTipCom,Nombre=@pmNombre,NomCnia=@pmNomCnia
 WHERE 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 paUpLogIntNomina @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmIdCia CHAR(2)
,@pmIdVehiculo VARCHAR(10),@pmNitPropietario VARCHAR(16),@pmNitConductor VARCHAR(16),@pmFecha SMALLDATETIME,@pmDocumento VARCHAR(50),@pmCerrado BIT,@pmVrTotal MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 UPDATE LogIntNomina SET NitPropietario=@pmNitPropietario,NitConductor=@pmNitConductor,Fecha=@pmFecha,Documento=@pmDocumento,Cerrado=@pmCerrado,VrTotal=@pmVrTotal,TimeSys=@pmTimeSys,IdUsuario=@pmIdUsuario
 WHERE TipProc=@pmTipProc AND CdNom=@pmCdNom AND IdPeriodo=@pmIdPeriodo AND IdCia=@pmIdCia AND 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 paUpLogIntNominaCie @pmTipProc VARCHAR(3),@pmCdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8)
,@pmIdCia CHAR(2),@pmCerrado BIT
 AS 
 UPDATE LogIntNomina SET Cerrado=@pmCerrado
 WHERE TipProc=@pmTipProc AND CdNom=@pmCdNom AND IdPeriodo=@pmIdPeriodo 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 paUpLogMayoriza @pmAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmEstado INT,@pmFecha SMALLDATETIME
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmCantidad INT,@pmIdCuenta VARCHAR(16)
 AS 
 UPDATE LogMayoriza SET Estado=@pmEstado,Fecha=@pmFecha,IdUsuario=@pmIdUsuario
,Nombre=@pmNombre,Cantidad=@pmCantidad,IdCuenta=@pmIdCuenta
 WHERE Anno=@pmAnno AND nMes=@pmnMes 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 paUpLogPrecios @pmIdLog INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipo VARCHAR(10),@pmListas VARCHAR(10),@pmSimbTarif CHAR(1),@pmVrTarifa DECIMAL(14,4)
,@pmBaseTarfa VARCHAR(10),@pmFecProg SMALLDATETIME,@pmIdCiaCie CHAR(2),@pmEstado INT,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE LogPrecios SET Fecha=@pmFecha,Tipo=@pmTipo,Listas=@pmListas,SimbTarif=@pmSimbTarif,VrTarifa=@pmVrTarifa,FecProg=@pmFecProg,IdCiaCie=@pmIdCiaCie
,Estado=@pmEstado,IdUsuario=@pmIdUsuario,Nombre=@pmNombre,Observacion=@pmObservacion,BaseTarfa=@pmBaseTarfa,FecUpdate=@pmFecUpdate
 WHERE IdLog=@pmIdLog 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 paUpLogPreciosCie @pmIdLog INT,@pmIdCia CHAR(2),@pmEstado INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE LogPrecios SET Estado=@pmEstado,FecUpdate=@pmFecUpdate
 WHERE IdLog=@pmIdLog 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 paUpLogPro  @pmIdPro VARCHAR(20),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNomTabla VARCHAR(20)
,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmObservacion VARCHAR(250),@pmNewTabla VARCHAR(20)
AS
 UPDATE LogPro SET IdUsuario=@pmIdUsuario,Nombre=@pmNombre,Observacion=@pmObservacion,NomTabla=@pmNewTabla
 WHERE IdPro=@pmIdPro AND Fecha=@pmFecha AND NomTabla=ISNULL(@pmNomTabla,NomTabla) AND IdCia=ISNULL(@pmIdCia,IdCia)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpLogSobTasasEst @pmIdDec VARCHAR(4),@pmIdLog INT,@pmIdEnterr VARCHAR(8)
,@pmEstado INT,@pmEsCorrecto BIT,@pmObservacion VARCHAR(250)
 AS 
 UPDATE LogSobTasas SET Estado=@pmEstado,EsCorrecto=@pmEsCorrecto
,Observacion=ISNULL(@pmObservacion,Observacion)
 WHERE IdDec=@pmIdDec AND IdLog=@pmIdLog AND IdEnterr=@pmIdEnterr
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

