ALTER TABLE Trn_TraRemesa  ADD SerieGuia CHAR(2) DEFAULT ('00') NOT NULL,
NumGuia INT DEFAULT (0) NOT NULL,CdForma VARCHAR(4),NumCausac INT DEFAULT (0) NOT NULL
,CdCiaCausac CHAR(2),EdoCausac INT DEFAULT (0) NOT NULL
GO
ALTER TABLE Trn_TraRemAnexo ADD NitEmpTransp VARCHAR(16),NumFactEmp VARCHAR(20)
GO
ALTER TABLE Trn_TraManifiesto ADD TipCom VARCHAR(3) DEFAULT ('0') NOT NULL
,Comprobante INT DEFAULT (0) NOT NULL,IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL
GO
CREATE TABLE Trn_TraTalonarios ( 
IdTalonario INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NumSerie CHAR(2) NOT NULL,
NumInicial INT DEFAULT (0) NOT NULL,
NumFinal INT DEFAULT (0) NOT NULL,
NumAuto BIT DEFAULT (0) NOT NULL,
NumActual INT DEFAULT (0) NOT NULL,
IdRespons VARCHAR(16),
NomRespons VARCHAR(150),
Anulado BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraTalonarios PRIMARY KEY CLUSTERED (IdTalonario),
 CONSTRAINT CK_Trn_TraTalonariosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraTalonariosNumSerie CHECK ((len([NumSerie]) > 0)))
CREATE TABLE tm_TraCentrega ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipRem VARCHAR(3) NOT NULL,
tmRemesa INT DEFAULT (0) NOT NULL,
tmIdCiaRem CHAR(2) NOT NULL,
tmVrTotal MONEY DEFAULT (0) NOT NULL,
tmVrCosto MONEY DEFAULT (0) NOT NULL,
tmVrDeclarado MONEY DEFAULT (0) NOT NULL,
tmVrSeguro MONEY DEFAULT (0) NOT NULL,
tmTipoVehic VARCHAR(10) NOT NULL,
tmCdConc VARCHAR(4),
tmCdCuenta VARCHAR(16),
tmCdCueIng VARCHAR(16),
tmCdCueSeg VARCHAR(16),
tmCdCueOcg VARCHAR(16),
tmCdCueOdc VARCHAR(16),
tmCdCiudad VARCHAR(8)
 CONSTRAINT PK_tm_TraCentrega PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraCentregatmIdCiaRem CHECK ((len([tmIdCiaRem]) > 0)),
 CONSTRAINT CK_tm_TraCentregatmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraCentregatmTipoVehic CHECK ((len([tmTipoVehic]) > 0)),
 CONSTRAINT CK_tm_TraCentregatmTipRem CHECK ((len([tmTipRem]) > 0)))
