if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsJurCasos]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInsJurCasos]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsKardex]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInsKardex]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsProdPrecCom]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInsProdPrecCom]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsSobretasas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInsSobretasas]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Kdex]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInstm_Kdex]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Kdex_Nts]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInstm_Kdex_Nts]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Kdex_Sel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInstm_Kdex_Sel]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Kdex_SelDev]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInstm_Kdex_SelDev]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_Kdex_SelDve]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInstm_Kdex_SelDve]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryClaseTarImp]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryClaseTarImp]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasos]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasos]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasos_Cr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasos_Cr]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasos_Crh]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasos_Crh]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasos_Crr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasos_Crr]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasos_CrrH]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasos_CrrH]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasosLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasosLta]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasosPen]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasosPen]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurCasosRad]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurCasosRad]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryJurInvestigaLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryJurInvestigaLta]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryKardex]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryKardex]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryKardex_Cr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryKardex_Cr]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryKardexSub]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryKardexSub]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryProdPrecCom]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryProdPrecCom]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryProdPrecComLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryProdPrecComLta]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrySobretasas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrySobretasas]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrySobretasasLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrySobretasasLta]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrySobretasas_Cr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrySobretasas_Cr]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrySobretasas_Crr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrySobretasas_Crr]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_Kdex]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_Kdex]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_KdexDet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_KdexDet]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_KdexDetC]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_KdexDetC]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_KdexFcr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_KdexFcr]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_KdexOcc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_KdexOcc]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_KdexPed]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_KdexPed]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_KdexSub]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQrytm_KdexSub]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpJurCasos]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paUpJurCasos]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpProdPrecCom]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paUpProdPrecCom]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpSobretasas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paUpSobretasas]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsJurCasos @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmRadicacion VARCHAR(20),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmSinRecorrido BIT,@pmTipCar VARCHAR(3)
,@pmCartulina INT,@pmIdCiaCar CHAR(2),@pmFechaSuc SMALLDATETIME,@pmIdRuta VARCHAR(4),@pmIdAbogado VARCHAR(16),@pmIdAuxiliar VARCHAR(16),@pmIdAutoridad VARCHAR(4),@pmIdTipoPro VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCalifica VARCHAR(4),@pmLugarAcc VARCHAR(100)
,@pmCausaAcc VARCHAR(3300),@pmComentario VARCHAR(3300),@pmObservacion VARCHAR(250),@pmContraparte VARCHAR(100),@pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20),@pmValDanosCParte MONEY,@pmValDanosEmp MONEY,@pmValDeducible MONEY
,@pmEmpAsegdora VARCHAR(100),@pmAuxMutuo BIT,@pmArchivoCaso VARCHAR(100),@pmDocumntos VARCHAR(250),@pmCroquis VARCHAR(20),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmReclamaciones VARCHAR(1000),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_JurCasos (TipDoc,CasoID,IdCia,Fecha,Radicacion,IdVehiculo,IdPropietario,IdConductor,SinRecorrido,TipCar,Cartulina,IdCiaCar,FechaSuc,IdRuta,IdAbogado,IdAuxiliar,IdAutoridad,IdTipoPro,IdClase,IdCalifica,LugarAcc,CausaAcc,Comentario,Observacion,Contraparte,DirContraparte,TelContraparte
,ValDanosCParte,ValDanosEmp,ValDeducible,EmpAsegdora,AuxMutuo,ArchivoCaso,Documntos,Croquis,Anulado,FecDev,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Reclamaciones)
 VALUES (@pmTipDoc,@pmCasoID,@pmIdCia,@pmFecha,@pmRadicacion,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmSinRecorrido,@pmTipCar,@pmCartulina,@pmIdCiaCar,@pmFechaSuc,@pmIdRuta,@pmIdAbogado,@pmIdAuxiliar,@pmIdAutoridad,@pmIdTipoPro,@pmIdClase,@pmIdCalifica
,@pmLugarAcc,@pmCausaAcc,@pmComentario,@pmObservacion,@pmContraparte,@pmDirContraparte,@pmTelContraparte,@pmValDanosCParte,@pmValDanosEmp,@pmValDeducible,@pmEmpAsegdora,@pmAuxMutuo,@pmArchivoCaso,@pmDocumntos,@pmCroquis,@pmAnulado,@pmFecDev,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmReclamaciones)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsKardex @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCdTanque VARCHAR(4),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4),@pmIdUnd VARCHAR(4),@pmVrUnitario MONEY,@pmVrPrecio MONEY,@pmVrCostProm MONEY,@pmTarifaIva DECIMAL(14,4),@pmVrIvaEnt MONEY,@pmVrIvaSal MONEY,@pmTarifaDct DECIMAL(14,4),@pmVrDctoEnt MONEY,@pmVrDctoSal MONEY,@pmVrCostoEnt MONEY
,@pmVrCostoSal MONEY,@pmTarifaRet DECIMAL(14,4),@pmVrReteEnt MONEY,@pmVrReteSal MONEY,@pmTarifaIca DECIMAL(14,4),@pmVrIcaEnt MONEY,@pmVrIcaSal MONEY,@pmVrBruto MONEY,@pmCdUbic VARCHAR(10),@pmNumLote VARCHAR(30),@pmFechLote SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmCdLocal VARCHAR(8),@pmCdSzona VARCHAR(4),@pmpVehiculo VARCHAR(10),@pmIdVend VARCHAR(16),@pmComision DECIMAL(14,4)
,@pmCdOperario VARCHAR(16),@pmComisnOper DECIMAL(14,4),@pmReferencia VARCHAR(50),@pmDescripcion VARCHAR(250),@pmComptmntos VARCHAR(50),@pmCdProdEquiv VARCHAR(16),@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFactura VARCHAR(15),@pmTipDocDev VARCHAR(3),@pmNumDocDev INT,@pmCdMngra VARCHAR(10),@pmNumInicial DECIMAL(14,4),@pmNumFinal DECIMAL(14,4),@pmSobretasa DECIMAL(14,4),@pmTasaNac DECIMAL(14,4),@pmTasaDep DECIMAL(14,4)
,@pmTasaMun DECIMAL(14,4),@pmSoldicom DECIMAL(14,4),@pmImpGlobal DECIMAL(14,4),@pmOtroImpto DECIMAL(14,4),@pmUnidades DECIMAL(14,4),@pmItemCombo INT,@pmServcios BIT,@pmNoVentas INT,@pmEsCombo BIT,@pmEsProdBase INT,@pmCodTarDct VARCHAR(4),@pmCodTarIva VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarCom VARCHAR(4),@pmCodTarCmc VARCHAR(4),@pmListaPrec CHAR(1),@pmVrBase MONEY,@pmCdMoneda VARCHAR(5),@pmVrTasaCamb MONEY,@pmVrDivisa1 MONEY,@pmVrDivisa2 MONEY
,@pmVrDivisa3 MONEY,@pmReferencia2 VARCHAR(50),@pmFecOrden SMALLDATETIME,@pmgalsbruto DECIMAL(14,4),@pmgalsneto DECIMAL(14,4), @pmTemperatura DECIMAL(14,4),@pmUmTemp VARCHAR(3),@pmDensidad DECIMAL(14,4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmRec_Costo DECIMAL(14,4)
 AS 
 INSERT INTO Trn_Kardex (TipDoc,Documento,IdCia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,CdMngra,NumInicial
,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecha,@pmIdProducto,@pmIdBodega,@pmCdTanque,@pmEntradas,@pmSalidas,@pmIdUnd,@pmVrUnitario,@pmVrPrecio,@pmVrCostProm,@pmTarifaIva,@pmVrIvaEnt,@pmVrIvaSal,@pmTarifaDct,@pmVrDctoEnt,@pmVrDctoSal,@pmVrCostoEnt,@pmVrCostoSal,@pmTarifaRet,@pmVrReteEnt,@pmVrReteSal,@pmTarifaIca,@pmVrIcaEnt,@pmVrIcaSal,@pmVrBruto,@pmCdUbic,@pmNumLote,@pmFechLote,@pmIdConcepto,@pmIdTercero,@pmCdAgencia,@pmCdCCosto,@pmCdSubCos,@pmCdLocal,@pmCdSzona,@pmpVehiculo,@pmIdVend
,@pmComision,@pmCdOperario,@pmComisnOper,@pmReferencia,@pmDescripcion,@pmComptmntos,@pmCdProdEquiv,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmCotizacion,@pmIdCiaCot,@pmRemision,@pmIdCiaRem,@pmFactura,@pmTipDocDev,@pmNumDocDev,@pmCdMngra,@pmNumInicial,@pmNumFinal,@pmSobretasa,@pmTasaNac,@pmTasaDep,@pmTasaMun,@pmSoldicom,@pmImpGlobal,@pmOtroImpto,@pmUnidades,@pmItemCombo,@pmServcios,@pmNoVentas,@pmEsCombo,@pmEsProdBase,@pmCodTarDct,@pmCodTarIva,@pmCodTarIca,@pmCodTarRet,@pmCodTarCom,@pmCodTarCmc
,@pmListaPrec,@pmVrBase,@pmCdMoneda,@pmVrTasaCamb,@pmVrDivisa1,@pmVrDivisa2,@pmVrDivisa3,@pmReferencia2,@pmFecOrden,@pmgalsbruto,@pmgalsneto,@pmTemperatura,@pmUmTemp,@pmDensidad,@pmTimeSys,@pmIdUsuario,@pmRec_Costo)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paInsProdPrecCom @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmNumero INT,@pmTipoTarif VARCHAR(3),@pmnMes INT,@pmnAnno INT
,@pmTarifa DECIMAL(14,4),@pmNitProv VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO ProdPrecCom (IdProducto,IdCia,Numero,TipoTarif,nMes,nAnno,Tarifa,NitProv,Inactivo)
 VALUES (@pmIdProducto,@pmIdCia,@pmNumero,@pmTipoTarif,@pmnMes,@pmnAnno,@pmTarifa,@pmNitProv,@pmInactivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsSobretasas @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmFecha SMALLDATETIME,@pmnAnno INT,@pmnMes INT,@pmIdEnterr VARCHAR(8),@pmTipoEntidad VARCHAR(10),@pmVrSobretasa MONEY,@pmVrSanciones MONEY,@pmVrCompensa MONEY,@pmVrIntMora MONEY
,@pmVrTotalPagar MONEY,@pmVrFondoSubs MONEY,@pmVrRecaudoDep MONEY,@pmNitDeclara VARCHAR(16),@pmDvDeclara CHAR(1),@pmCedDeclara VARCHAR(16),@pmDeclarante VARCHAR(250),@pmDirEntidad VARCHAR(250),@pmEmailEnt VARCHAR(100),@pmNomRepres VARCHAR(150)
,@pmCargoRepres VARCHAR(50),@pmTipoFirma INT,@pmNitRevisor VARCHAR(16),@pmNomRevisor VARCHAR(150),@pmTpRevisor VARCHAR(20),@pmNumCheque VARCHAR(30),@pmCodBanco VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4)
,@pmCdLocCue VARCHAR(8),@pmTitularCuenta VARCHAR(150),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTransf MONEY,@pmVrPagado MONEY,@pmEstado INT,@pmAdhesivo VARCHAR(30),@pmFechaPago SMALLDATETIME,@pmEsCorr BIT,@pmNumCorr VARCHAR(30),@pmFecCorr SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmCodCta VARCHAR(4),@pmTipEgreso VARCHAR(3),@pmNumEgreso INT,@pmCiaEgreso CHAR(2)
 AS 
 INSERT INTO Trn_Sobretasas (IdDec,NumDeclara,Fecha,nAnno,nMes,IdEnterr,TipoEntidad,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrFondoSubs,VrRecaudoDep,NitDeclara,DvDeclara,CedDeclara,Declarante,DirEntidad,EmailEnt,NomRepres,CargoRepres,TipoFirma,NitRevisor
,NomRevisor,TpRevisor,NumCheque,CodBanco,IdClase,NumCuenta,IdBanco,CdLocCue,TitularCuenta,VrEfectivo,VrOtros,VrTransf,VrPagado,Estado,Adhesivo,FechaPago,EsCorr,NumCorr,FecCorr,Observacion,TimeSys,IdUsuario,CodCta,TipEgreso,NumEgreso,CiaEgreso)
 VALUES (@pmIdDec,@pmNumDeclara,@pmFecha,@pmnAnno,@pmnMes,@pmIdEnterr,@pmTipoEntidad,@pmVrSobretasa,@pmVrSanciones,@pmVrCompensa,@pmVrIntMora,@pmVrTotalPagar,@pmVrFondoSubs,@pmVrRecaudoDep,@pmNitDeclara,@pmDvDeclara,@pmCedDeclara,@pmDeclarante
,@pmDirEntidad,@pmEmailEnt,@pmNomRepres,@pmCargoRepres,@pmTipoFirma,@pmNitRevisor,@pmNomRevisor,@pmTpRevisor,@pmNumCheque,@pmCodBanco,@pmIdClase,@pmNumCuenta,@pmIdBanco,@pmCdLocCue,@pmTitularCuenta,@pmVrEfectivo,@pmVrOtros,@pmVrTransf,@pmVrPagado
,@pmEstado,@pmAdhesivo,@pmFechaPago,@pmEsCorr,@pmNumCorr,@pmFecCorr,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmCodCta,@pmTipEgreso,@pmNumEgreso,@pmCiaEgreso)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstm_Kdex @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmCdTanque VARCHAR(4),@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmIdUnd VARCHAR(4),@pmtmVrUnitario MONEY,@pmtmVrPrecio MONEY,@pmtmVrCostProm MONEY,@pmtmVrProm MONEY
,@pmtmTarifaIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifaDct DECIMAL(14,4),@pmtmVrDcto MONEY,@pmtmTarifaRet DECIMAL(14,4),@pmtmVrRete MONEY,@pmtmTarifaIca DECIMAL(14,4),@pmtmVrIca MONEY,@pmtmVrBruto MONEY,@pmtmCdUbic VARCHAR(10),@pmtmNumLote VARCHAR(30),@pmtmFechLote SMALLDATETIME,@pmtmFecVceLote SMALLDATETIME
,@pmtmIdTercero VARCHAR(16),@pmtmCdAgencia VARCHAR(16),@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmCdLocal VARCHAR(8),@pmtmCdSzona VARCHAR(4),@pmtmpVehiculo VARCHAR(10),@pmtmIdVend VARCHAR(16),@pmtmComision DECIMAL(14,4),@pmtmCdOperario VARCHAR(16),@pmtmComisnOper DECIMAL(14,4),@pmtmReferencia VARCHAR(50)
,@pmtmDescripcion VARCHAR(250),@pmtmComptmntos VARCHAR(50),@pmtmCdProdEquiv VARCHAR(16),@pmtmCdMngra VARCHAR(10),@pmtmNumInicial DECIMAL(14,4),@pmtmNumFinal DECIMAL(14,4),@pmtmSobretasa DECIMAL(14,4),@pmtmTasaNac DECIMAL(14,4),@pmtmTasaDep DECIMAL(14,4),@pmtmTasaMun DECIMAL(14,4),@pmtmSoldicom DECIMAL(14,4)
,@pmtmImpGlobal DECIMAL(14,4),@pmtmOtroImpto DECIMAL(14,4),@pmtmUnidades DECIMAL(14,4),@pmtmServcios BIT,@pmtmNoVentas INT,@pmtmEsCombo BIT,@pmtmEsProdBase INT,@pmtmItemCbo INT,@pmtmCodTarDct VARCHAR(4),@pmtmCodTarIva VARCHAR(4),@pmtmCodTarIca VARCHAR(4),@pmtmCodTarRet VARCHAR(4),@pmtmCodTarCom VARCHAR(4)
,@pmtmCodTarCmc VARCHAR(4),@pmtmCdSubgrupo VARCHAR(8),@pmtmListaPrec CHAR(1),@pmtmVrBase MONEY,@pmtmCdMoneda VARCHAR(5),@pmtmVrTasaCamb MONEY,@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmTipRem VARCHAR(3),@pmtmRemision INT,@pmtmIdCiaRem CHAR(2),@pmtmReferencia2 VARCHAR(50),@pmtmFecOrden SMALLDATETIME
,@pmtmgalsbruto DECIMAL(14,4),@pmtmgalsneto DECIMAL(14,4),@pmtmTemperatura DECIMAL(14,4),@pmtmUmTemp VARCHAR(3),@pmtmDensidad DECIMAL(14,4),@pmtmRec_Costo DECIMAL(14,4)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmCdTanque,@pmtmEntradas,@pmtmSalidas,@pmtmIdUnd,@pmtmVrUnitario,@pmtmVrPrecio,@pmtmVrCostProm,@pmtmVrProm,@pmtmTarifaIva,@pmtmVrIva,@pmtmTarifaDct,@pmtmVrDcto,@pmtmTarifaRet,@pmtmVrRete,@pmtmTarifaIca,@pmtmVrIca,@pmtmVrBruto,@pmtmCdUbic,@pmtmNumLote,@pmtmFechLote,@pmtmFecVceLote
,@pmtmIdTercero,@pmtmCdAgencia,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmCdLocal,@pmtmCdSzona,@pmtmpVehiculo,@pmtmIdVend,@pmtmComision,@pmtmCdOperario,@pmtmComisnOper,@pmtmReferencia,@pmtmDescripcion,@pmtmComptmntos,@pmtmCdProdEquiv,@pmtmCdMngra,@pmtmNumInicial,@pmtmNumFinal,@pmtmSobretasa,@pmtmTasaNac,@pmtmTasaDep,@pmtmTasaMun,@pmtmSoldicom
,@pmtmImpGlobal,@pmtmOtroImpto,@pmtmUnidades,@pmtmServcios,@pmtmNoVentas,@pmtmEsCombo,@pmtmEsProdBase,@pmtmItemCbo,@pmtmCodTarDct,@pmtmCodTarIva,@pmtmCodTarIca,@pmtmCodTarRet,@pmtmCodTarCom,@pmtmCodTarCmc,@pmtmCdSubgrupo,@pmtmListaPrec,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCia
,@pmtmVrBase,@pmtmCdMoneda,@pmtmVrTasaCamb,@pmtmTipRem,@pmtmRemision,@pmtmIdCiaRem,@pmtmReferencia2,@pmtmFecOrden,@pmtmgalsbruto,@pmtmgalsneto,@pmtmTemperatura,@pmtmUmTemp,@pmtmDensidad,@pmtmRec_Costo)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstm_Kdex_Nts @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,Entradas,Salidas,K.IdUnd,VrUnitario,VrPrecio,VrCostProm,0,TarifaIva,VrIvaEnt+VrIvaSal,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipDoc,Documento,IdCia,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,0,0,0,'',0,Rec_Costo
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND EsProdBase=0 AND Salidas>0
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstm_Kdex_Sel @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,Entradas,Salidas,K.IdUnd,VrUnitario,VrPrecio,VrCostProm,0,TarifaIva,VrIvaEnt+VrIvaSal,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND EsProdBase=0
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstm_Kdex_SelDev @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,Salidas,Entradas,K.IdUnd,VrUnitario,VrPrecio,VrCostProm,0,TarifaIva,VrIvaEnt+VrIvaSal,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia  AND  EsProdBase<=1
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstm_Kdex_SelDve @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,Salidas,Entradas,K.IdUnd,CASE WHEN NumInicial>0 THEN VrUnitario-NumInicial ELSE VrUnitario END,CASE WHEN NumInicial>0 THEN VrPrecio-NumInicial ELSE VrPrecio END
,VrCostProm,0,TarifaIva,VrIvaEnt+VrIvaSal,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento 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 paQryClaseTarImp
 AS 
  SELECT IdClase,NomClase
  FROM ClaseTar
  WHERE Inactivo=0 AND IdClase IN ('DEP','GLO','ICA','IVA','MUN','NAC','RET','RIV','SOB','SOL','MGM','PRE','TSN','TSD','TSM','SUB','MAR','COS')
  ORDER BY NomClase
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryJurCasos @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,CasoID,IdCia,Fecha,Radicacion,IdVehiculo,IdPropietario,IdConductor,SinRecorrido,TipCar,Cartulina,IdCiaCar,FechaSuc,IdRuta,IdAbogado,IdAuxiliar,IdAutoridad,IdTipoPro,IdClase,IdCalifica,LugarAcc,CausaAcc
,Comentario,Observacion,Contraparte,DirContraparte,TelContraparte,ValDanosCParte,ValDanosEmp,ValDeducible,EmpAsegdora,AuxMutuo,ArchivoCaso,Documntos,Croquis,Anulado,FecDev,IdEstado,Reclamaciones,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_JurCasos
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID 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 paQryJurCasos_Cr @pmTipDoc VARCHAR(3),@pmCasoIDIni INT,@pmCasoIDFin INT,@pmIdCia CHAR(2)
AS 
SELECT C.CasoID AS NumCaso, C.IdCia AS CodCia,Compania,Fecha, Radicacion,C.IdVehiculo AS PlacaVeh,C.IdPropietario AS NitPropiterio,C.IdConductor AS CedConductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,Item,QT.IdPregunta AS IdPregnta,PreguntaBas,QT.Descripcion AS RptaPregunta,Anulado, FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm
,Reclamaciones,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,C.TipDoc AS CodTipo,TipoDoc,FecUpdate,TimeSys
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc  AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
    INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa   LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal 
 LEFT JOIN Trn_JurCasosQtn AS QT ON C.TipDoc=QT.TipDoc AND C.CasoID=QT.CasoID AND C.IdCia=QT.IdCia
 LEFT JOIN JurPreguntas AS JP ON QT.IdPregunta=JP.IdPregunta
 WHERE  C.TipDoc=@pmTipDoc AND C.CasoID BETWEEN @pmCasoIDIni AND @pmCasoIDFin
 AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
