CREATE TABLE AcuPrestamosLin ( 
IdReg INT IDENTITY ( 1,1 ) NOT NULL,
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdLinea VARCHAR(4) NOT NULL,
Concepto VARCHAR(10) NOT NULL,
SaldoAnt MONEY DEFAULT ((0)) NOT NULL,
TotalCargos MONEY DEFAULT ((0)) NOT NULL,
TotalAbonos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuPrestamosLin PRIMARY KEY NONCLUSTERED (IdReg),
 CONSTRAINT CK_AcuPrestamosLinConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_AcuPrestamosLinIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_AcuPrestamosLinIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuPrestamosLinIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_AcuPrestamosLinIdLinea CHECK ((len([IdLinea])>(0))))
CREATE TABLE tm_PreExto ( 
IdReg INT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
tmNumero INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCargos MONEY DEFAULT ((0)) NOT NULL,
tmAbonos MONEY DEFAULT ((0)) NOT NULL,
tmIdLinea VARCHAR(4) NOT NULL,
tmConcepto VARCHAR(10) NOT NULL,
tmDetalle VARCHAR(250),
tmReferencia VARCHAR(50),
tmCredito VARCHAR(10) NOT NULL,
tmVrPrestamo MONEY DEFAULT ((0)) NOT NULL,
tmVrCuota MONEY DEFAULT ((0)) NOT NULL,
tmTotAbonos MONEY DEFAULT ((0)) NOT NULL,
tmNCuota INT DEFAULT ((0)) NOT NULL,
tmIdVend VARCHAR(16) NOT NULL,
tmTimeSys SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME,
tmTipoAbono INT DEFAULT ((0)) NOT NULL,
tmDTF_EA DECIMAL(16,8) DEFAULT ((0)) NOT NULL,
tmTasaNom DECIMAL(16,8) DEFAULT ((0)) NOT NULL,
tmTasaEfe DECIMAL(16,8) DEFAULT ((0)) NOT NULL,
tmTipRef VARCHAR(3) DEFAULT ('0') NOT NULL,
tmDocRef INT DEFAULT ((0)) NOT NULL,
tmIdCiaRef CHAR(2) DEFAULT ('00') NOT NULL,
tmTipCom VARCHAR(3) NOT NULL,
tmComprobante INT DEFAULT ((0)) NOT NULL,
tmIdCiaCom CHAR(2) NOT NULL,
tmAnulado BIT DEFAULT ((0)) NOT NULL,
tmNumDev INT DEFAULT ((0)) NOT NULL,
tmFecDev SMALLDATETIME,
tmSanClie MONEY DEFAULT ((0)) NOT NULL,
tmSanCia MONEY DEFAULT ((0)) NOT NULL,
tmSanAgenc MONEY DEFAULT ((0)) NOT NULL,
tmSanAgeCia MONEY DEFAULT ((0)) NOT NULL,
tmSanLinea MONEY DEFAULT ((0)) NOT NULL,
tmSanLineaCia MONEY DEFAULT ((0)) NOT NULL,
tmSanConc MONEY DEFAULT ((0)) NOT NULL,
tmSanConcCia MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_PreExto PRIMARY KEY NONCLUSTERED (IdReg),
 CONSTRAINT CK_tm_PreExtotmConcepto CHECK ((len([tmConcepto])>(0))),
 CONSTRAINT CK_tm_PreExtotmCredito CHECK ((len([tmCredito])>(0))),
 CONSTRAINT CK_tm_PreExtotmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_PreExtotmIdAgencia CHECK ((len([tmIdAgencia])>(0))),
 CONSTRAINT CK_tm_PreExtotmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_PreExtotmIdCiaCom CHECK ((len([tmIdCiaCom])>(0))),
 CONSTRAINT CK_tm_PreExtotmIdCliente CHECK ((len([tmIdCliente])>(0))),
 CONSTRAINT CK_tm_PreExtotmIdLinea CHECK ((len([tmIdLinea])>(0))),
 CONSTRAINT CK_tm_PreExtotmIdVend CHECK ((len([tmIdVend])>(0))),
 CONSTRAINT CK_tm_PreExtotmTipCom CHECK ((len([tmTipCom])>(0))),
 CONSTRAINT CK_tm_PreExtotmTipDoc CHECK ((len([tmTipDoc])>(0))))
GO
ALTER TABLE AcuPrestamosLin ADD 
 CONSTRAINT FK_AcuPrestamosLin_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuPrestamosLin_LineasCred FOREIGN KEY (IdLinea) REFERENCES [dbo].[LineasCred] (IdLinea),
 CONSTRAINT FK_AcuPrestamosLin_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
 CREATE CLUSTERED INDEX IX_AcuPrestamosLinIdCliente ON AcuPrestamosLin(nAnno,nMes,IdCia,IdCliente,IdLinea)

CREATE CLUSTERED INDEX IX_tm_PreExtotmIdCliente ON tm_PreExto(tmIdCliente,tmIdAgencia,tmIdCia,tmIdLinea)
 CREATE NONCLUSTERED INDEX IX_tm_PreExtotmNumero ON tm_PreExto(tmTipDoc,tmNumero,tmIdCia)

INSERT INTO Sys_ObjetosApp (IdObj,IdGrupo,SubModulo,IndObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo)
 VALUES ('FRMLXPRE','PREINF','GEN',11,'Estado de Cuenta','FRMLXPRE','S',0,'')
