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].[paInsOilGuia]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsOilGuia]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTercCliente]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTercCliente]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTercCliente_Sel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTercCliente_Sel]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTercProvee]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTercProvee]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTercProvee_Sel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTercProvee_Sel]
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].[paQryOilEntradaFmt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryOilEntradaFmt]
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].[paQryOilGuiaFmt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryOilGuiaFmt]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTercCliente]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTercCliente]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTercClienteLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTercClienteLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTercProvee]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTercProvee]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTercProveeLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTercProveeLta]
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].[paUpTercCliente]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTercCliente]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTercProvee]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTercProvee]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClienteLta] @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdRegimen VARCHAR(4)=Null,@pmTipoId CHAR(1)=Null
,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmIdForma VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdZona VARCHAR(4)=Null
,@pmIdSzona VARCHAR(4)=Null,@pmIdPlazo VARCHAR(4)=Null,@pmIdEstrato VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdRuta VARCHAR(4)=Null
,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmInactivoTer BIT=Null
 AS 
 SELECT IdClie,T.RazonSocial AS RaznSocial,T.TipoId AS TipId,T.Dv AS DvNit,T.NomCial AS NombreCmcial,T.SiglaRaz AS SiglaRazSocial
,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,T.Direccion AS Dirccion,T.IdLocal AS CdCiudad,L.Localidad AS Ciudad,L.IdDep AS CdDpto
,D.Departamento AS Dpto,T.Telefono AS Tlefono,T.Fax AS NumFax,T.TelMovil AS TelCeluar,T.SitioWeb AS WebSite,T.e_mail AS Email,DirEnv,IdLocEnv,LE.Localidad AS CiuEnvio
,DE.Departamento AS Dptoenvio,DiasEntga,C.IdGrupo AS CdGrupo,GrupoClie,C.IdEstrato AS CdEstrato,Estrato,SZ.IdZona AS CdZona,Zona,C.IdSzona AS CdSubzona,Subzona
,C.IdRuta AS CdRuta,Ruta,C.IdPlazo AS CdPlazo,Plazo,NVmto,PlazosImp,CdPlazoComb,C.IdForma AS CdFrma,FormaPago,T.IdSector AS CdSector,SectorEco,T.IdProf AS CdProf,Profesion,T.IdRegimen AS CdRgmen
,Regimen,T.TipEnte AS TipoEnte,IdVend,TV.RazonSocial AS NomVendedor,NitFact,C.IdClase AS CdClase,ClaseCuenta,NumCuenta,C.IdBanco AS CdBanco,Banco,B.Direccion AS Dirbanco
,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret,AutoIca,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,Contrato,NContrato,CiaContMay,FecIngreso,FecVigencia
,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,T.Observacion AS Observ,Cmntario1,Cmntario2,Cmntario3,CdBandera,TipoBandera,PrendGarant,FecUpCupo,TipoCliente,CodClieSicom,CdDiaEnt,C.IdEstado AS CdEst_clie,EC.Estado AS EstadoClie,C.Inactivo AS Clie_inactivo
,T.IdEstado AS CdEst_terc,ET.Estado AS Estad_terc,T.Inactivo AS Terc_inactivo,T.Codigo AS CodTerc,T.IdLugarCed AS IdLugCed,LC.Localidad AS LugarCed,T.FecExpCed AS FecExpCedula
,T.EsVendedor AS EsVend,T.EsConductor AS EsCond,T.EsPropietario AS EsProp,T.EsProveedor AS EsProvee,T.EsEmpleado AS EsEmpldo,T.EsOperario AS EsOper,T.EsAccnista AS EsAcc
,T.EsCiaAseg AS EsAseg,CdTipBloq,C.FechaAdd AS FecAdd,C.FechaUpdate AS FecUpd,C.IdUsuario AS IdUsuari,Usuario,T.IniStgNom AS PosNomb,Restric_Cia,CupoGalones,FecPlazoDoc,EdoRadicaDoc
,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,T.FechaNac,T.ImagenDoc1,T.ImagenDoc2,T.ImagenDoc3
 FROM TercCliente  AS C INNER JOIN Terceros AS T ON C.IdClie=T.IdTercero  INNER JOIN Terceros AS TV ON C.IdVend=TV.IdTercero
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN Estratos AS ETC ON C.IdEstrato=ETC.IdEstrato
 INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona  INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta
 INNER JOIN Formaspago AS F ON C.IdForma=F.IdForma
 INNER JOIN ClaseCta AS CTA ON  C.IdClase=CTA.IdClase
 INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco INNER JOIN EstadoTer AS EC ON C.IdEstado=EC.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario   INNER JOIN Localidades AS LE ON C.IdLocEnv=LE.IdLocal
 INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf LEFT JOIN TiposBan TB ON C.CdBandera=TB.IdBandera
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%')  AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND T.TipoId LIKE ISNULL(@pmTipoId,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%') AND C.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%') AND C.IdForma LIKE ISNULL(@pmIdForma,'%') AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND SZ.IdZona LIKE ISNULL(@pmIdZona,'%') AND C.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND C.IdPlazo LIKE ISNULL(@pmIdPlazo,'%') AND C.IdEstrato LIKE ISNULL(@pmIdEstrato,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercProveeLta]  @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdRegimen VARCHAR(4)=Null,@pmTipoId CHAR(1)=Null
,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLocOrd VARCHAR(8)=Null,@pmIdForma VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmInactivoTer BIT=Null
 AS 
 SELECT IdProv,Dv,TipoId,RazonSocial,T.Codigo AS Codtercero,NomCial,SiglaRaz,NitRepLeg,NomRepLeg,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto,Telefono,Fax,TelMovil