ORDER BY C.IdCia,C.CasoID,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryJurCasos_Crh @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT=Null
AS 
SELECT C.CasoID AS NumCaso, C.IdCia AS CodCia,Compania,Fecha, Radicacion,C.IdVehiculo AS PlacaVeh,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,ActualizaID, FechaUp, Historial, EstadoAct, CierreProc, ArchivoProc, NombreCparte, DirCparte, TelCparte,DanosCParte,DanosEmp, ValorDeducible, Aseguradora
,Reclamaciones,AuxilioMutuo,H.IdEstado AS His_IdEstado,H.IdUsuario AS His_IdUsuario,UH.Usuario AS His_Usuario,Anulado, FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS Cas_Usuario,C.TipDoc AS CodTipo,TipoDoc,FecUpdate,TimeSys
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc  AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  INNER JOIN Trn_JurCasosHis AS H ON C.TipDoc=H.TipDoc AND C.CasoID=H.CasoID AND C.IdCia=H.IdCia
  INNER JOIN adm_Usuarios AS UH ON H.IdUsuario=UH.IdUsuario 
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
 LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal
 WHERE  C.TipDoc=@pmTipDoc
 AND ( C.CasoID>=ISNULL(@pmCasoID,0)  AND  C.CasoID<=ISNULL(@pmCasoID,2147483647))
 AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND  ActualizaID<=ISNULL(@pmActualizaID,2147483647))
