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

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

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPrestFact @pmNumero INT,@pmFecha SMALLDATETIME,@pmTipoProc VARCHAR(10),@pmEstadoProc INT
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogPrestFact (Numero,Fecha,TipoProc,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre)
 VALUES (@pmNumero,@pmFecha,@pmTipoProc,@pmEstadoProc,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPrestFactDet @pmNumero INT,@pmItem INT,@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItemCuo INT,@pmNumCuota INT,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrTotal MONEY
,@pmTasaEfeMes DECIMAL(16,8),@pmTasaEfeDia DECIMAL(16,8),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmConcepto VARCHAR(10),@pmCodLinCred VARCHAR(4),@pmFecInicio SMALLDATETIME
,@pmFecFinal SMALLDATETIME,@pmDiasLiquida DECIMAL(14,4),@pmEstado INT,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmReferencia VARCHAR(50),@pmComentario VARCHAR(250),@pmNomCliente VARCHAR(150)
 AS 
 INSERT INTO LogPrestFactDet (Numero,Item,TipDoc,IdPrestamo,IdCia,ItemCuo,NumCuota,Fecha,FecVence,VrTotal,TasaEfeMes,TasaEfeDia,IdCliente,IdAgencia,IdVend,Concepto,CodLinCred,FecInicio,FecFinal,DiasLiquida,Estado,TipFac,Factura,IdCiaFac,FechaFac,Referencia,Comentario,NomCliente)
 VALUES (@pmNumero,@pmItem,@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItemCuo,@pmNumCuota,@pmFecha,@pmFecVence,@pmVrTotal,@pmTasaEfeMes,@pmTasaEfeDia,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmConcepto,@pmCodLinCred
,@pmFecInicio,@pmFecFinal,@pmDiasLiquida,@pmEstado,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFac,@pmReferencia,@pmComentario,@pmNomCliente)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

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

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPrestFactFmt @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT L.Numero AS NumReg,L.Fecha AS FecProc,TipoProc,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre
,Item,TipDoc,IdPrestamo,IdCia,ItemCuo,NumCuota,D.Fecha AS FecCausac,FecVence,VrTotal,TasaEfeMes,TasaEfeDia,IdCliente,IdAgencia,IdVend,Concepto,CodLinCred
,FecInicio,FecFinal,DiasLiquida,Estado,TipFac,Factura,IdCiaFac,FechaFac,Referencia,Comentario,NomCliente
 FROM LogPrestFact AS L LEFT JOIN LogPrestFactDet AS D ON L.Numero=D.Numero
 WHERE L.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

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

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogPrestRecFmt @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT  R.Numero AS NumReg,Fecha,FechaArc,EstadoProc,Observacion,NomArchivo,TimeSys,IdUsuario,Nombre
,Item,FechaLiq,IdCliente,NomCliente,ValorRec,TipoPrest,Referencia,Estado,NumRecibo,IdCiaRec,FechaRec
,DescRegistro,Comentario 
 FROM   LogPrestRec AS R LEFT JOIN LogPrestRecDet AS D ON R.Numero=D.Numero
 WHERE R.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
 ORDER BY R.Numero,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

