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

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

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

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

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

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

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

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

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntegra @pmNumero INT,@pmFecha SMALLDATETIME,@pmEstadoLog INT
,@pmComentarios VARCHAR(250),@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogIntegra (Numero,Fecha,EstadoLog,Comentarios,IdUsuario,Nombre)
 VALUES (@pmNumero,@pmFecha,@pmEstadoLog,@pmComentarios,@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 paInsLogIntegraDet @pmNumero INT,@pmItem INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFechaDoc SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmEstado INT,@pmIdTercero VARCHAR(16)
,@pmNomCia VARCHAR(50),@pmNomTercero VARCHAR(150)
 AS 
 INSERT INTO LogIntegraDet (Numero,Item,TipDoc,Documento,IdCia,FechaDoc,TipCom,Comprobante,IdCiaCom,Observacion,Estado,IdTercero,NomCia,NomTercero)
 VALUES (@pmNumero,@pmItem,@pmTipDoc,@pmDocumento,@pmIdCia,@pmFechaDoc,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion
,@pmEstado,@pmIdTercero,@pmNomCia,@pmNomTercero)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogFactAuto @pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmCriterios VARCHAR(100)
,@pmConcepto VARCHAR(100),@pmPlazo VARCHAR(30),@pmVendedor VARCHAR(50),@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY
,@pmVrFletes MONEY,@pmVrNeto MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50),@pmObservacion VARCHAR(250)
 AS 
 INSERT INTO LogFactAuto (Numero,IdCia,Fecha,Criterios,Concepto,Plazo,Vendedor,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA
,VrCargos,VrOtrDcto,VrFletes,VrNeto,TimeSys,IdUsuario,Nombre,Observacion)
 VALUES (@pmNumero,@pmIdCia,@pmFecha,@pmCriterios,@pmConcepto,@pmPlazo,@pmVendedor,@pmVrSubTotal,@pmVrDescuento
,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCargos,@pmVrOtrDcto,@pmVrFletes,@pmVrNeto,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmObservacion)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogFactDetalle @pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaVence SMALLDATETIME
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCiudad VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmNomCiaFact VARCHAR(50),@pmNomCliente VARCHAR(150),@pmNomVend VARCHAR(150),@pmNomAgencia VARCHAR(50),@pmDetalles VARCHAR(100)
 AS 
 INSERT INTO LogFactDetalle (Numero,IdCia,Item,TipDoc,Factura,IdCiaFac,FechaVence,IdCliente,IdAgencia,IdVend,TarifaCom,Ciudad,TipCom,Comprobante,IdCiaCom,NomCiaFact,NomCliente,NomVend,NomAgencia,Detalles)
 VALUES (@pmNumero,@pmIdCia,@pmItem,@pmTipDoc,@pmFactura,@pmIdCiaFac,@pmFechaVence,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmTarifaCom,@pmCiudad
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmNomCiaFact,@pmNomCliente,@pmNomVend,@pmNomAgencia,@pmDetalles)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogFactAuto @pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT Numero,IdCia,Fecha,Criterios,Concepto,Plazo,Vendedor,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrFletes,VrNeto,TimeSys,IdUsuario,Nombre,Observacion
 FROM LogFactAuto
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogRetiros @pmTipoProc VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
 AS 
 INSERT INTO LogRetiros (TipoProc,Numero,Fecha,Observacion,TimeSys,IdUsuario,Nombre)
 VALUES (@pmTipoProc,@pmNumero,@pmFecha,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmNombre)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogRetirosProd @pmTipoProc VARCHAR(3),@pmNumero INT,@pmItem INT,@pmIdProducto VARCHAR(16)
,@pmDescripcion VARCHAR(150),@pmFecUltCompra SMALLDATETIME,@pmFecUltVenta SMALLDATETIME,@pmEstado INT,@pmCantExist DECIMAL(14,4)
 AS 
 INSERT INTO LogRetirosProd (TipoProc,Numero,Item,IdProducto,Descripcion,FecUltCompra,FecUltVenta,Estado,CantExist)
 VALUES (@pmTipoProc,@pmNumero,@pmItem,@pmIdProducto,@pmDescripcion,@pmFecUltCompra,@pmFecUltVenta,@pmEstado,@pmCantExist)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogRetiros @pmTipoProc VARCHAR(3),@pmNumero INT
 AS 
 SELECT TipoProc,Numero,Fecha,Observacion,TimeSys,IdUsuario,Nombre
 FROM LogRetiros
 WHERE TipoProc=@pmTipoProc AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

