ALTER TABLE Trn_TraPresAnt ADD Cantgalones DECIMAL(14,4) DEFAULT(0),VrExtralegal MONEY DEFAULT(0)
GO
ALTER TABLE Trn_TraLiqViajes ADD Num_Ppto INT DEFAULT(0) NOT NULL
GO
ALTER TABLE Trn_TraPorteInt ADD Condic_Pago VARCHAR(1000)
GO
INSERT INTO  Sys_ObjetosApp (IdObj,IdGrupo,SubModulo,IndObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo)
 VALUES ('FRMPEDCIE','TRAPRO','TRA',22,'Cierre Masivo de Pedidos','FRMPEDCIE','SSSSSSSSSSSSS',0,'')
GO
INSERT INTO Sys_Roles (IdObj,IdRole,Funcion)
 VALUES ('FRMPEDCIE','FEC','Editar Fecha de Cierre')
INSERT INTO Sys_Roles (IdObj,IdRole,Funcion)
 VALUES ('FRMDMVV','RUT','Permitir Modificar Ruta')
GO
INSERT INTO adm_Opciones (IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo)
 VALUES ('CTP','CATEGORIA DE PEAJES DEL PRESUPUESTO SELECCIONADA EN EL MANIFIESTO','BOOLEAN','0',5,'TRANS')
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTraLiqViajes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTraLiqViajes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTraPresAnt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTraPresAnt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraLiqViajes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraLiqViajes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraLiqViajesFmt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraLiqViajesFmt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraLiqViajesLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraLiqViajesLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPresAnt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPresAnt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPresAntFmt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPresAntFmt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPresAntLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPresAntLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTraLiqViajes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTraLiqViajes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTraPresAnt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTraPresAnt]
GO
--Abr 3/2019
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTraPorteInt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTraPorteInt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTraPorteInt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTraPorteInt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPorteInt_Cr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPorteInt_Cr]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPorteInt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPorteInt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPorteIntLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPorteIntLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTraPorteIntLtd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTraPorteIntLtd]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_EdsFormas_Fac]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_EdsFormas_Fac]
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajesFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT LQ.TipDoc AS TipoLiq,TipoDoc,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,Compania,Fecha,LQ.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc
,LQ.IdVehiculo AS PlacaVeh,LQ.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,LQ.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,LQ.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,VrAnticipos,VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen
,LQ.IdRuta AS CdRuta,Ruta,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,Referencia,DescMcias,LiqMixto,Num_Ppto,kmtInicial,kmtFinal,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,Estado,TimeSys,LQ.FecUpdate AS FechaAct,IdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario,Leyenda
,Item,D.IdConcepto AS DetCodConc,CG.Concepto AS DetNomConc,DescConcepto,D.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito,D.IdTercero AS NitTercero,N.RazonSocial AS NomTercero
,CdCCosto,CCosto,CdSubCos,SubCosto,D.RubroConc,VrBase,TarifBase,CantComb,TipFac,Factura,IdCiaFac,ItemFac,FecVence,RefConcep
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraLiqViajes AS LQ  INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON LQ.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON LQ.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto
 INNER JOIN Localidades AS CO ON  LQ.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON LQ.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON LQ.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON LQ.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON LQ.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON LQ.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS ETR ON LQ.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN Trn_TraLiqDetalle AS D ON LQ.TipDoc=D.TipDoc AND LQ.Liquidacion=D.Liquidacion AND LQ.IdCia=D.IdCia
 LEFT JOIN ConcDiversos AS CG ON D.IdConcepto=CG.IdConcepto LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS N ON  D.IdTercero=N.IdTercero
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 WHERE LQ.TipDoc=@pmTipDoc AND LQ.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND LQ.IdCia=@pmIdCia
 ORDER BY LQ.Liquidacion
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajesLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT  Liquidacion,L.IdCia AS CdCia,Compania,Fecha,L.IdConcepto AS CdConcepto,Concepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc,IdVehiculo,IdConductor,CDT.RazonSocial AS Conductor
,IdPropietario,TP.RazonSocial AS Propietario,IdPoseedor,T.RazonSocial AS Poseedor,NitEmpresa,NE.RazonSocial AS NomEmpresa,VrAnticipos,VrGastos,VrCombustible,VrOtrosCred,VrDiferencia
,galsComb,PesoTotal,Cantidad,Volumen,IdRuta,IdLocOrigen,LO.Localidad AS CiudadOrigen,IdLocDestino,LD.Localidad AS CiudadDestino,Referencia,DescMcias,LiqMixto,kmtInicial,kmtFinal
,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,Num_Ppto,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,L.Observacion AS Observ,L.IdEstado AS CdEstado
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,L.IdUsuario AS Cdusuario,Usuario
 FROM Trn_TraLiqViajes AS L  INNER JOIN Terceros AS T ON L.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Terceros AS TP ON L.IdPropietario=TP.IdTercero 
 INNER JOIN Conceptos AS C ON L.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON L.IdCia=CI.IdCia LEFT JOIN Terceros AS NE ON L.NitEmpresa=NE.IdTercero 
 LEFT JOIN Localidades AS LO ON L.IdLocOrigen=LO.IdLocal LEFT JOIN Localidades AS LD ON L.IdLocDestino=LD.IdLocal
 WHERE TipDoc=@pmTipDoc   AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND L.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND L.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
  AND L.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 ORDER BY L.IdCia,Liquidacion
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPresAntFmt] @pmNumPstoIni INT,@pmNumPstoFin INT
 AS 
 SELECT P.NumPsto AS NumPrespto,Fecha,IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,TipoRuta,CdRuta,Ruta
