if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paDelOilEntrada]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paDelOilEntrada]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paDelOilGuia]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paDelOilGuia]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsOilEntrada]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsOilEntrada]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsOilEntradaProd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsOilEntradaProd]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsOilGuia]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsOilGuia]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsProdPrecCrudo]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsProdPrecCrudo]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTiposTasas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTiposTasas]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryOilEntrada]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryOilEntrada]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryOilGuia]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryOilGuia]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTiposTasas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTiposTasas]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpOilEntrada]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpOilEntrada]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpOilGuia]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpOilGuia]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpProdPrecCrudo]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpProdPrecCrudo]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTiposTasas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTiposTasas]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryOilGuiaFmt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryOilGuiaFmt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryOilEntradaFmt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryOilEntradaFmt]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumGuia,IdCia,Fecha,FecDespacho,IdProveedor,IdVehiculo,IdConductor,IdEstacion,IdProducto,CantBruto,CantNeto,UndMed,Temperatura,UnidTemp,ValorAPI,ValorVCW,CantDescargue,APIDescargue,TempDescargue,FecDescargue,NitEmpTrans,NomEmpTrans,NumRemision,Remolque,TipoEnt,NumEntrada,IdCiaEnt,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilGuia
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilGuia WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdEstacion VARCHAR(4),@pmIdProducto VARCHAR(16),@pmCantBruto DECIMAL(16,6),@pmCantNeto DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmCantDescargue DECIMAL(16,6),@pmAPIDescargue DECIMAL(16,6),@pmTempDescargue DECIMAL(16,6),@pmFecDescargue SMALLDATETIME
,@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmNumRemision VARCHAR(20),@pmRemolque VARCHAR(10),@pmTipoEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilGuia SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,IdProveedor=@pmIdProveedor,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdEstacion=@pmIdEstacion,IdProducto=@pmIdProducto,CantBruto=@pmCantBruto,CantNeto=@pmCantNeto,UndMed=@pmUndMed,Temperatura=@pmTemperatura,UnidTemp=@pmUnidTemp,ValorAPI=@pmValorAPI,ValorVCW=@pmValorVCW,CantDescargue=@pmCantDescargue,APIDescargue=@pmAPIDescargue,TempDescargue=@pmTempDescargue,FecDescargue=@pmFecDescargue,NitEmpTrans=@pmNitEmpTrans,NomEmpTrans=@pmNomEmpTrans,NumRemision=@pmNumRemision,Remolque=@pmRemolque
,TipoEnt=@pmTipoEnt,NumEntrada=@pmNumEntrada,IdCiaEnt=@pmIdCiaEnt,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdEstacion VARCHAR(4),@pmIdProducto VARCHAR(16),@pmCantBruto DECIMAL(16,6),@pmCantNeto DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmCantDescargue DECIMAL(16,6),@pmAPIDescargue DECIMAL(16,6),@pmTempDescargue DECIMAL(16,6),@pmFecDescargue SMALLDATETIME
,@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmNumRemision VARCHAR(20),@pmRemolque VARCHAR(10),@pmTipoEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilGuia (TipDoc,NumGuia,IdCia,Fecha,FecDespacho,IdProveedor,IdVehiculo,IdConductor,IdEstacion,IdProducto,CantBruto,CantNeto,UndMed,Temperatura,UnidTemp,ValorAPI,ValorVCW,CantDescargue,APIDescargue,TempDescargue,FecDescargue,NitEmpTrans,NomEmpTrans,NumRemision,Remolque,TipoEnt,NumEntrada,IdCiaEnt,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumGuia,@pmIdCia,@pmFecha,@pmFecDespacho,@pmIdProveedor,@pmIdVehiculo,@pmIdConductor,@pmIdEstacion,@pmIdProducto,@pmCantBruto,@pmCantNeto,@pmUndMed,@pmTemperatura,@pmUnidTemp,@pmValorAPI,@pmValorVCW,@pmCantDescargue,@pmAPIDescargue,@pmTempDescargue,@pmFecDescargue,@pmNitEmpTrans,@pmNomEmpTrans,@pmNumRemision,@pmRemolque,@pmTipoEnt,@pmNumEntrada,@pmIdCiaEnt,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposTasas] @pmIdTasa VARCHAR(4)
 AS 
 SELECT IdTasa,TipoTasa,Simbolo,Unidad,Inactivo
 FROM TiposTasas
 WHERE IdTasa=@pmIdTasa
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposTasas] @pmIdTasa VARCHAR(4),@pmTipoTasa VARCHAR(50),@pmSimbolo VARCHAR(10),@pmUnidad VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposTasas (IdTasa,TipoTasa,Simbolo,Unidad,Inactivo)
 VALUES (@pmIdTasa,@pmTipoTasa,@pmSimbolo,@pmUnidad,@pmInactivo)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposTasas] @pmIdTasa VARCHAR(4),@pmTipoTasa VARCHAR(50),@pmSimbolo VARCHAR(10),@pmUnidad VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposTasas SET TipoTasa=@pmTipoTasa,Simbolo=@pmSimbolo,Unidad=@pmUnidad,Inactivo=@pmInactivo
 WHERE IdTasa=@pmIdTasa
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdPrecCrudo] @pmTipoTarif VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16),@pmIdTercero VARCHAR(16),@pmDuracion VARCHAR(10),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmTarifa DECIMAL(16,6),@pmIdMoneda VARCHAR(5),@pmInactivo BIT
 AS 
 INSERT INTO ProdPrecCrudo (TipoTarif,Numero,IdCia,IdProducto,IdTercero,Duracion,FecInicio,FecFinal,Tarifa,IdMoneda,Inactivo)
 VALUES (@pmTipoTarif,@pmNumero,@pmIdCia,@pmIdProducto,@pmIdTercero,@pmDuracion,@pmFecInicio,@pmFecFinal,@pmTarifa,@pmIdMoneda,@pmInactivo)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdPrecCrudo] @pmTipoTarif VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16),@pmIdTercero VARCHAR(16),@pmDuracion VARCHAR(10),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmTarifa DECIMAL(16,6),@pmIdMoneda VARCHAR(5),@pmInactivo BIT
 AS 
 UPDATE ProdPrecCrudo SET IdCia=@pmIdCia,IdProducto=@pmIdProducto,IdTercero=@pmIdTercero,Duracion=@pmDuracion,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,Tarifa=@pmTarifa,IdMoneda=@pmIdMoneda,Inactivo=@pmInactivo
 WHERE TipoTarif=@pmTipoTarif AND Numero=@pmNumero
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilEntrada
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmFecDespacho SMALLDATETIME,@pmFecDescargue SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmRemolque VARCHAR(10),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT,@pmTipFactCxp VARCHAR(3),@pmNumFactura INT,@pmIdCiaCxp CHAR(2),@pmEstContable INT,@pmCdConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilEntrada (TipEnt,NumEntrada,IdCia,Fecha,NumGuia,IdCiaGuia,FecDespacho,FecDescargue,IdProveedor,IdVehiculo,IdConductor,NitEmpTrans,NomEmpTrans,Remolque,ValorTotal,CtaPagar,TipFactCxp,NumFactura,IdCiaCxp,EstContable,CdConcepto,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipEnt,@pmNumEntrada,@pmIdCia,@pmFecha,@pmNumGuia,@pmIdCiaGuia,@pmFecDespacho,@pmFecDescargue,@pmIdProveedor,@pmIdVehiculo,@pmIdConductor,@pmNitEmpTrans,@pmNomEmpTrans,@pmRemolque,@pmValorTotal,@pmCtaPagar,@pmTipFactCxp,@pmNumFactura,@pmIdCiaCxp,@pmEstContable,@pmCdConcepto,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmFecDespacho SMALLDATETIME,@pmFecDescargue SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmRemolque VARCHAR(10),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT,@pmTipFactCxp VARCHAR(3),@pmNumFactura INT,@pmIdCiaCxp CHAR(2),@pmEstContable INT,@pmCdConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilEntrada SET Fecha=@pmFecha,NumGuia=@pmNumGuia,IdCiaGuia=@pmIdCiaGuia,FecDespacho=@pmFecDespacho,FecDescargue=@pmFecDescargue,IdProveedor=@pmIdProveedor,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,NitEmpTrans=@pmNitEmpTrans,NomEmpTrans=@pmNomEmpTrans,Remolque=@pmRemolque,ValorTotal=@pmValorTotal,CtaPagar=@pmCtaPagar,TipFactCxp=@pmTipFactCxp,NumFactura=@pmNumFactura,IdCiaCxp=@pmIdCiaCxp,EstContable=@pmEstContable,CdConcepto=@pmCdConcepto,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=@pmIdEstado
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipEnt,NumEntrada,IdCia,Fecha,NumGuia,IdCiaGuia,FecDespacho,FecDescargue,IdProveedor,IdVehiculo,IdConductor,NitEmpTrans,NomEmpTrans,Remolque,ValorTotal,CtaPagar,TipFactCxp,NumFactura,IdCiaCxp,EstContable,CdConcepto,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilEntrada
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilEntradaProd] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmAPI_Corregido DECIMAL(16,6),@pmDensidad DECIMAL(16,6),@pmCantCargue DECIMAL(16,6)
,@pmTempCargue DECIMAL(16,6),@pmAPI_Cargue DECIMAL(16,6),@pmVCW_Cargue DECIMAL(16,6),@pmPesoNeto DECIMAL(16,6),@pmVrUnitario DECIMAL(16,6)
 AS 
 INSERT INTO Trn_OilEntradaProd (TipEnt,NumEntrada,IdCia,Item,IdTanque,IdProducto,Cantidad,UndMed,Temperatura,UnidTemp,ValorAPI,ValorVCW,API_Corregido,Densidad,CantCargue,TempCargue,API_Cargue,VCW_Cargue,PesoNeto,VrUnitario)
 VALUES (@pmTipEnt,@pmNumEntrada,@pmIdCia,@pmItem,@pmIdTanque,@pmIdProducto,@pmCantidad,@pmUndMed,@pmTemperatura,@pmUnidTemp,@pmValorAPI,@pmValorVCW,@pmAPI_Corregido,@pmDensidad,@pmCantCargue,@pmTempCargue,@pmAPI_Cargue,@pmVCW_Cargue,@pmPesoNeto,@pmVrUnitario)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilGuiaFmt] @pmTipDoc VARCHAR(3),@pmNumGuiaIni INT,@pmNumGuiaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT G.TipDoc,G.NumGuia,G.IdCia,Compania,G.Fecha,G.FecDespacho,G.IdProveedor,T.RazonSocial AS NomProveedor,G.IdVehiculo,G.IdConductor,CD.RazonSocial AS NomConductor,G.IdEstacion AS IdCampo,CM.EstServicio AS Campo
