ALTER TABLE Trn_MudOrdenServ ADD EstadoBod INT DEFAULT(0) NOT NULL,CdBodega VARCHAR(4),FechaIngBod SMALLDATETIME,FechaRetBod SMALLDATETIME
GO
ALTER TABLE Trn_MudOrdenConc ADD TarifSeguro DECIMAL(14,4) DEFAULT(0) NOT NULL,CodTarSeg VARCHAR(4)
GO
ALTER TABLE ConcDiversos ADD RubroConc VARCHAR(50)
GO
ALTER TABLE Trn_MudOrdenOper ADD PlacaVehic VARCHAR(10)
GO
ALTER TABLE Trn_MudInventDet ADD CantSalida DECIMAL(14,4) DEFAULT(0) NOT NULL
GO
ALTER TABLE Trn_TraManifIntMcia ADD DescripUnid VARCHAR(500)
ALTER TABLE Trn_TraPorteIntMcia ADD DescripUnid VARCHAR(500)
ALTER TABLE Trn_TraDecMcia ADD DescripUnid VARCHAR(500)
GO
ALTER TABLE Trn_TraPorteInt ADD Negociacion VARCHAR(1000)
ALTER TABLE Trn_TraDecAduana ADD Negociacion VARCHAR(1000)
ALTER TABLE Trn_TraManifInt ADD Negociacion VARCHAR(1000)
GO
ALTER TABLE Companias ADD AutoIca BIT DEFAULT(0) NOT NULL
GO
CREATE TABLE Trn_MudContratos ( 
TipDoc VARCHAR(3) DEFAULT ('CAB') NOT NULL,
NumContrato INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaInicio SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdBodega2 VARCHAR(4),
VrServicio MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrDeclarado MONEY DEFAULT ((0)) NOT NULL,
VrSeguro MONEY DEFAULT ((0)) NOT NULL,
TipOrden VARCHAR(3) DEFAULT ('0') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrden CHAR(2) DEFAULT ('01') NOT NULL,
FechaRetiro SMALLDATETIME,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2500),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_MudContratos PRIMARY KEY CLUSTERED (TipDoc,NumContrato,IdCia),
 CONSTRAINT CK_Trn_MudContratosIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdCiaOrden CHECK ((len([IdCiaOrden])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_MudContratosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MudContratosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_MudContratosTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudContratosTipOrden CHECK ((len([TipOrden])>(0))))
GO
CREATE TABLE Trn_MudContConc ( 
TipDoc VARCHAR(3) DEFAULT ('CAB') NOT NULL,
NumContrato INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoRubro VARCHAR(20) NOT NULL,
CdCuenta VARCHAR(16),
CodTarIva VARCHAR(4),
CodTarSeg VARCHAR(4)
 CONSTRAINT PK_Trn_MudContConc PRIMARY KEY CLUSTERED (TipDoc,NumContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MudContConcDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_MudContConcIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudContConcIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_MudContConcTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudContConcTipoRubro CHECK ((len([TipoRubro])>(0))))
GO
CREATE TABLE Trn_MudContNov ( 
TipDoc VARCHAR(3) DEFAULT ('CAB') NOT NULL,
NumContrato INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipoNov VARCHAR(10) NOT NULL,
Descripcion VARCHAR(500),
TarifaServ DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
TipInv VARCHAR(3),
NumInvent INT DEFAULT ((0)) NOT NULL,
CdCiaInv CHAR(2),
ItemInv INT DEFAULT ((0)) NOT NULL,
CdArticulo VARCHAR(16),
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdEstado VARCHAR(4),
CdBodega VARCHAR(4),
CdBodDest VARCHAR(4),
NumDocRef VARCHAR(20),
IdUsuario VARCHAR(11) NOT NULL,
Notas VARCHAR(2500)
 CONSTRAINT PK_Trn_MudContNov PRIMARY KEY CLUSTERED (TipDoc,NumContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MudContNovIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudContNovIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MudContNovTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudContNovTipoNov CHECK ((len([TipoNov])>(0))))
GO
ALTER TABLE Trn_MudContratos ADD 
 CONSTRAINT FK_Trn_MudContratos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MudContratos_AlmBodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[AlmBodegas] (IdBodega),
 CONSTRAINT FK_Trn_MudContratos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MudContratos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MudContratos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_MudContratos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_MudContratos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)

 CREATE NONCLUSTERED INDEX IX_Trn_MudContratosFecha ON Trn_MudContratos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MudContratosFechaInicio ON Trn_MudContratos(FechaInicio)
 CREATE NONCLUSTERED INDEX IX_Trn_MudContratosIdCliente ON Trn_MudContratos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_MudContratosNumOrden ON Trn_MudContratos(TipOrden,NumOrden,IdCiaOrden)

ALTER TABLE Trn_MudContConc ADD 
 CONSTRAINT FK_Trn_MudContConc_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_MudContConc_Trn_MudContratos FOREIGN KEY (TipDoc,NumContrato,IdCia) REFERENCES [dbo].[Trn_MudContratos] (TipDoc,NumContrato,IdCia)

ALTER TABLE Trn_MudContNov ADD 
 CONSTRAINT FK_Trn_MudContNov_Trn_MudContratos FOREIGN KEY (TipDoc,NumContrato,IdCia) REFERENCES [dbo].[Trn_MudContratos] (TipDoc,NumContrato,IdCia)