,FecInicio,FecFinal,VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,Catpeaje,CdTipoVeh,TipoVehiculo,TipoAfilVeh,CdTipoMot,TipoMotor
,CdCom,TipoComb,CdRango,DescripRango,ValorFijo,P.Observacion,P.Inactivo AS Inactvo,NitCliente,CL.RazonSocial AS Cliente,CdMercancia,DescripMcia
,P.TipoServicio,Cantgalones,VrExtralegal,FechaCrea,FechaAct,P.IdUsuario AS CdUsuario,Usuario
,D.IdConcepto AS CdConcepto,Concepto,Descripcion,Cantidad,VrUnitario,VrTotal,TipoRubro,CdClase,ClasePeaje,NitTercero,T.RazonSocial,CdTipOper,TipoOperacion
 FROM Trn_TraPresAnt AS P INNER JOIN Trn_TraPresItems AS D ON P.NumPsto=D.NumPsto
 INNER JOIN Localidades AS CO ON  P.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Rutas AS R ON P.CdRuta=R.IdRuta LEFT JOIN TiposVeh AS TV ON P.CdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN PeajesCat AS CP ON P.CdCat=CP.IdCat LEFT JOIN TiposMot AS TM ON P.CdTipoMot=TM.IdTipoMot
 LEFT JOIN TiposFuel AS TF ON P.CdCom=TF.IdCom LEFT JOIN RangosPeso AS RP ON P.CdRango=RP.IdRango
 LEFT JOIN ConcDiversos AS C ON D.IdConcepto=C.IdConcepto LEFT JOIN PeajesClase AS PC ON D.CdClase=PC.IdClase
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN TiposOperac AS TP ON D.CdTipOper=TP.IdTipoOper
 LEFT JOIN Terceros AS CL ON P.NitCliente=CL.IdTercero LEFT JOIN Mercancias AS MC ON P.CdMercancia=MC.IdMercancia
 WHERE P.NumPsto BETWEEN @pmNumPstoIni AND @pmNumPstoFin
 ORDER BY P.NumPsto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPresAntLta] @pmIdOrigen VARCHAR(8)=Null,@pmIdDestino VARCHAR(8)=Null,@pmTipoAfilVeh VARCHAR(10)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT P.NumPsto AS NumPrespto,Fecha,IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,TipoRuta,CdRuta,Ruta
