CREATE TABLE Trn_TraDevCum ( 
TipDev VARCHAR(3) DEFAULT ('DCU') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('CUM') NOT NULL,
Cumplido INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraDevCum PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevCumIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDevCumIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraDevCumIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraDevCumIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_TraDevCumIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraDevCumIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraDevCumModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_TraDevCumOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraDevCumTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraDevCumTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_TraDevCumTipDoc CHECK ((len([TipDoc])>(0))))
GO
ALTER TABLE Trn_TraDevCum ADD 
 CONSTRAINT FK_Trn_TraDevCum_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevCum_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevCum_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevCum_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevCum_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevCum_Trn_TraCumplido FOREIGN KEY (TipDoc,Cumplido,IdCiaDoc) REFERENCES [dbo].[Trn_TraCumplido] (TipDoc,Cumplido,IdCia)

INSERT INTO Sys_TiposDoc (IdDoc,TipoDoc,ConsUnico,Leyenda,Inactivo,IntegraCias)
 VALUES ('DCU','DEVOLUCION DE CUMPLIDOS',0,'',0,0)
GO
INSERT INTO Sys_TiposDocCue (IdDoc,IdClase,ClaseCuenta,TipoMov)
 VALUES ('DCU',1,'INGRESOS RECIBIDOS PARA TERCEROS','D')
INSERT INTO Sys_TiposDocCue (IdDoc,IdClase,ClaseCuenta,TipoMov)
 VALUES ('DCU',2,'CLIENTES','C')
INSERT INTO Sys_TiposDocCue (IdDoc,IdClase,ClaseCuenta,TipoMov)
 VALUES ('DCU',8,'INGRESOS VEHICULOS PROPIOS','D')
INSERT INTO Sys_TiposDocCue (IdDoc,IdClase,ClaseCuenta,TipoMov)
 VALUES ('DCU',13,'INGRESOS VEHICULOS TERCEROS','D')
GO