CREATE TABLE LogIntCias ( 
TipProc VARCHAR(10) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Estado INT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Nombre VARCHAR(50) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
TipoInt INT DEFAULT (0) NOT NULL,
FechaInicial SMALLDATETIME,
FechaFinal SMALLDATETIME,
Documentos VARCHAR(100),
Comprobantes VARCHAR(100),
Consolidado BIT DEFAULT (0) NOT NULL,
SobParam BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_LogIntCias PRIMARY KEY CLUSTERED (TipProc,Numero),
 CONSTRAINT CK_LogIntCiasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_LogIntCiasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_LogIntCiasNombre CHECK ((len([Nombre]) > 0)),
 CONSTRAINT CK_LogIntCiasTipProc CHECK ((len([TipProc]) > 0)))
CREATE TABLE LogIntExporta ( 
TipProc VARCHAR(10) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
NomTabla VARCHAR(20) NOT NULL,
NumInicial INT DEFAULT (0) NOT NULL,
NumFinal INT DEFAULT (0) NOT NULL,
Cantidad INT DEFAULT (0) NOT NULL,
EstadoDoc INT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250) NOT NULL
 CONSTRAINT PK_LogIntExporta PRIMARY KEY CLUSTERED (TipProc,Numero,NomTabla),
 CONSTRAINT CK_LogIntExportaNomTabla CHECK ((len([NomTabla]) > 0)),
 CONSTRAINT CK_LogIntExportaObservacion CHECK ((len([Observacion]) > 0)),
 CONSTRAINT CK_LogIntExportaTipProc CHECK ((len([TipProc]) > 0)))
CREATE TABLE LogIntImporta ( 
TipProc VARCHAR(10) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoReg INT DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
NumDoc INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) NOT NULL,
NomTabla VARCHAR(20) NOT NULL,
NivelRel INT DEFAULT (0) NOT NULL,
EstValida INT DEFAULT (0) NOT NULL,
EstadoReg INT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
PkFields VARCHAR(50),
PkTypes VARCHAR(50),
PkValues VARCHAR(100),
NuevoId VARCHAR(50),
Reemplazar BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_LogIntImporta PRIMARY KEY CLUSTERED (TipProc,Numero,Item),
 CONSTRAINT CK_LogIntImportaIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_LogIntImportaNomTabla CHECK ((len([NomTabla]) > 0)),
 CONSTRAINT CK_LogIntImportaTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_LogIntImportaTipProc CHECK ((len([TipProc]) > 0)))
GO


CREATE PROCEDURE paInsLogIntCias @pmTipProc VARCHAR(10),@pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmEstado INT,@pmIdUsuario VARCHAR(11),@pmNombre VARCHAR(50)
,@pmTimeSys SMALLDATETIME,@pmTipoInt INT,@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmDocumentos VARCHAR(100),@pmComprobantes VARCHAR(100),@pmConsolidado BIT
,@pmSobParam BIT
 AS 
 INSERT INTO LogIntCias (TipProc,Numero,IdCia,Fecha,Estado,IdUsuario,Nombre,TimeSys,TipoInt,FechaInicial,FechaFinal,Documentos,Comprobantes,Consolidado,SobParam)
 VALUES (@pmTipProc,@pmNumero,@pmIdCia,@pmFecha,@pmEstado,@pmIdUsuario,@pmNombre,@pmTimeSys,@pmTipoInt,@pmFechaInicial,@pmFechaFinal,@pmDocumentos,@pmComprobantes,@pmConsolidado,@pmSobParam)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntExporta @pmTipProc VARCHAR(10),@pmNumero INT,@pmNomTabla VARCHAR(20),@pmNumInicial INT,@pmNumFinal INT
,@pmCantidad INT,@pmEstadoDoc INT,@pmObservacion VARCHAR(250)
 AS 
 INSERT INTO LogIntExporta (TipProc,Numero,NomTabla,NumInicial,NumFinal,Cantidad,EstadoDoc,Observacion)
 VALUES (@pmTipProc,@pmNumero,@pmNomTabla,@pmNumInicial,@pmNumFinal,@pmCantidad,@pmEstadoDoc,@pmObservacion)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogIntImporta @pmTipProc VARCHAR(10),@pmNumero INT,@pmItem INT,@pmTipoReg INT,@pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCiaDoc CHAR(2)
,@pmNomTabla VARCHAR(20),@pmNivelRel INT,@pmEstValida INT,@pmEstadoReg INT,@pmObservacion VARCHAR(250),@pmPkFields VARCHAR(50),@pmPkTypes VARCHAR(50)
,@pmPkValues VARCHAR(100),@pmNuevoId VARCHAR(50),@pmReemplazar BIT
 AS 
 INSERT INTO LogIntImporta (TipProc,Numero,Item,TipoReg,TipDoc,NumDoc,IdCiaDoc,NomTabla,NivelRel,EstValida,EstadoReg,Observacion,PkFields,PkTypes,PkValues,NuevoId,Reemplazar)
 VALUES (@pmTipProc,@pmNumero,@pmItem,@pmTipoReg,@pmTipDoc,@pmNumDoc,@pmIdCiaDoc,@pmNomTabla,@pmNivelRel,@pmEstValida,@pmEstadoReg,@pmObservacion
,@pmPkFields,@pmPkTypes,@pmPkValues,@pmNuevoId,@pmReemplazar)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

CREATE NONCLUSTERED INDEX IX_LogIntCiasFecha ON LogIntCias(Fecha)
ALTER TABLE LogIntExporta ADD 
 CONSTRAINT FK_LogIntExporta_LogIntCias FOREIGN KEY (TipProc,Numero) REFERENCES [dbo].[LogIntCias] (TipProc,Numero)
ALTER TABLE LogIntImporta ADD 
 CONSTRAINT FK_LogIntImporta_LogIntCias FOREIGN KEY (TipProc,Numero) REFERENCES [dbo].[LogIntCias] (TipProc,Numero)
 CREATE NONCLUSTERED INDEX IX_LogIntImportaNumDoc ON LogIntImporta(TipDoc,NumDoc,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_LogIntImportaNomTabla ON LogIntImporta(NomTabla)

SET QUOTED_IDENTIFIER ON 

SET ANSI_NULLS OFF 