,FecInicio,FecFinal,VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,Catpeaje,CdTipoVeh,TipoVehiculo,TipoAfilVeh,CdTipoMot,TipoMotor
,CdCom,TipoComb,CdRango,DescripRango,ValorFijo,P.Observacion,P.Inactivo AS Inactvo,NitCliente,CL.RazonSocial AS Cliente,CdMercancia,DescripMcia
,Cantgalones,VrExtralegal,FechaCrea,FechaAct,P.IdUsuario AS CdUsuario,Usuario
,D.IdConcepto AS CdConcepto,Concepto,Descripcion,Cantidad,VrUnitario,VrTotal,TipoRubro,CdClase,ClasePeaje,NitTercero,T.RazonSocial,CdTipOper,TipoOperacion
 FROM Trn_TraPresAnt AS P INNER JOIN Trn_TraPresItems AS D ON P.NumPsto=D.NumPsto
 INNER JOIN Localidades AS CO ON  P.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Rutas AS R ON P.CdRuta=R.IdRuta LEFT JOIN TiposVeh AS TV ON P.CdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN PeajesCat AS CP ON P.CdCat=CP.IdCat LEFT JOIN TiposMot AS TM ON P.CdTipoMot=TM.IdTipoMot
 LEFT JOIN TiposFuel AS TF ON P.CdCom=TF.IdCom LEFT JOIN RangosPeso AS RP ON P.CdRango=RP.IdRango
 LEFT JOIN ConcDiversos AS C ON D.IdConcepto=C.IdConcepto LEFT JOIN PeajesClase AS PC ON D.CdClase=PC.IdClase
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN TiposOperac AS TP ON D.CdTipOper=TP.IdTipoOper
 LEFT JOIN Terceros AS CL ON P.NitCliente=CL.IdTercero LEFT JOIN Mercancias AS MC ON P.CdMercancia=MC.IdMercancia
 WHERE IdOrigen LIKE ISNULL(@pmIdOrigen,'%') AND IdDestino LIKE ISNULL(@pmIdDestino,'%') AND TipoAfilVeh LIKE ISNULL(@pmTipoAfilVeh,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY P.NumPsto
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPresAnt] @pmNumPsto INT,@pmFecha SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmVrGastos MONEY,@pmVrComb MONEY,@pmVrPeajes MONEY,@pmVrAnticipo MONEY,@pmCdCat VARCHAR(4)
,@pmCdTipoVeh VARCHAR(4),@pmTipoAfilVeh VARCHAR(10),@pmCdTipoMot VARCHAR(4),@pmCdCom VARCHAR(4),@pmCdRango VARCHAR(4),@pmValorFijo BIT,@pmObservacion VARCHAR(250),@pmInactivo BIT,@pmTipoRuta VARCHAR(10),@pmCdRuta  VARCHAR(4)
,@pmNitCliente VARCHAR(16),@pmCdMercancia VARCHAR(16),@pmTipoServicio INT,@pmCantgalones DECIMAL(14,4),@pmVrExtralegal MONEY,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraPresAnt (NumPsto,Fecha,IdOrigen,IdDestino,TipoRuta,CdRuta,FecInicio,FecFinal,VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,CdTipoVeh,TipoAfilVeh,CdTipoMot,CdCom,CdRango,ValorFijo,Observacion,Inactivo,FechaCrea,IdUsuario,NitCliente,CdMercancia,TipoServicio,Cantgalones,VrExtralegal)
 VALUES (@pmNumPsto,@pmFecha,@pmIdOrigen,@pmIdDestino,@pmTipoRuta,@pmCdRuta,@pmFecInicio,@pmFecFinal,@pmVrGastos,@pmVrComb,@pmVrPeajes,@pmVrAnticipo,@pmCdCat,@pmCdTipoVeh,@pmTipoAfilVeh,@pmCdTipoMot,@pmCdCom
,@pmCdRango,@pmValorFijo,@pmObservacion,@pmInactivo,@pmFechaCrea,@pmIdUsuario,@pmNitCliente,@pmCdMercancia,@pmTipoServicio,@pmCantgalones,@pmVrExtralegal)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraPresAnt] @pmNumPsto INT,@pmFecha SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
,@pmVrGastos MONEY,@pmVrComb MONEY,@pmVrPeajes MONEY,@pmVrAnticipo MONEY,@pmCdCat VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmTipoAfilVeh VARCHAR(10),@pmCdTipoMot VARCHAR(4)
,@pmCdCom VARCHAR(4),@pmCdRango VARCHAR(4),@pmValorFijo BIT,@pmObservacion VARCHAR(250),@pmInactivo BIT,@pmTipoRuta VARCHAR(10),@pmCdRuta  VARCHAR(4),@pmNitCliente VARCHAR(16)
,@pmCdMercancia VARCHAR(16),@pmTipoServicio INT,@pmCantgalones DECIMAL(14,4),@pmVrExtralegal MONEY,@pmFechaAct SMALLDATETIME 
 AS 
 UPDATE Trn_TraPresAnt SET Fecha=@pmFecha,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,VrGastos=@pmVrGastos,VrComb=@pmVrComb,VrPeajes=@pmVrPeajes