,DirOrdComp,IdLocOrd,LP.Localidad AS CiudadOrd,DP.Departamento AS DeptoOrd,SitioWeb,e_mail,TipEnte,T.IdSector AS CodSector,SectorEco,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,PV.IdGrupo AS CdGrupo,GrupoClie
,NitContac,NomContac,TelContac,emlContac,CargContac,DiasEntga,PV.IdPlazo AS CdPlazo,Plazo,PV.IdForma AS CdForma,FormaPago,PV.IdClase AS CdClase,ClaseCuenta,NumCuenta,PV.IdBanco AS CdBanco,Banco
,B.Direccion AS DirBanco,Contacto,CdMney,CdDct,Tarifa,Simbolo,Autoret,AutoIca,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv,GartProd,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed
,Observacion,Cmntarios,ObsFinanc,ObsJuridica,PathFoto,PathFirma,T.IdEstado AS IdEstTerc,ET.Estado AS EstadTerc,T.Inactivo AS Ter_Inactvo,PV.IdEstado AS IdEstProv,EP.Estado AS EstadProv,PV.Inactivo AS Prv_Inactvo,CodRetCom
,Contrato,NContrato,FecIngreso,FecVigencia,FecRetiro,EsCliente,EsProveedor,EsPropietario,EsAccnista,EsCiaAseg,PV.FechaAdd AS Fec_Add,PV.FechaUpdate AS Fec_Upd,PV.IdUsuario AS IdUsario,Usuario,IniStgNom,EP.NColor AS ClrEstado
,T.FechaNac,T.ImagenDoc1,T.ImagenDoc2,T.ImagenDoc3,CupoElectcom
 FROM TercProvee AS PV INNER JOIN Terceros AS T ON PV.IdProv=T.IdTercero
 INNER JOIN GruposCli AS G ON PV.IdGrupo=G.IdGrupo INNER JOIN Plazos AS PZ ON PV.IdPlazo=PZ.IdPlazo
 INNER JOIN Formaspago AS F ON PV.IdForma=F.IdForma INNER JOIN ClaseCta AS CTA ON  PV.IdClase=CTA.IdClase
 INNER JOIN Bancos AS B ON PV.IdBanco=B.IdBanco INNER JOIN EstadoTer AS EP ON PV.IdEstado=EP.IdEstado
 INNER JOIN adm_Usuarios AS U ON PV.IdUsuario=U.IdUsuario   INNER JOIN Localidades AS LP ON PV.IdLocOrd=LP.IdLocal
 INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep  INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN Tablapor AS TD ON PV.CdDct=TD.IdTarifa
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%')  AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND TipoId LIKE ISNULL(@pmTipoId,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%') AND PV.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdLocOrd LIKE ISNULL(@pmIdLocOrd,'%') AND PV.IdForma LIKE ISNULL(@pmIdForma,'%') AND PV.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND PV.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (PV.Inactivo=ISNULL(@pmInactivo,0) or PV.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY RazonSocial
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),@pmNumFactCom INT,@pmCdCiaFco CHAR(2),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2)
 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,NumFactCom=@pmNumFactCom,CdCiaFco=@pmCdCiaFco,NumFactTra=@pmNumFactTra,CdCiaFtr=@pmCdCiaFtr
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
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,NumFactCom,CdCiaFco,NumFactTra,CdCiaFtr,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].[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),@pmNumFactCom INT,@pmCdCiaFco CHAR(2),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2)
,@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,NumFactCom,CdCiaFco,NumFactTra,CdCiaFtr)
 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,@pmNumFactCom,@pmCdCiaFco,@pmNumFactTra,@pmCdCiaFtr)
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.NumFactCom,G.CdCiaFco,G.NumFactTra,G.CdCiaFtr,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.UMCargue,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.TipoAju,E.NumAjuInv,E.IdCiaAju,E.CantAjuste,E.NumFactTra,E.CdCiaFtr,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
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),@pmTipoAju VARCHAR(3),@pmNumAjuInv INT,@pmIdCiaAju CHAR(2),@pmCantAjuste DECIMAL(16,6),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2),@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,TipoAju,NumAjuInv,IdCiaAju,CantAjuste,EstContable,CdConcepto,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario,NumFactTra,CdCiaFtr)
 VALUES (@pmTipEnt,@pmNumEntrada,@pmIdCia,@pmFecha,@pmNumGuia,@pmIdCiaGuia,@pmFecDespacho,@pmFecDescargue,@pmIdProveedor,@pmIdVehiculo,@pmIdConductor,@pmNitEmpTrans,@pmNomEmpTrans,@pmRemolque,@pmValorTotal,@pmCtaPagar,@pmTipFactCxp,@pmNumFactura,@pmIdCiaCxp,@pmTipoAju,@pmNumAjuInv,@pmIdCiaAju,@pmCantAjuste,@pmEstContable,@pmCdConcepto,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario,@pmNumFactTra,@pmCdCiaFtr)
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),@pmTipoAju VARCHAR(3),@pmNumAjuInv INT,@pmIdCiaAju CHAR(2),@pmCantAjuste DECIMAL(16,6),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2)
 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,TipoAju=@pmTipoAju,NumAjuInv=@pmNumAjuInv,IdCiaAju=@pmIdCiaAju,CantAjuste=@pmCantAjuste,NumFactTra=@pmNumFactTra,CdCiaFtr=@pmCdCiaFtr
 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