ORDER BY C.IdCia,C.CasoID,ActualizaID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryJurCasos_Crr @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
,@pmIdAbogado VARCHAR(16)=Null,@pmIdAuxiliar VARCHAR(16)=Null,@pmIdAutoridad VARCHAR(4)=Null,@pmIdTipoPro VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCalifica VARCHAR(4)=Null,@pmSinRecorrido BIT=Null
,@pmRadicacion VARCHAR(20)=Null,@pmCasoID INT=Null,@pmCartulina INT=Null,@pmFechaSuc SMALLDATETIME=Null,@pmIdRuta VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null
AS 
SELECT CasoID,C.IdCia AS CodCia,Fecha,Radicacion,C.IdVehiculo AS PlacaVeh,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso,C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,Reclamaciones,Anulado,FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm,C.IdUsuario AS IdUsuari,Usuario,Compania,TipDoc,IdCiaCrea,FecUpdate,TimeSys
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
 LEFT JOIN TercCndtores AS CT ON C.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  C.IdCia like ISNULL(@pmIdCia,'%%') AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND C.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND IdAbogado LIKE ISNULL(@pmIdAbogado,'%')
 AND IdAuxiliar LIKE ISNULL(@pmIdAuxiliar,'%') AND C.IdAutoridad LIKE ISNULL(@pmIdAutoridad,'%') AND C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 AND  C.IdClase LIKE ISNULL(@pmIdClase,'%') AND C.IdCalifica LIKE ISNULL(@pmIdCalifica,'%')   AND Radicacion LIKE ISNULL(@pmRadicacion,'%')
 AND (CasoID>=ISNULL(@pmCasoID,0)  AND CasoID<=ISNULL(@pmCasoID,2147483647))
  AND (Cartulina>=ISNULL(@pmCartulina,0)  AND Cartulina<=ISNULL(@pmCartulina,2147483647))
  AND (FechaSuc>=ISNULL(@pmFechaSuc,CAST('19100101' AS SMALLDATETIME)) AND FechaSuc<=ISNULL(@pmFechaSuc,CAST('20781230' AS SMALLDATETIME)))
  AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%') 
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
  AND  (SinRecorrido=ISNULL(@pmSinRecorrido,0) or SinRecorrido=ISNULL(@pmSinRecorrido,1))
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY C.IdCia,CasoID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryJurCasos_CrrH @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
,@pmIdAbogado VARCHAR(16)=Null,@pmIdAuxiliar VARCHAR(16)=Null,@pmIdAutoridad VARCHAR(4)=Null,@pmIdTipoPro VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCalifica VARCHAR(4)=Null,@pmSinRecorrido BIT=Null
,@pmRadicacion VARCHAR(20)=Null,@pmCasoID INT=Null,@pmCartulina INT=Null,@pmFechaSuc SMALLDATETIME=Null,@pmIdRuta VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmActualizaID INT=Null
AS 
SELECT C.CasoID AS NumCaso,C.IdCia AS CodCia,Fecha,Radicacion,C.IdVehiculo AS PlacaVeh,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso,C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,ActualizaID, FechaUp, Historial, EstadoAct, CierreProc, ArchivoProc, NombreCparte, DirCparte, TelCparte,DanosCParte,DanosEmp, ValorDeducible, Aseguradora
,AuxilioMutuo,Reclamaciones,H.IdEstado AS His_IdEstado,EH.Estado AS His_Estado,H.IdUsuario AS His_IdUsuario,UH.Usuario AS His_Usuario
,Anulado,FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm,C.IdUsuario AS IdUsuari,U.Usuario AS Usuario_Doc,Compania,C.TipDoc AS IdTipDcm,IdCiaCrea,FecUpdate,TimeSys
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
 INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 INNER JOIN Trn_JurCasosHis AS H ON C.TipDoc=H.TipDoc AND C.CasoID=H.CasoID AND C.IdCia=H.IdCia
 INNER JOIN adm_Usuarios AS UH ON H.IdUsuario=UH.IdUsuario   INNER JOIN JurEstados AS EH ON H.IdEstado=EH.IdEstado
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
   LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON C.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  C.IdCia like ISNULL(@pmIdCia,'%%') AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND C.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND IdAbogado LIKE ISNULL(@pmIdAbogado,'%')
 AND IdAuxiliar LIKE ISNULL(@pmIdAuxiliar,'%') AND C.IdAutoridad LIKE ISNULL(@pmIdAutoridad,'%') AND C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 AND  C.IdClase LIKE ISNULL(@pmIdClase,'%') AND C.IdCalifica LIKE ISNULL(@pmIdCalifica,'%')   AND Radicacion LIKE ISNULL(@pmRadicacion,'%')
 AND (C.CasoID>=ISNULL(@pmCasoID,0)  AND C.CasoID<=ISNULL(@pmCasoID,2147483647))
  AND (Cartulina>=ISNULL(@pmCartulina,0)  AND Cartulina<=ISNULL(@pmCartulina,2147483647))
  AND (FechaSuc>=ISNULL(@pmFechaSuc,CAST('19100101' AS SMALLDATETIME)) AND FechaSuc<=ISNULL(@pmFechaSuc,CAST('20781230' AS SMALLDATETIME)))
  AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%') 
AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
  AND  (SinRecorrido=ISNULL(@pmSinRecorrido,0) or SinRecorrido=ISNULL(@pmSinRecorrido,1))
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
  AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
 ORDER BY C.IdCia,C.CasoID,ActualizaID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryJurCasosLta @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmAnulado BIT=Null,@pmIdVehiculo VARCHAR(10)=Null
AS 
SELECT CasoID, IdCia, Fecha, Radicacion,C.IdVehiculo AS PlacaVeh,NumVeh,C.IdPropietario AS NitPropiterio,T.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,Reclamaciones, Anulado, FecDev,C.IdEstado AS IdEstad,Estado
,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,TipDoc,FecUpdate,TimeSys
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS T ON C.IdPropietario=T.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE  TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  IdCia like ISNULL(@pmIdCia,'%%')
 AND C.IdVehiculo like ISNULL(@pmIdVehiculo,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY IdCia,CasoID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryJurCasosPen @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmAnulado BIT=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdTipoPro VARCHAR(4)=Null
,@pmIdClase VARCHAR(4)=Null
AS 
SELECT CasoID, IdCia, Fecha, Radicacion,C.IdVehiculo AS PlacaVeh,NumVeh,C.IdPropietario AS NitPropiterio,T.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis, Anulado, FecDev,C.IdEstado AS IdEstad,Estado,Reclamaciones
,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,TipDoc,FecUpdate,TimeSys
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS T ON C.IdPropietario=T.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
WHERE  TipDoc=@pmTipDoc AND C.IdEstado<>'9998' AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
  AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 AND C.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY IdCia,CasoID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryJurCasosRad @pmTipDoc VARCHAR(3),@pmRadicacion VARCHAR(20), @pmIdCia CHAR(2)=Null
AS 
SELECT   TipDoc, CasoID, IdCia, Fecha, Radicacion, IdVehiculo, IdPropietario, IdConductor, SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, IdRuta
,IdAbogado, IdAuxiliar, IdAutoridad, IdTipoPro, IdClase, IdCalifica, LugarAcc, CausaAcc, Comentario, Observacion, Contraparte, DirContraparte,TelContraparte
,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis, Reclamaciones,Anulado, FecDev,IdEstado, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
 FROM Trn_JurCasos
 WHERE  TipDoc=@pmTipDoc AND Radicacion=@pmRadicacion  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY  IdCia,CasoID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE  paQryJurInvestigaLta  @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmAnulado BIT=Null,@pmIdAbogado VARCHAR(16)=Null,@pmIdEmpresa VARCHAR(16)=Null
AS
SELECT CasoID, C.IdCia AS CodCia, Fecha, Radicacion, IdAbogado,A.RazonSocial AS Abogado, IdAuxiliar,AX.RazonSocial AS Auxiliar, C.IdAutoridad AS IdAutordad,NomAutoridad,IdEmpresa,T.RazonSocial AS Empresa
,C.Observacion AS Observ, Contraparte, DirContraparte,TelContraparte,ArchivoCaso, Anulado, FecDev, C.IdEstado AS IdEstad,Estado,C.IdUsuario AS IdUsuari,Usuario,TipDoc,Compania,IdCiaCrea,FecUpdate,TimeSys
 FROM Trn_JurInvestiga AS C  INNER JOIN  Terceros AS T ON C.IdEmpresa=T.IdTercero 
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero  INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero 
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 WHERE  TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdAbogado like ISNULL(@pmIdAbogado,'%') AND IdEmpresa LIKE ISNULL(@pmIdEmpresa,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY C.IdCia,CasoID
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryKardex @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona
,pVehiculo,IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev
,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct
,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,Temperatura
,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento 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 ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryKardex_Cr @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipDoc VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmnAnnoAnt INT=Null,@pmnMesAnt INT=Null
 AS 
 SELECT  K.IdProducto AS CdProducto,DescripProd,TipDoc,Documento,K.IdCia AS CdCia,Compania,Fecha,Item,K.IdBodega AS CdBodega,Bodega
,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,TarifaDct,VrDctoEnt,VrDctoSal
,TarifaIva,VrIvaEnt,VrIvaSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden
,K.IdConcepto AS CdConcepto,Concepto,K.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,CdAgencia,Agencia,CodAgencia,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,Comision
,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper,pVehiculo,CdLocal,LK.Localidad AS KarCiudad,CdCCosto,CCosto,CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,Factura,Remision,IdCiaRem,Cotizacion,IdCiaCot
,TipDocDev,NumDocDev,CdUbic,NumLote,FechLote,Comptmntos,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun
,Soldicom,ImpGlobal,OtroImpto,Rec_Costo,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo
,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,TimeSys,K.IdUsuario AS IdUsuari,Usuario,TipoDoc
--Datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono
--datos del producto
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,Tamano,Color,PM.UndMed AS CdUndMed,SU.Unidad AS ProdUnidad,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,IvaInc,IdTarIva,Tarifa,Simbolo
,Seriales,Lotes,Combo,Tanques,DescripLong,DescripAbrv,Precio1,Precio2,Precio3,Precio4,Precio5,IdProv,PV.RazonSocial AS NomProveedor
,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo AS ProdInactivo
--Información del saldo anterior
,SaldoAntProd,CostoAntProd,SaldoAntBod,CostoAntBod
 FROM Trn_Kardex AS K INNER JOIN Companias AS CN ON K.IdCia=CN.IdCia 
 INNER JOIN Sys_TiposDoc AS TD ON K.TipDoc=TD.IdDoc
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed   INNER JOIN Terceros AS PV ON PM.IdProv=PV.IdTercero
 INNER JOIN  Conceptos AS C ON K.IdConcepto=C.IdConcepto 
 INNER JOIN Terceros AS T ON K.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON K.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN Agencias  AS A ON K.CdAgencia=A.IdAgencia
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN  Localidades AS LK ON K.CdLocal=LK.IdLocal 
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 LEFT JOIN Tablapor AS TI ON PM.IdTarIva=TI.IdTarifa
--Saldos anteriores
 LEFT JOIN (SELECT IdProducto,SUM(SaldoAnt+Entradas-Salidas) AS SaldoAntProd,SUM(CostoAnt+CostoEnt-CostoSal) AS CostoAntProd 
 FROM  AcuInventario
 WHERE  nAnno=@pmnAnnoAnt AND nMes=@pmnMesAnt
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 GROUP BY IdProducto) AS SP ON K.IdProducto=SP.IdProducto
--Saldos por bodega
 LEFT JOIN (SELECT IdProducto,IdBodega,SUM(SaldoAnt+Entradas-Salidas) AS SaldoAntBod,SUM(CostoAnt+CostoEnt-CostoSal) AS CostoAntBod
 FROM  AcuInventario
 WHERE  nAnno=@pmnAnnoAnt AND nMes=@pmnMesAnt
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 GROUP BY IdProducto,IdBodega) AS SB ON K.IdProducto=SB.IdProducto AND K.IdBodega=SB.IdBodega
 WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%')  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND K.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 ORDER BY DescripProd,Fecha,TimeSys
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryKardexSub @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdSubgrupo,K.IdProducto AS tmIdProducto,DescripProd,TipoRef,Combo,EsProdBase AS tmEsProdBase
,IdProv,COUNT(Item) AS SCANT,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
,SUM(VrCostoEnt) AS SCOSENT,SUM(VrCostoSal) AS SCOSSAL
,SUM(VrPrecio*Entradas) AS SVALENT,SUM(VrPrecio*Salidas) AS SVALSAL
,SUM(VrBruto*Entradas) AS SBRUENT,SUM(VrBruto*Salidas) AS SBRUSAL
,SUM(Entradas*ImpGlobal) AS SGLOENT,SUM(Salidas*ImpGlobal) AS SGLOSAL
,SUM(Sobretasa*Entradas) AS SSOBENT,SUM(Sobretasa*Salidas) AS SSOBSAL
,SUM(TasaNac*Entradas) AS SNACENT,SUM(TasaNac*Salidas) AS SNACSAL
,SUM(TasaDep*Entradas) AS SDEPENT,SUM(TasaDep*Salidas) AS SDEPSAL
,SUM(TasaMun*Entradas) AS SMUNENT,SUM(TasaMun*Salidas) AS SMUNSAL
,SUM(Soldicom*Entradas) AS SSOLENT,SUM(Soldicom*Salidas) AS SSOLSAL
,SUM(CASE WHEN  Salidas>0 THEN VrIvaSal ELSE VrIvaEnt END) AS SIVA
,SUM(CASE WHEN  Salidas>0 THEN VrDctoSal ELSE VrDctoEnt END) AS SDCT
,SUM(CASE WHEN  Salidas>0 THEN VrReteSal ELSE VrReteEnt END) AS SRET
,SUM(CASE WHEN  Salidas>0 THEN VrIcaSal ELSE VrIcaEnt END) AS SICA
,SUM(OtroImpto*Entradas) AS SOTRENT,SUM(OtroImpto*Salidas) AS SOTRSAL
,SUM(Rec_Costo*Entradas) AS SRCOSENT,SUM(Rec_Costo*Salidas) AS SRCOSSAL
--Para los ajustes con cantidad en cero (0)
,SUM(VrUnitario) AS SCOSAJU,SUM(OtroImpto) AS SDVEAJU
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 GROUP BY  IdSubgrupo,K.IdProducto,DescripProd,TipoRef,Combo,EsProdBase,IdProv
 ORDER BY IdSubgrupo,K.IdProducto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paQryProdPrecCom @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmNumero INT
 AS 
 SELECT IdProducto,IdCia,Numero,TipoTarif,nMes,nAnno,Tarifa,NitProv,Inactivo
 FROM ProdPrecCom
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia 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 paQryProdPrecComLta @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT T.IdProducto AS CdProducto,DescripProd,T.IdCia AS CdCia,Compania,Numero,TipoTarif,nMes,nAnno
,Tarifa,NitProv,RazonSocial,T.Inactivo AS Inactvo
 FROM ProdPrecCom AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto INNER JOIN Companias AS CI ON T.IdCia=CI.IdCia
 LEFT JOIN Terceros AS PV ON T.NitProv=PV.IdTercero
 WHERE T.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND T.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 paQrySobretasas @pmIdDec VARCHAR(4),@pmNumDeclara INT
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,IdEnterr,TipoEntidad,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar
,VrFondoSubs,VrRecaudoDep,NitDeclara,DvDeclara,CedDeclara,Declarante,DirEntidad,EmailEnt,NomRepres,CargoRepres
,TipoFirma,NitRevisor,NomRevisor,TpRevisor,NumCheque,CodBanco,IdClase,NumCuenta,IdBanco,CdLocCue,TitularCuenta
,VrEfectivo,VrOtros,VrTransf,VrPagado,Estado,Adhesivo,FechaPago,EsCorr,NumCorr,FecCorr,Observacion,TimeSys,FecUpdate,IdUsuario,CodCta
,TipEgreso,NumEgreso,CiaEgreso
 FROM Trn_Sobretasas
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrySobretasasLta @pmIdDec VARCHAR(4),@pmnAnno INT,@pmnMesIni INT=Null,@pmnMesFin INT=Null
,@pmNumDeclaraIni INT=Null,@pmNumDeclaraFin INT=Null,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null
,@pmIdBanco VARCHAR(4)=Null,@pmEstado INT=Null
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,TipoEntidad,S.IdEnterr AS CdEnterr,TipoId,NitEntidad,Dv,DirEntidad,SitioWeb,EmailEnt
,NomRepres,CargoRepres,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar
,VrFondoSubs,VrRecaudoDep,NitDeclara,DvDeclara,CedDeclara,Declarante,TipoFirma,NitRevisor,NomRevisor
,TpRevisor,FormaPago,NumCheque,CodBanco,CodCta,NumeroCta,S.IdClase AS CdClase,ClaseCuenta,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco
,S.CdLocCue AS IdLocCue,Localidad,TitularCuenta,VrEfectivo,VrOtros,VrTransf,VrPagado,TipEgreso,NumEgreso,CiaEgreso,Estado,Adhesivo,FechaPago,EsCorr
,NumCorr,FecCorr,Observacion,TimeSys,FecUpdate,S.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Sobretasas AS S INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco
 INNER JOIN  ClaseCta AS CT ON S.IdClase=CT.IdClase
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 LEFT JOIN Localidades AS L ON S.CdLocCue=L.IdLocal
 LEFT JOIN CtasCorrientes AS CTA ON S.CodCta=CTA.IdCta
 WHERE IdDec=@pmIdDec AND nAnno=@pmnAnno AND nMes BETWEEN ISNULL(@pmnMesIni,0)  AND ISNULL(@pmnMesFin,20)
 AND NumDeclara BETWEEN  ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
 AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%') AND TipoEntidad  LIKE ISNULL(@pmTipoEntidad ,'%')
 AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647)) 
 ORDER BY NumDeclara
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrySobretasas_Cr  @pmIdDec VARCHAR(4),@pmNumDeclaraIni INT,@pmNumDeclaraFin INT
,@pmnAnnoIni INT=Null,@pmnAnnoFin INT=Null,@pmnMesIni INT=Null,@pmnMesFin INT=Null
,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null,@pmIdBanco VARCHAR(4)=Null,@pmEstado INT=Null
 AS 
 SELECT S.IdDec AS CdDec,Declaracion,S.NumDeclara AS NumeroDec,Fecha,nAnno,nMes,NitDeclara,DvDeclara,CedDeclara,Declarante