,G.IdProducto,DescripProd,G.CantBruto,G.CantNeto,G.UndMed,UM.Unidad,G.Temperatura,G.UnidTemp,G.ValorAPI,G.ValorVCW,G.CantDescargue,G.APIDescargue,G.TempDescargue,G.FecDescargue
,G.NitEmpTrans,G.NomEmpTrans,G.NumRemision,G.Remolque,G.TipoEnt,G.NumEntrada,G.IdCiaEnt,G.Anulado,G.FecDev
,G.Observacion,G.IdEstado,Estado,G.FechaCrea,G.IdCiaCrea,G.OrigenAdd,G.IdUsuario,Usuario,TipoDoc
--datos proveedor
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
 FROM Trn_OilGuia AS G INNER JOIN Sys_TiposDoc AS TD ON G.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON G.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CN ON G.IdCia=CN.IdCia INNER JOIN Terceros AS T ON G.IdProveedor=T.IdTercero
 INNER JOIN ProdMcias AS P ON G.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON G.UndMed=UM.UndMed
 INNER JOIN Terceros AS CD ON G.IdConductor=CD.IdTercero INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN EdsServicio AS CM ON G.IdEstacion=CM.IdEstacion
 WHERE G.TipDoc=@pmTipDoc AND G.NumGuia BETWEEN @pmNumGuiaIni AND @pmNumGuiaFin AND G.IdCia=@pmIdCia
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilEntradaFmt] @pmTipEnt VARCHAR(3),@pmNumEntradaIni INT,@pmNumEntradaFin INT,@pmIdCia CHAR(2)
AS 
 SELECT E.TipEnt,E.NumEntrada,E.IdCia,Compania,E.Fecha,E.NumGuia,E.IdCiaGuia,E.FecDespacho,E.FecDescargue,E.IdProveedor,T.RazonSocial AS NomProveedor,E.IdVehiculo,E.IdConductor,CD.RazonSocial AS NomConductor