,TipoAju,NumAjuInv,IdCiaAju,CantAjuste,NumFactTra,CdCiaFtr,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 OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercProvee] @pmIdProv VARCHAR(16)
 AS 
 SELECT IdProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo
,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv,GartProd,FecIngreso,PathFoto,PathFirma
,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Cmntarios,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario,CodRetCom,CupoElectcom,AutoIca
 FROM TercProvee
 WHERE IdProv=@pmIdProv
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercProvee] @pmIdProv VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150)
,@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50),@pmDirOrdComp VARCHAR(250),@pmIdLocOrd VARCHAR(8),@pmDiasEntga INT,@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4)
,@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT,@pmIncIca BIT,@pmLiqFletes BIT,@pmCdRet VARCHAR(4)
,@pmCdRiv VARCHAR(4),@pmGartProd INT,@pmFecIngreso SMALLDATETIME,@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmCmntarios VARCHAR(250),@pmContrato BIT,@pmNContrato VARCHAR(20),@pmFecVigencia SMALLDATETIME
,@pmFecRetiro SMALLDATETIME,@pmObsFinanc VARCHAR(250),@pmObsJuridica VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCodRetCom VARCHAR(4),@pmCupoElectcom DECIMAL(14,4),@pmAutoIca BIT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercProvee (IdProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv
,GartProd,FecIngreso,PathFoto,PathFirma,Cmntarios,IdEstado,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Inactivo,FechaAdd,IdUsuario,CodRetCom,CupoElectcom,AutoIca)
 VALUES (@pmIdProv,@pmIdGrupo,@pmNitRepLeg,@pmNomRepLeg,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargContac,@pmDirOrdComp,@pmIdLocOrd,@pmDiasEntga,@pmIdPlazo,@pmIdForma,@pmCdMney,@pmCdDct,@pmIdClase
,@pmNumCuenta,@pmIdBanco,@pmAutoret,@pmIncRet,@pmIncRiv,@pmIncIca,@pmLiqFletes,@pmCdRet,@pmCdRiv,@pmGartProd,@pmFecIngreso,@pmPathFoto,@pmPathFirma,@pmCmntarios,@pmIdEstado
,@pmContrato,@pmNContrato,@pmFecVigencia,@pmFecRetiro,@pmObsFinanc,@pmObsJuridica,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmCodRetCom,@pmCupoElectcom,@pmAutoIca)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercProvee] @pmIdProv VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20)
,@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50),@pmDirOrdComp VARCHAR(250),@pmIdLocOrd VARCHAR(8),@pmDiasEntga INT,@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4),@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmIdClase VARCHAR(4)
,@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT,@pmIncIca BIT,@pmLiqFletes BIT,@pmCdRet VARCHAR(4),@pmCdRiv VARCHAR(4),@pmGartProd INT,@pmFecIngreso SMALLDATETIME,@pmPathFoto VARCHAR(30)
,@pmPathFirma VARCHAR(30),@pmCmntarios VARCHAR(250),@pmContrato BIT,@pmNContrato VARCHAR(20),@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmObsFinanc VARCHAR(250),@pmObsJuridica VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCodRetCom VARCHAR(4),@pmCupoElectcom DECIMAL(14,4),@pmAutoIca BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercProvee SET IdGrupo=@pmIdGrupo,NitRepLeg=@pmNitRepLeg,NomRepLeg=@pmNomRepLeg,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargContac=@pmCargContac,DirOrdComp=@pmDirOrdComp,IdLocOrd=@pmIdLocOrd
,DiasEntga=@pmDiasEntga,IdPlazo=@pmIdPlazo,IdForma=@pmIdForma,CdMney=@pmCdMney,CdDct=@pmCdDct,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,Autoret=@pmAutoret,IncRet=@pmIncRet,IncRiv=@pmIncRiv,IncIca=@pmIncIca,LiqFletes=@pmLiqFletes,CdRet=@pmCdRet
,CdRiv=@pmCdRiv,GartProd=@pmGartProd,FecIngreso=@pmFecIngreso,PathFoto=@pmPathFoto,PathFirma=@pmPathFirma,Cmntarios=@pmCmntarios,Contrato=@pmContrato,NContrato=@pmNContrato,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,ObsFinanc=@pmObsFinanc,ObsJuridica=@pmObsJuridica
,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,CodRetCom=@pmCodRetCom,CupoElectcom=@pmCupoElectcom,AutoIca=@pmAutoIca,FechaUpdate=@pmFechaUpdate
 WHERE IdProv=@pmIdProv
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercProvee_Sel] @pmIdProv VARCHAR(16),@pmNewProv VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdProv FROM  TercProvee WHERE  IdProv=@pmIdProv)
 INSERT INTO TercProvee (IdProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv
,GartProd,FecIngreso,PathFoto,PathFirma,Cmntarios,IdEstado,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Inactivo,FechaAdd,IdUsuario,CodRetCom,CupoElectcom,AutoIca)
 SELECT @pmNewProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv
,GartProd,FecIngreso,PathFoto,PathFirma,Cmntarios,IdEstado,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Inactivo,FechaAdd,IdUsuario,CodRetCom,CupoElectcom,AutoIca
 FROM TercProvee WHERE  IdProv=@pmIdProv
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliente] @pmIdClie VARCHAR(16),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50),@pmDirEnv VARCHAR(250)
,@pmIdLocEnv VARCHAR(8),@pmDiasEntga INT,@pmIdSzona VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4),@pmIdEstrato VARCHAR(4),@pmIdVend VARCHAR(16),@pmNitFact VARCHAR(16),@pmIdRuta VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30)
,@pmIdBanco VARCHAR(4),@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmCdRet VARCHAR(4),@pmCdRiv VARCHAR(4),@pmCdCms VARCHAR(4),@pmExcIva BIT,@pmTrfIntMora DECIMAL(14,4),@pmDiasGracia INT,@pmLiqFletes BIT,@pmFactSold BIT,@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT
,@pmIncIca BIT,@pmFactTipo INT,@pmVrCupo MONEY,@pmVrSaldo MONEY,@pmUidClie VARCHAR(16),@pmPwdClie VARCHAR(10),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmMatMerc VARCHAR(20),@pmFecMat SMALLDATETIME
,@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmCmntario1 VARCHAR(250),@pmCmntario2 VARCHAR(250),@pmPlazosImp VARCHAR(20),@pmCdBandera VARCHAR(4),@pmContrato BIT,@pmNContrato INT,@pmCiaContMay CHAR(2),@pmCmntario3 VARCHAR(250),@pmPrendGarant VARCHAR(150)
,@pmFecUpCupo SMALLDATETIME,@pmTipoCliente VARCHAR(10),@pmRestric_Cia BIT,@pmCupoGalones DECIMAL(14,4),@pmCdPlazoComb VARCHAR(4),@pmCodClieSicom VARCHAR(20),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFecPlazoDoc SMALLDATETIME,@pmEdoRadicaDoc INT,@pmCdTipBloq VARCHAR(4)
,@pmDescEdoDoc VARCHAR(250),@pmComIndustrial INT,@pmNumLista CHAR(1),@pmTermicas BIT,@pmCodRetCom VARCHAR(4),@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16),@pmCdDiaEnt VARCHAR(4),@pmAutoIca BIT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercCliente (IdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga,IdSzona,IdGrupo,IdPlazo,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret
,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie,CodClieSicom,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,PlazosImp,IdEstado,TipoCliente,Inactivo,CdBandera,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo,FechaAdd,IdUsuario
,CupoGalones,Restric_Cia,CdPlazoComb,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca)
 VALUES (@pmIdClie,@pmNitRepLeg,@pmNomRepLeg,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargContac,@pmDirEnv,@pmIdLocEnv,@pmDiasEntga,@pmIdSzona,@pmIdGrupo,@pmIdPlazo,@pmIdForma,@pmIdEstrato,@pmIdVend,@pmNitFact,@pmIdRuta,@pmIdClase,@pmNumCuenta
,@pmIdBanco,@pmCdMney,@pmCdDct,@pmCdRet,@pmCdRiv,@pmCdCms,@pmExcIva,@pmTrfIntMora,@pmDiasGracia,@pmLiqFletes,@pmFactSold,@pmAutoret,@pmIncRet,@pmIncRiv,@pmIncIca,@pmFactTipo,@pmVrCupo,@pmVrSaldo,@pmUidClie,@pmPwdClie,@pmCodClieSicom,@pmFecIngreso,@pmFecVigencia,@pmFecRetiro
,@pmMatMerc,@pmFecMat,@pmPathFoto,@pmPathFirma,@pmCmntario1,@pmCmntario2,@pmPlazosImp,@pmIdEstado,@pmTipoCliente,@pmInactivo,@pmCdBandera,@pmContrato,@pmNContrato,@pmCiaContMay,@pmCmntario3,@pmPrendGarant,@pmFecUpCupo,@pmFechaAdd,@pmIdUsuario,@pmCupoGalones,@pmRestric_Cia
,@pmCdPlazoComb,@pmFecPlazoDoc,@pmEdoRadicaDoc,@pmCdTipBloq,@pmDescEdoDoc,@pmComIndustrial,@pmNumLista,@pmTermicas,@pmCodRetCom,@pmCodCCosto,@pmCodSubCosto,@pmCdDiaEnt,@pmAutoIca)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCliente] @pmIdClie VARCHAR(16),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100)
,@pmCargContac VARCHAR(50),@pmDirEnv VARCHAR(250),@pmIdLocEnv VARCHAR(8),@pmDiasEntga INT,@pmIdSzona VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4),@pmIdEstrato VARCHAR(4)
,@pmIdVend VARCHAR(16),@pmNitFact VARCHAR(16),@pmIdRuta VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmCdRet VARCHAR(4)
,@pmCdRiv VARCHAR(4),@pmCdCms VARCHAR(4),@pmExcIva BIT,@pmTrfIntMora DECIMAL(14,4),@pmDiasGracia INT,@pmLiqFletes BIT,@pmFactSold BIT,@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT,@pmIncIca BIT,@pmFactTipo INT,@pmVrCupo MONEY
,@pmVrSaldo MONEY,@pmUidClie VARCHAR(16),@pmPwdClie VARCHAR(10),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmMatMerc VARCHAR(20),@pmFecMat SMALLDATETIME
,@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmCmntario1 VARCHAR(250),@pmCmntario2 VARCHAR(250),@pmPlazosImp VARCHAR(20),@pmCdBandera VARCHAR(4),@pmContrato BIT,@pmNContrato INT,@pmCiaContMay CHAR(2)
,@pmCmntario3 VARCHAR(250),@pmPrendGarant VARCHAR(150),@pmFecUpCupo SMALLDATETIME,@pmTipoCliente VARCHAR(10),@pmRestric_Cia BIT,@pmCupoGalones DECIMAL(14,4)
,@pmCdPlazoComb VARCHAR(4),@pmCodClieSicom VARCHAR(20),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFecPlazoDoc SMALLDATETIME,@pmEdoRadicaDoc INT,@pmCdTipBloq VARCHAR(4),@pmDescEdoDoc VARCHAR(250),@pmComIndustrial INT
,@pmNumLista CHAR(1),@pmTermicas BIT,@pmCodRetCom VARCHAR(4),@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16),@pmCdDiaEnt VARCHAR(4),@pmAutoIca BIT,@pmFechaUpdate SMALLDATETIME 
 AS 
 UPDATE TercCliente SET NitRepLeg=@pmNitRepLeg,NomRepLeg=@pmNomRepLeg,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargContac=@pmCargContac,DirEnv=@pmDirEnv,IdLocEnv=@pmIdLocEnv