,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrFondoSubs,VrRecaudoDep,VrEfectivo,VrOtros,VrTransf,VrPagado,TipEgreso,NumEgreso,CiaEgreso
--detalles
,Item,Concepto,Cantidad,VrUnitario,VrBase,Tarifa,VrLiquida,VrPrecio,ClaseProd,TarifGalon,PorcBase
--entidad
,TipoEntidad,S.IdEnterr AS CdEnterr,NomEntidad,E.TipoId AS EntTipoID,NitEntidad,E.Dv AS EntDv,RazonSocial,DirEntidad,E.Telefono AS EntTelefono,E.Fax AS EntFax
,E.SitioWeb AS EntSitioWeb,EmailEnt,E.CedRepLegal AS CedRepres,NomRepres,CargoRepres,FormaPago
,S.IdClase AS CdClase,ClaseCuenta,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco,CodEntidad
,S.CdLocCue AS IdLocCue,L.Localidad AS LugarCuenta,L.IdDep AS CdDepLugar,DP.Departamento AS DptoLugarCuenta,TitularCuenta,NumCheque,CodBanco,CodCta,NumeroCta
,S.TipoFirma AS TipFirma,S.NitRevisor AS IdRevisor,S.NomRevisor AS NombRevisor,S.TpRevisor AS TarjProf,Estado,Adhesivo,FechaPago
,EsCorr,NumCorr,FecCorr,S.Observacion AS Observ,S.IdUsuario AS IdUsuari,Usuario,TimeSys
--información del tipo de declaracion
,TipoDec,TipoIdDec,TD.Direccion AS DirDeclarante,TD.IdLocal AS CdCiuDec,LT.Localidad AS CiuDeclarante
,LT.IdDep AS CdDepDec,DT.Departamento AS DptoDeclarante,TD.Telefono AS TelefDeclara,TD.CedRepLegal AS CedRepDeclara,TD.RepLegal AS RepLegalDeclara
 FROM Trn_Sobretasas AS S INNER JOIN Trn_SobDetalle AS D ON S.IdDec=D.IdDec AND S.NumDeclara=D.NumDeclara
 INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr INNER JOIN SobTiposDec AS TD ON S.IdDec=TD.IdDec
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco
 INNER JOIN  ClaseCta AS CT ON S.IdClase=CT.IdClase
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LT ON TD.IdLocal=LT.IdLocal INNER JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 LEFT JOIN Localidades AS L ON S.CdLocCue=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Terceros AS T ON E.NitEntidad=T.IdTercero LEFT JOIN CtasCorrientes AS CTA ON S.CodCta=CTA.IdCta
 WHERE S.IdDec LIKE ISNULL(@pmIdDec ,'%')
 AND S.NumDeclara BETWEEN  ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
 AND nMes BETWEEN ISNULL(@pmnMesIni,0)  AND ISNULL(@pmnMesFin,20)
 AND nAnno BETWEEN ISNULL(@pmnAnnoIni,0) AND ISNULL(@pmnAnnoFin,2147483647)
 AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%') AND TipoEntidad  LIKE ISNULL(@pmTipoEntidad ,'%')
 AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647)) 
 ORDER BY S.NumDeclara,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrySobretasas_Crr  @pmnAnno INT,@pmnMesIni INT=Null,@pmnMesFin INT=Null,@pmIdDec VARCHAR(4)=Null