,VrAnticipo=@pmVrAnticipo,CdCat=@pmCdCat,CdTipoVeh=@pmCdTipoVeh,TipoAfilVeh=@pmTipoAfilVeh,CdTipoMot=@pmCdTipoMot,CdCom=@pmCdCom,CdRango=@pmCdRango,ValorFijo=@pmValorFijo
,Observacion=@pmObservacion,Inactivo=@pmInactivo,TipoRuta=@pmTipoRuta,CdRuta=@pmCdRuta,FechaAct=@pmFechaAct,NitCliente=@pmNitCliente,CdMercancia=@pmCdMercancia,TipoServicio=@pmTipoServicio
,Cantgalones=@pmCantgalones,VrExtralegal=@pmVrExtralegal
 WHERE NumPsto=@pmNumPsto
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPresAnt] @pmNumPsto INT
 AS 
 SELECT NumPsto,Fecha,IdOrigen,IdDestino,TipoRuta,CdRuta,FecInicio,FecFinal,VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,CdTipoVeh
,TipoAfilVeh,CdTipoMot,CdCom,CdRango,ValorFijo,Observacion,Inactivo,NitCliente,CdMercancia,TipoServicio,Cantgalones,VrExtralegal,FechaCrea,FechaAct,IdUsuario
 FROM Trn_TraPresAnt
 WHERE NumPsto=@pmNumPsto
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor
,NitEmpresa,VrAnticipos,VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen,IdRuta,IdLocOrigen,IdLocDestino,Referencia,DescMcias,kmtInicial,kmtFinal
,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,LiqMixto,Num_Ppto
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraLiqViajes
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmFechaMuc SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmVrAnticipos MONEY,@pmVrGastos MONEY,@pmVrCombustible MONEY
,@pmVrDiferencia MONEY,@pmgalsComb DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmIdRuta VARCHAR(4),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmReferencia VARCHAR(50),@pmDescMcias VARCHAR(150),@pmkmtInicial DECIMAL(14,4),@pmkmtFinal DECIMAL(14,4),@pmEstFactura INT
,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmFecDocRef SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrOtrosCred MONEY,@pmLiqMixto BIT,@pmNum_Ppto INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraLiqViajes SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,TipMuc=@pmTipMuc,Manifiesto=@pmManifiesto,IdCiaMuc=@pmIdCiaMuc,FechaMuc=@pmFechaMuc,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdPropietario=@pmIdPropietario,IdPoseedor=@pmIdPoseedor,NitEmpresa=@pmNitEmpresa,VrAnticipos=@pmVrAnticipos,VrGastos=@pmVrGastos,VrCombustible=@pmVrCombustible,VrDiferencia=@pmVrDiferencia,galsComb=@pmgalsComb
,PesoTotal=@pmPesoTotal,Cantidad=@pmCantidad,Volumen=@pmVolumen,IdRuta=@pmIdRuta,IdLocOrigen=@pmIdLocOrigen,IdLocDestino=@pmIdLocDestino,Referencia=@pmReferencia,DescMcias=@pmDescMcias,kmtInicial=@pmkmtInicial,kmtFinal=@pmkmtFinal,EstFactura=@pmEstFactura,TipDocRef=@pmTipDocRef,NumDocRef=@pmNumDocRef,IdCiaRef=@pmIdCiaRef,FecDocRef=@pmFecDocRef,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,VrOtrosCred=@pmVrOtrosCred,LiqMixto=@pmLiqMixto,Num_Ppto=@pmNum_Ppto,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmFechaMuc SMALLDATETIME,@pmIdVehiculo VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmVrAnticipos MONEY,@pmVrGastos MONEY,@pmVrCombustible MONEY,@pmVrDiferencia MONEY,@pmgalsComb DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmVolumen DECIMAL(14,4)
,@pmIdRuta VARCHAR(4),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmReferencia VARCHAR(50),@pmDescMcias VARCHAR(150),@pmkmtInicial DECIMAL(14,4),@pmkmtFinal DECIMAL(14,4),@pmEstFactura INT,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmFecDocRef SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrOtrosCred MONEY,@pmLiqMixto BIT,@pmNum_Ppto INT,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraLiqViajes (TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,NitEmpresa,VrAnticipos,VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen,IdRuta,IdLocOrigen,IdLocDestino,Referencia,DescMcias
,kmtInicial,kmtFinal,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,LiqMixto,Num_Ppto)
 VALUES (@pmTipDoc,@pmLiquidacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmFechaMuc,@pmIdVehiculo,@pmIdConductor,@pmIdPropietario,@pmIdPoseedor,@pmNitEmpresa,@pmVrAnticipos,@pmVrGastos,@pmVrCombustible,@pmVrOtrosCred,@pmVrDiferencia,@pmgalsComb
,@pmPesoTotal,@pmCantidad,@pmVolumen,@pmIdRuta,@pmIdLocOrigen,@pmIdLocDestino,@pmReferencia,@pmDescMcias,@pmkmtInicial,@pmkmtFinal,@pmEstFactura,@pmTipDocRef,@pmNumDocRef,@pmIdCiaRef,@pmFecDocRef,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmLiqMixto,@pmNum_Ppto)
GO
--abril 3/2019
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteInt_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,O.FecCargue,O.FecEntrega,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino,O.IdNotificado,O.Notificado,NF.Telefono AS TelNoti,NF.TelMovil AS MovNoti,O.IdRemitente,O.Remitente,RM.Telefono AS TelRemi,RM.TelMovil AS MovRemi,O.DirOrigen
,O.IdDestinatario,O.Destinatario,DT.Telefono AS TelDest,DT.TelMovil AS MovDest,O.DirDestino,O.IdConsig,O.Consignatario,CS.Telefono AS TelCons,CS.TelMovil AS MovCons,O.DirConsig,O.InsTransporte,O.DocRemitente,O.ValorTotal,M.Simbolo,O.IdMoneda AS CdMoneda,M.Mneda AS Moneda,O.PesoTotal,O.Manifiesto,O.CdCiaManif
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario,O.Negociacion,O.Condic_Pago
,D.Item,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MN.Mneda AS DetMoneda,MN.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad,D.IdEmp AS CdEmp,Empaque
,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.Observacion AS DetObservacion,D.DescripUnid
 FROM Trn_TraPorteInt AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Trn_TraPorteIntMcia AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MN ON D.IdMoneda=MN.IdMneda  
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat
 INNER JOIN Terceros AS RM ON O.IdRemitente=RM.IdTercero INNER JOIN Terceros AS DT ON O.IdDestinatario=DT.IdTercero
 INNER JOIN Terceros AS NF ON O.IdNotificado=NF.IdTercero INNER JOIN Terceros AS CS ON O.IdConsig=CS.IdTercero
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteIntLtd] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,O.FecCargue,O.FecEntrega,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino,O.IdNotificado,O.Notificado,O.IdRemitente,O.Remitente,O.DirOrigen
,O.IdDestinatario,O.Destinatario,O.DirDestino,O.IdConsig,O.Consignatario,O.DirConsig,O.InsTransporte,O.DocRemitente,O.ValorTotal,M.Simbolo,O.IdMoneda AS CdMoneda,M.Mneda AS Moneda,O.PesoTotal,O.Manifiesto,O.CdCiaManif
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario,O.Negociacion,O.Condic_Pago
--detalles
,D.Item,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MN.Mneda AS DetMoneda,MN.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad,D.IdEmp AS CdEmp,Empaque
,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.Observacion AS DetObservacion,D.DescripUnid
 FROM Trn_TraPorteInt AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 INNER JOIN Trn_TraPorteIntMcia AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MN ON D.IdMoneda=MN.IdMneda
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp 
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed
 WHERE O.TipDoc=@pmTipDoc AND O.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteIntLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,O.FecCargue,O.FecEntrega,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino,O.IdNotificado,O.Notificado,O.IdRemitente,O.Remitente,O.DirOrigen