,DiasEntga=@pmDiasEntga,IdSzona=@pmIdSzona,IdGrupo=@pmIdGrupo,IdPlazo=@pmIdPlazo,IdForma=@pmIdForma,IdEstrato=@pmIdEstrato,IdVend=@pmIdVend,NitFact=@pmNitFact,IdRuta=@pmIdRuta,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco
,CdMney=@pmCdMney,CdDct=@pmCdDct,CdRet=@pmCdRet,CdRiv=@pmCdRiv,CdCms=@pmCdCms,ExcIva=@pmExcIva,TrfIntMora=@pmTrfIntMora,DiasGracia=@pmDiasGracia,LiqFletes=@pmLiqFletes,FactSold=@pmFactSold,Autoret=@pmAutoret,IncRet=@pmIncRet,IncRiv=@pmIncRiv
,IncIca=@pmIncIca,FactTipo=@pmFactTipo,VrCupo=@pmVrCupo,VrSaldo=@pmVrSaldo,UidClie=@pmUidClie,PwdClie=@pmPwdClie,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,MatMerc=@pmMatMerc,FecMat=@pmFecMat,PathFoto=@pmPathFoto
,PathFirma=@pmPathFirma,Cmntario1=@pmCmntario1,Cmntario2=@pmCmntario2,PlazosImp=@pmPlazosImp,CdBandera=@pmCdBandera,Contrato=@pmContrato,NContrato=@pmNContrato,CiaContMay=@pmCiaContMay,Cmntario3=@pmCmntario3,PrendGarant=@pmPrendGarant,FecUpCupo=@pmFecUpCupo
,CdPlazoComb=@pmCdPlazoComb,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,TipoCliente=@pmTipoCliente,FechaUpdate=@pmFechaUpdate,Restric_Cia=@pmRestric_Cia,CupoGalones=@pmCupoGalones,CodClieSicom=@pmCodClieSicom,FecPlazoDoc=@pmFecPlazoDoc,EdoRadicaDoc=@pmEdoRadicaDoc
,CdTipBloq=@pmCdTipBloq,DescEdoDoc=@pmDescEdoDoc,ComIndustrial=@pmComIndustrial,NumLista=@pmNumLista,Termicas=@pmTermicas,CodRetCom=@pmCodRetCom,CodCCosto=@pmCodCCosto,CodSubCosto=@pmCodSubCosto,CdDiaEnt=@pmCdDiaEnt,AutoIca=@pmAutoIca
 WHERE IdClie=@pmIdClie
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCliente] @pmIdClie VARCHAR(16)
 AS 
 SELECT IdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga
,IdSzona,IdGrupo,IdPlazo,CdPlazoComb,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv
,CdCms,PlazosImp,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie
,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,CdBandera,CodClieSicom,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo
,TipoCliente,CupoGalones,Restric_Cia,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,IdEstado,Inactivo,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca
,FechaAdd,FechaUpdate,IdUsuario
 FROM TercCliente
 WHERE IdClie=@pmIdClie
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliente_Sel] @pmIdClie VARCHAR(16),@pmNewIdClie VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdClie FROM  TercCliente WHERE  IdClie=@pmIdClie)
  INSERT INTO TercCliente (IdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga,IdSzona,IdGrupo,IdPlazo,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret
 ,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie,CodClieSicom,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,PlazosImp,IdEstado,TipoCliente,Inactivo,CdBandera,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo,FechaAdd,IdUsuario
,CupoGalones,Restric_Cia,CdPlazoComb,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca)
  SELECT @pmNewIdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga,IdSzona,IdGrupo,IdPlazo,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret
 ,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie,CodClieSicom,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,PlazosImp,IdEstado,TipoCliente,Inactivo,CdBandera,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo,FechaAdd,IdUsuario,CupoGalones,Restric_Cia,CdPlazoComb
,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca
  FROM  TercCliente 
  WHERE IdClie=@pmIdClie
GO
