ALTER TABLE dbo.ConcDiversos ADD OrdenServ INT DEFAULT(0) NOT NULL
GO
CREATE TABLE TarifasServ ( 
Numero INT IDENTITY ( 1,1 ) NOT NULL,
TipoServ INT DEFAULT ((0)) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdMercancia VARCHAR(16) NOT NULL,
IdEstacion VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('0') NOT NULL,
TipoAfiVehic VARCHAR(10),
CdTipoVeh VARCHAR(4),
TarifaClie DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
TarifaPago DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_TarifasServ PRIMARY KEY NONCLUSTERED (Numero),
 CONSTRAINT CK_TarifasServIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_TarifasServIdEstacion CHECK ((len([IdEstacion])>(0))),
 CONSTRAINT CK_TarifasServIdMercancia CHECK ((len([IdMercancia])>(0))),
 CONSTRAINT CK_TarifasServIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_TarifasServUndMed CHECK ((len([UndMed])>(0))))
GO
CREATE TABLE Trn_TraOrdenServ ( 
TipDoc VARCHAR(3) DEFAULT ('OST') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecRecibo SMALLDATETIME,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
nRemolque VARCHAR(10),
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
Modalidad VARCHAR(10) NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
VrCosto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
TipoOrden VARCHAR(10) NOT NULL,
IdEstacion VARCHAR(4) NOT NULL,
NomEstacion VARCHAR(50),
TipoResiduo VARCHAR(100),
RemCliente VARCHAR(30),
NomRecibido VARCHAR(150),
FecIngCertif SMALLDATETIME,
FecCertificado SMALLDATETIME,
NumRemesa INT DEFAULT ((0)) NOT NULL,
CdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
EstCumplido INT DEFAULT ((0)) NOT NULL,
EstFactura INT DEFAULT ((0)) NOT NULL,
TipFact VARCHAR(3),
NumFactura INT DEFAULT ((0)) NOT NULL,
CdCiaFact CHAR(2),
kmtInicial INT DEFAULT ((0)) NOT NULL,
kmtFinal INT DEFAULT ((0)) NOT NULL,
EstOrden INT DEFAULT ((0)) NOT NULL,
TipLiq VARCHAR(3),
NumLiquida INT DEFAULT ((0)) NOT NULL,
CdCiaLiq CHAR(2),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(1000),
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_TraOrdenServ PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_TraOrdenServCdCiaRem CHECK ((len([CdCiaRem])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdEstacion CHECK ((len([IdEstacion])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenServTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))))
GO
CREATE TABLE Trn_TraOrdenDet ( 
TipDoc VARCHAR(3) DEFAULT ('OST') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdMercancia VARCHAR(16) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
VrUnitario MONEY DEFAULT ((0)) NOT NULL,
TarifaPago MONEY DEFAULT ((0)) NOT NULL,
CantCump DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaCump MONEY DEFAULT ((0)) NOT NULL,
PagoCump MONEY DEFAULT ((0)) NOT NULL,
DocCliente VARCHAR(30)
 CONSTRAINT PK_Trn_TraOrdenDet PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenDetDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_TraOrdenDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenDetIdMercancia CHECK ((len([IdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenDetTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenDetUndMed CHECK ((len([UndMed])>(0))))
GO
CREATE TABLE tm_TraOst ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdMercancia VARCHAR(16) NOT NULL,
tmDescripcion VARCHAR(250) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmUndMed VARCHAR(10) NOT NULL,
tmVrUnitario MONEY DEFAULT ((0)) NOT NULL,
tmTarifPago MONEY DEFAULT ((0)) NOT NULL,
tmCantCump DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmTarifaCump MONEY DEFAULT ((0)) NOT NULL,
tmPagoCump MONEY DEFAULT ((0)) NOT NULL,
tmDocCliente VARCHAR(30)
 CONSTRAINT PK_tm_TraOst PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraOsttmDescripcion CHECK ((len([tmDescripcion])>(0))),
 CONSTRAINT CK_tm_TraOsttmIdMercancia CHECK ((len([tmIdMercancia])>(0))),
 CONSTRAINT CK_tm_TraOsttmNumero CHECK ((len([tmNumero])>(0))),
 CONSTRAINT CK_tm_TraOsttmUndMed CHECK ((len([tmUndMed])>(0))))
GO
CREATE TABLE Trn_TraOrdenAnt ( 
TipDoc VARCHAR(3) DEFAULT ('AOS') NOT NULL,
Anticipo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipOds VARCHAR(3) DEFAULT ('OSA') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOds CHAR(2) DEFAULT ('01') NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrAbonado MONEY DEFAULT ((0)) NOT NULL,
TipoPago VARCHAR(10) DEFAULT ('EFECTIVO') NOT NULL,
NumCheque VARCHAR(20),
FecCheque SMALLDATETIME,
IdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Beneficiario VARCHAR(150),
CedBenef VARCHAR(16),
FechaVence SMALLDATETIME,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') 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_TraOrdenAnt PRIMARY KEY CLUSTERED (TipDoc,Anticipo,IdCia),
 CONSTRAINT CK_Trn_TraOrdenAntIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdCiaOds CHECK ((len([IdCiaOds])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdCta CHECK ((len([IdCta])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntTipOds CHECK ((len([TipOds])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAntTipoPago CHECK ((len([TipoPago])>(0))))
GO
CREATE TABLE Trn_TraOrdenAbo ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipAnt VARCHAR(3) DEFAULT ('AOS') NOT NULL,
Anticipo INT DEFAULT ((0)) NOT NULL,
IdCiaAnt CHAR(2) NOT NULL,
VrAbono MONEY DEFAULT ((0)) NOT NULL,
TipoAplica VARCHAR(10) DEFAULT ('OPAGO') NOT NULL,
Observacion VARCHAR(250),
CodCuenta VARCHAR(16)
 CONSTRAINT PK_Trn_TraOrdenAbo PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenAboIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAboIdCiaAnt CHECK ((len([IdCiaAnt])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAboTipAnt CHECK ((len([TipAnt])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAboTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenAboTipoAplica CHECK ((len([TipoAplica])>(0))))
GO
CREATE TABLE Trn_TraDevAos ( 
TipDev VARCHAR(3) 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) NOT NULL,
Anticipo INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
VrDevolucion MONEY DEFAULT ((0)) NOT NULL,
CdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
CdCuenta VARCHAR(16) 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),
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_TraDevAos PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevAosCdCta CHECK ((len([CdCta])>(0))),
 CONSTRAINT CK_Trn_TraDevAosCdCuenta CHECK ((len([CdCuenta])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraDevAosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraDevAosModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_TraDevAosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraDevAosTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraDevAosTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_TraDevAosTipDoc CHECK ((len([TipDoc])>(0))))
GO
CREATE TABLE Trn_TraOrdenCum ( 
TipDoc VARCHAR(3) DEFAULT ('COS') NOT NULL,
Cumplido INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipOds VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOds CHAR(2) DEFAULT ('01') NOT NULL,
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecRecibo SMALLDATETIME,
FecIngCertif SMALLDATETIME,
FecCertificado SMALLDATETIME,
DescServicio VARCHAR(100),
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
VrCosto MONEY DEFAULT ((0)) NOT NULL,
RemCliente VARCHAR(30),
Funcionario VARCHAR(150),
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
NumDev INT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(1000),
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_TraOrdenCum PRIMARY KEY CLUSTERED (TipDoc,Cumplido,IdCia),
 CONSTRAINT CK_Trn_TraOrdenCumIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumIdCiaOds CHECK ((len([IdCiaOds])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumTipOds CHECK ((len([TipOds])>(0))))
GO
CREATE TABLE Trn_TraOrdenCumDet ( 
TipDoc VARCHAR(3) DEFAULT ('COS') NOT NULL,
Cumplido INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdMercancia VARCHAR(16) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
VrUnitario MONEY DEFAULT ((0)) NOT NULL,
TarifaPago MONEY DEFAULT ((0)) NOT NULL,
DocCliente VARCHAR(30)
 CONSTRAINT PK_Trn_TraOrdenCumDet PRIMARY KEY CLUSTERED (TipDoc,Cumplido,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenCumDetDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumDetIdMercancia CHECK ((len([IdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumDetTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenCumDetUndMed CHECK ((len([UndMed])>(0))))
GO
CREATE TABLE Trn_TraDevCos ( 
TipDev VARCHAR(3) 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) 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_TraDevCos PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevCosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDevCosIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraDevCosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraDevCosIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_TraDevCosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraDevCosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraDevCosModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_TraDevCosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraDevCosTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraDevCosTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_TraDevCosTipDoc CHECK ((len([TipDoc])>(0))))
GO
CREATE TABLE Trn_TraOrdenLiq ( 
TipDoc VARCHAR(3) DEFAULT ('LGO') NOT NULL,
Liquidacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipOds VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOds CHAR(2) DEFAULT ('01') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
VrCosto MONEY DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrGastos MONEY DEFAULT ((0)) NOT NULL,
VrIva MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteIca MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)),
VrReteIva MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaPago MONEY 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,
TarifaRiv DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
CodTarRtc VARCHAR(4),
Referencia VARCHAR(50),
CxPagar BIT DEFAULT ((0)) NOT NULL,
CdPlazo VARCHAR(4),
FechaVence SMALLDATETIME,
UndMed VARCHAR(10),
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(1000),
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_TraOrdenLiq PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia),
 CONSTRAINT CK_Trn_TraOrdenLiqIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdCiaOds CHECK ((len([IdCiaOds])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))),
 CONSTRAINT CK_Trn_TraOrdenLiqTipOds CHECK ((len([TipOds])>(0))))
GO
CREATE TABLE Trn_TraDevLgo ( 
TipDev VARCHAR(3) 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) NOT NULL,
Liquidacion INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
VrCosto MONEY DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrGastos MONEY DEFAULT ((0)) NOT NULL,
VrIva MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteIca MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)),
VrReteIva MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad 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(1000),
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_TraDevLgo PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevLgoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_TraDevLgoTipDoc CHECK ((len([TipDoc])>(0))))
GO
ALTER TABLE TarifasServ ADD 
 CONSTRAINT FK_TarifasServ_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TarifasServ_EdsServicio FOREIGN KEY (IdEstacion) REFERENCES [dbo].[EdsServicio] (IdEstacion),
 CONSTRAINT FK_TarifasServ_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_TarifasServ_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
 CREATE CLUSTERED INDEX IX_TarifasServIdCliente ON TarifasServ(IdCliente,IdMercancia,IdEstacion,UndMed)
ALTER TABLE Trn_TraOrdenServ ADD 
 CONSTRAINT FK_Trn_TraOrdenServ_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraOrdenServ_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenServ_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenServ_EdsServicio FOREIGN KEY (IdEstacion) REFERENCES [dbo].[EdsServicio] (IdEstacion),
 CONSTRAINT FK_Trn_TraOrdenServ_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraOrdenServ_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraOrdenServ_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenServ_Terceros1 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenServ_Terceros2 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenServFecha ON Trn_TraOrdenServ(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenServIdCliente ON Trn_TraOrdenServ(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenServIdPoseedor ON Trn_TraOrdenServ(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenServIdVehiculo ON Trn_TraOrdenServ(IdVehiculo)

ALTER TABLE Trn_TraOrdenDet ADD 
 CONSTRAINT FK_Trn_TraOrdenDet_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_TraOrdenDet_Trn_TraOrdenServ FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraOrdenServ] (TipDoc,NumOrden,IdCia)

ALTER TABLE Trn_TraOrdenAnt ADD 
 CONSTRAINT FK_Trn_TraOrdenAnt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraOrdenAnt_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenAnt_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenAnt_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraOrdenAnt_CtasCorrientes FOREIGN KEY (IdCta) REFERENCES [dbo].[CtasCorrientes] (IdCta),
 CONSTRAINT FK_Trn_TraOrdenAnt_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraOrdenAnt_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_TraOrdenAnt_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenAntFecha ON Trn_TraOrdenAnt(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenAntNumOrden ON Trn_TraOrdenAnt(TipOds,NumOrden,IdCiaOds)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenAntIdCta ON Trn_TraOrdenAnt(IdCta)

ALTER TABLE Trn_TraOrdenAbo ADD 
 CONSTRAINT FK_Trn_TraOrdenAbo_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenAbo_Trn_TraOrdenAnt FOREIGN KEY (TipAnt,Anticipo,IdCiaAnt) REFERENCES [dbo].[Trn_TraOrdenAnt] (TipDoc,Anticipo,IdCia)

ALTER TABLE Trn_TraDevAos ADD 
 CONSTRAINT FK_Trn_TraDevAos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevAos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevAos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevAos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevAos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevAos_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevAos_Trn_TraOrdenAnt FOREIGN KEY (TipDoc,Anticipo,IdCiaDoc) REFERENCES [dbo].[Trn_TraOrdenAnt] (TipDoc,Anticipo,IdCia)
CREATE NONCLUSTERED INDEX IX_Trn_TraDevAosFecha ON Trn_TraDevAos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevAosAnticipo ON Trn_TraDevAos(TipDoc,Anticipo,IdCiaDoc)

ALTER TABLE Trn_TraOrdenCum ADD 
 CONSTRAINT FK_Trn_TraOrdenCum_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraOrdenCum_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenCum_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenCum_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraOrdenCum_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraOrdenCum_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraOrdenCum_Trn_TraOrdenServ FOREIGN KEY (TipOds,NumOrden,IdCiaOds) REFERENCES [dbo].[Trn_TraOrdenServ] (TipDoc,NumOrden,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenCumFecha ON Trn_TraOrdenCum(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenCumNumOrden ON Trn_TraOrdenCum(TipOds,NumOrden,IdCiaOds)

ALTER TABLE Trn_TraOrdenCumDet ADD 
 CONSTRAINT FK_Trn_TraOrdenCumDet_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_TraOrdenCumDet_Trn_TraOrdenCum FOREIGN KEY (TipDoc,Cumplido,IdCia) REFERENCES [dbo].[Trn_TraOrdenCum] (TipDoc,Cumplido,IdCia)

ALTER TABLE Trn_TraDevCos ADD 
 CONSTRAINT FK_Trn_TraDevCos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevCos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevCos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevCos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevCos_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevCos_Trn_TraOrdenCum FOREIGN KEY (TipDoc,Cumplido,IdCiaDoc) REFERENCES [dbo].[Trn_TraOrdenCum] (TipDoc,Cumplido,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCosFecha ON Trn_TraDevCos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCosCumplido ON Trn_TraDevCos(TipDoc,Cumplido,IdCiaDoc)

ALTER TABLE Trn_TraOrdenLiq ADD 
 CONSTRAINT FK_Trn_TraOrdenLiq_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraOrdenLiq_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenLiq_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenLiq_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraOrdenLiq_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraOrdenLiq_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraOrdenLiq_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenLiq_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenLiq_Trn_TraOrdenServ FOREIGN KEY (TipOds,NumOrden,IdCiaOds) REFERENCES [dbo].[Trn_TraOrdenServ] (TipDoc,NumOrden,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenLiqFecha ON Trn_TraOrdenLiq(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenLiqNumOrden ON Trn_TraOrdenLiq(TipOds,NumOrden,IdCiaOds)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenLiqIdVehiculo ON Trn_TraOrdenLiq(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenLiqIdPoseedor ON Trn_TraOrdenLiq(IdPoseedor)

ALTER TABLE Trn_TraDevLgo ADD 
 CONSTRAINT FK_Trn_TraDevLgo_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevLgo_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevLgo_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevLgo_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevLgo_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevLgo_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevLgo_Trn_TraOrdenLiq FOREIGN KEY (TipDoc,Liquidacion,IdCiaDoc) REFERENCES [dbo].[Trn_TraOrdenLiq] (TipDoc,Liquidacion,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLgoFecha ON Trn_TraDevLgo(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLgoLiquidacion ON Trn_TraDevLgo(TipDoc,Liquidacion,IdCiaDoc)

ALTER TABLE [dbo].[Trn_TraLiqDetalle] DROP CONSTRAINT [FK_Trn_TraLiqDetalle_Trn_TraLiqViajes]