,D.IdTanque,D.IdProducto,D.Cantidad,D.UndMed,D.Temperatura,D.UnidTemp,D.ValorAPI,D.ValorVCW,D.API_Corregido,D.Densidad
,D.CantCargue,D.TempCargue,D.API_Cargue,D.VCW_Cargue,D.PesoNeto,D.VrUnitario
,E.NitEmpTrans,E.NomEmpTrans,E.Remolque,E.ValorTotal,E.CtaPagar,E.TipFactCxp,E.NumFactura,E.IdCiaCxp,E.EstContable,E.CdConcepto,Concepto
,E.TipCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.FecDev,E.Observacion,E.IdEstado,Estado,E.FechaCrea,E.IdCiaCrea,E.OrigenAdd,E.IdUsuario,Usuario,TipoDoc
--Datos del proveedor
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
 FROM Trn_OilEntrada AS E INNER JOIN Trn_OilEntradaProd AS D ON E.TipEnt=D.TipEnt AND E.NumEntrada=D.NumEntrada AND E.IdCia=D.IdCia
 INNER JOIN Sys_TiposDoc AS TD ON E.TipEnt=TD.IdDoc INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 INNER JOIN Terceros AS CD ON E.IdConductor=CD.IdTercero INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN Conceptos AS CT ON E.CdConcepto=CT.IdConcepto
 WHERE E.TipEnt=@pmTipEnt AND E.NumEntrada BETWEEN @pmNumEntradaIni AND @pmNumEntradaFin AND E.IdCia=@pmIdCia
GO
