ALTER TABLE Trn_Entradas ADD TipSop VARCHAR(3),NumDocSop INT DEFAULT(0) NOT NULL,CdCiaSop CHAR(2) 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsEntradas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsEntradas]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpEntradas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpEntradas]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryEntradasLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryEntradasLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryEntradas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryEntradas]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryEntradasRel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryEntradasRel]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryEntradas_Cr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryEntradas_Cr]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_TraDetConc_Leg]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_TraDetConc_Leg]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_EdsFormasCue]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQrytm_EdsFormasCue]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradas_Cr]  @pmTipDoc VARCHAR(3),@pmEntradaIni INT,@pmEntradaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT E.TipDoc AS Tip_Doc,TipoDoc,Entrada,E.IdCia AS CdCia,Compania,E.Fecha AS FechaDoc,E.IdConcepto AS CdConcepto,Concepto,E.IdProv AS NitPrevee,RazonSocial,E.Factura AS NumFactura,FechaFac,FechaVence
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrImpCarbono,VrIvaIngProd,VrNeto
,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaIgp
,E.TarifaIva AS TarifIva,E.TarifaRet AS TarifRet,E.TarifaIca AS TarifIca,TarifaRiv,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons
,E.CdCCosto AS CodCenCosto,CC.CCosto AS CentCosto,E.CdSubCos AS CodSubCent,SC.SubCosto AS SubcCosto,E.TipEgr,E.Egreso,E.IdCiaEgr,E.Modalidad,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop
,E.TipCom,TipoCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.NumDev,E.FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,E.OrigenAdd,E.TimeSys AS Fec_add,E.FecUpdate AS Fec_Update,E.IdCiaCrea,E.IdUsuario AS CdUsuario,Usuario,Leyenda
--Información del tercero
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
--Detalle
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo,K.Referencia AS KarReferencia,Descripcion,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,K.Factura AS KarFactura,K.TipDocDev,K.NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,K.CdMoneda,K.VrTasaCamb,K.VrDivisa1,K.VrDivisa2,K.VrDivisa3,Referencia2,FecOrden,CodTarIco,TarifaIco,VrImpCon,TarifaStc,SobtasaCons,VrImvCosto,K.BaseIvp,K.TarifaIvp,K.IvaIngProd
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
--datos memo
,Comentarios,CantImp
--datos de resolucion doc. equivalente
,DS.CodRes,DS.DescServicio,RS.Resolucion,RS.Prefijo,RS.NumInicial,RS.NumFinal,RS.FechaExpRes,RS.FechaVigencia,RS.Establecimiento
 FROM Trn_Entradas AS E INNER JOIN Trn_Kardex AS K ON E.TipDoc=K.TipDoc AND E.Entrada=K.Documento AND E.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON E.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN TiposCom AS TC ON E.TipCom=TC.IdCom
 LEFT JOIN CentroCosto AS CC ON E.CdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON E.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON E.IdProv=TP.IdProv 
 LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 LEFT JOIN Trn_DocMemo AS MM ON E.TipDoc=MM.TipDoc AND E.Entrada=MM.Documento AND E.IdCia=MM.IdCia
 --datos de resolucion
 LEFT JOIN Trn_DocSoporte DS ON E.TipSop=DS.TipDoc AND E.NumDocSop=DS.NumDoc AND E.CdCiaSop=DS.IdCia
 LEFT JOIN TiposComRes AS RS ON DS.CodRes=RS.IdRes
 WHERE E.TipDoc=@pmTipDoc AND Entrada BETWEEN @pmEntradaIni AND @pmEntradaFin  AND E.IdCia=@pmIdCia
 ORDER BY Entrada,Item
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmCxPagar BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Entrada,E.IdCia AS CdCia,Compania,Fecha,E.IdConcepto AS CdConcepto,Concepto,E.IdProv AS NitPrevee,RazonSocial,Factura,FechaFac,FechaVence
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrImpCarbono,VrIvaIngProd,VrNeto
,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaIgp
,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons,CdCCosto,CCosto,CdSubCos,SubCosto,TipEgr,Egreso,IdCiaEgr,Modalidad
,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,TimeSys,E.FecUpdate AS Fec_Update,IdCiaCrea,E.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_Entradas AS E INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN CentroCosto AS CC ON E.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON E.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON E.IdProv=TP.IdProv LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
  AND E.IdCia LIKE ISNULL(@pmIdCia,'%%') AND E.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND E.IdProv LIKE ISNULL(@pmIdProv,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (CxPagar=ISNULL(@pmCxPagar,0) or CxPagar=ISNULL(@pmCxPagar,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY E.IdCia,Entrada
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetConc_Leg]  @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetConc (tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos,tmpVehiculo
,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb)
 SELECT @pmtmNumero,Item,IdConcepto,DescConcepto,RubroConc,VrDebito,VrCredito,IdCuenta,IdTercero,CdCCosto,CdSubCos,pVehiculo
,'TERCEROS',VrBase,TarifBase,RefConcep,TipSop,NumSoporte,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodAgncia,CantComb
 FROM Trn_TraLiqDetalle
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmEntradaIni INT=Null,@pmEntradaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Entrada,IdCia,Fecha,E.IdConcepto AS CdConcepto,Concepto,IdProv,RazonSocial,Factura,FechaFac,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros
,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrBomberil,VrIvaIngProd,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,IdPlazo,CxPagar,DocEquiv
,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaBom,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarifBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono
,CdCCosto,CdSubCos,TipEgr,Egreso,IdCiaEgr,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,VrImpuCons,VrSobtasaCons,Modalidad,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,E.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_Entradas AS E INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero
 INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Entrada BETWEEN ISNULL(@pmEntradaIni,0) AND ISNULL(@pmEntradaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%') AND E.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Entrada
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmNitFletes VARCHAR(16),@pmTipOdc VARCHAR(3)
,@pmOCompra INT,@pmIdCiaOdc CHAR(2),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmDocEquiv VARCHAR(3),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4)
,@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT
,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrRetFlete MONEY,@pmVrIcaFlete MONEY,@pmCodTarRetFle VARCHAR(4),@pmCodTarIcaFle VARCHAR(4),@pmFletesCosto BIT,@pmVrIvaMvc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmCodTarifBom VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4)
,@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmTipoSA VARCHAR(3),@pmNumSalAlm INT,@pmCdCiaSA CHAR(2),@pmVrImpuCons MONEY,@pmVrSobtasaCons MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmTipSop VARCHAR(3),@pmNumDocSop INT,@pmCdCiaSop CHAR(2)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Entradas (TipDoc,Entrada,IdCia,Fecha,IdConcepto,IdProv,Factura,FechaFac,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,IdPlazo,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva
,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CdCCosto,CdSubCos,TipEgr,Egreso,IdCiaEgr,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,TipoSA,NumSalAlm,CdCiaSA,VrImpuCons,VrSobtasaCons,BaseIvaIgp,VrIvaIngProd,TipSop,NumDocSop,CdCiaSop)
 VALUES (@pmTipDoc,@pmEntrada,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdProv,@pmFactura,@pmFechaFac,@pmFechaVence,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrOtros,@pmVrSobretasa,@pmVrImpGlobal,@pmVrCargos,@pmVrOtrDcto,@pmVrNeto,@pmCantidad,@pmNitFletes
, @pmVrRetFlete,@pmVrIcaFlete,@pmCodTarRetFle,@pmCodTarIcaFle,@pmFletesCosto,@pmTipOdc,@pmOCompra,@pmIdCiaOdc,@pmMulPlazos,@pmIdPlazo,@pmCxPagar,@pmDocEquiv,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmCdCCosto,@pmCdSubCos,@pmTipEgr,@pmEgreso,@pmIdCiaEgr,@pmModalidad,@pmOrigenAdd
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrIvaMvc,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmCodTarifBom,@pmVrBomberil,@pmTarifaBom,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmVrImpCarbono,@pmTipoSA,@pmNumSalAlm,@pmCdCiaSA,@pmVrImpuCons,@pmVrSobtasaCons,@pmBaseIvaIgp,@pmVrIvaIngProd,@pmTipSop,@pmNumDocSop,@pmCdCiaSop)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY
,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmNitFletes VARCHAR(16),@pmTipOdc VARCHAR(3),@pmOCompra INT,@pmIdCiaOdc CHAR(2)
,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmDocEquiv VARCHAR(3),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4)
,@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrRetFlete MONEY,@pmVrIcaFlete MONEY,@pmCodTarRetFle VARCHAR(4),@pmCodTarIcaFle VARCHAR(4),@pmFletesCosto BIT,@pmVrIvaMvc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4)
,@pmCodTarifBom VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmTipoSA VARCHAR(3),@pmNumSalAlm INT,@pmCdCiaSA CHAR(2),@pmVrImpuCons MONEY,@pmVrSobtasaCons MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY
,@pmTipSop VARCHAR(3),@pmNumDocSop INT,@pmCdCiaSop CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Entradas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdProv=@pmIdProv,Factura=@pmFactura,FechaFac=@pmFechaFac,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes
,VrOtros=@pmVrOtros,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,NitFletes=@pmNitFletes,TipOdc=@pmTipOdc,OCompra=@pmOCompra,IdCiaOdc=@pmIdCiaOdc,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CxPagar=@pmCxPagar,DocEquiv=@pmDocEquiv
,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,TipEgr=@pmTipEgr
,Egreso=@pmEgreso,IdCiaEgr=@pmIdCiaEgr,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,VrRetFlete=@pmVrRetFlete,VrIcaFlete=@pmVrIcaFlete,CodTarRetFle=@pmCodTarRetFle,CodTarIcaFle=@pmCodTarIcaFle,FletesCosto=@pmFletesCosto,VrIvaMvc=@pmVrIvaMvc,FecUpdate=@pmFecUpdate,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,CodTarifBom=@pmCodTarifBom,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom
,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,VrImpCarbono=@pmVrImpCarbono,TipoSA=@pmTipoSA,NumSalAlm=@pmNumSalAlm,CdCiaSA=@pmCdCiaSA,VrImpuCons=@pmVrImpuCons,VrSobtasaCons=@pmVrSobtasaCons,BaseIvaIgp=@pmBaseIvaIgp,VrIvaIngProd=@pmVrIvaIngProd,TipSop=@pmTipSop,NumDocSop=@pmNumDocSop,CdCiaSop=@pmCdCiaSop
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Entrada,IdCia,Fecha,IdConcepto,IdProv,Factura,FechaFac,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,BaseIvaIgp,VrIvaIngProd
,TipOdc,OCompra,IdCiaOdc,MulPlazos,IdPlazo,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv
,CdCCosto,CdSubCos,TipEgr,Egreso,IdCiaEgr,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion
,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,VrImpuCons,VrSobtasaCons
,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop
 FROM Trn_Entradas
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasCue] @pmtmNumero VARCHAR(5),@pmIdConcepto VARCHAR(4)
AS 
 SELECT tmIdForma,IdConcepto,IdCuenta
FROM tm_EdsFormas AS EF LEFT JOIN FormasCue AS F ON EF.tmIdForma=F.IdForma
WHERE tmNumero=@pmtmNumero AND tmCredito=0
AND (ISNULL(IdConcepto,'')=@pmIdConcepto OR tmTipoRango='TKT')
GO