CREATE TABLE Trn_TraReexpedido ( 
TipDoc VARCHAR(3) DEFAULT ('CRR') NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdEmpTrans VARCHAR(16) NOT NULL,
NumFactura VARCHAR(15) NOT NULL,
FecFactura SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteIca MONEY DEFAULT (0) NOT NULL,
VrOtrosCargos MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
TarifaImp DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(16,6) DEFAULT (0) NOT NULL,
CodTarImp VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
Referencia VARCHAR(50),
CxPagar BIT DEFAULT (0) NOT NULL,
CdPlazo VARCHAR(4),
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraReexpedido PRIMARY KEY CLUSTERED (TipDoc,Causacion,IdCia),
 CONSTRAINT CK_Trn_TraReexpedidoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoIdEmpTrans CHECK ((len([IdEmpTrans]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoNumFactura CHECK ((len([NumFactura]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraReexpedidoRem ( 
TipDoc VARCHAR(3) DEFAULT ('CRR') NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipRem VARCHAR(3) DEFAULT ('RMT') NOT NULL,
Remesa INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
FecRemesa SMALLDATETIME NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndVol VARCHAR(10) NOT NULL,
UndTarifa VARCHAR(10) DEFAULT ('PESO') NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
pVehiculo VARCHAR(10),
CedConductor VARCHAR(16)
 CONSTRAINT PK_Trn_TraReexpedidoRem PRIMARY KEY CLUSTERED (TipDoc,Causacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraReexpedidoRemDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemTipRem CHECK ((len([TipRem]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemUndTarifa CHECK ((len([UndTarifa]) > 0)),
 CONSTRAINT CK_Trn_TraReexpedidoRemUndVol CHECK ((len([UndVol]) > 0)))
CREATE TABLE Trn_TraDevReex ( 
TipDev VARCHAR(3) DEFAULT ('DRR') 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 ('CRR') NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdEmpTrans VARCHAR(16) NOT NULL,
NumFactura VARCHAR(15) NOT NULL,
FecFactura SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteIca MONEY DEFAULT (0) NOT NULL,
VrOtrosCargos MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraDevReex PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevReexIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdEmpTrans CHECK ((len([IdEmpTrans]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexModdDev CHECK (([ModdDev] = 'TOTAL' or [ModdDev] = 'PARCIAL')),
 CONSTRAINT CK_Trn_TraDevReexNumFactura CHECK ((len([NumFactura]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevReexTipDoc CHECK ((len([TipDoc]) > 0)))
GO
ALTER TABLE Trn_TraTalonarios ADD 
 CONSTRAINT FK_Trn_TraTalonarios_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Trn_TraTalonariosFecha ON Trn_TraTalonarios(Fecha)
ALTER TABLE Trn_TraReexpedido ADD 
 CONSTRAINT FK_Trn_TraReexpedido_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraReexpedido_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraReexpedido_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraReexpedido_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraReexpedido_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraReexpedido_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraReexpedido_Terceros FOREIGN KEY (IdEmpTrans) REFERENCES [dbo].[Terceros] (IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_TraReexpedidoFecha ON Trn_TraReexpedido(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraReexpedidoIdEmpTrans ON Trn_TraReexpedido(IdEmpTrans)
 CREATE NONCLUSTERED INDEX IX_Trn_TraReexpedidoNumFactura ON Trn_TraReexpedido(NumFactura)
 CREATE NONCLUSTERED INDEX IX_Trn_TraReexpedidoComprobante ON Trn_TraReexpedido(TipCom,Comprobante,IdCiaCom)
ALTER TABLE Trn_TraReexpedidoRem ADD 
 CONSTRAINT FK_Trn_TraReexpedidoRem_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_TraReexpedidoRem_Sys_Um1 FOREIGN KEY (UndVol) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_TraReexpedidoRem_Trn_TraReexpedido FOREIGN KEY (TipDoc,Causacion,IdCia) REFERENCES [dbo].[Trn_TraReexpedido] (TipDoc,Causacion,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraReexpedidoRemRemesa ON Trn_TraReexpedidoRem(TipRem,Remesa,IdCiaRem)
ALTER TABLE Trn_TraDevReex ADD 
 CONSTRAINT FK_Trn_TraDevReex_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevReex_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevReex_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevReex_Companias2 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevReex_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevReex_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevReex_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevReex_Terceros FOREIGN KEY (IdEmpTrans) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevReex_Trn_TraReexpedido FOREIGN KEY (TipDoc,Causacion,IdCiaDoc) REFERENCES [dbo].[Trn_TraReexpedido] (TipDoc,Causacion,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevReexFecha ON Trn_TraDevReex(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevReexCausacion ON Trn_TraDevReex(TipDoc,Causacion,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevReexFecDoc ON Trn_TraDevReex(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevReexIdEmpTrans ON Trn_TraDevReex(IdEmpTrans)
--modificacion de check
ALTER TABLE Trn_TraAnticipos DROP CONSTRAINT CK_Trn_TraAnticiposModalidad
GO
ALTER TABLE Trn_TraAnticipos ADD CONSTRAINT CK_Trn_TraAnticiposModalidad CHECK (([Modalidad] = 'C_ENTREGA' or ([Modalidad] = 'EGRESO' or [Modalidad] = 'COMBUSTBLE')))
GO