,O.IdDestinatario,O.Destinatario,O.DirDestino,O.IdConsig,O.Consignatario,O.DirConsig,O.InsTransporte,O.DocRemitente,O.ValorTotal,M.Simbolo,O.IdMoneda AS CdMoneda,M.Mneda AS Moneda,O.PesoTotal,O.Manifiesto,O.CdCiaManif
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Negociacion,O.Condic_Pago,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraPorteInt AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda 
 WHERE O.TipDoc=@pmTipDoc AND O.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdNotificado VARCHAR(16),@pmNotificado VARCHAR(150),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirOrigen VARCHAR(250)
,@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDestino VARCHAR(250),@pmIdConsig VARCHAR(16),@pmConsignatario VARCHAR(150),@pmDirConsig VARCHAR(250),@pmInsTransporte VARCHAR(1000),@pmDocRemitente VARCHAR(500),@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmManifiesto INT,@pmCdCiaManif CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmCondic_Pago VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraPorteInt (TipDoc,NumOrden,IdCia,Fecha,FecEmision,FecCargue,FecEntrega,IdOrigen,IdDestino,IdNotificado,Notificado,IdRemitente,Remitente,DirOrigen,IdDestinatario,Destinatario,DirDestino,IdConsig,Consignatario,DirConsig,InsTransporte,DocRemitente,IdMoneda,ValorTotal,PesoTotal,Manifiesto,CdCiaManif,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Negociacion,Condic_Pago)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmFecEmision,@pmFecCargue,@pmFecEntrega,@pmIdOrigen,@pmIdDestino,@pmIdNotificado,@pmNotificado,@pmIdRemitente,@pmRemitente,@pmDirOrigen,@pmIdDestinatario,@pmDestinatario,@pmDirDestino,@pmIdConsig,@pmConsignatario,@pmDirConsig,@pmInsTransporte,@pmDocRemitente,@pmIdMoneda,@pmValorTotal,@pmPesoTotal,@pmManifiesto,@pmCdCiaManif,@pmOrigenAdd
,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNegociacion,@pmCondic_Pago)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdNotificado VARCHAR(16),@pmNotificado VARCHAR(150),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirOrigen VARCHAR(250)
,@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDestino VARCHAR(250),@pmIdConsig VARCHAR(16),@pmConsignatario VARCHAR(150),@pmDirConsig VARCHAR(250),@pmInsTransporte VARCHAR(1000),@pmDocRemitente VARCHAR(500),@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmManifiesto INT,@pmCdCiaManif CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmCondic_Pago VARCHAR(1000),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraPorteInt SET Fecha=@pmFecha,FecEmision=@pmFecEmision,FecCargue=@pmFecCargue,FecEntrega=@pmFecEntrega,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdNotificado=@pmIdNotificado,Notificado=@pmNotificado,IdRemitente=@pmIdRemitente,Remitente=@pmRemitente,DirOrigen=@pmDirOrigen,IdDestinatario=@pmIdDestinatario,Destinatario=@pmDestinatario,DirDestino=@pmDirDestino,IdConsig=@pmIdConsig
,Consignatario=@pmConsignatario,DirConsig=@pmDirConsig,InsTransporte=@pmInsTransporte,DocRemitente=@pmDocRemitente,IdMoneda=@pmIdMoneda,ValorTotal=@pmValorTotal,PesoTotal=@pmPesoTotal,Manifiesto=@pmManifiesto,CdCiaManif=@pmCdCiaManif,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Negociacion=@pmNegociacion,Condic_Pago=@pmCondic_Pago
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,FecEmision,FecCargue,FecEntrega,IdOrigen,IdDestino,IdNotificado,Notificado,IdRemitente,Remitente,DirOrigen,IdDestinatario,Destinatario,DirDestino,IdConsig,Consignatario,DirConsig,InsTransporte,DocRemitente
,IdMoneda,ValorTotal,PesoTotal,Manifiesto,CdCiaManif,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,Negociacion,Condic_Pago,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraPorteInt
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EdsFormas_Fac] @pmtmNumero VARCHAR(5),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2)
AS 
 INSERT INTO tm_EdsFormas (tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma
,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm
,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio)
SELECT @pmtmNumero,Item,1,TipoRango,IdRango,IdForma,Observacion,0,'0','0',Fecha,'0','',NumSerie,NumForma,VrTotal,IdCliente,IdAgencia,IdCuenta,pVehiculo,nVehiculo
,IdVend,CdProducto,Cantidad,Referencia,NumRef2,CantPuntos,'0','',0,0,'B','0','',IdCajero,CdCCosto,CdSubCos,VrPrecio
FROM Trn_EdsFormas
WHERE TipDcm=@pmTipDcm AND Documento=@pmDocumento AND IdCiaDcm=@pmIdCiaDcm
AND Planilla>0 AND IdCia<>'' AND IdCia<>'00'
GO