,@pmNumDeclaraIni INT=Null,@pmNumDeclaraFin INT=Null,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null
,@pmIdBanco VARCHAR(4)=Null
 AS 
 SELECT  IdDec,NumDeclara,nAnno,nMes,TipoEntidad,S.IdEnterr AS CdEnterr,E.TipoId AS EntTipoID
,NitEntidad,E.Dv AS EntDv,NomEntidad,S.IdClase AS CdClase,ClaseCuenta,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco,CodEntidad,TitularCuenta
--valores
,tmAcpmCant,tmAcpmBase,tmAcpmValor,tmAcpmTarif,tmAcpmPrecio,tmAcpiCant,tmAcpiBase,tmAcpiValor,tmAcpiTarif,tmAcpiPrecio,tmGcorCant,tmGcorBase
,tmGcorValor,tmGcorTarif,tmGcorPrecio,tmGextCant,tmGextBase,tmGextValor,tmGextTarif,tmGextPrecio,tmGimpCant,tmGimpBase,tmGimpValor,tmGimpTarif
,tmGimpPrecio,tmGcoxCant,tmGcoxBase,tmGcoxValor,tmGcoxTarif,tmGcoxPrecio,tmGeoxCant,tmGeoxBase,tmGeoxValor,tmGeoxTarif,tmGeoxPrecio
,tmAczfCant,tmAczfBase,tmAczfValor,tmAczfTarif,tmAczfPrecio,tmGnzfCant,tmGnzfBase,tmGnzfValor,tmGnzfTarif,tmGnzfPrecio
,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrFondoSubs,VrRecaudoDep,VrEfectivo,VrOtros,VrTransf,VrPagado,TipEgreso,NumEgreso,CiaEgreso
,FormaPago,S.CdLocCue AS IdLocCue,L.Localidad AS LugarCuenta,L.IdDep AS CdDepLugar,DP.Departamento AS DptoLugarCuenta,NumCheque,CodBanco
,CodCta,NumeroCta,DirEntidad,E.Telefono AS EntTelefono,E.Fax AS EntFax,E.SitioWeb AS EntSitioWeb,EmailEnt,E.CedRepLegal AS CedRepres,NomRepres,CargoRepres
,RazonSocial,LT.Localidad AS NomCiudad,LT.IdDep AS CdDep,DT.Departamento AS NomDpto
,Estado,Fecha,NitDeclara,DvDeclara,CedDeclara,Declarante
 FROM Trn_Sobretasas AS S  INNER JOIN tm_Sobtasas AS T ON S.IdDec=T.tmIdDec AND S.NumDeclara=T.tmNumDeclara
 INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco
 INNER JOIN ClaseCta AS CT ON S.IdClase=CT.IdClase
 LEFT JOIN Localidades AS L ON S.CdLocCue=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Localidades AS LT ON S.IdEnterr=LT.IdLocal LEFT JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 LEFT JOIN Terceros AS TE ON E.NitEntidad=TE.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON S.CodCta=CTA.IdCta
 WHERE nAnno=@pmnAnno AND Estado<=1 AND IdDec LIKE ISNULL(@pmIdDec ,'%')
 AND nMes BETWEEN ISNULL(@pmnMesIni,0)  AND ISNULL(@pmnMesFin,20)
 AND NumDeclara BETWEEN  ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
 AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%') AND TipoEntidad  LIKE ISNULL(@pmTipoEntidad ,'%')
 AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 ORDER BY IdDec,NomEntidad,NumDeclara
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_Kdex @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb
,tmTipDoc,tmDocumento,tmIdCia,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad
,tmRec_Costo
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY  tmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_KdexDet @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo
--variables de productos
,DescripProd,TipoRef,IdSubgrupo,Seriales,Lotes,Combo,Tanques
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 WHERE  tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_KdexDetC @pmtmNumero VARCHAR(5)
 AS 
--traslado de productos combos
 SELECT tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmRec_Costo
--variables de productos
,DescripProd,TipoRef,IdSubgrupo,Seriales,Lotes,Combo,Tanques
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 WHERE  tmNumero=@pmtmNumero AND tmEsCombo<>0 AND Combo<>0 AND TipoRef<>'SERVICIO'
 AND  tmEsProdBase=0
 ORDER BY tmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_KdexFcr @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmSalidas,tmVrPrecio,tmTarifaDct,tmVrDcto
,(tmVrPrecio*tmSalidas)-tmVrDcto AS SubTotal,tmTarifaIva,tmVrIva,((tmVrPrecio*tmSalidas)-tmVrDcto)+tmVrIva AS ValorTotal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca
,tmVrUnitario,tmVrUnitario*tmSalidas AS CostoTotal,tmVrBruto,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion
,tmIdVend,tmComision,tmCdOperario,tmComisnOper,tmNumLote,tmFechLote,tmFecVceLote,tmCdCCosto,tmCdSubCos,tmComptmntos
,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb
,tmServcios,Tanques,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmCdAgencia,tmRec_Costo
FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY  tmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_KdexOcc @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmCdTanque,tmSalidas,tmVrPrecio,(tmSalidas*tmVrPrecio)-tmVrDcto AS VrSubTotal
,tmTarifaIva,tmVrIva,((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva AS VrTotal,tmComptmntos,tmSobretasa,tmImpGlobal,tmSoldicom
,tmTasaNac,tmTasaDep,tmTasaMun,tmUnidades,tmReferencia,tmDescripcion,tmIdBodega,Bodega,tmListaPrec,tmVrBruto,tmVrUnitario
,tmServcios,Tanques,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmCdLocal,tmIdVend,tmComision,tmCodTarCom,tmpVehiculo,tmEsCombo
,tmReferencia2,tmRec_Costo
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
ORDER BY tmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_KdexPed @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmSalidas,tmVrPrecio,tmTarifaDct,tmVrDcto,(tmSalidas*tmVrPrecio)-tmVrDcto AS VrSubTotal
,tmTarifaIva,tmVrIva,((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva AS VrTotal,tmComptmntos,tmSobretasa,tmImpGlobal,tmSoldicom,tmTasaNac,tmTasaDep,tmTasaMun
,tmVrBruto,tmListaPrec,tmUnidades,tmReferencia,tmDescripcion,tmCodTarDct
,tmIdVend,tmComision,tmCodTarCom,tmServcios,Tanques,tmVrUnitario,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia,tmRec_Costo
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytm_KdexSub @pmtmNumero VARCHAR(5)
 AS 
 SELECT IdSubgrupo,tmIdProducto,DescripProd,TipoRef,Combo,tmEsProdBase,IdProv,COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmEntradas*tmImpGlobal) AS SGLOENT,SUM(tmSalidas*tmImpGlobal) AS SGLOSAL
,SUM(tmSobretasa*tmEntradas) AS SSOBENT,SUM(tmSobretasa*tmSalidas) AS SSOBSAL
,SUM(tmTasaNac*tmEntradas) AS SNACENT,SUM(tmTasaNac*tmSalidas) AS SNACSAL
,SUM(tmTasaDep*tmEntradas) AS SDEPENT,SUM(tmTasaDep*tmSalidas) AS SDEPSAL
,SUM(tmTasaMun*tmEntradas) AS SMUNENT,SUM(tmTasaMun*tmSalidas) AS SMUNSAL
,SUM(tmSoldicom*tmEntradas) AS SSOLENT,SUM(tmSoldicom*tmSalidas) AS SSOLSAL
,SUM(tmOtroImpto*tmEntradas) AS SOTRENT,SUM(tmOtroImpto*tmSalidas) AS SOTRSAL
--Para los ajustes con cantidad en cero (0)
,SUM(tmVrUnitario) AS SCOSAJU,SUM(tmOtroImpto) AS SDVEAJU
,SUM(tmRec_Costo*tmEntradas) AS SRCOSENT,SUM(tmRec_Costo*tmSalidas) AS SRCOSSAL
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero
 GROUP BY IdSubgrupo,tmIdProducto,DescripProd,TipoRef,Combo,tmEsProdBase,IdProv
 ORDER BY IdSubgrupo,tmIdProducto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE paUpJurCasos @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmRadicacion VARCHAR(20),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmSinRecorrido BIT,@pmTipCar VARCHAR(3),@pmCartulina INT,@pmIdCiaCar CHAR(2),@pmFechaSuc SMALLDATETIME,@pmIdRuta VARCHAR(4),@pmIdAbogado VARCHAR(16),@pmIdAuxiliar VARCHAR(16),@pmIdAutoridad VARCHAR(4),@pmIdTipoPro VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCalifica VARCHAR(4),@pmLugarAcc VARCHAR(100),@pmCausaAcc VARCHAR(3300)
,@pmComentario VARCHAR(3300),@pmObservacion VARCHAR(250),@pmContraparte VARCHAR(100),@pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20),@pmValDanosCParte MONEY,@pmValDanosEmp MONEY,@pmValDeducible MONEY,@pmEmpAsegdora VARCHAR(100),@pmAuxMutuo BIT,@pmArchivoCaso VARCHAR(100),@pmDocumntos VARCHAR(250),@pmCroquis VARCHAR(20),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmReclamaciones VARCHAR(1000),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_JurCasos SET Fecha=@pmFecha,Radicacion=@pmRadicacion,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor,SinRecorrido=@pmSinRecorrido,TipCar=@pmTipCar,Cartulina=@pmCartulina,IdCiaCar=@pmIdCiaCar,FechaSuc=@pmFechaSuc,IdRuta=@pmIdRuta,IdAbogado=@pmIdAbogado,IdAuxiliar=@pmIdAuxiliar,IdAutoridad=@pmIdAutoridad,IdTipoPro=@pmIdTipoPro,IdClase=@pmIdClase,IdCalifica=@pmIdCalifica,LugarAcc=@pmLugarAcc,CausaAcc=@pmCausaAcc,Comentario=@pmComentario,Observacion=@pmObservacion,Contraparte=@pmContraparte,DirContraparte=@pmDirContraparte
,TelContraparte=@pmTelContraparte,ValDanosCParte=@pmValDanosCParte,ValDanosEmp=@pmValDanosEmp,ValDeducible=@pmValDeducible,EmpAsegdora=@pmEmpAsegdora,AuxMutuo=@pmAuxMutuo,ArchivoCaso=@pmArchivoCaso,Documntos=@pmDocumntos,Croquis=@pmCroquis,Anulado=@pmAnulado,FecDev=@pmFecDev,Reclamaciones=@pmReclamaciones,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID 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 paUpProdPrecCom @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmNumero INT,@pmTipoTarif VARCHAR(3),@pmnMes INT,@pmnAnno INT
,@pmTarifa DECIMAL(14,4),@pmNitProv VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE ProdPrecCom SET TipoTarif=@pmTipoTarif,nMes=@pmnMes,nAnno=@pmnAnno,Tarifa=@pmTarifa,NitProv=@pmNitProv,Inactivo=@pmInactivo
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia AND Numero=@pmNumero

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpSobretasas @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmFecha SMALLDATETIME,@pmnAnno INT,@pmnMes INT,@pmIdEnterr VARCHAR(8),@pmTipoEntidad VARCHAR(10),@pmVrSobretasa MONEY,@pmVrSanciones MONEY,@pmVrCompensa MONEY,@pmVrIntMora MONEY
,@pmVrTotalPagar MONEY,@pmVrFondoSubs MONEY,@pmVrRecaudoDep MONEY,@pmNitDeclara VARCHAR(16),@pmDvDeclara CHAR(1),@pmCedDeclara VARCHAR(16),@pmDeclarante VARCHAR(250),@pmDirEntidad VARCHAR(250),@pmEmailEnt VARCHAR(100),@pmNomRepres VARCHAR(150)
,@pmCargoRepres VARCHAR(50),@pmTipoFirma INT,@pmNitRevisor VARCHAR(16),@pmNomRevisor VARCHAR(150),@pmTpRevisor VARCHAR(20),@pmNumCheque VARCHAR(30),@pmCodBanco VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4)
,@pmCdLocCue VARCHAR(8),@pmTitularCuenta VARCHAR(150),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTransf MONEY,@pmVrPagado MONEY,@pmEstado INT,@pmAdhesivo VARCHAR(30),@pmFechaPago SMALLDATETIME,@pmEsCorr BIT,@pmNumCorr VARCHAR(30)
,@pmFecCorr SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME,@pmCodCta VARCHAR(4),@pmTipEgreso VARCHAR(3),@pmNumEgreso INT,@pmCiaEgreso CHAR(2)
 AS 
 UPDATE Trn_Sobretasas SET Fecha=@pmFecha,nAnno=@pmnAnno,nMes=@pmnMes,IdEnterr=@pmIdEnterr,TipoEntidad=@pmTipoEntidad,VrSobretasa=@pmVrSobretasa,VrSanciones=@pmVrSanciones,VrCompensa=@pmVrCompensa,VrIntMora=@pmVrIntMora,VrTotalPagar=@pmVrTotalPagar
,VrFondoSubs=@pmVrFondoSubs,VrRecaudoDep=@pmVrRecaudoDep,NitDeclara=@pmNitDeclara,DvDeclara=@pmDvDeclara,CedDeclara=@pmCedDeclara,Declarante=@pmDeclarante,DirEntidad=@pmDirEntidad,EmailEnt=@pmEmailEnt,NomRepres=@pmNomRepres
,CargoRepres=@pmCargoRepres,TipoFirma=@pmTipoFirma,NitRevisor=@pmNitRevisor,NomRevisor=@pmNomRevisor,TpRevisor=@pmTpRevisor,NumCheque=@pmNumCheque,CodBanco=@pmCodBanco,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco
,CdLocCue=@pmCdLocCue,TitularCuenta=@pmTitularCuenta,VrEfectivo=@pmVrEfectivo,VrOtros=@pmVrOtros,VrPagado=@pmVrPagado,VrTransf=@pmVrTransf,Estado=@pmEstado,Adhesivo=@pmAdhesivo,FechaPago=@pmFechaPago,EsCorr=@pmEsCorr,NumCorr=@pmNumCorr,FecCorr=@pmFecCorr
,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate,CodCta=@pmCodCta,TipEgreso=@pmTipEgreso,NumEgreso=@pmNumEgreso,CiaEgreso=@pmCiaEgreso
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

