CREATE TABLE Activos ( 
IdActivo VARCHAR(30) NOT NULL,
NomActivo VARCHAR(250) NOT NULL,
NumSerie VARCHAR(30) NOT NULL,
CodInvent VARCHAR(16) DEFAULT ('0') NOT NULL,
CodBarras VARCHAR(20) DEFAULT ('0') NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdInstala VARCHAR(4) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdRespons VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProv VARCHAR(16) NOT NULL,
FecCompra SMALLDATETIME NOT NULL,
FecActivacion SMALLDATETIME NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrden CHAR(2) DEFAULT ('00') NOT NULL,
NumEntrada INT DEFAULT (0) NOT NULL,
IdCiaEnt CHAR(2) DEFAULT ('00') NOT NULL,
VrCompra MONEY DEFAULT (0) NOT NULL,
VrComercial MONEY DEFAULT (0) NOT NULL,
VrBaseDep MONEY DEFAULT (0) NOT NULL,
VrMejoras MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VidaUtil INT DEFAULT (0) NOT NULL,
FecFinDep DATETIME,
MetodoDep VARCHAR(10) DEFAULT ('LINEARECTA') NOT NULL,
Ajustable BIT DEFAULT (0) NOT NULL,
Contable BIT DEFAULT (0) NOT NULL,
CueEnGrupo BIT DEFAULT (0) NOT NULL,
VrAjuInfAcum MONEY DEFAULT (0) NOT NULL,
VrDepAcuHis MONEY DEFAULT (0) NOT NULL,
VrDepAcuAju MONEY DEFAULT (0) NOT NULL,
VrAjuInfDep MONEY DEFAULT (0) NOT NULL,
NumMesesDep INT DEFAULT (0) NOT NULL,
FecUltDep SMALLDATETIME NOT NULL,
Marca VARCHAR(30) DEFAULT ('GENERICO') NOT NULL,
Modelo VARCHAR(10),
NumPlaca VARCHAR(20) DEFAULT ('0') NOT NULL,
NumDoc VARCHAR(20),
Referencia VARCHAR(50),
IdEstado VARCHAR(4) DEFAULT ('0002') NOT NULL,
FecRetiro SMALLDATETIME,
IdCausal VARCHAR(4) DEFAULT ('0') NOT NULL,
VrVenta MONEY DEFAULT (0) NOT NULL,
FecCreacion SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoContable VARCHAR(10) DEFAULT ('CONTAB') NOT NULL,
VrSalvamento MONEY DEFAULT ((0)) NOT NULL,
DepPartes BIT DEFAULT ((0)) NOT NULL,
UndsProd INT DEFAULT ((0)) NOT NULL,
TipComp VARCHAR(3),
NumComp INT DEFAULT ((0)),
CdCiaComp CHAR(2),
VUExtend INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Activos PRIMARY KEY CLUSTERED (IdActivo),
 CONSTRAINT CK_ActivosCodBarras CHECK ((len([CodBarras]) > 0)),
 CONSTRAINT CK_ActivosCodInvent CHECK ((len([CodInvent]) > 0)),
 CONSTRAINT CK_ActivosIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_ActivosIdCausal CHECK ((len([IdCausal]) > 0)),
 CONSTRAINT CK_ActivosIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_ActivosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ActivosIdCiaEnt CHECK ((len([IdCiaEnt]) > 0)),
 CONSTRAINT CK_ActivosIdCiaOrden CHECK ((len([IdCiaOrden]) > 0)),
 CONSTRAINT CK_ActivosIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_ActivosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_ActivosIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_ActivosIdInstala CHECK ((len([IdInstala]) > 0)),
 CONSTRAINT CK_ActivosIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_ActivosIdRespons CHECK ((len([IdRespons]) > 0)),
 CONSTRAINT CK_ActivosIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_ActivosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_ActivosMarca CHECK ((len([Marca]) > 0)),
 CONSTRAINT CK_ActivosMetodoDep CHECK ((len([MetodoDep]) > 0)),
 CONSTRAINT CK_ActivosNomActivo CHECK ((len([NomActivo]) > 0)),
 CONSTRAINT CK_ActivosNumPlaca CHECK ((len([NumPlaca]) > 0)),
 CONSTRAINT CK_ActivosNumSerie CHECK ((len([NumSerie]) > 0)))
CREATE TABLE Activos_Anexo ( 
IdActivo VARCHAR(30) NOT NULL,
IdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueDep VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueGasto VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueAjuste VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueCorr VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueAjuDep VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueCorrAD VARCHAR(16) DEFAULT ('0') NOT NULL,
NumPoliza VARCHAR(30),
NitCiaAseg VARCHAR(16),
FecPoliza SMALLDATETIME,
FecVigencia SMALLDATETIME,
VrAsegurado MONEY DEFAULT (0) NOT NULL,
VrCuotaMes MONEY DEFAULT (0) NOT NULL,
VendPoliza VARCHAR(150),
TeleVend VARCHAR(30),
DiasGarantia INT DEFAULT (0) NOT NULL,
ComentGarantia VARCHAR(250),
Pignorado BIT DEFAULT (0) NOT NULL,
FecIniPignor SMALLDATETIME,
FecFinPignor SMALLDATETIME,
GarantPignor VARCHAR(150),
Mantenimiento BIT DEFAULT (0) NOT NULL,
NumContrato VARCHAR(20),
FecIniCont SMALLDATETIME,
FecFinCont SMALLDATETIME,
Periodicidad INT DEFAULT (0) NOT NULL,
FecUltMnmto SMALLDATETIME,
NitEmpMnmto VARCHAR(16),
ComentMnmto VARCHAR(250),
DesUbicacion VARCHAR(100),
Comentarios VARCHAR(250),
ComentRetiro VARCHAR(250),
DatosTecnicos VARCHAR(4000),
CodNiifAct VARCHAR(16),
CodNiifDep VARCHAR(16),
CodNiifGasto VARCHAR(16)
 CONSTRAINT PK_Activos_Anexo PRIMARY KEY CLUSTERED (IdActivo),
 CONSTRAINT CK_Activos_AnexoIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCueAjuDep CHECK ((len([IdCueAjuDep]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCueAjuste CHECK ((len([IdCueAjuste]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCueCorr CHECK ((len([IdCueCorr]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCueCorrAD CHECK ((len([IdCueCorrAD]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCueDep CHECK ((len([IdCueDep]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCueGasto CHECK ((len([IdCueGasto]) > 0)),
 CONSTRAINT CK_Activos_AnexoIdCuenta CHECK ((len([IdCuenta]) > 0)))
CREATE TABLE Activos_Partes ( 
IdActivo VARCHAR(30) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
DescParte VARCHAR(250) NOT NULL,
NumParte VARCHAR(30) DEFAULT ('0') NOT NULL,
FecIniDep SMALLDATETIME NOT NULL,
MetDeprec VARCHAR(10) DEFAULT ('LINEARECTA') NOT NULL,
VidaUtil INT DEFAULT ((0)) NOT NULL,
UndsProd INT DEFAULT ((0)) NOT NULL,
VrCompra MONEY DEFAULT ((0)) NOT NULL,
VrBaseDep MONEY DEFAULT ((0)) NOT NULL,
VrMejoras MONEY DEFAULT ((0)) NOT NULL,
VrDisminuc MONEY DEFAULT ((0)) NOT NULL,
VrSalvamento MONEY DEFAULT ((0)) NOT NULL,
VrDepAcum MONEY DEFAULT ((0)) NOT NULL,
VrDepAcumHis MONEY DEFAULT ((0)) NOT NULL,
VrAjuAcum MONEY DEFAULT ((0)) NOT NULL,
VrAjuDepAcum MONEY DEFAULT ((0)) NOT NULL,
NitProv VARCHAR(16) NOT NULL,
IdEstado VARCHAR(4) DEFAULT ('0002') NOT NULL,
FecCreacion SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CueEnAfijo BIT DEFAULT ((0)) NOT NULL,
IdCuenta VARCHAR(16),
IdCueDep VARCHAR(16),
IdCueGasto VARCHAR(16),
CodNiifAct VARCHAR(16),
CodNiifDep VARCHAR(16),
CodNiifGasto VARCHAR(16),
Fec_Retiro SMALLDATETIME,
VU_Extend INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Activos_Partes PRIMARY KEY CLUSTERED (IdActivo,Item),
 CONSTRAINT CK_Activos_PartesDescParte CHECK ((len([DescParte])>(0))),
 CONSTRAINT CK_Activos_PartesIdActivo CHECK ((len([IdActivo])>(0))),
 CONSTRAINT CK_Activos_PartesIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Activos_PartesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Activos_PartesMetDeprec CHECK ((len([MetDeprec])>(0))),
 CONSTRAINT CK_Activos_PartesNitProv CHECK ((len([NitProv])>(0))),
 CONSTRAINT CK_Activos_PartesNumParte CHECK ((len([NumParte])>(0))))
CREATE TABLE AcuAnticipos ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
SaldoAnt MONEY DEFAULT (0) NOT NULL,
VrAnticipos MONEY DEFAULT (0) NOT NULL,
VrPagos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuAnticipos PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo),
 CONSTRAINT CK_AcuAnticiposIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuAnticiposIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_AcuAnticiposIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_AcuAnticiposnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuAnticiposnMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuCaja ( 
FechaDia SMALLDATETIME NOT NULL,
NumCorte INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
SaldoAnt MONEY DEFAULT (0) NOT NULL,
Facturas MONEY DEFAULT (0) NOT NULL,
DevFacturas MONEY DEFAULT (0) NOT NULL,
Planillas MONEY DEFAULT (0) NOT NULL,
DevPlanillas MONEY DEFAULT (0) NOT NULL,
Recibos MONEY DEFAULT (0) NOT NULL,
DevRecibos MONEY DEFAULT (0) NOT NULL,
IngCaja MONEY DEFAULT (0) NOT NULL,
DevIngCaja MONEY DEFAULT (0) NOT NULL,
EgrCaja MONEY DEFAULT (0) NOT NULL,
DevEgrCaja MONEY DEFAULT (0) NOT NULL,
Consignac MONEY DEFAULT (0) NOT NULL,
DevConsig MONEY DEFAULT (0) NOT NULL,
NotasCalibra MONEY DEFAULT (0) NOT NULL,
DevCalibra MONEY DEFAULT (0) NOT NULL,
OtrosIng MONEY DEFAULT (0) NOT NULL,
OtrosEgr MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCaja PRIMARY KEY CLUSTERED (FechaDia,NumCorte,IdCia,IdUsuario),
 CONSTRAINT CK_AcuCajaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCajaIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE AcuCajaBuses ( 
IdUsuario VARCHAR(11) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL,
NuevoSaldo MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCajaBuses PRIMARY KEY CLUSTERED (IdUsuario,IdCia,Fecha),
 CONSTRAINT CK_AcuCajaBusesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCajaBusesIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE AcuClientes ( 
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,
SaldoAnt MONEY DEFAULT (0) NOT NULL,
Facturas MONEY DEFAULT (0) NOT NULL,
DevFacturas MONEY DEFAULT (0) NOT NULL,
Recibos MONEY DEFAULT (0) NOT NULL,
DevRecibos MONEY DEFAULT (0) NOT NULL,
NotasDeb MONEY DEFAULT (0) NOT NULL,
NotasCre MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuClientes PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCliente,IdAgencia),
 CONSTRAINT CK_AcuClientesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_AcuClientesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuClientesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_AcuClientesnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuClientesnMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuCuentas ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCuentas PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta),
 CONSTRAINT CK_AcuCuentasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCuentasIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_AcuCuentasnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuCuentasnMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuCuentasAge ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16) NOT NULL,
TipoAcum CHAR(2) DEFAULT ('NA') NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCuentasAge PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum),
 CONSTRAINT CK_AcuCuentasAgeCodAgncia CHECK ((len([CodAgncia]) > 0)),
 CONSTRAINT CK_AcuCuentasAgeIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCuentasAgeIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_AcuCuentasAgeIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_AcuCuentasAgenAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuCuentasAgenMes CHECK (([nMes] >= 0 and [nMes] <= 13)),
 CONSTRAINT CK_AcuCuentasAgeTipoAcum CHECK (([TipoAcum] = 'NV' or [TipoAcum] = 'NA')))
CREATE TABLE AcuCuentasAux ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
nReg INT DEFAULT ((0)) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
SubAuxiliar VARCHAR(16) NOT NULL,
TipoAcum VARCHAR(4) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL,
TipoAfiVehic INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuCuentasAux PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_AcuCuentasAuxCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_AcuCuentasAuxIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_AcuCuentasAuxIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuCuentasAuxIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuCuentasAuxIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_AcuCuentasAuxIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuCuentasAuxnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuCuentasAuxnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuCuentasAuxSubAuxiliar CHECK ((len([SubAuxiliar])>(0))),
 CONSTRAINT CK_AcuCuentasAuxTipoAcum CHECK ((len([TipoAcum])>(0))))
CREATE TABLE AcuCuentasCc ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
TipoAcum CHAR(2) DEFAULT ('CC') NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCuentasCc PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos),
 CONSTRAINT CK_AcuCuentasCcIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_AcuCuentasCcIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCuentasCcIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_AcuCuentasCcIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_AcuCuentasCcnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuCuentasCcnMes CHECK (([nMes] >= 0 and [nMes] <= 13)),
 CONSTRAINT CK_AcuCuentasCcTipoAcum CHECK (([TipoAcum] = 'CS' or ([TipoAcum] = 'SU' or [TipoAcum] = 'CC'))))
CREATE TABLE AcuCuentasNit ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCuentasNit PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdTercero),
 CONSTRAINT CK_AcuCuentasNitIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCuentasNitIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_AcuCuentasNitIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_AcuCuentasNitnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuCuentasNitnMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuCuentasVeh ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuCuentasVeh PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdVehiculo),
 CONSTRAINT CK_AcuCuentasVehIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuCuentasVehIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_AcuCuentasVehIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_AcuCuentasVehnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuCuentasVehnMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuCuentasVeht ( 
nReg 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,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
TipoAfiVehic INT DEFAULT ((0)) NOT NULL,
TipoAcum VARCHAR(3) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuCuentasVeht PRIMARY KEY NONCLUSTERED (nReg),
 CONSTRAINT CK_AcuCuentasVehtIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuCuentasVehtIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuCuentasVehtIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuCuentasVehtIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_AcuCuentasVehtTipoAcum CHECK ((len([TipoAcum])>(0))))
CREATE TABLE AcuFisCuentas ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentas PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta),
 CONSTRAINT CK_AcuFisCuentasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuFisCuentasnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))))
CREATE TABLE AcuFisCuentasAge ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16) NOT NULL,
TipoAcum CHAR(2) DEFAULT ('NA') NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentasAge PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum),
 CONSTRAINT CK_AcuFisCuentasAgeCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_AcuFisCuentasAgeIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasAgeIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasAgeIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuFisCuentasAgenAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuFisCuentasAgenMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuFisCuentasAgeTipoAcum CHECK (([TipoAcum]='NV' OR [TipoAcum]='NA')))
CREATE TABLE AcuFisCuentasAux ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
nReg INT DEFAULT ((0)) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
SubAuxiliar VARCHAR(16) NOT NULL,
TipoAcum VARCHAR(4) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL,
TipoAfiVehic INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentasAux PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_AcuFisCuentasAuxCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuFisCuentasAuxnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuFisCuentasAuxSubAuxiliar CHECK ((len([SubAuxiliar])>(0))),
 CONSTRAINT CK_AcuFisCuentasAuxTipoAcum CHECK ((len([TipoAcum])>(0))))
CREATE TABLE AcuFisCuentasCc ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
TipoAcum CHAR(2) DEFAULT ('CC') NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentasCc PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos),
 CONSTRAINT CK_AcuFisCuentasCcIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_AcuFisCuentasCcIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasCcIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasCcIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_AcuFisCuentasCcnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuFisCuentasCcnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuFisCuentasCcTipoAcum CHECK (([TipoAcum]='CS' OR ([TipoAcum]='SU' OR [TipoAcum]='CC'))))
CREATE TABLE AcuFisCuentasNit ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentasNit PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdTercero),
 CONSTRAINT CK_AcuFisCuentasNitIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasNitIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasNitIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuFisCuentasNitnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuFisCuentasNitnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))))
CREATE TABLE AcuFisCuentasVeh ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentasVeh PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdVehiculo),
 CONSTRAINT CK_AcuFisCuentasVehIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuFisCuentasVehnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))))
CREATE TABLE AcuFisCuentasVeht ( 
nReg 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,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
TipoAfiVehic INT DEFAULT ((0)) NOT NULL,
TipoAcum VARCHAR(3) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuFisCuentasVeht PRIMARY KEY NONCLUSTERED (nReg),
 CONSTRAINT CK_AcuFisCuentasVehtIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehtIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehtIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehtIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_AcuFisCuentasVehtTipoAcum CHECK ((len([TipoAcum])>(0))))
CREATE TABLE AcuInventario ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
SaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
CostoAnt MONEY DEFAULT (0) NOT NULL,
CostoEnt MONEY DEFAULT (0) NOT NULL,
CostoSal MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuInventario PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdProducto,IdBodega),
 CONSTRAINT CK_AcuInventarioIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_AcuInventarioIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuInventarioIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_AcuInventarionAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuInventarionMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuInvLotes ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
NumLote VARCHAR(30) NOT NULL,
SaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
CostoAnt MONEY DEFAULT (0) NOT NULL,
CostoEnt MONEY DEFAULT (0) NOT NULL,
CostoSal MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuInvLotes PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdProducto,IdBodega,NumLote),
 CONSTRAINT CK_AcuInvLotesIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_AcuInvLotesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuInvLotesIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_AcuInvLotesnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuInvLotesnMes CHECK (([nMes] >= 0 and [nMes] <= 13)),
 CONSTRAINT CK_AcuInvLotesNumLote CHECK ((len([NumLote]) > 0)))
CREATE TABLE AcuInvTallas ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
SaldoAnt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CostoAnt MONEY DEFAULT ((0)) NOT NULL,
CostoEnt MONEY DEFAULT ((0)) NOT NULL,
CostoSal MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuInvTallas PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_AcuInvTallasIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_AcuInvTallasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuInvTallasIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_AcuInvTallasIdUbic CHECK ((len([IdUbic])>(0))),
 CONSTRAINT CK_AcuInvTallasNumTalla CHECK ((len([NumTalla])>(0))))
CREATE TABLE AcuInvTanques ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
SaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
CostoAnt MONEY DEFAULT (0) NOT NULL,
CostoEnt MONEY DEFAULT (0) NOT NULL,
CostoSal MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuInvTanques PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdProducto,IdTanque),
 CONSTRAINT CK_AcuInvTanquesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuInvTanquesIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_AcuInvTanquesIdTanque CHECK ((len([IdTanque]) > 0)),
 CONSTRAINT CK_AcuInvTanquesnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuInvTanquesnMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuInvUbica ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
SaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
CostoAnt MONEY DEFAULT (0) NOT NULL,
CostoEnt MONEY DEFAULT (0) NOT NULL,
CostoSal MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuInvUbica PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdProducto,IdUbic),
 CONSTRAINT CK_AcuInvUbicaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuInvUbicaIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_AcuInvUbicaIdUbic CHECK ((len([IdUbic]) > 0)),
 CONSTRAINT CK_AcuInvUbicanAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_AcuInvUbicanMes CHECK (([nMes] >= 0 and [nMes] <= 13)))
CREATE TABLE AcuNiifCuentas ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentas PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta),
 CONSTRAINT CK_AcuNiifCuentasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuNiifCuentasnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))))
CREATE TABLE AcuNiifCuentasAge ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16) NOT NULL,
TipoAcum CHAR(2) DEFAULT ('NA') NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentasAge PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum),
 CONSTRAINT CK_AcuNiifCuentasAgeCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAgeIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAgeIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAgeIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAgenAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuNiifCuentasAgenMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuNiifCuentasAgeTipoAcum CHECK (([TipoAcum]='NV' OR [TipoAcum]='NA')))
CREATE TABLE AcuNiifCuentasAux ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
nReg INT DEFAULT ((0)) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
SubAuxiliar VARCHAR(16) NOT NULL,
TipoAcum VARCHAR(4) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL,
TipoAfiVehic INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentasAux PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_AcuNiifCuentasAuxCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuNiifCuentasAuxnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuNiifCuentasAuxSubAuxiliar CHECK ((len([SubAuxiliar])>(0))),
 CONSTRAINT CK_AcuNiifCuentasAuxTipoAcum CHECK ((len([TipoAcum])>(0))))
CREATE TABLE AcuNiifCuentasCc ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
TipoAcum CHAR(2) DEFAULT ('CC') NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentasCc PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos),
 CONSTRAINT CK_AcuNiifCuentasCcIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_AcuNiifCuentasCcIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasCcIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasCcIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_AcuNiifCuentasCcnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuNiifCuentasCcnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))),
 CONSTRAINT CK_AcuNiifCuentasCcTipoAcum CHECK (([TipoAcum]='CS' OR ([TipoAcum]='SU' OR [TipoAcum]='CC'))))
CREATE TABLE AcuNiifCuentasNit ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentasNit PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdTercero),
 CONSTRAINT CK_AcuNiifCuentasNitIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasNitIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasNitIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuNiifCuentasNitnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuNiifCuentasNitnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))))
CREATE TABLE AcuNiifCuentasVeh ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentasVeh PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCuenta,IdVehiculo),
 CONSTRAINT CK_AcuNiifCuentasVehIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehnAnno CHECK (([nAnno]>=(1990) AND [nAnno]<=(2050))),
 CONSTRAINT CK_AcuNiifCuentasVehnMes CHECK (([nMes]>=(0) AND [nMes]<=(13))))
CREATE TABLE AcuNiifCuentasVeht ( 
nReg 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,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
TipoAfiVehic INT DEFAULT ((0)) NOT NULL,
TipoAcum VARCHAR(3) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuNiifCuentasVeht PRIMARY KEY NONCLUSTERED (nReg),
 CONSTRAINT CK_AcuNiifCuentasVehtIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehtIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehtIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehtIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_AcuNiifCuentasVehtTipoAcum CHECK ((len([TipoAcum])>(0))))
CREATE TABLE AcuOrdenes ( 
nAnno INT DEFAULT ((0)) NOT NULL,
nMes INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
SaldoAnt MONEY DEFAULT ((0)) NOT NULL,
VrIngresos MONEY DEFAULT ((0)) NOT NULL,
VrCausac MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_AcuOrdenes PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo),
 CONSTRAINT CK_AcuOrdenesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_AcuOrdenesIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_AcuOrdenesIdVehiculo CHECK ((len([IdVehiculo])>(0))))
CREATE TABLE AcuPrestamos ( 
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,
SaldoAnt MONEY DEFAULT (0) NOT NULL,
Prestamos MONEY DEFAULT (0) NOT NULL,
DevPrestamos MONEY DEFAULT (0) NOT NULL,
Recibos MONEY DEFAULT (0) NOT NULL,
DevRecibos MONEY DEFAULT (0) NOT NULL,
NotasDeb MONEY DEFAULT (0) NOT NULL,
NotasCre MONEY DEFAULT (0) NOT NULL,
Facturas MONEY DEFAULT (0) NOT NULL,
DevFacturas MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuPrestamos PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCliente,IdAgencia),
 CONSTRAINT CK_AcuPrestamosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_AcuPrestamosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuPrestamosIdCliente CHECK ((len([IdCliente]) > 0)))
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 AcuPropietarios ( 
nAnno INT DEFAULT (0) NOT NULL,
IdReg INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (1) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
SaldoAnterior MONEY DEFAULT (0) NOT NULL,
TotalDebitos MONEY DEFAULT (0) NOT NULL,
TotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_AcuPropietarios PRIMARY KEY NONCLUSTERED (nAnno,IdReg),
 CONSTRAINT CK_AcuPropietariosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_AcuPropietariosIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_AcuPropietariosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_AcuPropietariosIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE AcuVentas ( 
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,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCon CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_AcuVentas PRIMARY KEY CLUSTERED (nAnno,nMes,IdCia,IdCliente,IdAgencia,CdProducto))
CREATE TABLE adm_monedas ( 
IdMneda VARCHAR(5) NOT NULL,
Mneda VARCHAR(50) NOT NULL,
Simbolo VARCHAR(10),
MneLocal BIT DEFAULT (0) NOT NULL,
VrCambio DECIMAL(12,6) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_adm_monedas PRIMARY KEY CLUSTERED (IdMneda),
 CONSTRAINT CK_adm_monedasIdMneda CHECK ((len([IdMneda]) > 0)),
 CONSTRAINT CK_adm_monedasMneda CHECK ((len([Mneda]) > 0)))
CREATE TABLE adm_Opciones ( 
IdOpc VARCHAR(3) NOT NULL,
Opcion VARCHAR(100) NOT NULL,
TipoDato VARCHAR(15) DEFAULT ('VARCHAR') NOT NULL,
Valor VARCHAR(100),
NivUp INT DEFAULT (5) NOT NULL,
nModulo VARCHAR(10) DEFAULT ('MAIN') NOT NULL
 CONSTRAINT PK_adm_Opciones PRIMARY KEY CLUSTERED (IdOpc),
 CONSTRAINT CK_adm_OpcionesIdOpc CHECK ((len([IdOpc]) > 0)),
 CONSTRAINT CK_adm_OpcionesNivUp CHECK (([NivUp] >= 3 and [NivUp] <= 5)),
 CONSTRAINT CK_adm_OpcionesnModulo CHECK (([nModulo]='TRAES' OR [nModulo]='MAIN' OR [nModulo]='NOMINA' OR [nModulo]='CONTAB' OR [nModulo]='BUSES' OR [nModulo]='TRANS' OR [nModulo]='RFISICO' OR [nModulo]='MNMIENTO' OR [nModulo]='GENERAL' OR [nModulo]='PRESTAMOS')),
 CONSTRAINT CK_adm_OpcionesOpcion CHECK ((len([Opcion]) > 0)),
 CONSTRAINT CK_adm_OpcionesTipoDato CHECK (([TipoDato] = 'NONE' or ([TipoDato] = 'VARCHAR' or ([TipoDato] = 'MONEY' or ([TipoDato] = 'INTEGER' or ([TipoDato] = 'DECIMAL' or ([TipoDato] = 'DATETIME' or ([TipoDato] = 'CHAR' or [TipoDato] = 'BOOLEAN')))))))))
CREATE TABLE adm_Paises ( 
IdPais VARCHAR(8) NOT NULL,
CodISO VARCHAR(3) NOT NULL,
NombrePais VARCHAR(50) NOT NULL,
IdMneda VARCHAR(5) NOT NULL
 CONSTRAINT PK_adm_Paises PRIMARY KEY CLUSTERED (IdPais),
 CONSTRAINT IX_PaisesCodISO UNIQUE NONCLUSTERED (CodISO),
 CONSTRAINT CK_adm_PaisesCodISO CHECK ((len([CodISO]) > 0)),
 CONSTRAINT CK_adm_PaisesIdMneda CHECK ((len([IdMneda]) > 0)),
 CONSTRAINT CK_adm_PaisesIdPais CHECK ((len([IdPais]) > 0)),
 CONSTRAINT CK_adm_PaisesNombrePais CHECK ((len([NombrePais]) > 0)))
CREATE TABLE adm_Permisos ( 
IdUsuario VARCHAR(11) NOT NULL,
IdObj VARCHAR(10) NOT NULL,
Consecutivo INT DEFAULT (0) NOT NULL,
PerAdd BIT DEFAULT (0) NOT NULL,
PerUpdate BIT DEFAULT (0) NOT NULL,
PerDelete BIT DEFAULT (0) NOT NULL,
PerAnular BIT DEFAULT (0) NOT NULL,
PerRead BIT DEFAULT (0) NOT NULL,
PerRename BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_adm_Permisos PRIMARY KEY CLUSTERED (IdUsuario,IdObj),
 CONSTRAINT CK_adm_PermisosIdObj CHECK ((len([IdObj]) > 0)),
 CONSTRAINT CK_adm_PermisosIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE adm_PermisosRoles ( 
IdUsuario VARCHAR(11) NOT NULL,
IdObj VARCHAR(10) NOT NULL,
IdRole VARCHAR(3) NOT NULL,
Asignado BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_adm_PermisosRoles PRIMARY KEY CLUSTERED (IdUsuario,IdObj,IdRole),
 CONSTRAINT CK_adm_PermisosRolesIdObj CHECK ((len([IdObj]) > 0)),
 CONSTRAINT CK_adm_PermisosRolesIdRole CHECK ((len([IdRole]) > 0)),
 CONSTRAINT CK_adm_PermisosRolesIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE adm_Registro ( 
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
TipoId CHAR(1) DEFAULT ('N') NOT NULL,
IdEmpresa VARCHAR(16) NOT NULL,
NitEmpresa VARCHAR(16) NOT NULL,
DvNit CHAR(1) DEFAULT ('0') NOT NULL,
RazonSocial VARCHAR(250) NOT NULL,
NitRepLegal VARCHAR(16),
RepLegal VARCHAR(150),
Descripcion VARCHAR(250),
Direccion VARCHAR(250) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
Fax VARCHAR(20),
IdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
IdPais VARCHAR(8) NOT NULL,
e_mail VARCHAR(100),
ArchivoLogo VARCHAR(30),
NumeroSerial VARCHAR(80) NOT NULL,
Regimen VARCHAR(50) NOT NULL,
TipoPersna CHAR(1) DEFAULT ('J') NOT NULL,
Licencia VARCHAR(20),
VigenciaLic SMALLDATETIME,
Personeria VARCHAR(40),
CIIUDane VARCHAR(8),
Leyenda VARCHAR(250),
FechaRegistro SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME,
CurrtyDate SMALLDATETIME,
CurDate1 SMALLDATETIME,
FechaPrest SMALLDATETIME
 CONSTRAINT PK_adm_Registro PRIMARY KEY CLUSTERED (IdCia),
 CONSTRAINT IX_RegistroNumeroSerial UNIQUE NONCLUSTERED (NumeroSerial),
 CONSTRAINT CK_adm_RegistroDireccion CHECK ((len([Direccion]) > 0)),
 CONSTRAINT CK_adm_RegistroDvNit CHECK ((len([DvNit]) > 0)),
 CONSTRAINT CK_adm_RegistroIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_adm_RegistroIdEmpresa CHECK ((len([IdEmpresa]) > 0)),
 CONSTRAINT CK_adm_RegistroIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_adm_RegistroIdPais CHECK ((len([IdPais]) > 0)),
 CONSTRAINT CK_adm_RegistroNitEmpresa CHECK ((len([NitEmpresa]) > 0)),
 CONSTRAINT CK_adm_RegistroNumeroSerial CHECK ((len([NumeroSerial]) > 0)),
 CONSTRAINT CK_adm_RegistroRazonSocial CHECK ((len([RazonSocial]) > 0)),
 CONSTRAINT CK_adm_RegistroRegimen CHECK ((len([Regimen]) > 0)),
 CONSTRAINT CK_adm_RegistroTelefono CHECK ((len([Telefono]) > 0)),
 CONSTRAINT CK_adm_RegistroTipoId CHECK (([TipoId] = 'P' or ([TipoId] = 'R' or ([TipoId] = 'T' or ([TipoId] = 'U' or ([TipoId] = 'O' or ([TipoId] = 'E' or ([TipoId] = 'C' or [TipoId] = 'N')))))))),
 CONSTRAINT CK_adm_RegistroTipoPersna CHECK (([TipoPersna] = 'N' or [TipoPersna] = 'J')))
CREATE TABLE adm_UOpciones ( 
IdUsuario VARCHAR(11) NOT NULL,
NomOpcion VARCHAR(20) NOT NULL,
Valor VARCHAR(50) NOT NULL
 CONSTRAINT PK_adm_UOpciones PRIMARY KEY CLUSTERED (IdUsuario,NomOpcion),
 CONSTRAINT CK_adm_UOpcionesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_adm_UOpcionesNomOpcion CHECK ((len([NomOpcion]) > 0)),
 CONSTRAINT CK_adm_UOpcionesValor CHECK ((len([Valor]) > 0)))
CREATE TABLE adm_Usuarios ( 
IdUsuario VARCHAR(11) NOT NULL,
Usuario VARCHAR(50) NOT NULL,
PwdLog VARCHAR(30) NOT NULL,
IdGrupo INT DEFAULT (0) NOT NULL,
IdEstacion CHAR(2) DEFAULT ('00') NOT NULL,
IdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
Conectado BIT DEFAULT (0) NOT NULL,
FechaAcc SMALLDATETIME,
FechaClave SMALLDATETIME,
Caducidad INT DEFAULT (0),
LoginSQL VARCHAR(20),
PwdSQL VARCHAR(20),
ModoSQL VARCHAR(3) DEFAULT ('WIN') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_adm_Usuarios PRIMARY KEY CLUSTERED (IdUsuario),
 CONSTRAINT IX_UsuariosIdEstacion UNIQUE NONCLUSTERED (IdEstacion),
 CONSTRAINT CK_adm_UsuariosIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_adm_UsuariosIdEstacion CHECK ((len([IdEstacion]) > 0)),
 CONSTRAINT CK_adm_UsuariosIdGrupo CHECK (([IdGrupo] >= 1 and [IdGrupo] <= 5)),
 CONSTRAINT CK_adm_UsuariosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_adm_UsuariosModoSQL CHECK (([ModoSQL] = 'SQL' or [ModoSQL] = 'WIN')),
 CONSTRAINT CK_adm_UsuariosPwdLog CHECK ((len([PwdLog]) > 0)),
 CONSTRAINT CK_adm_UsuariosUsuario CHECK ((len([Usuario]) > 0)))
CREATE TABLE adm_Usucaja ( 
IdUsuario VARCHAR(11) NOT NULL,
nFormato VARCHAR(10) NOT NULL,
CdCajero VARCHAR(11) DEFAULT ('0') NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
CdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
LtaPrec CHAR(1),
IdVend VARCHAR(16) NOT NULL,
CdCms VARCHAR(4),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
AbreCajon VARCHAR(10) DEFAULT ('EXE') NOT NULL,
FechaAdd SMALLDATETIME NOT NULL
 CONSTRAINT PK_adm_Usucaja PRIMARY KEY CLUSTERED (IdUsuario,nFormato),
 CONSTRAINT CK_adm_UsucajaAbreCajon CHECK (([AbreCajon] = 'NONE' or ([AbreCajon] = 'ESC' or [AbreCajon] = 'EXE'))),
 CONSTRAINT CK_adm_UsucajaCdBodega CHECK ((len([CdBodega]) > 0)),
 CONSTRAINT CK_adm_UsucajaCdCajero CHECK ((len([CdCajero]) > 0)),
 CONSTRAINT CK_adm_UsucajaIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_adm_UsucajaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_adm_UsucajaIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_adm_UsucajanFormato CHECK ((len([nFormato]) > 0)))
CREATE TABLE Aduanas ( 
IdAduana VARCHAR(4) NOT NULL,
NomAduana VARCHAR(150) NOT NULL,
IdPais VARCHAR(8) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Aduanas PRIMARY KEY CLUSTERED (IdAduana),
 CONSTRAINT CK_AduanasIdAduana CHECK ((len([IdAduana])>(0))),
 CONSTRAINT CK_AduanasIdPais CHECK ((len([IdPais])>(0))),
 CONSTRAINT CK_AduanasNomAduana CHECK ((len([NomAduana])>(0))))
CREATE TABLE AfCausales ( 
IdCausal VARCHAR(4) NOT NULL,
Causal VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfCausales PRIMARY KEY CLUSTERED (IdCausal),
 CONSTRAINT CK_AfCausalesCausal CHECK ((len([Causal]) > 0)),
 CONSTRAINT CK_AfCausalesIdCausal CHECK ((len([IdCausal]) > 0)))
CREATE TABLE AfClasesCue ( 
IdClase VARCHAR(4) NOT NULL,
ClaseCue VARCHAR(50) NOT NULL,
Concepto VARCHAR(50),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfClasesCue PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_AfClasesCueClaseCue CHECK ((len([ClaseCue]) > 0)),
 CONSTRAINT CK_AfClasesCueIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE AfEstados ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfEstados PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_AfEstadosEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_AfEstadosIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE AfGrupos ( 
IdGrupo VARCHAR(4) NOT NULL,
Grupo VARCHAR(50) NOT NULL,
IdLinea VARCHAR(4) NOT NULL,
VidaUtil INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfGrupos PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_AfGruposGrupo CHECK ((len([Grupo]) > 0)),
 CONSTRAINT CK_AfGruposIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_AfGruposIdLinea CHECK ((len([IdLinea]) > 0)))
CREATE TABLE AfGruposCue ( 
IdGrupo VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL
 CONSTRAINT PK_AfGruposCue PRIMARY KEY CLUSTERED (IdGrupo,IdClase),
 CONSTRAINT CK_AfGruposCueIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_AfGruposCueIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_AfGruposCueIdGrupo CHECK ((len([IdGrupo]) > 0)))
CREATE TABLE AfLineas ( 
IdLinea VARCHAR(4) NOT NULL,
Linea VARCHAR(50) NOT NULL,
VidaUtil INT DEFAULT (0) NOT NULL,
TarfDep DECIMAL(14,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfLineas PRIMARY KEY CLUSTERED (IdLinea),
 CONSTRAINT CK_AfLineasIdLinea CHECK ((len([IdLinea]) > 0)),
 CONSTRAINT CK_AfLineasLinea CHECK ((len([Linea]) > 0)))
CREATE TABLE AfTiposComp ( 
IdConc VARCHAR(4) NOT NULL,
Concepto VARCHAR(50) NOT NULL,
TipoContab VARCHAR(10) NOT NULL,
CdCom VARCHAR(3),
CdComNiif VARCHAR(3),
CdComFiscal VARCHAR(3)
 CONSTRAINT PK_AfTiposComp PRIMARY KEY CLUSTERED (IdConc),
 CONSTRAINT CK_AfTiposCompConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_AfTiposCompIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_AfTiposCompTipoContab CHECK ((len([TipoContab])>(0))))
CREATE TABLE AfTiposDif ( 
IdTipDif VARCHAR(4) NOT NULL,
TipoDiferido VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfTiposDif PRIMARY KEY CLUSTERED (IdTipDif),
 CONSTRAINT CK_AfTiposDifIdTipDif CHECK ((len([IdTipDif]) > 0)),
 CONSTRAINT CK_AfTiposDifTipoDiferido CHECK ((len([TipoDiferido]) > 0)))
CREATE TABLE AfTiposMov ( 
IdMov VARCHAR(4) NOT NULL,
TipoMov VARCHAR(50) NOT NULL,
Consecutivo INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AfTiposMov PRIMARY KEY CLUSTERED (IdMov),
 CONSTRAINT CK_AfTiposMovIdMov CHECK ((len([IdMov]) > 0)),
 CONSTRAINT CK_AfTiposMovTipoMov CHECK ((len([TipoMov]) > 0)))
CREATE TABLE Agencias ( 
IdAgencia VARCHAR(16) NOT NULL,
CodAgencia VARCHAR(16) NOT NULL,
IdClie VARCHAR(16) NOT NULL,
Agencia VARCHAR(150) NOT NULL,
DirAgncia VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
TelAgncia VARCHAR(20),
FaxAgncia VARCHAR(20),
NitCont VARCHAR(16),
NomCont VARCHAR(150),
emlCont VARCHAR(100),
CargoCont VARCHAR(50),
IdSzona VARCHAR(4) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CdPlazoComb VARCHAR(4) DEFAULT ('0') NOT NULL,
IdForma VARCHAR(4) NOT NULL,
CdBandera VARCHAR(4) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
CdCms VARCHAR(4),
CdDct VARCHAR(4),
IntMora DECIMAL(14,4) DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
FactFletes BIT DEFAULT (0) NOT NULL,
FactSold BIT DEFAULT (0) NOT NULL,
VrCupoCre MONEY DEFAULT (0) NOT NULL,
VrSaldoAct MONEY DEFAULT (0) NOT NULL,
FecUpCupo SMALLDATETIME,
NContrato INT DEFAULT (0) NOT NULL,
CiaCont CHAR(2) DEFAULT ('00') NOT NULL,
CodSicom VARCHAR(20) DEFAULT ('0') NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
Referencia VARCHAR(50),
Comentarios VARCHAR(250),
CupoGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoZona VARCHAR(10),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CdTipAgenc VARCHAR(4),
CdSubAgenc VARCHAR(4),
CdGrupAgenc VARCHAR(4),
CdSubGrupAgenc VARCHAR(4),
CdFntePago VARCHAR(4),
PlazoSobtasa VARCHAR(20),
DocFinanc VARCHAR(3),
VolContMes DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolContTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolViabMes DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolViabTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecPriVenta SMALLDATETIME,
InvCtbObra MONEY DEFAULT (0) NOT NULL,
InvCtbCapital MONEY DEFAULT (0) NOT NULL,
InvCtbEfectivo MONEY DEFAULT (0) NOT NULL,
InvCtbImagen MONEY DEFAULT (0) NOT NULL,
InvCtbMntmto MONEY DEFAULT (0) NOT NULL,
FecDesemb SMALLDATETIME,
InvContObra MONEY DEFAULT (0) NOT NULL,
InvContCapital MONEY DEFAULT (0) NOT NULL,
InvContEfectivo MONEY DEFAULT (0) NOT NULL,
InvContImagen MONEY DEFAULT (0) NOT NULL,
CrtlAprovInv INT DEFAULT (0) NOT NULL,
CrtlAprovImg INT DEFAULT (0) NOT NULL,
FecVigCond SMALLDATETIME,
TasaIntArranq DECIMAL(14,4) DEFAULT (0) NOT NULL,
AgencOperando BIT DEFAULT (0) NOT NULL,
TipoFactFletes INT DEFAULT ((0)),
CdCCBonif VARCHAR(16),
CdSubCCBonif VARCHAR(16),
CodRuta VARCHAR(4),
CodDiaEnt VARCHAR(4),
CdGruClie VARCHAR(4),
CupoElectcom DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Agencias PRIMARY KEY CLUSTERED (IdAgencia),
 CONSTRAINT IX_AgenciasCodAgencia UNIQUE NONCLUSTERED (CodAgencia,IdClie),
 CONSTRAINT CK_AgenciasAgencia CHECK ((len([Agencia]) > 0)),
 CONSTRAINT CK_AgenciasCdBandera CHECK ((len([CdBandera]) > 0)),
 CONSTRAINT CK_AgenciasCdPlazoComb CHECK ((len([CdPlazoComb]) > 0)),
 CONSTRAINT CK_AgenciasCiaCont CHECK ((len([CiaCont]) > 0)),
 CONSTRAINT CK_AgenciasCodAgencia CHECK ((len([CodAgencia]) > 0)),
 CONSTRAINT CK_AgenciasDirAgncia CHECK ((len([DirAgncia]) > 0)),
 CONSTRAINT CK_AgenciasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_AgenciasIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_AgenciasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_AgenciasIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_AgenciasIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_AgenciasIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_AgenciasIdSzona CHECK ((len([IdSzona]) > 0)),
 CONSTRAINT CK_AgenciasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_AgenciasIdVend CHECK ((len([IdVend]) > 0)))
CREATE TABLE AgenDocumentos ( 
IdAgencia VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdDoc VARCHAR(4) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME,
EstadoReg INT DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(250),
FechaAdd SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_AgenDocumentos PRIMARY KEY CLUSTERED (IdAgencia,Item),
 CONSTRAINT CK_AgenDocumentosIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_AgenDocumentosIdDoc CHECK ((len([IdDoc])>(0))),
 CONSTRAINT CK_AgenDocumentosIdUsuario CHECK ((len([IdUsuario])>(0))))
CREATE TABLE AlmBodegas ( 
IdBodega VARCHAR(4) NOT NULL,
Bodega VARCHAR(100) NOT NULL,
Direccion VARCHAR(100),
TelBodega VARCHAR(50),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_AlmBodegas PRIMARY KEY CLUSTERED (IdBodega),
 CONSTRAINT CK_AlmBodegasBodega CHECK ((len([Bodega]) > 0)),
 CONSTRAINT CK_AlmBodegasIdBodega CHECK ((len([IdBodega]) > 0)))
CREATE TABLE Areas ( 
IdArea VARCHAR(4) NOT NULL,
Area VARCHAR(50) NOT NULL,
JefeArea VARCHAR(50),
IdCCosto VARCHAR(16) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Areas PRIMARY KEY CLUSTERED (IdArea),
 CONSTRAINT CK_AreasArea CHECK ((len([Area]) > 0)),
 CONSTRAINT CK_AreasIdArea CHECK ((len([IdArea]) > 0)),
 CONSTRAINT CK_AreasIdCCosto CHECK ((len([IdCCosto]) > 0)))
CREATE TABLE Bancos ( 
IdBanco VARCHAR(4) NOT NULL,
Banco VARCHAR(50) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
CodEntidad VARCHAR(20) NOT NULL,
Direccion VARCHAR(50),
Contacto VARCHAR(50),
Comision DECIMAL(10,4) DEFAULT (0),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Bancos PRIMARY KEY CLUSTERED (IdBanco),
 CONSTRAINT IX_BancosCodEntidad UNIQUE NONCLUSTERED (CodEntidad),
 CONSTRAINT CK_BancosBanco CHECK ((len([Banco]) > 0)),
 CONSTRAINT CK_BancosCodEntidad CHECK ((len([CodEntidad]) > 0)),
 CONSTRAINT CK_BancosIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_BancosIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE Bodegas ( 
IdBodega VARCHAR(4) NOT NULL,
Bodega VARCHAR(50) NOT NULL,
Descrip VARCHAR(100),
LtaPre CHAR(1),
TipoInv VARCHAR(10) DEFAULT ('COMERCIAL') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Bodegas PRIMARY KEY CLUSTERED (IdBodega),
 CONSTRAINT CK_BodegasBodega CHECK ((len([Bodega]) > 0)),
 CONSTRAINT CK_BodegasIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_BodegasTipoInv CHECK ((len([TipoInv]) > 0)))
CREATE TABLE BodegasCias ( 
IdBodega VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL
 CONSTRAINT PK_BodegasCias PRIMARY KEY CLUSTERED (IdBodega,IdCia),
 CONSTRAINT CK_BodegasCiasIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_BodegasCiasIdCia CHECK ((len([IdCia]) > 0)))
CREATE TABLE BodUbic ( 
IdUbic VARCHAR(10) NOT NULL,
Ubicacion VARCHAR(50) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Pasillo VARCHAR(10) NOT NULL,
Nivel VARCHAR(10) NOT NULL,
Profdad VARCHAR(10) NOT NULL,
DimAltura DECIMAL(14,4) DEFAULT (0) NOT NULL,
DimAnch DECIMAL(14,4) DEFAULT (0) NOT NULL,
DimLong DECIMAL(14,4) DEFAULT (0) NOT NULL,
CapcVolm DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndCapc VARCHAR(10) NOT NULL,
CapcPeso DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndPes VARCHAR(10) NOT NULL,
CdTmcia VARCHAR(4),
CdMnjo VARCHAR(4),
Notas VARCHAR(250),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_BodUbic PRIMARY KEY CLUSTERED (IdUbic),
 CONSTRAINT CK_BodUbicIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_BodUbicIdUbic CHECK ((len([IdUbic]) > 0)),
 CONSTRAINT CK_BodUbicNivel CHECK ((len([Nivel]) > 0)),
 CONSTRAINT CK_BodUbicPasillo CHECK ((len([Pasillo]) > 0)),
 CONSTRAINT CK_BodUbicProfdad CHECK ((len([Profdad]) > 0)),
 CONSTRAINT CK_BodUbicUbicacion CHECK ((len([Ubicacion]) > 0)),
 CONSTRAINT CK_BodUbicUndCapc CHECK ((len([UndCapc]) > 0)),
 CONSTRAINT CK_BodUbicUndPes CHECK ((len([UndPes]) > 0)))
CREATE TABLE BusClaseCue ( 
IdClase VARCHAR(4) NOT NULL,
ClaseCuenta VARCHAR(50) NOT NULL,
Prioridad INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_BusClaseCue PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_BusClaseCueClaseCuenta CHECK ((len([ClaseCuenta]) > 0)),
 CONSTRAINT CK_BusClaseCueIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE Calndario ( 
FechaDia SMALLDATETIME NOT NULL,
TipoFtvo VARCHAR(3) DEFAULT ('DOM') NOT NULL
 CONSTRAINT PK_Calndario PRIMARY KEY CLUSTERED (FechaDia),
 CONSTRAINT CK_CalndarioTipoFtvo CHECK (([TipoFtvo] = 'FES' or [TipoFtvo] = 'DOM')))
CREATE TABLE Cargos ( 
IdCargo VARCHAR(4) NOT NULL,
Cargo VARCHAR(50) NOT NULL,
Funciones VARCHAR(3000),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Cargos PRIMARY KEY CLUSTERED (IdCargo),
 CONSTRAINT CK_CargosCargo CHECK ((len([Cargo]) > 0)),
 CONSTRAINT CK_CargosIdCargo CHECK ((len([IdCargo]) > 0)))
CREATE TABLE CentroCosto ( 
IdCCosto VARCHAR(16) NOT NULL,
CCosto VARCHAR(100) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
Inactivo BIT DEFAULT (0) NOT NULL,
CodCias VARCHAR(500)
 CONSTRAINT PK_CentroCosto PRIMARY KEY CLUSTERED (IdCCosto),
 CONSTRAINT CK_CentroCostoCCosto CHECK ((len([CCosto]) > 0)),
 CONSTRAINT CK_CentroCostoIdCCosto CHECK ((len([IdCCosto]) > 0)))
CREATE TABLE CentrosServ ( 
IdCenSer VARCHAR(4) NOT NULL,
CentroServ VARCHAR(50) NOT NULL,
DirCentro VARCHAR(100),
IdLocal VARCHAR(8) NOT NULL,
Telefonos VARCHAR(30),
TipoCentro VARCHAR(10) DEFAULT ('INTERNO') NOT NULL,
NitResp VARCHAR(16),
Respnsable VARCHAR(150),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_CentrosServ PRIMARY KEY CLUSTERED (IdCenSer),
 CONSTRAINT CK_CentrosServCentroServ CHECK ((len([CentroServ]) > 0)),
 CONSTRAINT CK_CentrosServIdCenSer CHECK ((len([IdCenSer]) > 0)),
 CONSTRAINT CK_CentrosServIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_CentrosServTipoCentro CHECK (([TipoCentro] = 'EXTERNO' or [TipoCentro] = 'INTERNO')))
CREATE TABLE ClaseBan ( 
IdClase VARCHAR(4) NOT NULL,
ClaseBanco VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClaseBan PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseBanClaseBanco CHECK ((len([ClaseBanco]) > 0)),
 CONSTRAINT CK_ClaseBanIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE ClaseCapac ( 
IdClase VARCHAR(4) NOT NULL,
NomClase VARCHAR(150) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ClaseCapac PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseCapacIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_ClaseCapacNomClase CHECK ((len([NomClase])>(0))))
CREATE TABLE ClaseCta ( 
IdClase VARCHAR(4) NOT NULL,
ClaseCuenta VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClaseCta PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseCtaClaseCuenta CHECK ((len([ClaseCuenta]) > 0)),
 CONSTRAINT CK_ClaseCtaIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE ClaseDiv ( 
IdClase VARCHAR(4) NOT NULL,
NomClase VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClaseDiv PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseDivIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_ClaseDivNomClase CHECK ((len([NomClase]) > 0)))
CREATE TABLE ClaseDocAgenc ( 
IdDoc VARCHAR(4) NOT NULL,
Documento VARCHAR(250) NOT NULL,
DiasAviso INT DEFAULT ((0)) NOT NULL,
Vigencia BIT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ClaseDocAgenc PRIMARY KEY CLUSTERED (IdDoc),
 CONSTRAINT CK_ClaseDocAgencDocumento CHECK ((len([Documento])>(0))),
 CONSTRAINT CK_ClaseDocAgencIdDoc CHECK ((len([IdDoc])>(0))))
CREATE TABLE ClaseDocCond ( 
IdDoc VARCHAR(4) NOT NULL,
Documento VARCHAR(150) NOT NULL,
Vigencia BIT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ClaseDocCond PRIMARY KEY CLUSTERED (IdDoc),
 CONSTRAINT CK_ClaseDocCondDocumento CHECK ((len([Documento])>(0))),
 CONSTRAINT CK_ClaseDocCondIdDoc CHECK ((len([IdDoc])>(0))))
CREATE TABLE ClaseFon ( 
IdClase VARCHAR(4) NOT NULL,
ClaseFondo VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClaseFon PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseFonClaseFondo CHECK ((len([ClaseFondo]) > 0)),
 CONSTRAINT CK_ClaseFonIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE ClasePol ( 
IdClase VARCHAR(4) NOT NULL,
ClasePoliza VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClasePol PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClasePolClasePoliza CHECK ((len([ClasePoliza]) > 0)),
 CONSTRAINT CK_ClasePolIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE ClaseRie ( 
IdClase VARCHAR(4) NOT NULL,
ClaseRiesgo VARCHAR(50) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
CodClase VARCHAR(4)
 CONSTRAINT PK_ClaseRie PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseRieClaseRiesgo CHECK ((len([ClaseRiesgo]) > 0)),
 CONSTRAINT CK_ClaseRieIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE ClaseSub ( 
IdClase VARCHAR(4) NOT NULL,
NomClase VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClaseSub PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseSubIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_ClaseSubNomClase CHECK ((len([NomClase]) > 0)))
CREATE TABLE ClaseTar ( 
IdClase VARCHAR(4) NOT NULL,
NomClase VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ClaseTar PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_ClaseTarIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_ClaseTarNomClase CHECK ((len([NomClase]) > 0)))
CREATE TABLE ClieContado ( 
IdCliente VARCHAR(16) NOT NULL,
Nombre VARCHAR(150) NOT NULL,
TipoId CHAR(1) DEFAULT ('C') NOT NULL,
Dv CHAR(1),
Direccion VARCHAR(150),
IdLocal VARCHAR(8) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
email VARCHAR(100),
Excento BIT DEFAULT (0) NOT NULL,
PosIniNom INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME
 CONSTRAINT PK_ClieContado PRIMARY KEY CLUSTERED (IdCliente),
 CONSTRAINT CK_ClieContadoIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_ClieContadoIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_ClieContadoNombre CHECK ((len([Nombre]) > 0)),
 CONSTRAINT CK_ClieContadoTelefono CHECK ((len([Telefono]) > 0)),
 CONSTRAINT CK_ClieContadoTipoId CHECK ((len([TipoId]) > 0)))
CREATE TABLE Companias ( 
IdCia CHAR(2) NOT NULL,
Compania VARCHAR(50) NOT NULL,
DirInterface VARCHAR(255),
FechaActual SMALLDATETIME NOT NULL,
PeriodoActual SMALLDATETIME NOT NULL,
IdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
IdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
IdTercero VARCHAR(16) DEFAULT ('0'),
CodSucsal VARCHAR(10) NOT NULL,
DireccSuc VARCHAR(250),
TelefSuc VARCHAR(20),
FaxSuc VARCHAR(20),
IdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
TipoEDS VARCHAR(10),
CodPlanta VARCHAR(20) DEFAULT ('0') NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
Inactivo BIT DEFAULT (0) NOT NULL,
CodBodega VARCHAR(4),
FecModPrest SMALLDATETIME,
AutoIca BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Companias PRIMARY KEY CLUSTERED (IdCia),
 CONSTRAINT CK_CompaniasCodSucsal CHECK ((len([CodSucsal]) > 0)),
 CONSTRAINT CK_CompaniasCompania CHECK ((len([Compania]) > 0)),
 CONSTRAINT CK_CompaniasIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_CompaniasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_CompaniasIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_CompaniasIdSubCos CHECK ((len([IdSubCos]) > 0)))
CREATE TABLE CompListas ( 
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdCiaPre CHAR(2) NOT NULL
 CONSTRAINT PK_CompListas PRIMARY KEY CLUSTERED (IdCia,Item),
 CONSTRAINT CK_CompListasIdCiaPre CHECK ((len([IdCiaPre])>(0))))
CREATE TABLE ConcDivCia ( 
IdConcepto VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL
 CONSTRAINT PK_ConcDivCia PRIMARY KEY CLUSTERED (IdConcepto,IdCia))
CREATE TABLE ConcDivCue ( 
IdConcepto VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
CdCueDev VARCHAR(16),
TipoMov CHAR(1) DEFAULT ('D') NOT NULL,
TipoTerc CHAR(1),
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME
 CONSTRAINT PK_ConcDivCue PRIMARY KEY CLUSTERED (IdConcepto,IdClase),
 CONSTRAINT CK_ConcDivCueIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_ConcDivCueIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_ConcDivCueIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_ConcDivCueTipoMov CHECK (([TipoMov] = 'C' or [TipoMov] = 'D')))
CREATE TABLE ConcDiversos ( 
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(250) NOT NULL,
Grupo VARCHAR(20) DEFAULT ('OTROS') NOT NULL,
EsServicio BIT DEFAULT ((0)) NOT NULL,
DeManfsto BIT DEFAULT ((0)) NOT NULL,
CdIva VARCHAR(4),
CdRet VARCHAR(4),
CdIca VARCHAR(4),
CdAutoret VARCHAR(4),
IdCueDeb VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueCre VARCHAR(16) DEFAULT ('0') NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
OrdenServ INT DEFAULT ((0)) NOT NULL,
NovedadNom BIT DEFAULT ((0)) NOT NULL,
CdConcDeveng VARCHAR(4),
CdConcDed VARCHAR(4),
RubroConc VARCHAR(50),
MudReajuste BIT DEFAULT ((0)) NOT NULL,
CodFEDian VARCHAR(20)
 CONSTRAINT PK_ConcDiversos PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_ConcDiversosConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_ConcDiversosGrupo CHECK (([Grupo]='ANTICIPOS' OR [Grupo]='FACTURA' OR [Grupo]='GASTOS' OR [Grupo]='EGRESOS' OR [Grupo]='INGRESOS' OR [Grupo]='OTROS')),
 CONSTRAINT CK_ConcDiversosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_ConcDiversosIdCueCre CHECK ((len([IdCueCre])>(0))),
 CONSTRAINT CK_ConcDiversosIdCueDeb CHECK ((len([IdCueDeb])>(0))),
 CONSTRAINT CK_ConcDiversosIdUsuario CHECK ((len([IdUsuario])>(0))))
CREATE TABLE Conceptos ( 
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(100) NOT NULL,
IdDoc VARCHAR(3) NOT NULL,
IdCom VARCHAR(3) NOT NULL,
Vcmto BIT DEFAULT (0) NOT NULL,
Imptos BIT DEFAULT (0) NOT NULL,
Retfte BIT DEFAULT (0) NOT NULL,
RetIca BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(150),
Pdterminado INT DEFAULT (0) NOT NULL,
TrfaSanc DECIMAL(14,4) DEFAULT (0) NOT NULL,
RndTotal INT DEFAULT (2) NOT NULL,
DcmtoEquiv BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
TipoContab VARCHAR(10) DEFAULT ('G'),
CdComNiif VARCHAR(3),
CdComFiscal VARCHAR(3),
CodCiaTdo CHAR(2),
TipoConRev INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Conceptos PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_ConceptosConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_ConceptosIdCom CHECK ((len([IdCom]) > 0)),
 CONSTRAINT CK_ConceptosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_ConceptosIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_ConceptosIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE ConceptosAdmon ( 
IdConcepto VARCHAR(4) NOT NULL,
IdAdmon VARCHAR(4) NOT NULL,
IdClase INT DEFAULT (1) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME
 CONSTRAINT PK_ConceptosAdmon PRIMARY KEY CLUSTERED (IdConcepto,IdAdmon,IdClase),
 CONSTRAINT CK_ConceptosAdmonIdAdmon CHECK ((len([IdAdmon]) > 0)),
 CONSTRAINT CK_ConceptosAdmonIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_ConceptosAdmonIdCuenta CHECK ((len([IdCuenta]) > 0)))
CREATE TABLE ConceptosCia ( 
IdConcepto VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL
 CONSTRAINT PK_ConceptosCia PRIMARY KEY CLUSTERED (IdConcepto,IdCia),
 CONSTRAINT CK_ConceptosCiaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ConceptosCiaIdConcepto CHECK ((len([IdConcepto]) > 0)))
CREATE TABLE ConceptosCue ( 
IdConcepto VARCHAR(4) NOT NULL,
IdClase INT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(50) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
TipoMov CHAR(1) DEFAULT ('D') NOT NULL,
DetalleMov VARCHAR(150),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
TipoTerc CHAR(1),
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME
 CONSTRAINT PK_ConceptosCue PRIMARY KEY CLUSTERED (IdConcepto,IdClase),
 CONSTRAINT CK_ConceptosCueDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_ConceptosCueIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_ConceptosCueIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_ConceptosCueTipoMov CHECK (([TipoMov] = 'C' or [TipoMov] = 'D')))
CREATE TABLE ConceptosTrib ( 
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(250) NOT NULL,
CodigoConc VARCHAR(10) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
CdTarifa VARCHAR(4),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ConceptosTrib PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_ConceptosTribCodigoConc CHECK ((len([CodigoConc])>(0))),
 CONSTRAINT CK_ConceptosTribConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_ConceptosTribIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_ConceptosTribIdConcepto CHECK ((len([IdConcepto])>(0))))
CREATE TABLE CtasCorrCia ( 
IdCta VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL
 CONSTRAINT PK_CtasCorrCia PRIMARY KEY CLUSTERED (IdCta,IdCia),
 CONSTRAINT CK_CtasCorrCiaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_CtasCorrCiaIdCta CHECK ((len([IdCta]) > 0)))
CREATE TABLE CtasCorrientes ( 
IdCta VARCHAR(4) NOT NULL,
NumeroCta VARCHAR(20) NOT NULL,
IdBanco VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
ConsCheques BIT DEFAULT (0) NOT NULL,
RangoCons VARCHAR(20),
ConsActual INT DEFAULT (0) NOT NULL,
Formato VARCHAR(20),
TipoPapel INT DEFAULT (1) NOT NULL,
Orientacion INT DEFAULT (1) NOT NULL,
VistaPrevia BIT DEFAULT (0) NOT NULL,
VerSetup BIT DEFAULT (0) NOT NULL,
NumCopias INT DEFAULT (1) NOT NULL,
IdCiaDef CHAR(2) DEFAULT ('00') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
TipoProp VARCHAR(10)
 CONSTRAINT PK_CtasCorrientes PRIMARY KEY CLUSTERED (IdCta),
 CONSTRAINT IX_CtasCorrientesNumeroCta UNIQUE NONCLUSTERED (NumeroCta,IdBanco),
 CONSTRAINT CK_CtasCorrientesIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_CtasCorrientesIdCiaDef CHECK ((len([IdCiaDef]) > 0)),
 CONSTRAINT CK_CtasCorrientesIdCta CHECK ((len([IdCta]) > 0)),
 CONSTRAINT CK_CtasCorrientesIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_CtasCorrientesNumCopias CHECK (([NumCopias] <= 10)),
 CONSTRAINT CK_CtasCorrientesNumeroCta CHECK ((len([NumeroCta]) > 0)),
 CONSTRAINT CK_CtasCorrientesOrientacion CHECK (([Orientacion] >= 0 and [Orientacion] <= 2)))
CREATE TABLE Departamentos ( 
IdDep VARCHAR(8) NOT NULL,
Departamento VARCHAR(50) NOT NULL,
Codigo VARCHAR(4) NOT NULL,
IdPais VARCHAR(8) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Departamentos PRIMARY KEY CLUSTERED (IdDep),
 CONSTRAINT IX_DepartamentosCodigo UNIQUE NONCLUSTERED (Codigo),
 CONSTRAINT CK_DepartamentosCodigo CHECK ((len([Codigo]) > 0)),
 CONSTRAINT CK_DepartamentosDepartamento CHECK ((len([Departamento]) > 0)),
 CONSTRAINT CK_DepartamentosIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_DepartamentosIdPais CHECK ((len([IdPais]) > 0)))
CREATE TABLE Dependencias ( 
IdDep VARCHAR(4) NOT NULL,
Dependencia VARCHAR(50) NOT NULL,
JefeDep VARCHAR(50),
IdArea VARCHAR(4) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
TipRiesgo DECIMAL(10,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Dependencias PRIMARY KEY CLUSTERED (IdDep),
 CONSTRAINT CK_DependenciasDependencia CHECK ((len([Dependencia]) > 0)),
 CONSTRAINT CK_DependenciasIdArea CHECK ((len([IdArea]) > 0)),
 CONSTRAINT CK_DependenciasIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_DependenciasIdSubCos CHECK ((len([IdSubCos]) > 0)))
CREATE TABLE Diarios ( 
IdDiario VARCHAR(4) NOT NULL,
Diario VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
CodTransac VARCHAR(10)
 CONSTRAINT PK_Diarios PRIMARY KEY CLUSTERED (IdDiario),
 CONSTRAINT CK_DiariosDiario CHECK ((len([Diario]) > 0)),
 CONSTRAINT CK_DiariosIdDiario CHECK ((len([IdDiario]) > 0)))
CREATE TABLE Diferidos ( 
IdDiferido VARCHAR(30) NOT NULL,
NomDiferido VARCHAR(250) NOT NULL,
IdTipDif VARCHAR(4) DEFAULT ('0') NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdRespons VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
VrAdiciones MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
NumPeriodos INT DEFAULT (0) NOT NULL,
FecFinAmtza DATETIME,
Ajustable BIT DEFAULT (0) NOT NULL,
Contable BIT DEFAULT (0) NOT NULL,
VrAjuInfAcum MONEY DEFAULT (0) NOT NULL,
VrAmtzaAcuHis MONEY DEFAULT (0) NOT NULL,
VrAmtzaAcum MONEY DEFAULT (0) NOT NULL,
VrAjuInfAmtza MONEY DEFAULT (0) NOT NULL,
CuotasAmtza INT DEFAULT (0) NOT NULL,
VrCorrMonDifAcu MONEY DEFAULT (0) NOT NULL,
CorrMonDiferida MONEY DEFAULT (0) NOT NULL,
NumMesesDif INT DEFAULT (0) NOT NULL,
FecUltAmtza SMALLDATETIME NOT NULL,
CueEnGrupo BIT DEFAULT (0) NOT NULL,
IdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueAmortiza VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueAjuDif VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueCorrDif VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueAjuAmtza VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCueCorrAA VARCHAR(16) DEFAULT ('0') NOT NULL,
NumDoc VARCHAR(20),
Referencia VARCHAR(50),
DesUbicacion VARCHAR(150),
IdEstado VARCHAR(4) DEFAULT ('0002') NOT NULL,
FecRetiro SMALLDATETIME,
IdCausal VARCHAR(4) NOT NULL,
ComentRetiro VARCHAR(250),
Comentarios VARCHAR(250),
FecCreacion SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoAmtza CHAR(1) DEFAULT ('T') NOT NULL,
NitCliente VARCHAR(16),
AgenCliente VARCHAR(16),
CantGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdProv VARCHAR(16) DEFAULT ('0') NOT NULL,
NumPlaca VARCHAR(20),
CodInstala VARCHAR(4),
TipoInvers VARCHAR(10),
TipoContable VARCHAR(10) DEFAULT ('CONTAB') NOT NULL,
CodNiifDif VARCHAR(16),
CodNiifAmtza VARCHAR(16),
TipComp VARCHAR(3),
NumComp INT DEFAULT ((0)),
CdCiaComp CHAR(2)
 CONSTRAINT PK_Diferidos PRIMARY KEY CLUSTERED (IdDiferido),
 CONSTRAINT CK_DiferidosIdCausal CHECK ((len([IdCausal]) > 0)),
 CONSTRAINT CK_DiferidosIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_DiferidosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_DiferidosIdCueAjuAmtza CHECK ((len([IdCueAjuAmtza]) > 0)),
 CONSTRAINT CK_DiferidosIdCueAjuDif CHECK ((len([IdCueAjuDif]) > 0)),
 CONSTRAINT CK_DiferidosIdCueAmortiza CHECK ((len([IdCueAmortiza]) > 0)),
 CONSTRAINT CK_DiferidosIdCueCorrAA CHECK ((len([IdCueCorrAA]) > 0)),
 CONSTRAINT CK_DiferidosIdCueCorrDif CHECK ((len([IdCueCorrDif]) > 0)),
 CONSTRAINT CK_DiferidosIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_DiferidosIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_DiferidosIdDiferido CHECK ((len([IdDiferido]) > 0)),
 CONSTRAINT CK_DiferidosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_DiferidosIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_DiferidosIdRespons CHECK ((len([IdRespons]) > 0)),
 CONSTRAINT CK_DiferidosIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_DiferidosIdTipDif CHECK ((len([IdTipDif]) > 0)),
 CONSTRAINT CK_DiferidosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_DiferidosNomDiferido CHECK ((len([NomDiferido]) > 0)),
 CONSTRAINT CK_DiferidosTipoAmtza CHECK ((len([TipoAmtza]) > 0)))
CREATE TABLE EdsServicio ( 
IdEstacion VARCHAR(4) NOT NULL,
EstServicio VARCHAR(50) NOT NULL,
Direccion VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EdsServicio PRIMARY KEY CLUSTERED (IdEstacion),
 CONSTRAINT CK_EstacionesDireccion CHECK ((len([Direccion]) > 0)),
 CONSTRAINT CK_EstacionesEstServicio CHECK ((len([EstServicio]) > 0)),
 CONSTRAINT CK_EstacionesIdEstacion CHECK ((len([IdEstacion]) > 0)))
CREATE TABLE Emp_Beneficiarios ( 
IdEmpleado VARCHAR(16) NOT NULL,
IdBenef VARCHAR(16) NOT NULL,
Apellido VARCHAR(40) NOT NULL,
SegApellido VARCHAR(40),
Nombre VARCHAR(40) NOT NULL,
SegNombre VARCHAR(40),
TipoId CHAR(1) DEFAULT ('N') NOT NULL,
Parentesco VARCHAR(10),
ValorUpc MONEY DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Emp_Beneficiarios PRIMARY KEY CLUSTERED (IdEmpleado,IdBenef),
 CONSTRAINT CK_Emp_BeneficiariosApellido CHECK ((len([Apellido]) > 0)),
 CONSTRAINT CK_Emp_BeneficiariosIdBenef CHECK ((len([IdBenef]) > 0)),
 CONSTRAINT CK_Emp_BeneficiariosIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Emp_BeneficiariosNombre CHECK ((len([Nombre]) > 0)),
 CONSTRAINT CK_Emp_BeneficiariosTipoId CHECK ((len([TipoId]) > 0)))
CREATE TABLE Emp_Centros ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
NContrato INT DEFAULT ((0)) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
CodSubCosto VARCHAR(16),
Tarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Emp_Centros PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Emp_CentrosIdCCosto CHECK ((len([IdCCosto])>(0))))
CREATE TABLE Emp_Contrato ( 
NContrato INT DEFAULT (0) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
IdTipCon VARCHAR(4) NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME,
FecRetiro SMALLDATETIME,
Indefinido BIT DEFAULT (0) NOT NULL,
IdCargo VARCHAR(4) NOT NULL,
IdJornada VARCHAR(4) NOT NULL,
IdArea VARCHAR(4) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdInstala VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdClase VARCHAR(4) DEFAULT ('0') NOT NULL,
TipoTrabj INT DEFAULT (1) NOT NULL,
IdCot VARCHAR(4) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdNom VARCHAR(4) NOT NULL,
TipoLiquida CHAR(1) DEFAULT ('M') NOT NULL,
ModPromdio CHAR(1) DEFAULT ('F') NOT NULL,
VrSalario MONEY DEFAULT (0) NOT NULL,
VrAuxTrans MONEY DEFAULT (0) NOT NULL,
VrUpc MONEY DEFAULT (0) NOT NULL,
SalMinimo BIT DEFAULT (0) NOT NULL,
SalIntegral BIT DEFAULT (0) NOT NULL,
FPnomina VARCHAR(10) DEFAULT ('EFECTIVO') NOT NULL,
ModoRet INT DEFAULT (0) NOT NULL,
FecAfiSeg SMALLDATETIME,
ATFinMes BIT DEFAULT (0) NOT NULL,
SegFinMes BIT DEFAULT (0) NOT NULL,
DenyPEN BIT DEFAULT (0) NOT NULL,
DenyEPS BIT DEFAULT (0) NOT NULL,
DenyARP BIT DEFAULT (0) NOT NULL,
DenyCaj BIT DEFAULT (0) NOT NULL,
DenyCes BIT DEFAULT (0) NOT NULL,
DenyPri BIT DEFAULT (0) NOT NULL,
DenyVac BIT DEFAULT (0) NOT NULL,
DenyHex BIT DEFAULT (0) NOT NULL,
DenyDcto BIT DEFAULT (0) NOT NULL,
BasePrest CHAR(2) DEFAULT ('PM') NOT NULL,
BaseSeg CHAR(2) DEFAULT ('PM') NOT NULL,
DchDotacion BIT DEFAULT (0) NOT NULL,
DchCafeteria BIT DEFAULT (0) NOT NULL,
Reclmto VARCHAR(50),
Notas VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
SubTipoCot VARCHAR(3),
DsoSabado BIT DEFAULT (0) NOT NULL,
FspFinmes BIT DEFAULT ((0)) NOT NULL,
FecFinPrueba SMALLDATETIME,
TipoPrendDot VARCHAR(10),
TipoMedSent VARCHAR(4),
BenefPacto VARCHAR(100),
TipoTraspaso INT DEFAULT ((0)) NOT NULL,
FechaTraspaso SMALLDATETIME,
ContratoRef INT DEFAULT ((0)) NOT NULL,
IdMedPago VARCHAR(4)
 CONSTRAINT PK_Emp_Contrato PRIMARY KEY CLUSTERED (NContrato),
 CONSTRAINT CK_Emp_ContratoBasePrest CHECK (([BasePrest] = 'BA' or ([BasePrest] = 'SM' or ([BasePrest] = 'SB' or ([BasePrest] = 'IB' or [BasePrest] = 'PM'))))),
 CONSTRAINT CK_Emp_ContratoBaseSeg CHECK (([BaseSeg] = 'BA' or ([BaseSeg] = 'SM' or ([BaseSeg] = 'SB' or ([BaseSeg] = 'IB' or [BaseSeg] = 'PM'))))),
 CONSTRAINT CK_Emp_ContratoFPnomina CHECK (([FPnomina] = 'OTRO' or ([FPnomina] = 'TRANS' or ([FPnomina] = 'CHEQUE' or [FPnomina] = 'EFECTIVO')))),
 CONSTRAINT CK_Emp_ContratoIdArea CHECK ((len([IdArea]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdCot CHECK ((len([IdCot]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdInstala CHECK ((len([IdInstala]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdJornada CHECK ((len([IdJornada]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdNom CHECK ((len([IdNom]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdTipCon CHECK ((len([IdTipCon]) > 0)),
 CONSTRAINT CK_Emp_ContratoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Emp_ContratoModoRet CHECK (([ModoRet] >= 0 and [ModoRet] <= 2)),
 CONSTRAINT CK_Emp_ContratoModPromdio CHECK (([ModPromdio] = 'F' or [ModPromdio] = 'V')),
 CONSTRAINT CK_Emp_ContratoTipoLiquida CHECK (([TipoLiquida] = 'S' or ([TipoLiquida] = 'M' or ([TipoLiquida] = 'Q' or [TipoLiquida] = 'D')))),
 CONSTRAINT CK_Emp_ContratoTipoTrabj CHECK (([TipoTrabj] >= 1 and [TipoTrabj] <= 9)))
CREATE TABLE Emp_Estudios ( 
IdEmpleado VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Estblecmto VARCHAR(50) NOT NULL,
Titulo VARCHAR(50) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME,
IdClase VARCHAR(4),
Habilitado BIT DEFAULT ((1)) NOT NULL
 CONSTRAINT PK_Emp_Estudios PRIMARY KEY CLUSTERED (IdEmpleado,Item),
 CONSTRAINT CK_Emp_EstudiosEstblecmto CHECK ((len([Estblecmto]) > 0)),
 CONSTRAINT CK_Emp_EstudiosIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Emp_EstudiosTitulo CHECK ((len([Titulo]) > 0)))
CREATE TABLE Emp_ExpLaboral ( 
IdEmpleado VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Empresa VARCHAR(50) NOT NULL,
Cargo VARCHAR(20) NOT NULL,
FecInicio SMALLDATETIME,
FecRetiro SMALLDATETIME,
DirEmpresa VARCHAR(100),
TelEmpresa VARCHAR(20)
 CONSTRAINT PK_Emp_ExpLaboral PRIMARY KEY CLUSTERED (IdEmpleado,Item),
 CONSTRAINT CK_Emp_ExpLaboralCargo CHECK ((len([Cargo]) > 0)),
 CONSTRAINT CK_Emp_ExpLaboralEmpresa CHECK ((len([Empresa]) > 0)),
 CONSTRAINT CK_Emp_ExpLaboralIdEmpleado CHECK ((len([IdEmpleado]) > 0)))
CREATE TABLE Emp_Parientes ( 
IdEmpleado VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Parntsco VARCHAR(10) DEFAULT ('HIJO') NOT NULL,
Nombre VARCHAR(50) NOT NULL,
FecNacmto SMALLDATETIME,
UltGrado VARCHAR(20),
Dirccion VARCHAR(100),
Telefno VARCHAR(20),
TipoRef VARCHAR(10),
NitRef VARCHAR(16),
EmailRef VARCHAR(100),
CargoRef VARCHAR(50)
 CONSTRAINT PK_Emp_Parientes PRIMARY KEY CLUSTERED (IdEmpleado,Item),
 CONSTRAINT CK_Emp_ParientesIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Emp_ParientesNombre CHECK ((len([Nombre]) > 0)),
 CONSTRAINT CK_Emp_ParientesParntsco CHECK (([Parntsco] = 'OTRO' or ([Parntsco] = 'AMIGO' or ([Parntsco] = 'PARIENTE' or ([Parntsco] = 'TIO' or ([Parntsco] = 'ABUELO' or ([Parntsco] = 'CONYUGE' or ([Parntsco] = 'PADRE' or [Parntsco] = 'HIJO')))))))))
CREATE TABLE Empaques ( 
IdEmp VARCHAR(4) NOT NULL,
Empaque VARCHAR(50) NOT NULL,
CodMintra VARCHAR(10),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Empaques PRIMARY KEY CLUSTERED (IdEmp),
 CONSTRAINT CK_EmpaquesEmpaque CHECK ((len([Empaque]) > 0)),
 CONSTRAINT CK_EmpaquesIdEmp CHECK ((len([IdEmp]) > 0)))
CREATE TABLE Empleados ( 
IdEmpleado VARCHAR(16) NOT NULL,
Apellidos VARCHAR(80) NOT NULL,
Nombres VARCHAR(70) NOT NULL,
Codigo VARCHAR(16) NOT NULL,
TipoId CHAR(1) DEFAULT ('N') NOT NULL,
Dv CHAR(1) DEFAULT ('0'),
IdLugarCed VARCHAR(8) NOT NULL,
Direccion VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
TelMovil VARCHAR(20),
e_mail VARCHAR(100),
VvdaPropia BIT DEFAULT ((0)) NOT NULL,
FecNacmto SMALLDATETIME NOT NULL,
LugarNacmto VARCHAR(30),
TipoSangre CHAR(2) DEFAULT ('A') NOT NULL,
FactorRh CHAR(1) DEFAULT ('+') NOT NULL,
Sexo CHAR(1) DEFAULT ('M') NOT NULL,
IdEstCivil VARCHAR(4) NOT NULL,
NHijos INT DEFAULT ((0)) NOT NULL,
LibMilitar VARCHAR(25),
ClaseLib INT DEFAULT ((0)) NOT NULL,
FechaLib SMALLDATETIME,
DistMil VARCHAR(10),
CertJudicial VARCHAR(25),
FecJudicial SMALLDATETIME,
VigJudicial SMALLDATETIME,
Pasporte VARCHAR(25),
VigPaspte SMALLDATETIME,
Licencia VARCHAR(25),
IdLugar VARCHAR(8) NOT NULL,
CatLicencia INT DEFAULT ((0)) NOT NULL,
FecLicencia SMALLDATETIME,
VigLicencia SMALLDATETIME,
IdProf VARCHAR(4) NOT NULL,
TallaCam VARCHAR(5),
TallaPan VARCHAR(5),
TallaZap VARCHAR(5),
UsaGafas BIT DEFAULT ((0)) NOT NULL,
Conyugue VARCHAR(50),
ConyFecNac SMALLDATETIME,
ConyTrabaja BIT DEFAULT ((0)) NOT NULL,
ConyEmpresa VARCHAR(50),
ConyCargo VARCHAR(20),
ConyFing SMALLDATETIME,
ConyTel VARCHAR(20),
IdFonPen VARCHAR(8) NOT NULL,
IdFonEps VARCHAR(8) NOT NULL,
IdFonArp VARCHAR(8) NOT NULL,
IdFonCes VARCHAR(8) NOT NULL,
IdCajaCom VARCHAR(8) NOT NULL,
CdFonAvp VARCHAR(8),
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(25),
IdBanco VARCHAR(4) NOT NULL,
CdLocCue VARCHAR(8),
NContrato INT DEFAULT ((0)) NOT NULL,
FecUltIng SMALLDATETIME,
FecUltRet SMALLDATETIME,
FecVincula SMALLDATETIME,
NCAnterior INT DEFAULT ((0)) NOT NULL,
FecIngAnt SMALLDATETIME,
FecRetAnt SMALLDATETIME,
FecUltAum SMALLDATETIME,
FecUltCes SMALLDATETIME,
FecUltPri SMALLDATETIME,
FecUltVac SMALLDATETIME,
FecUltDot SMALLDATETIME,
FecUltExm SMALLDATETIME,
FecUltCap SMALLDATETIME,
FecUltParc SMALLDATETIME,
EsCondtor BIT DEFAULT ((0)) NOT NULL,
pVehiculo VARCHAR(10),
FotoEmp VARCHAR(30),
FotoLic VARCHAR(30),
FotoFirma VARCHAR(30),
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
DecRenta INT DEFAULT ((0)) NOT NULL,
NivelEduc VARCHAR(4)
 CONSTRAINT PK_Empleados PRIMARY KEY CLUSTERED (IdEmpleado),
 CONSTRAINT IX_EmpleadosCodigo UNIQUE NONCLUSTERED (Codigo),
 CONSTRAINT CK_EmpleadosApellidos CHECK ((len([Apellidos])>(0))),
 CONSTRAINT CK_EmpleadosCatLicencia CHECK (([CatLicencia]>=(0) AND [CatLicencia]<=(12))),
 CONSTRAINT CK_EmpleadosClaseLib CHECK (([ClaseLib]>=(0) AND [ClaseLib]<=(2))),
 CONSTRAINT CK_EmpleadosCodigo CHECK ((len([Codigo])>(0))),
 CONSTRAINT CK_EmpleadosDireccion CHECK ((len([Direccion])>(0))),
 CONSTRAINT CK_EmpleadosFactorRh CHECK (([FactorRh]='+' OR [FactorRh]='-')),
 CONSTRAINT CK_EmpleadosIdBanco CHECK ((len([IdBanco])>(0))),
 CONSTRAINT CK_EmpleadosIdCajaCom CHECK ((len([IdCajaCom])>(0))),
 CONSTRAINT CK_EmpleadosIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_EmpleadosIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_EmpleadosIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_EmpleadosIdEstCivil CHECK ((len([IdEstCivil])>(0))),
 CONSTRAINT CK_EmpleadosIdFonArp CHECK ((len([IdFonArp])>(0))),
 CONSTRAINT CK_EmpleadosIdFonCes CHECK ((len([IdFonCes])>(0))),
 CONSTRAINT CK_EmpleadosIdFonEps CHECK ((len([IdFonEps])>(0))),
 CONSTRAINT CK_EmpleadosIdFonPen CHECK ((len([IdFonPen])>(0))),
 CONSTRAINT CK_EmpleadosIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_EmpleadosIdLugar CHECK ((len([IdLugar])>(0))),
 CONSTRAINT CK_EmpleadosIdLugarCed CHECK ((len([IdLugarCed])>(0))),
 CONSTRAINT CK_EmpleadosIdProf CHECK ((len([IdProf])>(0))),
 CONSTRAINT CK_EmpleadosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_EmpleadosNombres CHECK ((len([Nombres])>(0))),
 CONSTRAINT CK_EmpleadosSexo CHECK (([Sexo]='O' OR ([Sexo]='F' OR [Sexo]='M'))),
 CONSTRAINT CK_EmpleadosTelefono CHECK ((len([Telefono])>(0))),
 CONSTRAINT CK_EmpleadosTipoId CHECK (([TipoId]='P' OR ([TipoId]='R' OR ([TipoId]='T' OR ([TipoId]='U' OR ([TipoId]='O' OR ([TipoId]='E' OR ([TipoId]='C' OR ([TipoId]='X' OR [TipoId]='N'))))))))),
 CONSTRAINT CK_EmpleadosTipoSangre CHECK (([TipoSangre]='AB' OR ([TipoSangre]='B' OR ([TipoSangre]='O' OR [TipoSangre]='A')))))
CREATE TABLE EstadoCiv ( 
IdEstado VARCHAR(4) NOT NULL,
EstCivil VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EstadoCiv PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoCivEstCivil CHECK ((len([EstCivil]) > 0)),
 CONSTRAINT CK_EstadoCivIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE EstadoDoc ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0) NOT NULL,
CodDcmto VARCHAR(3) DEFAULT ('0'),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EstadoDoc PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoDocEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_EstadoDocIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE EstadoOper ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_EstadoOper PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoOperEstado CHECK ((len([Estado])>(0))))
CREATE TABLE EstadoPro ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EstadoPro PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoProEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_EstadoProIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE EstadoSer ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EstadoSer PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoSerEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_EstadoSerIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE EstadoTer ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EstadoTer PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoTerEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_EstadoTerIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE EstadoVeh ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0) NOT NULL,
OutDemand BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_EstadoVeh PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_EstadoVehEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_EstadoVehIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE Estratos ( 
IdEstrato VARCHAR(4) NOT NULL,
Estrato VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Estratos PRIMARY KEY CLUSTERED (IdEstrato),
 CONSTRAINT CK_EstratosEstrato CHECK ((len([Estrato]) > 0)),
 CONSTRAINT CK_EstratosIdEstrato CHECK ((len([IdEstrato]) > 0)))
CREATE TABLE ExpLicencias ( 
IdLugar VARCHAR(8) NOT NULL,
LugarLic VARCHAR(50) NOT NULL,
CodDpto VARCHAR(8) NOT NULL,
Dpto VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ExpLicencias PRIMARY KEY CLUSTERED (IdLugar),
 CONSTRAINT CK_ExpLicenciasCodDpto CHECK ((len([CodDpto]) > 0)),
 CONSTRAINT CK_ExpLicenciasDpto CHECK ((len([Dpto]) > 0)),
 CONSTRAINT CK_ExpLicenciasIdLugar CHECK ((len([IdLugar]) > 0)),
 CONSTRAINT CK_ExpLicenciasLugarLic CHECK ((len([LugarLic]) > 0)))
CREATE TABLE Fijos ( 
IdCargo VARCHAR(4) NOT NULL,
Concepto VARCHAR(100) NOT NULL,
Obligatorio BIT DEFAULT (0) NOT NULL,
TipoAplica VARCHAR(10) DEFAULT ('TODOS') NOT NULL,
DiasSemana VARCHAR(20),
DiasMes VARCHAR(100),
ValorMensual MONEY DEFAULT (0) NOT NULL,
ValorDiario MONEY DEFAULT (0) NOT NULL,
IdCuentaDeb VARCHAR(16) NOT NULL,
IdCuentaCre VARCHAR(16) NOT NULL,
IdCueDebVp VARCHAR(16) NOT NULL,
IdCueCreVp VARCHAR(16) NOT NULL,
NCuotas INT DEFAULT (0) NOT NULL,
DiasVcmto VARCHAR(50),
OrdenAbono INT DEFAULT (0) NOT NULL,
TipoDcto CHAR(1) DEFAULT ('%') NOT NULL,
DctoPpago DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrCargoAdic MONEY DEFAULT (0) NOT NULL,
FecLimiteIni SMALLDATETIME,
FecLimiteFin SMALLDATETIME,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CdTarifaIva VARCHAR(4),
CdTarifaRet VARCHAR(4),
CdCuentaIva VARCHAR(16),
CdCuentaRet VARCHAR(16),
CdCuentaIca VARCHAR(16),
CodFEDian VARCHAR(20),
IvaIncluido BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Fijos PRIMARY KEY CLUSTERED (IdCargo),
 CONSTRAINT CK_FijosConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_FijosIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_FijosIdCueCreVp CHECK ((len([IdCueCreVp]) > 0)),
 CONSTRAINT CK_FijosIdCueDebVp CHECK ((len([IdCueDebVp]) > 0)),
 CONSTRAINT CK_FijosIdCuentaCre CHECK ((len([IdCuentaCre]) > 0)),
 CONSTRAINT CK_FijosIdCuentaDeb CHECK ((len([IdCuentaDeb]) > 0)),
 CONSTRAINT CK_FijosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_FijosTipoAplica CHECK ((len([TipoAplica]) > 0)))
CREATE TABLE Fijos_Cla ( 
IdCargo VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
ValorMensual MONEY DEFAULT (0) NOT NULL,
ValorDiario MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Fijos_Cla PRIMARY KEY CLUSTERED (IdCargo,IdClase),
 CONSTRAINT CK_Fijos_ClaIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Fijos_ClaIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE Fijos_Cue ( 
IdCargo VARCHAR(4) NOT NULL,
IdAdmon VARCHAR(4) NOT NULL,
IdCuentaDeb VARCHAR(16) NOT NULL,
IdCuentaCre VARCHAR(16) NOT NULL,
IdCueDebVp VARCHAR(16) NOT NULL,
IdCueCreVp VARCHAR(16) NOT NULL,
IdCuentaIva VARCHAR(16),
IdCuentaRet VARCHAR(16),
IdCuentaIca VARCHAR(16)
 CONSTRAINT PK_Fijos_Cue PRIMARY KEY CLUSTERED (IdCargo,IdAdmon),
 CONSTRAINT CK_Fijos_CueIdAdmon CHECK ((len([IdAdmon]) > 0)),
 CONSTRAINT CK_Fijos_CueIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Fijos_CueIdCueCreVp CHECK ((len([IdCueCreVp]) > 0)),
 CONSTRAINT CK_Fijos_CueIdCueDebVp CHECK ((len([IdCueDebVp]) > 0)),
 CONSTRAINT CK_Fijos_CueIdCuentaCre CHECK ((len([IdCuentaCre]) > 0)),
 CONSTRAINT CK_Fijos_CueIdCuentaDeb CHECK ((len([IdCuentaDeb]) > 0)))
CREATE TABLE Fijos_Veh ( 
IdCargo VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
ValorMensual MONEY DEFAULT (0) NOT NULL,
ValorDiario MONEY DEFAULT (0) NOT NULL,
Excluir BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Fijos_Veh PRIMARY KEY CLUSTERED (IdCargo,IdVehiculo),
 CONSTRAINT CK_Fijos_VehIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Fijos_VehIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE FinAlmacenes ( 
IdAlmacen VARCHAR(4) NOT NULL,
Almacen VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_FinAlmacenes PRIMARY KEY CLUSTERED (IdAlmacen),
 CONSTRAINT CK_FinAlmacenesAlmacen CHECK ((len([Almacen]) > 0)),
 CONSTRAINT CK_FinAlmacenesIdAlmacen CHECK ((len([IdAlmacen]) > 0)))
CREATE TABLE FinClieSaldos ( 
IdClie VARCHAR(16) NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCia CHAR(2) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_FinClieSaldos PRIMARY KEY CLUSTERED (IdClie,CdAgencia,IdCia),
 CONSTRAINT CK_FinClieSaldosCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_FinClieSaldosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_FinClieSaldosIdClie CHECK ((len([IdClie]) > 0)))
CREATE TABLE FinClieSaldosLin ( 
IdClie VARCHAR(16) NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdLinea VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL,
VrSaldoCap MONEY DEFAULT (0) NOT NULL,
VrSaldoInt MONEY DEFAULT (0) NOT NULL,
VrSaldoOtro MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_FinClieSaldosLin PRIMARY KEY CLUSTERED (IdClie,CdAgencia,IdLinea,IdCia),
 CONSTRAINT CK_FinClieSaldosLinCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_FinClieSaldosLinIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_FinClieSaldosLinIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_FinClieSaldosLinIdLinea CHECK ((len([IdLinea]) > 0)))
CREATE TABLE FinConcFactura ( 
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(250) NOT NULL,
TipoConc VARCHAR(10) DEFAULT ('INTERESES') NOT NULL,
Gravado BIT DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
IdCuenta VARCHAR(16) NOT NULL,
CdCueIva VARCHAR(16),
CdCueRet VARCHAR(16),
CdCueIca VARCHAR(16),
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CodFEDian VARCHAR(20)
 CONSTRAINT PK_FinConcFactura PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_FinConcFacturaConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_FinConcFacturaIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_FinConcFacturaIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_FinConcFacturaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_FinConcFacturaTipoConc CHECK ((len([TipoConc]) > 0)))
CREATE TABLE FinCuposEmp ( 
nAnno INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
nSmlvIni DECIMAL(14,4) DEFAULT (0) NOT NULL,
nSmlvFin DECIMAL(14,4) DEFAULT (0) NOT NULL,
Antig_Ini DECIMAL(14,4) DEFAULT (0) NOT NULL,
Antig_Fin DECIMAL(14,4) DEFAULT (0) NOT NULL,
MontoConGar DECIMAL(14,4) DEFAULT (0) NOT NULL,
MontoSinGar DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_FinCuposEmp PRIMARY KEY CLUSTERED (nAnno,Item))
CREATE TABLE Fondos ( 
IdFondo VARCHAR(8) NOT NULL,
Fondo VARCHAR(100) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
CodigoEps VARCHAR(10),
CodigoPen VARCHAR(10),
CodigoArp VARCHAR(10),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Fondos PRIMARY KEY CLUSTERED (IdFondo),
 CONSTRAINT CK_FondosFondo CHECK ((len([Fondo]) > 0)),
 CONSTRAINT CK_FondosIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_FondosIdFondo CHECK ((len([IdFondo]) > 0)),
 CONSTRAINT CK_FondosIdTercero CHECK ((len([IdTercero]) > 0)))
CREATE TABLE FormasCue ( 
IdForma VARCHAR(4) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME
 CONSTRAINT PK_FormasCue PRIMARY KEY CLUSTERED (IdForma,IdConcepto),
 CONSTRAINT CK_Formaspago_CueIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Formaspago_CueIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Formaspago_CueIdForma CHECK ((len([IdForma]) > 0)))
CREATE TABLE Formaspago ( 
IdForma VARCHAR(4) NOT NULL,
FormaPago VARCHAR(50) NOT NULL,
Consecutivo INT DEFAULT ((0)) NOT NULL,
CuadreCaja BIT DEFAULT ((0)) NOT NULL,
RefDcmto BIT DEFAULT ((0)) NOT NULL,
RefNit BIT DEFAULT ((0)) NOT NULL,
RefBco BIT DEFAULT ((0)) NOT NULL,
RefFech BIT DEFAULT ((0)) NOT NULL,
RefAtza BIT DEFAULT ((0)) NOT NULL,
RefOtro BIT DEFAULT ((0)) NOT NULL,
VldRangos BIT DEFAULT ((0)) NOT NULL,
VleConsumo BIT DEFAULT ((0)) NOT NULL,
CodIntegrity VARCHAR(20),
Inactivo BIT DEFAULT ((0)) NOT NULL,
CodValera VARCHAR(10) DEFAULT ('VAL'),
CodIntCom VARCHAR(20),
RefProducto BIT DEFAULT ((0)) NOT NULL,
FactTicket BIT DEFAULT ((0)) NOT NULL,
CdMedPago VARCHAR(4)
 CONSTRAINT PK_Formaspago PRIMARY KEY CLUSTERED (IdForma),
 CONSTRAINT CK_FormaspagoFormaPago CHECK ((len([FormaPago])>(0))),
 CONSTRAINT CK_FormaspagoIdForma CHECK ((len([IdForma])>(0))))
CREATE TABLE FuentesPago ( 
IdFuente VARCHAR(4) NOT NULL,
FuentePago VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_FuentesPago PRIMARY KEY CLUSTERED (IdFuente),
 CONSTRAINT CK_FuentesPagoFuentePago CHECK ((len([FuentePago]) > 0)),
 CONSTRAINT CK_FuentesPagoIdFuente CHECK ((len([IdFuente]) > 0)))
CREATE TABLE Grupos ( 
IdGrupo VARCHAR(8) NOT NULL,
Grupo VARCHAR(150) NOT NULL,
IdLinea VARCHAR(8) NOT NULL,
TipoInvent VARCHAR(10) DEFAULT ('COMERCIAL') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Grupos PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposGrupo CHECK ((len([Grupo]) > 0)),
 CONSTRAINT CK_GruposIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_GruposIdLinea CHECK ((len([IdLinea]) > 0)),
 CONSTRAINT CK_GruposTipoInvent CHECK ((len([TipoInvent]) > 0)))
CREATE TABLE GruposAgenc ( 
IdGrupo VARCHAR(4) NOT NULL,
GrupoAgenc VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_GruposAgenc PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposAgencGrupoAgenc CHECK ((len([GrupoAgenc]) > 0)),
 CONSTRAINT CK_GruposAgencIdGrupo CHECK ((len([IdGrupo]) > 0)))
CREATE TABLE GruposAR ( 
IdGrupo VARCHAR(4) NOT NULL,
AltoRiesgo VARCHAR(50) NOT NULL,
TarfaTrab DECIMAL(10,4) DEFAULT (0) NOT NULL,
TarfaEmp DECIMAL(10,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_GruposAR PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposARAltoRiesgo CHECK ((len([AltoRiesgo]) > 0)),
 CONSTRAINT CK_GruposARIdGrupo CHECK ((len([IdGrupo]) > 0)))
CREATE TABLE GruposCli ( 
IdGrupo VARCHAR(4) NOT NULL,
GrupoClie VARCHAR(50) NOT NULL,
ModApp VARCHAR(10) DEFAULT ('CLIENTE') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_GruposCli PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposCliGrupoClie CHECK ((len([GrupoClie]) > 0)),
 CONSTRAINT CK_GruposCliIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_GruposCliModApp CHECK (([ModApp] = 'VENDEDOR' or ([ModApp] = 'CONDUCTOR' or ([ModApp] = 'PROVEEDOR' or [ModApp] = 'CLIENTE')))))
CREATE TABLE GruposMcia ( 
IdGrupo VARCHAR(10) NOT NULL,
GrupoMcia VARCHAR(250) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_GruposMcia PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposMciaGrupoMcia CHECK ((len([GrupoMcia]) > 0)),
 CONSTRAINT CK_GruposMciaIdGrupo CHECK ((len([IdGrupo]) > 0)))
CREATE TABLE GruposPro ( 
IdGrupo VARCHAR(4) NOT NULL,
GrupoProp VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_GruposPro PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposProGrupoProp CHECK ((len([GrupoProp]) > 0)),
 CONSTRAINT CK_GruposProIdGrupo CHECK ((len([IdGrupo]) > 0)))
CREATE TABLE GruposRot ( 
IdGrupo VARCHAR(4) NOT NULL,
GrupoRot VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_GruposRot PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_GruposRotGrupoRot CHECK ((len([GrupoRot]) > 0)),
 CONSTRAINT CK_GruposRotIdGrupo CHECK ((len([IdGrupo]) > 0)))
CREATE TABLE Infracciones ( 
NumInf INT DEFAULT (0) NOT NULL,
Infraccion VARCHAR(250) NOT NULL
 CONSTRAINT PK_Infracciones PRIMARY KEY CLUSTERED (NumInf),
 CONSTRAINT CK_InfraccionesInfraccion CHECK ((len([Infraccion]) > 0)))
CREATE TABLE Instalaciones ( 
IdInstala VARCHAR(4) NOT NULL,
Instlacion VARCHAR(50) NOT NULL,
DirInstala VARCHAR(100),
CodCiu VARCHAR(8),
CodCia CHAR(2) DEFAULT ('01'),
IdClase VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Instalaciones PRIMARY KEY CLUSTERED (IdInstala),
 CONSTRAINT CK_InstalacionesIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_InstalacionesIdInstala CHECK ((len([IdInstala]) > 0)),
 CONSTRAINT CK_InstalacionesInstlacion CHECK ((len([Instlacion]) > 0)))
CREATE TABLE Jornadas ( 
IdJornada VARCHAR(4) NOT NULL,
Jornada VARCHAR(50) NOT NULL,
HorasDia INT DEFAULT (8) NOT NULL,
Rangos VARCHAR(25) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Jornadas PRIMARY KEY CLUSTERED (IdJornada),
 CONSTRAINT CK_JornadasIdJornada CHECK ((len([IdJornada]) > 0)),
 CONSTRAINT CK_JornadasJornada CHECK ((len([Jornada]) > 0)),
 CONSTRAINT CK_JornadasRangos CHECK ((len([Rangos]) > 0)))
CREATE TABLE JurAutoridades ( 
IdAutoridad VARCHAR(4) NOT NULL,
NomAutoridad VARCHAR(50) NOT NULL,
Direccion VARCHAR(100),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurAutoridades PRIMARY KEY CLUSTERED (IdAutoridad),
 CONSTRAINT CK_JurAutoridadesIdAutoridad CHECK ((len([IdAutoridad]) > 0)),
 CONSTRAINT CK_JurAutoridadesNomAutoridad CHECK ((len([NomAutoridad]) > 0)))
CREATE TABLE JurCalifica ( 
IdCalifica VARCHAR(4) NOT NULL,
CalificaCaso VARCHAR(50) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurCalifica PRIMARY KEY CLUSTERED (IdCalifica),
 CONSTRAINT CK_JurCalificaCalificaCaso CHECK ((len([CalificaCaso]) > 0)),
 CONSTRAINT CK_JurCalificaIdCalifica CHECK ((len([IdCalifica]) > 0)),
 CONSTRAINT CK_JurCalificaIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE JurCausales ( 
IdCausal VARCHAR(4) NOT NULL,
Causal VARCHAR(50) NOT NULL,
IdTipoPro VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurCausales PRIMARY KEY CLUSTERED (IdCausal),
 CONSTRAINT CK_JurCausalesCausal CHECK ((len([Causal]) > 0)),
 CONSTRAINT CK_JurCausalesIdCausal CHECK ((len([IdCausal]) > 0)),
 CONSTRAINT CK_JurCausalesIdTipoPro CHECK ((len([IdTipoPro]) > 0)))
CREATE TABLE JurClaseAcc ( 
IdClase VARCHAR(4) NOT NULL,
ClaseAccdte VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurClaseAcc PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_JurClaseAccClaseAccdte CHECK ((len([ClaseAccdte]) > 0)),
 CONSTRAINT CK_JurClaseAccIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE JurDocumtos ( 
IdDoc VARCHAR(4) NOT NULL,
Documnto VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurDocumtos PRIMARY KEY CLUSTERED (IdDoc),
 CONSTRAINT CK_JurDocumtosDocumnto CHECK ((len([Documnto]) > 0)),
 CONSTRAINT CK_JurDocumtosIdDoc CHECK ((len([IdDoc]) > 0)))
CREATE TABLE JurEstados ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
NColor INT DEFAULT (0)
 CONSTRAINT PK_JurEstados PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_JurEstadosEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_JurEstadosIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE JurPreguntas ( 
IdPregunta VARCHAR(4) NOT NULL,
PreguntaBas VARCHAR(250) NOT NULL,
IdTipoPro VARCHAR(4) NOT NULL,
TipoDato VARCHAR(15) DEFAULT ('VARCHAR') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurPreguntas PRIMARY KEY CLUSTERED (IdPregunta),
 CONSTRAINT CK_JurPreguntasIdPregunta CHECK ((len([IdPregunta]) > 0)),
 CONSTRAINT CK_JurPreguntasIdTipoPro CHECK ((len([IdTipoPro]) > 0)),
 CONSTRAINT CK_JurPreguntasPreguntaBas CHECK ((len([PreguntaBas]) > 0)),
 CONSTRAINT CK_JurPreguntasTipoDato CHECK ((len([TipoDato]) > 0)))
CREATE TABLE JurTipos ( 
IdTipoPro VARCHAR(4) NOT NULL,
TipoProceso VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurTipos PRIMARY KEY CLUSTERED (IdTipoPro),
 CONSTRAINT CK_JurTiposIdTipoPro CHECK ((len([IdTipoPro]) > 0)),
 CONSTRAINT CK_JurTiposTipoProceso CHECK ((len([TipoProceso]) > 0)))
CREATE TABLE JurTiposRec ( 
IdTipoRec VARCHAR(4) NOT NULL,
TipReclamante VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_JurTiposRec PRIMARY KEY CLUSTERED (IdTipoRec),
 CONSTRAINT CK_JurTiposRecIdTipoRec CHECK ((len([IdTipoRec]) > 0)),
 CONSTRAINT CK_JurTiposRecTipReclamante CHECK ((len([TipReclamante]) > 0)))
CREATE TABLE Lineas ( 
IdLinea VARCHAR(8) NOT NULL,
Linea VARCHAR(150) NOT NULL,
TipoInvent VARCHAR(10) DEFAULT ('COMERCIAL') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Lineas PRIMARY KEY CLUSTERED (IdLinea),
 CONSTRAINT CK_LineasIdLinea CHECK ((len([IdLinea]) > 0)),
 CONSTRAINT CK_LineasLinea CHECK ((len([Linea]) > 0)),
 CONSTRAINT CK_LineasTipoInvent CHECK ((len([TipoInvent]) > 0)))
CREATE TABLE LineasCred ( 
IdLinea VARCHAR(4) NOT NULL,
LinCredito VARCHAR(100) NOT NULL,
CdTasaDef VARCHAR(4),
CdTarifIva VARCHAR(4),
CdTarifRet VARCHAR(4),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_LineasCred PRIMARY KEY CLUSTERED (IdLinea),
 CONSTRAINT CK_LineasCredIdLinea CHECK ((len([IdLinea])>(0))),
 CONSTRAINT CK_LineasCredLinCredito CHECK ((len([LinCredito])>(0))))
CREATE TABLE LineasCredCue ( 
IdLinea VARCHAR(4) NOT NULL,
IdTipoTerc VARCHAR(4) NOT NULL,
Concepto VARCHAR(10) NOT NULL,
IdCuentaDb VARCHAR(16) NOT NULL,
IdCuentaCr VARCHAR(16) NOT NULL
 CONSTRAINT PK_LineasCredCue PRIMARY KEY CLUSTERED (IdLinea,IdTipoTerc,Concepto),
 CONSTRAINT CK_LineasCredCueConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_LineasCredCueIdCuentaCr CHECK ((len([IdCuentaCr])>(0))),
 CONSTRAINT CK_LineasCredCueIdCuentaDb CHECK ((len([IdCuentaDb])>(0))),
 CONSTRAINT CK_LineasCredCueIdLinea CHECK ((len([IdLinea])>(0))),
 CONSTRAINT CK_LineasCredCueIdTipoTerc CHECK ((len([IdTipoTerc])>(0))))
CREATE TABLE Localidades ( 
IdLocal VARCHAR(8) NOT NULL,
Localidad VARCHAR(50) NOT NULL,
IdDep VARCHAR(8) NOT NULL,
TipLocal VARCHAR(20) DEFAULT ('CABECERA_MUNICIPAL') NOT NULL,
Dist_Kmt DECIMAL(10,4) DEFAULT (0) NOT NULL,
Time_hh VARCHAR(8),
DistSede DECIMAL(10,4) DEFAULT (0) NOT NULL,
TimeSede VARCHAR(8),
CelRow DECIMAL(14,4) DEFAULT (0) NOT NULL,
CelCol DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodAlias VARCHAR(10),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Localidades PRIMARY KEY CLUSTERED (IdLocal),
 CONSTRAINT CK_LocalidadesIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_LocalidadesIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_LocalidadesLocalidad CHECK ((len([Localidad]) > 0)),
 CONSTRAINT CK_LocalidadesTipLocal CHECK (([TipLocal] = 'DISTRITO' or ([TipLocal] = 'CASERIO' or ([TipLocal] = 'CABECERA_MUNICIPAL' or ([TipLocal] = 'POBLADO' or ([TipLocal] = 'CORREGIMIENTO' or ([TipLocal] = 'MUNICIPIO' or [TipLocal] = 'CAPITAL_DEP'))))))))
CREATE TABLE Log_Nomina ( 
IdNom VARCHAR(4) NOT NULL,
IdPeriodo VARCHAR(8) NOT NULL,
Cerrado BIT DEFAULT (0) NOT NULL,
IntCtaCte BIT DEFAULT (0) NOT NULL,
LogCtaCte VARCHAR(100)
 CONSTRAINT PK_Log_Nomina PRIMARY KEY CLUSTERED (IdNom,IdPeriodo),
 CONSTRAINT CK_Log_NominaIdNom CHECK ((len([IdNom]) > 0)),
 CONSTRAINT CK_Log_NominaIdPeriodo CHECK ((len([IdPeriodo]) > 0)))
CREATE TABLE Log_Periodos ( 
Anno INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Ene BIT DEFAULT (0) NOT NULL,
Feb BIT DEFAULT (0) NOT NULL,
Mar BIT DEFAULT (0) NOT NULL,
Abr BIT DEFAULT (0) NOT NULL,
May BIT DEFAULT (0) NOT NULL,
Jun BIT DEFAULT (0) NOT NULL,
Jul BIT DEFAULT (0) NOT NULL,
Ago BIT DEFAULT (0) NOT NULL,
Sep BIT DEFAULT (0) NOT NULL,
Oct BIT DEFAULT (0) NOT NULL,
Nov BIT DEFAULT (0) NOT NULL,
Dic BIT DEFAULT (0) NOT NULL,
CierreAnno BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Log_Periodos PRIMARY KEY CLUSTERED (Anno,IdCia),
 CONSTRAINT CK_Log_PeriodosAnno CHECK (([Anno] >= 1990 and [Anno] <= 2050)),
 CONSTRAINT CK_Log_PeriodosIdCia CHECK ((len([IdCia]) > 0)))
CREATE TABLE Marcas ( 
IdMarca VARCHAR(4) NOT NULL,
Marca VARCHAR(50) NOT NULL,
TipoMarca VARCHAR(20) DEFAULT ('PRODUCTOS') NOT NULL,
CodigoMT VARCHAR(10),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Marcas PRIMARY KEY CLUSTERED (IdMarca),
 CONSTRAINT CK_MarcasIdMarca CHECK ((len([IdMarca]) > 0)),
 CONSTRAINT CK_MarcasMarca CHECK ((len([Marca]) > 0)),
 CONSTRAINT CK_MarcasTipoMarca CHECK (([TipoMarca] = 'FILTROS' or ([TipoMarca] = 'GENERAL' or ([TipoMarca] = 'REMOLQUE' or ([TipoMarca] = 'PRODUCTOS' or ([TipoMarca] = 'ACEITES' or ([TipoMarca] = 'LLANTAS' or [TipoMarca] = 'VEHICULOS'))))))))
CREATE TABLE MarcasLin ( 
IdLinea VARCHAR(10) NOT NULL,
LineaVeh VARCHAR(50) NOT NULL,
IdMarca VARCHAR(4) NOT NULL,
CodMT VARCHAR(10),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MarcasLin PRIMARY KEY CLUSTERED (IdLinea),
 CONSTRAINT CK_MarcasLinIdLinea CHECK ((len([IdLinea]) > 0)),
 CONSTRAINT CK_MarcasLinIdMarca CHECK ((len([IdMarca]) > 0)),
 CONSTRAINT CK_MarcasLinLineaVeh CHECK ((len([LineaVeh]) > 0)))
CREATE TABLE MayBonCuentas ( 
IdBonif VARCHAR(4) NOT NULL,
TipoCue INT DEFAULT (0) NOT NULL,
CdTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL
 CONSTRAINT PK_MayBonCuentas PRIMARY KEY CLUSTERED (IdBonif,TipoCue,CdTipo),
 CONSTRAINT CK_MayBonCuentasCdTipo CHECK ((len([CdTipo]) > 0)),
 CONSTRAINT CK_MayBonCuentasIdBonif CHECK ((len([IdBonif]) > 0)),
 CONSTRAINT CK_MayBonCuentasIdCuenta CHECK ((len([IdCuenta]) > 0)))
CREATE TABLE MayEstados ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayEstados PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_MayEstadosEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_MayEstadosIdEstado CHECK ((len([IdEstado]) > 0)))
CREATE TABLE MayItemsInv ( 
IdArticulo VARCHAR(16) NOT NULL,
Descrpcion VARCHAR(150) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('und') NOT NULL,
GrupoArt VARCHAR(50) NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayItemsInv PRIMARY KEY CLUSTERED (IdArticulo),
 CONSTRAINT CK_MayItemsInvCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_MayItemsInvDescrpcion CHECK ((len([Descrpcion]) > 0)),
 CONSTRAINT CK_MayItemsInvGrupoArt CHECK ((len([GrupoArt]) > 0)),
 CONSTRAINT CK_MayItemsInvIdArticulo CHECK ((len([IdArticulo]) > 0)),
 CONSTRAINT CK_MayItemsInvUndMed CHECK ((len([UndMed]) > 0)))
CREATE TABLE MayTipos ( 
IdTipo VARCHAR(4) NOT NULL,
TipContrato VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayTipos PRIMARY KEY CLUSTERED (IdTipo),
 CONSTRAINT CK_MayTiposIdTipo CHECK ((len([IdTipo]) > 0)),
 CONSTRAINT CK_MayTiposTipContrato CHECK ((len([TipContrato]) > 0)))
CREATE TABLE MayTiposAprob ( 
IdAprob VARCHAR(4) NOT NULL,
TipoAprob VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayTiposAprob PRIMARY KEY CLUSTERED (IdAprob),
 CONSTRAINT CK_MayTiposAprobIdAprob CHECK ((len([IdAprob]) > 0)),
 CONSTRAINT CK_MayTiposAprobTipoAprob CHECK ((len([TipoAprob]) > 0)))
CREATE TABLE MayTiposBienes ( 
IdTipBien VARCHAR(4) NOT NULL,
TipoBien VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayTiposBienes PRIMARY KEY CLUSTERED (IdTipBien),
 CONSTRAINT CK_MayTiposBienesIdTipBien CHECK ((len([IdTipBien]) > 0)),
 CONSTRAINT CK_MayTiposBienesTipoBien CHECK ((len([TipoBien]) > 0)))
CREATE TABLE MayTiposBonif ( 
IdBonif VARCHAR(4) NOT NULL,
TipoBonif VARCHAR(50) NOT NULL,
AboCartera BIT DEFAULT (0) NOT NULL,
AboPstmo BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayTiposBonif PRIMARY KEY CLUSTERED (IdBonif),
 CONSTRAINT CK_MayTiposBonifIdBonif CHECK ((len([IdBonif]) > 0)),
 CONSTRAINT CK_MayTiposBonifTipoBonif CHECK ((len([TipoBonif]) > 0)))
CREATE TABLE MayTiposDoc ( 
IdDoc VARCHAR(4) NOT NULL,
NombreDoc VARCHAR(150) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayTiposDoc PRIMARY KEY CLUSTERED (IdDoc),
 CONSTRAINT CK_MayTiposDocIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_MayTiposDocNombreDoc CHECK ((len([NombreDoc]) > 0)))
CREATE TABLE MayTiposPoliza ( 
IdTipoPol VARCHAR(4) NOT NULL,
TipoPoliza VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_MayTiposPoliza PRIMARY KEY CLUSTERED (IdTipoPol),
 CONSTRAINT CK_MayTiposPolizaIdTipoPol CHECK ((len([IdTipoPol]) > 0)),
 CONSTRAINT CK_MayTiposPolizaTipoPoliza CHECK ((len([TipoPoliza]) > 0)))
CREATE TABLE Mercancias ( 
IdMercancia VARCHAR(16) NOT NULL,
DescripMcia VARCHAR(250) NOT NULL,
CodigoMcia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdGrupo VARCHAR(10) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) DEFAULT ('0') NOT NULL,
IdNat VARCHAR(4) NOT NULL,
IdMnjo VARCHAR(4) NOT NULL,
IdTmcia VARCHAR(4) NOT NULL,
EstadoMcia VARCHAR(20) DEFAULT ('SOLIDO') NOT NULL,
Contenedor BIT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
UmCapac VARCHAR(10) DEFAULT ('PESO') NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CodigoUN VARCHAR(30)
 CONSTRAINT PK_Mercancias PRIMARY KEY CLUSTERED (IdMercancia),
 CONSTRAINT CK_MercanciasCodigoMcia CHECK ((len([CodigoMcia]) > 0)),
 CONSTRAINT CK_MercanciasDescripMcia CHECK ((len([DescripMcia]) > 0)),
 CONSTRAINT CK_MercanciasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_MercanciasIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_MercanciasIdMercancia CHECK ((len([IdMercancia]) > 0)),
 CONSTRAINT CK_MercanciasIdMnjo CHECK ((len([IdMnjo]) > 0)),
 CONSTRAINT CK_MercanciasIdNat CHECK ((len([IdNat]) > 0)),
 CONSTRAINT CK_MercanciasIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_MercanciasIdTmcia CHECK ((len([IdTmcia]) > 0)),
 CONSTRAINT CK_MercanciasIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_MercanciasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_MercanciasUndMed CHECK ((len([UndMed]) > 0)))
CREATE TABLE MttoConceptos ( 
IdConc VARCHAR(4) NOT NULL,
Concepto VARCHAR(150) NOT NULL,
IdSistema VARCHAR(4) NOT NULL,
IdMtto VARCHAR(4) NOT NULL,
TipoControl INT DEFAULT ((0)) NOT NULL,
Intervalo_km INT DEFAULT ((0)) NOT NULL,
Intervalo_dias INT DEFAULT ((0)) NOT NULL,
Intervalo_Horas INT DEFAULT ((0)) NOT NULL,
Req_Parte BIT DEFAULT ((0)) NOT NULL,
CodigoMO VARCHAR(16),
CantHoras DECIMAL(14,2) DEFAULT ((0)) NOT NULL,
TarifaCosto DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TarifaClie DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
IntvAlarma VARCHAR(50)
 CONSTRAINT PK_MttoConceptos PRIMARY KEY CLUSTERED (IdConc),
 CONSTRAINT CK_MttoConceptosConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_MttoConceptosIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_MttoConceptosIdMtto CHECK ((len([IdMtto])>(0))),
 CONSTRAINT CK_MttoConceptosIdSistema CHECK ((len([IdSistema])>(0))),
 CONSTRAINT CK_MttoConceptosIdUsuario CHECK ((len([IdUsuario])>(0))))
CREATE TABLE MttoConcProductos ( 
IdConc VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((1)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoConcProductos PRIMARY KEY CLUSTERED (IdConc,IdProducto),
 CONSTRAINT CK_MttoConcProductosIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_MttoConcProductosIdProducto CHECK ((len([IdProducto])>(0))))
CREATE TABLE MttoControles ( 
TipoUnidad CHAR(1) DEFAULT ('V') NOT NULL,
NumUnidad VARCHAR(10) NOT NULL,
IdConc VARCHAR(4) NOT NULL,
TipoControl INT DEFAULT ((0)) NOT NULL,
Intervalo_km INT DEFAULT ((0)) NOT NULL,
Intervalo_dias INT DEFAULT ((0)) NOT NULL,
Intervalo_Horas INT DEFAULT ((0)) NOT NULL,
kmUltMtto INT DEFAULT ((0)) NOT NULL,
kmUltMttoRuta INT DEFAULT ((0)) NOT NULL,
kmUltMttoSat INT DEFAULT ((0)) NOT NULL,
FecUltMtto SMALLDATETIME,
HsUltMtto INT DEFAULT ((0)) NOT NULL,
Comentarios VARCHAR(1000),
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_MttoControles PRIMARY KEY CLUSTERED (TipoUnidad,NumUnidad,IdConc),
 CONSTRAINT CK_MttoControlesIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_MttoControlesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_MttoControlesNumUnidad CHECK ((len([NumUnidad])>(0))),
 CONSTRAINT CK_MttoControlesTipoUnidad CHECK ((len([TipoUnidad])>(0))))
CREATE TABLE MttoEstados ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoEstados PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_MttoEstadosEstado CHECK ((len([Estado])>(0))),
 CONSTRAINT CK_MttoEstadosIdEstado CHECK ((len([IdEstado])>(0))))
CREATE TABLE MttoInspecciones ( 
IdInspec VARCHAR(4) NOT NULL,
Inspeccion VARCHAR(150) NOT NULL,
IdSistema VARCHAR(4) NOT NULL,
IdMtto VARCHAR(4) NOT NULL,
TipoDato INT DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(50),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoInspecciones PRIMARY KEY CLUSTERED (IdInspec),
 CONSTRAINT CK_MttoInspeccionesIdInspec CHECK ((len([IdInspec])>(0))),
 CONSTRAINT CK_MttoInspeccionesIdMtto CHECK ((len([IdMtto])>(0))),
 CONSTRAINT CK_MttoInspeccionesIdSistema CHECK ((len([IdSistema])>(0))),
 CONSTRAINT CK_MttoInspeccionesInspeccion CHECK ((len([Inspeccion])>(0))))
CREATE TABLE MttoInspecRangos ( 
IdInspec VARCHAR(4) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Estado VARCHAR(100) NOT NULL,
ValorInicial DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorFinal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
NColor INT DEFAULT ((0)) NOT NULL,
ReqMtto BIT DEFAULT ((0)) NOT NULL,
CdConc VARCHAR(4)
 CONSTRAINT PK_MttoInspecRangos PRIMARY KEY CLUSTERED (IdInspec,Item),
 CONSTRAINT CK_MttoInspecRangosEstado CHECK ((len([Estado])>(0))),
 CONSTRAINT CK_MttoInspecRangosIdInspec CHECK ((len([IdInspec])>(0))))
CREATE TABLE MttoOpciones ( 
TipoInspec VARCHAR(3) NOT NULL,
Unidad VARCHAR(10) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ValorInicial DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorFinal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumColor INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoOpciones PRIMARY KEY CLUSTERED (TipoInspec,Unidad,Item),
 CONSTRAINT CK_MttoOpcionesTipoInspec CHECK ((len([TipoInspec])>(0))),
 CONSTRAINT CK_MttoOpcionesUnidad CHECK ((len([Unidad])>(0))))
CREATE TABLE MttoSistemas ( 
IdSistema VARCHAR(4) NOT NULL,
Sistema VARCHAR(50) NOT NULL,
Seccion CHAR(1) DEFAULT ('N') NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoSistemas PRIMARY KEY CLUSTERED (IdSistema),
 CONSTRAINT CK_MttoSistemasIdSistema CHECK ((len([IdSistema])>(0))),
 CONSTRAINT CK_MttoSistemasSistema CHECK ((len([Sistema])>(0))))
CREATE TABLE MttoTipos ( 
IdMtto VARCHAR(4) NOT NULL,
TipoMtto VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoTipos PRIMARY KEY CLUSTERED (IdMtto),
 CONSTRAINT CK_MttoTiposIdMtto CHECK ((len([IdMtto])>(0))),
 CONSTRAINT CK_MttoTiposTipoMtto CHECK ((len([TipoMtto])>(0))))
CREATE TABLE MttoTiposOdt ( 
IdTipoOdt VARCHAR(4) NOT NULL,
TipoOrden VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MttoTiposOdt PRIMARY KEY CLUSTERED (IdTipoOdt),
 CONSTRAINT CK_MttoTiposOdtIdTipoOdt CHECK ((len([IdTipoOdt])>(0))),
 CONSTRAINT CK_MttoTiposOdtTipoOrden CHECK ((len([TipoOrden])>(0))))
CREATE TABLE MudArticulos ( 
IdArticulo VARCHAR(16) NOT NULL,
Articulo VARCHAR(250) NOT NULL,
IdSeccion VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MudArticulos PRIMARY KEY CLUSTERED (IdArticulo),
 CONSTRAINT CK_MudArticulosArticulo CHECK ((len([Articulo])>(0))),
 CONSTRAINT CK_MudArticulosIdArticulo CHECK ((len([IdArticulo])>(0))),
 CONSTRAINT CK_MudArticulosIdSeccion CHECK ((len([IdSeccion])>(0))))
CREATE TABLE MudEstados ( 
IdEstado VARCHAR(4) NOT NULL,
Estado VARCHAR(50) NOT NULL,
NColor INT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MudEstados PRIMARY KEY CLUSTERED (IdEstado),
 CONSTRAINT CK_MudEstadosEstado CHECK ((len([Estado])>(0))),
 CONSTRAINT CK_MudEstadosIdEstado CHECK ((len([IdEstado])>(0))))
CREATE TABLE MudSecciones ( 
IdSeccion VARCHAR(4) NOT NULL,
Seccion VARCHAR(150) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MudSecciones PRIMARY KEY CLUSTERED (IdSeccion),
 CONSTRAINT CK_MudSeccionesIdSeccion CHECK ((len([IdSeccion])>(0))),
 CONSTRAINT CK_MudSeccionesSeccion CHECK ((len([Seccion])>(0))))
CREATE TABLE MudServicios ( 
IdTipoServ VARCHAR(4) NOT NULL,
TipoServicio VARCHAR(150) NOT NULL,
Transporte BIT DEFAULT ((0)) NOT NULL,
Bodega BIT DEFAULT ((0)) NOT NULL,
Empaque BIT DEFAULT ((0)) NOT NULL,
Personal BIT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_MudServicios PRIMARY KEY CLUSTERED (IdTipoServ),
 CONSTRAINT CK_MudServiciosIdTipoServ CHECK ((len([IdTipoServ])>(0))),
 CONSTRAINT CK_MudServiciosTipoServicio CHECK ((len([TipoServicio])>(0))))
CREATE TABLE NiifClases ( 
Id INT DEFAULT ((0)) NOT NULL,
ClasePol VARCHAR(100) NOT NULL
 CONSTRAINT PK_NiifClases PRIMARY KEY CLUSTERED (Id),
 CONSTRAINT CK_NiifClasesClasePol CHECK ((len([ClasePol])>(0))))
CREATE TABLE NiifPeriodos ( 
Anno INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Niif INT DEFAULT ((0)) NOT NULL,
Ene BIT DEFAULT ((0)) NOT NULL,
Feb BIT DEFAULT ((0)) NOT NULL,
Mar BIT DEFAULT ((0)) NOT NULL,
Abr BIT DEFAULT ((0)) NOT NULL,
May BIT DEFAULT ((0)) NOT NULL,
Jun BIT DEFAULT ((0)) NOT NULL,
Jul BIT DEFAULT ((0)) NOT NULL,
Ago BIT DEFAULT ((0)) NOT NULL,
Sep BIT DEFAULT ((0)) NOT NULL,
Oct BIT DEFAULT ((0)) NOT NULL,
Nov BIT DEFAULT ((0)) NOT NULL,
Dic BIT DEFAULT ((0)) NOT NULL,
CierreAnno BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NiifPeriodos PRIMARY KEY CLUSTERED (Anno,IdCia,Niif),
 CONSTRAINT CK_NiifPeriodosIdCia CHECK ((len([IdCia])>(0))))
CREATE TABLE NiifTasas ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
TipoCar VARCHAR(3) DEFAULT ('CXC') NOT NULL,
DiasInicio DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DiasFinal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdTarifa VARCHAR(4) NOT NULL
 CONSTRAINT PK_NiifTasas PRIMARY KEY CLUSTERED (Id),
 CONSTRAINT CK_NiifTasasIdTarifa CHECK ((len([IdTarifa])>(0))),
 CONSTRAINT CK_NiifTasasTipoCar CHECK ((len([TipoCar])>(0))))
CREATE TABLE NomAportante ( 
IdAportnte VARCHAR(16) NOT NULL,
RazonSocial VARCHAR(200) NOT NULL,
TipoId CHAR(1) DEFAULT ('N') NOT NULL,
DvNit CHAR(1) DEFAULT ('0') NOT NULL,
IdRepLegal VARCHAR(16) NOT NULL,
Direccion VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
Telefono VARCHAR(20) NOT NULL,
Fax VARCHAR(20),
e_mail VARCHAR(100),
ClaseApo CHAR(1) NOT NULL,
TipoEco CHAR(1) DEFAULT ('P') NOT NULL,
TipoPersna CHAR(1) DEFAULT ('J') NOT NULL,
CIIUDane VARCHAR(8),
FecIniCndato SMALLDATETIME,
TipAccCndato INT DEFAULT (0) NOT NULL,
FecFinCndato SMALLDATETIME,
CodOperInfo VARCHAR(10) NOT NULL,
TipoApo CHAR(1) DEFAULT ('1'),
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
FecMatMerc SMALLDATETIME,
ExonParaf INT DEFAULT ((0)),
ExonCajas INT DEFAULT ((0)),
CondEspecial VARCHAR(250)
 CONSTRAINT PK_NomAportante PRIMARY KEY CLUSTERED (IdAportnte),
 CONSTRAINT CK_NomAportanteClaseApo CHECK ((len([ClaseApo])>(0))),
 CONSTRAINT CK_NomAportanteCodOperInfo CHECK ((len([CodOperInfo]) > 0)),
 CONSTRAINT CK_NomAportanteDireccion CHECK ((len([Direccion]) > 0)),
 CONSTRAINT CK_NomAportanteDvNit CHECK ((len([DvNit]) > 0)),
 CONSTRAINT CK_NomAportanteIdAportnte CHECK ((len([IdAportnte]) > 0)),
 CONSTRAINT CK_NomAportanteIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_NomAportanteIdRepLegal CHECK ((len([IdRepLegal]) > 0)),
 CONSTRAINT CK_NomAportanteIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_NomAportanteRazonSocial CHECK ((len([RazonSocial]) > 0)),
 CONSTRAINT CK_NomAportanteTelefono CHECK ((len([Telefono]) > 0)),
 CONSTRAINT CK_NomAportanteTipAccCndato CHECK (([TipAccCndato] >= 0 and [TipAccCndato] <= 4)),
 CONSTRAINT CK_NomAportanteTipoEco CHECK ((len([TipoEco])>(0))),
 CONSTRAINT CK_NomAportanteTipoId CHECK (([TipoId]='D' OR [TipoId]='N' OR [TipoId]='C' OR [TipoId]='E' OR [TipoId]='O' OR [TipoId]='U' OR [TipoId]='T' OR [TipoId]='R' OR [TipoId]='P')),
 CONSTRAINT CK_NomAportanteTipoPersna CHECK (([TipoPersna] = 'N' or [TipoPersna] = 'J')))
CREATE TABLE NomCapacitaciones ( 
IdClase VARCHAR(4) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Vigencia INT DEFAULT ((0)) NOT NULL,
CdEmpleado VARCHAR(16) DEFAULT ('0') NOT NULL,
CdProf VARCHAR(4) DEFAULT ('0') NOT NULL,
CdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
CdArea VARCHAR(4) DEFAULT ('0') NOT NULL,
CdDep VARCHAR(4) DEFAULT ('0') NOT NULL,
Cumplimto VARCHAR(20) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NomCapacitaciones PRIMARY KEY CLUSTERED (IdClase,Item),
 CONSTRAINT CK_NomCapacitacionesCdArea CHECK ((len([CdArea])>(0))),
 CONSTRAINT CK_NomCapacitacionesCdCargo CHECK ((len([CdCargo])>(0))),
 CONSTRAINT CK_NomCapacitacionesCdDep CHECK ((len([CdDep])>(0))),
 CONSTRAINT CK_NomCapacitacionesCdEmpleado CHECK ((len([CdEmpleado])>(0))),
 CONSTRAINT CK_NomCapacitacionesCdProf CHECK ((len([CdProf])>(0))),
 CONSTRAINT CK_NomCapacitacionesCumplimto CHECK ((len([Cumplimto])>(0))),
 CONSTRAINT CK_NomCapacitacionesIdClase CHECK ((len([IdClase])>(0))))
CREATE TABLE NomCausalesRet ( 
IdCausa VARCHAR(4) NOT NULL,
CausalRet VARCHAR(100) NOT NULL,
Indmnizar BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_NomCausalesRet PRIMARY KEY CLUSTERED (IdCausa),
 CONSTRAINT CK_NomCausalesRetCausalRet CHECK ((len([CausalRet]) > 0)),
 CONSTRAINT CK_NomCausalesRetIdCausa CHECK ((len([IdCausa]) > 0)))
CREATE TABLE NomConcDian ( 
IdConcNE VARCHAR(50) NOT NULL,
ConceptoNE VARCHAR(500) NOT NULL,
TipoConc VARCHAR(10) NOT NULL
 CONSTRAINT PK_NomConcDian PRIMARY KEY CLUSTERED (IdConcNE),
 CONSTRAINT CK_NomConcDianConceptoNE CHECK ((len([ConceptoNE])>(0))),
 CONSTRAINT CK_NomConcDianTipoConc CHECK ((len([TipoConc])>(0))))
CREATE TABLE NomConceptos ( 
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(100) NOT NULL,
ClaseCon VARCHAR(10) DEFAULT ('DEVENGADO') NOT NULL,
Unidad VARCHAR(10) DEFAULT ('UNIDADES') NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
BaseTrfa CHAR(2) DEFAULT ('0') NOT NULL,
Pdtermnado BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
TarifaEmp DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DiasEmp INT DEFAULT ((0)) NOT NULL,
IdConcNE VARCHAR(50)
 CONSTRAINT PK_NomConceptos PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_NomConceptosBaseTrfa CHECK (([BaseTrfa] = '0' or ([BaseTrfa] = 'SD' or ([BaseTrfa] = 'TD' or ([BaseTrfa] = 'SB' or [BaseTrfa] = 'SM'))))),
 CONSTRAINT CK_NomConceptosClaseCon CHECK (([ClaseCon] = 'PROVISION' or ([ClaseCon] = 'APORTE' or ([ClaseCon] = 'DEDUCIDO' or [ClaseCon] = 'DEVENGADO')))),
 CONSTRAINT CK_NomConceptosConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_NomConceptosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_NomConceptosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_NomConceptosUnidad CHECK (([Unidad] = '$' or ([Unidad] = 'MESES' or ([Unidad] = 'HORAS' or ([Unidad] = '%' or ([Unidad] = 'DIAS' or [Unidad] = 'UNIDADES')))))))
CREATE TABLE NomConCuentas ( 
IdConcepto VARCHAR(4) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
NClase INT DEFAULT (0) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
TipoMov CHAR(1) DEFAULT ('D') NOT NULL,
CodNom VARCHAR(4),
CodDep VARCHAR(4),
CodFon VARCHAR(8),
NitTerc CHAR(1) DEFAULT ('E')
 CONSTRAINT PK_NomConCuentas PRIMARY KEY CLUSTERED (IdConcepto,Item),
 CONSTRAINT CK_NomConCuentasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_NomConCuentasIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_NomConCuentasTipoMov CHECK (([TipoMov] = 'C' or [TipoMov] = 'D')))
CREATE TABLE NomConOpciones ( 
IdConcepto VARCHAR(4) NOT NULL,
IdOpc INT DEFAULT (0) NOT NULL,
NomOpcion VARCHAR(50) NOT NULL,
Asignado BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_NomConOpciones PRIMARY KEY CLUSTERED (IdConcepto,IdOpc),
 CONSTRAINT CK_NomConOpcionesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_NomConOpcionesNomOpcion CHECK ((len([NomOpcion]) > 0)))
CREATE TABLE NomDefault ( 
nAnno INT DEFAULT (0) NOT NULL,
IdOpc VARCHAR(3) NOT NULL,
Descripcion VARCHAR(100) NOT NULL,
Valor MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_NomDefault PRIMARY KEY CLUSTERED (nAnno,IdOpc),
 CONSTRAINT CK_NomDefaultDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_NomDefaultIdOpc CHECK ((len([IdOpc]) > 0)),
 CONSTRAINT CK_NomDefaultnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)))
CREATE TABLE NomMediosPago ( 
IdMedPago VARCHAR(4) NOT NULL,
MedioPago VARCHAR(250) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NomMediosPago PRIMARY KEY CLUSTERED (IdMedPago),
 CONSTRAINT CK_NomMediosPagoMedioPago CHECK ((len([MedioPago])>(0))))
CREATE TABLE NomPrendas ( 
IdPrend VARCHAR(4) NOT NULL,
DescPrenda VARCHAR(100) NOT NULL,
TipoPrenda VARCHAR(10) DEFAULT ('DOTACION') NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
VrCostoUnd MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NomPrendas PRIMARY KEY CLUSTERED (IdPrend),
 CONSTRAINT CK_NomPrendasDescPrenda CHECK ((len([DescPrenda])>(0))),
 CONSTRAINT CK_NomPrendasIdPrend CHECK ((len([IdPrend])>(0))),
 CONSTRAINT CK_NomPrendasTipoPrenda CHECK ((len([TipoPrenda])>(0))))
CREATE TABLE NomRangosFsu ( 
IdRango INT DEFAULT (0) NOT NULL,
VrInicial DECIMAL(12,2) DEFAULT (0) NOT NULL,
VrFinal DECIMAL(12,2) DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_NomRangosFsu PRIMARY KEY CLUSTERED (IdRango))
CREATE TABLE NomTablaRet ( 
nAnno INT DEFAULT (0) NOT NULL,
nIntrvalo INT DEFAULT (0) NOT NULL,
VrInicial MONEY DEFAULT (0) NOT NULL,
VrFinal MONEY DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrRetncion MONEY DEFAULT (0) NOT NULL,
TarExcdnte DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrBaseExc MONEY DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_NomTablaRet PRIMARY KEY CLUSTERED (nAnno,nIntrvalo),
 CONSTRAINT CK_NomTablaRetIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE NomTablaRetMin ( 
nAnno INT DEFAULT ((0)) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Pm_Desde DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Tarifa DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NomTablaRetMin PRIMARY KEY CLUSTERED (nAnno,Item))
CREATE TABLE NomTiposComp ( 
IdConc VARCHAR(4) NOT NULL,
CdNom VARCHAR(4) NOT NULL,
Concepto VARCHAR(50) NOT NULL,
TipoContab VARCHAR(10) NOT NULL,
CdCom VARCHAR(3),
CdComNiif VARCHAR(3),
CdComFiscal VARCHAR(3)
 CONSTRAINT PK_NomTiposComp PRIMARY KEY CLUSTERED (IdConc,CdNom),
 CONSTRAINT CK_NomTiposCompCdNom CHECK ((len([CdNom])>(0))),
 CONSTRAINT CK_NomTiposCompConcepto CHECK ((len([Concepto])>(0))),
 CONSTRAINT CK_NomTiposCompIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_NomTiposCompTipoContab CHECK ((len([TipoContab])>(0))))
CREATE TABLE NomTiposDot ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
Descripcion VARCHAR(50) NOT NULL
 CONSTRAINT PK_NomTiposDot PRIMARY KEY CLUSTERED (Id),
 CONSTRAINT CK_NomTiposDotDescripcion CHECK ((len([Descripcion])>(0))))
CREATE TABLE NomVehiculos ( 
IdVehiculo VARCHAR(10) NOT NULL,
NumVeh VARCHAR(10) NOT NULL,
ClaseVeh VARCHAR(50),
TipoAdmon VARCHAR(50),
GrupoProp VARCHAR(50),
VehPropio BIT DEFAULT (0) NOT NULL,
CedCond VARCHAR(16),
Conductor VARCHAR(50)
 CONSTRAINT PK_NomVehiculos PRIMARY KEY CLUSTERED (IdVehiculo),
 CONSTRAINT CK_NomVehiculosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_NomVehiculosNumVeh CHECK ((len([NumVeh]) > 0)))
CREATE TABLE NovedadRep ( 
IdNov VARCHAR(4) NOT NULL,
Novedad VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_NovedadRep PRIMARY KEY CLUSTERED (IdNov),
 CONSTRAINT CK_NovedadRepIdNov CHECK ((len([IdNov]) > 0)),
 CONSTRAINT CK_NovedadRepNovedad CHECK ((len([Novedad]) > 0)))
CREATE TABLE NovedadTra ( 
IdNovedad VARCHAR(4) NOT NULL,
Novedad VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_NovedadTra PRIMARY KEY CLUSTERED (IdNovedad),
 CONSTRAINT CK_NovedadTraIdNovedad CHECK ((len([IdNovedad])>(0))),
 CONSTRAINT CK_NovedadTraNovedad CHECK ((len([Novedad])>(0))))
CREATE TABLE Ocupaciones ( 
IdOcupac VARCHAR(4) NOT NULL,
Ocupacion VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Ocupaciones PRIMARY KEY CLUSTERED (IdOcupac),
 CONSTRAINT CK_OcupacionesOcupacion CHECK ((len([Ocupacion])>(0))))
CREATE TABLE OrgTransito ( 
IdOrgTra VARCHAR(8) NOT NULL,
NomOrgTrans VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_OrgTransito PRIMARY KEY CLUSTERED (IdOrgTra),
 CONSTRAINT CK_OrgTransitoIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_OrgTransitoIdOrgTra CHECK ((len([IdOrgTra])>(0))),
 CONSTRAINT CK_OrgTransitoNomOrgTrans CHECK ((len([NomOrgTrans])>(0))))
CREATE TABLE PeajesCat ( 
IdCat VARCHAR(4) NOT NULL,
Catpeaje VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_PeajesCat PRIMARY KEY CLUSTERED (IdCat),
 CONSTRAINT CK_PeajesCatCatpeaje CHECK ((len([Catpeaje]) > 0)),
 CONSTRAINT CK_PeajesCatIdCat CHECK ((len([IdCat]) > 0)))
CREATE TABLE PeajesClase ( 
IdClase VARCHAR(4) NOT NULL,
ClasePeaje VARCHAR(50) NOT NULL,
NitConsec VARCHAR(16),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_PeajesClase PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_PeajesClaseClasePeaje CHECK ((len([ClasePeaje])>(0))),
 CONSTRAINT CK_PeajesClaseIdClase CHECK ((len([IdClase])>(0))))
CREATE TABLE PeajesTarf ( 
IdCat VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
VrTarifa MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_PeajesTarf PRIMARY KEY CLUSTERED (IdCat,IdClase),
 CONSTRAINT CK_PeajesTarfIdCat CHECK ((len([IdCat]) > 0)),
 CONSTRAINT CK_PeajesTarfIdClase CHECK ((len([IdClase]) > 0)))
CREATE TABLE PicoPlaca ( 
Fecha SMALLDATETIME NOT NULL,
UltimoDig VARCHAR(50) NOT NULL
 CONSTRAINT PK_PicoPlaca PRIMARY KEY CLUSTERED (Fecha),
 CONSTRAINT CK_PicoPlacaUltimoDig CHECK ((len([UltimoDig]) > 0)))
CREATE TABLE Plantillas ( 
IdPlantilla VARCHAR(4) NOT NULL,
DescPlantilla VARCHAR(150) NOT NULL,
CdTipCom VARCHAR(3),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Plantillas PRIMARY KEY CLUSTERED (IdPlantilla),
 CONSTRAINT CK_PlantillasDescPlantilla CHECK ((len([DescPlantilla]) > 0)),
 CONSTRAINT CK_PlantillasIdPlantilla CHECK ((len([IdPlantilla]) > 0)))
CREATE TABLE PlantillasCcto ( 
IdPlantilla VARCHAR(4) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
DescCosto VARCHAR(50),
TarifaCc DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_PlantillasCcto PRIMARY KEY CLUSTERED (IdPlantilla,Item,IdCCosto),
 CONSTRAINT CK_PlantillasCctoIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_PlantillasCctoIdPlantilla CHECK ((len([IdPlantilla]) > 0)))
CREATE TABLE PlantillasConc ( 
IdPlantilla VARCHAR(4) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Concepto VARCHAR(150) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
TipoMov CHAR(1) DEFAULT ('D') NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
Requerido BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_PlantillasConc PRIMARY KEY CLUSTERED (IdPlantilla,Item),
 CONSTRAINT CK_PlantillasConcConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_PlantillasConcIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_PlantillasConcIdPlantilla CHECK ((len([IdPlantilla]) > 0)),
 CONSTRAINT CK_PlantillasConcTipoMov CHECK (([TipoMov] = 'C' or [TipoMov] = 'D')))
CREATE TABLE Plazos ( 
IdPlazo VARCHAR(4) NOT NULL,
Plazo VARCHAR(50) NOT NULL,
NVmto INT DEFAULT (1) NOT NULL,
DiasPago VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
CdDctoPp VARCHAR(4)
 CONSTRAINT PK_Plazos PRIMARY KEY CLUSTERED (IdPlazo),
 CONSTRAINT CK_PlazosDiasPago CHECK ((len([DiasPago]) > 0)),
 CONSTRAINT CK_PlazosIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_PlazosPlazo CHECK ((len([Plazo]) > 0)))
CREATE TABLE Polizas ( 
NumPoliza VARCHAR(30) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Vigencia SMALLDATETIME NOT NULL,
NitCompania VARCHAR(16) NOT NULL,
Compania VARCHAR(150) NOT NULL,
NitTomador VARCHAR(16) NOT NULL,
Tomador VARCHAR(150) NOT NULL,
NitAseg VARCHAR(16) NOT NULL,
Asegurado VARCHAR(150) NOT NULL,
NitBenef VARCHAR(16) NOT NULL,
Beneficiario VARCHAR(150) NOT NULL,
DescFirma VARCHAR(2000),
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CodEmpresa VARCHAR(20)
 CONSTRAINT PK_Polizas PRIMARY KEY CLUSTERED (NumPoliza),
 CONSTRAINT CK_PolizasAsegurado CHECK ((len([Asegurado]) > 0)),
 CONSTRAINT CK_PolizasBeneficiario CHECK ((len([Beneficiario]) > 0)),
 CONSTRAINT CK_PolizasCompania CHECK ((len([Compania]) > 0)),
 CONSTRAINT CK_PolizasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_PolizasNitAseg CHECK ((len([NitAseg]) > 0)),
 CONSTRAINT CK_PolizasNitBenef CHECK ((len([NitBenef]) > 0)),
 CONSTRAINT CK_PolizasNitCompania CHECK ((len([NitCompania]) > 0)),
 CONSTRAINT CK_PolizasNitTomador CHECK ((len([NitTomador]) > 0)),
 CONSTRAINT CK_PolizasNumPoliza CHECK ((len([NumPoliza]) > 0)),
 CONSTRAINT CK_PolizasTomador CHECK ((len([Tomador]) > 0)))
CREATE TABLE ProdAditivos ( 
IdProducto VARCHAR(16) NOT NULL,
IdAditivo VARCHAR(16) NOT NULL,
Cant DECIMAL(14,4) DEFAULT (0) NOT NULL,
Unidad VARCHAR(10) DEFAULT ('UNIDAD') NOT NULL,
CdBodega VARCHAR(4),
CdTanq VARCHAR(4)
 CONSTRAINT PK_ProdAditivos PRIMARY KEY CLUSTERED (IdProducto,IdAditivo),
 CONSTRAINT CK_ProdAditivosIdAditivo CHECK ((len([IdAditivo]) > 0)),
 CONSTRAINT CK_ProdAditivosIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdAditivosUnidad CHECK (([Unidad] = '%' or [Unidad] = 'UNIDAD')))
CREATE TABLE ProdCodigos ( 
Codigo VARCHAR(20) NOT NULL,
IdProducto VARCHAR(16) NOT NULL
 CONSTRAINT PK_ProdCodigos PRIMARY KEY CLUSTERED (Codigo),
 CONSTRAINT CK_ProdCodigosIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE ProdCombo ( 
IdProducto VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdProdBas VARCHAR(16) NOT NULL,
Cant DECIMAL(14,4) DEFAULT (0) NOT NULL,
FacMezcla VARCHAR(10) DEFAULT ('UNIDAD') NOT NULL,
CdBodega VARCHAR(4),
CdTanq VARCHAR(4),
ExentoSob BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ProdCombo PRIMARY KEY CLUSTERED (IdProducto,Item),
 CONSTRAINT CK_ProdComboFacMezcla CHECK (([FacMezcla] = '%' or [FacMezcla] = 'UNIDAD')),
 CONSTRAINT CK_ProdComboIdProdBas CHECK ((len([IdProdBas]) > 0)),
 CONSTRAINT CK_ProdComboIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE ProdCompanias ( 
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) NOT NULL
 CONSTRAINT PK_ProdCompanias PRIMARY KEY CLUSTERED (IdProducto,IdCia),
 CONSTRAINT CK_ProdCompaniasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdCompaniasIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE ProdCostos ( 
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
CostoAnt MONEY DEFAULT (0) NOT NULL,
CostoUlt MONEY DEFAULT (0) NOT NULL,
CostoPmd MONEY DEFAULT (0) NOT NULL,
FecUltPmd SMALLDATETIME
 CONSTRAINT PK_ProdCostos PRIMARY KEY CLUSTERED (IdProducto,IdCia),
 CONSTRAINT CK_ProdCostosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdCostosIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE ProdCueCrudo ( 
IdProducto VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdEstacion VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
CdCueDev VARCHAR(16)
 CONSTRAINT PK_ProdCueCrudo PRIMARY KEY CLUSTERED (IdProducto,Item),
 CONSTRAINT CK_ProdCueCrudoIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_ProdCueCrudoIdEstacion CHECK ((len([IdEstacion])>(0))),
 CONSTRAINT CK_ProdCueCrudoIdProducto CHECK ((len([IdProducto])>(0))))
CREATE TABLE ProdEquiv ( 
IdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Unidad VARCHAR(10) DEFAULT ('UNIDAD') NOT NULL,
Largo DECIMAL(14,4) DEFAULT (0) NOT NULL,
Ancho DECIMAL(14,4) DEFAULT (0) NOT NULL,
Alto DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
Equivale DECIMAL(14,4) DEFAULT (0) NOT NULL,
UnidEquiv VARCHAR(10) NOT NULL
 CONSTRAINT PK_ProdEquiv PRIMARY KEY CLUSTERED (IdProducto,Unidad),
 CONSTRAINT CK_ProdEquivIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdEquivUnidad CHECK ((len([Unidad]) > 0)),
 CONSTRAINT CK_ProdEquivUnidEquiv CHECK ((len([UnidEquiv]) > 0)))
CREATE TABLE ProdEstandares ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
Codigo VARCHAR(20) NOT NULL,
Descripcion VARCHAR(500) NOT NULL
 CONSTRAINT PK_ProdEstandares PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_ProdEstandaresCodigo CHECK ((len([Codigo])>(0))),
 CONSTRAINT CK_ProdEstandaresDescripcion CHECK ((len([Descripcion])>(0))))
CREATE TABLE ProdImagenes ( 
IdProducto VARCHAR(16) NOT NULL,
IdImagen INT DEFAULT ((0)) NOT NULL,
ImagenBin IMAGE,
NomArchivo VARCHAR(50)
 CONSTRAINT PK_ProdImagenes PRIMARY KEY CLUSTERED (IdProducto,IdImagen),
 CONSTRAINT CK_ProdImagenesIdProducto CHECK ((len([IdProducto])>(0))))
CREATE TABLE ProdImpFron ( 
IdProducto VARCHAR(16) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
CdDpto VARCHAR(8) DEFAULT ('0') NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
SimbTfa CHAR(1) DEFAULT ('%') NOT NULL,
CdTarifa VARCHAR(4),
TarifZfe DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
RngFecha BIT DEFAULT ((0)) NOT NULL,
FecInicial SMALLDATETIME,
FecFinal SMALLDATETIME,
LtaPre CHAR(1),
Inactivo BIT DEFAULT ((0)) NOT NULL,
FecUpdate SMALLDATETIME NOT NULL
 CONSTRAINT PK_ProdImpFron PRIMARY KEY CLUSTERED (IdProducto,IdClase,Item),
 CONSTRAINT CK_ProdImpFronIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_ProdImpFronIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_ProdImpFronIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_ProdImpFronSimbTfa CHECK ((len([SimbTfa])>(0))))
CREATE TABLE ProdImptos ( 
IdProducto VARCHAR(16) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
SimbTfa CHAR(1) DEFAULT ('%') NOT NULL,
CdTarifa VARCHAR(4),
TarifZfe DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
RngFecha BIT DEFAULT ((0)) NOT NULL,
FecInicial SMALLDATETIME,
FecFinal SMALLDATETIME,
LtaPre CHAR(1),
Inactivo BIT DEFAULT ((0)) NOT NULL,
FecUpdate SMALLDATETIME NOT NULL
 CONSTRAINT PK_ProdImptos PRIMARY KEY CLUSTERED (IdProducto,IdClase,Item),
 CONSTRAINT CK_ProdImptosIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_ProdImptosIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_ProdImptosSimbTfa CHECK (([SimbTfa]='$' OR [SimbTfa]='%')))
CREATE TABLE ProdInsumos ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdInsumo VARCHAR(16) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ProdInsumos PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_ProdInsumosIdInsumo CHECK ((len([IdInsumo])>(0))),
 CONSTRAINT CK_ProdInsumosIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_ProdInsumosIdTipProc CHECK ((len([IdTipProc])>(0))))
CREATE TABLE ProdMcias ( 
IdProducto VARCHAR(16) NOT NULL,
DescripProd VARCHAR(150) NOT NULL,
DescripAbrv VARCHAR(50),
CodBarras VARCHAR(20) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(20) DEFAULT ('0') NOT NULL,
TipoRef VARCHAR(10) DEFAULT ('PRODUCTO') NOT NULL,
IdSubgrupo VARCHAR(8) NOT NULL,
IdMarca VARCHAR(4) DEFAULT ('0') NOT NULL,
Color VARCHAR(30),
Tamano VARCHAR(30),
MedAlto DECIMAL(14,4) DEFAULT (0) NOT NULL,
MedAncho DECIMAL(14,4) DEFAULT (0) NOT NULL,
MedLargo DECIMAL(14,4) DEFAULT (0) NOT NULL,
MedVolm DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdUndP VARCHAR(4) NOT NULL,
CdUndS VARCHAR(4),
CdUndE VARCHAR(4),
CdUndEb VARCHAR(4),
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
IdMnjo VARCHAR(4) NOT NULL,
IdTmcia VARCHAR(4) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10) DEFAULT ('0') NOT NULL,
DesUbic VARCHAR(50),
IdProv VARCHAR(16) NOT NULL,
GarProv INT DEFAULT (0) NOT NULL,
GarClie INT DEFAULT (0) NOT NULL,
CdDctCom VARCHAR(4),
VrCostAnt MONEY DEFAULT (0) NOT NULL,
VrCosto MONEY DEFAULT (0) NOT NULL,
VrCostPmd MONEY DEFAULT (0) NOT NULL,
IdTarIva VARCHAR(4) NOT NULL,
IvaInc VARCHAR(10),
LtPreDef CHAR(1),
Precio1 MONEY DEFAULT (0) NOT NULL,
Precio2 MONEY DEFAULT (0) NOT NULL,
Precio3 MONEY DEFAULT (0) NOT NULL,
Precio4 MONEY DEFAULT (0) NOT NULL,
Precio5 MONEY DEFAULT (0) NOT NULL,
CdMon1 VARCHAR(5),
CdMon2 VARCHAR(5),
CdMon3 VARCHAR(5),
CdMon4 VARCHAR(5),
CdMon5 VARCHAR(5),
BaseMgn VARCHAR(10),
CdMgn1 VARCHAR(4),
CdMgn2 VARCHAR(4),
CdMgn3 VARCHAR(4),
CdMgn4 VARCHAR(4),
CdMgn5 VARCHAR(4),
CdDct1 VARCHAR(4),
CdDct2 VARCHAR(4),
CdDct3 VARCHAR(4),
CdDct4 VARCHAR(4),
CdDct5 VARCHAR(4),
CdTarIca VARCHAR(4),
CdTarRet VARCHAR(4),
ExtciaMin DECIMAL(14,4) DEFAULT (0) NOT NULL,
ExtciaMax DECIMAL(14,4) DEFAULT (0) NOT NULL,
ExtciaAct DECIMAL(14,4) DEFAULT (0) NOT NULL,
Factor1 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Factor2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Factor3 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Factor4 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Factor5 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Seriales BIT DEFAULT (0) NOT NULL,
Lotes BIT DEFAULT (0) NOT NULL,
Combo BIT DEFAULT (0) NOT NULL,
NoAjustes BIT DEFAULT (0) NOT NULL,
Tanques BIT DEFAULT (0) NOT NULL,
ValesComb BIT DEFAULT (0) NOT NULL,
FecUltcom SMALLDATETIME,
FecUltVta SMALLDATETIME,
CodMcia VARCHAR(10),
DescripLong VARCHAR(250),
Cmntarios VARCHAR(250),
PathFoto VARCHAR(30),
CantTpv DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
TipoZonaFront VARCHAR(3) DEFAULT ('N'),
ExcluidoImp BIT DEFAULT ((0)) NOT NULL,
Electrocomb BIT DEFAULT ((0)) NOT NULL,
IvaDetCombo BIT DEFAULT ((0)) NOT NULL,
LtaBaseIva INT DEFAULT ((0)) NOT NULL,
CodFEDian VARCHAR(20),
Tallaje BIT DEFAULT ((0)) NOT NULL,
TipoProdCo VARCHAR(10)
 CONSTRAINT PK_ProdMcias PRIMARY KEY CLUSTERED (IdProducto),
 CONSTRAINT CK_ProdMciasCodBarras CHECK ((len([CodBarras]) > 0)),
 CONSTRAINT CK_ProdMciasDescripProd CHECK ((len([DescripProd]) > 0)),
 CONSTRAINT CK_ProdMciasIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_ProdMciasIdEmp CHECK ((len([IdEmp]) > 0)),
 CONSTRAINT CK_ProdMciasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_ProdMciasIdMarca CHECK ((len([IdMarca]) > 0)),
 CONSTRAINT CK_ProdMciasIdMnjo CHECK ((len([IdMnjo]) > 0)),
 CONSTRAINT CK_ProdMciasIdNat CHECK ((len([IdNat]) > 0)),
 CONSTRAINT CK_ProdMciasIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdMciasIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_ProdMciasIdSubgrupo CHECK ((len([IdSubgrupo]) > 0)),
 CONSTRAINT CK_ProdMciasIdTarIva CHECK ((len([IdTarIva]) > 0)),
 CONSTRAINT CK_ProdMciasIdTmcia CHECK ((len([IdTmcia]) > 0)),
 CONSTRAINT CK_ProdMciasIdUbic CHECK ((len([IdUbic]) > 0)),
 CONSTRAINT CK_ProdMciasIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_ProdMciasIdUndP CHECK ((len([IdUndP]) > 0)),
 CONSTRAINT CK_ProdMciasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_ProdMciasReferencia CHECK ((len([Referencia]) > 0)),
 CONSTRAINT CK_ProdMciasTipoRef CHECK (([TipoRef] = 'INSUMO' or ([TipoRef] = 'SERVICIO' or [TipoRef] = 'PRODUCTO'))),
 CONSTRAINT CK_ProdMciasUndMed CHECK ((len([UndMed]) > 0)))
CREATE TABLE ProdNiveles ( 
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NivelMin DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NivelMax DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ProdNiveles PRIMARY KEY CLUSTERED (IdProducto,IdCia),
 CONSTRAINT CK_ProdNivelesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_ProdNivelesIdProducto CHECK ((len([IdProducto])>(0))))
CREATE TABLE ProdPrecCom ( 
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
TipoTarif VARCHAR(3) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
NitProv VARCHAR(16) DEFAULT ('0') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ProdPrecCom PRIMARY KEY CLUSTERED (IdProducto,IdCia,Numero),
 CONSTRAINT CK_ProdPrecComIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdPrecComIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdPrecComNitProv CHECK ((len([NitProv]) > 0)),
 CONSTRAINT CK_ProdPrecComTipoTarif CHECK ((len([TipoTarif]) > 0)))
CREATE TABLE ProdPrecCrudo ( 
TipoTarif VARCHAR(3) NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
Duracion VARCHAR(10) NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME,
Tarifa DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
CodCiudad VARCHAR(8)
 CONSTRAINT PK_ProdPrecCrudo PRIMARY KEY CLUSTERED (TipoTarif,Numero),
 CONSTRAINT CK_ProdPrecCrudoDuracion CHECK ((len([Duracion])>(0))),
 CONSTRAINT CK_ProdPrecCrudoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_ProdPrecCrudoIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_ProdPrecCrudoIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_ProdPrecCrudoIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_ProdPrecCrudoTipoTarif CHECK ((len([TipoTarif])>(0))))
CREATE TABLE ProdPrecCrudoFmla ( 
TipoTarif VARCHAR(3) NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipoTasa VARCHAR(10) NOT NULL,
Promedio VARCHAR(3) NOT NULL,
Valor DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Unidad VARCHAR(50) NOT NULL,
CodTasa VARCHAR(4)
 CONSTRAINT PK_ProdPrecCrudoFmla PRIMARY KEY CLUSTERED (TipoTarif,Numero,Item),
 CONSTRAINT CK_ProdPrecCrudoFmlaPromedio CHECK ((len([Promedio])>(0))),
 CONSTRAINT CK_ProdPrecCrudoFmlaTipoTarif CHECK ((len([TipoTarif])>(0))),
 CONSTRAINT CK_ProdPrecCrudoFmlaTipoTasa CHECK ((len([TipoTasa])>(0))),
 CONSTRAINT CK_ProdPrecCrudoFmlaUnidad CHECK ((len([Unidad])>(0))))
CREATE TABLE ProdPrecios ( 
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
VrPrecio1 MONEY DEFAULT (0) NOT NULL,
VrPrecio2 MONEY DEFAULT (0) NOT NULL,
VrPrecio3 MONEY DEFAULT (0) NOT NULL,
VrPrecio4 MONEY DEFAULT (0) NOT NULL,
VrPrecio5 MONEY DEFAULT (0) NOT NULL,
IvaInc VARCHAR(10),
CdTarIva VARCHAR(4) NOT NULL,
CdMoney1 VARCHAR(5),
CdMoney2 VARCHAR(5),
CdMoney3 VARCHAR(5),
CdMoney4 VARCHAR(5),
CdMoney5 VARCHAR(5),
CdMargen1 VARCHAR(4),
CdMargen2 VARCHAR(4),
CdMargen3 VARCHAR(4),
CdMargen4 VARCHAR(4),
CdMargen5 VARCHAR(4),
BaseMargen VARCHAR(10),
CdDcto1 VARCHAR(4),
CdDcto2 VARCHAR(4),
CdDcto3 VARCHAR(4),
CdDcto4 VARCHAR(4),
CdDcto5 VARCHAR(4),
IdUnd VARCHAR(4) NOT NULL,
IdBodega VARCHAR(4) NOT NULL
 CONSTRAINT PK_ProdPrecios PRIMARY KEY CLUSTERED (IdProducto,IdCia),
 CONSTRAINT CK_ProdPreciosCdTarIva CHECK ((len([CdTarIva]) > 0)),
 CONSTRAINT CK_ProdPreciosIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_ProdPreciosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdPreciosIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdPreciosIdUnd CHECK ((len([IdUnd]) > 0)))
CREATE TABLE ProdProcesos ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
CostoEst MONEY DEFAULT ((0)) NOT NULL,
UltCosto MONEY DEFAULT ((0)) NOT NULL,
ProcFinal BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ProdProcesos PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_ProdProcesosIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_ProdProcesosIdTipProc CHECK ((len([IdTipProc])>(0))))
CREATE TABLE ProdProvee ( 
IdProducto VARCHAR(16) NOT NULL,
IdProv VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
DiasGar INT DEFAULT (0) NOT NULL,
CdDct VARCHAR(4),
VrCostCom MONEY DEFAULT (0) NOT NULL,
VrCostPmd MONEY DEFAULT (0) NOT NULL,
RefProv VARCHAR(20),
Dcmento INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_ProdProvee PRIMARY KEY CLUSTERED (IdProducto,IdProv,IdCia),
 CONSTRAINT CK_ProdProveeIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdProveeIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdProveeIdProv CHECK ((len([IdProv]) > 0)))
CREATE TABLE ProdSaldos ( 
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
SaldoActual DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_ProdSaldos PRIMARY KEY CLUSTERED (IdProducto,IdBodega,IdCia),
 CONSTRAINT CK_ProdSaldosIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_ProdSaldosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdSaldosIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE ProdSaldoUbc ( 
IdProducto VARCHAR(16) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
SaldoActual DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_ProdSaldoUbc PRIMARY KEY CLUSTERED (IdProducto,IdUbic,IdCia),
 CONSTRAINT CK_ProdSaldoUbcIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_ProdSaldoUbcIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_ProdSaldoUbcIdUbic CHECK ((len([IdUbic]) > 0)))
CREATE TABLE Profesiones ( 
IdProf VARCHAR(4) NOT NULL,
Profesion VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Profesiones PRIMARY KEY CLUSTERED (IdProf),
 CONSTRAINT CK_ProfesionesIdProf CHECK ((len([IdProf]) > 0)),
 CONSTRAINT CK_ProfesionesProfesion CHECK ((len([Profesion]) > 0)))
CREATE TABLE Puc ( 
IdCuenta VARCHAR(16) NOT NULL,
NomCuenta VARCHAR(100) NOT NULL,
Mayor BIT DEFAULT (0) NOT NULL,
Movimiento BIT DEFAULT (0) NOT NULL,
Tercero BIT DEFAULT (0) NOT NULL,
Vehiculo BIT DEFAULT (0) NOT NULL,
Agencia BIT DEFAULT (0) NOT NULL,
CentroCosto BIT DEFAULT (0) NOT NULL,
SubCentro BIT DEFAULT (0) NOT NULL,
Vencimiento BIT DEFAULT (0) NOT NULL,
BaseGravable BIT DEFAULT (0) NOT NULL,
Porcntaje DECIMAL(10,4) DEFAULT (0) NOT NULL,
Naturaleza CHAR(1) DEFAULT ('D') NOT NULL,
Ajustable BIT DEFAULT (0) NOT NULL,
CuentaAjuDeb VARCHAR(16),
CuentaAjuCre VARCHAR(16),
FmtDian INT DEFAULT (0) NOT NULL,
ConDian INT DEFAULT (0) NOT NULL,
RenDec INT DEFAULT (0) NOT NULL,
Cheques BIT DEFAULT (0) NOT NULL,
Referncias BIT DEFAULT (0) NOT NULL,
CdTipDoc VARCHAR(3),
FechaAdd SMALLDATETIME,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
Afijos INT DEFAULT (0) NOT NULL,
ListarConc VARCHAR(4) DEFAULT ('0'),
ReqAutorizac BIT DEFAULT ((0)) NOT NULL,
AntProveedor BIT DEFAULT ((0)) NOT NULL,
IdCueNiif VARCHAR(16) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_Puc PRIMARY KEY CLUSTERED (IdCuenta),
 CONSTRAINT CK_PucIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_PucIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_PucNaturaleza CHECK (([Naturaleza] = 'R' or ([Naturaleza] = 'C' or [Naturaleza] = 'D'))),
 CONSTRAINT CK_PucNomCuenta CHECK ((len([NomCuenta]) > 0)))
CREATE TABLE PucNiif ( 
IdCuenta VARCHAR(16) NOT NULL,
NomCuenta VARCHAR(250) NOT NULL,
Mayor BIT DEFAULT ((0)) NOT NULL,
Movimiento BIT DEFAULT ((0)) NOT NULL,
Tercero BIT DEFAULT ((0)) NOT NULL,
Vehiculo BIT DEFAULT ((0)) NOT NULL,
Agencia BIT DEFAULT ((0)) NOT NULL,
CentroCosto BIT DEFAULT ((0)) NOT NULL,
SubCentro BIT DEFAULT ((0)) NOT NULL,
Vencimiento BIT DEFAULT ((0)) NOT NULL,
BaseGravable BIT DEFAULT ((0)) NOT NULL,
TarifaPred DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Naturaleza CHAR(1) DEFAULT ('D') NOT NULL,
Ajustable BIT DEFAULT ((0)) NOT NULL,
CuentaAjuDeb VARCHAR(16),
CuentaAjuCre VARCHAR(16),
Cheques BIT DEFAULT ((0)) NOT NULL,
Referencias BIT DEFAULT ((0)) NOT NULL,
CdTipDoc VARCHAR(3),
FechaCrea SMALLDATETIME NOT NULL,
FechaAct SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
Afijos INT DEFAULT ((0)),
ListarConc VARCHAR(4) DEFAULT ('0'),
ReqAutorizac BIT DEFAULT ((0)) NOT NULL,
AntProveedor BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_PucNiif PRIMARY KEY CLUSTERED (IdCuenta),
 CONSTRAINT CK_PucNiifIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_PucNiifIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_PucNiifNaturaleza CHECK ((len([Naturaleza])>(0))),
 CONSTRAINT CK_PucNiifNomCuenta CHECK ((len([NomCuenta])>(0))))
CREATE TABLE Puestos ( 
IdPto VARCHAR(4) NOT NULL,
PtoControl VARCHAR(100) NOT NULL,
TagPuesto VARCHAR(50) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Ubicacion VARCHAR(100),
Contacto VARCHAR(150),
Telefono VARCHAR(20) NOT NULL,
TelMovil VARCHAR(20),
Referencia VARCHAR(50),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Puestos PRIMARY KEY CLUSTERED (IdPto),
 CONSTRAINT CK_PuestosIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_PuestosIdPto CHECK ((len([IdPto]) > 0)),
 CONSTRAINT CK_PuestosPtoControl CHECK ((len([PtoControl]) > 0)),
 CONSTRAINT CK_PuestosTagPuesto CHECK ((len([TagPuesto]) > 0)),
 CONSTRAINT CK_PuestosTelefono CHECK ((len([Telefono]) > 0)))
CREATE TABLE PuntBases ( 
IdProgrma INT DEFAULT (0) NOT NULL,
CdSubgrupo VARCHAR(8) DEFAULT ('0') NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Puntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
Monto DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_PuntBases PRIMARY KEY CLUSTERED (IdProgrma,CdSubgrupo,CdProducto),
 CONSTRAINT CK_PuntBasesCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_PuntBasesCdSubgrupo CHECK ((len([CdSubgrupo]) > 0)))
CREATE TABLE PuntFormas ( 
IdProgrma INT DEFAULT (0) NOT NULL,
IdForma VARCHAR(4) NOT NULL,
Puntos DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_PuntFormas PRIMARY KEY CLUSTERED (IdProgrma,IdForma),
 CONSTRAINT CK_PuntFormasIdForma CHECK ((len([IdForma]) > 0)))
CREATE TABLE PuntPremios ( 
IdProgrma INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(100) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Puntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrBono MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_PuntPremios PRIMARY KEY CLUSTERED (IdProgrma,Item),
 CONSTRAINT CK_PuntPremiosDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_PuntPremiosIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE PuntProg ( 
IdProgrma INT DEFAULT (0) NOT NULL,
FecInicial SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
MesesInact INT DEFAULT (0) NOT NULL,
MesesVcmto INT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
Anulado BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_PuntProg PRIMARY KEY CLUSTERED (IdProgrma),
 CONSTRAINT CK_PuntProgIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE PuntTarjetas ( 
NumTarjeta VARCHAR(20) NOT NULL,
IdClie VARCHAR(16) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TotalPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
PuntRedim DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecUltCompra SMALLDATETIME NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaUpdate SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_PuntTarjetas PRIMARY KEY CLUSTERED (NumTarjeta),
 CONSTRAINT CK_PuntTarjetasIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_PuntTarjetasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_PuntTarjetasNumTarjeta CHECK ((len([NumTarjeta]) > 0)))
CREATE TABLE RangosPeso ( 
IdRango VARCHAR(4) NOT NULL,
DescripRango VARCHAR(50) NOT NULL,
ValorInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
ValorFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_RangosPeso PRIMARY KEY CLUSTERED (IdRango),
 CONSTRAINT CK_RangosPesoDescripRango CHECK ((len([DescripRango]) > 0)),
 CONSTRAINT CK_RangosPesoIdRango CHECK ((len([IdRango]) > 0)))
CREATE TABLE RegimenDian ( 
IdRegimen VARCHAR(4) NOT NULL,
Regimen VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
CodFiscal VARCHAR(20)
 CONSTRAINT PK_RegimenDian PRIMARY KEY CLUSTERED (IdRegimen),
 CONSTRAINT CK_RegimenDianIdRegimen CHECK ((len([IdRegimen]) > 0)),
 CONSTRAINT CK_RegimenDianRegimen CHECK ((len([Regimen]) > 0)))
CREATE TABLE Rutas ( 
IdRuta VARCHAR(4) NOT NULL,
Ruta VARCHAR(100) NOT NULL,
IdLocOri VARCHAR(8) NOT NULL,
IdLocDes VARCHAR(8) NOT NULL,
EsLocal BIT DEFAULT (0) NOT NULL,
Distkmt DECIMAL(14,4) DEFAULT (0) NOT NULL,
TmHoras VARCHAR(8),
CodigoMt VARCHAR(5),
FleteTon MONEY DEFAULT (0),
Inactivo BIT DEFAULT (0) NOT NULL,
CdCiaTurno CHAR(2),
PuntosRut DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Rutas PRIMARY KEY CLUSTERED (IdRuta),
 CONSTRAINT CK_RutasIdLocDes CHECK ((len([IdLocDes]) > 0)),
 CONSTRAINT CK_RutasIdLocOri CHECK ((len([IdLocOri]) > 0)),
 CONSTRAINT CK_RutasIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_RutasRuta CHECK ((len([Ruta]) > 0)))
CREATE TABLE RutasPlan ( 
IdRuta VARCHAR(4) NOT NULL,
IdPunto INT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(100) NOT NULL,
Distancia DECIMAL(14,4) DEFAULT (0) NOT NULL,
Tiempo VARCHAR(8) NOT NULL,
ClasePto VARCHAR(10) DEFAULT ('PC') NOT NULL,
CdPto VARCHAR(4),
IdLocal VARCHAR(8) NOT NULL,
PosLat DECIMAL(14,4) DEFAULT (0) NOT NULL,
PosLon DECIMAL(14,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_RutasPlan PRIMARY KEY CLUSTERED (IdRuta,IdPunto),
 CONSTRAINT CK_RutasPlanClasePto CHECK (([ClasePto] = 'OTRO' or ([ClasePto] = 'VIRTUAL' or [ClasePto] = 'PC'))),
 CONSTRAINT CK_RutasPlanDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_RutasPlanIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_RutasPlanIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_RutasPlanTiempo CHECK ((len([Tiempo]) > 0)))
CREATE TABLE RutasTramos ( 
IdRuta VARCHAR(4) NOT NULL,
NumTramo INT DEFAULT (0) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
kmstramo DECIMAL(14,4) DEFAULT (0) NOT NULL,
kmstotal DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_RutasTramos PRIMARY KEY CLUSTERED (IdRuta,NumTramo),
 CONSTRAINT CK_RutasTramosIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_RutasTramosIdRuta CHECK ((len([IdRuta]) > 0)))
CREATE TABLE SectoresEco ( 
IdSector VARCHAR(8) NOT NULL,
SectorEco VARCHAR(250),
Inactivo BIT DEFAULT (0) NOT NULL,
CdTarifRtc VARCHAR(4)
 CONSTRAINT PK_SectoresEco PRIMARY KEY CLUSTERED (IdSector),
 CONSTRAINT CK_SectoresEcoIdSector CHECK ((len([IdSector]) > 0)),
 CONSTRAINT CK_SectoresEcoSectorEco CHECK ((len([SectorEco]) > 0)))
CREATE TABLE SobEntidades ( 
IdEnterr VARCHAR(8) NOT NULL,
TipoEnterr VARCHAR(10) DEFAULT ('MUNICIPIO') NOT NULL,
NitEntidad VARCHAR(16) NOT NULL,
TipoId CHAR(1) DEFAULT ('N') NOT NULL,
Dv CHAR(1),
DirOficina VARCHAR(250) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
Fax VARCHAR(20),
SitioWeb VARCHAR(100),
e_mail VARCHAR(100),
CedRepLegal VARCHAR(16),
RepLegal VARCHAR(150),
CargoRep VARCHAR(50),
FormaPago VARCHAR(10) DEFAULT ('EFECTIVO') NOT NULL,
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
NomTitular VARCHAR(150),
IdBanco VARCHAR(4) NOT NULL,
CdLocCue VARCHAR(8),
NomEntidad VARCHAR(50),
Inactivo BIT DEFAULT (0) NOT NULL,
CodCtaPag VARCHAR(4)
 CONSTRAINT PK_SobEntidades PRIMARY KEY CLUSTERED (IdEnterr),
 CONSTRAINT CK_SobEntidadesDirOficina CHECK ((len([DirOficina]) > 0)),
 CONSTRAINT CK_SobEntidadesFormaPago CHECK (([FormaPago] = 'TARJETA' or ([FormaPago] = 'OTRO' or ([FormaPago] = 'TRANS' or ([FormaPago] = 'CHEQUE' or [FormaPago] = 'EFECTIVO'))))),
 CONSTRAINT CK_SobEntidadesIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_SobEntidadesIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_SobEntidadesIdEnterr CHECK ((len([IdEnterr]) > 0)),
 CONSTRAINT CK_SobEntidadesNitEntidad CHECK ((len([NitEntidad]) > 0)),
 CONSTRAINT CK_SobEntidadesTelefono CHECK ((len([Telefono]) > 0)),
 CONSTRAINT CK_SobEntidadesTipoEnterr CHECK (([TipoEnterr] = 'NACION' or ([TipoEnterr] = 'DEPTO' or [TipoEnterr] = 'MUNICIPIO'))),
 CONSTRAINT CK_SobEntidadesTipoId CHECK ((len([TipoId]) > 0)))
CREATE TABLE SobProductos ( 
IdClase INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
ClaseProd VARCHAR(20) NOT NULL
 CONSTRAINT PK_SobProductos PRIMARY KEY CLUSTERED (IdClase),
 CONSTRAINT CK_SobProductosClaseProd CHECK ((len([ClaseProd]) > 0)),
 CONSTRAINT CK_SobProductosIdProducto CHECK ((len([IdProducto]) > 0)))
CREATE TABLE SobTiposDec ( 
IdDec VARCHAR(4) NOT NULL,
Declaracion VARCHAR(100) NOT NULL,
TipoDec VARCHAR(20) NOT NULL,
NitDec VARCHAR(16) NOT NULL,
TipoIdDec CHAR(1) DEFAULT ('N') NOT NULL,
NombreDec VARCHAR(250) NOT NULL,
DvDec CHAR(1),
Direccion VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
CedRepLegal VARCHAR(16),
RepLegal VARCHAR(150),
TipoFirma INT DEFAULT (0) NOT NULL,
NitRevisor VARCHAR(16),
NomRevisor VARCHAR(150),
TpRevisor VARCHAR(20),
TarifSubsidio DECIMAL(14,4) DEFAULT (0) NOT NULL,
Consecutivo INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_SobTiposDec PRIMARY KEY CLUSTERED (IdDec),
 CONSTRAINT CK_SobTiposDecDeclaracion CHECK ((len([Declaracion]) > 0)),
 CONSTRAINT CK_SobTiposDecDireccion CHECK ((len([Direccion]) > 0)),
 CONSTRAINT CK_SobTiposDecIdDec CHECK ((len([IdDec]) > 0)),
 CONSTRAINT CK_SobTiposDecIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_SobTiposDecNitDec CHECK ((len([NitDec]) > 0)),
 CONSTRAINT CK_SobTiposDecNombreDec CHECK ((len([NombreDec]) > 0)),
 CONSTRAINT CK_SobTiposDecTelefono CHECK ((len([Telefono]) > 0)),
 CONSTRAINT CK_SobTiposDecTipoDec CHECK ((len([TipoDec]) > 0)),
 CONSTRAINT CK_SobTiposDecTipoIdDec CHECK ((len([TipoIdDec]) > 0)))
CREATE TABLE SubCentros ( 
IdSubCos VARCHAR(16) NOT NULL,
SubCosto VARCHAR(100) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_SubCentros PRIMARY KEY CLUSTERED (IdSubCos),
 CONSTRAINT CK_SubCentrosIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_SubCentrosIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_SubCentrosSubCosto CHECK ((len([SubCosto]) > 0)))
CREATE TABLE SubGrupos ( 
IdSubgrupo VARCHAR(8) NOT NULL,
Subgrupo VARCHAR(150) NOT NULL,
IdGrupo VARCHAR(8) NOT NULL,
CdTarIva VARCHAR(4),
CdTarAut VARCHAR(4),
CdTarRet VARCHAR(4),
CdTarIca VARCHAR(4),
TipoInvent VARCHAR(10) DEFAULT ('COMERCIAL') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
CdTarifImv VARCHAR(4),
CdTarifIco VARCHAR(4),
CdTarIvp VARCHAR(4)
 CONSTRAINT PK_SubGrupos PRIMARY KEY CLUSTERED (IdSubgrupo),
 CONSTRAINT CK_SubGruposIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_SubGruposIdSubgrupo CHECK ((len([IdSubgrupo]) > 0)),
 CONSTRAINT CK_SubGruposSubgrupo CHECK ((len([Subgrupo]) > 0)),
 CONSTRAINT CK_SubGruposTipoInvent CHECK ((len([TipoInvent]) > 0)))
CREATE TABLE SubGruposAgenc ( 
IdSubAgenc VARCHAR(4) NOT NULL,
SubGrupoAgenc VARCHAR(50) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_SubGruposAgenc PRIMARY KEY CLUSTERED (IdSubAgenc),
 CONSTRAINT CK_SubGruposAgencIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_SubGruposAgencIdSubAgenc CHECK ((len([IdSubAgenc]) > 0)),
 CONSTRAINT CK_SubGruposAgencSubGrupoAgenc CHECK ((len([SubGrupoAgenc]) > 0)))
CREATE TABLE SubgruposCc ( 
IdSubgrupo VARCHAR(8) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL
 CONSTRAINT PK_SubgruposCc PRIMARY KEY CLUSTERED (IdSubgrupo,IdClase,IdCCosto),
 CONSTRAINT CK_SubgruposCcIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_SubgruposCcIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_SubgruposCcIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_SubgruposCcIdSubgrupo CHECK ((len([IdSubgrupo]) > 0)))
CREATE TABLE SubgruposCue ( 
IdSubgrupo VARCHAR(8) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
CdCueDev VARCHAR(16),
CdCueCom VARCHAR(16),
CdCueCdv VARCHAR(16),
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME
 CONSTRAINT PK_SubgruposCue PRIMARY KEY CLUSTERED (IdSubgrupo,IdClase),
 CONSTRAINT CK_SubgruposCueIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_SubgruposCueIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_SubgruposCueIdSubgrupo CHECK ((len([IdSubgrupo]) > 0)))
CREATE TABLE Subzonas ( 
IdSzona VARCHAR(4) NOT NULL,
Subzona VARCHAR(50) NOT NULL,
IdZona VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
Cd_Rut VARCHAR(4)
 CONSTRAINT PK_Subzonas PRIMARY KEY CLUSTERED (IdSzona),
 CONSTRAINT CK_SubzonasIdSzona CHECK ((len([IdSzona]) > 0)),
 CONSTRAINT CK_SubzonasIdZona CHECK ((len([IdZona]) > 0)),
 CONSTRAINT CK_SubzonasSubzona CHECK ((len([Subzona]) > 0)))
CREATE TABLE Sys_Autoriza ( 
IdConcepto VARCHAR(4) NOT NULL,
ConceptoAut VARCHAR(150) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Sys_Autoriza PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_Sys_AutorizaConceptoAut CHECK ((len([ConceptoAut]) > 0)),
 CONSTRAINT CK_Sys_AutorizaIdConcepto CHECK ((len([IdConcepto]) > 0)))
CREATE TABLE Sys_Cnxextna ( 
IdReg INT DEFAULT (0) NOT NULL,
CnxTipo VARCHAR(10) DEFAULT ('SYSCOM') NOT NULL,
CnxEngine VARCHAR(10) DEFAULT ('SQL') NOT NULL,
CnxDso VARCHAR(250) NOT NULL,
CnxDbname VARCHAR(50) NOT NULL,
CnxAutentic VARCHAR(3) DEFAULT ('SQL') NOT NULL,
CnxUid VARCHAR(50),
CnxPwd VARCHAR(50),
CnxOwner VARCHAR(20) DEFAULT ('dbo'),
CnxPpties VARCHAR(250),
CnxObserv VARCHAR(250),
CnxDriver VARCHAR(100),
CnxPort VARCHAR(30),
CnxTerminal VARCHAR(4)
 CONSTRAINT PK_Sys_Cnxextna PRIMARY KEY CLUSTERED (IdReg),
 CONSTRAINT CK_Sys_CnxextnaCnxAutentic CHECK (([CnxAutentic] = 'WIN' or [CnxAutentic] = 'SQL')),
 CONSTRAINT CK_Sys_CnxextnaCnxDbname CHECK ((len([CnxDbname]) > 0)),
 CONSTRAINT CK_Sys_CnxextnaCnxDso CHECK ((len([CnxDso]) > 0)),
 CONSTRAINT CK_Sys_CnxextnaCnxEngine CHECK ((len([CnxEngine]) > 0)),
 CONSTRAINT CK_Sys_CnxextnaCnxTipo CHECK ((len([CnxTipo]) > 0)))
CREATE TABLE Sys_Developer ( 
NitCia VARCHAR(13) NOT NULL,
Nombre VARCHAR(50) NOT NULL,
Direccion VARCHAR(50) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
Fax VARCHAR(20) NOT NULL,
Ciudad VARCHAR(20),
Internet VARCHAR(60),
email VARCHAR(60),
RepLegal VARCHAR(50)
 CONSTRAINT PK_Sys_Developer PRIMARY KEY CLUSTERED (NitCia),
 CONSTRAINT CK_Sys_DeveloperDireccion CHECK ((len([Direccion]) > 0)),
 CONSTRAINT CK_Sys_DeveloperFax CHECK ((len([Fax]) > 0)),
 CONSTRAINT CK_Sys_DeveloperNitCia CHECK ((len([NitCia]) > 0)),
 CONSTRAINT CK_Sys_DeveloperNombre CHECK ((len([Nombre]) > 0)),
 CONSTRAINT CK_Sys_DeveloperTelefono CHECK ((len([Telefono]) > 0)))
CREATE TABLE Sys_Entidades ( 
IdTabla VARCHAR(20) NOT NULL,
NivelRel INT DEFAULT (1) NOT NULL,
CamposPK VARCHAR(50) NOT NULL,
FngKey BIT DEFAULT (0) NOT NULL,
Sp_Qry VARCHAR(30),
Sp_Qpmt VARCHAR(50),
Sp_Ins VARCHAR(30),
Sp_Upd VARCHAR(30),
Sp_Del VARCHAR(30)
 CONSTRAINT PK_Sys_Entidades PRIMARY KEY CLUSTERED (IdTabla),
 CONSTRAINT CK_Sys_EntidadesCamposPK CHECK ((len([CamposPK]) > 0)),
 CONSTRAINT CK_Sys_EntidadesIdTabla CHECK ((len([IdTabla]) > 0)))
CREATE TABLE Sys_Estaciones ( 
IdEstacion CHAR(2) NOT NULL,
Estacion VARCHAR(50) NOT NULL
 CONSTRAINT PK_Sys_Estaciones PRIMARY KEY CLUSTERED (IdEstacion),
 CONSTRAINT CK_Sys_EstacionesEstacion CHECK ((len([Estacion]) > 0)),
 CONSTRAINT CK_Sys_EstacionesIdEstacion CHECK ((len([IdEstacion]) > 0)))
CREATE TABLE Sys_Fields ( 
IdEntidad VARCHAR(30) NOT NULL,
IdCampo VARCHAR(20) NOT NULL,
Descripcion VARCHAR(50),
TipoDato VARCHAR(15) DEFAULT ('VARCHAR') NOT NULL,
LongMax INT DEFAULT (0) NOT NULL,
Requerido BIT DEFAULT (0) NOT NULL,
PmryKey BIT DEFAULT (0) NOT NULL,
FmtValue VARCHAR(20),
DftValue VARCHAR(20),
AliasFld VARCHAR(20),
AliasQry2 VARCHAR(20),
IndField INT DEFAULT (0) NOT NULL,
TipoEntidad VARCHAR(5) DEFAULT ('TABLE') NOT NULL,
LstTipo VARCHAR(5) DEFAULT ('N') NOT NULL,
LstClnaValor VARCHAR(20),
LstClnaLista VARCHAR(50),
LstQuery VARCHAR(150),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Sys_Fields PRIMARY KEY CLUSTERED (IdEntidad,IdCampo),
 CONSTRAINT CK_Sys_FieldsIdCampo CHECK ((len([IdCampo]) > 0)),
 CONSTRAINT CK_Sys_FieldsIdEntidad CHECK ((len([IdEntidad]) > 0)),
 CONSTRAINT CK_Sys_FieldsLstTipo CHECK (([LstTipo] = 'N' or ([LstTipo] = 'LIST' or [LstTipo] = 'QRY'))),
 CONSTRAINT CK_Sys_FieldsTipoDato CHECK (([TipoDato] = 'NONE' or ([TipoDato] = 'VARCHAR' or ([TipoDato] = 'MONEY' or ([TipoDato] = 'INTEGER' or ([TipoDato] = 'DECIMAL' or ([TipoDato] = 'DATETIME' or ([TipoDato] = 'CHAR' or [TipoDato] = 'BOOLEAN')))))))),
 CONSTRAINT CK_Sys_FieldsTipoEntidad CHECK (([TipoEntidad] = 'SP' or [TipoEntidad] = 'TABLE')))
CREATE TABLE Sys_FmtDoc ( 
IdDoc VARCHAR(3) NOT NULL,
IdForma CHAR(2) NOT NULL,
Descripcion VARCHAR(100) NOT NULL,
Formato VARCHAR(20) NOT NULL,
Predtmnado BIT DEFAULT (0) NOT NULL,
TipoPapel INT DEFAULT (1) NOT NULL,
Orientacion INT DEFAULT (1) NOT NULL,
VistaPrevia BIT DEFAULT (0) NOT NULL,
VerSetup BIT DEFAULT (0) NOT NULL,
NumCopias INT DEFAULT (1) NOT NULL,
sp_Nombre VARCHAR(50),
Ind_Location VARCHAR(50)
 CONSTRAINT PK_Sys_FmtDoc PRIMARY KEY CLUSTERED (IdDoc,IdForma),
 CONSTRAINT CK_Sys_FmtDocDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Sys_FmtDocFormato CHECK ((len([Formato]) > 0)),
 CONSTRAINT CK_Sys_FmtDocIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_Sys_FmtDocIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_Sys_FmtDocNumCopias CHECK (([NumCopias] <= 10)),
 CONSTRAINT CK_Sys_FmtDocOrientacion CHECK (([Orientacion] >= 0 and [Orientacion] <= 2)))
CREATE TABLE Sys_FmtFactura ( 
nFormato VARCHAR(10) NOT NULL,
IdDoc VARCHAR(3) NOT NULL,
CdForma CHAR(2)
 CONSTRAINT PK_Sys_FmtFactura PRIMARY KEY CLUSTERED (nFormato),
 CONSTRAINT CK_Sys_FmtFacturaIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_Sys_FmtFacturanFormato CHECK ((len([nFormato]) > 0)))
CREATE TABLE Sys_GruposObj ( 
IdGrupo VARCHAR(6) NOT NULL,
GrupoObjeto VARCHAR(50) NOT NULL,
nModulo VARCHAR(10) DEFAULT ('MAIN') NOT NULL
 CONSTRAINT PK_Sys_GruposObj PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_Sys_GruposObjGrupoObjeto CHECK ((len([GrupoObjeto]) > 0)),
 CONSTRAINT CK_Sys_GruposObjIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_Sys_GruposObjnModulo CHECK (([nModulo]='PRODCOM' OR [nModulo]='TRAES' OR [nModulo]='PRESTAMOS' OR [nModulo]='MNMIENTO' OR [nModulo]='RFISICO' OR [nModulo]='TRANS' OR [nModulo]='BUSES' OR [nModulo]='CONTAB' OR [nModulo]='NOMINA' OR [nModulo]='MAIN' OR [nModulo]='JURIDICO')))
CREATE TABLE Sys_GruposUsu ( 
IdGrupo INT DEFAULT (0) NOT NULL,
Grupo VARCHAR(50) NOT NULL,
Descripcion VARCHAR(100)
 CONSTRAINT PK_Sys_GruposUsu PRIMARY KEY CLUSTERED (IdGrupo),
 CONSTRAINT CK_Sys_GruposUsuGrupo CHECK ((len([Grupo]) > 0)),
 CONSTRAINT CK_Sys_GruposUsuIdGrupo CHECK (([IdGrupo] >= 1 and [IdGrupo] <= 5)))
CREATE TABLE Sys_Modulos ( 
IdMod VARCHAR(3) NOT NULL,
Consecutivo INT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(50),
Valor BIT DEFAULT (0) NOT NULL,
nModulo VARCHAR(10) DEFAULT ('MAIN') NOT NULL
 CONSTRAINT PK_Sys_Modulos PRIMARY KEY CLUSTERED (IdMod),
 CONSTRAINT CK_Sys_ModulosIdMod CHECK ((len([IdMod]) > 0)),
 CONSTRAINT CK_Sys_ModulosnModulo CHECK (([nModulo]='TRAES' OR [nModulo]='MAIN' OR [nModulo]='NOMINA' OR [nModulo]='CONTAB' OR [nModulo]='BUSES' OR [nModulo]='TRANS' OR [nModulo]='RFISICO' OR [nModulo]='MNMIENTO')))
CREATE TABLE Sys_ObjetosApp ( 
IdObj VARCHAR(10) NOT NULL,
IdGrupo VARCHAR(6) NOT NULL,
SubModulo VARCHAR(3) NOT NULL,
IndObj INT DEFAULT (1) NOT NULL,
Nombre VARCHAR(100) NOT NULL,
Formulario VARCHAR(10),
Permisos VARCHAR(20) DEFAULT ('S'),
NivelMinimo INT DEFAULT (0),
NomArchivo VARCHAR(30)
 CONSTRAINT PK_Sys_ObjetosApp PRIMARY KEY CLUSTERED (IdObj),
 CONSTRAINT IX_ObjetosAppIndObj UNIQUE NONCLUSTERED (IdGrupo,SubModulo,IndObj),
 CONSTRAINT CK_Sys_ObjetosAppIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_Sys_ObjetosAppIdObj CHECK ((len([IdObj]) > 0)),
 CONSTRAINT CK_Sys_ObjetosAppNivelMinimo CHECK (([NivelMinimo] >= 0 and [NivelMinimo] <= 5)),
 CONSTRAINT CK_Sys_ObjetosAppNombre CHECK ((len([Nombre]) > 0)),
 CONSTRAINT CK_Sys_ObjetosAppSubModulo CHECK ((len([SubModulo]) > 0)))
CREATE TABLE Sys_Relaciones ( 
IdTabla VARCHAR(20) NOT NULL,
TablaForanea VARCHAR(20) NOT NULL,
CampoForaneo VARCHAR(20) NOT NULL,
BasedeDatos VARCHAR(10) DEFAULT ('DB') NOT NULL,
NoValidar BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Sys_Relaciones PRIMARY KEY CLUSTERED (IdTabla,TablaForanea,CampoForaneo),
 CONSTRAINT CK_Sys_RelacionesBasedeDatos CHECK ((len([BasedeDatos]) > 0)),
 CONSTRAINT CK_Sys_RelacionesCampoForaneo CHECK ((len([CampoForaneo]) > 0)),
 CONSTRAINT CK_Sys_RelacionesIdTabla CHECK ((len([IdTabla]) > 0)),
 CONSTRAINT CK_Sys_RelacionesTablaForanea CHECK ((len([TablaForanea]) > 0)))
CREATE TABLE Sys_Report ( 
TipoRep VARCHAR(3) NOT NULL,
IdRep CHAR(2) NOT NULL,
Descripcion VARCHAR(100),
Formato VARCHAR(20) NOT NULL,
TipoPapel INT DEFAULT (1) NOT NULL,
Orientacion INT DEFAULT (1) NOT NULL,
VistaPrevia BIT DEFAULT (0) NOT NULL,
VerSetup BIT DEFAULT (0) NOT NULL,
NumCopias INT DEFAULT (1) NOT NULL,
sp_Nombre VARCHAR(50),
Ind_Location VARCHAR(50),
NomRep VARCHAR(50)
 CONSTRAINT PK_Sys_Report PRIMARY KEY CLUSTERED (TipoRep,IdRep),
 CONSTRAINT CK_Sys_ReportFormato CHECK ((len([Formato]) > 0)),
 CONSTRAINT CK_Sys_ReportIdRep CHECK ((len([IdRep]) > 0)),
 CONSTRAINT CK_Sys_ReportNumCopias CHECK (([NumCopias] >= 0 and [NumCopias] <= 99)),
 CONSTRAINT CK_Sys_ReportOrientacion CHECK (([Orientacion] >= 0 and [Orientacion] <= 2)),
 CONSTRAINT CK_Sys_ReportTipoRep CHECK ((len([TipoRep]) > 0)))
CREATE TABLE Sys_ReportFmto ( 
TipoRep VARCHAR(10) NOT NULL,
Formato VARCHAR(20) NOT NULL,
TipoOrigen VARCHAR(10) DEFAULT ('SP') NOT NULL,
CrVersion INT DEFAULT (9) NOT NULL,
sp_Nombre VARCHAR(50),
Ind_Location VARCHAR(50)
 CONSTRAINT PK_Sys_ReportFmto PRIMARY KEY CLUSTERED (TipoRep,Formato),
 CONSTRAINT CK_Sys_ReportFmtoFormato CHECK ((len([Formato]) > 0)),
 CONSTRAINT CK_Sys_ReportFmtoTipoOrigen CHECK ((len([TipoOrigen]) > 0)),
 CONSTRAINT CK_Sys_ReportFmtoTipoRep CHECK ((len([TipoRep]) > 0)))
CREATE TABLE Sys_ReportSub ( 
TipoRep VARCHAR(10) NOT NULL,
Formato VARCHAR(20) NOT NULL,
NombreSub VARCHAR(20) NOT NULL,
TipoOrigen VARCHAR(10) DEFAULT ('SP') NOT NULL,
sp_Nombre VARCHAR(50),
Ind_Location VARCHAR(50)
 CONSTRAINT PK_Sys_ReportSub PRIMARY KEY CLUSTERED (TipoRep,Formato,NombreSub),
 CONSTRAINT CK_Sys_ReportSubFormato CHECK ((len([Formato]) > 0)),
 CONSTRAINT CK_Sys_ReportSubNombreSub CHECK ((len([NombreSub]) > 0)),
 CONSTRAINT CK_Sys_ReportSubTipoOrigen CHECK ((len([TipoOrigen]) > 0)),
 CONSTRAINT CK_Sys_ReportSubTipoRep CHECK ((len([TipoRep]) > 0)))
CREATE TABLE Sys_ReportSubPmt ( 
TipoRep VARCHAR(10) NOT NULL,
Formato VARCHAR(20) NOT NULL,
NombreSub VARCHAR(20) NOT NULL,
IndParam INT DEFAULT (0) NOT NULL,
NomParam VARCHAR(30) NOT NULL,
TipoDato VARCHAR(15) DEFAULT ('VARCHAR') NOT NULL,
ValorPred VARCHAR(100)
 CONSTRAINT PK_Sys_ReportSubPmt PRIMARY KEY CLUSTERED (TipoRep,Formato,NombreSub,IndParam),
 CONSTRAINT CK_Sys_ReportSubPmtFormato CHECK ((len([Formato]) > 0)),
 CONSTRAINT CK_Sys_ReportSubPmtNombreSub CHECK ((len([NombreSub]) > 0)),
 CONSTRAINT CK_Sys_ReportSubPmtNomParam CHECK ((len([NomParam]) > 0)),
 CONSTRAINT CK_Sys_ReportSubPmtTipoDato CHECK ((len([TipoDato]) > 0)),
 CONSTRAINT CK_Sys_ReportSubPmtTipoRep CHECK ((len([TipoRep]) > 0)))
CREATE TABLE Sys_Roles ( 
IdObj VARCHAR(10) NOT NULL,
IdRole VARCHAR(3) NOT NULL,
Funcion VARCHAR(100) NOT NULL
 CONSTRAINT PK_Sys_Roles PRIMARY KEY CLUSTERED (IdObj,IdRole),
 CONSTRAINT CK_Sys_RolesFuncion CHECK ((len([Funcion]) > 0)),
 CONSTRAINT CK_Sys_RolesIdObj CHECK ((len([IdObj]) > 0)),
 CONSTRAINT CK_Sys_RolesIdRole CHECK ((len([IdRole]) > 0)))
CREATE TABLE Sys_Security ( 
IdLla INT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(50) NOT NULL,
Pwd VARCHAR(10)
 CONSTRAINT PK_Sys_Security PRIMARY KEY CLUSTERED (IdLla),
 CONSTRAINT CK_Sys_SecurityDescripcion CHECK ((len([Descripcion]) > 0)))
CREATE TABLE Sys_TFmtos ( 
nFormato VARCHAR(10) NOT NULL,
FmtoFactura VARCHAR(50) NOT NULL,
TipFac VARCHAR(3) DEFAULT ('FCO') NOT NULL
 CONSTRAINT PK_Sys_TFmtos PRIMARY KEY CLUSTERED (nFormato),
 CONSTRAINT CK_Sys_TFmtosFmtoFactura CHECK ((len([FmtoFactura]) > 0)),
 CONSTRAINT CK_Sys_TFmtosnFormato CHECK ((len([nFormato]) > 0)),
 CONSTRAINT CK_Sys_TFmtosTipFac CHECK (([TipFac] = 'FCO' or [TipFac] = 'FCR')))
CREATE TABLE Sys_TiposDoc ( 
IdDoc VARCHAR(3) NOT NULL,
TipoDoc VARCHAR(50) NOT NULL,
ConsUnico BIT DEFAULT (0) NOT NULL,
Leyenda VARCHAR(250),
Inactivo BIT DEFAULT (0) NOT NULL,
IntegraCias BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Sys_TiposDoc PRIMARY KEY CLUSTERED (IdDoc),
 CONSTRAINT CK_Sys_TiposDocIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_Sys_TiposDocTipoDoc CHECK ((len([TipoDoc]) > 0)))
CREATE TABLE Sys_TiposDocCue ( 
IdDoc VARCHAR(3) NOT NULL,
IdClase INT DEFAULT (0) NOT NULL,
ClaseCuenta VARCHAR(50) NOT NULL,
TipoMov CHAR(1) DEFAULT ('N') NOT NULL
 CONSTRAINT PK_Sys_TiposDocCue PRIMARY KEY CLUSTERED (IdDoc,IdClase),
 CONSTRAINT CK_Sys_TiposDocCueClaseCuenta CHECK ((len([ClaseCuenta]) > 0)),
 CONSTRAINT CK_Sys_TiposDocCueIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_Sys_TiposDocCueTipoMov CHECK (([TipoMov] = 'N' or ([TipoMov] = 'C' or [TipoMov] = 'D'))))
CREATE TABLE Sys_Tpapers ( 
IdPapel INT DEFAULT (0) NOT NULL,
Nombre VARCHAR(30) NOT NULL
 CONSTRAINT PK_Sys_Tpapers PRIMARY KEY CLUSTERED (IdPapel),
 CONSTRAINT CK_Sys_TpapersNombre CHECK ((len([Nombre]) > 0)))
CREATE TABLE Sys_Um ( 
UndMed VARCHAR(10) NOT NULL,
Unidad VARCHAR(50) NOT NULL,
Carga BIT DEFAULT (0) NOT NULL,
CodUMFE VARCHAR(20)
 CONSTRAINT PK_Sys_Um PRIMARY KEY CLUSTERED (UndMed),
 CONSTRAINT CK_Sys_UmUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Sys_UmUnidad CHECK ((len([Unidad]) > 0)))
CREATE TABLE Tablapor ( 
IdTarifa VARCHAR(4) NOT NULL,
Descripcion VARCHAR(50),
IdClase VARCHAR(4) NOT NULL,
Tarifa DECIMAL(16,6) DEFAULT (0) NOT NULL,
Simbolo CHAR(1) DEFAULT ('%') NOT NULL,
CdLocdad VARCHAR(8),
Minimo MONEY DEFAULT (0) NOT NULL,
Maximo MONEY DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Tablapor PRIMARY KEY CLUSTERED (IdTarifa),
 CONSTRAINT CK_TablaporIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_TablaporIdTarifa CHECK ((len([IdTarifa]) > 0)),
 CONSTRAINT CK_TablaporSimbolo CHECK (([Simbolo] = '$' or [Simbolo] = '%')))
CREATE TABLE Talleres ( 
IdTaller VARCHAR(4) NOT NULL,
NomTaller VARCHAR(100) NOT NULL,
Direccion VARCHAR(250),
IdLocal VARCHAR(8) NOT NULL,
Telefono VARCHAR(30),
TelCelular VARCHAR(30),
NitTercero VARCHAR(16),
TipoTaller VARCHAR(20),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Talleres PRIMARY KEY CLUSTERED (IdTaller),
 CONSTRAINT CK_TalleresIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_TalleresIdTaller CHECK ((len([IdTaller])>(0))),
 CONSTRAINT CK_TalleresNomTaller CHECK ((len([NomTaller])>(0))))
CREATE TABLE TanqAforo ( 
IdTanque VARCHAR(4) NOT NULL,
UndAforo DECIMAL(14,4) DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TanqAforo PRIMARY KEY CLUSTERED (IdTanque,UndAforo),
 CONSTRAINT CK_TanqAforoIdTanque CHECK ((len([IdTanque]) > 0)))
CREATE TABLE TanqAforoFrac ( 
IdTanque VARCHAR(4) NOT NULL,
UndAforo DECIMAL(14,4) DEFAULT (0) NOT NULL,
Fraccion DECIMAL(14,4) DEFAULT (0) NOT NULL,
Milimetros DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TanqAforoFrac PRIMARY KEY CLUSTERED (IdTanque,UndAforo),
 CONSTRAINT CK_TanqAforoFracIdTanque CHECK ((len([IdTanque]) > 0)))
CREATE TABLE TanqDispens ( 
IdMngra VARCHAR(10) NOT NULL,
NumDisp VARCHAR(4) NOT NULL,
NumPos VARCHAR(4) NOT NULL,
NumMngra VARCHAR(4) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
Descripcion VARCHAR(50),
LecGalAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
LecGalUlt DECIMAL(14,4) DEFAULT (0) NOT NULL,
LecPesAnt MONEY DEFAULT (0) NOT NULL,
LecPesUlt MONEY DEFAULT (0) NOT NULL,
LtaPrec CHAR(1),
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
Inactivo BIT DEFAULT (0) NOT NULL,
LecGalMax DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TanqDispens PRIMARY KEY CLUSTERED (IdMngra),
 CONSTRAINT IX_TanqDispensNumDisp UNIQUE NONCLUSTERED (NumDisp,NumPos,NumMngra),
 CONSTRAINT CK_TanqDispensIdMngra CHECK ((len([IdMngra]) > 0)),
 CONSTRAINT CK_TanqDispensIdTanque CHECK ((len([IdTanque]) > 0)),
 CONSTRAINT CK_TanqDispensNumDisp CHECK ((len([NumDisp]) > 0)),
 CONSTRAINT CK_TanqDispensNumMngra CHECK ((len([NumMngra]) > 0)),
 CONSTRAINT CK_TanqDispensNumPos CHECK ((len([NumPos]) > 0)))
CREATE TABLE TanqSaldos ( 
IdTanque VARCHAR(4) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
SaldoActual DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TanqSaldos PRIMARY KEY CLUSTERED (IdTanque,IdCia),
 CONSTRAINT CK_TanqSaldosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_TanqSaldosIdTanque CHECK ((len([IdTanque]) > 0)))
CREATE TABLE Tanques ( 
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(50),
CapTanq DECIMAL(14,4) DEFAULT (0) NOT NULL,
NivAgua DECIMAL(14,4) DEFAULT (0) NOT NULL,
CapNeta DECIMAL(14,4) DEFAULT (0) NOT NULL,
SaldoActual DECIMAL(14,4) DEFAULT (0) NOT NULL,
TnqGas BIT DEFAULT (0) NOT NULL,
TnqUnido BIT DEFAULT (0) NOT NULL,
TnqVirtual BIT DEFAULT (0) NOT NULL,
CdNueTan VARCHAR(4),
NColor INT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
Inactivo BIT DEFAULT (0) NOT NULL,
IdCiaDef CHAR(2) DEFAULT ('00') NOT NULL,
CodigoApi VARCHAR(10),
CdTerminal VARCHAR(4),
TipoProd VARCHAR(10),
Altura DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Tanques PRIMARY KEY CLUSTERED (IdTanque),
 CONSTRAINT CK_TanquesIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_TanquesIdTanque CHECK ((len([IdTanque]) > 0)))
CREATE TABLE TarifAnticipos ( 
Numero INT DEFAULT ((0)) NOT NULL,
CuotaMax DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoCuota VARCHAR(10) DEFAULT ('FLETE') NOT NULL,
TipoAplica VARCHAR(10) DEFAULT ('GENERAL') NOT NULL,
CdOrigen VARCHAR(8) DEFAULT ('0') NOT NULL,
CdDestino VARCHAR(8) DEFAULT ('0') NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdTipoVeh VARCHAR(4) DEFAULT ('0') NOT NULL,
TipoAfilVeh VARCHAR(10),
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
NitPropietario VARCHAR(16) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_TarifAnticipos PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_TarifAnticiposCdDestino CHECK ((len([CdDestino])>(0))),
 CONSTRAINT CK_TarifAnticiposCdOrigen CHECK ((len([CdOrigen])>(0))),
 CONSTRAINT CK_TarifAnticiposCdTipoVeh CHECK ((len([CdTipoVeh])>(0))),
 CONSTRAINT CK_TarifAnticiposIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_TarifAnticiposNitCliente CHECK ((len([NitCliente])>(0))),
 CONSTRAINT CK_TarifAnticiposTipoAplica CHECK ((len([TipoAplica])>(0))),
 CONSTRAINT CK_TarifAnticiposTipoCuota CHECK ((len([TipoCuota])>(0))))
CREATE TABLE TarifasCom ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
DiasInicio DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DiasFinal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdTarifa VARCHAR(4) NOT NULL
 CONSTRAINT PK_TarifasCom PRIMARY KEY CLUSTERED (Id),
 CONSTRAINT CK_TarifasComIdTarifa CHECK ((len([IdTarifa])>(0))))
CREATE TABLE TarifasFleMay ( 
IdAgencia VARCHAR(16) NOT NULL,
TipoTarifa VARCHAR(10) NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
TipoVehic INT DEFAULT ((0)) NOT NULL,
NitEmpresa VARCHAR(16) NOT NULL,
CapacMin DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CapacMax DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrTarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoLiquida VARCHAR(10) NOT NULL,
DescTipoVeh VARCHAR(50),
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_TarifasFleMay PRIMARY KEY CLUSTERED (IdAgencia,TipoTarifa,Numero),
 CONSTRAINT CK_TarifasFleMayIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_TarifasFleMayIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_TarifasFleMayNitEmpresa CHECK ((len([NitEmpresa])>(0))),
 CONSTRAINT CK_TarifasFleMayTipoLiquida CHECK ((len([TipoLiquida])>(0))),
 CONSTRAINT CK_TarifasFleMayTipoTarifa CHECK ((len([TipoTarifa])>(0))))
CREATE TABLE TarifasFletes ( 
Numero INT DEFAULT ((0)) NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
TipoTarifa VARCHAR(10) DEFAULT ('RUTA') NOT NULL,
TarifClie MONEY DEFAULT ((0)) NOT NULL,
TarifPago MONEY DEFAULT ((0)) NOT NULL,
TarifTabla MONEY DEFAULT ((0)) NOT NULL,
IdMneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
UndMed VARCHAR(10) DEFAULT ('0') NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdNat VARCHAR(4),
CdTipoVeh VARCHAR(4),
CdRango VARCHAR(4),
UndTarifClie VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndTarifPago VARCHAR(10) DEFAULT ('PESO') NOT NULL,
CdMercancia VARCHAR(16) DEFAULT ('0') NOT NULL,
TipoAfiVehic VARCHAR(10),
TarifAfiliado DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifTercero DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifPropio DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoOper VARCHAR(10),
CdGrupo VARCHAR(4),
MargenMin DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0')
 CONSTRAINT PK_TarifasFletes PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_TarifasFletesCdRuta CHECK ((len([CdRuta])>(0))),
 CONSTRAINT CK_TarifasFletesIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_TarifasFletesIdMneda CHECK ((len([IdMneda])>(0))),
 CONSTRAINT CK_TarifasFletesIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_TarifasFletesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_TarifasFletesNitCliente CHECK ((len([NitCliente])>(0))),
 CONSTRAINT CK_TarifasFletesTipoTarifa CHECK ((len([TipoTarifa])>(0))),
 CONSTRAINT CK_TarifasFletesUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE TarifasMasivo ( 
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdTipoVeh VARCHAR(4) NOT NULL,
TarifaUnd DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrFletes DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TarifasMasivo PRIMARY KEY CLUSTERED (IdOrigen,IdDestino,IdTipoVeh),
 CONSTRAINT CK_TarifasMasivoIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_TarifasMasivoIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_TarifasMasivoIdTipoVeh CHECK ((len([IdTipoVeh])>(0))))
CREATE TABLE TarifasPaq ( 
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
TarifaUnd DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TiempoEnt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaMin DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
FormaPago VARCHAR(20) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TarifasPaq PRIMARY KEY CLUSTERED (IdOrigen,IdDestino),
 CONSTRAINT CK_TarifasPaqFormaPago CHECK ((len([FormaPago])>(0))),
 CONSTRAINT CK_TarifasPaqIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_TarifasPaqIdOrigen CHECK ((len([IdOrigen])>(0))))
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,
MargenMin DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdRuta VARCHAR(4),
CdCiuOrigen VARCHAR(8),
CdCiuDestino VARCHAR(8)
 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))))
CREATE TABLE TarifBuses ( 
IdTarifa VARCHAR(4) NOT NULL,
Descripcion VARCHAR(20) NOT NULL,
VrNormal MONEY DEFAULT (0) NOT NULL,
VrFestivo MONEY DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TarifBuses PRIMARY KEY CLUSTERED (IdTarifa),
 CONSTRAINT CK_TarifBusesDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_TarifBusesIdTarifa CHECK ((len([IdTarifa]) > 0)))
CREATE TABLE TarifCuentas ( 
IdTarifa VARCHAR(4) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
ClaseTarif VARCHAR(4) DEFAULT ('ICA') NOT NULL,
CdCueOtr VARCHAR(16)
 CONSTRAINT PK_TarifCuentas PRIMARY KEY CLUSTERED (IdTarifa,TipDoc),
 CONSTRAINT CK_TarifCuentasClaseTarif CHECK ((len([ClaseTarif]) > 0)),
 CONSTRAINT CK_TarifCuentasIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_TarifCuentasIdTarifa CHECK ((len([IdTarifa]) > 0)),
 CONSTRAINT CK_TarifCuentasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE TarifSeguro ( 
IdTarif VARCHAR(4) NOT NULL,
VrDecInicial MONEY DEFAULT ((0)) NOT NULL,
VrDecFinal MONEY DEFAULT ((0)) NOT NULL,
TarifSeguro DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TarifSeguro PRIMARY KEY CLUSTERED (IdTarif),
 CONSTRAINT CK_TarifSeguroIdTarif CHECK ((len([IdTarif])>(0))))
CREATE TABLE TasasDTF ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
nSem INT DEFAULT (0) NOT NULL,
DTF_EA DECIMAL(14,4) DEFAULT (0) NOT NULL,
TIBC_EA DECIMAL(14,4) DEFAULT (0) NOT NULL,
Factor_Mon DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TasasDTF PRIMARY KEY CLUSTERED (nAnno,nMes,nSem))
CREATE TABLE TasasInteres ( 
IdTasa VARCHAR(4) NOT NULL,
DescTasa VARCHAR(50) NOT NULL,
TipoInteres VARCHAR(10) DEFAULT ('DTF') NOT NULL,
TipoPeriodo VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
CausaInteres INT DEFAULT (0) NOT NULL,
TipoDTF VARCHAR(10) DEFAULT ('VARIABLE') NOT NULL,
DTF_EA DECIMAL(14,4) DEFAULT (0) NOT NULL,
Spread_TA DECIMAL(14,4) DEFAULT (0) NOT NULL,
TasaEfectiva DECIMAL(14,4) DEFAULT (0) NOT NULL,
OpcCompra DECIMAL(14,4) DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TasasInteres PRIMARY KEY CLUSTERED (IdTasa),
 CONSTRAINT CK_TasasInteresDescTasa CHECK ((len([DescTasa]) > 0)),
 CONSTRAINT CK_TasasInteresIdTasa CHECK ((len([IdTasa]) > 0)),
 CONSTRAINT CK_TasasInteresTipoDTF CHECK ((len([TipoDTF]) > 0)),
 CONSTRAINT CK_TasasInteresTipoInteres CHECK ((len([TipoInteres]) > 0)),
 CONSTRAINT CK_TasasInteresTipoPeriodo CHECK ((len([TipoPeriodo]) > 0)))
CREATE TABLE TasasIntmora ( 
IdMora VARCHAR(4) NOT NULL,
DescMora VARCHAR(50) NOT NULL,
TipoInteres VARCHAR(10) DEFAULT ('VARIABLE') NOT NULL,
TasaEA DECIMAL(14,4) DEFAULT (0) NOT NULL,
TasaEM DECIMAL(14,4) DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TasasIntmora PRIMARY KEY CLUSTERED (IdMora),
 CONSTRAINT CK_TasasIntmoraDescMora CHECK ((len([DescMora]) > 0)),
 CONSTRAINT CK_TasasIntmoraIdMora CHECK ((len([IdMora]) > 0)),
 CONSTRAINT CK_TasasIntmoraTipoInteres CHECK ((len([TipoInteres]) > 0)))
CREATE TABLE TaxRutas ( 
IdRuta VARCHAR(4) NOT NULL,
NomRuta VARCHAR(100) NOT NULL,
TipoRuta VARCHAR(10) DEFAULT ('PERSONAL') NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifCobro MONEY DEFAULT (0) NOT NULL,
Origen VARCHAR(30),
Destino VARCHAR(30),
CodRuta VARCHAR(20),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TaxRutas PRIMARY KEY CLUSTERED (IdRuta),
 CONSTRAINT CK_TaxRutasIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_TaxRutasNomRuta CHECK ((len([NomRuta]) > 0)),
 CONSTRAINT CK_TaxRutasTipoRuta CHECK ((len([TipoRuta]) > 0)))
CREATE TABLE TaxTarifas ( 
TipoTarif VARCHAR(10) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoHora INT DEFAULT (0) NOT NULL,
NumInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifCobro MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_TaxTarifas PRIMARY KEY CLUSTERED (TipoTarif,Item),
 CONSTRAINT CK_TaxTarifasTipoTarif CHECK ((len([TipoTarif]) > 0)))
CREATE TABLE TaxTarifClie ( 
TipoTarif VARCHAR(10) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdClie VARCHAR(16) NOT NULL,
TipoHora INT DEFAULT (0) NOT NULL,
IdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
NumInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifCobro MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_TaxTarifClie PRIMARY KEY CLUSTERED (TipoTarif,Item),
 CONSTRAINT CK_TaxTarifClieIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TaxTarifClieIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_TaxTarifClieTipoTarif CHECK ((len([TipoTarif]) > 0)))
CREATE TABLE TercClieAlmac ( 
nAnno INT DEFAULT ((0)) NOT NULL,
IdClie VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
VolInicial DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VolFinal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaFact DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaUnd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IdMneda VARCHAR(5) DEFAULT ('USD') NOT NULL,
VolExcedente DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaExd DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercClieAlmac PRIMARY KEY CLUSTERED (nAnno,IdClie,Item),
 CONSTRAINT CK_TercClieAlmacIdClie CHECK ((len([IdClie])>(0))),
 CONSTRAINT CK_TercClieAlmacIdMneda CHECK ((len([IdMneda])>(0))))
CREATE TABLE TercClieCia ( 
IdClie VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_TercClieCia PRIMARY KEY CLUSTERED (IdClie,IdCia))
CREATE TABLE TercClieCond ( 
IdClie VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
DescripCond VARCHAR(3000) NOT NULL
 CONSTRAINT PK_TercClieCond PRIMARY KEY CLUSTERED (IdClie,Item),
 CONSTRAINT CK_TercClieCondIdClie CHECK ((len([IdClie]) > 0)))
CREATE TABLE TercClieCupos ( 
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) NOT NULL,
CupoGals DECIMAL(14,4) DEFAULT (0) NOT NULL,
CupoZFE DECIMAL(14,4) DEFAULT (0) NOT NULL,
CupoAdic DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TercClieCupos PRIMARY KEY CLUSTERED (nAnno,nMes,IdClie,IdAgencia),
 CONSTRAINT CK_TercClieCuposIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_TercClieCuposIdClie CHECK ((len([IdClie]) > 0)))
CREATE TABLE TercClieDoc ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Documento VARCHAR(250) NOT NULL,
Requerido BIT DEFAULT ((1)) NOT NULL,
Referencia BIT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercClieDoc PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_TercClieDocDocumento CHECK ((len([Documento])>(0))),
 CONSTRAINT CK_TercClieDocIdCliente CHECK ((len([IdCliente])>(0))))
CREATE TABLE TercClieGarant ( 
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdLinea VARCHAR(4) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipoGarant VARCHAR(20) NOT NULL,
CdInmueble VARCHAR(4) NOT NULL,
CdTipoVeh VARCHAR(4) NOT NULL,
VrGarant MONEY DEFAULT ((0)) NOT NULL,
VrAvaluo MONEY DEFAULT ((0)) NOT NULL,
Propietario VARCHAR(250),
DirInmueble VARCHAR(250),
CdCiudad VARCHAR(8),
Matricula VARCHAR(50),
Escritura VARCHAR(50),
NumNotaria VARCHAR(20),
MarcaVeh VARCHAR(20),
Modelo VARCHAR(4),
CdBanco VARCHAR(4),
FecCheque SMALLDATETIME,
NumCheque VARCHAR(20),
OtroTipoVehic VARCHAR(50),
OtroInmueble VARCHAR(50),
CedFmnte1 VARCHAR(16),
NomFmnte1 VARCHAR(150),
CedFmnte2 VARCHAR(16),
NomFmnte2 VARCHAR(150),
CedFmnte3 VARCHAR(16),
NomFmnte3 VARCHAR(150),
CedFmnte4 VARCHAR(16),
NomFmnte4 VARCHAR(150),
CedFmnte5 VARCHAR(16),
NomFmnte5 VARCHAR(150),
CedFmnte6 VARCHAR(16),
NomFmnte6 VARCHAR(150)
 CONSTRAINT PK_TercClieGarant PRIMARY KEY CLUSTERED (IdClie,IdAgencia,IdLinea,Item),
 CONSTRAINT CK_TercClieGarantCdInmueble CHECK ((len([CdInmueble])>(0))),
 CONSTRAINT CK_TercClieGarantCdTipoVeh CHECK ((len([CdTipoVeh])>(0))),
 CONSTRAINT CK_TercClieGarantIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_TercClieGarantIdClie CHECK ((len([IdClie])>(0))),
 CONSTRAINT CK_TercClieGarantIdLinea CHECK ((len([IdLinea])>(0))),
 CONSTRAINT CK_TercClieGarantTipoGarant CHECK ((len([TipoGarant])>(0))))
CREATE TABLE TercClieLineas ( 
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdLinea VARCHAR(4) NOT NULL,
IdTasa VARCHAR(4) NOT NULL,
nPlazo INT DEFAULT (0) NOT NULL,
TipoPlazo CHAR(1) DEFAULT ('D') NOT NULL,
CupoCredito MONEY DEFAULT (0) NOT NULL,
SaldoCapital MONEY DEFAULT (0) NOT NULL,
SaldoInteres MONEY DEFAULT (0) NOT NULL,
MaxCupoSmlv DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoCausac VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
DiasVence VARCHAR(20),
LiqSeguro BIT DEFAULT (0) NOT NULL,
FecPreAprob SMALLDATETIME,
PlazoAprob INT DEFAULT (0) NOT NULL,
EtdoAprob INT DEFAULT (0) NOT NULL,
TipoAprob VARCHAR(20),
DescAprob VARCHAR(250),
Garantias BIT DEFAULT (0) NOT NULL,
TipoGarantia VARCHAR(10),
DescGarantia VARCHAR(250),
VrGarantia MONEY DEFAULT (0) NOT NULL,
ReqCheques BIT DEFAULT (0) NOT NULL,
FecActCupo SMALLDATETIME,
CdTasaConv VARCHAR(4),
NitConvenio VARCHAR(16),
CuotasConv INT DEFAULT (0) NOT NULL,
EstadoAct INT DEFAULT (0) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
FechaAct SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CdTarifSeguro VARCHAR(4),
TasaIntLinea BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercClieLineas PRIMARY KEY CLUSTERED (IdClie,IdAgencia,IdLinea),
 CONSTRAINT CK_TercClieLineasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_TercClieLineasIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TercClieLineasIdLinea CHECK ((len([IdLinea]) > 0)),
 CONSTRAINT CK_TercClieLineasIdTasa CHECK ((len([IdTasa]) > 0)),
 CONSTRAINT CK_TercClieLineasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TercClieLineasTipoCausac CHECK ((len([TipoCausac]) > 0)),
 CONSTRAINT CK_TercClieLineasTipoPlazo CHECK ((len([TipoPlazo]) > 0)))
CREATE TABLE TercCliente ( 
IdClie VARCHAR(16) NOT NULL,
NitRepLeg VARCHAR(16),
NomRepLeg VARCHAR(150),
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargContac VARCHAR(50),
DirEnv VARCHAR(250),
IdLocEnv VARCHAR(8) NOT NULL,
DiasEntga INT DEFAULT (0) NOT NULL,
IdSzona VARCHAR(4) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
IdForma VARCHAR(4) NOT NULL,
IdEstrato VARCHAR(4) NOT NULL,
CdBandera VARCHAR(4) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
NitFact VARCHAR(16),
IdRuta VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
CdMney VARCHAR(5),
CdDct VARCHAR(4),
CdRet VARCHAR(4),
CdRiv VARCHAR(4),
CdCms VARCHAR(4),
PlazosImp VARCHAR(20),
ExcIva BIT DEFAULT (0) NOT NULL,
TrfIntMora DECIMAL(14,4) DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
LiqFletes BIT DEFAULT (0) NOT NULL,
FactSold BIT DEFAULT (0) NOT NULL,
Autoret BIT DEFAULT (0) NOT NULL,
IncRet BIT DEFAULT (0) NOT NULL,
IncRiv BIT DEFAULT (0) NOT NULL,
IncIca BIT DEFAULT (0) NOT NULL,
FactTipo INT DEFAULT (0) NOT NULL,
VrCupo MONEY DEFAULT (0) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL,
UidClie VARCHAR(16) DEFAULT ('0') NOT NULL,
PwdClie VARCHAR(10),
Contrato BIT DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
CiaContMay CHAR(2) DEFAULT ('00') NOT NULL,
CodClieSicom VARCHAR(20) DEFAULT ('0') NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME,
FecRetiro SMALLDATETIME,
MatMerc VARCHAR(20),
FecMat SMALLDATETIME,
PathFoto VARCHAR(30),
PathFirma VARCHAR(30),
Cmntario1 VARCHAR(250),
Cmntario2 VARCHAR(250),
Cmntario3 VARCHAR(250),
PrendGarant VARCHAR(150),
FecUpCupo SMALLDATETIME,
TipoCliente VARCHAR(10) DEFAULT ('NONE') NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
Restric_Cia BIT DEFAULT (0) NOT NULL,
CdPlazoComb VARCHAR(4) DEFAULT ('0') NOT NULL,
CupoGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecPlazoDoc SMALLDATETIME,
EdoRadicaDoc INT DEFAULT (0) NOT NULL,
CdTipBloq VARCHAR(4),
DescEdoDoc VARCHAR(250),
ComIndustrial INT DEFAULT ((0)) NOT NULL,
NumLista CHAR(1),
Termicas BIT DEFAULT ((0)) NOT NULL,
CodRetCom VARCHAR(4),
CodCCosto VARCHAR(16),
CodSubCosto VARCHAR(16),
CdDiaEnt VARCHAR(4),
AutoIca BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercCliente PRIMARY KEY CLUSTERED (IdClie),
 CONSTRAINT CK_TercClienteCdBandera CHECK ((len([CdBandera]) > 0)),
 CONSTRAINT CK_TercClienteCdPlazoComb CHECK ((len([CdPlazoComb]) > 0)),
 CONSTRAINT CK_TercClienteCiaContMay CHECK ((len([CiaContMay]) > 0)),
 CONSTRAINT CK_TercClienteIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_TercClienteIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_TercClienteIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TercClienteIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_TercClienteIdEstrato CHECK ((len([IdEstrato]) > 0)),
 CONSTRAINT CK_TercClienteIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_TercClienteIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_TercClienteIdLocEnv CHECK ((len([IdLocEnv]) > 0)),
 CONSTRAINT CK_TercClienteIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_TercClienteIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_TercClienteIdSzona CHECK ((len([IdSzona]) > 0)),
 CONSTRAINT CK_TercClienteIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TercClienteIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_TercClienteTipoCliente CHECK ((len([TipoCliente]) > 0)),
 CONSTRAINT CK_TercClienteUidClie CHECK ((len([UidClie]) > 0)))
CREATE TABLE TercCliePreRef ( 
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoRef VARCHAR(10) NOT NULL,
Referencia VARCHAR(150) NOT NULL,
NitRefncia VARCHAR(16),
DirRefncia VARCHAR(150),
TelRefncia VARCHAR(30) NOT NULL,
emlRefncia VARCHAR(100),
CargRefncia VARCHAR(50),
NumCuenta VARCHAR(30),
Observcion VARCHAR(250),
Parentesco VARCHAR(10),
FechaNac SMALLDATETIME,
Edad INT DEFAULT ((0)) NOT NULL,
BenSolidario BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercCliePreRef PRIMARY KEY CLUSTERED (IdClie,IdAgencia,Item),
 CONSTRAINT CK_TercCliePreRefIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_TercCliePreRefIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TercCliePreRefReferencia CHECK ((len([Referencia]) > 0)),
 CONSTRAINT CK_TercCliePreRefTelRefncia CHECK ((len([TelRefncia]) > 0)),
 CONSTRAINT CK_TercCliePreRefTipoRef CHECK ((len([TipoRef]) > 0)))
CREATE TABLE TercCliePrestamo ( 
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdSzona VARCHAR(4) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdTipoTerc VARCHAR(4) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
NomAgencia VARCHAR(150),
DirAgencia VARCHAR(250),
IdLocalAge VARCHAR(8) NOT NULL,
NitRepLeg VARCHAR(16),
NomRepLeg VARCHAR(150),
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargContac VARCHAR(50),
EsExento BIT DEFAULT (0) NOT NULL,
CalcIntMora BIT DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME,
FecRetiro SMALLDATETIME,
VrSalBasico MONEY DEFAULT (0) NOT NULL,
MaxDcto DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoSalario CHAR(1) DEFAULT ('F') NOT NULL,
MatMerc VARCHAR(20),
FecMat SMALLDATETIME,
Comentarios VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
FechaAct SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
NumTarj VARCHAR(30),
PwdTarj VARCHAR(30),
FecVenceTc SMALLDATETIME,
IncRetFte BIT DEFAULT ((0)) NOT NULL,
FechaImp SMALLDATETIME,
CodCCosto VARCHAR(16),
CodSubCosto VARCHAR(16),
FecNacmto SMALLDATETIME,
Nacionalidad VARCHAR(50),
Sexo CHAR(1) DEFAULT ('N'),
CdEstCivil VARCHAR(4),
NumPerCargo INT DEFAULT ((0)) NOT NULL,
NivelEduc VARCHAR(4),
TipoVivienda VARCHAR(10),
EstratoSocial INT DEFAULT ((0)) NOT NULL,
IdOcupac VARCHAR(4),
VrPension MONEY DEFAULT ((0)) NOT NULL,
VrOtrosDev MONEY DEFAULT ((0)) NOT NULL,
VrPasivo MONEY DEFAULT ((0)) NOT NULL,
VrPatrimonio MONEY DEFAULT ((0)) NOT NULL,
EmpresaLab VARCHAR(150),
FecIngLab SMALLDATETIME,
TelEmpresa VARCHAR(20),
DirEmpresa VARCHAR(250),
EmailEmpresa VARCHAR(100),
BaseAportes MONEY DEFAULT ((0)) NOT NULL,
CdTarifApo VARCHAR(4),
VrAportes MONEY DEFAULT ((0)) NOT NULL,
FecInicioApo SMALLDATETIME,
FecFinalApo SMALLDATETIME,
DiaCausacApo VARCHAR(150),
FecRetiroApo SMALLDATETIME,
CausalRetiro VARCHAR(250),
SinDctoNom BIT DEFAULT ((0)) NOT NULL,
SinLiqAporte BIT DEFAULT ((0)) NOT NULL,
CabFamilia BIT DEFAULT ((0)) NOT NULL,
DebitoAuto VARCHAR(20) DEFAULT ('N')
 CONSTRAINT PK_TercCliePrestamo PRIMARY KEY CLUSTERED (IdClie,IdAgencia),
 CONSTRAINT CK_TercCliePrestamoIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdLocalAge CHECK ((len([IdLocalAge]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdSzona CHECK ((len([IdSzona]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdTipoTerc CHECK ((len([IdTipoTerc]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TercCliePrestamoIdVend CHECK ((len([IdVend]) > 0)))
CREATE TABLE TercClieRef ( 
IdClie VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoRef VARCHAR(10) NOT NULL,
Referencia VARCHAR(150) NOT NULL,
NitRefncia VARCHAR(16),
DirRefncia VARCHAR(150),
TelRefncia VARCHAR(30) NOT NULL,
emlRefncia VARCHAR(100),
CargRefncia VARCHAR(50),
NumCuenta VARCHAR(30),
Observcion VARCHAR(250)
 CONSTRAINT PK_TercClieRef PRIMARY KEY CLUSTERED (IdClie,Item),
 CONSTRAINT CK_TercClieRefIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TercClieRefReferencia CHECK ((len([Referencia]) > 0)),
 CONSTRAINT CK_TercClieRefTelRefncia CHECK ((len([TelRefncia]) > 0)),
 CONSTRAINT CK_TercClieRefTipoRef CHECK ((len([TipoRef])>(0))))
CREATE TABLE TercClieSalarios ( 
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
VrSalario MONEY DEFAULT (0) NOT NULL,
TarifDcto DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TercClieSalarios PRIMARY KEY CLUSTERED (IdClie,IdAgencia,nMes,nAnno),
 CONSTRAINT CK_TercClieSalariosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_TercClieSalariosIdClie CHECK ((len([IdClie]) > 0)))
CREATE TABLE TercClieSaldos ( 
IdClie VARCHAR(16) NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCia CHAR(2) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_TercClieSaldos PRIMARY KEY CLUSTERED (IdClie,CdAgencia,IdCia),
 CONSTRAINT CK_TercClieSaldosCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_TercClieSaldosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_TercClieSaldosIdClie CHECK ((len([IdClie]) > 0)))
CREATE TABLE TercClieVeh ( 
IdClie VARCHAR(16) NOT NULL,
pVehiculo VARCHAR(10) NOT NULL,
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
NumVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
Descripcion VARCHAR(100)
 CONSTRAINT PK_TercClieVeh PRIMARY KEY CLUSTERED (IdClie,pVehiculo),
 CONSTRAINT CK_TercClieVehCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_TercClieVehIdClie CHECK ((len([IdClie]) > 0)),
 CONSTRAINT CK_TercClieVehNumVehiculo CHECK ((len([NumVehiculo]) > 0)),
 CONSTRAINT CK_TercClieVehpVehiculo CHECK ((len([pVehiculo]) > 0)))
CREATE TABLE TercCndCapac ( 
IdConductor VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME,
Habilitado BIT DEFAULT ((1)) NOT NULL
 CONSTRAINT PK_TercCndCapac PRIMARY KEY CLUSTERED (IdConductor,Item),
 CONSTRAINT CK_TercCndCapacIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_TercCndCapacIdConductor CHECK ((len([IdConductor])>(0))))
CREATE TABLE TercCndContrato ( 
NumContrato INT DEFAULT (0) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdTipCon VARCHAR(4) NOT NULL,
IdModd VARCHAR(4) NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
FecRetiro SMALLDATETIME,
FecVigencia SMALLDATETIME,
Observaciones VARCHAR(250),
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_TercCndContrato PRIMARY KEY CLUSTERED (NumContrato),
 CONSTRAINT CK_TercCndContratoIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_TercCndContratoIdModd CHECK ((len([IdModd]) > 0)),
 CONSTRAINT CK_TercCndContratoIdTipCon CHECK ((len([IdTipCon]) > 0)),
 CONSTRAINT CK_TercCndContratoIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE TercCndDoc ( 
IdConductor VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdDoc VARCHAR(4) NOT NULL,
Fecha SMALLDATETIME,
FecVence SMALLDATETIME,
Radicado BIT DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(250)
 CONSTRAINT PK_TercCndDoc PRIMARY KEY CLUSTERED (IdConductor,Item),
 CONSTRAINT CK_TercCndDocIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_TercCndDocIdDoc CHECK ((len([IdDoc])>(0))))
CREATE TABLE TercCndReferencias ( 
IdConductor VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoRef VARCHAR(10) NOT NULL,
EmpresaRef VARCHAR(150) NOT NULL,
NitRef VARCHAR(16),
DireccionRef VARCHAR(150),
TelefonoRef VARCHAR(30) NOT NULL,
ContactoRef VARCHAR(150),
EmailRef VARCHAR(100),
CargoRef VARCHAR(50),
CuentaBanco VARCHAR(30),
FechaInicial SMALLDATETIME,
FechaFinal SMALLDATETIME,
Verificado VARCHAR(150),
ObservRef VARCHAR(250)
 CONSTRAINT PK_TercCndReferencias PRIMARY KEY CLUSTERED (IdConductor,Item),
 CONSTRAINT CK_TercCndReferenciasEmpresaRef CHECK ((len([EmpresaRef]) > 0)),
 CONSTRAINT CK_TercCndReferenciasIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_TercCndReferenciasTelefonoRef CHECK ((len([TelefonoRef]) > 0)),
 CONSTRAINT CK_TercCndReferenciasTipoRef CHECK ((len([TipoRef]) > 0)))
CREATE TABLE TercCndTarjetas ( 
IdConductor VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
NumeroTarj VARCHAR(30) NOT NULL,
Secuencia INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME
 CONSTRAINT PK_TercCndTarjetas PRIMARY KEY CLUSTERED (IdConductor,Item),
 CONSTRAINT CK_TercCndTarjetasIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_TercCndTarjetasNumeroTarj CHECK ((len([NumeroTarj]) > 0)))
CREATE TABLE TercCndtores ( 
IdConductor VARCHAR(16) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdModd VARCHAR(4) NOT NULL,
TipoSangre CHAR(2) DEFAULT ('A') NOT NULL,
FactorRh CHAR(1) DEFAULT ('+') NOT NULL,
FecNacmto SMALLDATETIME NOT NULL,
LugarNacmto VARCHAR(30),
Sexo CHAR(1) DEFAULT ('M') NOT NULL,
IdEstCivil VARCHAR(4) NOT NULL,
NHijos INT DEFAULT (0) NOT NULL,
LibMilitar VARCHAR(25),
ClaseLib INT DEFAULT (0) NOT NULL,
FechaLib SMALLDATETIME,
DistMil VARCHAR(10),
CertJudicial VARCHAR(25),
FecJudicial SMALLDATETIME,
VigJudicial SMALLDATETIME,
Pasporte VARCHAR(25),
VigPaspte SMALLDATETIME,
Licencia VARCHAR(25) NOT NULL,
IdLugar VARCHAR(8) NOT NULL,
CatLicencia INT DEFAULT (0) NOT NULL,
FecLicencia SMALLDATETIME NOT NULL,
VigLicencia SMALLDATETIME NOT NULL,
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
CdLocCue VARCHAR(8),
CdFonPen VARCHAR(8),
CdFonEps VARCHAR(8),
CdFonArp VARCHAR(8),
pVehiculo VARCHAR(10),
PathFoto VARCHAR(30),
PathFirma VARCHAR(30),
PathLic VARCHAR(30),
Cmntarios VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
NumTarjeta VARCHAR(30),
EdicTarjeta INT DEFAULT (0) NOT NULL,
FecTarjeta SMALLDATETIME,
VigTarjeta SMALLDATETIME,
PasSeguridad VARCHAR(30),
FecPasSeg SMALLDATETIME,
VigPasSeg SMALLDATETIME,
NitEmpTrans VARCHAR(16),
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
Num_Contrato INT DEFAULT (0) NOT NULL,
Contrato_Activo BIT DEFAULT (0) NOT NULL,
CdTipCon VARCHAR(4),
Fec_Ingreso SMALLDATETIME,
Fec_Retiro SMALLDATETIME,
Fec_Vigencia SMALLDATETIME,
Fec_IngresoAnt SMALLDATETIME,
Fec_UltimoAcc SMALLDATETIME,
PasadoJudicial VARCHAR(250),
Restriccion VARCHAR(50),
FecPagoPen SMALLDATETIME,
FecPagoEps SMALLDATETIME,
FecPagoArp SMALLDATETIME,
CdTipoOper VARCHAR(4)
 CONSTRAINT PK_TercCndtores PRIMARY KEY CLUSTERED (IdConductor),
 CONSTRAINT CK_TercCndtoresCatLicencia CHECK (([CatLicencia] >= 0 and [CatLicencia] <= 12)),
 CONSTRAINT CK_TercCndtoresClaseLib CHECK (([ClaseLib] >= 0 and [ClaseLib] <= 2)),
 CONSTRAINT CK_TercCndtoresFactorRh CHECK (([FactorRh] = '+' or [FactorRh] = '-')),
 CONSTRAINT CK_TercCndtoresIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_TercCndtoresIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_TercCndtoresIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_TercCndtoresIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_TercCndtoresIdEstCivil CHECK ((len([IdEstCivil]) > 0)),
 CONSTRAINT CK_TercCndtoresIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_TercCndtoresIdLugar CHECK ((len([IdLugar]) > 0)),
 CONSTRAINT CK_TercCndtoresIdModd CHECK ((len([IdModd]) > 0)),
 CONSTRAINT CK_TercCndtoresIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TercCndtoresLicencia CHECK ((len([Licencia]) > 0)),
 CONSTRAINT CK_TercCndtoresSexo CHECK (([Sexo] = 'O' or ([Sexo] = 'F' or [Sexo] = 'M'))),
 CONSTRAINT CK_TercCndtoresTipoSangre CHECK (([TipoSangre] = 'AB' or ([TipoSangre] = 'B' or ([TipoSangre] = 'O' or [TipoSangre] = 'A')))))
CREATE TABLE TercCuentas ( 
IdTercero VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
CdLugarCue VARCHAR(8),
NitTercAut VARCHAR(16),
TarjetaDb BIT DEFAULT ((0)) NOT NULL,
NumTarjetaDb VARCHAR(50)
 CONSTRAINT PK_TercCuentas PRIMARY KEY CLUSTERED (IdTercero,Item),
 CONSTRAINT CK_TercCuentasIdBanco CHECK ((len([IdBanco])>(0))),
 CONSTRAINT CK_TercCuentasIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_TercCuentasIdTercero CHECK ((len([IdTercero])>(0))))
CREATE TABLE TercDactilar ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
ImagenBin IMAGE
 CONSTRAINT PK_TercDactilar PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_TercDactilarIdTercero CHECK ((len([IdTercero])>(0))))
CREATE TABLE Terceros ( 
IdTercero VARCHAR(16) NOT NULL,
RazonSocial VARCHAR(250) NOT NULL,
Codigo VARCHAR(16) NOT NULL,
TipoId CHAR(1) DEFAULT ('N') NOT NULL,
Dv CHAR(1) DEFAULT ('0'),
NomCial VARCHAR(250),
SiglaRaz VARCHAR(50),
Direccion VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Telefono VARCHAR(20) NOT NULL,
Fax VARCHAR(20),
TelMovil VARCHAR(20),
SitioWeb VARCHAR(100),
e_mail VARCHAR(100),
EsCliente BIT DEFAULT (0) NOT NULL,
EsVendedor BIT DEFAULT (0) NOT NULL,
EsConductor BIT DEFAULT (0) NOT NULL,
EsPropietario BIT DEFAULT (0) NOT NULL,
EsProveedor BIT DEFAULT (0) NOT NULL,
EsEmpleado BIT DEFAULT (0) NOT NULL,
EsOperario BIT DEFAULT (0) NOT NULL,
EsAccnista BIT DEFAULT (0) NOT NULL,
EsCiaAseg BIT DEFAULT (0) NOT NULL,
EsCliePres BIT DEFAULT (0) NOT NULL,
IdSector VARCHAR(8) NOT NULL,
IdProf VARCHAR(4) NOT NULL,
IdRegimen VARCHAR(4) NOT NULL,
TipEnte CHAR(1) DEFAULT ('J') NOT NULL,
IdLugarCed VARCHAR(8) NOT NULL,
FecExpCed SMALLDATETIME,
Observacion VARCHAR(250),
IniStgNom INT DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
ImgFoto VARCHAR(30),
ImgFirma VARCHAR(30),
ImagenDoc1 VARCHAR(50),
ImagenDoc2 VARCHAR(50),
ImagenDoc3 VARCHAR(50),
FechaNac SMALLDATETIME,
IdEstOper VARCHAR(4),
IdLocUbic VARCHAR(8),
DescUbicac VARCHAR(150),
CdGrupoTerc VARCHAR(4),
RegimenFE BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Terceros PRIMARY KEY CLUSTERED (IdTercero),
 CONSTRAINT IX_TercerosCodigo UNIQUE NONCLUSTERED (Codigo),
 CONSTRAINT CK_TercerosCodigo CHECK ((len([Codigo]) > 0)),
 CONSTRAINT CK_TercerosDireccion CHECK ((len([Direccion]) > 0)),
 CONSTRAINT CK_TercerosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_TercerosIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_TercerosIdLugarCed CHECK ((len([IdLugarCed]) > 0)),
 CONSTRAINT CK_TercerosIdProf CHECK ((len([IdProf]) > 0)),
 CONSTRAINT CK_TercerosIdRegimen CHECK ((len([IdRegimen]) > 0)),
 CONSTRAINT CK_TercerosIdSector CHECK ((len([IdSector]) > 0)),
 CONSTRAINT CK_TercerosIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_TercerosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TercerosRazonSocial CHECK ((len([RazonSocial]) > 0)),
 CONSTRAINT CK_TercerosTelefono CHECK ((len([Telefono]) > 0)),
 CONSTRAINT CK_TercerosTipEnte CHECK (([TipEnte] = 'N' or [TipEnte] = 'J')),
 CONSTRAINT CK_TercerosTipoId CHECK (([TipoId]='D' OR [TipoId]='N' OR [TipoId]='X' OR [TipoId]='C' OR [TipoId]='E' OR [TipoId]='O' OR [TipoId]='U' OR [TipoId]='T' OR [TipoId]='R' OR [TipoId]='P')))
CREATE TABLE TercOperarios ( 
IdOperario VARCHAR(16) NOT NULL,
IdTipoOper VARCHAR(4) NOT NULL,
TipoSalario VARCHAR(10) DEFAULT ('NOMINA') NOT NULL,
VrSalario DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercOperarios PRIMARY KEY CLUSTERED (IdOperario),
 CONSTRAINT CK_TercOperariosIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_TercOperariosIdTipoOper CHECK ((len([IdTipoOper])>(0))),
 CONSTRAINT CK_TercOperariosTipoSalario CHECK ((len([TipoSalario])>(0))))
CREATE TABLE TercPropietario ( 
IdPropietario VARCHAR(16) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
CupoCredito MONEY DEFAULT (0) NOT NULL,
SaldoActual MONEY DEFAULT (0) NOT NULL,
Avala BIT DEFAULT (0) NOT NULL,
IdAdmon VARCHAR(4) NOT NULL,
IdTipCon VARCHAR(4) NOT NULL,
ContratoActivo BIT DEFAULT (0) NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
FecRetiro SMALLDATETIME,
FecVigencia SMALLDATETIME,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_TercPropietario PRIMARY KEY CLUSTERED (IdPropietario),
 CONSTRAINT CK_TercPropietarioIdAdmon CHECK ((len([IdAdmon]) > 0)),
 CONSTRAINT CK_TercPropietarioIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_TercPropietarioIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_TercPropietarioIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_TercPropietarioIdTipCon CHECK ((len([IdTipCon]) > 0)),
 CONSTRAINT CK_TercPropietarioIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE TercProvee ( 
IdProv VARCHAR(16) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
NitRepLeg VARCHAR(16),
NomRepLeg VARCHAR(150),
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargContac VARCHAR(50),
DirOrdComp VARCHAR(250),
IdLocOrd VARCHAR(8) NOT NULL,
DiasEntga INT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
IdForma VARCHAR(4) NOT NULL,
CdMney VARCHAR(5),
CdDct VARCHAR(4),
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
Autoret BIT DEFAULT (0) NOT NULL,
IncRet BIT DEFAULT (0) NOT NULL,
IncRiv BIT DEFAULT (0) NOT NULL,
IncIca BIT DEFAULT (0) NOT NULL,
LiqFletes BIT DEFAULT (0) NOT NULL,
CdRet VARCHAR(4),
CdRiv VARCHAR(4),
GartProd INT DEFAULT (0) NOT NULL,
Contrato BIT DEFAULT (0) NOT NULL,
NContrato VARCHAR(20),
FecIngreso SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME,
FecRetiro SMALLDATETIME,
PathFoto VARCHAR(30),
PathFirma VARCHAR(30),
Cmntarios VARCHAR(250),
ObsFinanc VARCHAR(250),
ObsJuridica VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CodRetCom VARCHAR(4),
CupoElectcom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
AutoIca BIT DEFAULT ((0)) NOT NULL,
CodRetIca VARCHAR(4)
 CONSTRAINT PK_TercProvee PRIMARY KEY CLUSTERED (IdProv),
 CONSTRAINT CK_TercProveeIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_TercProveeIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_TercProveeIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_TercProveeIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_TercProveeIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_TercProveeIdLocOrd CHECK ((len([IdLocOrd]) > 0)),
 CONSTRAINT CK_TercProveeIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_TercProveeIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_TercProveeIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE TercRespFiscal ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdResFis VARCHAR(10) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercRespFiscal PRIMARY KEY CLUSTERED (Id))
CREATE TABLE TercSedes ( 
IdTercero VARCHAR(16) NOT NULL,
IdSede VARCHAR(10) NOT NULL,
NomSede VARCHAR(50) NOT NULL,
Principal BIT DEFAULT ((0)) NOT NULL,
IdLocSede VARCHAR(8),
DirSede VARCHAR(250),
TelSede VARCHAR(20),
CoordLat DECIMAL(16,10) DEFAULT ((0)) NOT NULL,
CoordLong DECIMAL(16,10) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TercSedes PRIMARY KEY CLUSTERED (IdTercero,IdSede),
 CONSTRAINT CK_TercSedesIdSede CHECK ((len([IdSede])>(0))),
 CONSTRAINT CK_TercSedesIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_TercSedesNomSede CHECK ((len([NomSede])>(0))))
CREATE TABLE TercVendedor ( 
IdVend VARCHAR(16) NOT NULL,
IdTarCms VARCHAR(4) NOT NULL,
IdTarCm2 VARCHAR(4) NOT NULL,
CdJorn VARCHAR(4),
IdSzona VARCHAR(4) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
PathFoto VARCHAR(30),
PathFirma VARCHAR(30),
Comntarios VARCHAR(250),
Inactivo BIT DEFAULT (0) NOT NULL,
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_TercVendedor PRIMARY KEY CLUSTERED (IdVend),
 CONSTRAINT CK_TercVendedorIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_TercVendedorIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_TercVendedorIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_TercVendedorIdSzona CHECK ((len([IdSzona]) > 0)),
 CONSTRAINT CK_TercVendedorIdTarCm2 CHECK ((len([IdTarCm2]) > 0)),
 CONSTRAINT CK_TercVendedorIdTarCms CHECK ((len([IdTarCms]) > 0)),
 CONSTRAINT CK_TercVendedorIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TercVendedorIdVend CHECK ((len([IdVend]) > 0)))
CREATE TABLE Terminales ( 
IdTerminal VARCHAR(4) NOT NULL,
Terminal VARCHAR(50) NOT NULL,
IdCia CHAR(2) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Terminales PRIMARY KEY CLUSTERED (IdTerminal),
 CONSTRAINT CK_TerminalesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_TerminalesIdTerminal CHECK ((len([IdTerminal]) > 0)),
 CONSTRAINT CK_TerminalesTerminal CHECK ((len([Terminal]) > 0)))
CREATE TABLE TiposAdm ( 
IdAdmon VARCHAR(4) NOT NULL,
TipoAdmon VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposAdm PRIMARY KEY CLUSTERED (IdAdmon),
 CONSTRAINT CK_TiposAdmIdAdmon CHECK ((len([IdAdmon]) > 0)),
 CONSTRAINT CK_TiposAdmTipoAdmon CHECK ((len([TipoAdmon]) > 0)))
CREATE TABLE TiposAgenc ( 
IdTipAgenc VARCHAR(4) NOT NULL,
TipoAgencia VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposAgenc PRIMARY KEY CLUSTERED (IdTipAgenc),
 CONSTRAINT CK_TiposAgencIdTipAgenc CHECK ((len([IdTipAgenc]) > 0)),
 CONSTRAINT CK_TiposAgencTipoAgencia CHECK ((len([TipoAgencia]) > 0)))
CREATE TABLE TiposBan ( 
IdBandera VARCHAR(4) NOT NULL,
TipoBandera VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposBan PRIMARY KEY CLUSTERED (IdBandera),
 CONSTRAINT CK_TiposBanIdBandera CHECK ((len([IdBandera]) > 0)),
 CONSTRAINT CK_TiposBanTipoBandera CHECK ((len([TipoBandera]) > 0)))
CREATE TABLE TiposBloq ( 
IdTipBloq VARCHAR(4) NOT NULL,
TipoBloqueo VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposBloq PRIMARY KEY CLUSTERED (IdTipBloq),
 CONSTRAINT CK_TiposBloqIdTipBloq CHECK ((len([IdTipBloq]) > 0)),
 CONSTRAINT CK_TiposBloqTipoBloqueo CHECK ((len([TipoBloqueo]) > 0)))
CREATE TABLE TiposCar ( 
IdCrceria VARCHAR(4) NOT NULL,
TipoCar VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposCar PRIMARY KEY CLUSTERED (IdCrceria),
 CONSTRAINT CK_TiposCarIdCrceria CHECK ((len([IdCrceria]) > 0)),
 CONSTRAINT CK_TiposCarTipoCar CHECK ((len([TipoCar]) > 0)))
CREATE TABLE TiposCarga ( 
IdTipCarga VARCHAR(4) NOT NULL,
TipoCarga VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposCarga PRIMARY KEY CLUSTERED (IdTipCarga),
 CONSTRAINT CK_TiposCargaIdTipCarga CHECK ((len([IdTipCarga]) > 0)),
 CONSTRAINT CK_TiposCargaTipoCarga CHECK ((len([TipoCarga]) > 0)))
CREATE TABLE TiposCatLic ( 
IdCateg INT DEFAULT ((0)) NOT NULL,
CategMT VARCHAR(50) NOT NULL
 CONSTRAINT PK_TiposCatLic PRIMARY KEY CLUSTERED (IdCateg),
 CONSTRAINT CK_TiposCatLicCategMT CHECK ((len([CategMT])>(0))))
CREATE TABLE TiposCnd ( 
IdTipoCon VARCHAR(4) NOT NULL,
TipoContndor VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposCnd PRIMARY KEY CLUSTERED (IdTipoCon),
 CONSTRAINT CK_TiposCndIdTipoCon CHECK ((len([IdTipoCon]) > 0)),
 CONSTRAINT CK_TiposCndTipoContndor CHECK ((len([TipoContndor]) > 0)))
CREATE TABLE TiposCol ( 
IdColor VARCHAR(4) NOT NULL,
NomColor VARCHAR(50) NOT NULL,
NColor INT DEFAULT ((0)) NOT NULL,
CodigoMT VARCHAR(10),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposCol PRIMARY KEY CLUSTERED (IdColor),
 CONSTRAINT CK_TiposColIdColor CHECK ((len([IdColor])>(0))),
 CONSTRAINT CK_TiposColNomColor CHECK ((len([NomColor])>(0))))
CREATE TABLE TiposCom ( 
IdCom VARCHAR(3) NOT NULL,
TipoCom VARCHAR(50) NOT NULL,
IdDiario VARCHAR(4) NOT NULL,
EsEgreso BIT DEFAULT (0) NOT NULL,
ConsUnico BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
ClaseNiif VARCHAR(10) DEFAULT ('CONTAB'),
Doc_Soporte BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposCom PRIMARY KEY CLUSTERED (IdCom),
 CONSTRAINT CK_TiposComIdCom CHECK ((len([IdCom]) > 0)),
 CONSTRAINT CK_TiposComIdDiario CHECK ((len([IdDiario]) > 0)),
 CONSTRAINT CK_TiposComTipoCom CHECK ((len([TipoCom]) > 0)))
CREATE TABLE TiposComAgenc ( 
IdSubAgenc VARCHAR(4) NOT NULL,
SubTipoAgenc VARCHAR(50) NOT NULL,
IdTipAgenc VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposComAgenc PRIMARY KEY CLUSTERED (IdSubAgenc),
 CONSTRAINT CK_TiposComAgencIdSubAgenc CHECK ((len([IdSubAgenc]) > 0)),
 CONSTRAINT CK_TiposComAgencIdTipAgenc CHECK ((len([IdTipAgenc]) > 0)),
 CONSTRAINT CK_TiposComAgencSubTipoAgenc CHECK ((len([SubTipoAgenc]) > 0)))
CREATE TABLE TiposComCons ( 
IdCom VARCHAR(3) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
LDesde INT DEFAULT (0) NOT NULL,
LHasta INT DEFAULT (0) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
NumManual BIT DEFAULT (0) NOT NULL,
Formato VARCHAR(20),
ConfigFecha VARCHAR(10),
TipoPapel INT DEFAULT (1) NOT NULL,
Orientacion INT DEFAULT (1) NOT NULL,
VistaPrevia BIT DEFAULT (0) NOT NULL,
VerSetup BIT DEFAULT (0) NOT NULL,
NumCopias INT DEFAULT (1) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
CodResol VARCHAR(4)
 CONSTRAINT PK_TiposComCons PRIMARY KEY CLUSTERED (IdCom,IdCia),
 CONSTRAINT CK_TiposComConsIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_TiposComConsIdCom CHECK ((len([IdCom]) > 0)),
 CONSTRAINT CK_TiposComConsNumCopias CHECK (([NumCopias] >= 0 and [NumCopias] <= 99)),
 CONSTRAINT CK_TiposComConsOrientacion CHECK (([Orientacion] >= 0 and [Orientacion] <= 2)))
CREATE TABLE TiposComFmt ( 
IdCom VARCHAR(3) NOT NULL,
IdForma CHAR(2) NOT NULL,
Descripcion VARCHAR(100) NOT NULL,
Formato VARCHAR(20) NOT NULL,
Predtmnado BIT DEFAULT ((0)) NOT NULL,
TipoPapel INT DEFAULT ((1)) NOT NULL,
Orientacion INT DEFAULT ((1)) NOT NULL,
VistaPrevia BIT DEFAULT ((0)) NOT NULL,
VerSetup BIT DEFAULT ((0)) NOT NULL,
NumCopias INT DEFAULT ((1)) NOT NULL,
sp_Nombre VARCHAR(50),
Ind_Location VARCHAR(50)
 CONSTRAINT PK_TiposComFmt PRIMARY KEY CLUSTERED (IdCom,IdForma),
 CONSTRAINT CK_TiposComFmtDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_TiposComFmtFormato CHECK ((len([Formato])>(0))),
 CONSTRAINT CK_TiposComFmtIdCom CHECK ((len([IdCom])>(0))),
 CONSTRAINT CK_TiposComFmtIdForma CHECK ((len([IdForma])>(0))))
CREATE TABLE TiposComNiif ( 
IdCom VARCHAR(3) NOT NULL,
IdCia CHAR(2) NOT NULL,
TipoNiif VARCHAR(10) NOT NULL,
CdTipCom VARCHAR(3) NOT NULL
 CONSTRAINT PK_TiposComNiif PRIMARY KEY CLUSTERED (IdCom,IdCia,TipoNiif),
 CONSTRAINT CK_TiposComNiifCdTipCom CHECK ((len([CdTipCom])>(0))),
 CONSTRAINT CK_TiposComNiifIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_TiposComNiifIdCom CHECK ((len([IdCom])>(0))),
 CONSTRAINT CK_TiposComNiifTipoNiif CHECK ((len([TipoNiif])>(0))))
CREATE TABLE TiposComRes ( 
IdRes VARCHAR(4) NOT NULL,
Resolucion VARCHAR(50) NOT NULL,
Prefijo VARCHAR(5),
NumInicial INT DEFAULT ((0)) NOT NULL,
NumFinal INT DEFAULT ((0)) NOT NULL,
FechaExpRes SMALLDATETIME NOT NULL,
FechaVigencia SMALLDATETIME,
Establecimiento VARCHAR(100)
 CONSTRAINT PK_TiposComRes PRIMARY KEY CLUSTERED (IdRes),
 CONSTRAINT CK_TiposComResIdRes CHECK ((len([IdRes])>(0))),
 CONSTRAINT CK_TiposComResResolucion CHECK ((len([Resolucion])>(0))))
CREATE TABLE TiposCon ( 
IdTipCon VARCHAR(4) NOT NULL,
TipoContrato VARCHAR(100) NOT NULL,
Duracion INT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
VincLabUgpp VARCHAR(250),
CodDIAN VARCHAR(3)
 CONSTRAINT PK_TiposCon PRIMARY KEY CLUSTERED (IdTipCon),
 CONSTRAINT CK_TiposConIdTipCon CHECK ((len([IdTipCon]) > 0)),
 CONSTRAINT CK_TiposConTipoContrato CHECK ((len([TipoContrato]) > 0)))
CREATE TABLE TiposCot ( 
IdCot VARCHAR(4) NOT NULL,
Cotizante VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposCot PRIMARY KEY CLUSTERED (IdCot),
 CONSTRAINT CK_TiposCotCotizante CHECK ((len([Cotizante]) > 0)),
 CONSTRAINT CK_TiposCotIdCot CHECK ((len([IdCot]) > 0)))
CREATE TABLE TiposDocCons ( 
IdDoc VARCHAR(3) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
LDesde INT DEFAULT (0) NOT NULL,
LHasta INT DEFAULT (0) NOT NULL,
Resolucion VARCHAR(30),
RangoNum VARCHAR(50),
FechaRes SMALLDATETIME,
Prefijo VARCHAR(5),
Numero INT DEFAULT (0) NOT NULL,
NumManual BIT DEFAULT (0) NOT NULL,
IntLotes BIT DEFAULT (0) NOT NULL,
ConfigFecha VARCHAR(10),
Formato VARCHAR(20),
TipoPapel INT DEFAULT (1) NOT NULL,
Orientacion INT DEFAULT (1) NOT NULL,
VistaPrevia BIT DEFAULT (0) NOT NULL,
VerSetup BIT DEFAULT (0) NOT NULL,
NumCopias INT DEFAULT (1) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
FechaVigRes SMALLDATETIME,
ClaveTecDian VARCHAR(250),
CodResol VARCHAR(4)
 CONSTRAINT PK_TiposDocCons PRIMARY KEY CLUSTERED (IdDoc,IdCia),
 CONSTRAINT CK_TiposDocConsIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_TiposDocConsIdDoc CHECK ((len([IdDoc]) > 0)),
 CONSTRAINT CK_TiposDocConsNumCopias CHECK (([NumCopias] >= 0 and [NumCopias] <= 99)),
 CONSTRAINT CK_TiposDocConsOrientacion CHECK (([Orientacion] >= 0 and [Orientacion] <= 2)))
CREATE TABLE TiposEnt ( 
IdEnt VARCHAR(4) NOT NULL,
DiaEntrega VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposEnt PRIMARY KEY CLUSTERED (IdEnt),
 CONSTRAINT CK_TiposEntDiaEntrega CHECK ((len([DiaEntrega])>(0))),
 CONSTRAINT CK_TiposEntIdEnt CHECK ((len([IdEnt])>(0))))
CREATE TABLE TiposEsc ( 
IdTipoEsc VARCHAR(4) NOT NULL,
TipoEscolta VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposEsc PRIMARY KEY CLUSTERED (IdTipoEsc),
 CONSTRAINT CK_TiposEscIdTipoEsc CHECK ((len([IdTipoEsc]) > 0)),
 CONSTRAINT CK_TiposEscTipoEscolta CHECK ((len([TipoEscolta]) > 0)))
CREATE TABLE TiposFil ( 
IdFiltro VARCHAR(4) NOT NULL,
TipoFiltro VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposFil PRIMARY KEY CLUSTERED (IdFiltro),
 CONSTRAINT CK_TiposFilIdFiltro CHECK ((len([IdFiltro]) > 0)),
 CONSTRAINT CK_TiposFilTipoFiltro CHECK ((len([TipoFiltro]) > 0)))
CREATE TABLE TiposFuel ( 
IdCom VARCHAR(4) NOT NULL,
TipoComb VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposFuel PRIMARY KEY CLUSTERED (IdCom),
 CONSTRAINT CK_TiposFuelIdCom CHECK ((len([IdCom]) > 0)),
 CONSTRAINT CK_TiposFuelTipoComb CHECK ((len([TipoComb]) > 0)))
CREATE TABLE TiposInm ( 
IdTipoInm VARCHAR(4) NOT NULL,
TipoInmueble VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposInm PRIMARY KEY CLUSTERED (IdTipoInm),
 CONSTRAINT CK_TiposInmIdTipoInm CHECK ((len([IdTipoInm])>(0))),
 CONSTRAINT CK_TiposInmTipoInmueble CHECK ((len([TipoInmueble])>(0))))
CREATE TABLE TiposLla ( 
IdTlla VARCHAR(4) NOT NULL,
TipoLlanta VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposLla PRIMARY KEY CLUSTERED (IdTlla),
 CONSTRAINT CK_TiposLlaIdTlla CHECK ((len([IdTlla]) > 0)),
 CONSTRAINT CK_TiposLlaTipoLlanta CHECK ((len([TipoLlanta]) > 0)))
CREATE TABLE TiposLub ( 
IdLub VARCHAR(4) NOT NULL,
TipoLub VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposLub PRIMARY KEY CLUSTERED (IdLub),
 CONSTRAINT CK_TiposLubIdLub CHECK ((len([IdLub]) > 0)),
 CONSTRAINT CK_TiposLubTipoLub CHECK ((len([TipoLub]) > 0)))
CREATE TABLE TiposMat ( 
IdMat VARCHAR(4) NOT NULL,
Material VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposMat PRIMARY KEY CLUSTERED (IdMat),
 CONSTRAINT CK_TiposMatIdMat CHECK ((len([IdMat]) > 0)),
 CONSTRAINT CK_TiposMatMaterial CHECK ((len([Material]) > 0)))
CREATE TABLE TiposMcia ( 
IdTmcia VARCHAR(4) NOT NULL,
TipoMcia VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposMcia PRIMARY KEY CLUSTERED (IdTmcia),
 CONSTRAINT CK_TiposMciaIdTmcia CHECK ((len([IdTmcia]) > 0)),
 CONSTRAINT CK_TiposMciaTipoMcia CHECK ((len([TipoMcia]) > 0)))
CREATE TABLE TiposMnjo ( 
IdMnjo VARCHAR(4) NOT NULL,
ManejoMcia VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposMnjo PRIMARY KEY CLUSTERED (IdMnjo),
 CONSTRAINT CK_TiposMnjoIdMnjo CHECK ((len([IdMnjo]) > 0)),
 CONSTRAINT CK_TiposMnjoManejoMcia CHECK ((len([ManejoMcia]) > 0)))
CREATE TABLE TiposMod ( 
IdModd VARCHAR(4) NOT NULL,
Modalidad VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposMod PRIMARY KEY CLUSTERED (IdModd),
 CONSTRAINT CK_TiposModIdModd CHECK ((len([IdModd]) > 0)),
 CONSTRAINT CK_TiposModModalidad CHECK ((len([Modalidad]) > 0)))
CREATE TABLE TiposMot ( 
IdTipoMot VARCHAR(4) NOT NULL,
TipoMotor VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposMot PRIMARY KEY CLUSTERED (IdTipoMot),
 CONSTRAINT CK_TiposMotIdTipoMot CHECK ((len([IdTipoMot]) > 0)),
 CONSTRAINT CK_TiposMotTipoMotor CHECK ((len([TipoMotor]) > 0)))
CREATE TABLE TiposMotdev ( 
IdMotDev VARCHAR(4) NOT NULL,
MotivoDev VARCHAR(150) NOT NULL,
TipoFact VARCHAR(3),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposMotdev PRIMARY KEY CLUSTERED (IdMotDev),
 CONSTRAINT CK_TiposMotdevIdMotDev CHECK ((len([IdMotDev])>(0))),
 CONSTRAINT CK_TiposMotdevMotivoDev CHECK ((len([MotivoDev])>(0))))
CREATE TABLE TiposNat ( 
IdNat VARCHAR(4) NOT NULL,
Natlzaprod VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposNat PRIMARY KEY CLUSTERED (IdNat),
 CONSTRAINT CK_TiposNatIdNat CHECK ((len([IdNat]) > 0)),
 CONSTRAINT CK_TiposNatNatlzaprod CHECK ((len([Natlzaprod]) > 0)))
CREATE TABLE TiposNivs ( 
IdNiv VARCHAR(4) NOT NULL,
NivelServicio VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposNivs PRIMARY KEY CLUSTERED (IdNiv),
 CONSTRAINT CK_TiposNivsIdNiv CHECK ((len([IdNiv]) > 0)),
 CONSTRAINT CK_TiposNivsNivelServicio CHECK ((len([NivelServicio]) > 0)))
CREATE TABLE TiposNom ( 
IdNom VARCHAR(4) NOT NULL,
TipoNomina VARCHAR(50) NOT NULL,
Asistencia BIT DEFAULT (0) NOT NULL,
NoDevenga BIT DEFAULT (0) NOT NULL,
TipoLiquida CHAR(1) DEFAULT ('M') NOT NULL,
FechaActual SMALLDATETIME NOT NULL,
CdCiaInt CHAR(2),
Inactivo BIT DEFAULT (0) NOT NULL,
LiqEspSalud BIT DEFAULT ((0)) NOT NULL,
DctoSalud DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PagoSalud DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NomDiario BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposNom PRIMARY KEY CLUSTERED (IdNom),
 CONSTRAINT CK_TiposNomIdNom CHECK ((len([IdNom]) > 0)),
 CONSTRAINT CK_TiposNomTipoLiquida CHECK (([TipoLiquida] = 'S' or ([TipoLiquida] = 'M' or ([TipoLiquida] = 'Q' or [TipoLiquida] = 'D')))),
 CONSTRAINT CK_TiposNomTipoNomina CHECK ((len([TipoNomina]) > 0)))
CREATE TABLE TiposNov ( 
IdNov VARCHAR(4) NOT NULL,
Novedad VARCHAR(50) NOT NULL,
Admon VARCHAR(3) DEFAULT ('ALL') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposNov PRIMARY KEY CLUSTERED (IdNov),
 CONSTRAINT CK_TiposNovAdmon CHECK (([Admon] = 'ALL' or ([Admon] = 'COM' or ([Admon] = 'RIE' or ([Admon] = 'SAL' or [Admon] = 'PEN'))))),
 CONSTRAINT CK_TiposNovIdNov CHECK ((len([IdNov]) > 0)),
 CONSTRAINT CK_TiposNovNovedad CHECK ((len([Novedad]) > 0)))
CREATE TABLE TiposOperac ( 
IdTipoOper VARCHAR(4) NOT NULL,
TipoOperacion VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
TipoIngreso VARCHAR(10),
TarifaIng DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposOperac PRIMARY KEY CLUSTERED (IdTipoOper),
 CONSTRAINT CK_TiposOperacIdTipoOper CHECK ((len([IdTipoOper])>(0))),
 CONSTRAINT CK_TiposOperacTipoOperacion CHECK ((len([TipoOperacion])>(0))))
CREATE TABLE TiposOperarios ( 
IdOper VARCHAR(4) NOT NULL,
TipoOperario VARCHAR(50) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
GrupoOper VARCHAR(10)
 CONSTRAINT PK_TiposOperarios PRIMARY KEY CLUSTERED (IdOper),
 CONSTRAINT CK_TiposOperariosIdOper CHECK ((len([IdOper])>(0))),
 CONSTRAINT CK_TiposOperariosTipoOperario CHECK ((len([TipoOperario])>(0))))
CREATE TABLE TiposPcnto ( 
IdTipoPre VARCHAR(4) NOT NULL,
Precinto VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposPcnto PRIMARY KEY CLUSTERED (IdTipoPre),
 CONSTRAINT CK_TiposPcntoIdTipoPre CHECK ((len([IdTipoPre]) > 0)),
 CONSTRAINT CK_TiposPcntoPrecinto CHECK ((len([Precinto]) > 0)))
CREATE TABLE TiposPpt ( 
IdPpd VARCHAR(4) NOT NULL,
TipoProp VARCHAR(50) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposPpt PRIMARY KEY CLUSTERED (IdPpd),
 CONSTRAINT CK_TiposPptIdPpd CHECK ((len([IdPpd]) > 0)),
 CONSTRAINT CK_TiposPptTipoProp CHECK ((len([TipoProp]) > 0)))
CREATE TABLE TiposPrend ( 
IdPrend VARCHAR(4) NOT NULL,
TipoPrenda VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposPrend PRIMARY KEY CLUSTERED (IdPrend),
 CONSTRAINT CK_TiposPrendIdPrend CHECK ((len([IdPrend]) > 0)),
 CONSTRAINT CK_TiposPrendTipoPrenda CHECK ((len([TipoPrenda]) > 0)))
CREATE TABLE TiposProceso ( 
IdTipProc VARCHAR(4) NOT NULL,
TipoProceso VARCHAR(150) NOT NULL,
Descripcion VARCHAR(1000),
IndOrden INT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposProceso PRIMARY KEY CLUSTERED (IdTipProc),
 CONSTRAINT CK_TiposProcesoIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_TiposProcesoTipoProceso CHECK ((len([TipoProceso])>(0))))
CREATE TABLE TiposProd ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
TipoProd VARCHAR(50) NOT NULL
 CONSTRAINT PK_TiposProd PRIMARY KEY CLUSTERED (Id),
 CONSTRAINT CK_TiposProdTipoProd CHECK ((len([TipoProd])>(0))))
CREATE TABLE TiposRespFis ( 
IdResFis VARCHAR(10) NOT NULL,
NomResFiscal VARCHAR(250) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposRespFis PRIMARY KEY CLUSTERED (IdResFis),
 CONSTRAINT CK_TiposRespFisNomResFiscal CHECK ((len([NomResFiscal])>(0))))
CREATE TABLE TiposSustento ( 
IdSustento VARCHAR(4) NOT NULL,
Sustento VARCHAR(150) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposSustento PRIMARY KEY CLUSTERED (IdSustento),
 CONSTRAINT CK_TiposSustentoIdSustento CHECK ((len([IdSustento])>(0))),
 CONSTRAINT CK_TiposSustentoSustento CHECK ((len([Sustento])>(0))))
CREATE TABLE TiposTasas ( 
IdTasa VARCHAR(4) NOT NULL,
TipoTasa VARCHAR(50) NOT NULL,
Simbolo VARCHAR(10),
Unidad VARCHAR(50),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposTasas PRIMARY KEY CLUSTERED (IdTasa),
 CONSTRAINT CK_TiposTasasIdTasa CHECK ((len([IdTasa])>(0))),
 CONSTRAINT CK_TiposTasasTipoTasa CHECK ((len([TipoTasa])>(0))))
CREATE TABLE TiposTerc ( 
IdTipoTerc VARCHAR(4) NOT NULL,
TipoTercero VARCHAR(100) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposTerc PRIMARY KEY CLUSTERED (IdTipoTerc),
 CONSTRAINT CK_TiposTercIdTipoTerc CHECK ((len([IdTipoTerc]) > 0)),
 CONSTRAINT CK_TiposTercTipoTercero CHECK ((len([TipoTercero]) > 0)))
CREATE TABLE TiposVeh ( 
IdTipoVeh VARCHAR(4) NOT NULL,
TipoVehiculo VARCHAR(50) NOT NULL,
Configuracion VARCHAR(6),
Ejes INT DEFAULT ((0)) NOT NULL,
Llantas INT DEFAULT ((0)) NOT NULL,
CapacPeso DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
UndCapac VARCHAR(10),
CapacVol DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
UndCapVol VARCHAR(10),
CubAlto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CubLargo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CubAncho DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposVeh PRIMARY KEY CLUSTERED (IdTipoVeh),
 CONSTRAINT CK_TiposVehIdTipoVeh CHECK ((len([IdTipoVeh])>(0))),
 CONSTRAINT CK_TiposVehTipoVehiculo CHECK ((len([TipoVehiculo])>(0))))
CREATE TABLE TiposVehFactor ( 
IdTipoVeh VARCHAR(4) NOT NULL,
nSemana INT DEFAULT (0) NOT NULL,
TarifaFc DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposVehFactor PRIMARY KEY CLUSTERED (IdTipoVeh,nSemana),
 CONSTRAINT CK_TiposVehFactorIdTipoVeh CHECK ((len([IdTipoVeh]) > 0)))
CREATE TABLE TiposVehFletes ( 
Item INT DEFAULT ((0)) NOT NULL,
TipoVehic VARCHAR(50) NOT NULL,
CapacMin DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CapacMax DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_TiposVehFletes PRIMARY KEY CLUSTERED (Item),
 CONSTRAINT CK_TiposVehFletesTipoVehic CHECK ((len([TipoVehic])>(0))))
CREATE TABLE TiposZona ( 
IdTipZona VARCHAR(4) NOT NULL,
TipoZona VARCHAR(50) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TiposZona PRIMARY KEY CLUSTERED (IdTipZona),
 CONSTRAINT CK_TiposZonaIdTipZona CHECK ((len([IdTipZona]) > 0)),
 CONSTRAINT CK_TiposZonaTipoZona CHECK ((len([TipoZona]) > 0)))
CREATE TABLE tm_AfAmt ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdDiferido VARCHAR(30) NOT NULL,
tmCostoIni MONEY DEFAULT (0) NOT NULL,
tmAdiciones MONEY DEFAULT (0) NOT NULL,
tmDisminucion MONEY DEFAULT (0) NOT NULL,
tmAcuAjustes MONEY DEFAULT (0) NOT NULL,
tmAmortizaHis MONEY DEFAULT (0) NOT NULL,
tmAmortizaMes MONEY DEFAULT (0) NOT NULL,
tmAjustesInf MONEY DEFAULT (0) NOT NULL,
tmAjustesAmtza MONEY DEFAULT (0) NOT NULL,
tmAmortizaAcum MONEY DEFAULT (0) NOT NULL,
tmAjuAmtzaAcum MONEY DEFAULT (0) NOT NULL,
tmCorrMonAcum MONEY DEFAULT (0) NOT NULL,
tmBaseCorrMon MONEY DEFAULT (0) NOT NULL,
tmCorrMonDif MONEY DEFAULT (0) NOT NULL,
tmAmtzaHisAcum MONEY DEFAULT (0) NOT NULL,
tmTarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmCdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdDep VARCHAR(4) DEFAULT ('0') NOT NULL,
tmNitRespons VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNumPeriodos INT DEFAULT (0) NOT NULL,
tmFechaIni SMALLDATETIME NOT NULL,
tmEstadoReg INT DEFAULT (0) NOT NULL,
tmObservacion VARCHAR(150),
tmCuota DECIMAL(14,4) DEFAULT (0),
tmGalones DECIMAL(14,4) DEFAULT (0),
tmNitProvee VARCHAR(16),
tmInversion MONEY DEFAULT (0) NOT NULL,
tmCdGrupo VARCHAR(4),
tmTipoContab VARCHAR(10)
 CONSTRAINT PK_tm_AfAmt PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_AfAmttmCdCCosto CHECK ((len([tmCdCCosto]) > 0)),
 CONSTRAINT CK_tm_AfAmttmCdDep CHECK ((len([tmCdDep]) > 0)),
 CONSTRAINT CK_tm_AfAmttmCdSubCos CHECK ((len([tmCdSubCos]) > 0)),
 CONSTRAINT CK_tm_AfAmttmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_AfAmttmIdDiferido CHECK ((len([tmIdDiferido]) > 0)),
 CONSTRAINT CK_tm_AfAmttmNitRespons CHECK ((len([tmNitRespons]) > 0)),
 CONSTRAINT CK_tm_AfAmttmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_AfDep ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdActivo VARCHAR(30) NOT NULL,
tmCostoIni MONEY DEFAULT (0) NOT NULL,
tmMejoras MONEY DEFAULT (0) NOT NULL,
tmDisminucion MONEY DEFAULT (0) NOT NULL,
tmAcuAjustes MONEY DEFAULT (0) NOT NULL,
tmDepreciaHis MONEY DEFAULT (0) NOT NULL,
tmDepreciaMes MONEY DEFAULT (0) NOT NULL,
tmAjustesInf MONEY DEFAULT (0) NOT NULL,
tmAjustesDep MONEY DEFAULT (0) NOT NULL,
tmDepreciaAcum MONEY DEFAULT (0) NOT NULL,
tmAjuDepAcum MONEY DEFAULT (0) NOT NULL,
tmTarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmCdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdInstala VARCHAR(4) DEFAULT ('0') NOT NULL,
tmCdDep VARCHAR(4) DEFAULT ('0') NOT NULL,
tmNitRespons VARCHAR(16) DEFAULT ('0') NOT NULL,
tmVidaUtil INT DEFAULT (0) NOT NULL,
tmMetodo VARCHAR(10) NOT NULL,
tmFechaIni SMALLDATETIME NOT NULL,
tmEstadoReg INT DEFAULT (0) NOT NULL,
tmObservacion VARCHAR(150),
tmCdGrupo VARCHAR(4),
tmSalvamento MONEY DEFAULT ((0)) NOT NULL,
tmTipoContab VARCHAR(10) DEFAULT ('CONTAB'),
tmPartes BIT DEFAULT ((0)),
tmUnidades INT DEFAULT ((0)) NOT NULL,
tmCantidad INT DEFAULT ((0)) NOT NULL,
tmDepMejoras MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_AfDep PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_AfDeptmCdCCosto CHECK ((len([tmCdCCosto]) > 0)),
 CONSTRAINT CK_tm_AfDeptmCdDep CHECK ((len([tmCdDep]) > 0)),
 CONSTRAINT CK_tm_AfDeptmCdInstala CHECK ((len([tmCdInstala]) > 0)),
 CONSTRAINT CK_tm_AfDeptmCdSubCos CHECK ((len([tmCdSubCos]) > 0)),
 CONSTRAINT CK_tm_AfDeptmIdActivo CHECK ((len([tmIdActivo]) > 0)),
 CONSTRAINT CK_tm_AfDeptmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_AfDeptmMetodo CHECK ((len([tmMetodo]) > 0)),
 CONSTRAINT CK_tm_AfDeptmNitRespons CHECK ((len([tmNitRespons]) > 0)),
 CONSTRAINT CK_tm_AfDeptmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_AfDepPartes ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdActivo VARCHAR(30) NOT NULL,
tmIdParte INT DEFAULT ((0)) NOT NULL,
tmCostoIni MONEY DEFAULT ((0)) NOT NULL,
tmMejoras MONEY DEFAULT ((0)) NOT NULL,
tmDisminucion MONEY DEFAULT ((0)) NOT NULL,
tmAcuAjustes MONEY DEFAULT ((0)) NOT NULL,
tmDepreciaHis MONEY DEFAULT ((0)) NOT NULL,
tmDepreciaMes MONEY DEFAULT ((0)) NOT NULL,
tmAjustesInf MONEY DEFAULT ((0)) NOT NULL,
tmAjustesDep MONEY DEFAULT ((0)) NOT NULL,
tmDepreciaAcum MONEY DEFAULT ((0)) NOT NULL,
tmAjuDepAcum MONEY DEFAULT ((0)) NOT NULL,
tmTarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVidaUtil INT DEFAULT ((0)) NOT NULL,
tmMetodo VARCHAR(10) NOT NULL,
tmFechaIni SMALLDATETIME NOT NULL,
tmEstadoReg INT DEFAULT ((0)) NOT NULL,
tmObservacion VARCHAR(150),
tmSalvamento MONEY,
tmUnidades INT DEFAULT ((0)) NOT NULL,
tmCantidad INT DEFAULT ((0)) NOT NULL,
tmDepMejoras MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_AfDepPartes PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_AfDepPartestmIdActivo CHECK ((len([tmIdActivo])>(0))),
 CONSTRAINT CK_tm_AfDepPartestmMetodo CHECK ((len([tmMetodo])>(0))),
 CONSTRAINT CK_tm_AfDepPartestmNumero CHECK ((len([tmNumero])>(0))))
CREATE TABLE tm_AfIngreso ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdActivo VARCHAR(30) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmVrMejoras MONEY DEFAULT (0) NOT NULL,
tmVrDisminucion MONEY DEFAULT (0) NOT NULL,
tmVrAjuInfAcum MONEY DEFAULT (0) NOT NULL,
tmVrDepAcuHis MONEY DEFAULT (0) NOT NULL,
tmVrDepAcuAju MONEY DEFAULT (0) NOT NULL,
tmVrAjuInfDep MONEY DEFAULT (0) NOT NULL,
tmNumMeses INT DEFAULT (0) NOT NULL,
tmVidaUtil INT DEFAULT (0) NOT NULL,
tmBaseDep MONEY DEFAULT (0) NOT NULL,
tmMetodo VARCHAR(10) DEFAULT ('LINEARECTA') NOT NULL,
tmFecUltDep SMALLDATETIME,
tmConcepto VARCHAR(150),
tmUnidades INT DEFAULT ((0)),
tmSalvamento MONEY DEFAULT ((0)),
tmDepPartes BIT DEFAULT ((0)) NOT NULL,
tmNumParte INT DEFAULT ((0)) NOT NULL,
tmCantidad INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_AfIngreso PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_AfIngresotmIdActivo CHECK ((len([tmIdActivo]) > 0)),
 CONSTRAINT CK_tm_AfIngresotmMetodo CHECK ((len([tmMetodo]) > 0)),
 CONSTRAINT CK_tm_AfIngresotmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_AfRetiro ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdActivo VARCHAR(30) NOT NULL,
tmIdCausal VARCHAR(4) NOT NULL,
tmNitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNomTercero VARCHAR(150),
tmCostoIni MONEY DEFAULT (0) NOT NULL,
tmMejoras MONEY DEFAULT (0) NOT NULL,
tmDisminucion MONEY DEFAULT (0) NOT NULL,
tmAcuAjustes MONEY DEFAULT (0) NOT NULL,
tmDepAcum MONEY DEFAULT (0) NOT NULL,
tmAjuDepAcum MONEY DEFAULT (0) NOT NULL,
tmVrIngreso MONEY DEFAULT (0) NOT NULL,
tmFechaRet SMALLDATETIME,
tmIdCueDeb VARCHAR(16),
tmIdCueIng VARCHAR(16),
tmConcepto VARCHAR(250),
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmCdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNitRespons VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNumParte INT DEFAULT ((0))
 CONSTRAINT PK_tm_AfRetiro PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_AfRetirotmCdCCosto CHECK ((len([tmCdCCosto]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmCdSubCos CHECK ((len([tmCdSubCos]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmIdActivo CHECK ((len([tmIdActivo]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmIdCausal CHECK ((len([tmIdCausal]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmNitRespons CHECK ((len([tmNitRespons]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmNitTercero CHECK ((len([tmNitTercero]) > 0)),
 CONSTRAINT CK_tm_AfRetirotmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_AfTraslado ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdActivo VARCHAR(30) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmIdGrupo VARCHAR(4) NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmIdInstala VARCHAR(4) NOT NULL,
tmIdDep VARCHAR(4) NOT NULL,
tmIdRespons VARCHAR(16) NOT NULL,
tmCdCiaDest CHAR(2) DEFAULT ('01') NOT NULL,
tmCdGrupoDest VARCHAR(4) NOT NULL,
tmCdCCostoDest VARCHAR(16) NOT NULL,
tmCdSubCosDest VARCHAR(16) NOT NULL,
tmCdInstalaDest VARCHAR(4) NOT NULL,
tmCdDepDest VARCHAR(4) NOT NULL,
tmCdResponsDest VARCHAR(16) NOT NULL,
tmConcepto VARCHAR(150),
tmUbicacion VARCHAR(100),
tmUbicacionDest VARCHAR(100)
 CONSTRAINT PK_tm_AfTraslado PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_AfTrasladotmCdCCostoDest CHECK ((len([tmCdCCostoDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmCdCiaDest CHECK ((len([tmCdCiaDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmCdDepDest CHECK ((len([tmCdDepDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmCdGrupoDest CHECK ((len([tmCdGrupoDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmCdInstalaDest CHECK ((len([tmCdInstalaDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmCdResponsDest CHECK ((len([tmCdResponsDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmCdSubCosDest CHECK ((len([tmCdSubCosDest]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdActivo CHECK ((len([tmIdActivo]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdDep CHECK ((len([tmIdDep]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdGrupo CHECK ((len([tmIdGrupo]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdInstala CHECK ((len([tmIdInstala]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdRespons CHECK ((len([tmIdRespons]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_AfTrasladotmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_Aportes ( 
tmEst VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmApellido1 VARCHAR(50) NOT NULL,
tmApellido2 VARCHAR(50),
tmNombre1 VARCHAR(50) NOT NULL,
tmNombre2 VARCHAR(50),
tmNContto INT DEFAULT (0) NOT NULL,
tmDiasPen DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmDiasSal DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmDiasRie DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmDiasCom DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmBasePen MONEY DEFAULT (0) NOT NULL,
tmBaseSal MONEY DEFAULT (0) NOT NULL,
tmBaseRie MONEY DEFAULT (0) NOT NULL,
tmBaseCom MONEY DEFAULT (0) NOT NULL,
tmBaseRef MONEY DEFAULT (0) NOT NULL,
tmValorPen MONEY DEFAULT (0) NOT NULL,
tmValorSal MONEY DEFAULT (0) NOT NULL,
tmValorRie MONEY DEFAULT (0) NOT NULL,
tmValorCom MONEY DEFAULT (0) NOT NULL,
tmValorSena MONEY DEFAULT (0) NOT NULL,
tmValorIcbf MONEY DEFAULT (0) NOT NULL,
tmValorFsp MONEY DEFAULT (0) NOT NULL,
tmValorFsu MONEY DEFAULT (0) NOT NULL,
tmValorESAP MONEY DEFAULT (0) NOT NULL,
tmValorMin MONEY DEFAULT (0) NOT NULL,
tmTarfaPen DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaSal DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaRie DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaFsp DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaFsu DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaEsa DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaMin DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaCom DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaIcb DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTarfaSen DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmNovIng INT DEFAULT (0) NOT NULL,
tmNovRet INT DEFAULT (0) NOT NULL,
tmNovTda INT DEFAULT (0) NOT NULL,
tmNovTaa INT DEFAULT (0) NOT NULL,
tmNovTdp INT DEFAULT (0) NOT NULL,
tmNovTap INT DEFAULT (0) NOT NULL,
tmNovVsp INT DEFAULT (0) NOT NULL,
tmNovVte INT DEFAULT (0) NOT NULL,
tmNovVst INT DEFAULT (0) NOT NULL,
tmNovSln INT DEFAULT (0) NOT NULL,
tmNovIge INT DEFAULT (0) NOT NULL,
tmNovLma INT DEFAULT (0) NOT NULL,
tmNovVac INT DEFAULT (0) NOT NULL,
tmNovAvp INT DEFAULT (0) NOT NULL,
tmNovIrp INT DEFAULT (0) NOT NULL,
tmNovVct INT DEFAULT (0) NOT NULL,
tmCodNewEps VARCHAR(8),
tmCodNewPen VARCHAR(8),
tmCodNewRie VARCHAR(8),
tmCodNewIns VARCHAR(4),
tmCodNewTar VARCHAR(4),
tmCodNewGru VARCHAR(4),
tmVrIncap MONEY DEFAULT (0) NOT NULL,
tmVrLicencia MONEY DEFAULT (0) NOT NULL,
tmVrVolAfi MONEY DEFAULT (0) NOT NULL,
tmVrVolApo MONEY DEFAULT (0) NOT NULL,
tmVrNoReten MONEY DEFAULT (0) NOT NULL,
tmVrUpc MONEY DEFAULT (0) NOT NULL,
tmVrIncIrp MONEY DEFAULT (0) NOT NULL,
tmNAutLic VARCHAR(30),
tmNAutInc VARCHAR(30),
tmNAutIrp VARCHAR(30),
tmIdFonPen VARCHAR(8) NOT NULL,
tmIdFonSal VARCHAR(8) NOT NULL,
tmIdFonRie VARCHAR(8) NOT NULL,
tmIdFonCaj VARCHAR(8) NOT NULL,
tmIdInstala VARCHAR(4) NOT NULL,
tmIdDep VARCHAR(4) NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmIdNom VARCHAR(4) NOT NULL,
tmVehiculo VARCHAR(10),
tmVrBasico MONEY DEFAULT (0) NOT NULL,
tmDiasNov DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmCdFonAvp VARCHAR(8),
tmDiasSan DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDiasDnrPen INT DEFAULT ((0)) NOT NULL,
tmDiasDnrSal INT DEFAULT ((0)) NOT NULL,
tmNovDsr INT DEFAULT ((0)) NOT NULL,
tmFecNovIng SMALLDATETIME,
tmFecNovRet SMALLDATETIME,
tmFecNovVsp SMALLDATETIME,
tmFecIniSln SMALLDATETIME,
tmFecFinSln SMALLDATETIME,
tmFecIniIge SMALLDATETIME,
tmFecFinIge SMALLDATETIME,
tmFecIniLma SMALLDATETIME,
tmFecFinLma SMALLDATETIME,
tmFecIniVac SMALLDATETIME,
tmFecFinVac SMALLDATETIME,
tmFecIniVct SMALLDATETIME,
tmFecFinVct SMALLDATETIME,
tmFecIniIrl SMALLDATETIME,
tmFecFinIrl SMALLDATETIME,
tmVrIBCparaf MONEY DEFAULT ((0)) NOT NULL,
tmCantHoras INT DEFAULT ((0)) NOT NULL,
tmTipSalario VARCHAR(10)
 CONSTRAINT PK_tm_Aportes PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_AportestmApellido1 CHECK ((len([tmApellido1]) > 0)),
 CONSTRAINT CK_tm_AportestmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_AportestmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_AportestmIdDep CHECK ((len([tmIdDep]) > 0)),
 CONSTRAINT CK_tm_AportestmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_AportestmIdFonCaj CHECK ((len([tmIdFonCaj]) > 0)),
 CONSTRAINT CK_tm_AportestmIdFonPen CHECK ((len([tmIdFonPen]) > 0)),
 CONSTRAINT CK_tm_AportestmIdFonRie CHECK ((len([tmIdFonRie]) > 0)),
 CONSTRAINT CK_tm_AportestmIdFonSal CHECK ((len([tmIdFonSal]) > 0)),
 CONSTRAINT CK_tm_AportestmIdInstala CHECK ((len([tmIdInstala]) > 0)),
 CONSTRAINT CK_tm_AportestmIdNom CHECK ((len([tmIdNom]) > 0)),
 CONSTRAINT CK_tm_AportestmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_AportestmNombre1 CHECK ((len([tmNombre1]) > 0)))
CREATE TABLE tm_AutNovDet ( 
tmEst VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmNContrato INT DEFAULT ((0)) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmIdNov VARCHAR(4) NOT NULL,
tmFecInicio SMALLDATETIME NOT NULL,
tmFecFinal SMALLDATETIME,
tmCantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmOpcIBC VARCHAR(20),
tmIBCNov MONEY DEFAULT ((0)) NOT NULL,
tmIBCVac MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_AutNovDet PRIMARY KEY NONCLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_AutNovDettmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_AutNovDettmIdConcepto CHECK ((len([tmIdConcepto])>(0))),
 CONSTRAINT CK_tm_AutNovDettmIdEmpleado CHECK ((len([tmIdEmpleado])>(0))),
 CONSTRAINT CK_tm_AutNovDettmIdNov CHECK ((len([tmIdNov])>(0))))
CREATE TABLE tm_AutTot ( 
tmEst VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipAdm VARCHAR(3) NOT NULL,
tmIdFondo VARCHAR(8) NOT NULL,
tmCodTipoApo CHAR(2),
tmTotalCot MONEY DEFAULT (0) NOT NULL,
tmTotalFsp MONEY DEFAULT (0) NOT NULL,
tmTotalFsu MONEY DEFAULT (0) NOT NULL,
tmTotalAva MONEY DEFAULT (0) NOT NULL,
tmTotalAve MONEY DEFAULT (0) NOT NULL,
tmTotalUpc MONEY DEFAULT (0) NOT NULL,
tmTotalLic MONEY DEFAULT (0) NOT NULL,
tmTotalInc MONEY DEFAULT (0) NOT NULL,
tmTotalOtr MONEY DEFAULT (0) NOT NULL,
tmDiasMora INT DEFAULT (0) NOT NULL,
tmTarifMora DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmIntMora MONEY DEFAULT (0) NOT NULL,
tmIMoraOtr MONEY DEFAULT (0) NOT NULL,
tmTotalSAF MONEY DEFAULT (0) NOT NULL,
tmSAFUpc MONEY DEFAULT (0) NOT NULL,
tmTotalPagar MONEY DEFAULT (0) NOT NULL,
tmTotalFon MONEY DEFAULT (0) NOT NULL,
tmTotalAfi INT DEFAULT (0) NOT NULL,
tmNumAutLic VARCHAR(30),
tmNumAutInc VARCHAR(30),
tmNumPlaSAF VARCHAR(20)
 CONSTRAINT PK_tm_AutTot PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_AutTottmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_AutTottmIdFondo CHECK ((len([tmIdFondo]) > 0)),
 CONSTRAINT CK_tm_AutTottmTipAdm CHECK ((len([tmTipAdm]) > 0)))
CREATE TABLE tm_AuxInv ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmNumLote VARCHAR(30) DEFAULT ('0') NOT NULL,
tmSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoAnt MONEY DEFAULT (0) NOT NULL,
tmCostoEnt MONEY DEFAULT (0) NOT NULL,
tmCostoSal MONEY DEFAULT (0) NOT NULL,
tmCostoProm MONEY DEFAULT (0) NOT NULL,
tmCdTanque VARCHAR(4) DEFAULT ('0') NOT NULL,
tmVtaCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVtaCantDev DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVtaTotal MONEY DEFAULT (0) NOT NULL,
tmVtaTotalDev MONEY DEFAULT (0) NOT NULL,
tmVtaCosto MONEY DEFAULT (0) NOT NULL,
tmVtaCostoDev MONEY DEFAULT (0) NOT NULL,
tmVtaIva MONEY DEFAULT (0) NOT NULL,
tmVtaIvaDev MONEY DEFAULT (0) NOT NULL,
tmVtaDcto MONEY DEFAULT (0) NOT NULL,
tmVtaDctoDev MONEY DEFAULT (0) NOT NULL,
tmVtaRet MONEY DEFAULT (0) NOT NULL,
tmVtaRetDev MONEY DEFAULT (0) NOT NULL,
tmVtaIca MONEY DEFAULT (0) NOT NULL,
tmVtaIcaDev MONEY DEFAULT (0) NOT NULL,
tmVtaTasa MONEY DEFAULT (0) NOT NULL,
tmVtaTasaDev MONEY DEFAULT (0) NOT NULL,
tmVtaGlobal MONEY DEFAULT (0) NOT NULL,
tmVtaGlobalDev MONEY DEFAULT (0) NOT NULL,
tmVtaSol MONEY DEFAULT (0) NOT NULL,
tmVtaSolDev MONEY DEFAULT (0) NOT NULL,
tmProdCia BIT DEFAULT ((0)),
tmUltCostoPre MONEY DEFAULT ((0)) NOT NULL,
tmCostoAntPre MONEY DEFAULT ((0)) NOT NULL,
tmBaseMargen VARCHAR(10),
tmTarifaIva DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmPrecioBas1 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioBas2 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioBas3 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioBas4 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioBas5 MONEY DEFAULT ((0)) NOT NULL,
tmMargen1 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmMargen2 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmMargen3 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmMargen4 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmMargen5 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmDcto1 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmDcto2 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmDcto3 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmDcto4 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmDcto5 DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmIncIva1 BIT DEFAULT ((0)) NOT NULL,
tmIncIva2 BIT DEFAULT ((0)) NOT NULL,
tmIncIva3 BIT DEFAULT ((0)) NOT NULL,
tmIncIva4 BIT DEFAULT ((0)) NOT NULL,
tmIncIva5 BIT DEFAULT ((0)) NOT NULL,
tmPrecioVta1 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioVta2 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioVta3 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioVta4 MONEY DEFAULT ((0)) NOT NULL,
tmPrecioVta5 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_AuxInv PRIMARY KEY CLUSTERED (tmEst,tmIdProducto,tmIdBodega,tmIdCia,tmNumLote),
 CONSTRAINT CK_tm_AuxInvtmCdTanque CHECK ((len([tmCdTanque]) > 0)),
 CONSTRAINT CK_tm_AuxInvtmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_AuxInvtmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_AuxInvtmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_AuxInvtmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_AuxInvtmNumLote CHECK ((len([tmNumLote]) > 0)))
CREATE TABLE tm_AuxInvUbic ( 
tmId INT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmIdUbic VARCHAR(10) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmSaldoAnt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmCostoAnt MONEY DEFAULT ((0)) NOT NULL,
tmCostoEnt MONEY DEFAULT ((0)) NOT NULL,
tmCostoSal MONEY DEFAULT ((0)) NOT NULL,
tmCostoProm MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_AuxInvUbic PRIMARY KEY NONCLUSTERED (tmId),
 CONSTRAINT CK_tm_AuxInvUbictmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_AuxInvUbictmIdBodega CHECK ((len([tmIdBodega])>(0))),
 CONSTRAINT CK_tm_AuxInvUbictmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_AuxInvUbictmIdProducto CHECK ((len([tmIdProducto])>(0))),
 CONSTRAINT CK_tm_AuxInvUbictmIdUbic CHECK ((len([tmIdUbic])>(0))))
CREATE TABLE tm_BalAcum ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmSaldoAnterior MONEY DEFAULT (0) NOT NULL,
tmTotalDebitos MONEY DEFAULT (0) NOT NULL,
tmTotalCreditos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_BalAcum PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmItem),
 CONSTRAINT CK_tm_BalAcumtmCodAgncia CHECK ((len([tmCodAgncia]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_BalAcumtmTipo CHECK ((len([tmTipo]) > 0)))
CREATE TABLE tm_BalCom ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmSaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
tmTotalDebitos MONEY DEFAULT ((0)) NOT NULL,
tmTotalCreditos MONEY DEFAULT ((0)) NOT NULL,
tmNuevoSaldo MONEY DEFAULT ((0)) NOT NULL,
tmVrPresupto MONEY DEFAULT ((0)),
tmVrCompras MONEY DEFAULT ((0))
 CONSTRAINT PK_tm_BalCom PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmItem),
 CONSTRAINT CK_tm_BalComtmCodAgncia CHECK ((len([tmCodAgncia])>(0))),
 CONSTRAINT CK_tm_BalComtmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_BalComtmIdCCosto CHECK ((len([tmIdCCosto])>(0))),
 CONSTRAINT CK_tm_BalComtmIdCuenta CHECK ((len([tmIdCuenta])>(0))),
 CONSTRAINT CK_tm_BalComtmIdSubCos CHECK ((len([tmIdSubCos])>(0))),
 CONSTRAINT CK_tm_BalComtmIdTercero CHECK ((len([tmIdTercero])>(0))),
 CONSTRAINT CK_tm_BalComtmIdVehiculo CHECK ((len([tmIdVehiculo])>(0))),
 CONSTRAINT CK_tm_BalComtmTipo CHECK ((len([tmTipo])>(0))))
CREATE TABLE tm_BalComNiif ( 
tmId INT DEFAULT ((0)) NOT NULL,
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmIdCueNiif VARCHAR(16) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmSaldoAnt1 MONEY DEFAULT ((0)) NOT NULL,
tmDebitos1 MONEY DEFAULT ((0)) NOT NULL,
tmCreditos1 MONEY DEFAULT ((0)) NOT NULL,
tmSaldoAnt2 MONEY DEFAULT ((0)) NOT NULL,
tmDebitos2 MONEY DEFAULT ((0)) NOT NULL,
tmCreditos2 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_BalComNiif PRIMARY KEY NONCLUSTERED (tmId,tmEst),
 CONSTRAINT CK_tm_BalComNiiftmCodAgncia CHECK ((len([tmCodAgncia])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdCCosto CHECK ((len([tmIdCCosto])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdCueNiif CHECK ((len([tmIdCueNiif])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdCuenta CHECK ((len([tmIdCuenta])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdSubCos CHECK ((len([tmIdSubCos])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdTercero CHECK ((len([tmIdTercero])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmIdVehiculo CHECK ((len([tmIdVehiculo])>(0))),
 CONSTRAINT CK_tm_BalComNiiftmTipo CHECK ((len([tmTipo])>(0))))
CREATE TABLE tm_BalCompara ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmSaldoAnterior MONEY DEFAULT (0) NOT NULL,
tmTotalDebitos MONEY DEFAULT (0) NOT NULL,
tmTotalCreditos MONEY DEFAULT (0) NOT NULL,
tmNuevoSaldo MONEY DEFAULT (0) NOT NULL,
tmSalAnt2 MONEY DEFAULT (0) NOT NULL,
tmDebitos2 MONEY DEFAULT (0) NOT NULL,
tmCreditos2 MONEY DEFAULT (0) NOT NULL,
tmSaldo2 MONEY DEFAULT (0) NOT NULL,
tmSalAnt3 MONEY DEFAULT (0) NOT NULL,
tmDebitos3 MONEY DEFAULT (0) NOT NULL,
tmCreditos3 MONEY DEFAULT (0) NOT NULL,
tmSaldo3 MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_BalCompara PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmItem),
 CONSTRAINT CK_tm_BalComparatmCodAgncia CHECK ((len([tmCodAgncia]) > 0)),
 CONSTRAINT CK_tm_BalComparatmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_BalComparatmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_BalComparatmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_BalComparatmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_BalComparatmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_BalComparatmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_BalComparatmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_BalComparatmTipo CHECK ((len([tmTipo]) > 0)))
CREATE TABLE tm_BalGen ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmSaldoAnterior MONEY DEFAULT (0) NOT NULL,
tmTotalDebitos MONEY DEFAULT (0) NOT NULL,
tmTotalCreditos MONEY DEFAULT (0) NOT NULL,
tmNuevoSaldo MONEY DEFAULT (0) NOT NULL,
tmSalAnt2 MONEY DEFAULT (0) NOT NULL,
tmDebitos2 MONEY DEFAULT (0) NOT NULL,
tmCreditos2 MONEY DEFAULT (0) NOT NULL,
tmSaldo2 MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_BalGen PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmIdCia),
 CONSTRAINT CK_tm_BalGentmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_BalGentmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_BalGentmIdCuenta CHECK ((len([tmIdCuenta]) > 0)))
CREATE TABLE tm_BalPspto ( 
tmEst CHAR(2) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('00') NOT NULL,
VrPstoEne MONEY DEFAULT (0) NOT NULL,
VrSanEne MONEY DEFAULT (0) NOT NULL,
VrDebEne MONEY DEFAULT (0) NOT NULL,
VrCreEne MONEY DEFAULT (0) NOT NULL,
VrPstoFeb MONEY DEFAULT (0) NOT NULL,
VrSanFeb MONEY DEFAULT (0) NOT NULL,
VrDebFeb MONEY DEFAULT (0) NOT NULL,
VrCreFeb MONEY DEFAULT (0) NOT NULL,
VrPstoMar MONEY DEFAULT (0) NOT NULL,
VrSanMar MONEY DEFAULT (0) NOT NULL,
VrDebMar MONEY DEFAULT (0) NOT NULL,
VrCreMar MONEY DEFAULT (0) NOT NULL,
VrPstoAbr MONEY DEFAULT (0) NOT NULL,
VrSanAbr MONEY DEFAULT (0) NOT NULL,
VrDebAbr MONEY DEFAULT (0) NOT NULL,
VrCreAbr MONEY DEFAULT (0) NOT NULL,
VrPstoMay MONEY DEFAULT (0) NOT NULL,
VrSanMay MONEY DEFAULT (0) NOT NULL,
VrDebMay MONEY DEFAULT (0) NOT NULL,
VrCreMay MONEY DEFAULT (0) NOT NULL,
VrPstoJun MONEY DEFAULT (0) NOT NULL,
VrSanJun MONEY DEFAULT (0) NOT NULL,
VrDebJun MONEY DEFAULT (0) NOT NULL,
VrCreJun MONEY DEFAULT (0) NOT NULL,
VrPstoJul MONEY DEFAULT (0) NOT NULL,
VrSanJul MONEY DEFAULT (0) NOT NULL,
VrDebJul MONEY DEFAULT (0) NOT NULL,
VrCreJul MONEY DEFAULT (0) NOT NULL,
VrPstoAgo MONEY DEFAULT (0) NOT NULL,
VrSanAgo MONEY DEFAULT (0) NOT NULL,
VrDebAgo MONEY DEFAULT (0) NOT NULL,
VrCreAgo MONEY DEFAULT (0) NOT NULL,
VrPstoSep MONEY DEFAULT (0) NOT NULL,
VrSanSep MONEY DEFAULT (0) NOT NULL,
VrDebSep MONEY DEFAULT (0) NOT NULL,
VrCreSep MONEY DEFAULT (0) NOT NULL,
VrPstoOct MONEY DEFAULT (0) NOT NULL,
VrSanOct MONEY DEFAULT (0) NOT NULL,
VrDebOct MONEY DEFAULT (0) NOT NULL,
VrCreOct MONEY DEFAULT (0) NOT NULL,
VrPstoNov MONEY DEFAULT (0) NOT NULL,
VrSanNov MONEY DEFAULT (0) NOT NULL,
VrDebNov MONEY DEFAULT (0) NOT NULL,
VrCreNov MONEY DEFAULT (0) NOT NULL,
VrPstoDic MONEY DEFAULT (0) NOT NULL,
VrSanDic MONEY DEFAULT (0) NOT NULL,
VrDebDic MONEY DEFAULT (0) NOT NULL,
VrCreDic MONEY DEFAULT (0) NOT NULL,
VrPstoAnual MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_BalPspto PRIMARY KEY CLUSTERED (tmEst,IdCuenta,IdCCosto,IdSubCos,IdCia),
 CONSTRAINT CK_tm_BalPsptoIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_tm_BalPsptoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_BalPsptoIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_tm_BalPsptoIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_tm_BalPsptotmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_Caja ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VCargos MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrSoldicom MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
VrCreditos MONEY DEFAULT (0) NOT NULL,
VrGastComb MONEY DEFAULT (0) NOT NULL,
VrGastOtros MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
PuntosAcum DECIMAL(14,4) DEFAULT (0) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdForma VARCHAR(4) DEFAULT ('0') NOT NULL,
NumForma VARCHAR(30),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
DetallePagos VARCHAR(150),
CdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
FecCheque SMALLDATETIME,
IdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
nClieCon VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Referencia VARCHAR(50),
Referencia2 VARCHAR(50),
Modalidad VARCHAR(10),
pVehiculo VARCHAR(10),
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
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),
TimeSys SMALLDATETIME NOT NULL
 CONSTRAINT PK_tm_Caja PRIMARY KEY CLUSTERED (tmEst,tmItem,TipDoc,Numero,IdCia),
 CONSTRAINT CK_tm_CajaCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_tm_CajaCdCta CHECK ((len([CdCta]) > 0)),
 CONSTRAINT CK_tm_CajaCdForma CHECK ((len([CdForma]) > 0)),
 CONSTRAINT CK_tm_CajaIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_CajaIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_tm_CajaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_CajaIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_tm_CajaIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_CajaIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_tm_CajaIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_tm_CajaIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_tm_CajanClieCon CHECK ((len([nClieCon]) > 0)),
 CONSTRAINT CK_tm_CajaTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_tm_CajaTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_CajatmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_CajaTot ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipo INT DEFAULT (0) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmConcepto VARCHAR(150),
tmValorTotal MONEY DEFAULT (0) NOT NULL,
tmValorOtros MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_CajaTot PRIMARY KEY CLUSTERED (tmEst,tmTipo,tmItem),
 CONSTRAINT CK_tm_CajaTottmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_Cargos ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdConductor VARCHAR(16) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdCargo VARCHAR(4) NOT NULL,
tmConcepto VARCHAR(100),
tmReferencia VARCHAR(20),
tmFactura VARCHAR(15),
tmValor MONEY DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(100),
tmFecVence SMALLDATETIME,
tmTipDoc VARCHAR(3),
tmDocumento INT DEFAULT (0),
tmIdCiaDoc CHAR(2),
tmConductor VARCHAR(100),
tmAbonado MONEY DEFAULT (0) NOT NULL,
tmTipDocAnt VARCHAR(3),
tmDocAnticipo INT DEFAULT (0),
tmCiaDocAnt CHAR(2),
tmPrestamoID INT DEFAULT (0),
tmIdCiaPre CHAR(2),
tmNumCuota INT DEFAULT (0),
tmFecCausa SMALLDATETIME,
tmValorCapital MONEY DEFAULT (0),
tmValorInteres MONEY DEFAULT (0),
tmIdCuenta VARCHAR(16) DEFAULT ('0'),
tmCombCant DECIMAL(14,4) DEFAULT (0),
tmCombValor MONEY DEFAULT (0),
tmBaseImpu MONEY DEFAULT ((0)),
tmTarifaIva DECIMAL(14,4) DEFAULT ((0)),
tmVrIva MONEY DEFAULT ((0)),
tmTarifaRet DECIMAL(14,4) DEFAULT ((0)),
tmVrRetFte MONEY DEFAULT ((0)),
tmTarifaIca DECIMAL(14,4) DEFAULT ((0)),
tmVrRetIca MONEY DEFAULT ((0)),
tmCodTarifIva VARCHAR(4),
tmCodTarifRet VARCHAR(4),
tmCodTarifIca VARCHAR(4)
 CONSTRAINT PK_tm_Cargos PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CargostmIdCargo CHECK ((len([tmIdCargo]) > 0)),
 CONSTRAINT CK_tm_CargostmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_CargostmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_CargostmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_CargostmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_Cartera ( 
tmEst CHAR(2) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrFactura MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoDcto CHAR(1) DEFAULT ('%'),
TipoBase VARCHAR(10) DEFAULT ('TOTAL'),
FecLmtDcto SMALLDATETIME,
IdConcepto VARCHAR(4) NOT NULL,
Referencia VARCHAR(50),
Detalle VARCHAR(150),
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
FecUltPago SMALLDATETIME,
NumNota INT DEFAULT (0) NOT NULL,
IdCiaNot CHAR(2),
TarifInt DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecLiqMora SMALLDATETIME,
CtaForma VARCHAR(30) NOT NULL,
Beneficiario VARCHAR(150),
RefCheque VARCHAR(50),
NumCheque VARCHAR(20),
CdBanco VARCHAR(4)
 CONSTRAINT PK_tm_Cartera PRIMARY KEY CLUSTERED (tmEst,TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_tm_CarteraCtaForma CHECK ((len([CtaForma]) > 0)),
 CONSTRAINT CK_tm_CarteraIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_CarteraIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_CarteraIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_tm_CarteraIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_CarteraIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_tm_CarteraTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_CarteratmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_ccCupones ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipoReg INT DEFAULT (1) NOT NULL,
tmTipDoc VARCHAR(3) NOT NULL,
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItemDoc INT DEFAULT (0) NOT NULL,
tmFecEmision SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmValorFactura MONEY DEFAULT (0) NOT NULL,
tmValorAbono MONEY DEFAULT (0) NOT NULL,
tmIdPropietario VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdConductor VARCHAR(16) NOT NULL,
tmIdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdClase VARCHAR(4) DEFAULT ('0') NOT NULL,
tmFactura VARCHAR(15),
tmReferencia VARCHAR(50),
tmDetalle VARCHAR(100),
tmDescuento MONEY DEFAULT (0) NOT NULL,
tmNCuota INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_ccCupones PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_ccCuponestmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmIdCargo CHECK ((len([tmIdCargo]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmIdClase CHECK ((len([tmIdClase]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmIdPropietario CHECK ((len([tmIdPropietario]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_ccCuponestmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_cheq ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipForma VARCHAR(3) DEFAULT ('CHE') NOT NULL,
tmNumForma VARCHAR(20) NOT NULL,
tmIdBanco VARCHAR(4) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmFecPago SMALLDATETIME NOT NULL,
tmVrForma MONEY DEFAULT (0) NOT NULL,
tmCtaForma VARCHAR(30) NOT NULL,
tmBeneficiario VARCHAR(150),
tmReferncia1 VARCHAR(50),
tmReferncia2 VARCHAR(50),
tmDetalle VARCHAR(150),
tmNitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdLocal VARCHAR(8) NOT NULL,
tmCdCta VARCHAR(4)
 CONSTRAINT PK_tm_cheq PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT IX_tm_cheqtmNumForma UNIQUE NONCLUSTERED (tmNumero,tmItem,tmTipForma,tmNumForma,tmIdBanco),
 CONSTRAINT CK_tm_cheqtmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_cheqtmCdVend CHECK ((len([tmCdVend]) > 0)),
 CONSTRAINT CK_tm_cheqtmCtaForma CHECK ((len([tmCtaForma]) > 0)),
 CONSTRAINT CK_tm_cheqtmIdBanco CHECK ((len([tmIdBanco]) > 0)),
 CONSTRAINT CK_tm_cheqtmIdLocal CHECK ((len([tmIdLocal]) > 0)),
 CONSTRAINT CK_tm_cheqtmNitCliente CHECK ((len([tmNitCliente]) > 0)),
 CONSTRAINT CK_tm_cheqtmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_cheqtmNumForma CHECK ((len([tmNumForma]) > 0)),
 CONSTRAINT CK_tm_cheqtmTipForma CHECK ((len([tmTipForma]) > 0)))
CREATE TABLE tm_Combo ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdProdBase VARCHAR(16) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmCdTanque VARCHAR(4),
tmIdUnd VARCHAR(4) NOT NULL,
tmFactor DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndFac VARCHAR(10),
tmServcios BIT DEFAULT (0) NOT NULL,
tmLinea INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_Combo PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CombotmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_CombotmIdProdBase CHECK ((len([tmIdProdBase]) > 0)),
 CONSTRAINT CK_tm_CombotmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_CombotmIdUnd CHECK ((len([tmIdUnd]) > 0)),
 CONSTRAINT CK_tm_CombotmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_Comisiones ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VCargos MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
nClieCon VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
CdOperario VARCHAR(16) DEFAULT ('0'),
ComisnOper DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
CdSzona VARCHAR(4),
Modalidad VARCHAR(10),
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
Anulado BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
Detalles VARCHAR(250),
Referencia VARCHAR(50)
 CONSTRAINT PK_tm_Comisiones PRIMARY KEY CLUSTERED (tmEst,TipDoc,Numero,IdCia,Item),
 CONSTRAINT CK_tm_ComisionesCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_tm_ComisionesIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_tm_ComisionesnClieCon CHECK ((len([nClieCon]) > 0)),
 CONSTRAINT CK_tm_ComisionesTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_ComisionestmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_Comp ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmDetalle VARCHAR(250) NOT NULL,
tmVrDebito MONEY DEFAULT (0) NOT NULL,
tmVrCredito MONEY DEFAULT (0) NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmTarifaBase DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3),
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCiaDoc CHAR(2) DEFAULT ('01'),
tmCodConce VARCHAR(4),
tmTipFac VARCHAR(3),
tmFactura VARCHAR(15),
tmIdCiaFac CHAR(2) DEFAULT ('01'),
tmItemFac INT DEFAULT (0) NOT NULL,
tmFecVence SMALLDATETIME,
tmCodCta VARCHAR(4),
tmNumCheque VARCHAR(20),
tmIntegrado BIT DEFAULT (0) NOT NULL,
tmTipoAplica CHAR(1) DEFAULT ('N') NOT NULL,
tmConsolida BIT DEFAULT (0) NOT NULL,
tmCodCargo VARCHAR(4),
tmNitOtros VARCHAR(16),
tmCodSubgpo VARCHAR(8),
tmCiuOrigen VARCHAR(8),
tmCodAgncia VARCHAR(16),
tmVehPropio INT DEFAULT ((0)) NOT NULL,
tmReferncia VARCHAR(50),
tmTipCom VARCHAR(3),
tmComprobante INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2),
tmNombre VARCHAR(100),
tmCcosto VARCHAR(100),
tmSubcc VARCHAR(100),
tmTercero VARCHAR(150),
tmTipDocRef VARCHAR(3),
tmDocRef INT DEFAULT (0) NOT NULL,
tmIdCiaRef CHAR(2),
tmNitDoc VARCHAR(16),
tmConcTrib VARCHAR(4),
tmTarifTrib VARCHAR(4),
tmEstablec VARCHAR(20),
tmPtoEmision VARCHAR(20),
tmAutoriza VARCHAR(50),
tmFechAut SMALLDATETIME,
tmCuentaNiif VARCHAR(16)
 CONSTRAINT PK_tm_Comp PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_ComptmDetalle CHECK ((len([tmDetalle]) > 0)),
 CONSTRAINT CK_tm_ComptmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_ComptmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_ComptmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_ComptmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_ComptmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_ComptmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_ComptmTipoAplica CHECK ((len([tmTipoAplica]) > 0)))
CREATE TABLE tm_Compau ( 
tmNumero VARCHAR(5) NOT NULL,
tmTipCom VARCHAR(3) NOT NULL,
tmComprobante INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmDetalle VARCHAR(250) NOT NULL,
tmVrDebito MONEY DEFAULT (0) NOT NULL,
tmVrCredito MONEY DEFAULT (0) NOT NULL,
tmIdTercero VARCHAR(16) NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmTarifaBase DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3),
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCiaDoc CHAR(2) DEFAULT ('01'),
tmCodConce VARCHAR(4),
tmTipFac VARCHAR(3),
tmFactura VARCHAR(15),
tmIdCiaFac CHAR(2) DEFAULT ('01'),
tmItemFac INT DEFAULT (0) NOT NULL,
tmFecVence SMALLDATETIME,
tmCodCta VARCHAR(4),
tmNumCheque VARCHAR(20),
tmIntegrado BIT DEFAULT (0) NOT NULL,
tmTipoAplica CHAR(1) DEFAULT ('N') NOT NULL,
tmConsolida BIT DEFAULT (0) NOT NULL,
tmCodCargo VARCHAR(4),
tmNitOtros VARCHAR(16),
tmCodSubgpo VARCHAR(8),
tmCiuOrigen VARCHAR(8),
tmCodAgncia VARCHAR(16),
tmVehPropio INT DEFAULT ((0)) NOT NULL,
tmReferncia VARCHAR(50),
tmNombre VARCHAR(100),
tmCcosto VARCHAR(100),
tmSubcc VARCHAR(100),
tmTercero VARCHAR(150),
tmTipDocRef VARCHAR(3),
tmDocRef INT DEFAULT (0) NOT NULL,
tmIdCiaRef CHAR(2) DEFAULT ('01'),
tmNitDoc VARCHAR(16),
tmConcTrib VARCHAR(4),
tmTarifTrib VARCHAR(4),
tmEstablec VARCHAR(20),
tmPtoEmision VARCHAR(20),
tmAutoriza VARCHAR(50),
tmFechAut SMALLDATETIME
 CONSTRAINT PK_tm_Compau PRIMARY KEY CLUSTERED (tmNumero,tmTipCom,tmComprobante,tmIdCia,tmItem),
 CONSTRAINT CK_tm_CompautmDetalle CHECK ((len([tmDetalle]) > 0)),
 CONSTRAINT CK_tm_CompautmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_CompautmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_CompautmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_CompautmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_CompautmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_CompautmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_CompautmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_CompautmTipCom CHECK ((len([tmTipCom]) > 0)),
 CONSTRAINT CK_tm_CompautmTipoAplica CHECK ((len([tmTipoAplica]) > 0)))
CREATE TABLE tm_Contratos ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmContrato INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmTipoProd VARCHAR(20) DEFAULT ('COMBUSTIBLE') NOT NULL,
tmCdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmPeriodo VARCHAR(6) NOT NULL,
tmPresptoMes DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmPresptoAnno DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCantNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmValorNeto MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_Contratos PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_ContratostmCdProducto CHECK ((len([tmCdProducto]) > 0)),
 CONSTRAINT CK_tm_ContratostmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_ContratostmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_ContratostmPeriodo CHECK ((len([tmPeriodo]) > 0)),
 CONSTRAINT CK_tm_ContratostmTipoProd CHECK ((len([tmTipoProd]) > 0)))
CREATE TABLE tm_Cuotas ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmPrestamoID INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmNumCuota INT DEFAULT (0) NOT NULL,
tmFecCausa SMALLDATETIME,
tmFecVence SMALLDATETIME,
tmValorCapital MONEY DEFAULT (0) NOT NULL,
tmValorInteres MONEY DEFAULT (0) NOT NULL,
tmValorCuota MONEY DEFAULT (0) NOT NULL,
tmSaldo MONEY DEFAULT (0) NOT NULL,
tmValorCausado MONEY DEFAULT (0) NOT NULL,
tmValorAbonado MONEY DEFAULT (0) NOT NULL,
tmFecPago SMALLDATETIME,
tmTipRec VARCHAR(3),
tmRecibo INT DEFAULT (0),
tmIdCiaRec CHAR(2)
 CONSTRAINT PK_tm_Cuotas PRIMARY KEY CLUSTERED (tmEst,tmPrestamoID,tmIdCia,tmNumCuota),
 CONSTRAINT CK_tm_CuotastmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_CuotastmIdCia CHECK ((len([tmIdCia]) > 0)))
CREATE TABLE tm_CxcAbonos ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
tmFactura INT DEFAULT (0) NOT NULL,
tmIdCiaFac CHAR(2) NOT NULL,
tmItemFac INT DEFAULT (0) NOT NULL,
tmVrAbono MONEY DEFAULT (0) NOT NULL,
tmVrDescto MONEY DEFAULT (0) NOT NULL,
tmVrBaseCms MONEY DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) NOT NULL,
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(150),
tmTipoAplica VARCHAR(10) DEFAULT ('FACTURA') NOT NULL,
tmCodTarDct VARCHAR(4),
tmCodTarCom VARCHAR(4),
tmTipRec VARCHAR(3),
tmRecibo INT DEFAULT (0) NOT NULL,
tmCiaRec CHAR(2),
tmItemRec INT DEFAULT (0) NOT NULL,
tmFecPago SMALLDATETIME
 CONSTRAINT PK_tm_CxcAbonos PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CxcAbonostmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_CxcAbonostmIdCiaFac CHECK ((len([tmIdCiaFac]) > 0)),
 CONSTRAINT CK_tm_CxcAbonostmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_CxcAbonostmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_CxcAbonostmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_CxcAbonostmTipDoc CHECK ((len([tmTipDoc]) > 0)),
 CONSTRAINT CK_tm_CxcAbonostmTipoAplica CHECK ((len([tmTipoAplica]) > 0)))
CREATE TABLE tm_CxCobrar ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmVrFactura MONEY DEFAULT (0) NOT NULL,
tmTarifDcto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTipoDcto CHAR(1) DEFAULT ('%') NOT NULL,
tmTipoBase VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
tmFecLmtDcto SMALLDATETIME,
tmReferencia VARCHAR(50),
tmDetalle VARCHAR(150),
tmTipRef VARCHAR(3),
tmDocRef INT DEFAULT (0) NOT NULL,
tmIdCiaRef CHAR(2),
tmTotAbono MONEY DEFAULT (0) NOT NULL,
tmFecPlazo SMALLDATETIME
 CONSTRAINT PK_tm_CxCobrar PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CxCobrartmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_CxCobrartmTipoBase CHECK ((len([tmTipoBase]) > 0)),
 CONSTRAINT CK_tm_CxCobrartmTipoDcto CHECK ((len([tmTipoDcto]) > 0)))
CREATE TABLE tm_CxPagar ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProveedor VARCHAR(16) NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmTipDoc VARCHAR(3),
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCiaDoc CHAR(2) DEFAULT ('01'),
tmVrFactura MONEY DEFAULT (0) NOT NULL,
tmItemCom INT DEFAULT (0) NOT NULL,
tmReferencia VARCHAR(50),
tmDetalle VARCHAR(100),
tmpVehiculo VARCHAR(10),
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmTipRef VARCHAR(3),
tmDocRef INT DEFAULT (0) NOT NULL,
tmIdCiaRef CHAR(2) DEFAULT ('01'),
tmProveedor VARCHAR(250)
 CONSTRAINT PK_tm_CxPagar PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CxPagartmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_CxPagartmIdProveedor CHECK ((len([tmIdProveedor]) > 0)),
 CONSTRAINT CK_tm_CxPagartmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_CxpAnticipo ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmTipCom VARCHAR(3) NOT NULL,
tmNumCom INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmItemCom INT DEFAULT ((0)) NOT NULL,
tmValor MONEY DEFAULT ((0)) NOT NULL,
tmVrSaldo MONEY DEFAULT ((0)) NOT NULL,
tmTipFac VARCHAR(3) NOT NULL,
tmFactura VARCHAR(15) NOT NULL,
tmIdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
tmItemFac INT DEFAULT ((0)) NOT NULL,
tmIdCuenta VARCHAR(16),
tmIdProv VARCHAR(16),
tmItemDet INT DEFAULT ((0)) NOT NULL,
tmTipoReg INT DEFAULT ((0)) NOT NULL,
tmCodCueCxp VARCHAR(16)
 CONSTRAINT PK_tm_CxpAnticipo PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CxpAnticipotmFactura CHECK ((len([tmFactura])>(0))),
 CONSTRAINT CK_tm_CxpAnticipotmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_CxpAnticipotmIdCiaFac CHECK ((len([tmIdCiaFac])>(0))),
 CONSTRAINT CK_tm_CxpAnticipotmNumero CHECK ((len([tmNumero])>(0))),
 CONSTRAINT CK_tm_CxpAnticipotmTipCom CHECK ((len([tmTipCom])>(0))),
 CONSTRAINT CK_tm_CxpAnticipotmTipFac CHECK ((len([tmTipFac])>(0))))
CREATE TABLE tm_CxpAplica ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProveedor VARCHAR(16) NOT NULL,
tmTipFac VARCHAR(3) NOT NULL,
tmFactura VARCHAR(15) NOT NULL,
tmIdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
tmItemFac INT DEFAULT (0) NOT NULL,
tmVrAbono MONEY DEFAULT (0) NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmpVehiculo VARCHAR(10),
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmTipDev VARCHAR(3),
tmNumDev INT DEFAULT (0) NOT NULL,
tmDetAbono VARCHAR(100),
tmProveedor VARCHAR(250)
 CONSTRAINT PK_tm_CxpAplica PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_CxpAplicatmFactura CHECK ((len([tmFactura]) > 0)),
 CONSTRAINT CK_tm_CxpAplicatmIdCiaFac CHECK ((len([tmIdCiaFac]) > 0)),
 CONSTRAINT CK_tm_CxpAplicatmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_CxpAplicatmIdProveedor CHECK ((len([tmIdProveedor]) > 0)),
 CONSTRAINT CK_tm_CxpAplicatmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_CxpAplicatmTipFac CHECK ((len([tmTipFac]) > 0)))
CREATE TABLE tm_DetCue ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmConcepto VARCHAR(10) NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmValor MONEY DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(150),
tmIdTercero VARCHAR(16) NOT NULL,
tmCodAgncia VARCHAR(16),
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmpVehiculo VARCHAR(10),
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmTipFac VARCHAR(3),
tmFactura VARCHAR(15),
tmIdCiaFac CHAR(2) DEFAULT ('01'),
tmItemFac INT DEFAULT (0) NOT NULL,
tmFecVence SMALLDATETIME,
tmCheque VARCHAR(20),
tmCiuOrigen VARCHAR(8),
tmReferencia VARCHAR(50),
tmTarifa DECIMAL(14,4) DEFAULT ((0)),
tmTipoTarif CHAR(1),
tmCodConc VARCHAR(4),
tmCodTarif VARCHAR(4)
 CONSTRAINT PK_tm_DetCue PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_DetCuetmConcepto CHECK ((len([tmConcepto]) > 0)),
 CONSTRAINT CK_tm_DetCuetmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_DetCuetmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_DetCuetmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_Diario ( 
tmId INT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteIca MONEY DEFAULT (0) NOT NULL,
VrReteIva MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VCargos MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrSoldicom MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
VrCreditos MONEY DEFAULT (0) NOT NULL,
VrValesGastos MONEY DEFAULT (0) NOT NULL,
CantPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0'),
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdForma VARCHAR(4) DEFAULT ('0'),
NumForma VARCHAR(30),
CdBanco VARCHAR(4) DEFAULT ('0'),
DetallePagos VARCHAR(150),
CdCta VARCHAR(4) DEFAULT ('0'),
FecCheque SMALLDATETIME,
IdVend VARCHAR(16) DEFAULT ('0'),
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
nClieCon VARCHAR(16) DEFAULT ('0'),
IdCajero VARCHAR(11) NOT NULL,
IdLocal VARCHAR(8),
Referencia VARCHAR(50),
Referencia2 VARCHAR(50),
Beneficiario VARCHAR(150),
Modalidad VARCHAR(10),
pVehiculo VARCHAR(10),
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
VrImpConsumo MONEY DEFAULT ((0)),
IdRuta VARCHAR(4) DEFAULT ('0'),
IdLocOrigen VARCHAR(8) DEFAULT ('0'),
IdLocDestino VARCHAR(8) DEFAULT ('0'),
IdPoseedor VARCHAR(16) DEFAULT ('0'),
IdConductor VARCHAR(16) DEFAULT ('0'),
IdRemitente VARCHAR(16) DEFAULT ('0'),
IdDestinatario VARCHAR(16) DEFAULT ('0'),
NumPedido INT DEFAULT ((0)),
IdCiaPed CHAR(2) DEFAULT ('00')
 CONSTRAINT PK_tm_Diario PRIMARY KEY CLUSTERED (tmId),
 CONSTRAINT CK_tm_DiarioIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_DiarioIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_tm_DiarioIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_DiarioIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_DiarioIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_tm_DiarioTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_DiariotmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_DifIngreso ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdDiferido VARCHAR(30) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmPeriodos INT DEFAULT (0) NOT NULL,
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmMejoras MONEY DEFAULT (0) NOT NULL,
tmDisminucion MONEY DEFAULT (0) NOT NULL,
tmAjustes MONEY DEFAULT (0) NOT NULL,
tmAmortiza MONEY DEFAULT (0) NOT NULL,
tmAmortizaAju MONEY DEFAULT (0) NOT NULL,
tmAjuInfAmtza MONEY DEFAULT (0) NOT NULL,
tmMesesAcum INT DEFAULT (0) NOT NULL,
tmCorrMonDif MONEY DEFAULT (0) NOT NULL,
tmMesesCorr INT DEFAULT (0) NOT NULL,
tmFecUltAmtza SMALLDATETIME,
tmConcepto VARCHAR(150)
 CONSTRAINT PK_tm_DifIngreso PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_DifIngresotmIdDiferido CHECK ((len([tmIdDiferido]) > 0)),
 CONSTRAINT CK_tm_DifIngresotmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_Dotacion ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmNContrato INT DEFAULT ((0)) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmTipo VARCHAR(10) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmNumReg INT DEFAULT ((0)) NOT NULL,
tmDiasPlazo INT DEFAULT ((0)) NOT NULL,
tmFecVence SMALLDATETIME,
tmDetalle VARCHAR(1000)
 CONSTRAINT PK_tm_Dotacion PRIMARY KEY CLUSTERED (tmEst,tmIdEmpleado),
 CONSTRAINT CK_tm_DotaciontmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_DotaciontmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_DotaciontmIdEmpleado CHECK ((len([tmIdEmpleado])>(0))),
 CONSTRAINT CK_tm_DotaciontmTipo CHECK ((len([tmTipo])>(0))))
CREATE TABLE tm_EdsFormas ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmCredito BIT DEFAULT (0) NOT NULL,
tmTipoRango VARCHAR(3) NOT NULL,
tmIdRango INT DEFAULT (0) NOT NULL,
tmIdForma VARCHAR(4) NOT NULL,
tmObservacion VARCHAR(150),
tmEsCaja BIT DEFAULT (0) NOT NULL,
tmIdBanco VARCHAR(4) NOT NULL,
tmNForma VARCHAR(20),
tmFecForma SMALLDATETIME,
tmCtaForma VARCHAR(30),
tmBeneficiario VARCHAR(150),
tmNumSerie VARCHAR(5) NOT NULL,
tmNumForma INT DEFAULT (0) NOT NULL,
tmVrTotal MONEY DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmpVehiculo VARCHAR(10),
tmnVehiculo VARCHAR(10),
tmIdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmReferencia VARCHAR(50),
tmReferncia2 VARCHAR(50),
tmCantPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
tmNumAutoriza VARCHAR(30),
tmVrDenom MONEY DEFAULT (0) NOT NULL,
tmCantDenm INT DEFAULT (0) NOT NULL,
tmTipDenom CHAR(1) DEFAULT ('B') NOT NULL,
tmCdCta VARCHAR(4),
tmTipAplica VARCHAR(10),
tmIdUsuario VARCHAR(11),
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmVrPrecio MONEY DEFAULT ((0)) NOT NULL,
tmVrBase MONEY DEFAULT ((0)) NOT NULL,
tmVrPresp MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_EdsFormas PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_EdsFormastmCdLocal CHECK ((len([tmCdLocal]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmCdProducto CHECK ((len([tmCdProducto]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmIdBanco CHECK ((len([tmIdBanco]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmIdForma CHECK ((len([tmIdForma]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmNumSerie CHECK ((len([tmNumSerie]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmTipDenom CHECK ((len([tmTipDenom]) > 0)),
 CONSTRAINT CK_tm_EdsFormastmTipoRango CHECK ((len([tmTipoRango]) > 0)))
CREATE TABLE tm_EstadoGyp ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmSaldoAnterior MONEY DEFAULT (0) NOT NULL,
tmTotalDebitos MONEY DEFAULT (0) NOT NULL,
tmTotalCreditos MONEY DEFAULT (0) NOT NULL,
tmNuevoSaldo MONEY DEFAULT (0) NOT NULL,
tmSalAnt2 MONEY DEFAULT (0) NOT NULL,
tmDebitos2 MONEY DEFAULT (0) NOT NULL,
tmCreditos2 MONEY DEFAULT (0) NOT NULL,
tmSaldo2 MONEY DEFAULT (0) NOT NULL,
tmTipoAfi INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_EstadoGyp PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmItem),
 CONSTRAINT CK_tm_EstadoGyptmCodAgncia CHECK ((len([tmCodAgncia]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_EstadoGyptmTipo CHECK ((len([tmTipo]) > 0)))
CREATE TABLE tm_EstClientes ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmFecUltFcr SMALLDATETIME,
tmPPlazoFcr DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMayorFcr MONEY DEFAULT (0) NOT NULL,
tmMenorFcr MONEY DEFAULT (0) NOT NULL,
tmFecUltFco SMALLDATETIME,
tmPPlazoFco DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMayorFco MONEY DEFAULT (0) NOT NULL,
tmMenorFco MONEY DEFAULT (0) NOT NULL,
tmVentaBruto MONEY DEFAULT (0) NOT NULL,
tmVrDevolucion MONEY DEFAULT (0) NOT NULL,
tmVrDescuentos MONEY DEFAULT (0) NOT NULL,
tmCostoBruto MONEY DEFAULT (0) NOT NULL,
tmCostoDev MONEY DEFAULT (0) NOT NULL,
tmVrIva MONEY DEFAULT (0) NOT NULL,
tmFecUltPago SMALLDATETIME,
tmPromPago DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSaldoMora MONEY DEFAULT (0) NOT NULL,
tmFecIniMora SMALLDATETIME,
tmDiasEnMora INT DEFAULT (0) NOT NULL,
tmChequesDev INT DEFAULT (0) NOT NULL,
tmSaldoActual MONEY DEFAULT (0) NOT NULL,
tmSaldoAnterior MONEY DEFAULT (0) NOT NULL,
tmVrFacturas MONEY DEFAULT (0) NOT NULL,
tmVrDevFacturas MONEY DEFAULT (0) NOT NULL,
tmVrRecibos MONEY DEFAULT (0) NOT NULL,
tmVrDevRecibos MONEY DEFAULT (0) NOT NULL,
tmVrNotasDeb MONEY DEFAULT (0) NOT NULL,
tmVrNotasCre MONEY DEFAULT (0) NOT NULL,
tmVrCheques MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_EstClientes PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_EstClientestmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_EstClientestmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_EstClientestmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_EstClientestmIdCliente CHECK ((len([tmIdCliente]) > 0)))
CREATE TABLE tm_EstCueCte ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipDoc VARCHAR(3) NOT NULL,
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIndTip INT DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmValorDebito MONEY DEFAULT (0) NOT NULL,
tmValorCredito MONEY DEFAULT (0) NOT NULL,
tmValorAbono MONEY DEFAULT (0),
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdVendedor VARCHAR(16) DEFAULT ('0') NOT NULL,
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdClase VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmFecUltPago SMALLDATETIME,
tmFactura VARCHAR(15),
tmReferencia VARCHAR(50),
tmDetalle VARCHAR(250),
tmTipCar VARCHAR(3),
tmCartulina INT DEFAULT (0),
tmIdCiaCar CHAR(2),
tmModalidad VARCHAR(10),
tmCentInicial INT DEFAULT (0),
tmCentFinal INT DEFAULT (0),
tmNPasajeros INT DEFAULT (0),
tmRecorridos INT DEFAULT (0),
tmValorRecibido MONEY DEFAULT (0),
tmTotalGastos MONEY DEFAULT (0),
tmTotalVales MONEY DEFAULT (0),
tmTotalAhorro MONEY DEFAULT (0),
tmTotalOtros MONEY DEFAULT (0),
tmTotalAbono MONEY DEFAULT (0),
tmNumCheque VARCHAR(20),
tmIdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
tmAnulado BIT DEFAULT (0) NOT NULL,
tmNumDev INT DEFAULT (0),
tmFecDev SMALLDATETIME,
tmIntMora BIT DEFAULT (0) NOT NULL,
tmCxPagar BIT DEFAULT (0) NOT NULL,
tmTipDcm VARCHAR(3),
tmDocDev INT DEFAULT (0),
tmIdCiaDcm CHAR(2),
tmFecDcm SMALLDATETIME,
tmIdEstado VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdUsuario VARCHAR(11) DEFAULT ('0') NOT NULL,
tmTimeSys SMALLDATETIME,
tmSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmSaldoAntCla MONEY DEFAULT (0) NOT NULL,
tmSaldoAntCia MONEY DEFAULT (0) NOT NULL,
tmSaldoAntDia MONEY DEFAULT (0) NOT NULL,
tmNuevoSaldo MONEY DEFAULT (0) NOT NULL,
tmSalAntPro MONEY DEFAULT (0) NOT NULL,
tmSalAntProCla MONEY DEFAULT (0) NOT NULL,
tmSalAntProCia MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_EstCueCte PRIMARY KEY CLUSTERED (tmEst,tmTipDoc,tmDocumento,tmIdCia,tmItem),
 CONSTRAINT CK_tm_EstCueCtetmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdBanco CHECK ((len([tmIdBanco]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdCargo CHECK ((len([tmIdCargo]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdClase CHECK ((len([tmIdClase]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdEstado CHECK ((len([tmIdEstado]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdUsuario CHECK ((len([tmIdUsuario]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmIdVendedor CHECK ((len([tmIdVendedor]) > 0)),
 CONSTRAINT CK_tm_EstCueCtetmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_EVcau ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipo VARCHAR(3) NOT NULL,
tmDocmnto INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmGrupo VARCHAR(3) NOT NULL,
tmIdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmValor MONEY DEFAULT (0) NOT NULL,
tmValorDev MONEY DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
tmModalidad VARCHAR(10),
tmValorTotal MONEY DEFAULT (0) NOT NULL,
tmGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrComb MONEY DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(250),
tmNumCheque VARCHAR(20),
tmReferencia VARCHAR(50),
tmIdClase VARCHAR(4) DEFAULT ('0') NOT NULL,
tmAnulado BIT DEFAULT (0) NOT NULL,
tmNumDev INT DEFAULT (0),
tmFecDev SMALLDATETIME,
tmTipDcm VARCHAR(3),
tmDocDev INT DEFAULT (0),
tmIdCiaDcm CHAR(2),
tmFecDcm SMALLDATETIME,
tmIdEstado VARCHAR(4) DEFAULT ('0'),
tmVrGastos MONEY DEFAULT (0),
tmIdUsuario VARCHAR(11) DEFAULT ('0'),
tmTimeSys SMALLDATETIME
 CONSTRAINT PK_tm_EVcau PRIMARY KEY CLUSTERED (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem),
 CONSTRAINT CK_tm_EVcautmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_EVcautmGrupo CHECK ((len([tmGrupo]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdCargo CHECK ((len([tmIdCargo]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdClase CHECK ((len([tmIdClase]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_EVcautmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_EVcautmTipo CHECK ((len([tmTipo]) > 0)))
CREATE TABLE tm_EVEst ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdTipo VARCHAR(4) NOT NULL,
tmTotalProducido MONEY DEFAULT (0) NOT NULL,
tmMaxProducido MONEY DEFAULT (0) NOT NULL,
tmMinProducido MONEY DEFAULT (0) NOT NULL,
tmTotalRecrridos INT DEFAULT (0) NOT NULL,
tmTotalPasaj INT DEFAULT (0) NOT NULL,
tmTotalDias INT DEFAULT (0) NOT NULL,
tmTotalCausac MONEY DEFAULT (0) NOT NULL,
tmGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmValorComb MONEY DEFAULT (0) NOT NULL,
tmCantVeh INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_EVEst PRIMARY KEY CLUSTERED (tmEst,tmIdTipo),
 CONSTRAINT CK_tm_EVEsttmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_EVEsttmIdTipo CHECK ((len([tmIdTipo]) > 0)))
CREATE TABLE tm_EVrec ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipo VARCHAR(3) NOT NULL,
tmDocmnto INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmGrupo VARCHAR(3) NOT NULL,
tmValor MONEY DEFAULT (0) NOT NULL,
tmValorDev MONEY DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
tmModalidad VARCHAR(10),
tmTipCar VARCHAR(3),
tmCartulina INT DEFAULT (0),
tmIdCiaCar CHAR(2),
tmFechaRec SMALLDATETIME,
tmCentInicial INT DEFAULT (0),
tmCentFinal INT DEFAULT (0),
tmNPasajeros INT DEFAULT (0),
tmRecorridos INT DEFAULT (0),
tmValorTotal MONEY DEFAULT (0),
tmValorOtros MONEY DEFAULT (0),
tmTotalProducido MONEY DEFAULT (0),
tmTotalGastos MONEY DEFAULT (0),
tmTotalAhorro MONEY DEFAULT (0),
tmTotalOtros MONEY DEFAULT (0),
tmTotalVales MONEY DEFAULT (0),
tmTotalAbono MONEY DEFAULT (0),
tmValorPasaje MONEY DEFAULT (0),
tmDetalle VARCHAR(250),
tmNumCheque VARCHAR(20),
tmReferencia VARCHAR(50),
tmIdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdClase VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
tmAnulado BIT DEFAULT (0) NOT NULL,
tmNumDev INT DEFAULT (0),
tmFecDev SMALLDATETIME,
tmTipDcm VARCHAR(3),
tmDocDev INT DEFAULT (0),
tmIdCiaDcm CHAR(2),
tmFecDcm SMALLDATETIME,
tmIdEstado VARCHAR(4) DEFAULT ('0'),
tmIdUsuario VARCHAR(11) DEFAULT ('0'),
tmTimeSys SMALLDATETIME,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_tm_EVrec PRIMARY KEY CLUSTERED (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem),
 CONSTRAINT CK_tm_EVrectmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_EVrectmGrupo CHECK ((len([tmGrupo]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdBanco CHECK ((len([tmIdBanco]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdClase CHECK ((len([tmIdClase]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdRuta CHECK ((len([tmIdRuta]) > 0)),
 CONSTRAINT CK_tm_EVrectmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_EVrectmTipo CHECK ((len([tmTipo]) > 0)))
CREATE TABLE tm_ExtVeh ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdPropietario VARCHAR(16) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmIdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmTotaDebito MONEY DEFAULT (0) NOT NULL,
tmTotaCredito MONEY DEFAULT (0) NOT NULL,
tmSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmSaldoAntCla MONEY DEFAULT (0) NOT NULL,
tmSalAntPro MONEY DEFAULT (0) NOT NULL,
tmSalAntProCla MONEY DEFAULT (0) NOT NULL,
tmTotalProducido MONEY DEFAULT (0) NOT NULL,
tmMaxProducido MONEY DEFAULT (0) NOT NULL,
tmMinProducido MONEY DEFAULT (0) NOT NULL,
tmTotalRecrridos INT DEFAULT (0) NOT NULL,
tmTotalPasaj INT DEFAULT (0) NOT NULL,
tmTotalDias INT DEFAULT (0) NOT NULL,
tmTotalCausac MONEY DEFAULT (0) NOT NULL,
tmGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmValorComb MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_ExtVeh PRIMARY KEY CLUSTERED (tmEst,tmIdPropietario,tmIdVehiculo),
 CONSTRAINT CK_tm_ExtVehtmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_ExtVehtmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_ExtVehtmIdPropietario CHECK ((len([tmIdPropietario]) > 0)),
 CONSTRAINT CK_tm_ExtVehtmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)))
CREATE TABLE tm_FacAbonos ( 
tmTipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
tmFactura INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmVrAbonado MONEY DEFAULT (0) NOT NULL,
tmDescuentos MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_FacAbonos PRIMARY KEY CLUSTERED (tmTipDoc,tmFactura,tmIdCia,tmItem),
 CONSTRAINT CK_tm_FacAbonostmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_FacAbonostmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_FactNeto ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipFac VARCHAR(3) NOT NULL,
tmFactura INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmSubTotal MONEY DEFAULT ((0)) NOT NULL,
tmDescuento MONEY DEFAULT ((0)) NOT NULL,
tmImpuesto MONEY DEFAULT ((0)) NOT NULL,
tmRetencion MONEY DEFAULT ((0)) NOT NULL,
tmReteICA MONEY DEFAULT ((0)) NOT NULL,
tmReteIVA MONEY DEFAULT ((0)) NOT NULL,
tmFletes MONEY DEFAULT ((0)) NOT NULL,
tmOtros MONEY DEFAULT ((0)) NOT NULL,
tmCargos MONEY DEFAULT ((0)) NOT NULL,
tmOtrDcto MONEY DEFAULT ((0)) NOT NULL,
tmCostos MONEY DEFAULT ((0)) NOT NULL,
tmSobretasa MONEY DEFAULT ((0)) NOT NULL,
tmImpGlobal MONEY DEFAULT ((0)) NOT NULL,
tmFaltantes MONEY DEFAULT ((0)) NOT NULL,
tmAnticipos MONEY DEFAULT ((0)) NOT NULL,
tmNeto MONEY DEFAULT ((0)) NOT NULL,
tmImpCons MONEY DEFAULT ((0)) NOT NULL,
tmReteCREE MONEY DEFAULT ((0)) NOT NULL,
tmEntradas DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmSalidas DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmTasaNac DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmTasaDep DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmTasaMun DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmRec_Costo DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmMgenCont DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmIvaInf DECIMAL(16,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_FactNeto PRIMARY KEY CLUSTERED (tmEst,tmTipFac,tmFactura,tmIdCia,tmItem),
 CONSTRAINT CK_tm_FactNetotmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_FactNetotmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_FactNetotmTipFac CHECK ((len([tmTipFac])>(0))))
CREATE TABLE tm_Finmail ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdClie VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) NOT NULL,
RazonSocial VARCHAR(250) NOT NULL,
e_mail VARCHAR(100),
NumTarj VARCHAR(30),
CodTarj VARCHAR(30),
FecVenceTc SMALLDATETIME
 CONSTRAINT PK_tm_Finmail PRIMARY KEY CLUSTERED (Id),
 CONSTRAINT CK_tm_FinmailIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_tm_FinmailIdClie CHECK ((len([IdClie])>(0))),
 CONSTRAINT CK_tm_FinmailRazonSocial CHECK ((len([RazonSocial])>(0))))
CREATE TABLE tm_ForItems ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrPrecio MONEY DEFAULT (0) NOT NULL,
tmTarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrIva MONEY DEFAULT (0) NOT NULL,
tmTarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrDcto MONEY DEFAULT (0) NOT NULL,
tmVrBruto MONEY DEFAULT (0) NOT NULL,
tmDescripcion VARCHAR(150),
tmServcios BIT DEFAULT (0) NOT NULL,
tmListaPrec CHAR(1) DEFAULT ('0') NOT NULL,
tmCantDev DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmCantFact DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmCdOperario VARCHAR(16),
tmComsOper DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_ForItems PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_ForItemstmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_ForItemstmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_ForItemstmListaPrec CHECK ((len([tmListaPrec]) > 0)),
 CONSTRAINT CK_tm_ForItemstmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_GypVentas ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmTipo INT DEFAULT ((0)) NOT NULL,
tmConcepto VARCHAR(100),
tmEnero DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmFebrero DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmMarzo DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmAbril DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmMayo DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmJunio DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmJulio DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmAgosto DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmSeptiembre DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmOctubre DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmNoviembre DECIMAL(18,4) DEFAULT ((0)) NOT NULL,
tmDiciembre DECIMAL(18,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_GypVentas PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_GypVentastmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_GypVentastmIdCia CHECK ((len([tmIdCia])>(0))))
CREATE TABLE tm_InfDiario ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VCargos MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrSoldicom MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
VrCreditos MONEY DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdForma VARCHAR(4) DEFAULT ('0') NOT NULL,
NumForma VARCHAR(30),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
DetallePagos VARCHAR(150),
IdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
nClieCon VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Referencia VARCHAR(50),
Referencia2 VARCHAR(50),
Modalidad VARCHAR(10),
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
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),
TimeSys SMALLDATETIME NOT NULL,
VrImpCon MONEY DEFAULT ((0))
 CONSTRAINT PK_tm_InfDiario PRIMARY KEY CLUSTERED (tmEst,tmItem,TipDoc,Numero,IdCia),
 CONSTRAINT CK_tm_InfDiarioCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_tm_InfDiarioCdForma CHECK ((len([CdForma]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_tm_InfDiarioIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_tm_InfDiarionClieCon CHECK ((len([nClieCon]) > 0)),
 CONSTRAINT CK_tm_InfDiarioTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_tm_InfDiarioTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_InfDiariotmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_Ingresos ( 
tmEst CHAR(2) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmNMes VARCHAR(6) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmDetalle VARCHAR(100),
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmCantDevg DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmCantDed DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmVrDevngado MONEY DEFAULT (0) NOT NULL,
tmVrDeducido MONEY DEFAULT (0) NOT NULL,
tmTarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmDiasBase INT DEFAULT (0) NOT NULL,
tmDiasNoRem INT DEFAULT (0) NOT NULL,
tmFecInicial SMALLDATETIME NOT NULL,
tmFecFinal SMALLDATETIME NOT NULL,
tmNContrato INT DEFAULT (0) NOT NULL,
tmpVehiculo VARCHAR(10),
tmIdDep VARCHAR(4) NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmIdNom VARCHAR(4) NOT NULL,
tmIdInstala VARCHAR(4) NOT NULL,
tmVrSalario MONEY DEFAULT (0) NOT NULL,
tmCodFondo VARCHAR(8),
tmClaseLiq VARCHAR(10),
tmOrigenLiq VARCHAR(10),
tmBaseRet BIT DEFAULT (0) NOT NULL,
tmEsPstamo BIT DEFAULT (0) NOT NULL,
tmEsRetiro BIT DEFAULT (0) NOT NULL,
tmNPrestamo INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_Ingresos PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_IngresostmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdDep CHECK ((len([tmIdDep]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdInstala CHECK ((len([tmIdInstala]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdNom CHECK ((len([tmIdNom]) > 0)),
 CONSTRAINT CK_tm_IngresostmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_IngresostmNMes CHECK ((len([tmNMes]) > 0)))
CREATE TABLE tm_IntAhorro ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmSaldoBase MONEY DEFAULT (0) NOT NULL,
tmTasa DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmValor MONEY DEFAULT (0) NOT NULL,
tmNmes INT DEFAULT (0) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdPropietario VARCHAR(16) DEFAULT ('0') NOT NULL,
tmConductor VARCHAR(100),
tmTercero VARCHAR(100),
tmRetencion MONEY DEFAULT (0) NOT NULL,
tmVrAbono MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_IntAhorro PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_IntAhorrotmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_IntAhorrotmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_IntAhorrotmIdPropietario CHECK ((len([tmIdPropietario]) > 0)),
 CONSTRAINT CK_tm_IntAhorrotmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_IntAhorrotmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)))
CREATE TABLE tm_IntNomina ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmIdConductor VARCHAR(16) NOT NULL,
tmIdPropietario VARCHAR(16) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmConductor VARCHAR(100),
tmTercero VARCHAR(100),
tmCcosto VARCHAR(16),
tmValorAbono MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_IntNomina PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_IntNominatmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_IntNominatmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_IntNominatmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_IntNominatmIdPropietario CHECK ((len([tmIdPropietario]) > 0)),
 CONSTRAINT CK_tm_IntNominatmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)))
CREATE TABLE tm_KarUbi ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmIdUbic VARCHAR(10) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmLinea INT DEFAULT (0) NOT NULL,
tmCdNueBod VARCHAR(4),
tmCdNueUbic VARCHAR(10)
 CONSTRAINT PK_tm_KarUbi PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_KarUbitmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_KarUbitmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_KarUbitmIdUbic CHECK ((len([tmIdUbic]) > 0)),
 CONSTRAINT CK_tm_KarUbitmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_Kdex ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmCdTanque VARCHAR(4),
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdUnd VARCHAR(4) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmVrPrecio MONEY DEFAULT (0) NOT NULL,
tmVrCostProm MONEY DEFAULT (0) NOT NULL,
tmVrProm MONEY DEFAULT (0) NOT NULL,
tmTarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrIva MONEY DEFAULT (0) NOT NULL,
tmTarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrDcto MONEY DEFAULT (0) NOT NULL,
tmTarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrRete MONEY DEFAULT (0) NOT NULL,
tmTarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrIca MONEY DEFAULT (0) NOT NULL,
tmVrBruto MONEY DEFAULT (0) NOT NULL,
tmCdUbic VARCHAR(10),
tmNumLote VARCHAR(30),
tmFechLote SMALLDATETIME,
tmFecVceLote SMALLDATETIME,
tmIdTercero VARCHAR(16) NOT NULL,
tmCdAgencia VARCHAR(16),
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmCdLocal VARCHAR(8),
tmCdSzona VARCHAR(4),
tmpVehiculo VARCHAR(10),
tmIdVend VARCHAR(16) NOT NULL,
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCdOperario VARCHAR(16),
tmComisnOper DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmReferencia VARCHAR(50),
tmDescripcion VARCHAR(250),
tmComptmntos VARCHAR(50),
tmCdProdEquiv VARCHAR(16),
tmCdMngra VARCHAR(10),
tmNumInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmNumFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSobretasa DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTasaNac DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTasaDep DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTasaMun DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSoldicom DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmImpGlobal DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmOtroImpto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUnidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmServcios BIT DEFAULT (0) NOT NULL,
tmNoVentas INT DEFAULT (0) NOT NULL,
tmEsCombo BIT DEFAULT (0) NOT NULL,
tmEsProdBase INT DEFAULT (0) NOT NULL,
tmItemCbo INT DEFAULT (0) NOT NULL,
tmCodTarDct VARCHAR(4),
tmCodTarIva VARCHAR(4),
tmCodTarIca VARCHAR(4),
tmCodTarRet VARCHAR(4),
tmCodTarCom VARCHAR(4),
tmCodTarCmc VARCHAR(4),
tmCdSubgrupo VARCHAR(8),
tmListaPrec CHAR(1) DEFAULT ('0') NOT NULL,
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmCdMoneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
tmVrTasaCamb MONEY DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3),
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01'),
tmTipRem VARCHAR(3),
tmRemision INT DEFAULT (0) NOT NULL,
tmIdCiaRem CHAR(2),
tmReferencia2 VARCHAR(50),
tmFecOrden SMALLDATETIME,
tmgalsbruto DECIMAL(14,4) DEFAULT (0),
tmgalsneto DECIMAL(14,4) DEFAULT (0),
tmTemperatura DECIMAL(14,4) DEFAULT (0),
tmUmTemp VARCHAR(3),
tmDensidad DECIMAL(14,4) DEFAULT (0),
tmRec_Costo DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMgenCont DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCotizacion INT DEFAULT (0) NOT NULL,
tmCiaCotiza CHAR(2),
tmVrImvCosto DECIMAL(16,4) DEFAULT ((0)),
tmTarifaIco DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrImpCon DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmCantObseq DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmIvaObseq MONEY DEFAULT ((0)) NOT NULL,
tmIvaComb DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmImpCarb DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmIngCombo DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmTarifaStc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmSobtasaCons DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmCodTarIco VARCHAR(4),
tmBaseIvp MONEY DEFAULT ((0)) NOT NULL,
tmTarifaIvp DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmIvaIngProd MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_Kdex PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_KdextmCdMoneda CHECK ((len([tmCdMoneda]) > 0)),
 CONSTRAINT CK_tm_KdextmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_KdextmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_KdextmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_KdextmIdUnd CHECK ((len([tmIdUnd]) > 0)),
 CONSTRAINT CK_tm_KdextmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_KdextmListaPrec CHECK ((len([tmListaPrec]) > 0)),
 CONSTRAINT CK_tm_KdextmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_LibOf ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipCom VARCHAR(3) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('0') NOT NULL,
tmTotalDebitos MONEY DEFAULT (0) NOT NULL,
tmTotalCreditos MONEY DEFAULT (0) NOT NULL,
tmSaldoAnterior MONEY DEFAULT (0) NOT NULL,
tmSanNit MONEY DEFAULT (0) NOT NULL,
tmSanNitcc MONEY DEFAULT (0) NOT NULL,
tmSanNitCcSub MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_LibOf PRIMARY KEY CLUSTERED (tmEst,tmTipCom,tmItem),
 CONSTRAINT CK_tm_LibOftmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_LibOftmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_LibOftmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_LibOftmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_LibOftmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_LibOftmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_LibOftmTipCom CHECK ((len([tmTipCom]) > 0)))
CREATE TABLE tm_Liquida ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmDetalle VARCHAR(100),
tmFecUltLiq SMALLDATETIME NOT NULL,
tmFecInicial SMALLDATETIME NOT NULL,
tmFecFinal SMALLDATETIME NOT NULL,
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmCantidad INT DEFAULT (0) NOT NULL,
tmVrLiquida MONEY DEFAULT (0) NOT NULL,
tmVrDeducido MONEY DEFAULT (0) NOT NULL,
tmFecIniPmd SMALLDATETIME,
tmFecFinPmd SMALLDATETIME,
tmDiasBase INT DEFAULT (0) NOT NULL,
tmDiasNoRem INT DEFAULT (0) NOT NULL,
tmTarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmNPrestamo INT DEFAULT (0) NOT NULL,
tmNCuota INT DEFAULT (0) NOT NULL,
tmLogPmdio VARCHAR(600),
tmNContrato INT DEFAULT (0) NOT NULL,
tmpVehiculo VARCHAR(10),
tmIdDep VARCHAR(4) NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmIdNom VARCHAR(4) NOT NULL,
tmVrSalario MONEY DEFAULT (0),
tmVrParcial MONEY DEFAULT (0) NOT NULL,
tmNitTercero VARCHAR(16)
 CONSTRAINT PK_tm_Liquida PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_LiquidatmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_LiquidatmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_LiquidatmIdDep CHECK ((len([tmIdDep]) > 0)),
 CONSTRAINT CK_tm_LiquidatmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_LiquidatmIdNom CHECK ((len([tmIdNom]) > 0)),
 CONSTRAINT CK_tm_LiquidatmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_LiquidatmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_ListaPrec ( 
tmEst CHAR(2) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Margen1 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Margen2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Margen3 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Margen4 DECIMAL(14,4) DEFAULT (0) NOT NULL,
Margen5 DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto1 DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto3 DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto4 DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto5 DECIMAL(14,4) DEFAULT (0) NOT NULL,
TrmDia1 MONEY DEFAULT (0) NOT NULL,
TrmDia2 MONEY DEFAULT (0) NOT NULL,
TrmDia3 MONEY DEFAULT (0) NOT NULL,
TrmDia4 MONEY DEFAULT (0) NOT NULL,
TrmDia5 MONEY DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
CostoAnt MONEY DEFAULT (0) NOT NULL,
CostoUlt MONEY DEFAULT (0) NOT NULL,
CostoPmd MONEY DEFAULT (0) NOT NULL,
ExistenciaCia DECIMAL(14,4) DEFAULT (0) NOT NULL,
KarTipDoc VARCHAR(3),
KarEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
KarSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
KarCostoEnt MONEY DEFAULT (0) NOT NULL,
KarCostoSal MONEY DEFAULT (0) NOT NULL,
CiaPrecio1 MONEY DEFAULT (0) NOT NULL,
CiaPrecio2 MONEY DEFAULT (0) NOT NULL,
CiaPrecio3 MONEY DEFAULT (0) NOT NULL,
CiaPrecio4 MONEY DEFAULT (0) NOT NULL,
CiaPrecio5 MONEY DEFAULT (0) NOT NULL,
CiaTarifIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
CiaIvaInc VARCHAR(10),
PrecioVenta1 MONEY DEFAULT ((0)) NOT NULL,
PrecioVenta2 MONEY DEFAULT ((0)) NOT NULL,
PrecioVenta3 MONEY DEFAULT ((0)) NOT NULL,
PrecioVenta4 MONEY DEFAULT ((0)) NOT NULL,
PrecioVenta5 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_ListaPrec PRIMARY KEY CLUSTERED (tmEst,IdProducto),
 CONSTRAINT CK_tm_ListaPrecIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_ListaPrecIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_tm_ListaPrectmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_Lot ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmLinea INT DEFAULT (0) NOT NULL,
tmNumLote VARCHAR(30) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmCdUbic VARCHAR(10),
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmCdNueUbic VARCHAR(10)
 CONSTRAINT PK_tm_Lot PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_LottmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_LottmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_LottmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_LottmNumLote CHECK ((len([tmNumLote]) > 0)))
CREATE TABLE tm_MovClientes ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('FCR') 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,
tmIdVend VARCHAR(16) NOT NULL,
tmCargos MONEY DEFAULT (0) NOT NULL,
tmAbonos MONEY DEFAULT (0) NOT NULL,
tmTimeSys SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME,
tmCdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmModalidad VARCHAR(10) NOT NULL,
tmDetalle VARCHAR(250),
tmReferencia VARCHAR(50),
tmTipRef VARCHAR(3) DEFAULT ('0') NOT NULL,
tmDocRef INT DEFAULT (0) NOT NULL,
tmIdCiaRef CHAR(2) DEFAULT ('00') NOT NULL,
tmCdLocal VARCHAR(8) NOT NULL,
tmNumForma VARCHAR(20),
tmCdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
tmBeneficiario VARCHAR(150),
tmCdForma VARCHAR(4),
tmEnEfectivo BIT DEFAULT (0) NOT NULL,
tmTotalAbono MONEY DEFAULT (0) NOT NULL,
tmVrAfavor MONEY DEFAULT (0) 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,
tmIdUsuario VARCHAR(11) NOT NULL,
tmSanClie MONEY DEFAULT (0) NOT NULL,
tmSanClieCia MONEY DEFAULT (0) NOT NULL,
tmSanAge MONEY DEFAULT (0) NOT NULL,
tmSanAgeCia MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_MovClientes PRIMARY KEY CLUSTERED (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem),
 CONSTRAINT CK_tm_MovClientestmCdBanco CHECK ((len([tmCdBanco]) > 0)),
 CONSTRAINT CK_tm_MovClientestmCdConcepto CHECK ((len([tmCdConcepto]) > 0)),
 CONSTRAINT CK_tm_MovClientestmCdLocal CHECK ((len([tmCdLocal]) > 0)),
 CONSTRAINT CK_tm_MovClientestmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdCiaCom CHECK ((len([tmIdCiaCom]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdCiaRef CHECK ((len([tmIdCiaRef]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdUsuario CHECK ((len([tmIdUsuario]) > 0)),
 CONSTRAINT CK_tm_MovClientestmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_MovClientestmModalidad CHECK ((len([tmModalidad]) > 0)),
 CONSTRAINT CK_tm_MovClientestmTipCom CHECK ((len([tmTipCom]) > 0)),
 CONSTRAINT CK_tm_MovClientestmTipDoc CHECK ((len([tmTipDoc]) > 0)),
 CONSTRAINT CK_tm_MovClientestmTipRef CHECK ((len([tmTipRef]) > 0)))
CREATE TABLE tm_MovCue ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Detalle VARCHAR(250),
VrDebito MONEY DEFAULT ((0)) NOT NULL,
VrCredito MONEY DEFAULT ((0)) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
IdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
VrBase MONEY DEFAULT ((0)) NOT NULL,
TarifaBase DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipDoc VARCHAR(3),
Documento INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01'),
CodConce VARCHAR(4),
NitDoc VARCHAR(16),
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT ((0)) NOT NULL,
FecVence SMALLDATETIME,
CodCta VARCHAR(4),
NumCheque VARCHAR(20),
Integrado BIT DEFAULT ((0)) NOT NULL,
TipoAplica CHAR(1) DEFAULT ('N'),
Consolida BIT DEFAULT ((0)) NOT NULL,
CodCargo VARCHAR(4),
NitOtros VARCHAR(16),
CodSubgpo VARCHAR(8),
CiuOrigen VARCHAR(8),
CodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
VehPropio INT DEFAULT ((0)) NOT NULL,
Referncia VARCHAR(50),
TipDocRef VARCHAR(3),
DocRef INT DEFAULT ((0)) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('01'),
VrSanCue MONEY DEFAULT ((0)) NOT NULL,
VrSanCueCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNit MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCia MONEY DEFAULT ((0)) NOT NULL,
VrSanVeh MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCia MONEY DEFAULT ((0)) NOT NULL,
VrSanCc MONEY DEFAULT ((0)) NOT NULL,
VrSanCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanCcSubCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCc MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCcSubCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAge MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCc MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCcSubCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVeh MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVehCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVehCc MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVehCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCc MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCcSubCia MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_MovCue PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_tm_MovCueCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_tm_MovCueIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_tm_MovCueIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_tm_MovCueIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_tm_MovCueIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_tm_MovCueIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_tm_MovCueIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_tm_MovCueTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_tm_MovCuetmEst CHECK ((len([tmEst])>(0))))
CREATE TABLE tm_MovInvent ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('0') NOT NULL,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
tmCdSubzona VARCHAR(4) DEFAULT ('0') NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoEnt MONEY DEFAULT (0) NOT NULL,
tmCostoSal MONEY DEFAULT (0) NOT NULL,
tmValorEnt MONEY DEFAULT (0) NOT NULL,
tmValorSal MONEY DEFAULT (0) NOT NULL,
tmDctosEnt MONEY DEFAULT (0) NOT NULL,
tmDctosSal MONEY DEFAULT (0) NOT NULL,
tmIvaEnt MONEY DEFAULT (0) NOT NULL,
tmIvaSal MONEY DEFAULT (0) NOT NULL,
tmOtrosImpEnt MONEY DEFAULT (0) NOT NULL,
tmOtrosImpSal MONEY DEFAULT (0) NOT NULL,
tmUnidVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmEntradas2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoEnt2 MONEY DEFAULT (0) NOT NULL,
tmCostoSal2 MONEY DEFAULT (0) NOT NULL,
tmValorEnt2 MONEY DEFAULT (0) NOT NULL,
tmValorSal2 MONEY DEFAULT (0) NOT NULL,
tmDctosEnt2 MONEY DEFAULT (0) NOT NULL,
tmDctosSal2 MONEY DEFAULT (0) NOT NULL,
tmIvaEnt2 MONEY DEFAULT (0) NOT NULL,
tmIvaSal2 MONEY DEFAULT (0) NOT NULL,
tmOtrosImpEnt2 MONEY DEFAULT (0) NOT NULL,
tmOtrosImpSal2 MONEY DEFAULT (0) NOT NULL,
tmUnidVolumen2 DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_MovInvent PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_MovInventtmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_MovInventtmCdLocal CHECK ((len([tmCdLocal]) > 0)),
 CONSTRAINT CK_tm_MovInventtmCdSubzona CHECK ((len([tmCdSubzona]) > 0)),
 CONSTRAINT CK_tm_MovInventtmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_MovInventtmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_MovInventtmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_MovInventtmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_MovInventtmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_MovInventtmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_MovInventtmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_MovInventtmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_MovTanques ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdTanque VARCHAR(4) DEFAULT ('0') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoAnt MONEY DEFAULT (0) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoEnt MONEY DEFAULT (0) NOT NULL,
tmDevEnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoDve MONEY DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoSal MONEY DEFAULT (0) NOT NULL,
tmDevSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoDvs MONEY DEFAULT (0) NOT NULL,
tmFacturas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoFac MONEY DEFAULT (0) NOT NULL,
tmDevFact DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoDfc MONEY DEFAULT (0) NOT NULL,
tmAjusteSob DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoAjs MONEY DEFAULT (0) NOT NULL,
tmAjusteFal DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoAjf MONEY DEFAULT (0) NOT NULL,
tmPlanillas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoPla MONEY DEFAULT (0) NOT NULL,
tmDevPlanillas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoDvp MONEY DEFAULT (0) NOT NULL,
tmNotasCalib DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoNot MONEY DEFAULT (0) NOT NULL,
tmTraslados DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoTra MONEY DEFAULT (0) NOT NULL,
tmOtros DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoOtr MONEY DEFAULT (0) NOT NULL,
tmNuevoSaldo DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoNsal MONEY DEFAULT (0) NOT NULL,
tmCantFisico DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCantAgua DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDiferencia DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSaldoAntCia DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoSanCia MONEY DEFAULT (0) NOT NULL,
tmSaldoAntTan DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoSanTan MONEY DEFAULT (0) NOT NULL,
tmSaldoAntPro DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoSanPro MONEY DEFAULT (0) NOT NULL,
tmSaldoAntDia DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoAntDia MONEY DEFAULT (0) NOT NULL,
tmUndsEnt DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsDve DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsFac DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsDfc DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsSal DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsDvs DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsOtr DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
tmUndsDot DECIMAL(16,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_MovTanques PRIMARY KEY CLUSTERED (tmEst,tmIdProducto,tmIdTanque,tmItem),
 CONSTRAINT CK_tm_MovTanquestmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_MovTanquestmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_MovTanquestmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_MovTanquestmIdTanque CHECK ((len([tmIdTanque]) > 0)))
CREATE TABLE tm_MovVentas ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('0') NOT NULL,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
tmCdSubzona VARCHAR(4) DEFAULT ('0') NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoEnt MONEY DEFAULT (0) NOT NULL,
tmCostoSal MONEY DEFAULT (0) NOT NULL,
tmValorEnt MONEY DEFAULT (0) NOT NULL,
tmValorSal MONEY DEFAULT (0) NOT NULL,
tmDctosEnt MONEY DEFAULT (0) NOT NULL,
tmDctosSal MONEY DEFAULT (0) NOT NULL,
tmIvaEnt MONEY DEFAULT (0) NOT NULL,
tmIvaSal MONEY DEFAULT (0) NOT NULL,
tmImpGlobalEnt MONEY DEFAULT (0) NOT NULL,
tmImpGlobalSal MONEY DEFAULT (0) NOT NULL,
tmOtrosEnt MONEY DEFAULT (0) NOT NULL,
tmOtrosSal MONEY DEFAULT (0) NOT NULL,
tmUnidVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmEntradas2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCostoEnt2 MONEY DEFAULT (0) NOT NULL,
tmCostoSal2 MONEY DEFAULT (0) NOT NULL,
tmValorEnt2 MONEY DEFAULT (0) NOT NULL,
tmValorSal2 MONEY DEFAULT (0) NOT NULL,
tmDctosEnt2 MONEY DEFAULT (0) NOT NULL,
tmDctosSal2 MONEY DEFAULT (0) NOT NULL,
tmIvaEnt2 MONEY DEFAULT (0) NOT NULL,
tmIvaSal2 MONEY DEFAULT (0) NOT NULL,
tmImpGlobalEnt2 MONEY DEFAULT (0) NOT NULL,
tmImpGlobalSal2 MONEY DEFAULT (0) NOT NULL,
tmOtrosEnt2 MONEY DEFAULT (0) NOT NULL,
tmOtrosSal2 MONEY DEFAULT (0) NOT NULL,
tmUnidVolumen2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmImpConEnt MONEY DEFAULT ((0)) NOT NULL,
tmImpConSal MONEY DEFAULT ((0)) NOT NULL,
tmImpConEnt2 MONEY DEFAULT ((0)) NOT NULL,
tmImpConSal2 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_MovVentas PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_MovVentastmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_MovVentastmCdLocal CHECK ((len([tmCdLocal]) > 0)),
 CONSTRAINT CK_tm_MovVentastmCdSubzona CHECK ((len([tmCdSubzona]) > 0)),
 CONSTRAINT CK_tm_MovVentastmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_MovVentastmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_MovVentastmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_MovVentastmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_MovVentastmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_MovVentastmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_MovVentastmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_MovVentastmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_MttoDetalle ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmIdConc VARCHAR(4) NOT NULL,
tmDescripcion VARCHAR(1000) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
tmUndMed VARCHAR(50),
tmCdMtto VARCHAR(4),
tmIdEstado VARCHAR(4) NOT NULL,
tmIdOperario VARCHAR(16) NOT NULL,
tmNumVehic VARCHAR(10),
tmNumParte VARCHAR(20),
tmReqRep BIT DEFAULT ((0)) NOT NULL,
tmReqMO BIT DEFAULT ((0)) NOT NULL,
tmTipoServ VARCHAR(10),
tmCdCentro VARCHAR(4),
tmNitTercero VARCHAR(16)
 CONSTRAINT PK_tm_MttoDetalle PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_MttoDetalletmDescripcion CHECK ((len([tmDescripcion])>(0))),
 CONSTRAINT CK_tm_MttoDetalletmIdConc CHECK ((len([tmIdConc])>(0))),
 CONSTRAINT CK_tm_MttoDetalletmIdEstado CHECK ((len([tmIdEstado])>(0))),
 CONSTRAINT CK_tm_MttoDetalletmIdOperario CHECK ((len([tmIdOperario])>(0))),
 CONSTRAINT CK_tm_MttoDetalletmNumero CHECK ((len([tmNumero])>(0))))
CREATE TABLE tm_NiifCom ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmSaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
tmTotalDebitos MONEY DEFAULT ((0)) NOT NULL,
tmTotalCreditos MONEY DEFAULT ((0)) NOT NULL,
tmNuevoSaldo MONEY DEFAULT ((0)) NOT NULL,
tmSaldoAnterior2 MONEY DEFAULT ((0)) NOT NULL,
tmTotalDebitos2 MONEY DEFAULT ((0)) NOT NULL,
tmTotalCreditos2 MONEY DEFAULT ((0)) NOT NULL,
tmNuevoSaldo2 MONEY DEFAULT ((0)) NOT NULL,
tmVrPresupto MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_NiifCom PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmIdCia,tmItem),
 CONSTRAINT CK_tm_NiifComtmCodAgncia CHECK ((len([tmCodAgncia])>(0))),
 CONSTRAINT CK_tm_NiifComtmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_NiifComtmIdCCosto CHECK ((len([tmIdCCosto])>(0))),
 CONSTRAINT CK_tm_NiifComtmIdCuenta CHECK ((len([tmIdCuenta])>(0))),
 CONSTRAINT CK_tm_NiifComtmIdSubCos CHECK ((len([tmIdSubCos])>(0))),
 CONSTRAINT CK_tm_NiifComtmIdTercero CHECK ((len([tmIdTercero])>(0))),
 CONSTRAINT CK_tm_NiifComtmIdVehiculo CHECK ((len([tmIdVehiculo])>(0))),
 CONSTRAINT CK_tm_NiifComtmTipo CHECK ((len([tmTipo])>(0))))
CREATE TABLE tm_NiifGen ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmSaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
tmTotalDebitos MONEY DEFAULT ((0)) NOT NULL,
tmTotalCreditos MONEY DEFAULT ((0)) NOT NULL,
tmNuevoSaldo MONEY DEFAULT ((0)) NOT NULL,
tmSalAnt2 MONEY DEFAULT ((0)) NOT NULL,
tmDebitos2 MONEY DEFAULT ((0)) NOT NULL,
tmCreditos2 MONEY DEFAULT ((0)) NOT NULL,
tmSaldo2 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_NiifGen PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmIdCia),
 CONSTRAINT CK_tm_NiifGentmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_NiifGentmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_NiifGentmIdCuenta CHECK ((len([tmIdCuenta])>(0))))
CREATE TABLE tm_NiifGyp ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmTipoAfi INT DEFAULT ((0)) NOT NULL,
tmSaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
tmTotalDebitos MONEY DEFAULT ((0)) NOT NULL,
tmTotalCreditos MONEY DEFAULT ((0)) NOT NULL,
tmNuevoSaldo MONEY DEFAULT ((0)) NOT NULL,
tmSalAnt2 MONEY DEFAULT ((0)) NOT NULL,
tmDebitos2 MONEY DEFAULT ((0)) NOT NULL,
tmCreditos2 MONEY DEFAULT ((0)) NOT NULL,
tmSaldo2 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_NiifGyp PRIMARY KEY CLUSTERED (tmEst,tmIdCuenta,tmItem),
 CONSTRAINT CK_tm_NiifGyptmCodAgncia CHECK ((len([tmCodAgncia])>(0))),
 CONSTRAINT CK_tm_NiifGyptmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_NiifGyptmIdCCosto CHECK ((len([tmIdCCosto])>(0))),
 CONSTRAINT CK_tm_NiifGyptmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_NiifGyptmIdCuenta CHECK ((len([tmIdCuenta])>(0))),
 CONSTRAINT CK_tm_NiifGyptmIdSubCos CHECK ((len([tmIdSubCos])>(0))),
 CONSTRAINT CK_tm_NiifGyptmIdTercero CHECK ((len([tmIdTercero])>(0))),
 CONSTRAINT CK_tm_NiifGyptmIdVehiculo CHECK ((len([tmIdVehiculo])>(0))),
 CONSTRAINT CK_tm_NiifGyptmTipo CHECK ((len([tmTipo])>(0))))
CREATE TABLE tm_NiifLib ( 
tmItem BIGINT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipCom VARCHAR(3) NOT NULL,
tmIdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('0') NOT NULL,
tmTotalDebitos MONEY DEFAULT ((0)) NOT NULL,
tmTotalCreditos MONEY DEFAULT ((0)) NOT NULL,
tmSaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
tmSanNit MONEY DEFAULT ((0)) NOT NULL,
tmSanNitcc MONEY DEFAULT ((0)) NOT NULL,
tmSanNitCcSub MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_NiifLib PRIMARY KEY NONCLUSTERED (tmItem),
 CONSTRAINT CK_tm_NiifLibtmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_NiifLibtmIdCCosto CHECK ((len([tmIdCCosto])>(0))),
 CONSTRAINT CK_tm_NiifLibtmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_NiifLibtmIdCuenta CHECK ((len([tmIdCuenta])>(0))),
 CONSTRAINT CK_tm_NiifLibtmIdSubCos CHECK ((len([tmIdSubCos])>(0))),
 CONSTRAINT CK_tm_NiifLibtmIdTercero CHECK ((len([tmIdTercero])>(0))),
 CONSTRAINT CK_tm_NiifLibtmTipCom CHECK ((len([tmTipCom])>(0))))
CREATE TABLE tm_NiifMov ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Detalle VARCHAR(250),
VrDebito MONEY DEFAULT ((0)) NOT NULL,
VrCredito MONEY DEFAULT ((0)) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
IdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
VrBase MONEY DEFAULT ((0)) NOT NULL,
TarifaBase DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipDoc VARCHAR(3),
Documento INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01'),
CodConce VARCHAR(4),
NitDoc VARCHAR(16),
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT ((0)) NOT NULL,
FecVence SMALLDATETIME,
CodCta VARCHAR(4),
NumCheque VARCHAR(20),
Integrado BIT DEFAULT ((0)) NOT NULL,
TipoAplica CHAR(1) DEFAULT ('N'),
Consolida BIT DEFAULT ((0)) NOT NULL,
CodCargo VARCHAR(4),
NitOtros VARCHAR(16),
CodSubgpo VARCHAR(8),
CiuOrigen VARCHAR(8),
CodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
VehPropio INT DEFAULT ((0)) NOT NULL,
Referncia VARCHAR(50),
TipDocRef VARCHAR(3),
DocRef INT DEFAULT ((0)) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('01'),
VrSanCue MONEY DEFAULT ((0)) NOT NULL,
VrSanCueCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNit MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCia MONEY DEFAULT ((0)) NOT NULL,
VrSanVeh MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCia MONEY DEFAULT ((0)) NOT NULL,
VrSanCc MONEY DEFAULT ((0)) NOT NULL,
VrSanCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanCcSubCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCc MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanNitCcSubCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAge MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCc MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanNitAgeCcSubCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVeh MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVehCia MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVehCc MONEY DEFAULT ((0)) NOT NULL,
VrSanNitVehCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCc MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCcCia MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCcSub MONEY DEFAULT ((0)) NOT NULL,
VrSanVehCcSubCia MONEY DEFAULT ((0)) NOT NULL,
CodCuentaCG VARCHAR(16)
 CONSTRAINT PK_tm_NiifMov PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_tm_NiifMovCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_tm_NiifMovIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_tm_NiifMovIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_tm_NiifMovIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_tm_NiifMovIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_tm_NiifMovIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_tm_NiifMovIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_tm_NiifMovTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_tm_NiifMovtmEst CHECK ((len([tmEst])>(0))))
CREATE TABLE tm_NivCue ( 
tmIdCuenta VARCHAR(16) NOT NULL,
tmNivel1 VARCHAR(100) NOT NULL,
tmNivel2 VARCHAR(100) NOT NULL,
tmNivel4 VARCHAR(100) NOT NULL,
tmNivel6 VARCHAR(100) NOT NULL,
tmNivel9 VARCHAR(100),
tmNivel12 VARCHAR(100)
 CONSTRAINT PK_tm_NivCue PRIMARY KEY CLUSTERED (tmIdCuenta),
 CONSTRAINT CK_tm_NivCuetmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_NivCuetmNivel1 CHECK ((len([tmNivel1]) > 0)),
 CONSTRAINT CK_tm_NivCuetmNivel2 CHECK ((len([tmNivel2]) > 0)),
 CONSTRAINT CK_tm_NivCuetmNivel4 CHECK ((len([tmNivel4]) > 0)),
 CONSTRAINT CK_tm_NivCuetmNivel6 CHECK ((len([tmNivel6]) > 0)))
CREATE TABLE tm_NivCueNiif ( 
tmIdCuenta VARCHAR(16) NOT NULL,
tmNivel1 VARCHAR(100) NOT NULL,
tmNivel2 VARCHAR(100) NOT NULL,
tmNivel4 VARCHAR(100),
tmNivel6 VARCHAR(100),
tmNivel9 VARCHAR(100),
tmNivel12 VARCHAR(100)
 CONSTRAINT PK_tm_NivCueNiif PRIMARY KEY CLUSTERED (tmIdCuenta),
 CONSTRAINT CK_tm_NivCueNiiftmIdCuenta CHECK ((len([tmIdCuenta])>(0))),
 CONSTRAINT CK_tm_NivCueNiiftmNivel1 CHECK ((len([tmNivel1])>(0))),
 CONSTRAINT CK_tm_NivCueNiiftmNivel2 CHECK ((len([tmNivel2])>(0))))
CREATE TABLE tm_NomHoras ( 
tmIdEmpleado VARCHAR(16) NOT NULL,
tmNContrato INT DEFAULT (0) NOT NULL,
tmHorDiurno DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorNocturno DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorExtraDia DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorExtraNoc DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorRecNoc DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorDomDia DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorDomNoc DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorExtDom DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHorExtDomNoc DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrHoras1 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrHoras2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrHoras3 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrHoras4 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdArea VARCHAR(4) NOT NULL,
tmIdDep VARCHAR(4) NOT NULL,
tmIdInstala VARCHAR(4) NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmIdNom VARCHAR(4) NOT NULL,
tmVrSalario MONEY DEFAULT (0) NOT NULL,
tmVrATrans MONEY DEFAULT (0) NOT NULL,
tmpVehiculo VARCHAR(10),
tmTipoLiquida CHAR(1)
 CONSTRAINT PK_tm_NomHoras PRIMARY KEY CLUSTERED (tmIdEmpleado,tmNContrato),
 CONSTRAINT CK_tm_NomHorastmIdArea CHECK ((len([tmIdArea]) > 0)),
 CONSTRAINT CK_tm_NomHorastmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_NomHorastmIdDep CHECK ((len([tmIdDep]) > 0)),
 CONSTRAINT CK_tm_NomHorastmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_NomHorastmIdInstala CHECK ((len([tmIdInstala]) > 0)),
 CONSTRAINT CK_tm_NomHorastmIdNom CHECK ((len([tmIdNom]) > 0)),
 CONSTRAINT CK_tm_NomHorastmIdSubCos CHECK ((len([tmIdSubCos]) > 0)))
CREATE TABLE tm_Nomina ( 
tmNumero VARCHAR(5) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmClaseCon VARCHAR(10) NOT NULL,
tmDetalle VARCHAR(100),
tmCantDevg DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmCantDed DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmVrTotDevg MONEY DEFAULT (0) NOT NULL,
tmVrTotDed MONEY DEFAULT (0) NOT NULL,
tmUnidad VARCHAR(10) DEFAULT ('UNIDADES'),
tmClaseLiq VARCHAR(10) DEFAULT ('NOMINA') NOT NULL,
tmVrOrigen MONEY DEFAULT (0) NOT NULL,
tmTarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmDiasCalc DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmDiasNov DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmCodFondo VARCHAR(8),
tmNPrestamo INT DEFAULT (0) NOT NULL,
tmNCuota INT DEFAULT (0) NOT NULL,
tmOrigCargue VARCHAR(10),
tmVrBaseLiq MONEY DEFAULT (0) NOT NULL,
tmNContto INT DEFAULT (0) NOT NULL,
tmFecIni SMALLDATETIME NOT NULL,
tmFecFin SMALLDATETIME NOT NULL,
tmIdPeriodo VARCHAR(8),
tmFecUltLiq SMALLDATETIME,
tmFecIniPmd SMALLDATETIME,
tmFecFinPmd SMALLDATETIME,
tmLogPmdio VARCHAR(600),
tmVrPension MONEY DEFAULT (0) NOT NULL,
tmVrSalud MONEY DEFAULT (0) NOT NULL,
tmBasExceso MONEY DEFAULT ((0)) NOT NULL,
tmNitTercero VARCHAR(16),
tmHoraInicial DATETIME,
tmHoraFinal DATETIME,
tmTipoInc VARCHAR(20)
 CONSTRAINT PK_tm_Nomina PRIMARY KEY CLUSTERED (tmNumero,tmIdEmpleado,tmItem),
 CONSTRAINT CK_tm_NominatmClaseCon CHECK ((len([tmClaseCon]) > 0)),
 CONSTRAINT CK_tm_NominatmClaseLiq CHECK ((len([tmClaseLiq]) > 0)),
 CONSTRAINT CK_tm_NominatmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_NominatmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_NominatmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_NomRes ( 
tmNumero VARCHAR(5) NOT NULL,
tmIdEmpleado VARCHAR(16) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmNContrato INT DEFAULT (0) NOT NULL,
tmFecInicial SMALLDATETIME NOT NULL,
tmFecFinal SMALLDATETIME NOT NULL,
tmIdPeriodo VARCHAR(8),
tmIdArea VARCHAR(4) NOT NULL,
tmIdDep VARCHAR(4) NOT NULL,
tmIdInstala VARCHAR(4) NOT NULL,
tmIdCCosto VARCHAR(16) NOT NULL,
tmIdSubCos VARCHAR(16) NOT NULL,
tmIdNom VARCHAR(4) NOT NULL,
tmVrSalario MONEY DEFAULT (0) NOT NULL,
tmVrATrans MONEY DEFAULT (0) NOT NULL,
tmpVehiculo VARCHAR(10),
tmTipCom VARCHAR(3),
tmComprobante INT DEFAULT (0) NOT NULL,
tmIdCiaCom CHAR(2),
tmObservacion VARCHAR(250),
tmEsRetiro BIT DEFAULT (0) NOT NULL,
tmNLiqRet INT DEFAULT (0) NOT NULL,
tmTipoLiq CHAR(1) DEFAULT ('M') NOT NULL,
tmDetalle VARCHAR(100),
tmCantDevg DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCantDed DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmVrTotDevg MONEY DEFAULT (0) NOT NULL,
tmVrTotDed MONEY DEFAULT (0) NOT NULL,
tmUnidad VARCHAR(10) DEFAULT ('UNIDADES'),
tmClaseLiq VARCHAR(10) DEFAULT ('NOMINA') NOT NULL,
tmVrOrigen MONEY DEFAULT (0) NOT NULL,
tmTarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDiasCalc DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDiasNov DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCodFondo VARCHAR(8),
tmNPrestamo INT DEFAULT (0) NOT NULL,
tmNCuota INT DEFAULT (0) NOT NULL,
tmVrBaseLiq MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_NomRes PRIMARY KEY CLUSTERED (tmNumero,tmIdEmpleado,tmIdConcepto,tmItem),
 CONSTRAINT CK_tm_NomRestmClaseLiq CHECK ((len([tmClaseLiq]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdArea CHECK ((len([tmIdArea]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdCCosto CHECK ((len([tmIdCCosto]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdDep CHECK ((len([tmIdDep]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdEmpleado CHECK ((len([tmIdEmpleado]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdInstala CHECK ((len([tmIdInstala]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdNom CHECK ((len([tmIdNom]) > 0)),
 CONSTRAINT CK_tm_NomRestmIdSubCos CHECK ((len([tmIdSubCos]) > 0)),
 CONSTRAINT CK_tm_NomRestmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_NomRestmTipoLiq CHECK ((len([tmTipoLiq]) > 0)))
CREATE TABLE tm_OccComp ( 
tmTipDoc VARCHAR(3) DEFAULT ('OCC') NOT NULL,
tmOCargue INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmNumComp INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDescProd VARCHAR(50),
tmComp2 INT DEFAULT (0),
tmIdProd2 VARCHAR(16),
tmDescProd2 VARCHAR(50),
tmCantidad2 DECIMAL(14,4) DEFAULT (0),
tmComp3 INT DEFAULT (0),
tmIdProd3 VARCHAR(16),
tmDescProd3 VARCHAR(50),
tmCantidad3 DECIMAL(14,4) DEFAULT (0),
tmComp4 INT DEFAULT (0),
tmIdProd4 VARCHAR(16),
tmDescProd4 VARCHAR(50),
tmCantidad4 DECIMAL(14,4) DEFAULT (0),
tmComp5 INT DEFAULT (0),
tmIdProd5 VARCHAR(16),
tmDescProd5 VARCHAR(50),
tmCantidad5 DECIMAL(14,4) DEFAULT (0)
 CONSTRAINT PK_tm_OccComp PRIMARY KEY CLUSTERED (tmTipDoc,tmOCargue,tmIdCia,tmNumComp),
 CONSTRAINT CK_tm_OccComptmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_OccComptmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_OccComptmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_Pagos ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdForma VARCHAR(4) DEFAULT ('EFE') NOT NULL,
tmDetalle VARCHAR(150) NOT NULL,
tmVrPagado MONEY DEFAULT (0) NOT NULL,
tmVrCambio MONEY DEFAULT (0) NOT NULL,
tmEsCaja BIT DEFAULT (1) NOT NULL,
tmIdBanco VARCHAR(4) NOT NULL,
tmNitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNumForma VARCHAR(20),
tmFecForma SMALLDATETIME,
tmCtaForma VARCHAR(30),
tmBeneficiario VARCHAR(150),
tmReferncia1 VARCHAR(50),
tmReferncia2 VARCHAR(50),
tmCdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
tmNumAutoriza VARCHAR(30),
tmVrDenom MONEY DEFAULT (0) NOT NULL,
tmCantidad INT DEFAULT (0) NOT NULL,
tmTipDenom CHAR(1) DEFAULT ('B') NOT NULL,
tmTipRef VARCHAR(3) DEFAULT ('0') NOT NULL,
tmDocRef INT DEFAULT (0) NOT NULL,
tmIdCiaRef CHAR(2) DEFAULT ('00') NOT NULL,
tmItemDoc INT DEFAULT (0) NOT NULL,
tmCdCta VARCHAR(4),
tmCliente VARCHAR(150),
tmTipDoc VARCHAR(3),
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01'),
tmTipAplica VARCHAR(10)
 CONSTRAINT PK_tm_Pagos PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PagostmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_PagostmCdLocal CHECK ((len([tmCdLocal]) > 0)),
 CONSTRAINT CK_tm_PagostmDetalle CHECK ((len([tmDetalle]) > 0)),
 CONSTRAINT CK_tm_PagostmIdBanco CHECK ((len([tmIdBanco]) > 0)),
 CONSTRAINT CK_tm_PagostmIdCiaRef CHECK ((len([tmIdCiaRef]) > 0)),
 CONSTRAINT CK_tm_PagostmIdForma CHECK ((len([tmIdForma]) > 0)),
 CONSTRAINT CK_tm_PagostmNitCliente CHECK ((len([tmNitCliente]) > 0)),
 CONSTRAINT CK_tm_PagostmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_PagostmTipDenom CHECK ((len([tmTipDenom]) > 0)),
 CONSTRAINT CK_tm_PagostmTipRef CHECK ((len([tmTipRef]) > 0)))
CREATE TABLE tm_Plasueldos ( 
tmIdPeriodo VARCHAR(8) NOT NULL,
tmKeyRegistro VARCHAR(30) NOT NULL,
tmDias DECIMAL(10,4) DEFAULT (0) NOT NULL,
tmVrBasico MONEY DEFAULT (0) NOT NULL,
tmVrAuxtrans MONEY DEFAULT (0) NOT NULL,
tmVrHextras MONEY DEFAULT (0) NOT NULL,
tmVrRecargos MONEY DEFAULT (0) NOT NULL,
tmVrComision MONEY DEFAULT (0) NOT NULL,
tmVrIncapac MONEY DEFAULT (0) NOT NULL,
tmVrLicencia MONEY DEFAULT (0) NOT NULL,
tmVrVacacnes MONEY DEFAULT (0) NOT NULL,
tmVrOtrosDev MONEY DEFAULT (0) NOT NULL,
tmVrDctoPen MONEY DEFAULT (0) NOT NULL,
tmVrDctoSal MONEY DEFAULT (0) NOT NULL,
tmVrDctoFsp MONEY DEFAULT (0) NOT NULL,
tmVrRetencion MONEY DEFAULT (0) NOT NULL,
tmVrPrestmos MONEY DEFAULT (0) NOT NULL,
tmVrSanciones MONEY DEFAULT (0) NOT NULL,
tmVrOtrosDed MONEY DEFAULT (0) NOT NULL,
tmObserv VARCHAR(1000),
tmVrVacLiquida MONEY DEFAULT (0) NOT NULL,
tmVrVacPen MONEY DEFAULT (0) NOT NULL,
tmVrVacSal MONEY DEFAULT (0) NOT NULL,
tmVrVacFsp MONEY DEFAULT (0) NOT NULL,
tmVrVacOtr MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_Plasueldos PRIMARY KEY CLUSTERED (tmIdPeriodo,tmKeyRegistro),
 CONSTRAINT CK_tm_PlasueldostmIdPeriodo CHECK ((len([tmIdPeriodo]) > 0)),
 CONSTRAINT CK_tm_PlasueldostmKeyRegistro CHECK ((len([tmKeyRegistro]) > 0)))
CREATE TABLE tm_PreAbonos ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
tmIdPrestamo INT DEFAULT (0) NOT NULL,
tmIdCiaPre CHAR(2) NOT NULL,
tmItemPre INT DEFAULT (0) NOT NULL,
tmVrAbono MONEY DEFAULT (0) NOT NULL,
tmVrBaseCms MONEY DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) NOT NULL,
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(150),
tmGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTipoAplica INT DEFAULT (0) NOT NULL,
tmCodTarCom VARCHAR(4),
tmTipRec VARCHAR(3),
tmRecibo INT DEFAULT (0) NOT NULL,
tmCiaRec CHAR(2),
tmItemRec INT DEFAULT (0) NOT NULL,
tmFecPago SMALLDATETIME
 CONSTRAINT PK_tm_PreAbonos PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PreAbonostmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_PreAbonostmIdCiaPre CHECK ((len([tmIdCiaPre]) > 0)),
 CONSTRAINT CK_tm_PreAbonostmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_PreAbonostmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_PreAbonostmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_PreAbonostmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_PreCartera ( 
tmEst CHAR(2) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
NumCuota INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL,
TipoTasa VARCHAR(10),
DTF_EA DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaNom DECIMAL(16,8) DEFAULT (0) NOT NULL,
Spread_TA DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaEfe DECIMAL(16,8) DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
Concepto VARCHAR(10),
TipoCuota INT DEFAULT (0) NOT NULL,
NumCausacion INT DEFAULT (0) NOT NULL,
IdCiaCau CHAR(2) DEFAULT ('00') NOT NULL,
Detalle VARCHAR(250),
IdConcepto VARCHAR(4) NOT NULL,
FecUltPago SMALLDATETIME,
FecLiqMora SMALLDATETIME,
FechaCrea SMALLDATETIME NOT NULL,
CtaForma VARCHAR(30) NOT NULL,
Beneficiario VARCHAR(150),
RefCheque VARCHAR(50),
NumCheque VARCHAR(20),
CdBanco VARCHAR(4)
 CONSTRAINT PK_tm_PreCartera PRIMARY KEY CLUSTERED (tmEst,TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_tm_PreCarteraCtaForma CHECK ((len([CtaForma]) > 0)),
 CONSTRAINT CK_tm_PreCarteraIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_tm_PreCarteraIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_PreCarteraIdCiaCau CHECK ((len([IdCiaCau]) > 0)),
 CONSTRAINT CK_tm_PreCarteraIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_tm_PreCarteraIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_tm_PreCarteraIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_tm_PreCarteraTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_PreCarteratmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_PreCompra ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmFactura VARCHAR(20) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmDiasPlazo INT DEFAULT ((0)),
tmVrFactura MONEY DEFAULT ((0)) NOT NULL,
tmDescripcion VARCHAR(250)
 CONSTRAINT PK_tm_PreCompra PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PreCompratmFactura CHECK ((len([tmFactura])>(0))),
 CONSTRAINT CK_tm_PreCompratmNumero CHECK ((len([tmNumero])>(0))))
CREATE TABLE tm_PreCuotas ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
tmPrestamo INT DEFAULT (0) NOT NULL,
tmIdCiaPre CHAR(2) DEFAULT ('01') NOT NULL,
tmItemPre INT DEFAULT (0) NOT NULL,
tmCuota INT DEFAULT (0) NOT NULL,
tmConcepto VARCHAR(10) DEFAULT ('CAPITAL') NOT NULL,
tmFecCausa SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmVrTotal MONEY DEFAULT (0) NOT NULL,
tmTipoTasa VARCHAR(10) DEFAULT ('VARIABLE') NOT NULL,
tmDTF_EA DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmTasaNom DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmSpread DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmTasaEfe DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) NOT NULL,
tmEstado INT DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(250),
tmTotAbono MONEY DEFAULT (0) NOT NULL,
tmLinCred VARCHAR(4),
tmFactura VARCHAR(20),
tmDiasLiq INT DEFAULT (0) NOT NULL,
tmVrIntCorr MONEY DEFAULT (0) NOT NULL,
tmVrSaldo MONEY DEFAULT (0) NOT NULL,
tmUltCausac SMALLDATETIME,
tmVrAcumCap MONEY DEFAULT (0) NOT NULL,
tmNitConv VARCHAR(16),
tmConvnio INT DEFAULT (0) NOT NULL,
tmVrSeguro MONEY DEFAULT ((0)),
tmVrProrroga MONEY DEFAULT ((0)),
tmVrCustodia MONEY DEFAULT ((0)),
tmTasaCustod DECIMAL(16,8) DEFAULT ((0)),
tmTarifIva DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrIva MONEY DEFAULT ((0)) NOT NULL,
tmTarifRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrRet MONEY DEFAULT ((0)) NOT NULL,
tmPMInicio SMALLDATETIME,
tmPMFinal SMALLDATETIME,
tmPMDias INT DEFAULT ((0)) NOT NULL,
tmPMValorInt MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_PreCuotas PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PreCuotastmConcepto CHECK ((len([tmConcepto]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmIdCiaPre CHECK ((len([tmIdCiaPre]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmTipDoc CHECK ((len([tmTipDoc]) > 0)),
 CONSTRAINT CK_tm_PreCuotastmTipoTasa CHECK ((len([tmTipoTasa]) > 0)))
CREATE TABLE tm_PreExto ( 
IdReg INT IDENTITY ( 1,1 ) NOT NULL,
tmEst CHAR(2) NOT NULL,
tmTipoRep INT DEFAULT ((0)) 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))))
CREATE TABLE tm_PreFactura ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdConc VARCHAR(4) NOT NULL,
tmConcepto VARCHAR(250) NOT NULL,
tmTipoConc VARCHAR(10) DEFAULT ('INTERESES') NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmVrTotal MONEY DEFAULT (0) NOT NULL,
tmTarifIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrIva MONEY DEFAULT (0) NOT NULL,
tmTarifRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrRetfte MONEY DEFAULT (0) NOT NULL,
tmTarifIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrRetica MONEY DEFAULT (0) NOT NULL,
tmTarifDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrDcto MONEY DEFAULT (0) NOT NULL,
tmnPrestamo INT DEFAULT (0) NOT NULL,
tmCdCiaPrest CHAR(2) DEFAULT ('00') NOT NULL,
tmFecIniLiq SMALLDATETIME,
tmFecFinLiq SMALLDATETIME,
tmCantDias INT DEFAULT (0) NOT NULL,
tmCdTarifIva VARCHAR(4),
tmCdTarifRet VARCHAR(4),
tmCdTarifIca VARCHAR(4),
tmCdTarifDct VARCHAR(4)
 CONSTRAINT PK_tm_PreFactura PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PreFacturatmCdCiaPrest CHECK ((len([tmCdCiaPrest]) > 0)),
 CONSTRAINT CK_tm_PreFacturatmConcepto CHECK ((len([tmConcepto]) > 0)),
 CONSTRAINT CK_tm_PreFacturatmIdConc CHECK ((len([tmIdConc]) > 0)),
 CONSTRAINT CK_tm_PreFacturatmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_PreFacturatmTipoConc CHECK ((len([tmTipoConc]) > 0)))
CREATE TABLE tm_PreIntMora ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipDoc VARCHAR(3) NOT NULL,
tmPrestamo INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmItemPre INT DEFAULT (0) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmVrTotal MONEY DEFAULT (0) NOT NULL,
tmVrAbonado MONEY DEFAULT (0) NOT NULL,
tmFecUltLiq SMALLDATETIME NOT NULL,
tmFecIniLiq SMALLDATETIME NOT NULL,
tmFecFinLiq SMALLDATETIME NOT NULL,
tmDiasLiq INT DEFAULT (0) NOT NULL,
tmDiasGracia INT DEFAULT (0) NOT NULL,
tmBaseLiq MONEY DEFAULT (0) NOT NULL,
tmTasaEA DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmTasaEM DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmTasaDia DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmVrLiquida MONEY DEFAULT (0) NOT NULL,
tmTarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrIva MONEY DEFAULT (0) NOT NULL,
tmEstado INT DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(250),
tmLinCred VARCHAR(4),
tmNCuota INT DEFAULT (0) NOT NULL,
tmTarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrRetFte MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_PreIntMora PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PreIntMoratmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_PreIntMoratmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_PreIntMoratmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_PreIntMoratmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_PreIntMoratmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_PreIntMoratmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_PreMora ( 
tmTipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
tmIdPrestamo INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmVrCuota MONEY DEFAULT (0) NOT NULL,
tmDescCuota VARCHAR(100),
tmVrMora MONEY DEFAULT (0) NOT NULL,
tmDiasMora INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_PreMora PRIMARY KEY CLUSTERED (tmTipDoc,tmIdPrestamo,tmIdCia),
 CONSTRAINT CK_tm_PreMoratmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_PreMoratmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_PreMovi ( 
tmEst CHAR(2) DEFAULT ('01') 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,
tmIdVend VARCHAR(16) NOT NULL,
tmCargos MONEY DEFAULT (0) NOT NULL,
tmAbonos MONEY DEFAULT (0) NOT NULL,
tmNumCuota INT DEFAULT (0) NOT NULL,
tmTimeSys SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME,
tmCdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmConcepto VARCHAR(10),
tmDetalle VARCHAR(250),
tmReferencia VARCHAR(50),
tmTipoTasa VARCHAR(10),
tmDTF_EA DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmTasaNom DECIMAL(16,8) DEFAULT (0) NOT NULL,
tmPuntos 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,
tmNumForma VARCHAR(20),
tmCdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
tmBeneficiario VARCHAR(150),
tmCdForma VARCHAR(4),
tmEnEfectivo BIT DEFAULT (0) NOT NULL,
tmTotalAbono MONEY DEFAULT (0) NOT NULL,
tmVrAfavor MONEY DEFAULT (0) 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,
tmIdUsuario VARCHAR(11) NOT NULL,
tmSanClie MONEY DEFAULT (0) NOT NULL,
tmSanClieCia MONEY DEFAULT (0) NOT NULL,
tmSanAge MONEY DEFAULT (0) NOT NULL,
tmSanAgeCia MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_PreMovi PRIMARY KEY CLUSTERED (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem),
 CONSTRAINT CK_tm_PreMovitmCdBanco CHECK ((len([tmCdBanco]) > 0)),
 CONSTRAINT CK_tm_PreMovitmCdConcepto CHECK ((len([tmCdConcepto]) > 0)),
 CONSTRAINT CK_tm_PreMovitmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdCiaCom CHECK ((len([tmIdCiaCom]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdCiaRef CHECK ((len([tmIdCiaRef]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdUsuario CHECK ((len([tmIdUsuario]) > 0)),
 CONSTRAINT CK_tm_PreMovitmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_PreMovitmTipCom CHECK ((len([tmTipCom]) > 0)),
 CONSTRAINT CK_tm_PreMovitmTipDoc CHECK ((len([tmTipDoc]) > 0)),
 CONSTRAINT CK_tm_PreMovitmTipRef CHECK ((len([tmTipRef]) > 0)))
CREATE TABLE tm_PresPagos ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmNumForma VARCHAR(20) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmFecPago SMALLDATETIME NOT NULL,
tmVrCuota MONEY DEFAULT (0) NOT NULL,
tmCdBanco VARCHAR(4),
tmCtaCheque VARCHAR(30),
tmDetalle VARCHAR(150),
tmTarifSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_PresPagos PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_PresPagostmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_PresPagostmNumForma CHECK ((len([tmNumForma]) > 0)))
CREATE TABLE tm_PreVence ( 
tmEst CHAR(2) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NumCuota INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
NumDias INT DEFAULT (0) NOT NULL,
VrCuota MONEY DEFAULT (0) NOT NULL,
VrCapital MONEY DEFAULT (0) NOT NULL,
VrInteres MONEY DEFAULT (0) NOT NULL,
VrIntMora MONEY DEFAULT (0) NOT NULL,
VrAbonoCap MONEY DEFAULT (0) NOT NULL,
VrAbonoInt MONEY DEFAULT (0) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL,
TasaEfeMes DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaEfeDia DECIMAL(16,8) DEFAULT (0) NOT NULL,
TipoCuota VARCHAR(10) NOT NULL
 CONSTRAINT PK_tm_PreVence PRIMARY KEY CLUSTERED (tmEst,TipDoc,IdPrestamo,IdCia,NumCuota),
 CONSTRAINT CK_tm_PreVenceIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_tm_PreVenceTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_tm_PreVenceTipoCuota CHECK ((len([TipoCuota]) > 0)),
 CONSTRAINT CK_tm_PreVencetmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_RecAplica ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipoDoc VARCHAR(3) NOT NULL,
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCiaDoc CHAR(2) NOT NULL,
tmItemDoc INT DEFAULT (0) NOT NULL,
tmIdClase VARCHAR(4) NOT NULL,
tmIdCargo VARCHAR(4) NOT NULL,
tmValor MONEY DEFAULT (0) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdConductor VARCHAR(16) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) NOT NULL,
tmReferencia VARCHAR(20),
tmFactura VARCHAR(15),
tmDetalle VARCHAR(100),
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDescuento MONEY DEFAULT (0) NOT NULL,
tmConductor VARCHAR(100),
tmTipRec VARCHAR(3),
tmRecibo INT DEFAULT (0),
tmCiaRec CHAR(2),
tmFecRec SMALLDATETIME,
tmItemRec INT DEFAULT (0),
tmAplAnt BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_RecAplica PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_RecAplicatmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmIdCargo CHECK ((len([tmIdCargo]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmIdCiaDoc CHECK ((len([tmIdCiaDoc]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmIdClase CHECK ((len([tmIdClase]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_RecAplicatmTipoDoc CHECK ((len([tmTipoDoc]) > 0)))
CREATE TABLE tm_ReqDetalle ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmCdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmDescripcion VARCHAR(250),
tmIdSubgrupo VARCHAR(8) NOT NULL,
tmCdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdUnd VARCHAR(4) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmTipOrd VARCHAR(3) DEFAULT ('0') NOT NULL,
tmNumOrden INT DEFAULT (0) NOT NULL,
tmIdCiaOrd CHAR(2) DEFAULT ('00') NOT NULL,
tmTipSal VARCHAR(3) DEFAULT ('0') NOT NULL,
tmNSalida INT DEFAULT (0) NOT NULL,
tmIdCiaSal CHAR(2) DEFAULT ('00') NOT NULL,
tmFechaSal SMALLDATETIME,
tmCantSalida DECIMAL(14,4),
tmIdOperario VARCHAR(16),
tmCdCenServ VARCHAR(4),
tmNitTercero VARCHAR(16),
tmNumVehic VARCHAR(10),
tmNumParte VARCHAR(20),
tmEstado INT DEFAULT ((0)),
tmObservacion VARCHAR(1000),
tmCodConc VARCHAR(4),
tmVrPrecio MONEY DEFAULT ((0)) NOT NULL,
tmCodCenCto VARCHAR(16),
tmCodSubCto VARCHAR(16),
tmCantOrden DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_ReqDetalle PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_ReqDetalletmCdBodega CHECK ((len([tmCdBodega]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmCdProducto CHECK ((len([tmCdProducto]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmIdCiaOrd CHECK ((len([tmIdCiaOrd]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmIdCiaSal CHECK ((len([tmIdCiaSal]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmIdSubgrupo CHECK ((len([tmIdSubgrupo]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmIdUnd CHECK ((len([tmIdUnd]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmTipOrd CHECK ((len([tmTipOrd]) > 0)),
 CONSTRAINT CK_tm_ReqDetalletmTipSal CHECK ((len([tmTipSal]) > 0)))
CREATE TABLE tm_ResInvent ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipo INT DEFAULT (1) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmEneSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmEneEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmEneSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmFebSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmFebEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmFebSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMarSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMarEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMarSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAbrSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAbrEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAbrSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMaySaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMayEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMaySalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJunSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJunEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJunSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJulSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJulEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJulSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAgoSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAgoEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAgoSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSepSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSepEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSepSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmOctSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmOctEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmOctSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmNovSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmNovEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmNovSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDicSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDicEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDicSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_ResInvent PRIMARY KEY CLUSTERED (tmEst,tmTipo,tmItem),
 CONSTRAINT CK_tm_ResInventtmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_ResMensual ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipo INT DEFAULT (1) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmCodigo VARCHAR(16) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmIdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
tmpVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmCdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
tmCdTanque VARCHAR(4) DEFAULT ('0') NOT NULL,
tmEneSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmEneDebitos MONEY DEFAULT (0) NOT NULL,
tmEneCreditos MONEY DEFAULT (0) NOT NULL,
tmFebSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmFebDebitos MONEY DEFAULT (0) NOT NULL,
tmFebCreditos MONEY DEFAULT (0) NOT NULL,
tmMarSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmMarDebitos MONEY DEFAULT (0) NOT NULL,
tmMarCreditos MONEY DEFAULT (0) NOT NULL,
tmAbrSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmAbrDebitos MONEY DEFAULT (0) NOT NULL,
tmAbrCreditos MONEY DEFAULT (0) NOT NULL,
tmMaySaldoAnt MONEY DEFAULT (0) NOT NULL,
tmMayDebitos MONEY DEFAULT (0) NOT NULL,
tmMayCreditos MONEY DEFAULT (0) NOT NULL,
tmJunSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmJunDebitos MONEY DEFAULT (0) NOT NULL,
tmJunCreditos MONEY DEFAULT (0) NOT NULL,
tmJulSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmJulDebitos MONEY DEFAULT (0) NOT NULL,
tmJulCreditos MONEY DEFAULT (0) NOT NULL,
tmAgoSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmAgoDebitos MONEY DEFAULT (0) NOT NULL,
tmAgoCreditos MONEY DEFAULT (0) NOT NULL,
tmSepSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmSepDebitos MONEY DEFAULT (0) NOT NULL,
tmSepCreditos MONEY DEFAULT (0) NOT NULL,
tmOctSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmOctDebitos MONEY DEFAULT (0) NOT NULL,
tmOctCreditos MONEY DEFAULT (0) NOT NULL,
tmNovSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmNovDebitos MONEY DEFAULT (0) NOT NULL,
tmNovCreditos MONEY DEFAULT (0) NOT NULL,
tmDicSaldoAnt MONEY DEFAULT (0) NOT NULL,
tmDicDebitos MONEY DEFAULT (0) NOT NULL,
tmDicCreditos MONEY DEFAULT (0) NOT NULL,
tmM13SaldoAnt MONEY DEFAULT (0) NOT NULL,
tmM13Debitos MONEY DEFAULT (0) NOT NULL,
tmM13Creditos MONEY DEFAULT (0) NOT NULL,
tmTipoAfi INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_ResMensual PRIMARY KEY CLUSTERED (tmEst,tmTipo,tmItem),
 CONSTRAINT CK_tm_ResMensualtmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmCdBodega CHECK ((len([tmCdBodega]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmCdCCosto CHECK ((len([tmCdCCosto]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmCdSubCos CHECK ((len([tmCdSubCos]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmCdTanque CHECK ((len([tmCdTanque]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmCodigo CHECK ((len([tmCodigo]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmIdTercero CHECK ((len([tmIdTercero]) > 0)),
 CONSTRAINT CK_tm_ResMensualtmpVehiculo CHECK ((len([tmpVehiculo]) > 0)))
CREATE TABLE tm_Saldos ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmIdTercero VARCHAR(16) NOT NULL,
tmCdSubgrupo VARCHAR(8) DEFAULT ('0') NOT NULL,
tmSanCue MONEY DEFAULT (0) NOT NULL,
tmDebitos MONEY DEFAULT (0) NOT NULL,
tmCreditos MONEY DEFAULT (0) NOT NULL,
tmCostoAnt MONEY DEFAULT (0) NOT NULL,
tmCostoEnt MONEY DEFAULT (0) NOT NULL,
tmCostoSal MONEY DEFAULT (0) NOT NULL,
tmSaldoAnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_Saldos PRIMARY KEY CLUSTERED (tmEst,tmIdCia,tmIdCuenta,tmIdTercero,tmCdSubgrupo),
 CONSTRAINT CK_tm_SaldostmCdSubgrupo CHECK ((len([tmCdSubgrupo]) > 0)),
 CONSTRAINT CK_tm_SaldostmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_SaldostmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_SaldostmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_SaldostmIdTercero CHECK ((len([tmIdTercero]) > 0)))
CREATE TABLE tm_Semanas ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmVehiculo VARCHAR(10) NOT NULL,
tmSemana INT DEFAULT (0) NOT NULL,
tmVrTotal MONEY DEFAULT (0) NOT NULL,
tmVrPagado MONEY DEFAULT (0) NOT NULL,
tmDescripcion VARCHAR(150)
 CONSTRAINT PK_tm_Semanas PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_SemanastmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_SemanastmVehiculo CHECK ((len([tmVehiculo]) > 0)))
CREATE TABLE tm_Ser ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmNumSerial VARCHAR(30) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmCdUbic VARCHAR(10),
tmIdEstado VARCHAR(4) NOT NULL,
tmLinea INT DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(250),
tmReferencia VARCHAR(50),
tmRef2 VARCHAR(50),
tmFecRef1 SMALLDATETIME,
tmFecRef2 SMALLDATETIME,
tmUbicacion VARCHAR(50),
tmIdBodNue VARCHAR(4),
tmUbicNue VARCHAR(10),
tmNueEstado VARCHAR(4),
tmInactivo BIT DEFAULT (0) NOT NULL,
tmTipMovi VARCHAR(3)
 CONSTRAINT PK_tm_Ser PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_SertmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_SertmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_SertmIdEstado CHECK ((len([tmIdEstado]) > 0)),
 CONSTRAINT CK_tm_SertmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_SertmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_SertmNumSerial CHECK ((len([tmNumSerial]) > 0)))
CREATE TABLE tm_Sobtasas ( 
tmIdDec VARCHAR(4) NOT NULL,
tmNumDeclara INT DEFAULT (0) NOT NULL,
tmAcpmCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAcpmBase MONEY DEFAULT (0) NOT NULL,
tmAcpmValor MONEY DEFAULT (0) NOT NULL,
tmAcpmTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAcpmPrecio MONEY DEFAULT (0) NOT NULL,
tmAcpiCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAcpiBase MONEY DEFAULT (0) NOT NULL,
tmAcpiValor MONEY DEFAULT (0) NOT NULL,
tmAcpiTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAcpiPrecio MONEY DEFAULT (0) NOT NULL,
tmGcorCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGcorBase MONEY DEFAULT (0) NOT NULL,
tmGcorValor MONEY DEFAULT (0) NOT NULL,
tmGcorTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGcorPrecio MONEY DEFAULT (0) NOT NULL,
tmGextCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGextBase MONEY DEFAULT (0) NOT NULL,
tmGextValor MONEY DEFAULT (0) NOT NULL,
tmGextTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGextPrecio MONEY DEFAULT (0) NOT NULL,
tmGimpCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGimpBase MONEY DEFAULT (0) NOT NULL,
tmGimpValor MONEY DEFAULT (0) NOT NULL,
tmGimpTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGimpPrecio MONEY DEFAULT (0) NOT NULL,
tmGcoxCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGcoxBase MONEY DEFAULT (0) NOT NULL,
tmGcoxValor MONEY DEFAULT (0) NOT NULL,
tmGcoxTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGcoxPrecio MONEY DEFAULT (0) NOT NULL,
tmGeoxCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGeoxBase MONEY DEFAULT (0) NOT NULL,
tmGeoxValor MONEY DEFAULT (0) NOT NULL,
tmGeoxTarif DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmGeoxPrecio MONEY DEFAULT (0) NOT NULL,
tmAczfCant DECIMAL(14,4) DEFAULT (0),
tmAczfBase MONEY DEFAULT (0),
tmAczfValor MONEY DEFAULT (0),
tmAczfTarif DECIMAL(14,4) DEFAULT (0),
tmAczfPrecio MONEY DEFAULT (0),
tmGnzfCant DECIMAL(14,4) DEFAULT (0),
tmGnzfBase MONEY DEFAULT (0),
tmGnzfValor MONEY DEFAULT (0),
tmGnzfTarif DECIMAL(14,4) DEFAULT (0),
tmGnzfPrecio MONEY DEFAULT (0)
 CONSTRAINT PK_tm_Sobtasas PRIMARY KEY CLUSTERED (tmIdDec,tmNumDeclara),
 CONSTRAINT CK_tm_SobtasastmIdDec CHECK ((len([tmIdDec]) > 0)))
CREATE TABLE tm_Tallas ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmItemKdx INT DEFAULT ((0)) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmIdBodega VARCHAR(4) NOT NULL,
tmIdUbic VARCHAR(10) NOT NULL,
tmNumTalla VARCHAR(30) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmCdNueBod VARCHAR(4),
tmCdNueUbic VARCHAR(10),
tmCantPedido DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_Tallas PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TallastmIdBodega CHECK ((len([tmIdBodega])>(0))),
 CONSTRAINT CK_tm_TallastmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_TallastmIdProducto CHECK ((len([tmIdProducto])>(0))),
 CONSTRAINT CK_tm_TallastmIdUbic CHECK ((len([tmIdUbic])>(0))),
 CONSTRAINT CK_tm_TallastmNumero CHECK ((len([tmNumero])>(0))),
 CONSTRAINT CK_tm_TallastmNumTalla CHECK ((len([tmNumTalla])>(0))))
CREATE TABLE tm_Tanqueos ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmDocumento VARCHAR(10) NOT NULL,
tmIdTipoCom VARCHAR(4) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmValorUnitario MONEY DEFAULT (0) NOT NULL,
tmIdEstacion VARCHAR(4) NOT NULL,
tmTipoCom VARCHAR(50),
tmEstacion VARCHAR(50)
 CONSTRAINT PK_tm_Tanqueos PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TanqueostmDocumento CHECK ((len([tmDocumento]) > 0)),
 CONSTRAINT CK_tm_TanqueostmIdEstacion CHECK ((len([tmIdEstacion]) > 0)),
 CONSTRAINT CK_tm_TanqueostmIdTipoCom CHECK ((len([tmIdTipoCom]) > 0)),
 CONSTRAINT CK_tm_TanqueostmNumero CHECK ((len([tmNumero]) > 0)))
CREATE TABLE tm_TraAnt ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipAnt VARCHAR(3) DEFAULT ('ANT') NOT NULL,
tmAnticipo INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmValor MONEY DEFAULT (0) NOT NULL,
tmVrAnticipo MONEY DEFAULT (0) NOT NULL,
tmTotalAbonos MONEY DEFAULT (0) NOT NULL,
tmDetalle VARCHAR(100),
tmCdCueAnt VARCHAR(16)
 CONSTRAINT PK_tm_TraAnt PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraAnttmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_TraAnttmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraAnttmTipAnt CHECK ((len([tmTipAnt]) > 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 tm_TraConc ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmDescripcion VARCHAR(250) NOT NULL,
tmTarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmTipoConc VARCHAR(10) DEFAULT ('DEDUCCION') NOT NULL,
tmRubro VARCHAR(20) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmTarifIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmCdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNitTercero VARCHAR(16) DEFAULT ('0'),
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmTipoTarif CHAR(1) DEFAULT ('%') NOT NULL,
tmRefConc VARCHAR(50),
tmFijos BIT DEFAULT (0) NOT NULL,
tmBaseRet INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_TraConc PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraConctmCdCuenta CHECK ((len([tmCdCuenta]) > 0)),
 CONSTRAINT CK_tm_TraConctmDescripcion CHECK ((len([tmDescripcion]) > 0)),
 CONSTRAINT CK_tm_TraConctmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_TraConctmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraConctmRubro CHECK ((len([tmRubro]) > 0)),
 CONSTRAINT CK_tm_TraConctmTipoConc CHECK ((len([tmTipoConc]) > 0)),
 CONSTRAINT CK_tm_TraConctmTipoTarif CHECK ((len([tmTipoTarif]) > 0)))
CREATE TABLE tm_TraDedAnt ( 
tmEst CHAR(2) NOT NULL,
tmTipAnt VARCHAR(3) NOT NULL,
tmAnticipo INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) NOT NULL,
tmConcepto1 VARCHAR(100),
tmValor1 MONEY DEFAULT ((2)) NOT NULL,
tmConcepto2 VARCHAR(100),
tmValor2 MONEY DEFAULT ((2)) NOT NULL,
tmConcepto3 VARCHAR(100),
tmValor3 MONEY DEFAULT ((2)) NOT NULL,
tmConcepto4 VARCHAR(100),
tmValor4 MONEY DEFAULT ((2)) NOT NULL,
tmConcepto5 VARCHAR(100),
tmValor5 MONEY DEFAULT ((2)) NOT NULL
 CONSTRAINT PK_tm_TraDedAnt PRIMARY KEY CLUSTERED (tmEst,tmTipAnt,tmAnticipo,tmIdCia),
 CONSTRAINT CK_tm_TraDedAnttmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_TraDedAnttmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_TraDedAnttmTipAnt CHECK ((len([tmTipAnt])>(0))))
CREATE TABLE tm_TraDetalle ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdMercancia VARCHAR(16) NOT NULL,
tmDescripMcias VARCHAR(250) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmPesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndMed VARCHAR(10) NOT NULL,
tmdmsAlto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmdmsAncho DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmdmsLargo DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndVol VARCHAR(10) NOT NULL,
tmIdUnd VARCHAR(4) NOT NULL,
tmIdEmp VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdNat VARCHAR(4) NOT NULL,
tmIdMnjo VARCHAR(4) NOT NULL,
tmIdTmcia VARCHAR(4) NOT NULL,
tmCdRango VARCHAR(4),
tmCases INT DEFAULT (0) NOT NULL,
tmCajas INT DEFAULT (0) NOT NULL,
tmPalets INT DEFAULT (0) NOT NULL,
tmRemision DECIMAL(18,2) DEFAULT (0) NOT NULL,
tmNumOrden INT DEFAULT (0) NOT NULL,
tmNitRemite VARCHAR(16) NOT NULL,
tmRemitente VARCHAR(250) NOT NULL,
tmDirOrigen VARCHAR(250) NOT NULL,
tmIdOrigen VARCHAR(8) NOT NULL,
tmNitDestntario VARCHAR(16) NOT NULL,
tmDestinatario VARCHAR(250) DEFAULT ('varios') NOT NULL,
tmDirDestino VARCHAR(250) NOT NULL,
tmIdDestino VARCHAR(8) NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmTipoVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
tmTarifClie MONEY DEFAULT (0) NOT NULL,
tmTarifPago MONEY DEFAULT (0) NOT NULL,
tmTarifTabla MONEY DEFAULT (0) NOT NULL,
tmVrDeclarado MONEY DEFAULT (0) NOT NULL,
tmVrSeguro MONEY DEFAULT (0) NOT NULL,
tmTarifSeguro DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDocCliente VARCHAR(30),
tmReferencia1 VARCHAR(50),
tmReferencia2 VARCHAR(50),
tmReferencia3 VARCHAR(50),
tmContenedor1 VARCHAR(50),
tmContenedor2 VARCHAR(50),
tmUndTarifa VARCHAR(10) DEFAULT ('PESO'),
tmTipRem VARCHAR(3),
tmRemesa INT DEFAULT (0) NOT NULL,
tmIdCiaRem CHAR(2) DEFAULT ('00'),
tmItemRem INT DEFAULT (0) NOT NULL,
tmNumMintrans DECIMAL(14,2) DEFAULT (0) NOT NULL,
tmPesoCont DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndTarPago VARCHAR(10) DEFAULT ('PESO'),
tmCodBodega VARCHAR(4),
tmTipoTraslado INT DEFAULT ((0)),
tmTieCargue DECIMAL(14,4) DEFAULT ((0)),
tmTieDesc DECIMAL(14,4) DEFAULT ((0)),
tmFecIniCargue SMALLDATETIME,
tmFecFinCargue SMALLDATETIME,
tmFecInidesc SMALLDATETIME,
tmFecFindesc SMALLDATETIME,
tmCdTipoVeh VARCHAR(4),
tmTipoServicio VARCHAR(10),
tmSedeRem VARCHAR(10),
tmSedeDest VARCHAR(10),
tmFecLlegaCargue SMALLDATETIME,
tmFecLlegaDesc SMALLDATETIME,
tmMinCargue INT DEFAULT ((0)),
tmMinDescargue INT DEFAULT ((0))
 CONSTRAINT PK_tm_TraDetalle PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraDetalletmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmDescripMcias CHECK ((len([tmDescripMcias]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmDestinatario CHECK ((len([tmDestinatario]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmDirDestino CHECK ((len([tmDirDestino]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmDirOrigen CHECK ((len([tmDirOrigen]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdDestino CHECK ((len([tmIdDestino]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdEmbalaje CHECK ((len([tmIdEmp]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdMercancia CHECK ((len([tmIdMercancia]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdMnjo CHECK ((len([tmIdMnjo]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdNat CHECK ((len([tmIdNat]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdOrigen CHECK ((len([tmIdOrigen]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdTmcia CHECK ((len([tmIdTmcia]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmIdUnd CHECK ((len([tmIdUnd]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmNitDestntario CHECK ((len([tmNitDestntario]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmNitRemite CHECK ((len([tmNitRemite]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmRemitente CHECK ((len([tmRemitente]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmTipoVehic CHECK ((len([tmTipoVehic]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmUndMed CHECK ((len([tmUndMed]) > 0)),
 CONSTRAINT CK_tm_TraDetalletmUndVol CHECK ((len([tmUndVol]) > 0)))
CREATE TABLE tm_TraDetConc ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmDescripcion VARCHAR(250) NOT NULL,
tmTipoConc VARCHAR(10) DEFAULT ('CTACOBRAR') NOT NULL,
tmVrDebito MONEY DEFAULT (0) NOT NULL,
tmVrCredito MONEY DEFAULT (0) NOT NULL,
tmCdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
tmNitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmpVehiculo VARCHAR(10),
tmTipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
tmVrBase MONEY DEFAULT (0) NOT NULL,
tmTarifBase DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmReferencia VARCHAR(50),
tmTipDocRef VARCHAR(3),
tmDocRef INT DEFAULT (0) NOT NULL,
tmTipFac VARCHAR(3),
tmFactura VARCHAR(15),
tmIdCiaFac CHAR(2) DEFAULT ('01'),
tmItemFac INT DEFAULT (0) NOT NULL,
tmFecVence SMALLDATETIME,
tmCodAgncia VARCHAR(16),
tmCantComb DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDocSop BIT DEFAULT ((0)) NOT NULL,
tmTipoImp VARCHAR(4),
tmCodTarImp VARCHAR(4),
tmItemBase INT DEFAULT ((0)) NOT NULL,
tmTipoDs VARCHAR(3),
tmNumDs INT DEFAULT ((0)) NOT NULL,
tmIdCiaDs CHAR(2)
 CONSTRAINT PK_tm_TraDetConc PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraDetConctmCdCuenta CHECK ((len([tmCdCuenta]) > 0)),
 CONSTRAINT CK_tm_TraDetConctmDescripcion CHECK ((len([tmDescripcion]) > 0)),
 CONSTRAINT CK_tm_TraDetConctmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_TraDetConctmNitTercero CHECK ((len([tmNitTercero]) > 0)),
 CONSTRAINT CK_tm_TraDetConctmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraDetConctmTipoAfiVehic CHECK ((len([tmTipoAfiVehic]) > 0)),
 CONSTRAINT CK_tm_TraDetConctmTipoConc CHECK ((len([tmTipoConc]) > 0)))
CREATE TABLE tm_TraInfOper ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
IdEst CHAR(2) NOT NULL,
TipoRep INT DEFAULT ((0)) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nRemolque VARCHAR(10),
TipoOrd VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2),
Remesa INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2)
 CONSTRAINT PK_tm_TraInfOper PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_tm_TraInfOperIdEst CHECK ((len([IdEst])>(0))),
 CONSTRAINT CK_tm_TraInfOperIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_tm_TraInfOperIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_tm_TraInfOperTipoOrd CHECK ((len([TipoOrd])>(0))))
CREATE TABLE tm_TraLegMuc ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT ((0)) NOT NULL,
tmTipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
tmManifiesto INT DEFAULT ((0)) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmpVehiculo VARCHAR(10),
tmCedConductor VARCHAR(16),
tmIdPoseedor VARCHAR(16)
 CONSTRAINT PK_tm_TraLegMuc PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraLegMuctmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_TraLegMuctmNumero CHECK ((len([tmNumero])>(0))),
 CONSTRAINT CK_tm_TraLegMuctmTipMuc CHECK ((len([tmTipMuc])>(0))))
CREATE TABLE tm_TraLiqCausac ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipCau VARCHAR(3) DEFAULT ('CCD') NOT NULL,
tmCausacion INT DEFAULT (0) NOT NULL,
tmIdCiaCau CHAR(2) DEFAULT ('01') NOT NULL,
tmItemCau INT DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmDescripcion VARCHAR(250) NOT NULL,
tmVrAbono MONEY DEFAULT (0) NOT NULL,
tmNit VARCHAR(16) NOT NULL,
tmVehiculo VARCHAR(10),
tmTipOdp VARCHAR(3) DEFAULT ('ODP'),
tmOrdenPago INT DEFAULT (0) NOT NULL,
tmIdCiaOdp CHAR(2),
tmTipMuc VARCHAR(3) DEFAULT ('MUC'),
tmManifiesto INT DEFAULT (0) NOT NULL,
tmIdCiaMuc CHAR(2),
tmItemFact INT DEFAULT (0) NOT NULL,
tmVrSaldo MONEY DEFAULT (0) NOT NULL,
tmEsVence BIT DEFAULT (0) NOT NULL,
tmCdCuenta VARCHAR(16),
tmCuePagar VARCHAR(16),
tmFactura VARCHAR(20),
tmConcValor MONEY DEFAULT (0) NOT NULL,
tmConcAbono MONEY DEFAULT (0) NOT NULL,
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmTipoFac VARCHAR(3)
 CONSTRAINT PK_tm_TraLiqCausac PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraLiqCausactmDescripcion CHECK ((len([tmDescripcion]) > 0)),
 CONSTRAINT CK_tm_TraLiqCausactmIdCiaCau CHECK ((len([tmIdCiaCau]) > 0)),
 CONSTRAINT CK_tm_TraLiqCausactmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_TraLiqCausactmNit CHECK ((len([tmNit]) > 0)),
 CONSTRAINT CK_tm_TraLiqCausactmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraLiqCausactmTipCau CHECK ((len([tmTipCau]) > 0)))
CREATE TABLE tm_TraMovAnt ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
IdEst CHAR(2) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipMuc VARCHAR(3) NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
SaldoAnt MONEY DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrPagos MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_TraMovAnt PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_tm_TraMovAntIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_tm_TraMovAntIdCiaMuc CHECK ((len([IdCiaMuc])>(0))),
 CONSTRAINT CK_tm_TraMovAntIdEst CHECK ((len([IdEst])>(0))),
 CONSTRAINT CK_tm_TraMovAntIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_tm_TraMovAntIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_tm_TraMovAntTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_tm_TraMovAntTipMuc CHECK ((len([TipMuc])>(0))))
CREATE TABLE tm_TraMovLiquida ( 
tmEst CHAR(2) NOT NULL,
tmTipo VARCHAR(3) 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,
tmFecVence SMALLDATETIME NOT NULL,
tmIdPoseedor VARCHAR(16) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmIdConcepto VARCHAR(4) NOT NULL,
tmDescripcion VARCHAR(250) NOT NULL,
tmVrDebito MONEY DEFAULT ((0)) NOT NULL,
tmVrCredito MONEY DEFAULT ((0)) NOT NULL,
tmVrAbonado MONEY DEFAULT ((0)) NOT NULL,
tmTipoVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
tmVrBase MONEY DEFAULT ((0)) NOT NULL,
tmTarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmReferencia VARCHAR(50),
tmTipDocRef VARCHAR(3),
tmDocRef INT DEFAULT ((0)) NOT NULL,
tmEstado INT DEFAULT ((0)) NOT NULL,
tmTipoLiq VARCHAR(3),
tmLiquida INT DEFAULT ((0)) NOT NULL,
tmCiaLiq CHAR(2),
tmSaldoAnt MONEY DEFAULT ((0)) NOT NULL,
tmSaldoCia MONEY DEFAULT ((0)) NOT NULL,
tmSaldoAntVeh MONEY DEFAULT ((0)) NOT NULL,
tmSaldoVehCia MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_TraMovLiquida PRIMARY KEY NONCLUSTERED (tmEst,tmTipo,tmNumero,tmIdCia,tmItem),
 CONSTRAINT CK_tm_TraMovLiquidatmDescripcion CHECK ((len([tmDescripcion])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmEst CHECK ((len([tmEst])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmIdCia CHECK ((len([tmIdCia])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmIdConcepto CHECK ((len([tmIdConcepto])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmIdPoseedor CHECK ((len([tmIdPoseedor])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmIdVehiculo CHECK ((len([tmIdVehiculo])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmTipo CHECK ((len([tmTipo])>(0))),
 CONSTRAINT CK_tm_TraMovLiquidatmTipoVehic CHECK ((len([tmTipoVehic])>(0))))
CREATE TABLE tm_TraOperarios ( 
Id VARCHAR(5) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
RazonSocial VARCHAR(250)
 CONSTRAINT PK_tm_TraOperarios PRIMARY KEY CLUSTERED (Id,Item),
 CONSTRAINT CK_tm_TraOperariosId CHECK ((len([Id])>(0))),
 CONSTRAINT CK_tm_TraOperariosIdTercero CHECK ((len([IdTercero])>(0))))
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))))
CREATE TABLE tm_TraRemCum ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipRem VARCHAR(3) DEFAULT ('RMT') NOT NULL,
tmRemesa INT DEFAULT (0) NOT NULL,
tmIdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
tmItemRem INT DEFAULT (0) NOT NULL,
tmIdMercancia VARCHAR(16) NOT NULL,
tmDescripMcias VARCHAR(250) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmPesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndMed VARCHAR(10),
tmVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndVol VARCHAR(10),
tmCases INT DEFAULT (0) NOT NULL,
tmCajas INT DEFAULT (0) NOT NULL,
tmPalets INT DEFAULT (0) NOT NULL,
tmTarifClie MONEY DEFAULT (0) NOT NULL,
tmTarifPago MONEY DEFAULT (0) NOT NULL,
tmUndTarif VARCHAR(10) DEFAULT ('PESO') NOT NULL,
tmUndTarifPago VARCHAR(10) DEFAULT ('PESO') NOT NULL,
tmCantCargue DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmPesoCargue DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVolCargue DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmCasesCargue INT DEFAULT (0) NOT NULL,
tmCajasCargue INT DEFAULT (0) NOT NULL,
tmPaletsCargue INT DEFAULT (0) NOT NULL,
tmEstadoCump INT DEFAULT (1) NOT NULL,
tmRemision DECIMAL(18,2) DEFAULT (0) NOT NULL,
tmDocCliente VARCHAR(30),
tmReferencia1 VARCHAR(50),
tmReferencia2 VARCHAR(50),
tmReferencia3 VARCHAR(50),
tmDetalle VARCHAR(250),
tmNitRemite VARCHAR(16) NOT NULL,
tmRemitente VARCHAR(250),
tmDirOrigen VARCHAR(250),
tmIdOrigen VARCHAR(8) NOT NULL,
tmNitDestntario VARCHAR(16) NOT NULL,
tmDestinatario VARCHAR(250),
tmDirDestino VARCHAR(250),
tmIdDestino VARCHAR(8) NOT NULL,
tmTarifTabla MONEY DEFAULT ((0)),
tmTipoCum VARCHAR(3),
tmMotivoSusp VARCHAR(3),
tmHoraLlegaCargue SMALLDATETIME,
tmHoraEntraCargue SMALLDATETIME,
tmHoraSaleCargue SMALLDATETIME,
tmHoraLlegaDescargue SMALLDATETIME,
tmHoraEntraDescargue SMALLDATETIME,
tmHoraSaleDescargue SMALLDATETIME,
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmNitCliente VARCHAR(16)
 CONSTRAINT PK_tm_TraRemCum PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraRemCumtmDescripMcias CHECK ((len([tmDescripMcias]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmIdCiaRem CHECK ((len([tmIdCiaRem]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmIdDestino CHECK ((len([tmIdDestino]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmIdMercancia CHECK ((len([tmIdMercancia]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmIdOrigen CHECK ((len([tmIdOrigen]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmNitDestntario CHECK ((len([tmNitDestntario]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmNitRemite CHECK ((len([tmNitRemite]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmTipRem CHECK ((len([tmTipRem]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmUndTarif CHECK ((len([tmUndTarif]) > 0)),
 CONSTRAINT CK_tm_TraRemCumtmUndTarifPago CHECK ((len([tmUndTarifPago]) > 0)))
CREATE TABLE tm_TraRemFact ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipoReg INT DEFAULT (0) NOT NULL,
tmTipRem VARCHAR(3) NOT NULL,
tmRemesa INT DEFAULT (0) NOT NULL,
tmIdCiaRem CHAR(2) NOT NULL,
tmItemRem INT DEFAULT (0) NOT NULL,
tmDescripcion VARCHAR(250) NOT NULL,
tmCantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrUnitario MONEY DEFAULT (0) NOT NULL,
tmVrCosto MONEY DEFAULT (0) NOT NULL,
tmUndTarifa VARCHAR(10) DEFAULT ('PESO') NOT NULL,
tmUndCosto VARCHAR(10) DEFAULT ('PESO') NOT NULL,
tmUnidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmPesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndMed VARCHAR(10) NOT NULL,
tmVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUndVol VARCHAR(10) NOT NULL,
tmCases INT DEFAULT (0) NOT NULL,
tmCajas INT DEFAULT (0) NOT NULL,
tmPalets INT DEFAULT (0) NOT NULL,
tmTarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrIva MONEY DEFAULT (0) NOT NULL,
tmTarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrDscto MONEY DEFAULT (0) NOT NULL,
tmTarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrRetFte MONEY DEFAULT (0) NOT NULL,
tmTarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVrReteIca MONEY DEFAULT (0) NOT NULL,
tmVrFaltante MONEY DEFAULT (0) NOT NULL,
tmRemision DECIMAL(18,2) DEFAULT (0) NOT NULL,
tmDocCliente VARCHAR(30),
tmReferencia1 VARCHAR(50),
tmReferencia2 VARCHAR(50),
tmReferencia3 VARCHAR(50),
tmCdMercancia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdConc VARCHAR(4) DEFAULT ('0') NOT NULL,
tmCdCCosto VARCHAR(16),
tmCdSubCos VARCHAR(16),
tmNitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmpVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmTipoVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
tmNitRemite VARCHAR(16),
tmRemitente VARCHAR(250),
tmDirOrigen VARCHAR(250),
tmIdOrigen VARCHAR(8) NOT NULL,
tmNitDestntario VARCHAR(16),
tmDestinatario VARCHAR(250),
tmDirDestino VARCHAR(250),
tmIdDestino VARCHAR(8) NOT NULL,
tmCantFalt DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUnidadFalt VARCHAR(10),
tmCdTarRet VARCHAR(4),
tmCdTarIca VARCHAR(4),
tmCdTarDct VARCHAR(4),
tmPedRem INT DEFAULT (0) NOT NULL,
tmCiaPed CHAR(2) DEFAULT ('00'),
tmEtdoFact INT DEFAULT (0) NOT NULL,
tmFecRemesa SMALLDATETIME,
tmIntCumplido INT DEFAULT ((0)) NOT NULL,
tmVrDeclarado MONEY DEFAULT ((0)) NOT NULL,
tmTarifSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrSeguro MONEY DEFAULT ((0)) NOT NULL,
tmNitAsegurad VARCHAR(16),
tmCostoCump MONEY DEFAULT ((0)),
tmTipoOrd VARCHAR(3),
tmNumOrden INT DEFAULT ((0)),
tmIdCiaOrd CHAR(2),
tmCantPago DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
tmVrAutoIca MONEY DEFAULT ((0)) NOT NULL,
tmRemTransb INT DEFAULT ((0)) NOT NULL,
tmCostoAdic MONEY DEFAULT ((0)) NOT NULL,
tmNitMucTbdo VARCHAR(16)
 CONSTRAINT PK_tm_TraRemFact PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_TraRemFacttmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmCdConc CHECK ((len([tmCdConc]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmCdMercancia CHECK ((len([tmCdMercancia]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmDescripcion CHECK ((len([tmDescripcion]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmIdCiaRem CHECK ((len([tmIdCiaRem]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmIdDestino CHECK ((len([tmIdDestino]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmIdOrigen CHECK ((len([tmIdOrigen]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmNitTercero CHECK ((len([tmNitTercero]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmpVehiculo CHECK ((len([tmpVehiculo]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmTipoVehic CHECK ((len([tmTipoVehic]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmTipRem CHECK ((len([tmTipRem]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmUndCosto CHECK ((len([tmUndCosto]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmUndMed CHECK ((len([tmUndMed]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmUndTarifa CHECK ((len([tmUndTarifa]) > 0)),
 CONSTRAINT CK_tm_TraRemFacttmUndVol CHECK ((len([tmUndVol]) > 0)))
CREATE TABLE tm_ValesCred ( 
tmNumero VARCHAR(5) NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmTipo VARCHAR(3) NOT NULL,
tmRango INT DEFAULT (0) NOT NULL,
tmNumSerie VARCHAR(5) NOT NULL,
tmNumVale INT DEFAULT (0) NOT NULL,
tmFecha SMALLDATETIME NOT NULL,
tmHoraServ VARCHAR(10) NOT NULL,
tmIdCliente VARCHAR(16) NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdCuenta VARCHAR(16) NOT NULL,
tmNumMovil VARCHAR(10) NOT NULL,
tmCentCosto VARCHAR(50) DEFAULT ('0') NOT NULL,
tmUnidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHoraRec DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmHoraEspera DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmFactUnid BIT DEFAULT (0) NOT NULL,
tmFactRutas BIT DEFAULT (0) NOT NULL,
tmFactHoras BIT DEFAULT (0) NOT NULL,
tmVrPago MONEY DEFAULT (0) NOT NULL,
tmVrCobro MONEY DEFAULT (0) NOT NULL,
tmPlacaVeh VARCHAR(10),
tmCdConductor VARCHAR(16),
tmConductor VARCHAR(150),
tmCantidad INT DEFAULT (0) NOT NULL,
tmUsuarios VARCHAR(1000),
tmObservacion VARCHAR(1000),
tmNumAuto BIT DEFAULT (0) NOT NULL,
tmRutas VARCHAR(150),
tmRadica INT DEFAULT (0) NOT NULL,
tmCiaRad CHAR(2),
tmItemRad INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_ValesCred PRIMARY KEY CLUSTERED (tmNumero,tmItem),
 CONSTRAINT CK_tm_ValesCredtmCentCosto CHECK ((len([tmCentCosto]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmHoraServ CHECK ((len([tmHoraServ]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmIdCuenta CHECK ((len([tmIdCuenta]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmNumero CHECK ((len([tmNumero]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmNumMovil CHECK ((len([tmNumMovil]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmNumSerie CHECK ((len([tmNumSerie]) > 0)),
 CONSTRAINT CK_tm_ValesCredtmTipo CHECK ((len([tmTipo]) > 0)))
CREATE TABLE tm_vce ( 
tmTipDoc VARCHAR(3) NOT NULL,
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmValorFactura MONEY DEFAULT (0) NOT NULL,
tmValorAbono MONEY DEFAULT (0) NOT NULL,
tmIdVehiculo VARCHAR(10) NOT NULL,
tmFecUltPago SMALLDATETIME
 CONSTRAINT PK_tm_vce PRIMARY KEY CLUSTERED (tmTipDoc,tmDocumento,tmIdCia,tmItem),
 CONSTRAINT CK_tm_vcetmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_vcetmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_vcetmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_vence ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmTipDoc VARCHAR(3) NOT NULL,
tmDocumento INT DEFAULT (0) NOT NULL,
tmIdCia CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmFecEmision SMALLDATETIME NOT NULL,
tmFecVence SMALLDATETIME NOT NULL,
tmValorFactura MONEY DEFAULT (0) NOT NULL,
tmValorAbono MONEY DEFAULT (0) NOT NULL,
tmIdPropietario VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
tmIdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmVehPropio BIT DEFAULT (0) NOT NULL,
tmIdConductor VARCHAR(16) NOT NULL,
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmIdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdClase VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmFecUltPago SMALLDATETIME,
tmNotaInt INT DEFAULT (0),
tmFecUltLiquida SMALLDATETIME,
tmFactura VARCHAR(15),
tmReferencia VARCHAR(50),
tmDetalle VARCHAR(100),
tmObservacion VARCHAR(250),
tmModalidad VARCHAR(10),
tmIdEstado VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdUsuario VARCHAR(11) DEFAULT ('0') NOT NULL,
tmTipCom VARCHAR(3),
tmComprobante INT DEFAULT (0),
tmIdCiaCom CHAR(2),
tmTipDcm VARCHAR(3),
tmDocmto INT DEFAULT (0),
tmIdCiaDcm CHAR(2),
tmTimeSys SMALLDATETIME,
tmVencido MONEY DEFAULT (0) NOT NULL,
tmPorVencer MONEY DEFAULT (0) NOT NULL,
tmVence1 MONEY DEFAULT (0) NOT NULL,
tmVence2 MONEY DEFAULT (0) NOT NULL,
tmVence3 MONEY DEFAULT (0) NOT NULL,
tmVence4 MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_vence PRIMARY KEY CLUSTERED (tmEst,tmTipDoc,tmDocumento,tmIdCia,tmItem),
 CONSTRAINT CK_tm_vencetmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_vencetmIdAgencia CHECK ((len([tmIdAgencia]) > 0)),
 CONSTRAINT CK_tm_vencetmIdCargo CHECK ((len([tmIdCargo]) > 0)),
 CONSTRAINT CK_tm_vencetmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_vencetmIdClase CHECK ((len([tmIdClase]) > 0)),
 CONSTRAINT CK_tm_vencetmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_vencetmIdConductor CHECK ((len([tmIdConductor]) > 0)),
 CONSTRAINT CK_tm_vencetmIdEstado CHECK ((len([tmIdEstado]) > 0)),
 CONSTRAINT CK_tm_vencetmIdPropietario CHECK ((len([tmIdPropietario]) > 0)),
 CONSTRAINT CK_tm_vencetmIdUsuario CHECK ((len([tmIdUsuario]) > 0)),
 CONSTRAINT CK_tm_vencetmIdVehiculo CHECK ((len([tmIdVehiculo]) > 0)),
 CONSTRAINT CK_tm_vencetmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_Ventas ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmIdProducto VARCHAR(16) NOT NULL,
tmIdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCia CHAR(2) DEFAULT ('00') NOT NULL,
tmTipDoc VARCHAR(3) DEFAULT ('0') NOT NULL,
tmIdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
tmIdCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
tmIdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
tmCdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
tmCdSubzona VARCHAR(4) DEFAULT ('0') NOT NULL,
tmPeriodo VARCHAR(6) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_tm_Ventas PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_VentastmCdAgencia CHECK ((len([tmCdAgencia]) > 0)),
 CONSTRAINT CK_tm_VentastmCdLocal CHECK ((len([tmCdLocal]) > 0)),
 CONSTRAINT CK_tm_VentastmCdSubzona CHECK ((len([tmCdSubzona]) > 0)),
 CONSTRAINT CK_tm_VentastmEst CHECK ((len([tmEst]) > 0)),
 CONSTRAINT CK_tm_VentastmIdBodega CHECK ((len([tmIdBodega]) > 0)),
 CONSTRAINT CK_tm_VentastmIdCia CHECK ((len([tmIdCia]) > 0)),
 CONSTRAINT CK_tm_VentastmIdCliente CHECK ((len([tmIdCliente]) > 0)),
 CONSTRAINT CK_tm_VentastmIdConcepto CHECK ((len([tmIdConcepto]) > 0)),
 CONSTRAINT CK_tm_VentastmIdProducto CHECK ((len([tmIdProducto]) > 0)),
 CONSTRAINT CK_tm_VentastmIdVend CHECK ((len([tmIdVend]) > 0)),
 CONSTRAINT CK_tm_VentastmPeriodo CHECK ((len([tmPeriodo]) > 0)),
 CONSTRAINT CK_tm_VentastmTipDoc CHECK ((len([tmTipDoc]) > 0)))
CREATE TABLE tm_VentasCom ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmUnidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVentaNeto MONEY DEFAULT (0) NOT NULL,
tmCostoNeto MONEY DEFAULT (0) NOT NULL,
tmImpuestos MONEY DEFAULT (0) NOT NULL,
tmImpGlobal MONEY DEFAULT (0) NOT NULL,
tmSoldicom MONEY DEFAULT (0) NOT NULL,
tmVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmUnidades2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVentaNeto2 MONEY DEFAULT (0) NOT NULL,
tmCostoNeto2 MONEY DEFAULT (0) NOT NULL,
tmImpuestos2 MONEY DEFAULT (0) NOT NULL,
tmImpGlobal2 MONEY DEFAULT (0) NOT NULL,
tmSoldicom2 MONEY DEFAULT (0) NOT NULL,
tmVolumen2 DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmImpConsumo MONEY DEFAULT ((0)) NOT NULL,
tmImpConsumo2 MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_VentasCom PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_VentasComtmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_VentasDet ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmEntradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSalidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmVtaBrutoEnt MONEY DEFAULT (0) NOT NULL,
tmVtaBrutoSal MONEY DEFAULT (0) NOT NULL,
tmCostoEnt MONEY DEFAULT (0) NOT NULL,
tmCostoSal MONEY DEFAULT (0) NOT NULL,
tmDctosEnt MONEY DEFAULT (0) NOT NULL,
tmDctosSal MONEY DEFAULT (0) NOT NULL,
tmIvaEnt MONEY DEFAULT (0) NOT NULL,
tmIvaSal MONEY DEFAULT (0) NOT NULL,
tmReteFteEnt MONEY DEFAULT (0) NOT NULL,
tmReteFteSal MONEY DEFAULT (0) NOT NULL,
tmReteIcaEnt MONEY DEFAULT (0) NOT NULL,
tmReteIcaSal MONEY DEFAULT (0) NOT NULL,
tmSobtasaEnt MONEY DEFAULT (0) NOT NULL,
tmSobtasaSal MONEY DEFAULT (0) NOT NULL,
tmImpGlobalEnt MONEY DEFAULT (0) NOT NULL,
tmImpGlobalSal MONEY DEFAULT (0) NOT NULL,
tmSoldicomEnt MONEY DEFAULT (0) NOT NULL,
tmSoldicomSal MONEY DEFAULT (0) NOT NULL,
tmUnidVolumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmComision DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmImpConEnt MONEY DEFAULT ((0)) NOT NULL,
tmImpConSal MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_tm_VentasDet PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_VentasDettmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE tm_VentasRes ( 
tmEst CHAR(2) DEFAULT ('01') NOT NULL,
tmItem INT DEFAULT (0) NOT NULL,
tmEnero DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmFebrero DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMarzo DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAbril DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmMayo DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJunio DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmJulio DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmAgosto DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmSeptiembre DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmOctubre DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmNoviembre DECIMAL(14,4) DEFAULT (0) NOT NULL,
tmDiciembre DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_tm_VentasRes PRIMARY KEY CLUSTERED (tmEst,tmItem),
 CONSTRAINT CK_tm_VentasRestmEst CHECK ((len([tmEst]) > 0)))
CREATE TABLE TraConcCausac ( 
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(250) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
TipoConc VARCHAR(10) DEFAULT ('CTACOBRAR') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_TraConcCausac PRIMARY KEY CLUSTERED (IdConcepto),
 CONSTRAINT CK_TraConcCausacConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_TraConcCausacIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_TraConcCausacIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_TraConcCausacTipoConc CHECK ((len([TipoConc]) > 0)))
CREATE TABLE TraFijos ( 
Numero INT DEFAULT ((0)) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
DescConc VARCHAR(250) NOT NULL,
TipoConc VARCHAR(10) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoTarif CHAR(1) DEFAULT ('%') NOT NULL,
TipoAfilVeh VARCHAR(10) DEFAULT ('0') NOT NULL,
CdTipoVeh VARCHAR(4) DEFAULT ('0') NOT NULL,
TipoTerc CHAR(1) DEFAULT ('N'),
Anulado BIT DEFAULT ((0)) NOT NULL,
CdCiuOrigen VARCHAR(8),
CdCiuDestino VARCHAR(8),
pVehiculo VARCHAR(10),
CedConductor VARCHAR(16),
CdRuta VARCHAR(4),
TipoVigencia CHAR(1),
FechaInicial SMALLDATETIME,
FechaFinal SMALLDATETIME,
NitCliente VARCHAR(16),
CdMercancia VARCHAR(16),
IdentProp VARCHAR(16)
 CONSTRAINT PK_TraFijos PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_TraFijosCdTipoVeh CHECK ((len([CdTipoVeh])>(0))),
 CONSTRAINT CK_TraFijosDescConc CHECK ((len([DescConc])>(0))),
 CONSTRAINT CK_TraFijosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_TraFijosTipoAfilVeh CHECK ((len([TipoAfilVeh])>(0))),
 CONSTRAINT CK_TraFijosTipoConc CHECK ((len([TipoConc])>(0))),
 CONSTRAINT CK_TraFijosTipoTarif CHECK ((len([TipoTarif])>(0))))
CREATE TABLE Trn_AfAmortiza ( 
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Estado INT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_Trn_AfAmortiza PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_Trn_AfAmortizaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfAmortizaIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_AfAmtComp ( 
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
TipoCompNiif VARCHAR(3),
NumCompNiif INT DEFAULT ((0)) NOT NULL,
TipoCompFis VARCHAR(3),
NumCompFis INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfAmtComp PRIMARY KEY CLUSTERED (Numero,IdCia),
 CONSTRAINT CK_Trn_AfAmtCompIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfAmtCompTipCom CHECK ((len([TipCom]) > 0)))
CREATE TABLE Trn_AfAmtDetalle ( 
Numero INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdDiferido VARCHAR(30) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
VrAdiciones MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VrAcuAjustes MONEY DEFAULT (0) NOT NULL,
VrAmortizaHis MONEY DEFAULT (0) NOT NULL,
VrAmortizaMes MONEY DEFAULT (0) NOT NULL,
VrAjustesInf MONEY DEFAULT (0) NOT NULL,
VrAjustesAmtza MONEY DEFAULT (0) NOT NULL,
VrAmtzaHisAcum MONEY DEFAULT (0) NOT NULL,
VrAmortizaAcum MONEY DEFAULT (0) NOT NULL,
VrAjuAmtzaAcum MONEY DEFAULT (0) NOT NULL,
VrCorrMonAcum MONEY DEFAULT (0) NOT NULL,
VrBaseCorrMon MONEY DEFAULT (0) NOT NULL,
VrCorrMonDif MONEY DEFAULT (0) NOT NULL,
TarifaAju DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
CdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
CdDep VARCHAR(4) DEFAULT ('0') NOT NULL,
NitRespons VARCHAR(16) DEFAULT ('0') NOT NULL,
FecInicioAmtza SMALLDATETIME NOT NULL,
NPeriodos INT DEFAULT (0) NOT NULL,
CuotaGal DECIMAL(14,4) DEFAULT (0),
VentaGal DECIMAL(14,4) DEFAULT (0),
VrInversion MONEY DEFAULT (0) NOT NULL,
CdGrupoDif VARCHAR(4),
CantCuotasIni INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfAmtDetalle PRIMARY KEY CLUSTERED (Numero,Item),
 CONSTRAINT CK_Trn_AfAmtDetalleCdCCosto CHECK ((len([CdCCosto]) > 0)),
 CONSTRAINT CK_Trn_AfAmtDetalleCdDep CHECK ((len([CdDep]) > 0)),
 CONSTRAINT CK_Trn_AfAmtDetalleCdSubCos CHECK ((len([CdSubCos]) > 0)),
 CONSTRAINT CK_Trn_AfAmtDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfAmtDetalleIdDiferido CHECK ((len([IdDiferido]) > 0)),
 CONSTRAINT CK_Trn_AfAmtDetalleNitRespons CHECK ((len([NitRespons]) > 0)))
CREATE TABLE Trn_AfDeprecCom ( 
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
TipComAju VARCHAR(3) DEFAULT ('0') NOT NULL,
CompAjustes INT DEFAULT (0) NOT NULL,
TipoCompNiif VARCHAR(3),
NumCompNiif INT DEFAULT ((0)) NOT NULL,
TipoCompFis VARCHAR(3),
NumCompFis INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfDeprecCom PRIMARY KEY CLUSTERED (Numero,IdCia),
 CONSTRAINT CK_Trn_AfDeprecComIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDeprecComTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_AfDeprecComTipComAju CHECK ((len([TipComAju]) > 0)))
CREATE TABLE Trn_AfDeprecia ( 
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Estado INT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_Trn_AfDeprecia PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_Trn_AfDepreciaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDepreciaIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_AfDetalle ( 
Numero INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
VrCostoIni MONEY DEFAULT (0) NOT NULL,
VrMejoras MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VrAcuAjustes MONEY DEFAULT (0) NOT NULL,
VrDepreciaHis MONEY DEFAULT (0) NOT NULL,
VrDepreciaMes MONEY DEFAULT (0) NOT NULL,
VrAjustesInf MONEY DEFAULT (0) NOT NULL,
VrAjustesDep MONEY DEFAULT (0) NOT NULL,
VrDepreciaAcum MONEY DEFAULT (0) NOT NULL,
VrAjuDepAcum MONEY DEFAULT (0) NOT NULL,
TarifaAju DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
CdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
CdInstala VARCHAR(4) DEFAULT ('0') NOT NULL,
CdDep VARCHAR(4) DEFAULT ('0') NOT NULL,
NitRespons VARCHAR(16) DEFAULT ('0') NOT NULL,
FecIniDep SMALLDATETIME NOT NULL,
MesesVida INT DEFAULT (0) NOT NULL,
MetodoDeprec VARCHAR(10) NOT NULL,
CdGrupoAct VARCHAR(4),
VrSalvamnto MONEY DEFAULT ((0)) NOT NULL,
Unidades INT DEFAULT ((0)) NOT NULL,
Cantidad INT DEFAULT ((0)) NOT NULL,
Dep_Partes BIT DEFAULT ((0)) NOT NULL,
CantMeses INT DEFAULT ((0)) NOT NULL,
VrDepMejoras MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfDetalle PRIMARY KEY CLUSTERED (Numero,Item),
 CONSTRAINT CK_Trn_AfDetalleCdCCosto CHECK ((len([CdCCosto]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleCdDep CHECK ((len([CdDep]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleCdInstala CHECK ((len([CdInstala]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleCdSubCos CHECK ((len([CdSubCos]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleMetodoDeprec CHECK ((len([MetodoDeprec]) > 0)),
 CONSTRAINT CK_Trn_AfDetalleNitRespons CHECK ((len([NitRespons]) > 0)))
CREATE TABLE Trn_AfDifIngreso ( 
IdMov VARCHAR(4) DEFAULT ('0001') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdDiferido VARCHAR(30) NOT NULL,
FecActivacion SMALLDATETIME NOT NULL,
NumPeriodos INT DEFAULT (0) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
VrMejoras MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VrAjuInfAcum MONEY DEFAULT (0) NOT NULL,
VrAmortizaHis MONEY DEFAULT (0) NOT NULL,
VrAmortizaAju MONEY DEFAULT (0) NOT NULL,
VrAjuInfAmtza MONEY DEFAULT (0) NOT NULL,
NumMesesAmtza INT DEFAULT (0) NOT NULL,
VrCorrMonDif MONEY DEFAULT (0) NOT NULL,
NumMesesCorr INT DEFAULT (0) NOT NULL,
FecUltAmtza SMALLDATETIME,
Concepto VARCHAR(150)
 CONSTRAINT PK_Trn_AfDifIngreso PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfDifIngresoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDifIngresoIdDiferido CHECK ((len([IdDiferido]) > 0)),
 CONSTRAINT CK_Trn_AfDifIngresoIdMov CHECK ((len([IdMov]) > 0)))
CREATE TABLE Trn_AfDifMovi ( 
IdMov VARCHAR(4) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
FecCreacion SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_AfDifMovi PRIMARY KEY NONCLUSTERED (IdMov,Numero,IdCia),
 CONSTRAINT CK_Trn_AfDifMoviIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDifMoviIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_AfDifMoviIdMov CHECK ((len([IdMov]) > 0)),
 CONSTRAINT CK_Trn_AfDifMoviIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AfDifMoviTipCom CHECK ((len([TipCom]) > 0)))
CREATE TABLE Trn_AfDifRetiro ( 
IdMov VARCHAR(4) DEFAULT ('2005') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdDiferido VARCHAR(30) NOT NULL,
IdCausal VARCHAR(4) NOT NULL,
VrCostoIni MONEY DEFAULT (0) NOT NULL,
VrAdiciones MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VrAcuAjustes MONEY DEFAULT (0) NOT NULL,
VrAmortizaAcum MONEY DEFAULT (0) NOT NULL,
VrAjuAmtzaAcum MONEY DEFAULT (0) NOT NULL,
FechaRet SMALLDATETIME,
Concepto VARCHAR(250)
 CONSTRAINT PK_Trn_AfDifRetiro PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfDifRetiroIdCausal CHECK ((len([IdCausal]) > 0)),
 CONSTRAINT CK_Trn_AfDifRetiroIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDifRetiroIdDiferido CHECK ((len([IdDiferido]) > 0)),
 CONSTRAINT CK_Trn_AfDifRetiroIdMov CHECK ((len([IdMov]) > 0)))
CREATE TABLE Trn_AfDifTraslado ( 
IdMov VARCHAR(4) DEFAULT ('0002') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdDiferido VARCHAR(30) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdRespons VARCHAR(16) NOT NULL,
Ubicacion VARCHAR(150),
CdCiaDest CHAR(2) DEFAULT ('01') NOT NULL,
CdGrupoDest VARCHAR(4) NOT NULL,
CdCCostoDest VARCHAR(16) NOT NULL,
CdSubCosDest VARCHAR(16) NOT NULL,
CdDepDest VARCHAR(4) NOT NULL,
CdResponsDest VARCHAR(16) NOT NULL,
UbicacionDest VARCHAR(150),
Concepto VARCHAR(150)
 CONSTRAINT PK_Trn_AfDifTraslado PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfDifTrasladoCdCCostoDest CHECK ((len([CdCCostoDest]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoCdCiaDest CHECK ((len([CdCiaDest]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoCdDepDest CHECK ((len([CdDepDest]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoCdGrupoDest CHECK ((len([CdGrupoDest]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoCdResponsDest CHECK ((len([CdResponsDest]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoCdSubCosDest CHECK ((len([CdSubCosDest]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdDiferido CHECK ((len([IdDiferido]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdMov CHECK ((len([IdMov]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdRespons CHECK ((len([IdRespons]) > 0)),
 CONSTRAINT CK_Trn_AfDifTrasladoIdSubCos CHECK ((len([IdSubCos]) > 0)))
CREATE TABLE Trn_AfDifValoriza ( 
IdMov VARCHAR(4) DEFAULT ('0003') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdDiferido VARCHAR(30) NOT NULL,
Concepto VARCHAR(250),
Valor MONEY DEFAULT (0) NOT NULL,
NitProvee VARCHAR(16) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_Trn_AfDifValoriza PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfDifValorizaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfDifValorizaIdDiferido CHECK ((len([IdDiferido]) > 0)),
 CONSTRAINT CK_Trn_AfDifValorizaIdMov CHECK ((len([IdMov]) > 0)))
CREATE TABLE Trn_AfMantnmto ( 
Numero INT IDENTITY ( 1,1 ) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NumContrato VARCHAR(20),
NitEmpresa VARCHAR(16) DEFAULT ('0') NOT NULL,
NomEmpresa VARCHAR(150) NOT NULL,
FinContrato BIT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Diagnostico VARCHAR(2000),
Comentarios VARCHAR(4000)
 CONSTRAINT PK_Trn_AfMantnmto PRIMARY KEY NONCLUSTERED (Numero),
 CONSTRAINT CK_Trn_AfMantnmtoIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfMantnmtoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfMantnmtoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AfMantnmtoNitEmpresa CHECK ((len([NitEmpresa]) > 0)),
 CONSTRAINT CK_Trn_AfMantnmtoNomEmpresa CHECK ((len([NomEmpresa]) > 0)))
CREATE TABLE Trn_AfMovimiento ( 
IdMov VARCHAR(4) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Documento VARCHAR(20),
Anulado BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
FecCreacion SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoCompNiif VARCHAR(3),
NumCompNiif INT DEFAULT ((0)) NOT NULL,
TipoCompFis VARCHAR(3),
NumCompFis INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfMovimiento PRIMARY KEY NONCLUSTERED (IdMov,Numero,IdCia),
 CONSTRAINT CK_Trn_AfMovimientoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfMovimientoIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_AfMovimientoIdMov CHECK ((len([IdMov]) > 0)),
 CONSTRAINT CK_Trn_AfMovimientoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AfMovimientoTipCom CHECK ((len([TipCom]) > 0)))
CREATE TABLE Trn_AfMovIngreso ( 
IdMov VARCHAR(4) DEFAULT ('0001') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
FecActivacion SMALLDATETIME NOT NULL,
VrMejoras MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VrAjuInfAcum MONEY DEFAULT (0) NOT NULL,
VrDepAcuHis MONEY DEFAULT (0) NOT NULL,
VrDepAcuAju MONEY DEFAULT (0) NOT NULL,
VrAjuInfDep MONEY DEFAULT (0) NOT NULL,
NumMesesDep INT DEFAULT (0) NOT NULL,
FecUltDep SMALLDATETIME,
Concepto VARCHAR(150),
NumParte INT DEFAULT ((0)) NOT NULL,
Cantidad INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfMovIngreso PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfMovIngresoIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfMovIngresoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfMovIngresoIdMov CHECK ((len([IdMov]) > 0)))
CREATE TABLE Trn_AfMovRetiro ( 
IdMov VARCHAR(4) DEFAULT ('0005') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
IdCausal VARCHAR(4) NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
NomTercero VARCHAR(150),
VrCostoIni MONEY DEFAULT (0) NOT NULL,
VrMejoras MONEY DEFAULT (0) NOT NULL,
VrDisminucion MONEY DEFAULT (0) NOT NULL,
VrAcuAjustes MONEY DEFAULT (0) NOT NULL,
VrDepAcum MONEY DEFAULT (0) NOT NULL,
VrAjuDepAcum MONEY DEFAULT (0) NOT NULL,
VrIngreso MONEY DEFAULT (0) NOT NULL,
FechaRet SMALLDATETIME,
IdCueDeb VARCHAR(16),
IdCueIng VARCHAR(16),
Concepto VARCHAR(250),
NumParte INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfMovRetiro PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfMovRetiroIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfMovRetiroIdCausal CHECK ((len([IdCausal]) > 0)),
 CONSTRAINT CK_Trn_AfMovRetiroIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfMovRetiroIdMov CHECK ((len([IdMov]) > 0)),
 CONSTRAINT CK_Trn_AfMovRetiroNitTercero CHECK ((len([NitTercero]) > 0)))
CREATE TABLE Trn_AfMovTraslado ( 
IdMov VARCHAR(4) DEFAULT ('0002') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdInstala VARCHAR(4) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdRespons VARCHAR(16) NOT NULL,
CdCiaDest CHAR(2) DEFAULT ('01') NOT NULL,
CdGrupoDest VARCHAR(4) NOT NULL,
CdCCostoDest VARCHAR(16) NOT NULL,
CdSubCosDest VARCHAR(16) NOT NULL,
CdInstalaDest VARCHAR(4) NOT NULL,
CdDepDest VARCHAR(4) NOT NULL,
CdResponsDest VARCHAR(16) NOT NULL,
Concepto VARCHAR(150),
Ubicacion VARCHAR(100),
UbicacionDest VARCHAR(100)
 CONSTRAINT PK_Trn_AfMovTraslado PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfMovTrasladoCdCCostoDest CHECK ((len([CdCCostoDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoCdCiaDest CHECK ((len([CdCiaDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoCdDepDest CHECK ((len([CdDepDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoCdGrupoDest CHECK ((len([CdGrupoDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoCdInstalaDest CHECK ((len([CdInstalaDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoCdResponsDest CHECK ((len([CdResponsDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoCdSubCosDest CHECK ((len([CdSubCosDest]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdInstala CHECK ((len([IdInstala]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdMov CHECK ((len([IdMov]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdRespons CHECK ((len([IdRespons]) > 0)),
 CONSTRAINT CK_Trn_AfMovTrasladoIdSubCos CHECK ((len([IdSubCos]) > 0)))
CREATE TABLE Trn_AfMovValoriza ( 
IdMov VARCHAR(4) DEFAULT ('0003') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
Concepto VARCHAR(250),
Valor MONEY DEFAULT (0) NOT NULL,
NitProvee VARCHAR(16) DEFAULT ('0') NOT NULL,
FecAdquis SMALLDATETIME,
NumDocmto VARCHAR(20),
DescripParte VARCHAR(150),
Num_Parte INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfMovValoriza PRIMARY KEY CLUSTERED (IdMov,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_AfMovValorizaIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfMovValorizaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AfMovValorizaIdMov CHECK ((len([IdMov]) > 0)))
CREATE TABLE Trn_AfPartes ( 
Numero INT DEFAULT ((0)) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
IdParte INT DEFAULT ((0)) NOT NULL,
VrBaseDep MONEY DEFAULT ((0)) NOT NULL,
VrCostoIni MONEY DEFAULT ((0)) NOT NULL,
VrMejoras MONEY DEFAULT ((0)) NOT NULL,
VrDisminuc MONEY DEFAULT ((0)) NOT NULL,
VrAcumAju MONEY DEFAULT ((0)) NOT NULL,
VrDepAcum MONEY DEFAULT ((0)) NOT NULL,
VrDeprecia MONEY DEFAULT ((0)) NOT NULL,
VrDepHis MONEY DEFAULT ((0)) NOT NULL,
VrAjusteInf MONEY DEFAULT ((0)) NOT NULL,
VrAjuDeprec MONEY DEFAULT ((0)) NOT NULL,
VrAcumAjuDep MONEY DEFAULT ((0)) NOT NULL,
VrSalvamnto MONEY DEFAULT ((0)),
Unidades INT DEFAULT ((0)) NOT NULL,
Cantidad INT DEFAULT ((0)) NOT NULL,
FecIniDep SMALLDATETIME NOT NULL,
Vida_Util INT DEFAULT ((0)) NOT NULL,
MetDeprec VARCHAR(10) NOT NULL,
CantCuoIni INT DEFAULT ((0)) NOT NULL,
VrDepMejoras MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_AfPartes PRIMARY KEY CLUSTERED (Numero,Item),
 CONSTRAINT CK_Trn_AfPartesIdActivo CHECK ((len([IdActivo])>(0))),
 CONSTRAINT CK_Trn_AfPartesMetDeprec CHECK ((len([MetDeprec])>(0))))
CREATE TABLE Trn_AfPignora ( 
Numero INT IDENTITY ( 1,1 ) NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipoAccion VARCHAR(10) DEFAULT ('PIGNORAR') NOT NULL,
NomTercero VARCHAR(150) NOT NULL,
Comentarios VARCHAR(150) NOT NULL,
Garantia VARCHAR(150),
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_AfPignora PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_Trn_AfPignoraComentarios CHECK ((len([Comentarios]) > 0)),
 CONSTRAINT CK_Trn_AfPignoraIdActivo CHECK ((len([IdActivo]) > 0)),
 CONSTRAINT CK_Trn_AfPignoraIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AfPignoraNomTercero CHECK ((len([NomTercero]) > 0)),
 CONSTRAINT CK_Trn_AfPignoraTipoAccion CHECK ((len([TipoAccion]) > 0)))
CREATE TABLE Trn_AfUnidades ( 
Numero BIGINT IDENTITY ( 1,1 ) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdActivo VARCHAR(30) NOT NULL,
Cantidad INT DEFAULT ((0)) NOT NULL,
Tipo_UP VARCHAR(10),
FechaCrea SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_AfUnidades PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_Trn_AfUnidadesIdActivo CHECK ((len([IdActivo])>(0))))
CREATE TABLE Trn_AjuInv ( 
TipDoc VARCHAR(3) NOT NULL,
Ajuste INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
BaseAjuInf MONEY DEFAULT (0) NOT NULL,
TarifPaag DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumDcmto INT DEFAULT (0) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') 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_AjuInv PRIMARY KEY CLUSTERED (TipDoc,Ajuste,IdCia),
 CONSTRAINT CK_Trn_AjuInvIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_AjuInvIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AjuInvModalidad CHECK (([Modalidad] = 'NORMAL' or ([Modalidad] = 'INSUMOS' or ([Modalidad] = 'INVENTARIO' or ([Modalidad] = 'INFLACION' or [Modalidad] = 'COSTOS'))))),
 CONSTRAINT CK_Trn_AjuInvOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_AjuInvTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_AjuInvTipDoc CHECK (([TipDoc] = 'AJS' or [TipDoc] = 'AJF')))
CREATE TABLE Trn_Aprobacion ( 
TipDoc VARCHAR(3) DEFAULT ('APR') NOT NULL,
Aprobacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipoPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('01') NOT NULL,
FecPedido SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
pVehiculo VARCHAR(10),
VrCupoCred MONEY DEFAULT (0) NOT NULL,
VrSaldoAct MONEY DEFAULT (0) NOT NULL,
ChequesDev BIT DEFAULT (0) NOT NULL,
ClienteMora BIT DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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_Aprobacion PRIMARY KEY CLUSTERED (TipDoc,Aprobacion,IdCia),
 CONSTRAINT CK_Trn_AprobacionIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_AprobacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AprobacionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_AprobacionIdCiaPed CHECK ((len([IdCiaPed]) > 0)),
 CONSTRAINT CK_Trn_AprobacionIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_AprobacionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_AprobacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AprobacionOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_AprobacionTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_AprobacionTipoPed CHECK ((len([TipoPed]) > 0)))
CREATE TABLE Trn_Autoriza ( 
TipAut VARCHAR(3) DEFAULT ('AUT') NOT NULL,
Autoriza INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
NumAutoriza INT DEFAULT (0) NOT NULL,
IdUsuarioAut VARCHAR(11) NOT NULL,
IdEstacion CHAR(2) NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
pVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
TipoDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('00') NOT NULL,
FechaDoc SMALLDATETIME,
DocRef INT DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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,
VrAprobado MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Autoriza PRIMARY KEY CLUSTERED (TipAut,Autoriza,IdCia),
 CONSTRAINT CK_Trn_AutorizaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdEstacion CHECK ((len([IdEstacion]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_AutorizaIdUsuarioAut CHECK ((len([IdUsuarioAut]) > 0)),
 CONSTRAINT CK_Trn_AutorizaNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_AutorizaOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_AutorizapVehiculo CHECK ((len([pVehiculo]) > 0)),
 CONSTRAINT CK_Trn_AutorizaTipAut CHECK ((len([TipAut]) > 0)),
 CONSTRAINT CK_Trn_AutorizaTipoDoc CHECK ((len([TipoDoc]) > 0)))
CREATE TABLE Trn_Causacion ( 
TipDoc VARCHAR(3) DEFAULT ('ADM') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Factura VARCHAR(15) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
FecFactura SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
Referencia VARCHAR(20),
Modalidad VARCHAR(10) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
ValorDcto MONEY DEFAULT (0) NOT NULL,
ValorIva MONEY DEFAULT (0) NOT NULL,
ValorReteFte MONEY DEFAULT (0) NOT NULL,
ValorReteIva MONEY DEFAULT (0) NOT NULL,
ValorReteIca MONEY DEFAULT (0) NOT NULL,
ValorOtros MONEY DEFAULT (0) NOT NULL,
ValorFletes MONEY DEFAULT (0) NOT NULL,
ValorNeto MONEY DEFAULT (0) NOT NULL,
ValorCCobrar MONEY DEFAULT (0) NOT NULL,
BaseIva MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTarIva VARCHAR(4) NOT NULL,
IdTarRet VARCHAR(4) NOT NULL,
IdTarIca VARCHAR(4) NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
CxcVarios BIT DEFAULT (0) NOT NULL,
TipEgr VARCHAR(3),
Egreso INT DEFAULT (0),
IdCiaEgr CHAR(2),
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
CierreCte BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
IndFactura INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Causacion PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia),
 CONSTRAINT CK_Trn_CausacionFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdProveedor CHECK ((len([IdProveedor]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdTarIca CHECK ((len([IdTarIca]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdTarIva CHECK ((len([IdTarIva]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdTarRet CHECK ((len([IdTarRet]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_CausacionIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_CausacionModalidad CHECK (([Modalidad] = 'OCASIONAL' or ([Modalidad] = 'OTROS' or [Modalidad] = 'DIARIO'))),
 CONSTRAINT CK_Trn_CausacionTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_CausacionTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_CausacVence ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
ValorFactura MONEY DEFAULT (0) NOT NULL,
ValorAbono MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
IdVendedor VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCargo VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
FecUltPago SMALLDATETIME,
NotaInt INT DEFAULT (0),
FecUltLiquida SMALLDATETIME,
Factura VARCHAR(15),
Referencia VARCHAR(20),
Detalle VARCHAR(100),
TipRec VARCHAR(3),
Recibo INT DEFAULT (0) NOT NULL,
IdCiaRec CHAR(2),
ValorAtcpo MONEY DEFAULT (0) NOT NULL,
IdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
CombCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
CombValor MONEY DEFAULT (0) NOT NULL,
BaseImpu MONEY DEFAULT ((0)),
Tarifa_Iva DECIMAL(14,4) DEFAULT ((0)),
VrIva MONEY DEFAULT ((0)),
Tarifa_Ret DECIMAL(14,4) DEFAULT ((0)),
VrRetFte MONEY DEFAULT ((0)),
Tarifa_Ica DECIMAL(14,4) DEFAULT ((0)),
VrRetIca MONEY DEFAULT ((0)),
CodTarifIva VARCHAR(4),
CodTarifRet VARCHAR(4),
CodTarifIca VARCHAR(4),
TipDocFac VARCHAR(3),
NumDocFac INT DEFAULT ((0)),
CdCiaFac CHAR(2)
 CONSTRAINT PK_Trn_CausacVence PRIMARY KEY NONCLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_CausacVenceIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceIdVendedor CHECK ((len([IdVendedor]) > 0)),
 CONSTRAINT CK_Trn_CausacVenceTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_CausaVales ( 
TipDoc VARCHAR(3) DEFAULT ('FVC') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CodTarArf VARCHAR(4),
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
CodTarAri VARCHAR(4),
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_CausaVales PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia),
 CONSTRAINT CK_Trn_CausaValesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_CausaValesIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_CausaValesOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_CausaValesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_CausaValesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_Cheques ( 
TipForma VARCHAR(3) DEFAULT ('CHE') NOT NULL,
Numero VARCHAR(20) NOT NULL,
IdBanco VARCHAR(4) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecPago SMALLDATETIME NOT NULL,
VrForma MONEY DEFAULT (0) NOT NULL,
CtaForma VARCHAR(30) NOT NULL,
Beneficiario VARCHAR(150),
Referncia1 VARCHAR(50),
Referncia2 VARCHAR(50),
Detalle VARCHAR(150),
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
CdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
TipRec VARCHAR(3) DEFAULT ('CHE') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('REC') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME,
TipCon VARCHAR(3) DEFAULT ('0') NOT NULL,
NumConsig INT DEFAULT (0) NOT NULL,
IdCiaCon CHAR(2) DEFAULT ('01') NOT NULL,
FecConsig SMALLDATETIME,
CdCta VARCHAR(4),
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
IdEstado VARCHAR(4) NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_Cheques PRIMARY KEY CLUSTERED (TipForma,Numero,IdBanco,IdCia),
 CONSTRAINT CK_Trn_ChequesCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_ChequesCdVend CHECK ((len([CdVend]) > 0)),
 CONSTRAINT CK_Trn_ChequesCtaForma CHECK ((len([CtaForma]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdCiaCon CHECK ((len([IdCiaCon]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_ChequesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_ChequesNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_ChequesNumero CHECK ((len([Numero]) > 0)),
 CONSTRAINT CK_Trn_ChequesTipCon CHECK ((len([TipCon]) > 0)),
 CONSTRAINT CK_Trn_ChequesTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_ChequesTipForma CHECK ((len([TipForma]) > 0)),
 CONSTRAINT CK_Trn_ChequesTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_ComDetalle ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Detalle VARCHAR(250) NOT NULL,
VrDebito MONEY DEFAULT (0) NOT NULL,
VrCredito MONEY DEFAULT (0) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
TarifaBase DECIMAL(10,4) DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3),
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01'),
CodConce VARCHAR(4),
NitDoc VARCHAR(16),
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT (0) NOT NULL,
FecVence SMALLDATETIME NOT NULL,
CodCta VARCHAR(4),
NumCheque VARCHAR(20),
Integrado BIT DEFAULT (0) NOT NULL,
TipoAplica CHAR(1) DEFAULT ('N') NOT NULL,
Consolida BIT DEFAULT (0) NOT NULL,
CodCargo VARCHAR(4),
NitOtros VARCHAR(16),
CodSubgpo VARCHAR(8),
CiuOrigen VARCHAR(8),
CodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
VehPropio INT DEFAULT ((0)) NOT NULL,
Referncia VARCHAR(50),
TipDocRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CdConcTrib VARCHAR(4),
CdTarifTrib VARCHAR(4),
NumEstablec VARCHAR(20),
PtoEmision VARCHAR(20),
Num_Autoriza VARCHAR(50),
FechAutoriza SMALLDATETIME,
CdCuentaNiif VARCHAR(16)
 CONSTRAINT PK_Trn_ComDetalle PRIMARY KEY NONCLUSTERED (TipCom,Comprobante,IdCia,Item),
 CONSTRAINT CK_Trn_ComDetalleCodAgncia CHECK ((len([CodAgncia]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleDetalle CHECK ((len([Detalle]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdCuenta CHECK ((len([IdCuenta]) > 4)),
 CONSTRAINT CK_Trn_ComDetalleIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_ComDetalleTipoAplica CHECK (([TipoAplica] = 'N' or ([TipoAplica] = 'C' or [TipoAplica] = 'A'))))
CREATE TABLE Trn_ComFactura ( 
TipFac VARCHAR(3) NOT NULL,
Factura VARCHAR(15) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
TipDoc VARCHAR(3),
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01'),
FecEmision SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
VrFactura MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
ItemCom INT DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
Detalle VARCHAR(100),
pVehiculo VARCHAR(10),
VehPropio BIT DEFAULT (0) NOT NULL,
TipRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2),
EstadoApr INT DEFAULT (0) NOT NULL,
MontoAprob MONEY DEFAULT ((0)) NOT NULL,
FecProgPago SMALLDATETIME,
ObservAprob VARCHAR(250)
 CONSTRAINT PK_Trn_ComFactura PRIMARY KEY NONCLUSTERED (TipFac,Factura,IdCia,Item,IdProveedor),
 CONSTRAINT CK_Trn_ComFacturaFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_ComFacturaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ComFacturaIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_ComFacturaIdProveedor CHECK ((len([IdProveedor]) > 0)),
 CONSTRAINT CK_Trn_ComFacturaTipFac CHECK ((len([TipFac]) > 0)))
CREATE TABLE Trn_CompCaja ( 
TipDoc VARCHAR(3) DEFAULT ('RCO') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrTotDebito MONEY DEFAULT (0) NOT NULL,
VrTotCredito MONEY DEFAULT (0) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
IdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
NumForma VARCHAR(20),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(50),
NumVehiculo VARCHAR(10),
FacCalidad INT DEFAULT (0) NOT NULL,
SemInicial INT DEFAULT (0) NOT NULL,
SemFinal INT DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_CompCaja PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia),
 CONSTRAINT CK_Trn_CompCajaCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_CompCajaCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_Trn_CompCajaCdCta CHECK ((len([CdCta]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_CompCajaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_CompCajaOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_CompCajaTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_CompCajaTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_CompCajaDet ( 
TipDoc VARCHAR(3) DEFAULT ('RCO') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Detalle VARCHAR(250) NOT NULL,
VrDebito MONEY DEFAULT (0) NOT NULL,
VrCredito MONEY DEFAULT (0) NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
pVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
CdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
TarifaBase DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT (0) NOT NULL,
FecVence SMALLDATETIME,
CodCta VARCHAR(4),
NumCheque VARCHAR(20),
TipoAplica CHAR(1) DEFAULT ('N') NOT NULL,
NitOtros VARCHAR(16),
CodAgencia VARCHAR(16),
Referncia VARCHAR(50),
TipDocRef VARCHAR(3),
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('01'),
DocSop BIT DEFAULT ((0)) NOT NULL,
TipSop VARCHAR(3),
NumSoporte INT DEFAULT ((0)) NOT NULL,
IdCiaSop CHAR(2),
TipoImp VARCHAR(4),
CodTarImp VARCHAR(4),
ItemBase INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_CompCajaDet PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_CompCajaDetCdCCosto CHECK ((len([CdCCosto]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetCdSubCos CHECK ((len([CdSubCos]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetDetalle CHECK ((len([Detalle]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetpVehiculo CHECK ((len([pVehiculo]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_CompCajaDetTipoAplica CHECK ((len([TipoAplica]) > 0)))
CREATE TABLE Trn_CompGastos ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdPlantilla VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
TipFact VARCHAR(3),
Factura VARCHAR(15),
FecFactura SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME,
VrTotal MONEY DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_CompGastos PRIMARY KEY CLUSTERED (TipCom,Comprobante,IdCia),
 CONSTRAINT CK_Trn_CompGastosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_CompGastosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_CompGastosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_CompGastosIdPlantilla CHECK ((len([IdPlantilla]) > 0)),
 CONSTRAINT CK_Trn_CompGastosIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_CompGastosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_CompGastosOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_CompGastosTipCom CHECK ((len([TipCom]) > 0)))
CREATE TABLE Trn_Comprobantes ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
IdCta VARCHAR(4) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
NumCheque VARCHAR(20),
FecCheque SMALLDATETIME,
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
TipEgr VARCHAR(3),
NEgreso INT DEFAULT (0) NOT NULL,
pVehiculo VARCHAR(10),
VehPropio INT DEFAULT ((0)) NOT NULL,
CedCondtor VARCHAR(16),
CodConce VARCHAR(4),
Beneficiario VARCHAR(150),
VrDivisa1 MONEY DEFAULT (0) NOT NULL,
VrDivisa2 MONEY DEFAULT (0) NOT NULL,
VrDivisa3 MONEY DEFAULT (0) NOT NULL,
PermEditar BIT DEFAULT (0) NOT NULL,
Integrado BIT DEFAULT (0) NOT NULL,
EsEgreso BIT DEFAULT (0) NOT NULL,
Anticipo BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
Propddes VARCHAR(50),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CdSustento VARCHAR(4),
Tipo_Pago VARCHAR(10),
Establec VARCHAR(20),
PEmision VARCHAR(20),
Autorizac VARCHAR(50),
FechaAut SMALLDATETIME,
NiifTipo VARCHAR(3),
NiifNumero INT DEFAULT ((0)) NOT NULL,
FisTipo VARCHAR(3),
FisNumero INT DEFAULT ((0)) NOT NULL,
DocSoporte INT DEFAULT ((0)) NOT NULL,
CodRes VARCHAR(4),
DescServicio VARCHAR(500)
 CONSTRAINT PK_Trn_Comprobantes PRIMARY KEY NONCLUSTERED (TipCom,Comprobante,IdCia),
 CONSTRAINT CK_Trn_ComprobantesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesIdCta CHECK ((len([IdCta]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_ComprobantesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_Consigna ( 
TipDoc VARCHAR(3) DEFAULT ('CNS') NOT NULL,
Consignacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
VrEfectivo MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
EnEfectivo BIT DEFAULT ((0)) NOT NULL,
IdCta VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
NitDeptante VARCHAR(16) DEFAULT ('0') NOT NULL,
Depositante VARCHAR(150),
TelDeptante VARCHAR(20),
Referencia VARCHAR(50),
Referncia2 VARCHAR(50),
NumConsigna VARCHAR(20) DEFAULT ('0') NOT NULL,
RangosDoc VARCHAR(100),
FecConsig SMALLDATETIME,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_Consigna PRIMARY KEY CLUSTERED (TipDoc,Consignacion,IdCia),
 CONSTRAINT CK_Trn_ConsignaIdCajero CHECK ((len([IdCajero])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCta CHECK ((len([IdCta])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_Trn_ConsignaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_ConsignaNitDeptante CHECK ((len([NitDeptante])>(0))),
 CONSTRAINT CK_Trn_ConsignaNumConsigna CHECK ((len([NumConsigna])>(0))),
 CONSTRAINT CK_Trn_ConsignaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_ConsignaTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_ConsignaTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_Cotizacion ( 
TipDoc VARCHAR(3) DEFAULT ('COT') NOT NULL,
Cotizacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarCom VARCHAR(4),
DirContacto VARCHAR(250),
IdLocal VARCHAR(8) NOT NULL,
DiasVigencia INT DEFAULT ((0)) NOT NULL,
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargoContac VARCHAR(50),
IdForma VARCHAR(4) NOT NULL,
DetallePago VARCHAR(250),
MulPlazos BIT DEFAULT ((0)) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CdMney VARCHAR(5),
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
FechaFact SMALLDATETIME,
Modalidad VARCHAR(10) DEFAULT ('NORMAL') NOT NULL,
NumAprob INT DEFAULT ((0)) NOT NULL,
FecAprob SMALLDATETIME,
CdUsuAprob VARCHAR(11),
NumPedido INT DEFAULT ((0)) NOT NULL,
CdCiaPed CHAR(2) DEFAULT ('00'),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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_Cotizacion PRIMARY KEY CLUSTERED (TipDoc,Cotizacion,IdCia),
 CONSTRAINT CK_Trn_CotizacionIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdForma CHECK ((len([IdForma])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdPlazo CHECK ((len([IdPlazo])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_CotizacionIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_CotizacionModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_CotizacionOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_CotizacionTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_CotizacionTipFac CHECK ((len([TipFac])>(0))))
CREATE TABLE Trn_Despachos ( 
TipDoc VARCHAR(3) DEFAULT ('CAR') NOT NULL,
Cartulina INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
FechaRec SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdConductor1 VARCHAR(16) NOT NULL,
IdRelevador VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
CentInicial INT DEFAULT (0) NOT NULL,
CentFinal INT DEFAULT (0) NOT NULL,
NPasajeros INT DEFAULT (0) NOT NULL,
Recorridos INT DEFAULT (0) NOT NULL,
ValorProducido MONEY DEFAULT (0) NOT NULL,
ValorGastos MONEY DEFAULT (0) NOT NULL,
ValorAhorro MONEY DEFAULT (0) NOT NULL,
ValorOtros MONEY DEFAULT (0) NOT NULL,
ValorVales MONEY DEFAULT (0) NOT NULL,
ValorAbono MONEY DEFAULT (0) NOT NULL,
ValorPasaje MONEY DEFAULT (0) NOT NULL,
TipoAdmon VARCHAR(10) DEFAULT ('ADMON') NOT NULL,
IdTipRec VARCHAR(3),
ReciboCaja INT DEFAULT (0) NOT NULL,
IdCiaRec CHAR(2),
NumAutoriza VARCHAR(30),
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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_Despachos PRIMARY KEY CLUSTERED (TipDoc,Cartulina,IdCia),
 CONSTRAINT CK_Trn_DespachosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdConductor1 CHECK ((len([IdConductor1]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdRelevador CHECK ((len([IdRelevador]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DespachosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_DespachosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_DespachosTipoAdmon CHECK ((len([TipoAdmon]) > 0)))
CREATE TABLE Trn_DetCuentas ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Concepto VARCHAR(10) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Valor MONEY DEFAULT (0) NOT NULL,
Detalle VARCHAR(150),
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
pVehiculo VARCHAR(10),
VrBase MONEY DEFAULT (0) NOT NULL,
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT (0) NOT NULL,
FecVence SMALLDATETIME,
Cheque VARCHAR(20),
CiuOrigen VARCHAR(8),
Referencia VARCHAR(50),
VrTarifa DECIMAL(14,4) DEFAULT ((0)),
TipoTarif CHAR(1),
CodConc VARCHAR(4),
CodTarif VARCHAR(4)
 CONSTRAINT PK_Trn_DetCuentas PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Concepto,Item),
 CONSTRAINT CK_Trn_DetCuentasConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_Trn_DetCuentasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DetCuentasIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_DetCuentasIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_DetCuentasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevCaj ( 
TipDev VARCHAR(3) DEFAULT ('DRC') 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 ('RCO') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrTotDebito MONEY DEFAULT (0) NOT NULL,
VrTotCredito MONEY DEFAULT (0) NOT NULL,
IdTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
NumForma VARCHAR(20),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(50),
NumAutoriza INT DEFAULT (0) 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,
NumVehiculo VARCHAR(10)
 CONSTRAINT PK_Trn_DevCaj PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevCajCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_Trn_DevCajCdCta CHECK ((len([CdCta]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_DevCajIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevCajModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevCajOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevCajTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevCajTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevCajTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevCausacion ( 
TipDev VARCHAR(3) DEFAULT ('DVO') 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 ('OTR') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
ValorDcto MONEY DEFAULT (0) NOT NULL,
ValorIva MONEY DEFAULT (0) NOT NULL,
ValorReteFte MONEY DEFAULT (0) NOT NULL,
ValorReteIva MONEY DEFAULT (0) NOT NULL,
ValorReteIca MONEY DEFAULT (0) NOT NULL,
ValorOtros MONEY DEFAULT (0) NOT NULL,
ValorFletes MONEY DEFAULT (0) NOT NULL,
ValorNeto MONEY DEFAULT (0) NOT NULL,
ValorCxc MONEY DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
Factura VARCHAR(15) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_DevCausacion PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevCausacionFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdProveedor CHECK ((len([IdProveedor]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevCausacionTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevCns ( 
TipDev VARCHAR(3) DEFAULT ('DVC') 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 ('CNS') NOT NULL,
Consignacion INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
IdCta VARCHAR(4) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
Referencia VARCHAR(50),
Referncia2 VARCHAR(50),
NumConsigna VARCHAR(20) DEFAULT ('0') 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_DevCns PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevCnsIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCta CHECK ((len([IdCta]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevCnsIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevCnsModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevCnsNumConsigna CHECK ((len([NumConsigna]) > 0)),
 CONSTRAINT CK_Trn_DevCnsOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevCnsTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevCnsTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevCnsTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevEnt ( 
TipDev VARCHAR(3) DEFAULT ('DVE') 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 ('ENT') NOT NULL,
Entrada INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdProv VARCHAR(16) NOT NULL,
Factura VARCHAR(15) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
NitFletes VARCHAR(16),
VrRetFlete MONEY DEFAULT (0) NOT NULL,
VrIcaFlete MONEY DEFAULT (0) NOT NULL,
FletesCosto BIT DEFAULT (0) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
DocEquiv VARCHAR(3) DEFAULT ('N') NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') 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,
VrIvaMvc MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
VrBomberil MONEY DEFAULT ((0)) NOT NULL,
TarifaBom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
BaseIvaObsq MONEY DEFAULT ((0)) NOT NULL,
VrIvaObsequio MONEY DEFAULT ((0)) NOT NULL,
VrImpCarbono MONEY DEFAULT ((0)) NOT NULL,
VrImpuCons MONEY DEFAULT ((0)) NOT NULL,
VrSobtasaCons MONEY DEFAULT ((0)) NOT NULL,
BaseIvaIgp MONEY DEFAULT ((0)) NOT NULL,
VrIvaIngProd MONEY DEFAULT ((0)) NOT NULL,
ImpAviTab MONEY DEFAULT ((0)) NOT NULL,
TarifaAvta DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_DevEnt PRIMARY KEY NONCLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevEntDocEquiv CHECK (([DocEquiv] = 'N' or ([DocEquiv] = 'SER' or [DocEquiv] = 'COM'))),
 CONSTRAINT CK_Trn_DevEntFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_Trn_DevEntIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevEntModalidad CHECK (([Modalidad] = 'INSUMOS' or ([Modalidad] = 'INVENTARIO' or ([Modalidad] = 'COMBUSTBLE' or [Modalidad] = 'MAYCOMB')))),
 CONSTRAINT CK_Trn_DevEntModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevEntOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevEntTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevEntTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevEntTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevFco ( 
TipDev VARCHAR(3) DEFAULT ('DFO') 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 ('FCO') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
nClieCon VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
Remision INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
FecPedido SMALLDATETIME,
Modalidad VARCHAR(10) DEFAULT ('TPV') NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
NumAutoriza INT DEFAULT (0) NOT NULL,
PlacaVehic VARCHAR(10),
KmtVehic INT DEFAULT (0) 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,
VrImpCons MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
BaseIvaObsq MONEY DEFAULT ((0)) NOT NULL,
VrIvaObsequio MONEY DEFAULT ((0)) NOT NULL,
CdMotDev VARCHAR(4),
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_DevFco PRIMARY KEY NONCLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevFcoCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCiaPed CHECK ((len([IdCiaPed]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevFcoIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_DevFcoModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_DevFcoModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevFconClieCon CHECK ((len([nClieCon]) > 0)),
 CONSTRAINT CK_Trn_DevFcoNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_DevFcoOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevFcoTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevFcoTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevFcoTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevFcr ( 
TipDev VARCHAR(3) DEFAULT ('DFC') 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 ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteICA MONEY DEFAULT ((0)) NOT NULL,
VrReteIVA MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrCostos MONEY DEFAULT ((0)) NOT NULL,
VrSobretasa MONEY DEFAULT ((0)) NOT NULL,
VrImpGlobal MONEY DEFAULT ((0)) NOT NULL,
VrFaltantes MONEY DEFAULT ((0)) NOT NULL,
VrAnticipos MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantPuntos DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
BaseImp MONEY DEFAULT ((0)) NOT NULL,
BaseRet MONEY DEFAULT ((0)) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarCom VARCHAR(4),
IdLocEnv VARCHAR(8) NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
Remision INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
Cotizacion INT DEFAULT ((0)) NOT NULL,
IdCiaCot CHAR(2) DEFAULT ('00') NOT NULL,
FecPedido SMALLDATETIME,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
PlacaVehic VARCHAR(10),
KmtVehic INT DEFAULT ((0)) NOT NULL,
ZonaFrontera INT DEFAULT ((0)) 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,
VrImpCons MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
BaseIvaObsq MONEY DEFAULT ((0)) NOT NULL,
VrIvaObsequio MONEY DEFAULT ((0)) NOT NULL,
VrImpCarbono MONEY DEFAULT ((0)) NOT NULL,
DevMasivo INT DEFAULT ((0)) NOT NULL,
NumRecibo INT DEFAULT ((0)) NOT NULL,
CdCiaRec CHAR(2),
CdMotDev VARCHAR(4),
BaseIvaIgp MONEY DEFAULT ((0)) NOT NULL,
VrIvaIngProd MONEY DEFAULT ((0)) NOT NULL,
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_DevFcr PRIMARY KEY NONCLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevFcrIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCiaCot CHECK ((len([IdCiaCot])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdLocEnv CHECK ((len([IdLocEnv])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_DevFcrIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_DevFcrModalidad CHECK (([Modalidad]='TRANSPORTE' OR ([Modalidad]='COMBUSTBLE' OR ([Modalidad]='VALES' OR [Modalidad]='INVENTARIO')))),
 CONSTRAINT CK_Trn_DevFcrModdDev CHECK (([ModdDev]='PARCIAL' OR [ModdDev]='TOTAL')),
 CONSTRAINT CK_Trn_DevFcrOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_DevFcrTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_DevFcrTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_DevFcrTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_DevFvc ( 
TipDev VARCHAR(3) DEFAULT ('DFV') 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 ('FVC') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
ModdDev VARCHAR(10) DEFAULT ('TOTAL') 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,
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_DevFvc PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevFvcIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevFvcIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_DevFvcModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevFvcOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevFvcTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevFvcTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevFvcTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevNpr ( 
TipDev VARCHAR(3) DEFAULT ('DVN') 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 ('NPR') NOT NULL,
NumNota INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
CantEnt DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantSal DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('ENSAMBLE') 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_DevNpr PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevNprIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_DevNprIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevNprModalidad CHECK (([Modalidad] = 'DESGLOSE' or [Modalidad] = 'ENSAMBLE')),
 CONSTRAINT CK_Trn_DevNprModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevNprOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevNprTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevNprTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevNprTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevPas ( 
TipDev VARCHAR(3) DEFAULT ('DNP') 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 ('PAS') NOT NULL,
nNota INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
CdJornada VARCHAR(4) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Referencia VARCHAR(50),
ModdDev VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
NumAutoriza INT DEFAULT (0) 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_DevPas PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevPasCdJornada CHECK ((len([CdJornada]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevPasIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_DevPasModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevPasNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_DevPasOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevPasTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevPasTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevPasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevPla ( 
TipDev VARCHAR(3) DEFAULT ('DVP') 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 ('PLA') NOT NULL,
Planilla INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
IdJornada VARCHAR(4) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrSobrantes MONEY DEFAULT (0) NOT NULL,
VrFaltantes MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrCreditos MONEY DEFAULT (0) NOT NULL,
VrGastComb MONEY DEFAULT (0) NOT NULL,
VrGastOtros MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrConTotal MONEY DEFAULT (0) NOT NULL,
VrConImp MONEY DEFAULT (0) NOT NULL,
VrConDcto MONEY DEFAULT (0) NOT NULL,
VrConCos MONEY DEFAULT (0) NOT NULL,
ConCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrCreTotal MONEY DEFAULT (0) NOT NULL,
VrCreImp MONEY DEFAULT (0) NOT NULL,
VrCreDcto MONEY DEFAULT (0) NOT NULL,
VrCreCos MONEY DEFAULT (0) NOT NULL,
CreCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
NitRef VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Referencia VARCHAR(50),
Modalidad VARCHAR(10) DEFAULT ('MANUAL') NOT NULL,
FecCorte SMALLDATETIME NOT NULL,
NumCorte INT DEFAULT (0) NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
NumAutoriza INT DEFAULT (0) 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_DevPla PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevPlaIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdJornada CHECK ((len([IdJornada]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevPlaIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_DevPlaModalidad CHECK (([Modalidad] = 'AUTO' or [Modalidad] = 'MANUAL')),
 CONSTRAINT CK_Trn_DevPlaModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevPlaNitRef CHECK ((len([NitRef]) > 0)),
 CONSTRAINT CK_Trn_DevPlaNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_DevPlaOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevPlaTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevPlaTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevPlaTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevPrestamos ( 
TipDev VARCHAR(3) DEFAULT ('DPR') 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 ('PRE') NOT NULL,
Prestamo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
FechaPrest SMALLDATETIME NOT NULL,
TipoPlazo VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
NumCuotas INT DEFAULT (0) NOT NULL,
TipoCuota VARCHAR(10) DEFAULT ('VARIABLE') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
TasaInteres DECIMAL(14,4) DEFAULT (0) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
Factura VARCHAR(20) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_DevPrestamos PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevPrestamosFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosTipoCuota CHECK ((len([TipoCuota]) > 0)),
 CONSTRAINT CK_Trn_DevPrestamosTipoPlazo CHECK ((len([TipoPlazo]) > 0)))
CREATE TABLE Trn_DevRec ( 
TipDev VARCHAR(3) DEFAULT ('ODB') 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 ('REC') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
FecPago SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrRecibido MONEY DEFAULT (0) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrAhorro MONEY DEFAULT (0) NOT NULL,
VrPagosMas MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
VrAnticipo MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseRiv MONEY DEFAULT (0) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
IdLocal VARCHAR(8) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('00') NOT NULL,
NumAutoriza INT DEFAULT (0) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('CLIENTES') 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,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4)
 CONSTRAINT PK_Trn_DevRec PRIMARY KEY NONCLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevRecCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCiaDcm CHECK ((len([IdCiaDcm]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevRecIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_DevRecModalidad CHECK (([Modalidad] = 'OTROS' or [Modalidad] = 'CLIENTES')),
 CONSTRAINT CK_Trn_DevRecModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevRecOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevRecTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevRecTipDcm CHECK ((len([TipDcm]) > 0)),
 CONSTRAINT CK_Trn_DevRecTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevRecTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevRecBuses ( 
TipDev VARCHAR(3) DEFAULT ('OD1') 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 ('REC') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('CARTULINA') NOT NULL,
ValorRecibido MONEY DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
ValorDcto MONEY DEFAULT (0) NOT NULL,
ValorReteFte MONEY DEFAULT (0) NOT NULL,
ValorReteIva MONEY DEFAULT (0) NOT NULL,
ValorReteIca MONEY DEFAULT (0) NOT NULL,
ValorOtros MONEY DEFAULT (0) NOT NULL,
ValorOtrosDct MONEY DEFAULT (0) NOT NULL,
ValorPagMas MONEY DEFAULT (0) NOT NULL,
ValorAhorro MONEY DEFAULT (0) NOT NULL,
ValorOConce MONEY DEFAULT (0) NOT NULL,
ValorNeto MONEY DEFAULT (0) NOT NULL,
ValorAplicado MONEY DEFAULT (0) NOT NULL,
ValorAnticipo MONEY DEFAULT (0) NOT NULL,
IdVendedor VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTarCom VARCHAR(4) NOT NULL,
IdCta VARCHAR(4) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
NumCheque VARCHAR(20),
IdBanco VARCHAR(4) NOT NULL,
EsParcial BIT DEFAULT (0) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_DevRecBuses PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevRecBusesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdCta CHECK ((len([IdCta]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdTarCom CHECK ((len([IdTarCom]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesIdVendedor CHECK ((len([IdVendedor]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesModalidad CHECK (([Modalidad] = 'OTROS' or ([Modalidad] = 'VC' or [Modalidad] = 'CARTULINA'))),
 CONSTRAINT CK_Trn_DevRecBusesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevRecBusesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DevSal ( 
TipDev VARCHAR(3) DEFAULT ('DVS') 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 ('SAL') NOT NULL,
Salida INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
TipOrd VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2) NOT NULL,
pVehiculo VARCHAR(10),
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCont CHAR(2) DEFAULT ('00') NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
ModRequis VARCHAR(10) DEFAULT ('0') NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') 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_DevSal PRIMARY KEY NONCLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevSalCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCiaCont CHECK ((len([IdCiaCont]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdCiaOrd CHECK ((len([IdCiaOrd]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_DevSalIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevSalModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevSalModRequis CHECK ((len([ModRequis]) > 0)),
 CONSTRAINT CK_Trn_DevSalNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_DevSalOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevSalTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevSalTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevSalTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_DevSalTipOrd CHECK ((len([TipOrd]) > 0)))
CREATE TABLE Trn_DevVal ( 
TipDev VARCHAR(3) DEFAULT ('DRV') 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 ('VAL') NOT NULL,
nRadica INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
TotalPagos MONEY DEFAULT (0) NOT NULL,
TotalCobros MONEY DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
CxPagar BIT DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) 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_DevVal PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_DevValIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DevValIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_DevValIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DevValIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_DevValIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_DevValIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DevValIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_DevValIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DevValModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_DevValOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DevValTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_DevValTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_DevValTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_Disciplinario ( 
TipDoc VARCHAR(3) DEFAULT ('DIS') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecSuceso SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
TipoInf VARCHAR(10) DEFAULT ('CONDUCTOR') NOT NULL,
Lugar VARCHAR(150) NOT NULL,
NomReporta VARCHAR(150),
CedReporta VARCHAR(16),
VehiculoRep VARCHAR(10),
RepCond BIT DEFAULT (0) NOT NULL,
Coordinador VARCHAR(150),
Despachador VARCHAR(150),
CitaDescargos BIT DEFAULT (0) NOT NULL,
FecCita SMALLDATETIME,
MemoCita VARCHAR(50),
Imputacion VARCHAR(2500),
Descargos VARCHAR(3000),
FecDesc SMALLDATETIME,
RecibeDesc VARCHAR(150),
TipoSancion VARCHAR(10) NOT NULL,
DescSancion VARCHAR(1000),
FecSancion SMALLDATETIME,
CantSancion DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodInfracc INT DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
Observacion VARCHAR(250),
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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_Disciplinario PRIMARY KEY CLUSTERED (TipDoc,Numero,IdCia),
 CONSTRAINT CK_Trn_DisciplinarioIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioLugar CHECK ((len([Lugar]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_DisciplinarioTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DisInfraccion ( 
TipDoc VARCHAR(3) DEFAULT ('DIS') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Infraccion VARCHAR(250) NOT NULL
 CONSTRAINT PK_Trn_DisInfraccion PRIMARY KEY CLUSTERED (TipDoc,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_DisInfraccionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DisInfraccionInfraccion CHECK ((len([Infraccion]) > 0)),
 CONSTRAINT CK_Trn_DisInfraccionTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DocMemo ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Comentarios VARCHAR(6500) NOT NULL,
Nota1 VARCHAR(500),
Nota2 VARCHAR(500),
Nota3 VARCHAR(500),
CantImp INT DEFAULT ((0)),
ArchivoImg VARCHAR(150)
 CONSTRAINT PK_Trn_DocMemo PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia),
 CONSTRAINT CK_Trn_DocMemoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_DocMemoTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_DocSoporte ( 
TipDoc VARCHAR(3) NOT NULL,
NumDoc INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdAdquiriente VARCHAR(16),
IdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
IdMedPago VARCHAR(4) DEFAULT ('0') NOT NULL,
MetPago INT DEFAULT ((0)) NOT NULL,
Modalidad VARCHAR(20) DEFAULT ('CONTAB') NOT NULL,
NumFactura VARCHAR(15),
FechaFac SMALLDATETIME,
FechaVence SMALLDATETIME,
SubTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Descuento DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Retencion DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ReteIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Bomberil DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ImpAviTab DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
OtrosCargos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
OtrosDctos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseBom DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaBom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaAvta DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarifBom VARCHAR(4),
CodTarifAvta VARCHAR(4),
DescServicio VARCHAR(500),
CodRes VARCHAR(4),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
TipDocRef VARCHAR(3) NOT NULL,
NumDocRef INT DEFAULT ((0)) NOT NULL,
IdCiaRef CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
TipDocDev VARCHAR(3),
NumDev INT DEFAULT ((0)) NOT NULL,
CdCiaDev CHAR(2),
FecDev SMALLDATETIME,
Observacion VARCHAR(500),
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,
CodCueProv VARCHAR(16),
NitCueProv VARCHAR(16)
 CONSTRAINT PK_Trn_DocSoporte PRIMARY KEY CLUSTERED (TipDoc,NumDoc,IdCia),
 CONSTRAINT CK_Trn_DocSoporteIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_DocSoporteIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_DocSoporteIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_DocSoporteIdMedPago CHECK ((len([IdMedPago])>(0))),
 CONSTRAINT CK_Trn_DocSoporteIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_DocSoporteIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_DocSoporteModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_DocSoporteOrigenAdd CHECK ((len([OrigenAdd])>(0))))
CREATE TABLE Trn_DocSoporteDet ( 
TipDoc VARCHAR(3) NOT NULL,
NumDoc INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Descripcion VARCHAR(1000),
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorOper DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDcto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrRetencion DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrRetIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrBomberil DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrAviTab DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaDct DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaBom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaAvta DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarDct VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarifBom VARCHAR(4),
CodTarifAvta VARCHAR(4),
ItemCom INT DEFAULT ((0)) NOT NULL,
CdCuenta VARCHAR(16),
CdCueCre VARCHAR(16),
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)),
IdCiaCom CHAR(2),
Detalle VARCHAR(500),
NitTercero VARCHAR(16),
CodCC VARCHAR(16),
CodSubCc VARCHAR(16),
PlacaVeh VARCHAR(10),
Veh_Propio INT DEFAULT ((0)) NOT NULL,
NitCliente VARCHAR(16),
CodAgencia VARCHAR(16)
 CONSTRAINT PK_Trn_DocSoporteDet PRIMARY KEY CLUSTERED (TipDoc,NumDoc,IdCia,Item),
 CONSTRAINT CK_Trn_DocSoporteDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_DocSoporteDetIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_DocSoporteDetTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_EdsCalibra ( 
TipDoc VARCHAR(3) DEFAULT ('PAS') NOT NULL,
nNota INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
CdJornada VARCHAR(4) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Referencia VARCHAR(50),
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_EdsCalibra PRIMARY KEY CLUSTERED (TipDoc,nNota,IdCia),
 CONSTRAINT CK_Trn_EdsCalibraCdJornada CHECK ((len([CdJornada]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_EdsCalibraTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_EdsCortes ( 
TipDoc VARCHAR(3) DEFAULT ('PLA') NOT NULL,
Planilla INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
IdJornada VARCHAR(4) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrSobrantes MONEY DEFAULT (0) NOT NULL,
VrFaltantes MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrCreditos MONEY DEFAULT (0) NOT NULL,
VrGastComb MONEY DEFAULT (0) NOT NULL,
VrGastOtros MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrConTotal MONEY DEFAULT (0) NOT NULL,
VrConImp MONEY DEFAULT (0) NOT NULL,
VrConDcto MONEY DEFAULT (0) NOT NULL,
VrConCos MONEY DEFAULT (0) NOT NULL,
ConCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrCreTotal MONEY DEFAULT (0) NOT NULL,
VrCreImp MONEY DEFAULT (0) NOT NULL,
VrCreDcto MONEY DEFAULT (0) NOT NULL,
VrCreCos MONEY DEFAULT (0) NOT NULL,
CreCant DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
NitRef VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Referencia VARCHAR(50),
Modalidad VARCHAR(10) DEFAULT ('MANUAL') NOT NULL,
FecCorte SMALLDATETIME NOT NULL,
NumCorte INT DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoInt VARCHAR(10),
VrDctoClie MONEY DEFAULT ((0)) NOT NULL,
NumTurno INT DEFAULT ((0)) NOT NULL,
VrExcedClie MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EdsCortes PRIMARY KEY CLUSTERED (TipDoc,Planilla,IdCia),
 CONSTRAINT CK_Trn_EdsCortesIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdJornada CHECK ((len([IdJornada]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesModalidad CHECK (([Modalidad] = 'AUTO' or [Modalidad] = 'MANUAL')),
 CONSTRAINT CK_Trn_EdsCortesNitRef CHECK ((len([NitRef]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_EdsCortesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_EdsForItems ( 
TipoRango VARCHAR(3) NOT NULL,
IdRango INT DEFAULT (0) NOT NULL,
NumSerie VARCHAR(5) NOT NULL,
NumForma INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrPrecio MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrIva MONEY DEFAULT (0) NOT NULL,
TarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrDcto MONEY DEFAULT (0) NOT NULL,
Servicios BIT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(150),
ListaPrec CHAR(1) DEFAULT ('1') NOT NULL,
CantDev DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantFact DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdOperario VARCHAR(16),
Comision DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EdsForItems PRIMARY KEY CLUSTERED (TipoRango,IdRango,NumSerie,NumForma,Item),
 CONSTRAINT CK_Trn_EdsForItemsIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_EdsForItemsIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_EdsForItemsNumSerie CHECK ((len([NumSerie]) > 0)),
 CONSTRAINT CK_Trn_EdsForItemsTipoRango CHECK ((len([TipoRango]) > 0)))
CREATE TABLE Trn_EdsFormas ( 
TipoRango VARCHAR(3) NOT NULL,
IdRango INT DEFAULT (0) NOT NULL,
NumSerie VARCHAR(5) NOT NULL,
NumForma INT DEFAULT (0) NOT NULL,
Planilla INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
pVehiculo VARCHAR(10),
nVehiculo VARCHAR(10),
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdForma VARCHAR(4) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
CantPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
Observacion VARCHAR(150),
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('00') NOT NULL,
FechaDcm SMALLDATETIME,
AgencDcm VARCHAR(16),
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
VrPrecio MONEY DEFAULT ((0)) NOT NULL,
NumRef2 VARCHAR(50),
VrBase MONEY DEFAULT ((0)) NOT NULL,
VrPrecioEsp MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EdsFormas PRIMARY KEY CLUSTERED (TipoRango,IdRango,NumSerie,NumForma),
 CONSTRAINT CK_Trn_EdsFormasCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdCiaDcm CHECK ((len([IdCiaDcm]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasNumSerie CHECK ((len([NumSerie]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasTipDcm CHECK ((len([TipDcm]) > 0)),
 CONSTRAINT CK_Trn_EdsFormasTipoRango CHECK ((len([TipoRango]) > 0)))
CREATE TABLE Trn_EdsRangos ( 
TipoRango VARCHAR(3) DEFAULT ('VAL') NOT NULL,
IdRango INT DEFAULT (0) NOT NULL,
IdForma VARCHAR(4) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
pVehiculo VARCHAR(10),
nVehiculo VARCHAR(10),
IdCuenta VARCHAR(16) NOT NULL,
NumSerie VARCHAR(5) DEFAULT ('0') NOT NULL,
NumInicial INT DEFAULT (0) NOT NULL,
NumFinal INT DEFAULT (0) NOT NULL,
NumTarjeta VARCHAR(30) DEFAULT ('0') NOT NULL,
VrCupo MONEY DEFAULT (0) NOT NULL,
VrConsumos MONEY DEFAULT (0) NOT NULL,
TipoConsumo INT DEFAULT (0) NOT NULL,
ReqPlaca BIT DEFAULT (0) NOT NULL,
ReqProd BIT DEFAULT (0) NOT NULL,
ReqGalones BIT DEFAULT (0) NOT NULL,
VldAgencia BIT DEFAULT (0) NOT NULL,
VldPlaca VARCHAR(10) DEFAULT ('NONE') NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('PERSONAL') NOT NULL,
NumAuto BIT DEFAULT (0) NOT NULL,
NumActual INT DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) 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,
Cod_CCosto VARCHAR(16),
Cod_SubCosto VARCHAR(16)
 CONSTRAINT PK_Trn_EdsRangos PRIMARY KEY CLUSTERED (TipoRango,IdRango),
 CONSTRAINT CK_Trn_EdsRangosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosModalidad CHECK (([Modalidad] = 'GENERAL' or [Modalidad] = 'PERSONAL')),
 CONSTRAINT CK_Trn_EdsRangosNumSerie CHECK ((len([NumSerie]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosNumTarjeta CHECK ((len([NumTarjeta]) > 0)),
 CONSTRAINT CK_Trn_EdsRangosTipoRango CHECK (([TipoRango] = 'VGA' or ([TipoRango] = 'VPP' or ([TipoRango] = 'VCO' or ([TipoRango] = 'VAL' or ([TipoRango] = 'TDB' or [TipoRango] = 'TCR')))))),
 CONSTRAINT CK_Trn_EdsRangosVldPlaca CHECK (([VldPlaca] = 'NONE' or ([VldPlaca] = 'TRANS' or ([VldPlaca] = 'BUSES' or [VldPlaca] = 'CLIENTE')))))
CREATE TABLE Trn_EdsUnion ( 
TipDoc VARCHAR(3) DEFAULT ('UTQ') NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
CdTanque VARCHAR(4) NOT NULL,
Capacidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NivAgua DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoTrasl VARCHAR(3) DEFAULT ('NTS') NOT NULL,
NumTraslado INT DEFAULT ((0)) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_EdsUnion PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_EdsUnionCdTanque CHECK ((len([CdTanque])>(0))),
 CONSTRAINT CK_Trn_EdsUnionIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_EdsUnionIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_EdsUnionIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_EdsUnionOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_EdsUnionTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_EdsUnionTipoTrasl CHECK ((len([TipoTrasl])>(0))))
CREATE TABLE Trn_EdsUnionDisp ( 
TipDoc VARCHAR(3) DEFAULT ('UTQ') NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdMngra VARCHAR(10) NOT NULL,
LecturaGal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
LecturaVal DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EdsUnionDisp PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_EdsUnionDispIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_EdsUnionDispIdMngra CHECK ((len([IdMngra])>(0))),
 CONSTRAINT CK_Trn_EdsUnionDispIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_EdsUnionDispTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_EdsUnionItems ( 
TipDoc VARCHAR(3) DEFAULT ('UTQ') NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
Capacidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NivelAgua DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EdsUnionItems PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_EdsUnionItemsIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_EdsUnionItemsIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_EdsUnionItemsTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_EgrAntAbonos ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipCan VARCHAR(3) NOT NULL,
nAnticipo INT DEFAULT ((0)) NOT NULL,
IdCiaAnt CHAR(2) NOT NULL,
ItemAnt INT DEFAULT ((0)) NOT NULL,
VrAbonado MONEY DEFAULT ((0)) NOT NULL,
TipFac VARCHAR(3) NOT NULL,
Factura VARCHAR(15) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
ItemFac INT DEFAULT ((0)) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
FecFactura SMALLDATETIME NOT NULL,
ItemCom INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EgrAntAbonos PRIMARY KEY CLUSTERED (TipCom,Comprobante,IdCia,Item),
 CONSTRAINT CK_Trn_EgrAntAbonosFactura CHECK ((len([Factura])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosIdCiaAnt CHECK ((len([IdCiaAnt])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosTipCan CHECK ((len([TipCan])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_EgrAntAbonosTipFac CHECK ((len([TipFac])>(0))))
CREATE TABLE Trn_EgrAnticipo ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((1)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrAplicado MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_EgrAnticipo PRIMARY KEY NONCLUSTERED (TipCom,Comprobante,IdCia,Item),
 CONSTRAINT CK_Trn_EgrAnticipoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_EgrAnticipoIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_Trn_EgrAnticipoIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_EgrAnticipoTipCom CHECK ((len([TipCom])>(0))))
CREATE TABLE Trn_EgrFactura ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipFac VARCHAR(3) NOT NULL,
Factura VARCHAR(15) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
ItemFac INT DEFAULT (0) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
EsEgreso BIT DEFAULT (0) NOT NULL,
ItemCom INT DEFAULT (0) NOT NULL,
pVehiculo VARCHAR(10),
VehPropio BIT DEFAULT (0) NOT NULL,
TipDev VARCHAR(3),
NumDev INT DEFAULT (0) NOT NULL,
DetAbono VARCHAR(100)
 CONSTRAINT PK_Trn_EgrFactura PRIMARY KEY NONCLUSTERED (TipCom,Comprobante,IdCia,Item),
 CONSTRAINT CK_Trn_EgrFacturaFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_EgrFacturaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_EgrFacturaIdCiaFac CHECK ((len([IdCiaFac]) > 0)),
 CONSTRAINT CK_Trn_EgrFacturaIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_EgrFacturaIdProveedor CHECK ((len([IdProveedor]) > 0)),
 CONSTRAINT CK_Trn_EgrFacturaTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_EgrFacturaTipFac CHECK ((len([TipFac]) > 0)))
CREATE TABLE Trn_EntArticulos ( 
TipDoc VARCHAR(3) DEFAULT ('COM') NOT NULL,
Entrada INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrIva MONEY DEFAULT (0) NOT NULL,
TarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrDcto MONEY DEFAULT (0) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('0') NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2) DEFAULT ('00') NOT NULL,
TipSal VARCHAR(3) DEFAULT ('0') NOT NULL,
NumSalida INT DEFAULT (0) NOT NULL,
IdCiaSal CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_Trn_EntArticulos PRIMARY KEY CLUSTERED (TipDoc,Entrada,IdCia,Item),
 CONSTRAINT CK_Trn_EntArticulosIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosIdCiaOrd CHECK ((len([IdCiaOrd]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosIdCiaSal CHECK ((len([IdCiaSal]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosTipOrd CHECK ((len([TipOrd]) > 0)),
 CONSTRAINT CK_Trn_EntArticulosTipSal CHECK ((len([TipSal]) > 0)))
CREATE TABLE Trn_Entradas ( 
TipDoc VARCHAR(3) DEFAULT ('ENT') NOT NULL,
Entrada INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdProv VARCHAR(16) NOT NULL,
Factura VARCHAR(15) NOT NULL,
FechaFac SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrImpGlobal MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
NitFletes VARCHAR(16),
VrRetFlete MONEY DEFAULT (0) NOT NULL,
VrIcaFlete MONEY DEFAULT (0) NOT NULL,
CodTarRetFle VARCHAR(4),
CodTarIcaFle VARCHAR(4),
FletesCosto BIT DEFAULT (0) NOT NULL,
TipOdc VARCHAR(3) DEFAULT ('ODC') NOT NULL,
OCompra INT DEFAULT (0) NOT NULL,
IdCiaOdc CHAR(2) DEFAULT ('01') NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
DocEquiv VARCHAR(3) DEFAULT ('N') NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseRiv MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
TipEgr VARCHAR(3),
Egreso INT DEFAULT (0) NOT NULL,
IdCiaEgr CHAR(2),
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
VrIvaMvc MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
CodTarifBom VARCHAR(4),
VrBomberil MONEY DEFAULT ((0)) NOT NULL,
TarifaBom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
BaseIvaObsq MONEY DEFAULT ((0)) NOT NULL,
VrIvaObsequio MONEY DEFAULT ((0)) NOT NULL,
VrImpCarbono MONEY DEFAULT ((0)) NOT NULL,
TipoSA VARCHAR(3),
NumSalAlm INT DEFAULT ((0)) NOT NULL,
CdCiaSA CHAR(2),
VrImpuCons MONEY DEFAULT ((0)) NOT NULL,
VrSobtasaCons MONEY DEFAULT ((0)) NOT NULL,
BaseIvaIgp MONEY DEFAULT ((0)) NOT NULL,
VrIvaIngProd MONEY DEFAULT ((0)) NOT NULL,
TipSop VARCHAR(3),
NumDocSop INT DEFAULT ((0)) NOT NULL,
CdCiaSop CHAR(2),
ImpAviTab MONEY DEFAULT ((0)) NOT NULL,
TarifaAvta DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarifAvta VARCHAR(4)
 CONSTRAINT PK_Trn_Entradas PRIMARY KEY NONCLUSTERED (TipDoc,Entrada,IdCia),
 CONSTRAINT IX_Trn_EntradasFactura UNIQUE NONCLUSTERED (IdProv,Factura,IdCia),
 CONSTRAINT CK_Trn_EntradasDocEquiv CHECK (([DocEquiv] = 'N' or ([DocEquiv] = 'SER' or [DocEquiv] = 'COM'))),
 CONSTRAINT CK_Trn_EntradasFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdCiaOdc CHECK ((len([IdCiaOdc]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_Trn_EntradasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_EntradasModalidad CHECK (([Modalidad] = 'INSUMOS' or ([Modalidad] = 'COMBUSTBLE' or ([Modalidad] = 'INVENTARIO' or [Modalidad] = 'MAYCOMB')))),
 CONSTRAINT CK_Trn_EntradasOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_EntradasTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_EntradasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_EntradasTipOdc CHECK ((len([TipOdc]) > 0)))
CREATE TABLE Trn_Face ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
EstadoFE VARCHAR(50) NOT NULL,
Prefijo VARCHAR(20),
NumFace INT DEFAULT ((0)) NOT NULL,
CUFE VARCHAR(500),
CUFE_QR IMAGE,
Resolucion VARCHAR(50),
RangoNum VARCHAR(50),
FecVigencia VARCHAR(50),
Notas VARCHAR(3000),
FechaValidacion DATETIME
 CONSTRAINT PK_Trn_Face PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia),
 CONSTRAINT CK_Trn_FaceEstadoFE CHECK ((len([EstadoFE])>(0))),
 CONSTRAINT CK_Trn_FaceIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FaceTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_FactCausacion ( 
TipDoc VARCHAR(3) NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdCargo VARCHAR(4) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
ValorCargo MONEY DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrIva MONEY DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrReteIca MONEY DEFAULT ((0)) NOT NULL,
CdAgencia VARCHAR(16),
IdVehiculo VARCHAR(10),
Referencia VARCHAR(20),
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CdClaseCue VARCHAR(4),
TipCausac VARCHAR(3),
NumCausac INT DEFAULT ((0)) NOT NULL,
CiaCausac VARCHAR(3),
ItemCausac INT DEFAULT ((0))
 CONSTRAINT PK_Trn_FactCausacion PRIMARY KEY CLUSTERED (TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_FactCausacionDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_FactCausacionIdCargo CHECK ((len([IdCargo])>(0))))
CREATE TABLE Trn_Factcon ( 
TipDoc VARCHAR(3) DEFAULT ('FCO') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
nClieCon VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrPagosOtr MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantPuntos DECIMAL(14,4) DEFAULT (0) NOT NULL,
PuntosAcum 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,
BaseRiv MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdForma VARCHAR(4),
NumForma VARCHAR(20),
DetallePago VARCHAR(250),
Referncia1 VARCHAR(50),
Referncia2 VARCHAR(50),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
TipRem VARCHAR(3) DEFAULT ('REM') NOT NULL,
Remision INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
FecPedido SMALLDATETIME,
Modalidad VARCHAR(10) DEFAULT ('TPV') NOT NULL,
PlacaVehic VARCHAR(10),
KmtVehic INT DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
VrImpCons MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
BaseIvaObsq MONEY DEFAULT ((0)) NOT NULL,
VrIvaObsequio MONEY DEFAULT ((0)) NOT NULL,
TipoFE VARCHAR(3) DEFAULT ('1'),
FechaFE SMALLDATETIME,
CodTarArf VARCHAR(4),
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
CodTarAri VARCHAR(4),
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Factcon PRIMARY KEY NONCLUSTERED (TipDoc,Factura,IdCia),
 CONSTRAINT CK_Trn_FactconCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FactconCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCiaPed CHECK ((len([IdCiaPed]) > 0)),
 CONSTRAINT CK_Trn_FactconIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_FactconIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FactconIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FactconIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_FactconIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_FactconIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FactconIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FactconModalidad CHECK (([Modalidad] = 'CLIENTES' or [Modalidad] = 'TPV')),
 CONSTRAINT CK_Trn_FactconnClieCon CHECK ((len([nClieCon]) > 0)),
 CONSTRAINT CK_Trn_FactconNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_FactconOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FactconTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FactconTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FactconTipPed CHECK ((len([TipPed]) > 0)),
 CONSTRAINT CK_Trn_FactconTipRem CHECK ((len([TipRem]) > 0)))
CREATE TABLE Trn_Facturas ( 
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteICA MONEY DEFAULT ((0)) NOT NULL,
VrReteIVA MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrCostos MONEY DEFAULT ((0)) NOT NULL,
VrSobretasa MONEY DEFAULT ((0)) NOT NULL,
VrImpGlobal MONEY DEFAULT ((0)) NOT NULL,
VrFaltantes MONEY DEFAULT ((0)) NOT NULL,
VrAnticipos MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
VrAplicado MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantPuntos DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PuntosAcum 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,
BaseRiv MONEY DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarCom VARCHAR(4),
DirEnvio VARCHAR(250),
IdLocEnv VARCHAR(8) NOT NULL,
DiasEntraga INT DEFAULT ((0)) NOT NULL,
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargoContac VARCHAR(50),
IdForma VARCHAR(4) NOT NULL,
DetallePago VARCHAR(100),
MulPlazos BIT DEFAULT ((0)) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CdMney VARCHAR(5) NOT NULL,
NitEmpTrans VARCHAR(16) DEFAULT ('0') NOT NULL,
EmpTrans VARCHAR(150),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
TipRem VARCHAR(3) DEFAULT ('REM') NOT NULL,
Remision INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
TipCot VARCHAR(3) DEFAULT ('COT') NOT NULL,
Cotizacion INT DEFAULT ((0)) NOT NULL,
IdCiaCot CHAR(2) DEFAULT ('00') NOT NULL,
FecPedido SMALLDATETIME,
AutzaMora INT DEFAULT ((0)) NOT NULL,
AutzaCupo INT DEFAULT ((0)) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
KmtVehic INT DEFAULT ((0)) NOT NULL,
ZonaFrontera INT DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
UnidTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VolTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantFalt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrCostoRem MONEY DEFAULT ((0)) NOT NULL,
VrCostoAfi MONEY DEFAULT ((0)) NOT NULL,
CodAutoRet VARCHAR(4),
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
VrImpCons MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
Parqueadero BIT DEFAULT ((0)) NOT NULL,
FecCuotaParq SMALLDATETIME,
BaseIvaObsq MONEY DEFAULT ((0)) NOT NULL,
VrIvaObsequio MONEY DEFAULT ((0)) NOT NULL,
VrImpCarbono MONEY DEFAULT ((0)) NOT NULL,
TipoFE VARCHAR(3) DEFAULT ('1'),
FechaFE SMALLDATETIME,
BaseIvaIgp MONEY DEFAULT ((0)) NOT NULL,
VrIvaIngProd MONEY DEFAULT ((0)) NOT NULL,
CodTarArf VARCHAR(4),
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
CodTarAri VARCHAR(4),
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Facturas PRIMARY KEY NONCLUSTERED (TipDoc,Factura,IdCia),
 CONSTRAINT CK_Trn_FacturasCdConductor CHECK ((len([CdConductor])>(0))),
 CONSTRAINT CK_Trn_FacturasCdMney CHECK ((len([CdMney])>(0))),
 CONSTRAINT CK_Trn_FacturasCdRuta CHECK ((len([CdRuta])>(0))),
 CONSTRAINT CK_Trn_FacturasIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCiaCot CHECK ((len([IdCiaCot])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_FacturasIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_FacturasIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_FacturasIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_FacturasIdForma CHECK ((len([IdForma])>(0))),
 CONSTRAINT CK_Trn_FacturasIdLocEnv CHECK ((len([IdLocEnv])>(0))),
 CONSTRAINT CK_Trn_FacturasIdPlazo CHECK ((len([IdPlazo])>(0))),
 CONSTRAINT CK_Trn_FacturasIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_Trn_FacturasIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_FacturasIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_FacturasModalidad CHECK (([Modalidad]='TRANSPORTE' OR ([Modalidad]='COMBUSTBLE' OR ([Modalidad]='VALES' OR [Modalidad]='INVENTARIO')))),
 CONSTRAINT CK_Trn_FacturasNitEmpTrans CHECK ((len([NitEmpTrans])>(0))),
 CONSTRAINT CK_Trn_FacturasOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_FacturasTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_FacturasTipCot CHECK ((len([TipCot])>(0))),
 CONSTRAINT CK_Trn_FacturasTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_FacturasTipPed CHECK ((len([TipPed])>(0))),
 CONSTRAINT CK_Trn_FacturasTipRem CHECK ((len([TipRem])>(0))))
CREATE TABLE Trn_FactVales ( 
TipDoc VARCHAR(3) NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipRad VARCHAR(3) DEFAULT ('VAL') NOT NULL,
nRadica INT DEFAULT (0) NOT NULL,
IdCiaRad CHAR(2) DEFAULT ('01') NOT NULL,
ItemRad INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_FactVales PRIMARY KEY CLUSTERED (TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_FactValesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FactValesIdCiaRad CHECK ((len([IdCiaRad]) > 0)),
 CONSTRAINT CK_Trn_FactValesTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FactValesTipRad CHECK ((len([TipRad]) > 0)))
CREATE TABLE Trn_FcAbonos ( 
TipRec VARCHAR(3) NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nSemana INT DEFAULT (0) NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
Descripcion VARCHAR(150)
 CONSTRAINT PK_Trn_FcAbonos PRIMARY KEY CLUSTERED (TipRec,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_FcAbonosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FcAbonosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_FcAbonosTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_FcCausacion ( 
TipDoc VARCHAR(3) DEFAULT ('CFC') NOT NULL,
NumDoc INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecCausac SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
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_FcCausacion PRIMARY KEY CLUSTERED (TipDoc,NumDoc,IdCia),
 CONSTRAINT CK_Trn_FcCausacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FcCausacionTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FcNotas ( 
TipDoc VARCHAR(3) DEFAULT ('NCF') NOT NULL,
NumNota INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
VrNota MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
CdCCosto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdSubCos VARCHAR(16) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(50),
TipRec VARCHAR(3) DEFAULT ('0') NOT NULL,
ReciboFc INT DEFAULT (0) NOT NULL,
IdCiaRec CHAR(2) DEFAULT ('00') NOT NULL,
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,
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_FcNotas PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_FcNotasCdCCosto CHECK ((len([CdCCosto]) > 0)),
 CONSTRAINT CK_Trn_FcNotasCdSubCos CHECK ((len([CdSubCos]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdCiaRec CHECK ((len([IdCiaRec]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FcNotasIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_FcNotasOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FcNotasTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FcNotasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FcNotasTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_FcSemanas ( 
IdVehiculo VARCHAR(10) NOT NULL,
nSemana INT DEFAULT (0) NOT NULL,
NumCargue INT DEFAULT (0) NOT NULL,
CiaCargue CHAR(2) DEFAULT ('01') NOT NULL,
TipoSem INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
VrCargo MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrPagado MONEY DEFAULT (0) NOT NULL,
TipRec VARCHAR(3) NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCiaRec CHAR(2) DEFAULT ('00') NOT NULL,
FechaPago SMALLDATETIME,
Observacion VARCHAR(250),
FecSemIni SMALLDATETIME,
FecSemFin SMALLDATETIME,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_FcSemanas PRIMARY KEY CLUSTERED (IdVehiculo,nSemana),
 CONSTRAINT CK_Trn_FcSemanasIdCiaRec CHECK ((len([IdCiaRec]) > 0)),
 CONSTRAINT CK_Trn_FcSemanasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FcSemanasIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_FcSemanasTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_FinAbonos ( 
TipRec VARCHAR(3) NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCiaPre CHAR(2) NOT NULL,
ItemPre INT DEFAULT (0) NOT NULL,
TotalAbono MONEY DEFAULT (0) NOT NULL,
VrBaseCms MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantGal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Detalle VARCHAR(150),
TipoAplica INT DEFAULT (0) NOT NULL,
FecPago SMALLDATETIME NOT NULL,
TimeSys SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_FinAbonos PRIMARY KEY CLUSTERED (TipRec,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_FinAbonosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinAbonosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinAbonosIdCiaPre CHECK ((len([IdCiaPre]) > 0)),
 CONSTRAINT CK_Trn_FinAbonosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinAbonosIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinAbonosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FinAbonosTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_FinAfavor ( 
TipDoc VARCHAR(3) DEFAULT ('RC2') NOT NULL,
Recibo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Concepto VARCHAR(10) DEFAULT ('PRESTAMO') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
VrAFavor MONEY DEFAULT ((0)) NOT NULL,
VrOtrosDb MONEY DEFAULT ((0)) NOT NULL,
VrAbono MONEY DEFAULT ((0)) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
CodLinCred VARCHAR(4)
 CONSTRAINT PK_Trn_FinAfavor PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia,Concepto),
 CONSTRAINT CK_Trn_FinAfavorIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_FinAfavorIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinAfavorIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_FinAfavorIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_FinAfavorTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_FinAmtza ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
FecCausac SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
NumDias INT DEFAULT (0) NOT NULL,
VrCuota MONEY DEFAULT (0) NOT NULL,
VrCapital MONEY DEFAULT (0) NOT NULL,
VrInteres MONEY DEFAULT (0) NOT NULL,
VrSaldo MONEY DEFAULT (0) NOT NULL,
TasaEfeMes DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaEfeDia DECIMAL(16,8) DEFAULT (0) NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
CdCiaCausac CHAR(2),
VrCuoCausac MONEY DEFAULT (0) NOT NULL,
VrIntCausac MONEY DEFAULT (0) NOT NULL,
VrSaldoCausac MONEY DEFAULT (0) NOT NULL,
VrSeguroCuo MONEY DEFAULT ((0)) NOT NULL,
VrCustodia MONEY DEFAULT ((0)) NOT NULL,
VrProrroga MONEY DEFAULT ((0)) NOT NULL,
TasaCustodia DECIMAL(16,8) DEFAULT ((0)) NOT NULL,
FecInicioPM SMALLDATETIME,
FecFinalPM SMALLDATETIME,
DiasInteresPM INT DEFAULT ((0)) NOT NULL,
VrInteresPM MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinAmtza PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinAmtzaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinAmtzaTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinAportes ( 
TipLiq VARCHAR(3) DEFAULT ('APO') NOT NULL,
NumLiquida INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecLiquida SMALLDATETIME NOT NULL,
CodCia CHAR(2),
CodGrupo VARCHAR(4),
CodTipoTerc VARCHAR(4),
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
BaseApo MONEY DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
NumDev INT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_FinAportes PRIMARY KEY CLUSTERED (TipLiq,NumLiquida,IdCia),
 CONSTRAINT CK_Trn_FinAportesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinAportesIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_FinAportesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_FinAportesIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_FinAportesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_FinAportesOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_FinAportesTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_FinAportesTipLiq CHECK ((len([TipLiq])>(0))))
CREATE TABLE Trn_FinAportesDet ( 
TipLiq VARCHAR(3) DEFAULT ('APO') NOT NULL,
NumLiquida INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
FecVence SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
BaseAporte MONEY DEFAULT ((0)) NOT NULL,
TarifaApo DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrAporte MONEY DEFAULT ((0)) NOT NULL,
CdTarifApo VARCHAR(4),
Descripcion VARCHAR(500),
FecUltPago SMALLDATETIME,
FecUltLiq SMALLDATETIME,
DctoNom BIT DEFAULT ((0)) NOT NULL,
CodConcNom VARCHAR(4),
PeriodoNom VARCHAR(8),
NumCuota INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinAportesDet PRIMARY KEY CLUSTERED (TipLiq,NumLiquida,IdCia,Item),
 CONSTRAINT CK_Trn_FinAportesDetIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_FinAportesDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinAportesDetIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_FinAportesDetTipLiq CHECK ((len([TipLiq])>(0))))
CREATE TABLE Trn_FinCanAportes ( 
TipDoc VARCHAR(3) DEFAULT ('CAP') NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Observacion VARCHAR(2000),
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_FinCanAportes PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_FinCanAportesIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_FinCanAportesTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_FinCauMora ( 
TipoProc VARCHAR(3) DEFAULT ('INT') NOT NULL,
NumProc INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCiaPre CHAR(2) NOT NULL,
ItemPre INT DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
FecVence SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
FecUltLiq SMALLDATETIME NOT NULL,
FecIniLiq SMALLDATETIME NOT NULL,
FecFinLiq SMALLDATETIME NOT NULL,
DiasLiquida INT DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
BaseLiquida MONEY DEFAULT (0) NOT NULL,
TasaEA DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaEM DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaDia DECIMAL(16,8) DEFAULT (0) NOT NULL,
VrLiquida MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrIvaInt MONEY DEFAULT (0) NOT NULL,
NumNotaDb INT DEFAULT (0) NOT NULL,
NumComp INT DEFAULT (0) NOT NULL,
CdLinCred VARCHAR(4),
NCuotaLiq INT DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrRetFte MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinCauMora PRIMARY KEY CLUSTERED (TipoProc,NumProc,IdCia,Item),
 CONSTRAINT CK_Trn_FinCauMoraIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinCauMoraIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinCauMoraIdCiaPre CHECK ((len([IdCiaPre]) > 0)),
 CONSTRAINT CK_Trn_FinCauMoraIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinCauMoraIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinCauMoraTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FinCauMoraTipoProc CHECK ((len([TipoProc]) > 0)))
CREATE TABLE Trn_FinCausacion ( 
TipoProc VARCHAR(3) DEFAULT ('CAU') NOT NULL,
NumProc INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TotalCapital MONEY DEFAULT (0) NOT NULL,
TotalInteres MONEY DEFAULT (0) NOT NULL,
TotalIntMora MONEY DEFAULT (0) NOT NULL,
TotalOtros MONEY DEFAULT (0) NOT NULL,
TipoLiquida VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
TipoCred VARCHAR(10) DEFAULT ('PRESTAMOS') NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
EdoCausac INT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TotalCustodia MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinCausacion PRIMARY KEY CLUSTERED (TipoProc,NumProc,IdCia),
 CONSTRAINT CK_Trn_FinCausacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinCausacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinCausacionTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinCausacionTipoLiquida CHECK ((len([TipoLiquida]) > 0)),
 CONSTRAINT CK_Trn_FinCausacionTipoProc CHECK ((len([TipoProc]) > 0)))
CREATE TABLE Trn_FinCausaRec ( 
TipoProc VARCHAR(3) DEFAULT ('CAU') NOT NULL,
NumProc INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipRec VARCHAR(3) DEFAULT ('RC2') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCiaRec CHAR(2) DEFAULT ('01') NOT NULL,
VrCapital MONEY DEFAULT (0) NOT NULL,
TipPrest VARCHAR(3) DEFAULT ('PR1') NOT NULL,
NumPrest INT DEFAULT (0) NOT NULL,
IdCiaPrest CHAR(2) DEFAULT ('01') NOT NULL,
ItemPrest INT DEFAULT (1) NOT NULL,
NCuota INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_FinCausaRec PRIMARY KEY CLUSTERED (TipoProc,NumProc,IdCia,Item),
 CONSTRAINT CK_Trn_FinCausaRecIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinCausaRecIdCiaPrest CHECK ((len([IdCiaPrest]) > 0)),
 CONSTRAINT CK_Trn_FinCausaRecIdCiaRec CHECK ((len([IdCiaRec]) > 0)),
 CONSTRAINT CK_Trn_FinCausaRecTipoProc CHECK ((len([TipoProc]) > 0)),
 CONSTRAINT CK_Trn_FinCausaRecTipPrest CHECK ((len([TipPrest]) > 0)),
 CONSTRAINT CK_Trn_FinCausaRecTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_FinCiAportes ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
CantCuotas INT DEFAULT ((0)) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(500),
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_FinCiAportes PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_FinCiAportesIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_FinCiAportesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_FinCiAportesIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_FinCiAportesIdUsuario CHECK ((len([IdUsuario])>(0))))
CREATE TABLE Trn_FinConvenios ( 
TipLiq VARCHAR(3) DEFAULT ('CVN') NOT NULL,
NumLiquida INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
NumFactura VARCHAR(15),
FecFactura SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Observacion VARCHAR(2000),
Anulado BIT DEFAULT ((0)) NOT NULL,
NumDev INT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_FinConvenios PRIMARY KEY CLUSTERED (TipLiq,NumLiquida,IdCia),
 CONSTRAINT CK_Trn_FinConveniosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinConveniosIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_FinConveniosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_FinConveniosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_FinConveniosIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_FinConveniosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_FinConveniosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_FinConveniosTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_FinConveniosTipLiq CHECK ((len([TipLiq])>(0))))
CREATE TABLE Trn_FinCuotas ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
NumCuota INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
TipoTasa VARCHAR(10) DEFAULT ('VARIABLE') NOT NULL,
DTF_EA DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaNom DECIMAL(16,8) DEFAULT (0) NOT NULL,
Spread_TA DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaEfe DECIMAL(16,8) DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Concepto VARCHAR(10) DEFAULT ('CAPITAL') NOT NULL,
TipoCuota INT DEFAULT (0) NOT NULL,
TipoCausac VARCHAR(3) DEFAULT ('CAU') NOT NULL,
NumCausacion INT DEFAULT (0) NOT NULL,
IdCiaCau CHAR(2) DEFAULT ('00') NOT NULL,
Detalle VARCHAR(250),
FecUltPago SMALLDATETIME,
FecLiqMora SMALLDATETIME,
FechaCrea SMALLDATETIME NOT NULL,
CodLinCred VARCHAR(4),
NumFactura VARCHAR(20),
VrInteresFact MONEY DEFAULT (0) NOT NULL,
DiasLiquida INT DEFAULT (0) NOT NULL,
FecUltCausac SMALLDATETIME,
VrAcumCapital MONEY DEFAULT (0) NOT NULL,
Convenio INT DEFAULT (0) NOT NULL,
NitConvenio VARCHAR(16),
NumPreMora INT DEFAULT (0) NOT NULL,
FacturaInt INT DEFAULT (0) NOT NULL,
TipFacInt VARCHAR(3),
NumFacInt INT DEFAULT (0) NOT NULL,
CdCiaFacInt CHAR(2),
FechaFacInt SMALLDATETIME,
TarifIvaInt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrIvaInt MONEY DEFAULT ((0)) NOT NULL,
TarifRetInt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrRetInt MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinCuotas PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinCuotasConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_Trn_FinCuotasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinCuotasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinCuotasIdCiaCau CHECK ((len([IdCiaCau]) > 0)),
 CONSTRAINT CK_Trn_FinCuotasIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinCuotasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FinCuotasTipoTasa CHECK ((len([TipoTasa]) > 0)))
CREATE TABLE Trn_FinDevFac ( 
TipDev VARCHAR(3) DEFAULT ('DFI') 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 ('FIF') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
IdLocal VARCHAR(8) 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,
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinDevFac PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_FinDevFacIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacModdDev CHECK ((len([ModdDev]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_FinDevFacTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinDevPre ( 
TipDev VARCHAR(3) DEFAULT ('DP1') 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 ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrPrestamo MONEY DEFAULT (0) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
CxPagar BIT DEFAULT (0) 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_FinDevPre PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_FinDevPreIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_FinDevPreOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_FinDevPreTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinDevRec ( 
TipDev VARCHAR(3) DEFAULT ('OD2') 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 ('RC2') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
FecPago SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrRecibido MONEY DEFAULT (0) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrPagosMas MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
VrAnticipo MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseRiv MONEY DEFAULT (0) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
EnEfectivo BIT DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
NumAutoriza INT DEFAULT (0) NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') 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,
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_FinDevRec PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_FinDevRecIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_FinDevRecOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_FinDevRecTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinFactDet ( 
TipDoc VARCHAR(3) DEFAULT ('FIF') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Concepto VARCHAR(250) NOT NULL,
TipoReg VARCHAR(10) DEFAULT ('INTERESES') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
TarifIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrIva MONEY DEFAULT (0) NOT NULL,
TarifRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrRetfte MONEY DEFAULT (0) NOT NULL,
TarifIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrRetica MONEY DEFAULT (0) NOT NULL,
TarifDcto DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrDcto MONEY DEFAULT (0) NOT NULL,
nPrestamo INT DEFAULT (0) NOT NULL,
CdCiaPrest CHAR(2) DEFAULT ('00') NOT NULL,
FecIniLiq SMALLDATETIME,
FecFinLiq SMALLDATETIME,
CantDias INT DEFAULT (0) NOT NULL,
CdTarifIva VARCHAR(4),
CdTarifRet VARCHAR(4),
CdTarifIca VARCHAR(4),
CdTarifDct VARCHAR(4)
 CONSTRAINT PK_Trn_FinFactDet PRIMARY KEY CLUSTERED (TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_FinFactDetCdCiaPrest CHECK ((len([CdCiaPrest]) > 0)),
 CONSTRAINT CK_Trn_FinFactDetConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_Trn_FinFactDetIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinFactDetIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinFactDetTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FinFactDetTipoReg CHECK ((len([TipoReg]) > 0)))
CREATE TABLE Trn_FinFactint ( 
TipDoc VARCHAR(3) DEFAULT ('FIF') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseRiv MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
IdLocal VARCHAR(8) NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
TipoFactInt VARCHAR(10) DEFAULT ('FACTURAS') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CodTarRtc VARCHAR(4),
TarifaRtc DECIMAL(14,4) DEFAULT ((0)),
TipoFE VARCHAR(3) DEFAULT ('1'),
FechaFE SMALLDATETIME,
CodTarArf VARCHAR(4),
TarifaArf DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetFte MONEY DEFAULT ((0)) NOT NULL,
CodTarAri VARCHAR(4),
TarifaAri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinFactint PRIMARY KEY CLUSTERED (TipDoc,Factura,IdCia),
 CONSTRAINT CK_Trn_FinFactintIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinFactintIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinFactintOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FinFactintTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinFactintTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinFactSeguro ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((1)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
VrSaldoIni MONEY DEFAULT ((0)) NOT NULL,
VrPagos MONEY DEFAULT ((0)) NOT NULL,
TarifSeguro DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinFactSeguro PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinFactSeguroIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinFactSeguroTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_FinFacturas ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
NumFactura VARCHAR(20) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrFactura MONEY DEFAULT (0) NOT NULL,
VrInteres MONEY DEFAULT (0) NOT NULL,
DiasLiq DECIMAL(14,4) DEFAULT (0) NOT NULL,
TasaEfeMes DECIMAL(16,8) DEFAULT (0) NOT NULL,
TasaEfeDia DECIMAL(16,8) DEFAULT (0) NOT NULL,
FechaPago SMALLDATETIME NOT NULL,
ItemPago INT DEFAULT (0) NOT NULL,
FechaLiq SMALLDATETIME NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
Facturado BIT DEFAULT (0) NOT NULL,
TipFac VARCHAR(3),
FacturaInt INT DEFAULT (0) NOT NULL,
CdCiaFac CHAR(2) DEFAULT ('00'),
FecFactura SMALLDATETIME,
DiasPlazo INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_FinFacturas PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinFacturasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinFacturasNumFactura CHECK ((len([NumFactura]) > 0)),
 CONSTRAINT CK_Trn_FinFacturasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinNotas ( 
TipDoc VARCHAR(3) DEFAULT ('ND2') NOT NULL,
NumNota INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrSancion MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
VrAnticipo MONEY DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseRiv MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
Referencia VARCHAR(50),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('00') NOT NULL,
FecDcm SMALLDATETIME,
CdForma VARCHAR(4) DEFAULT ('0') NOT NULL,
NumCheque VARCHAR(20),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) DEFAULT ('0') NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('NOTA') NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Observacion VARCHAR(250),
Anulado BIT DEFAULT (0) NOT NULL,
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_FinNotas PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_FinNotasCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_Trn_FinNotasCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_FinNotasCdForma CHECK ((len([CdForma]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdCiaDcm CHECK ((len([IdCiaDcm]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinNotasIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinNotasModalidad CHECK (([Modalidad]='PRORROGA' OR [Modalidad]='NOTA' OR [Modalidad]='MORA' OR [Modalidad]='CHEQUES')),
 CONSTRAINT CK_Trn_FinNotasOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FinNotasTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinNotasTipDcm CHECK ((len([TipDcm]) > 0)),
 CONSTRAINT CK_Trn_FinNotasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinObserv ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
CausaMora VARCHAR(3000),
GestionClie VARCHAR(2000),
AcuerdosClie VARCHAR(2500)
 CONSTRAINT PK_Trn_FinObserv PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia),
 CONSTRAINT CK_Trn_FinObservIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinObservTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinPagos ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
Numero VARCHAR(20) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecPago SMALLDATETIME NOT NULL,
VrCuota MONEY DEFAULT (0) NOT NULL,
EdoForma INT DEFAULT (0) NOT NULL,
CdBanco VARCHAR(4),
CtaCheque VARCHAR(30),
Detalle VARCHAR(150),
TipRec VARCHAR(3),
Recibo INT DEFAULT (0) NOT NULL,
IdCiaRec CHAR(2),
VrLiqMora MONEY DEFAULT (0) NOT NULL,
FecLiqMora SMALLDATETIME,
VrRecCaja MONEY DEFAULT (0) NOT NULL,
TarifSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TotalSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinPagos PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinPagosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinPagosNumero CHECK ((len([Numero]) > 0)),
 CONSTRAINT CK_Trn_FinPagosTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinPrestamo ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecPrestamo SMALLDATETIME NOT NULL,
FecCorte SMALLDATETIME NOT NULL,
DiaCausac INT DEFAULT (0) NOT NULL,
DiaCausac2 INT DEFAULT (0) NOT NULL,
DiasVence VARCHAR(50),
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrPrestamo MONEY DEFAULT (0) NOT NULL,
IdLinea VARCHAR(4) DEFAULT ('0') NOT NULL,
IdTasa VARCHAR(4) NOT NULL,
NPlazos INT DEFAULT (0) NOT NULL,
TipoPlazo CHAR(1) DEFAULT ('M') NOT NULL,
Causacion VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
IdMora VARCHAR(4) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
CdCiaCon CHAR(2) DEFAULT ('01') NOT NULL,
NActaJunta INT DEFAULT (0) NOT NULL,
NumCredito VARCHAR(20) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
TipoGarantia VARCHAR(10) DEFAULT ('HIPOTECA') NOT NULL,
VrGarantia MONEY DEFAULT (0) NOT NULL,
DescGarantia VARCHAR(250),
CxPagar BIT DEFAULT (0) NOT NULL,
NumCuotaIni INT DEFAULT (0) NOT NULL,
AcumCapital MONEY DEFAULT (0) NOT NULL,
AcumIntereses MONEY DEFAULT (0) NOT NULL,
AcumIntMora MONEY DEFAULT (0) NOT NULL,
AcumCuotas INT DEFAULT (0) NOT NULL,
PagosCapital MONEY DEFAULT (0) NOT NULL,
PagosIntereses MONEY DEFAULT (0) NOT NULL,
PagosIntMora MONEY DEFAULT (0) NOT NULL,
CuotasPagadas INT DEFAULT (0) NOT NULL,
CuotasMora INT DEFAULT (0) NOT NULL,
TipoAprob VARCHAR(20) DEFAULT ('JUNTADIRECTIVA') NOT NULL,
TipoCausac INT DEFAULT (1) NOT NULL,
CdTasa2 VARCHAR(4),
VrSeguro MONEY DEFAULT (0) NOT NULL,
VrIntereses MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrCuota MONEY DEFAULT (0) NOT NULL,
TipoCredito VARCHAR(10) DEFAULT ('PRESTAMO') NOT NULL,
CalcIntMora BIT DEFAULT (1) NOT NULL,
NitEmpConv VARCHAR(16),
CuotasConv INT DEFAULT (0) NOT NULL,
Refinanciado INT DEFAULT (0) NOT NULL,
NumPrestRef INT DEFAULT (0) NOT NULL,
CiaPrestRef CHAR(2),
VrRefinanc MONEY DEFAULT (0) NOT NULL,
DescRefinanc VARCHAR(150),
CdAlmacen VARCHAR(4),
CauAnticipado BIT DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CdCtaPago VARCHAR(4) DEFAULT ('0'),
VrInteresPM MONEY DEFAULT ((0)) NOT NULL,
CantDiasPM INT DEFAULT ((0)) NOT NULL,
NumNotaIni INT DEFAULT ((0)) NOT NULL,
NumNotaFin INT DEFAULT ((0)) NOT NULL,
FechaFinPM SMALLDATETIME
 CONSTRAINT PK_Trn_FinPrestamo PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia),
 CONSTRAINT CK_Trn_FinPrestamoCausacion CHECK ((len([Causacion]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoCdCiaCon CHECK ((len([CdCiaCon]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdMora CHECK ((len([IdMora]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdTasa CHECK ((len([IdTasa]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoNumCredito CHECK ((len([NumCredito]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FinPrestamoTipoAprob CHECK ((len([TipoAprob]) > 0)))
CREATE TABLE Trn_FinPrestEgreso ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipEgr VARCHAR(3) NOT NULL,
NumEgreso INT DEFAULT (0) NOT NULL,
IdCiaEgr CHAR(2) NOT NULL,
FecEgreso SMALLDATETIME NOT NULL,
VrEgreso MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_FinPrestEgreso PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinPrestEgresoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinPrestEgresoIdCiaEgr CHECK ((len([IdCiaEgr]) > 0)),
 CONSTRAINT CK_Trn_FinPrestEgresoTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_FinPrestEgresoTipEgr CHECK ((len([TipEgr]) > 0)))
CREATE TABLE Trn_FinPrestGarant ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipoGarant VARCHAR(20) NOT NULL,
DescGarant VARCHAR(250) NOT NULL,
CdInmueble VARCHAR(4) NOT NULL,
CdTipoVeh VARCHAR(4) NOT NULL,
VrGarantia MONEY DEFAULT ((0)) NOT NULL,
VrAvaluo MONEY DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Propietario VARCHAR(250),
DirInmueble VARCHAR(250),
CdCiudad VARCHAR(8),
Matricula VARCHAR(50),
Escritura VARCHAR(50),
NumNotaria VARCHAR(20),
MarcaVeh VARCHAR(20),
Modelo VARCHAR(4),
CdBanco VARCHAR(4),
FecCheque SMALLDATETIME,
NumCheque VARCHAR(20),
OtroTipoVehic VARCHAR(50),
OtroInmueble VARCHAR(50),
CedFmnte1 VARCHAR(16),
NomFmnte1 VARCHAR(150),
CedFmnte2 VARCHAR(16),
NomFmnte2 VARCHAR(150),
CedFmnte3 VARCHAR(16),
NomFmnte3 VARCHAR(150),
CedFmnte4 VARCHAR(16),
NomFmnte4 VARCHAR(150),
CedFmnte5 VARCHAR(16),
NomFmnte5 VARCHAR(150),
CedFmnte6 VARCHAR(16),
NomFmnte6 VARCHAR(150),
ArchivoImg VARCHAR(500)
 CONSTRAINT PK_Trn_FinPrestGarant PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinPrestGarantCdInmueble CHECK ((len([CdInmueble])>(0))),
 CONSTRAINT CK_Trn_FinPrestGarantCdTipoVeh CHECK ((len([CdTipoVeh])>(0))),
 CONSTRAINT CK_Trn_FinPrestGarantDescGarant CHECK ((len([DescGarant])>(0))),
 CONSTRAINT CK_Trn_FinPrestGarantIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinPrestGarantIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_FinPrestGarantTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_FinPrestGarantTipoGarant CHECK ((len([TipoGarant])>(0))))
CREATE TABLE Trn_FinPrestSeguro ( 
TipDoc VARCHAR(3) DEFAULT ('PR1') NOT NULL,
IdPrestamo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TarifSeguro MONEY DEFAULT (0) NOT NULL,
CdTarSeguro VARCHAR(4)
 CONSTRAINT PK_Trn_FinPrestSeguro PRIMARY KEY CLUSTERED (TipDoc,IdPrestamo,IdCia,Item),
 CONSTRAINT CK_Trn_FinPrestSeguroIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_FinPrestSeguroTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_FinRecibos ( 
TipDoc VARCHAR(3) DEFAULT ('RC2') NOT NULL,
Recibo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FecPago SMALLDATETIME NOT NULL,
VrRecibido MONEY DEFAULT ((0)) NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteICA MONEY DEFAULT ((0)) NOT NULL,
VrReteIVA MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrPagosMas MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
VrAplicado MONEY DEFAULT ((0)) NOT NULL,
VrEfectivo MONEY DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
BaseRet MONEY DEFAULT ((0)) NOT NULL,
BaseIca MONEY DEFAULT ((0)) NOT NULL,
BaseRiv MONEY DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarCom VARCHAR(4),
EnEfectivo BIT DEFAULT ((0)) NOT NULL,
CdForma VARCHAR(4),
NumForma VARCHAR(20),
DetallePago VARCHAR(250),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
CdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(50),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
TipoCredito VARCHAR(10),
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT ((0)) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('00') NOT NULL,
VrAboCapital MONEY DEFAULT ((0)) NOT NULL,
LiqAboCapital INT DEFAULT ((0)) NOT NULL,
VrAboOtros MONEY DEFAULT ((0)),
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,
VrPagoCuotas MONEY DEFAULT ((0)) NOT NULL,
VrPagoAportes MONEY DEFAULT ((0)) NOT NULL,
VrPagoConvenio MONEY DEFAULT ((0)) NOT NULL,
VrAboCuotas MONEY DEFAULT ((0)) NOT NULL,
VrAboAportes MONEY DEFAULT ((0)) NOT NULL,
VrAboConvenio MONEY DEFAULT ((0)) NOT NULL,
VrAntPrestamo MONEY DEFAULT ((0)) NOT NULL,
VrAntAportes MONEY DEFAULT ((0)) NOT NULL,
VrAntConvenio MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_FinRecibos PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia),
 CONSTRAINT CK_Trn_FinRecibosCdBanco CHECK ((len([CdBanco])>(0))),
 CONSTRAINT CK_Trn_FinRecibosCdConductor CHECK ((len([CdConductor])>(0))),
 CONSTRAINT CK_Trn_FinRecibosCdCta CHECK ((len([CdCta])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdCiaDcm CHECK ((len([IdCiaDcm])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_FinRecibosIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_FinRecibosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_FinRecibosTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_FinRecibosTipDcm CHECK ((len([TipDcm])>(0))),
 CONSTRAINT CK_Trn_FinRecibosTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_Guia ( 
TipDoc VARCHAR(3) DEFAULT ('GUI') NOT NULL,
Guia INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaDesp SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DirEnvio VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
LugarEnv VARCHAR(50),
HorasVig DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
NitEmpTrans VARCHAR(16) DEFAULT ('0') NOT NULL,
EmpTrans VARCHAR(150),
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
CdCiuOrigen VARCHAR(8) DEFAULT ('0') NOT NULL,
Referncia VARCHAR(50),
TipOcc VARCHAR(3) DEFAULT ('OCC') NOT NULL,
OCargue INT DEFAULT ((0)) NOT NULL,
IdCiaOcc CHAR(2) DEFAULT ('01') NOT NULL,
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
FechaFact SMALLDATETIME,
OrigenAdd VARCHAR(10) NOT NULL,
ZonaFrontera INT DEFAULT ((0)) NOT NULL,
TipoTemp VARCHAR(10),
Temperatura DECIMAL(14,4) DEFAULT ((0)),
Remolque VARCHAR(10),
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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,
TipoOCargue INT DEFAULT ((0)),
NumVerifica INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Guia PRIMARY KEY CLUSTERED (TipDoc,Guia,IdCia),
 CONSTRAINT CK_Trn_GuiaCdCiuOrigen CHECK ((len([CdCiuOrigen])>(0))),
 CONSTRAINT CK_Trn_GuiaCdRuta CHECK ((len([CdRuta])>(0))),
 CONSTRAINT CK_Trn_GuiaDirEnvio CHECK ((len([DirEnvio])>(0))),
 CONSTRAINT CK_Trn_GuiaIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_GuiaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_GuiaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_GuiaIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_GuiaIdCiaOcc CHECK ((len([IdCiaOcc])>(0))),
 CONSTRAINT CK_Trn_GuiaIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_GuiaIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_GuiaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_GuiaIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_Trn_GuiaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_GuiaIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_GuiaNitEmpTrans CHECK ((len([NitEmpTrans])>(0))),
 CONSTRAINT CK_Trn_GuiaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_GuiaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_GuiaTipFac CHECK ((len([TipFac])>(0))),
 CONSTRAINT CK_Trn_GuiaTipOcc CHECK ((len([TipOcc])>(0))))
CREATE TABLE Trn_InvDetalle ( 
TipDoc VARCHAR(3) DEFAULT ('FIS') NOT NULL,
nInventario INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10) DEFAULT ('0') NOT NULL,
CdTanque VARCHAR(4) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
CantExist DECIMAL(14,4) DEFAULT (0) NOT NULL,
Descripcion VARCHAR(250),
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndAforo DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndAgua DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantAgua DECIMAL(14,4) DEFAULT (0) NOT NULL,
NoConteo BIT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
IdEstacion CHAR(2) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_InvDetalle PRIMARY KEY CLUSTERED (TipDoc,nInventario,IdCia,Item),
 CONSTRAINT CK_Trn_InvDetalleCdTanque CHECK ((len([CdTanque]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleCdUbic CHECK ((len([CdUbic]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleIdEstacion CHECK ((len([IdEstacion]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_InvDetalleTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_InvFisico ( 
TipDoc VARCHAR(3) DEFAULT ('FIS') NOT NULL,
nInventario INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
CdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
CantFisico DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrTotalFisico MONEY DEFAULT (0) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrTotalCosto MONEY DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Procesado BIT DEFAULT (0) NOT NULL,
FecProceso SMALLDATETIME,
NumAjuSob INT DEFAULT (0) NOT NULL,
NumAjuFal INT DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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,
FCodBodega VARCHAR(4),
FCodMarca VARCHAR(4),
FCodSubGrupo VARCHAR(8)
 CONSTRAINT PK_Trn_InvFisico PRIMARY KEY CLUSTERED (TipDoc,nInventario,IdCia),
 CONSTRAINT CK_Trn_InvFisicoCdBodega CHECK ((len([CdBodega]) > 0)),
 CONSTRAINT CK_Trn_InvFisicoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_InvFisicoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_InvFisicoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_InvFisicoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_InvFisicoModalidad CHECK (([Modalidad] = 'OTRO' or ([Modalidad] = 'COMBUSTBLE' or [Modalidad] = 'INVENTARIO'))),
 CONSTRAINT CK_Trn_InvFisicoOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_InvFisicoTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurCasos ( 
TipDoc VARCHAR(3) DEFAULT ('SIN') NOT NULL,
CasoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Radicacion VARCHAR(20) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
SinRecorrido BIT DEFAULT (0) NOT NULL,
TipCar VARCHAR(3) DEFAULT ('CAR') NOT NULL,
Cartulina INT DEFAULT (0) NOT NULL,
IdCiaCar CHAR(2) DEFAULT ('01') NOT NULL,
FechaSuc SMALLDATETIME NOT NULL,
IdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
IdAbogado VARCHAR(16) NOT NULL,
IdAuxiliar VARCHAR(16) NOT NULL,
IdAutoridad VARCHAR(4) NOT NULL,
IdTipoPro VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCalifica VARCHAR(4) NOT NULL,
LugarAcc VARCHAR(100),
CausaAcc VARCHAR(3300) NOT NULL,
Comentario VARCHAR(3300),
Observacion VARCHAR(250),
Contraparte VARCHAR(100),
DirContraparte VARCHAR(100),
TelContraparte VARCHAR(20),
ValDanosCParte MONEY DEFAULT (0) NOT NULL,
ValDanosEmp MONEY DEFAULT (0) NOT NULL,
ValDeducible MONEY DEFAULT (0) NOT NULL,
EmpAsegdora VARCHAR(100),
AuxMutuo BIT DEFAULT (0) NOT NULL,
ArchivoCaso VARCHAR(100),
Documntos VARCHAR(250),
Croquis VARCHAR(20),
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Reclamaciones VARCHAR(1000),
CdCausal VARCHAR(4),
Cedtraparte VARCHAR(16),
PolizaResCivil VARCHAR(30),
VigencResCivil SMALLDATETIME,
NitEmpAseg VARCHAR(16),
NombreAseg VARCHAR(150)
 CONSTRAINT PK_Trn_JurCasos PRIMARY KEY CLUSTERED (TipDoc,CasoID,IdCia),
 CONSTRAINT CK_Trn_JurCasosIdAbogado CHECK ((len([IdAbogado]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdAutoridad CHECK ((len([IdAutoridad]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdAuxiliar CHECK ((len([IdAuxiliar]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdCalifica CHECK ((len([IdCalifica]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdCiaCar CHECK ((len([IdCiaCar]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdTipoPro CHECK ((len([IdTipoPro]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_JurCasosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_JurCasosRadicacion CHECK ((len([Radicacion]) > 0)),
 CONSTRAINT CK_Trn_JurCasosTipCar CHECK ((len([TipCar]) > 0)),
 CONSTRAINT CK_Trn_JurCasosTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurCasosHis ( 
TipDoc VARCHAR(3) DEFAULT ('SIN') NOT NULL,
CasoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
ActualizaID INT DEFAULT (0) NOT NULL,
FechaUp SMALLDATETIME NOT NULL,
Historial VARCHAR(3500) NOT NULL,
EstadoAct VARCHAR(3500),
CierreProc BIT DEFAULT (0) NOT NULL,
ArchivoProc VARCHAR(100),
NombreCparte VARCHAR(100),
DirCparte VARCHAR(100),
TelCparte VARCHAR(20),
DanosCParte MONEY DEFAULT (0) NOT NULL,
DanosEmp MONEY DEFAULT (0) NOT NULL,
ValorDeducible MONEY DEFAULT (0) NOT NULL,
Aseguradora VARCHAR(100),
AuxilioMutuo BIT DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) DEFAULT ('0') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CedContparte VARCHAR(16)
 CONSTRAINT PK_Trn_JurCasosHis PRIMARY KEY CLUSTERED (TipDoc,CasoID,IdCia,ActualizaID),
 CONSTRAINT CK_Trn_JurCasosHisIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurCasosHisIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_JurCasosHisIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_JurCasosHisTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurCasosQtn ( 
TipDoc VARCHAR(3) DEFAULT ('SIN') NOT NULL,
CasoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdPregunta VARCHAR(4) NOT NULL,
Descripcion VARCHAR(250) NOT NULL
 CONSTRAINT PK_Trn_JurCasosQtn PRIMARY KEY CLUSTERED (TipDoc,CasoID,IdCia,Item),
 CONSTRAINT CK_Trn_JurCasosQtnDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Trn_JurCasosQtnIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurCasosQtnIdPregunta CHECK ((len([IdPregunta]) > 0)),
 CONSTRAINT CK_Trn_JurCasosQtnTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurInvesHis ( 
TipDoc VARCHAR(3) DEFAULT ('IVG') NOT NULL,
CasoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
ActualizaID INT DEFAULT (0) NOT NULL,
FechaUp SMALLDATETIME NOT NULL,
Historial VARCHAR(3000) NOT NULL,
EstadoAct VARCHAR(3000),
Pruebas VARCHAR(1200),
Documntos VARCHAR(250),
CierreProc BIT DEFAULT (0) NOT NULL,
ArchivoProc VARCHAR(100),
NombreCparte VARCHAR(100),
DirCparte VARCHAR(100),
TelCparte VARCHAR(20),
IdEstado VARCHAR(4) DEFAULT ('0') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CedContparte VARCHAR(16)
 CONSTRAINT PK_Trn_JurInvesHis PRIMARY KEY CLUSTERED (TipDoc,CasoID,IdCia,ActualizaID),
 CONSTRAINT CK_Trn_JurInvesHisIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurInvesHisIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_JurInvesHisIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_JurInvesHisTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurInvestiga ( 
TipDoc VARCHAR(3) DEFAULT ('IVG') NOT NULL,
CasoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Radicacion VARCHAR(20) NOT NULL,
IdAbogado VARCHAR(16) NOT NULL,
IdAuxiliar VARCHAR(16) NOT NULL,
IdAutoridad VARCHAR(4) NOT NULL,
IdEmpresa VARCHAR(16) NOT NULL,
Observacion VARCHAR(250),
Contraparte VARCHAR(100),
DirContraparte VARCHAR(100),
TelContraparte VARCHAR(20),
ArchivoCaso VARCHAR(100),
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Cedtraparte VARCHAR(16),
CdTipoPro VARCHAR(4),
CdCausal VARCHAR(4)
 CONSTRAINT PK_Trn_JurInvestiga PRIMARY KEY CLUSTERED (TipDoc,CasoID,IdCia),
 CONSTRAINT CK_Trn_JurInvestigaIdAbogado CHECK ((len([IdAbogado]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdAutoridad CHECK ((len([IdAutoridad]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdAuxiliar CHECK ((len([IdAuxiliar]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdEmpresa CHECK ((len([IdEmpresa]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaRadicacion CHECK ((len([Radicacion]) > 0)),
 CONSTRAINT CK_Trn_JurInvestigaTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurInvVehic ( 
TipDoc VARCHAR(3) DEFAULT ('IVG') NOT NULL,
CasoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL
 CONSTRAINT PK_Trn_JurInvVehic PRIMARY KEY CLUSTERED (TipDoc,CasoID,IdCia,Item),
 CONSTRAINT CK_Trn_JurInvVehicIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurInvVehicIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_JurInvVehicIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_JurInvVehicIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_JurInvVehicTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_JurReclamac ( 
TipDoc VARCHAR(3) DEFAULT ('JRC') NOT NULL,
Reclamac INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaRec SMALLDATETIME NOT NULL,
TipSin VARCHAR(3) DEFAULT ('SIN') NOT NULL,
Siniestro INT DEFAULT (0) NOT NULL,
IdCiaSin CHAR(2) NOT NULL,
IdReclamnte VARCHAR(16) NOT NULL,
IdTipoRec VARCHAR(4) NOT NULL,
VrReclamac MONEY DEFAULT (0) NOT NULL,
Observacion VARCHAR(1000),
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_JurReclamac PRIMARY KEY CLUSTERED (TipDoc,Reclamac,IdCia),
 CONSTRAINT CK_Trn_JurReclamacIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacIdCiaSin CHECK ((len([IdCiaSin]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacIdReclamnte CHECK ((len([IdReclamnte]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacIdTipoRec CHECK ((len([IdTipoRec]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_JurReclamacTipSin CHECK ((len([TipSin]) > 0)))
CREATE TABLE Trn_JurRecOfrecmto ( 
TipDoc VARCHAR(3) DEFAULT ('JRC') NOT NULL,
Reclamac INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
FechaOfrec SMALLDATETIME NOT NULL,
VrOfrecmto MONEY DEFAULT (0) NOT NULL,
OfcAceptado INT DEFAULT (0) NOT NULL,
FecAceptado SMALLDATETIME,
OfcPagado INT DEFAULT (0) NOT NULL,
NumSolGiro VARCHAR(30),
Comentarios VARCHAR(1000),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_JurRecOfrecmto PRIMARY KEY CLUSTERED (TipDoc,Reclamac,IdCia,Item),
 CONSTRAINT CK_Trn_JurRecOfrecmtoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_JurRecOfrecmtoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_JurRecOfrecmtoTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_Kardex ( 
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,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdTanque VARCHAR(4),
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrPrecio MONEY DEFAULT (0) NOT NULL,
VrCostProm MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrIvaEnt MONEY DEFAULT (0) NOT NULL,
VrIvaSal MONEY DEFAULT (0) NOT NULL,
TarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrDctoEnt MONEY DEFAULT (0) NOT NULL,
VrDctoSal MONEY DEFAULT (0) NOT NULL,
VrCostoEnt MONEY DEFAULT (0) NOT NULL,
VrCostoSal MONEY DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrReteEnt MONEY DEFAULT (0) NOT NULL,
VrReteSal MONEY DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrIcaEnt MONEY DEFAULT (0) NOT NULL,
VrIcaSal MONEY DEFAULT (0) NOT NULL,
VrBruto MONEY DEFAULT (0) NOT NULL,
CdUbic VARCHAR(10),
NumLote VARCHAR(30),
FechLote SMALLDATETIME,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CdAgencia VARCHAR(16),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
CdLocal VARCHAR(8) NOT NULL,
CdSzona VARCHAR(4),
pVehiculo VARCHAR(10),
IdVend VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
CdOperario VARCHAR(16),
ComisnOper DECIMAL(14,4) DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
Descripcion VARCHAR(250),
Comptmntos VARCHAR(50),
CdProdEquiv VARCHAR(16),
TipOrd VARCHAR(3) DEFAULT ('0') NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2) DEFAULT ('00') NOT NULL,
Cotizacion INT DEFAULT (0) NOT NULL,
IdCiaCot CHAR(2) DEFAULT ('00') NOT NULL,
Remision INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
Factura VARCHAR(15),
TipDocDev VARCHAR(3) DEFAULT ('0') NOT NULL,
NumDocDev INT DEFAULT (0) NOT NULL,
CdMngra VARCHAR(10),
NumInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Sobretasa DECIMAL(14,4) DEFAULT (0) NOT NULL,
TasaNac DECIMAL(14,4) DEFAULT (0) NOT NULL,
TasaDep DECIMAL(14,4) DEFAULT (0) NOT NULL,
TasaMun DECIMAL(14,4) DEFAULT (0) NOT NULL,
Soldicom DECIMAL(14,4) DEFAULT (0) NOT NULL,
ImpGlobal DECIMAL(14,4) DEFAULT (0) NOT NULL,
OtroImpto DECIMAL(14,4) DEFAULT (0) NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
ItemCombo INT DEFAULT (0) NOT NULL,
Servcios BIT DEFAULT (0) NOT NULL,
NoVentas INT DEFAULT (0) NOT NULL,
EsCombo BIT DEFAULT (0) NOT NULL,
EsProdBase INT DEFAULT (0) NOT NULL,
CodTarDct VARCHAR(4),
CodTarIva VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarCom VARCHAR(4),
CodTarCmc VARCHAR(4),
ListaPrec CHAR(1) DEFAULT ('0') NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
CdMoneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
VrTasaCamb MONEY DEFAULT (0) NOT NULL,
VrDivisa1 MONEY DEFAULT (0) NOT NULL,
VrDivisa2 MONEY DEFAULT (0) NOT NULL,
VrDivisa3 MONEY DEFAULT (0) NOT NULL,
Referencia2 VARCHAR(50),
FecOrden SMALLDATETIME,
galsbruto DECIMAL(14,4) DEFAULT (0),
galsneto DECIMAL(14,4) DEFAULT (0),
Temperatura DECIMAL(14,4) DEFAULT (0),
UmTemp VARCHAR(3),
Densidad DECIMAL(14,4) DEFAULT (0),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Rec_Costo DECIMAL(14,4) DEFAULT (0) NOT NULL,
MgenCont DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrImvCosto DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
TarifaIco DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrImpCon DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
CantObseq DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrIvaObseq MONEY DEFAULT ((0)) NOT NULL,
BaseIvaCom DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
ImpCarbono DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IngBaseCom DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
TarifaStc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
SobtasaCons DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
CodTarIco VARCHAR(4),
BaseIvp MONEY DEFAULT ((0)) NOT NULL,
TarifaIvp DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IvaIngProd MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Kardex PRIMARY KEY NONCLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_KardexCdLocal CHECK ((len([CdLocal]) > 0)),
 CONSTRAINT CK_Trn_KardexCdMoneda CHECK ((len([CdMoneda]) > 0)),
 CONSTRAINT CK_Trn_KardexIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_KardexIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_KardexIdCiaCot CHECK ((len([IdCiaCot]) > 0)),
 CONSTRAINT CK_Trn_KardexIdCiaOrd CHECK ((len([IdCiaOrd]) > 0)),
 CONSTRAINT CK_Trn_KardexIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_KardexIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_KardexIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_KardexIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_KardexIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_Trn_KardexIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_KardexIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_KardexListaPrec CHECK ((len([ListaPrec]) > 0)),
 CONSTRAINT CK_Trn_KardexTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_KardexTipDocDev CHECK ((len([TipDocDev]) > 0)),
 CONSTRAINT CK_Trn_KardexTipOrd CHECK ((len([TipOrd]) > 0)))
CREATE TABLE Trn_KarUbic ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Linea INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_KarUbic PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_KarUbicIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_KarUbicIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_KarUbicIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_KarUbicIdUbic CHECK ((len([IdUbic]) > 0)),
 CONSTRAINT CK_Trn_KarUbicTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_Lotes ( 
NumLote VARCHAR(30) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
SaldoActual DECIMAL(14,4) DEFAULT (0) NOT NULL,
NitProv VARCHAR(16),
TipDoc VARCHAR(3),
Entrada INT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_Lotes PRIMARY KEY CLUSTERED (NumLote,IdProducto,IdCia,IdBodega,IdUbic),
 CONSTRAINT CK_Trn_LotesIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_LotesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_LotesIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_LotesIdUbic CHECK ((len([IdUbic]) > 0)),
 CONSTRAINT CK_Trn_LotesNumLote CHECK ((len([NumLote]) > 0)))
CREATE TABLE Trn_LotMov ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
NumLote VARCHAR(30) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
Entradas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
Linea INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_LotMov PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_LotMovIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_LotMovIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_LotMovIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_LotMovNumLote CHECK ((len([NumLote]) > 0)),
 CONSTRAINT CK_Trn_LotMovTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_MayAcumula ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
nPeriodo VARCHAR(6) NOT NULL,
TipoProd VARCHAR(20) DEFAULT ('COMBUSTIBLE') NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_MayAcumula PRIMARY KEY CLUSTERED (NContrato,IdCia,nPeriodo,TipoProd,CdProducto))
CREATE TABLE Trn_MayAgencias ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdAgencia VARCHAR(16) NOT NULL
 CONSTRAINT PK_Trn_MayAgencias PRIMARY KEY CLUSTERED (NContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MayAgenciasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_MayAgenciasIdCia CHECK ((len([IdCia]) > 0)))
CREATE TABLE Trn_MayAnotaciones ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Detalle VARCHAR(5000) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_MayAnotaciones PRIMARY KEY CLUSTERED (NContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MayAnotacionesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayAnotacionesIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_MayBonif ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoProd VARCHAR(20) DEFAULT ('COMBUSTIBLE') NOT NULL,
VrInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Unidad VARCHAR(10) DEFAULT ('galones'),
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoTarifa CHAR(1) DEFAULT ('$') NOT NULL,
Periodo VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdSubgrupo VARCHAR(8) DEFAULT ('0') NOT NULL,
TipoMargen CHAR(1) DEFAULT ('B'),
IntvExcluido BIT DEFAULT ((0)) NOT NULL,
IntvGlobal BIT DEFAULT ((0)) NOT NULL,
IvaIncluido BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_MayBonif PRIMARY KEY CLUSTERED (NContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MayBonifCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_Trn_MayBonifCdSubgrupo CHECK ((len([CdSubgrupo]) > 0)),
 CONSTRAINT CK_Trn_MayBonifIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayBonifPeriodo CHECK (([Periodo] = 'ANUAL' or ([Periodo] = 'SEMESTRAL' or ([Periodo] = 'TRIMESTRAL' or ([Periodo] = 'BIMENSUAL' or [Periodo] = 'MENSUAL'))))),
 CONSTRAINT CK_Trn_MayBonifTipoProd CHECK (([TipoProd] = 'COMBUSTIBLE' or [TipoProd] = 'OTROS')),
 CONSTRAINT CK_Trn_MayBonifTipoTarifa CHECK (([TipoTarifa]='M' OR [TipoTarifa]='$' OR [TipoTarifa]='%')))
CREATE TABLE Trn_MayCesion ( 
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) NOT NULL,
IdNueClie VARCHAR(16) NOT NULL,
IdNueAgenc VARCHAR(16) NOT NULL,
FecInicio SMALLDATETIME,
ClaseCont VARCHAR(10),
CdTipoCont VARCHAR(4),
CuotaBase DECIMAL(14,4) DEFAULT (0) NOT NULL,
CuotaMin DECIMAL(14,4) DEFAULT (0) NOT NULL,
AcumGals DECIMAL(14,4) DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_MayCesion PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_Trn_MayCesionIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_MayCesionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayCesionIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_MayCesionIdNueAgenc CHECK ((len([IdNueAgenc]) > 0)),
 CONSTRAINT CK_Trn_MayCesionIdNueClie CHECK ((len([IdNueClie]) > 0)),
 CONSTRAINT CK_Trn_MayCesionIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_MayContDoc ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdDoc VARCHAR(4) NOT NULL,
FechaRad SMALLDATETIME NOT NULL,
Dependencia VARCHAR(50) NOT NULL,
Estado VARCHAR(10) DEFAULT ('RADICADO') NOT NULL,
FechaAprob SMALLDATETIME,
Comentarios VARCHAR(250),
CdUsuario VARCHAR(11) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_Trn_MayContDoc PRIMARY KEY CLUSTERED (NContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MayContDocCdUsuario CHECK ((len([CdUsuario]) > 0)),
 CONSTRAINT CK_Trn_MayContDocDependencia CHECK ((len([Dependencia]) > 0)),
 CONSTRAINT CK_Trn_MayContDocEstado CHECK (([Estado] = 'PENDIENTE' or ([Estado] = 'APROBADO' or [Estado] = 'RADICADO'))),
 CONSTRAINT CK_Trn_MayContDocIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayContDocIdDoc CHECK ((len([IdDoc]) > 0)))
CREATE TABLE Trn_MayContratos ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdTipo VARCHAR(4) NOT NULL,
IdBonif VARCHAR(4) NOT NULL,
ConvBonif BIT DEFAULT (0) NOT NULL,
CuotaFija BIT DEFAULT (0) NOT NULL,
CondPago BIT DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
ModPlazo VARCHAR(10) DEFAULT ('TIEMPO') NOT NULL,
Plazo INT DEFAULT (0),
FechaVence SMALLDATETIME,
ModRecursos VARCHAR(150),
VrInversion MONEY DEFAULT (0) NOT NULL,
VrInventario MONEY DEFAULT (0) NOT NULL,
VrCuota MONEY DEFAULT (0) NOT NULL,
ModCuota VARCHAR(10) DEFAULT ('NONE') NOT NULL,
IdBandera VARCHAR(4) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
AprobJunta INT DEFAULT (0) NOT NULL,
FechaAprob SMALLDATETIME,
ObservAprob VARCHAR(250),
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,
FechaInicio SMALLDATETIME NOT NULL,
CuotaMin DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoAprob VARCHAR(10) DEFAULT ('JUNTADIR') NOT NULL,
NumInterno VARCHAR(20) DEFAULT ('0') NOT NULL,
InvCombus DECIMAL(14,4) DEFAULT (0) NOT NULL,
CuotaBase DECIMAL(14,4) DEFAULT (0) NOT NULL,
FechaFirma SMALLDATETIME,
CdAprobNeg VARCHAR(4),
ArchivoAprob VARCHAR(50),
ClaseContrato VARCHAR(10),
DescTipoCont VARCHAR(250),
GarantHipoteca BIT DEFAULT (0) NOT NULL,
GarantPrenda BIT DEFAULT (0) NOT NULL,
GarantPoliza BIT DEFAULT (0) NOT NULL,
GarantBanco BIT DEFAULT (0) NOT NULL,
GarantPagare BIT DEFAULT (0) NOT NULL,
GarantOtro BIT DEFAULT (0) NOT NULL,
CdTipoBien VARCHAR(4),
VrAvaludo MONEY DEFAULT (0) NOT NULL,
NroEscritura VARCHAR(50),
CdTipoPoliza VARCHAR(4),
DescPoliza VARCHAR(150),
VigencPoliza INT DEFAULT (0) NOT NULL,
FecVencPoliza SMALLDATETIME,
ValorPoliza MONEY DEFAULT (0) NOT NULL,
EdoGarantias INT DEFAULT (0) NOT NULL,
DescGarantOtro VARCHAR(250),
InverContab INT DEFAULT (0) NOT NULL,
InverContrac INT DEFAULT (0) NOT NULL,
VolContMes DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolContTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolViabMes DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolViabTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
InvCtbObra MONEY DEFAULT (0) NOT NULL,
InvCtbCapital MONEY DEFAULT (0) NOT NULL,
InvCtbEfectivo MONEY DEFAULT (0) NOT NULL,
InvCtbImagen MONEY DEFAULT (0) NOT NULL,
InvCtbMntmto MONEY DEFAULT (0) NOT NULL,
FecDesemb SMALLDATETIME,
InvContObra MONEY DEFAULT (0) NOT NULL,
InvContCapital MONEY DEFAULT (0) NOT NULL,
InvContEfectivo MONEY DEFAULT (0) NOT NULL,
InvContImagen MONEY DEFAULT (0) NOT NULL,
CrtlAprovInv INT DEFAULT (0) NOT NULL,
CrtlAprovImg INT DEFAULT (0) NOT NULL,
CdTipoBloq VARCHAR(4),
EdoDocmtos INT DEFAULT (0) NOT NULL,
DescEdoDoc VARCHAR(250),
RentabInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
GraciaBonif INT DEFAULT (0) NOT NULL,
ActFechaIni INT DEFAULT (0) NOT NULL,
CdZonaCont VARCHAR(4),
ContVigente BIT DEFAULT (0) NOT NULL,
VolContrac INT DEFAULT (0) NOT NULL,
DescHipotec VARCHAR(250),
VrAvaComerc MONEY DEFAULT (0) NOT NULL,
FecRegEscritura SMALLDATETIME,
NotariaEsc VARCHAR(50),
CdTipPrenda VARCHAR(4),
VrAvaPrenda MONEY DEFAULT (0) NOT NULL,
PolizaPrenda VARCHAR(30),
FecVigPrenda SMALLDATETIME,
VrAsegPrenda MONEY DEFAULT (0) NOT NULL,
ContOperando BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_MayContratos PRIMARY KEY CLUSTERED (NContrato,IdCia),
 CONSTRAINT CK_Trn_MayContratosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdBandera CHECK ((len([IdBandera]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdBonif CHECK ((len([IdBonif]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdTipo CHECK ((len([IdTipo]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_MayContratosIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_MayContratosModCuota CHECK (([ModCuota] = 'ANUAL' or ([ModCuota] = 'SEMESTRAL' or ([ModCuota] = 'TRIMESTRAL' or ([ModCuota] = 'BIMENSUAL' or ([ModCuota] = 'MENSUAL' or [ModCuota] = 'NONE')))))),
 CONSTRAINT CK_Trn_MayContratosModPlazo CHECK ((len([ModPlazo]) > 0)))
CREATE TABLE Trn_MayFacturas ( 
TipFac VARCHAR(3) NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
CantDev DECIMAL(14,4) DEFAULT (0) NOT NULL,
ValorDev MONEY DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
CdCiaCon CHAR(2) DEFAULT ('01') NOT NULL,
ClaseCont VARCHAR(10),
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
EsProdBase INT DEFAULT (0) NOT NULL,
TipoProd VARCHAR(20) DEFAULT ('COMBUSTIBLE')
 CONSTRAINT PK_Trn_MayFacturas PRIMARY KEY NONCLUSTERED (TipFac,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_MayFacturasCdCiaCon CHECK ((len([CdCiaCon]) > 0)),
 CONSTRAINT CK_Trn_MayFacturasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_MayFacturasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayFacturasIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_MayFacturasIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_MayFacturasTipFac CHECK ((len([TipFac]) > 0)))
CREATE TABLE Trn_MayInventario ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdArticulo VARCHAR(16) NOT NULL,
Detalle VARCHAR(150),
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
TipoArticulo VARCHAR(10) NOT NULL,
Referencia VARCHAR(50),
IdTipo VARCHAR(4) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('00') NOT NULL,
CantEntrega DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecEntrega SMALLDATETIME,
Estado VARCHAR(10) DEFAULT ('PENDIENTE') NOT NULL,
CdProd VARCHAR(16) DEFAULT ('0') NOT NULL,
NumReq INT DEFAULT (0) NOT NULL,
IdCiaReq CHAR(2),
CantReq DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2),
CantOrden DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_MayInventario PRIMARY KEY CLUSTERED (NContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MayInventarioCdProd CHECK ((len([CdProd]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioEstado CHECK ((len([Estado]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioIdArticulo CHECK ((len([IdArticulo]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioIdTipo CHECK ((len([IdTipo]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_MayInventarioTipoArticulo CHECK ((len([TipoArticulo]) > 0)))
CREATE TABLE Trn_MayInvmov ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
FechaDoc SMALLDATETIME NOT NULL,
IdArticulo VARCHAR(16) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCon CHAR(2) NOT NULL,
ItemArt INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_MayInvmov PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_MayInvmovIdArticulo CHECK ((len([IdArticulo]) > 0)),
 CONSTRAINT CK_Trn_MayInvmovIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayInvmovIdCiaCon CHECK ((len([IdCiaCon]) > 0)),
 CONSTRAINT CK_Trn_MayInvmovTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_MayLiqDetalle ( 
NLiquida INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCon CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdSubgrupo VARCHAR(8) NOT NULL,
Combustible BIT DEFAULT (0) NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
UnidDev DECIMAL(14,4) DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
ValorDev MONEY DEFAULT (0) NOT NULL,
Intervalo VARCHAR(50),
Margen DECIMAL(14,4) DEFAULT (0) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoTarifa CHAR(1) DEFAULT ('$') NOT NULL,
VrLiquida MONEY DEFAULT (0) NOT NULL,
LogDetalle VARCHAR(250),
Subsidio DECIMAL(14,4) DEFAULT (0) NOT NULL,
VenGalones DECIMAL(14,4) DEFAULT (0) NOT NULL,
VenTotal MONEY DEFAULT (0) NOT NULL,
CantExcluido DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
MgnNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoMargen CHAR(1),
PorcIvaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrIvaCom DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
IvaIncBonif BIT DEFAULT ((0)) NOT NULL,
CdAgenc VARCHAR(16),
VrBaseIva DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
VrLiquidaNeto MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_MayLiqDetalle PRIMARY KEY CLUSTERED (NLiquida,IdCia,NContrato,IdCiaCon,Item),
 CONSTRAINT CK_Trn_MayLiqDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayLiqDetalleIdCiaCon CHECK ((len([IdCiaCon]) > 0)),
 CONSTRAINT CK_Trn_MayLiqDetalleIdSubgrupo CHECK ((len([IdSubgrupo]) > 0)),
 CONSTRAINT CK_Trn_MayLiqDetalleTipoTarifa CHECK ((len([TipoTarifa]) > 0)))
CREATE TABLE Trn_MayLiqTotales ( 
NLiquida INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCon CHAR(2) DEFAULT ('01') NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrBonif MONEY DEFAULT (0) NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
VrCuotaFija MONEY DEFAULT (0) NOT NULL,
DiasGracia INT DEFAULT (0) NOT NULL,
TipoNcr VARCHAR(3) DEFAULT ('NCR') NOT NULL,
NotaCred INT DEFAULT (0) NOT NULL,
IdCiaNot CHAR(2) DEFAULT ('00') NOT NULL,
LogLiquida VARCHAR(250),
VrIvaBonif DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
BaseIvaBonif DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
VrBonifNeto MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_MayLiqTotales PRIMARY KEY CLUSTERED (NLiquida,IdCia,Item),
 CONSTRAINT CK_Trn_MayLiqTotalesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_MayLiqTotalesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayLiqTotalesIdCiaCon CHECK ((len([IdCiaCon]) > 0)),
 CONSTRAINT CK_Trn_MayLiqTotalesIdCiaNot CHECK ((len([IdCiaNot]) > 0)),
 CONSTRAINT CK_Trn_MayLiqTotalesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_MayLiqTotalesTipoNcr CHECK ((len([TipoNcr]) > 0)))
CREATE TABLE Trn_MayLiquida ( 
NLiquida INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Observacion VARCHAR(250),
Estado INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_MayLiquida PRIMARY KEY CLUSTERED (NLiquida,IdCia),
 CONSTRAINT CK_Trn_MayLiquidaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayLiquidaIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_MayLiquidaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_MayLiquidaTipCom CHECK ((len([TipCom]) > 0)))
CREATE TABLE Trn_MayPspto ( 
NContrato INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoProd VARCHAR(20) DEFAULT ('COMBUSTIBLE') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
Unidad VARCHAR(10) DEFAULT ('galones'),
CantMes DECIMAL(14,4) DEFAULT (0) NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdSubgrupo VARCHAR(8) DEFAULT ('0') NOT NULL
 CONSTRAINT PK_Trn_MayPspto PRIMARY KEY CLUSTERED (NContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MayPsptoCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_Trn_MayPsptoCdSubgrupo CHECK ((len([CdSubgrupo]) > 0)),
 CONSTRAINT CK_Trn_MayPsptoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_MayPsptoTipoProd CHECK (([TipoProd] = 'OTROS' or [TipoProd] = 'COMBUSTIBLE')))
CREATE TABLE Trn_MttoDiagn ( 
TipOdt VARCHAR(3) DEFAULT ('ODT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NumDiagn INT DEFAULT ((0)) NOT NULL,
FechaDiagn SMALLDATETIME NOT NULL,
TipoUnidad CHAR(1) DEFAULT ('V') NOT NULL,
NumVehic VARCHAR(10) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_MttoDiagn PRIMARY KEY CLUSTERED (TipOdt,NumOrden,IdCia,NumDiagn),
 CONSTRAINT CK_Trn_MttoDiagnIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnNumVehic CHECK ((len([NumVehic])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnTipOdt CHECK ((len([TipOdt])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnTipoUnidad CHECK ((len([TipoUnidad])>(0))))
CREATE TABLE Trn_MttoDiagnDet ( 
TipOdt VARCHAR(3) DEFAULT ('ODT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NumDiagn INT DEFAULT ((0)) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdInspec VARCHAR(4) NOT NULL,
ValorInspec VARCHAR(100) NOT NULL,
UndMedida VARCHAR(50),
NumColor INT DEFAULT ((0)) NOT NULL,
Req_Mtto BIT DEFAULT ((0)) NOT NULL,
Intervalo VARCHAR(100),
Observacion VARCHAR(500)
 CONSTRAINT PK_Trn_MttoDiagnDet PRIMARY KEY CLUSTERED (TipOdt,NumOrden,IdCia,NumDiagn,Item),
 CONSTRAINT CK_Trn_MttoDiagnDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnDetIdInspec CHECK ((len([IdInspec])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnDetTipOdt CHECK ((len([TipOdt])>(0))),
 CONSTRAINT CK_Trn_MttoDiagnDetValorInspec CHECK ((len([ValorInspec])>(0))))
CREATE TABLE Trn_MttoOrden ( 
TipDoc VARCHAR(3) DEFAULT ('ODT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaOrden SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME,
IdTipoOdt VARCHAR(4) NOT NULL,
IdCenSer VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nRemolque VARCHAR(10) DEFAULT ('0') NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
IdSupervisor VARCHAR(16) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INTERNA') NOT NULL,
kmVehiculo INT DEFAULT ((0)) NOT NULL,
kmRemolque INT DEFAULT ((0)) NOT NULL,
VrServicios MONEY DEFAULT ((0)) NOT NULL,
VrRepuestos MONEY DEFAULT ((0)) NOT NULL,
VrManoObra MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
FechaCierre SMALLDATETIME,
NitCenSer VARCHAR(16),
CdEstadoVeh VARCHAR(4),
IdEstado VARCHAR(4) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
NumDev INT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipFact VARCHAR(3),
NumFactura INT DEFAULT ((0)) NOT NULL,
IdCiaFact CHAR(2) DEFAULT ('00')
 CONSTRAINT PK_Trn_MttoOrden PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_MttoOrdenIdCenSer CHECK ((len([IdCenSer])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdSupervisor CHECK ((len([IdSupervisor])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdTipoOdt CHECK ((len([IdTipoOdt])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_MttoOrdenDet ( 
TipOdt VARCHAR(3) DEFAULT ('ODT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
FechaServ SMALLDATETIME NOT NULL,
IdConc VARCHAR(4) NOT NULL,
Descripcion VARCHAR(1000) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(50),
CdMtto VARCHAR(4),
IdEstado VARCHAR(4) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
NumVehic VARCHAR(10),
NumParte VARCHAR(20),
Req_Rep BIT DEFAULT ((0)) NOT NULL,
Req_MO BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoServ VARCHAR(10),
CodCentro VARCHAR(4),
NitCenServ VARCHAR(16)
 CONSTRAINT PK_Trn_MttoOrdenDet PRIMARY KEY CLUSTERED (TipOdt,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_MttoOrdenDetDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenDetIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenDetIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenDetIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenDetIdUsuario CHECK ((len([IdUsuario])>(0))))
CREATE TABLE Trn_MttoOrdenReq ( 
TipReq VARCHAR(3) DEFAULT ('RQM') NOT NULL,
Requisicion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipoItem VARCHAR(10) DEFAULT ('REPUESTO') NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CdBodega VARCHAR(4),
TipOdt VARCHAR(3) DEFAULT ('ODT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOdt CHAR(2) DEFAULT ('00') NOT NULL,
EstadoReq INT DEFAULT ((0)) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
CdCenServ VARCHAR(4),
NitTercero VARCHAR(16),
NumVehic VARCHAR(10),
NumParte VARCHAR(20),
TipSal VARCHAR(3) DEFAULT ('0') NOT NULL,
NumSalida INT DEFAULT ((0)) NOT NULL,
IdCiaSal CHAR(2) DEFAULT ('00') NOT NULL,
CantSalida DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(1000),
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CdConcServ VARCHAR(4),
VrPrecioUnd MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_MttoOrdenReq PRIMARY KEY CLUSTERED (TipReq,Requisicion,IdCia,Item),
 CONSTRAINT CK_Trn_MttoOrdenReqDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqIdCiaSal CHECK ((len([IdCiaSal])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqTipOdt CHECK ((len([TipOdt])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqTipoItem CHECK ((len([TipoItem])>(0))),
 CONSTRAINT CK_Trn_MttoOrdenReqTipSal CHECK ((len([TipSal])>(0))))
CREATE TABLE Trn_MttoTrabajos ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConc VARCHAR(4) NOT NULL,
TipoMtto INT DEFAULT ((0)) NOT NULL,
TipoUnidad CHAR(1) DEFAULT ('V') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nRemolque VARCHAR(10) DEFAULT ('0') NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NumParte VARCHAR(20) DEFAULT ('0') NOT NULL,
CantHoras INT DEFAULT ((0)) NOT NULL,
kmActual INT DEFAULT ((0)) NOT NULL,
KmRuta INT DEFAULT ((0)) NOT NULL,
kmOtro INT DEFAULT ((0)) NOT NULL,
kmAntMtto INT DEFAULT ((0)) NOT NULL,
KmAntMtto2 INT DEFAULT ((0)) NOT NULL,
kmAntMtto3 INT DEFAULT ((0)) NOT NULL,
FecAntMtto SMALLDATETIME
 CONSTRAINT PK_Trn_MttoTrabajos PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_MttoTrabajosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MttoTrabajosIdConc CHECK ((len([IdConc])>(0))),
 CONSTRAINT CK_Trn_MttoTrabajosIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_MttoTrabajosnRemolque CHECK ((len([nRemolque])>(0))),
 CONSTRAINT CK_Trn_MttoTrabajosNumParte CHECK ((len([NumParte])>(0))),
 CONSTRAINT CK_Trn_MttoTrabajosTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MttoTrabajosTipoUnidad CHECK ((len([TipoUnidad])>(0))))
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))))
CREATE TABLE Trn_MudContFact ( 
TipDoc VARCHAR(3) DEFAULT ('CAB') NOT NULL,
NumContrato INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
NumFactura INT DEFAULT ((0)) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_MudContFact PRIMARY KEY CLUSTERED (TipDoc,NumContrato,IdCia,Item),
 CONSTRAINT CK_Trn_MudContFactIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudContFactIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_MudContFactTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudContFactTipFac CHECK ((len([TipFac])>(0))))
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))))
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,
NomContacto VARCHAR(150),
TelsContacto VARCHAR(30),
emlContacto VARCHAR(150)
 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))))
CREATE TABLE Trn_MudInventario ( 
TipDoc VARCHAR(3) DEFAULT ('MUD') NOT NULL,
NumInvent INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
IdTipoServ VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdRemitente VARCHAR(16) NOT NULL,
Remitente VARCHAR(150) NOT NULL,
DirCargue VARCHAR(500),
TipoInmRem VARCHAR(30),
PisoCargue VARCHAR(10),
TelsRemite VARCHAR(30),
CelRemite VARCHAR(30),
IdDestinatario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(150) NOT NULL,
DirDescargue VARCHAR(500),
TipoInmDest VARCHAR(30),
PisoDescargue VARCHAR(10),
TelsDest VARCHAR(30),
CelDest VARCHAR(30),
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
pVehiculo VARCHAR(10) NOT NULL,
CdConductor VARCHAR(16),
nRemolque VARCHAR(10),
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
NitEmpresa VARCHAR(16),
NomEmpresa VARCHAR(150),
CajasEmp INT DEFAULT ((0)) NOT NULL,
CajasClie INT DEFAULT ((0)) NOT NULL,
VrDeclarado MONEY DEFAULT ((0)) NOT NULL,
VrServicio MONEY DEFAULT ((0)) NOT NULL,
NumCotizac VARCHAR(20),
NumPlanilla VARCHAR(20),
NumActa VARCHAR(20),
TipOsm VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOsm CHAR(2) DEFAULT ('01') NOT NULL,
NomContacto VARCHAR(150),
TelsContacto VARCHAR(30),
emlContacto VARCHAR(100),
Responsable VARCHAR(150),
FormaPago VARCHAR(50),
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,
ContactoDest VARCHAR(150)
 CONSTRAINT PK_Trn_MudInventario PRIMARY KEY CLUSTERED (TipDoc,NumInvent,IdCia),
 CONSTRAINT CK_Trn_MudInventarioDestinatario CHECK ((len([Destinatario])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdCiaOsm CHECK ((len([IdCiaOsm])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdDestinatario CHECK ((len([IdDestinatario])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdRemitente CHECK ((len([IdRemitente])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdTipoServ CHECK ((len([IdTipoServ])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MudInventarioIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_MudInventarioOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_MudInventariopVehiculo CHECK ((len([pVehiculo])>(0))),
 CONSTRAINT CK_Trn_MudInventarioRemitente CHECK ((len([Remitente])>(0))),
 CONSTRAINT CK_Trn_MudInventarioTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudInventarioTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))),
 CONSTRAINT CK_Trn_MudInventarioTipOsm CHECK ((len([TipOsm])>(0))))
CREATE TABLE Trn_MudInventDet ( 
TipDoc VARCHAR(3) DEFAULT ('MUD') NOT NULL,
NumInvent INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdArticulo VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
Observacion VARCHAR(500),
CantSalida DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoIngreso VARCHAR(10),
FechaReg SMALLDATETIME,
CdUsuario VARCHAR(11)
 CONSTRAINT PK_Trn_MudInventDet PRIMARY KEY CLUSTERED (TipDoc,NumInvent,IdCia,Item),
 CONSTRAINT CK_Trn_MudInventDetDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_MudInventDetIdArticulo CHECK ((len([IdArticulo])>(0))),
 CONSTRAINT CK_Trn_MudInventDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudInventDetIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_MudInventDetTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_MudOrdenConc ( 
TipDoc VARCHAR(3) DEFAULT ('OSM') NOT NULL,
NumOrden 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,
TipoConc VARCHAR(10) NOT NULL,
TipoRubro VARCHAR(20) NOT NULL,
TipoReg INT DEFAULT ((0)) NOT NULL,
CdCuenta VARCHAR(16),
NitTercero VARCHAR(16),
Referencia VARCHAR(50),
NumDocRef VARCHAR(20),
CodTarIva VARCHAR(4),
IndFactItem INT DEFAULT ((0)) NOT NULL,
NumDocFac VARCHAR(20),
TarifSeguro DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarSeg VARCHAR(4),
PlacaVehic VARCHAR(10),
TarifaPago MONEY DEFAULT ((0)) NOT NULL,
FechaReg SMALLDATETIME,
CdUsuario VARCHAR(11)
 CONSTRAINT PK_Trn_MudOrdenConc PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_MudOrdenConcDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_MudOrdenConcIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudOrdenConcIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_MudOrdenConcTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudOrdenConcTipoConc CHECK ((len([TipoConc])>(0))),
 CONSTRAINT CK_Trn_MudOrdenConcTipoRubro CHECK ((len([TipoRubro])>(0))))
CREATE TABLE Trn_MudOrdenNov ( 
TipDoc VARCHAR(3) DEFAULT ('OSM') NOT NULL,
NumOrden 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),
EstadoBod INT DEFAULT ((0)) NOT NULL,
CdBodAnt VARCHAR(4),
CdBodega VARCHAR(4),
FechaIngBod SMALLDATETIME,
FechaRetBod SMALLDATETIME,
CdConcepto VARCHAR(4),
ValorTotal MONEY DEFAULT ((0)),
Referencia VARCHAR(50),
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_MudOrdenNov PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_MudOrdenNovIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudOrdenNovIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MudOrdenNovTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudOrdenNovTipoNov CHECK ((len([TipoNov])>(0))))
CREATE TABLE Trn_MudOrdenOper ( 
TipDoc VARCHAR(3) DEFAULT ('OSM') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdOperario VARCHAR(16) NOT NULL,
NomOperario VARCHAR(150) NOT NULL,
IdTipoOper VARCHAR(4) NOT NULL,
CdConcepto VARCHAR(4),
TarifaCargo MONEY DEFAULT ((0)) NOT NULL,
PlacaVehic VARCHAR(10),
TipoReg INT DEFAULT ((0)) NOT NULL,
FechaReg SMALLDATETIME,
CdUsuario VARCHAR(11),
Descripcion VARCHAR(500)
 CONSTRAINT PK_Trn_MudOrdenOper PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_MudOrdenOperIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudOrdenOperIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_MudOrdenOperIdTipoOper CHECK ((len([IdTipoOper])>(0))),
 CONSTRAINT CK_Trn_MudOrdenOperNomOperario CHECK ((len([NomOperario])>(0))),
 CONSTRAINT CK_Trn_MudOrdenOperTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_MudOrdenServ ( 
TipDoc VARCHAR(3) DEFAULT ('OSM') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
IdTipoServ VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
DirCargue VARCHAR(500),
TipoInmRem VARCHAR(30),
PisoCargue VARCHAR(10),
TelsRemite VARCHAR(30),
CelRemite VARCHAR(30),
DirDescargue VARCHAR(500),
TipoInmDest VARCHAR(30),
PisoDescargue VARCHAR(10),
TelsDest VARCHAR(30),
CelDest VARCHAR(30),
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
VrServicio MONEY DEFAULT ((0)) NOT NULL,
VrEmpaque MONEY DEFAULT ((0)) NOT NULL,
VrBodega MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
VrDeclarado MONEY DEFAULT ((0)) NOT NULL,
VrSeguro MONEY DEFAULT ((0)) NOT NULL,
Servicios VARCHAR(50) NOT NULL,
FormaPago VARCHAR(50),
Referencia VARCHAR(50),
TipInv VARCHAR(3) DEFAULT ('MUD') NOT NULL,
NumInvent INT DEFAULT ((0)) NOT NULL,
IdCiaInv CHAR(2) DEFAULT ('01') NOT NULL,
TipRem VARCHAR(3) NOT NULL,
NumRemesa INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
EstFactura INT DEFAULT ((0)) NOT NULL,
TipFact VARCHAR(3),
NumFactura INT DEFAULT ((0)) NOT NULL,
CdCiaFact CHAR(2),
TipCausac VARCHAR(3),
Causacion INT DEFAULT ((0)) NOT NULL,
CdCiaCau CHAR(2),
EstCumplido INT DEFAULT ((0)) NOT NULL,
FechaCump SMALLDATETIME,
TipoRuta VARCHAR(10) DEFAULT ('URBANO') NOT NULL,
NomContacto VARCHAR(150),
TelsContacto VARCHAR(30),
emlContacto VARCHAR(100),
ContactoDest VARCHAR(150),
emlContDest VARCHAR(100),
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,
Volumen VARCHAR(50),
EstadoBod INT DEFAULT ((0)) NOT NULL,
CdBodega VARCHAR(4),
FechaIngBod SMALLDATETIME,
FechaRetBod SMALLDATETIME,
NitRemitente VARCHAR(16),
Remitente VARCHAR(150),
NitDestinatario VARCHAR(16),
Destinatario VARCHAR(150),
NumAutCupo INT DEFAULT ((0)) NOT NULL,
NumAutMora INT DEFAULT ((0)) NOT NULL,
Referencias VARCHAR(1000)
 CONSTRAINT PK_Trn_MudOrdenServ PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_MudOrdenServIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdCiaInv CHECK ((len([IdCiaInv])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdTipoServ CHECK ((len([IdTipoServ])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServServicios CHECK ((len([Servicios])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudOrdenServTipInv CHECK ((len([TipInv])>(0))))
CREATE TABLE Trn_MudOrdenVeh ( 
TipDoc VARCHAR(3) DEFAULT ('OSM') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
NitEmpresa VARCHAR(16),
NomEmpresa VARCHAR(150),
nRemolque VARCHAR(10),
IdConductor VARCHAR(16) NOT NULL,
IdCondAux VARCHAR(16),
TipDocRef VARCHAR(3),
NumDocRef INT DEFAULT ((0)) NOT NULL,
CdCiaRef CHAR(2) DEFAULT ('01'),
CdTipoOper VARCHAR(4),
TipoIngreso VARCHAR(10),
TarifaIng DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrIngreso MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_MudOrdenVeh PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_MudOrdenVehIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_MudOrdenVehIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_MudOrdenVehIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_MudOrdenVehTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_MudOrdenVehTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))))
CREATE TABLE Trn_NiifComp ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
IdCta VARCHAR(4) NOT NULL,
EnEfectivo BIT DEFAULT ((0)) NOT NULL,
NumCheque VARCHAR(20),
FecCheque SMALLDATETIME,
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
NumDev INT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
TipEgr VARCHAR(3),
NEgreso INT DEFAULT ((0)) NOT NULL,
pVehiculo VARCHAR(10),
VehPropio INT DEFAULT ((0)),
CedCondtor VARCHAR(16),
CodConce VARCHAR(4),
Beneficiario VARCHAR(250),
VrDivisa1 DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDivisa2 DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDivisa3 DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
PermEditar BIT DEFAULT ((0)) NOT NULL,
Integrado BIT DEFAULT ((0)) NOT NULL,
EsEgreso BIT DEFAULT ((0)) NOT NULL,
Anticipo BIT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(1000),
IdEstado VARCHAR(4) NOT NULL,
Propddes VARCHAR(50),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
TipoNiif VARCHAR(10) DEFAULT ('NIIF') NOT NULL,
CdSustento VARCHAR(4),
Tipo_Pago VARCHAR(10),
Establec VARCHAR(20),
PEmision VARCHAR(20),
Autorizac VARCHAR(50),
FechaAut SMALLDATETIME,
CtbTipo VARCHAR(3),
CtbNumero INT DEFAULT ((0)) NOT NULL,
FisTipo VARCHAR(3),
FisNumero INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NiifComp PRIMARY KEY NONCLUSTERED (TipCom,Comprobante,IdCia),
 CONSTRAINT CK_Trn_NiifCompIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NiifCompIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_NiifCompIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_NiifCompIdCta CHECK ((len([IdCta])>(0))),
 CONSTRAINT CK_Trn_NiifCompIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_NiifCompIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_NiifCompIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NiifCompTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_NiifCompTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_NiifCompTipoNiif CHECK ((len([TipoNiif])>(0))))
CREATE TABLE Trn_NiifDetalle ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
Detalle VARCHAR(250) NOT NULL,
VrDebito MONEY DEFAULT ((0)) NOT NULL,
VrCredito MONEY DEFAULT ((0)) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
VrBase MONEY DEFAULT ((0)) NOT NULL,
TarifaBase DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipDoc VARCHAR(3),
Documento INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01'),
CodConce VARCHAR(4),
NitDoc VARCHAR(16),
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT ((0)) NOT NULL,
FecVence SMALLDATETIME NOT NULL,
CodCta VARCHAR(4),
NumCheque VARCHAR(20),
Integrado BIT DEFAULT ((0)) NOT NULL,
TipoAplica CHAR(1) DEFAULT ('N') NOT NULL,
Consolida BIT DEFAULT ((0)) NOT NULL,
CodCargo VARCHAR(4),
NitOtros VARCHAR(16),
CodSubgpo VARCHAR(8),
CiuOrigen VARCHAR(8),
CodAgncia VARCHAR(16) DEFAULT ('0') NOT NULL,
VehPropio INT DEFAULT ((0)),
Referncia VARCHAR(50),
TipDocRef VARCHAR(3),
DocRef INT DEFAULT ((0)) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('01'),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
CdConcTrib VARCHAR(4),
CdTarifTrib VARCHAR(4),
NumEstablec VARCHAR(20),
PtoEmision VARCHAR(20),
Num_Autoriza VARCHAR(50),
FechAutoriza SMALLDATETIME,
CodCuentaCG VARCHAR(16)
 CONSTRAINT PK_Trn_NiifDetalle PRIMARY KEY NONCLUSTERED (TipCom,Comprobante,IdCia,Item),
 CONSTRAINT CK_Trn_NiifDetalleCodAgncia CHECK ((len([CodAgncia])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleDetalle CHECK ((len([Detalle])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_NiifDetalleTipoAplica CHECK ((len([TipoAplica])>(0))))
CREATE TABLE Trn_NiifPolCuentas ( 
IdPolitica INT DEFAULT ((0)) NOT NULL,
CdCuenta VARCHAR(16) NOT NULL
 CONSTRAINT PK_Trn_NiifPolCuentas PRIMARY KEY CLUSTERED (IdPolitica,CdCuenta))
CREATE TABLE Trn_NiifPoliticas ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdPolitica INT DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
ClasePol VARCHAR(100) NOT NULL,
Objetivo VARCHAR(1000),
Alcance VARCHAR(2500),
Reconocimiento VARCHAR(2500),
Med_Inicial VARCHAR(2000) NOT NULL,
Med_Final VARCHAR(2000),
PdoVigencia INT DEFAULT ((0)) NOT NULL,
Vigencia VARCHAR(250),
Notas VARCHAR(1000),
Anexo VARCHAR(150),
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NiifPoliticas PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_NiifPoliticasClasePol CHECK ((len([ClasePol])>(0))),
 CONSTRAINT CK_Trn_NiifPoliticasDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_NiifPoliticasIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NiifPoliticasMed_Inicial CHECK ((len([Med_Inicial])>(0))))
CREATE TABLE Trn_NiifRevelac ( 
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipoRev VARCHAR(10) DEFAULT ('COMP') NOT NULL,
Titulo VARCHAR(250),
Comentario VARCHAR(3000) NOT NULL,
CdCuenta VARCHAR(16),
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NiifRevelac PRIMARY KEY CLUSTERED (TipCom,Comprobante,IdCia,Item),
 CONSTRAINT CK_Trn_NiifRevelacIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NiifRevelacIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NiifRevelacTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_NiifRevelacTipoRev CHECK ((len([TipoRev])>(0))))
CREATE TABLE Trn_NomAbonos ( 
NPrestamo INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
FechaAbo SMALLDATETIME NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
nCuotas INT DEFAULT (0) NOT NULL,
IdPeriodo VARCHAR(8),
Dscto VARCHAR(3) NOT NULL,
Detalle VARCHAR(50),
NLiquida INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_NomAbonos PRIMARY KEY CLUSTERED (NPrestamo,Item),
 CONSTRAINT CK_Trn_NomAbonosDscto CHECK (([Dscto] = 'OTR' or ([Dscto] = 'CAN' or ([Dscto] = 'VAC' or ([Dscto] = 'PRI' or [Dscto] = 'NOM'))))),
 CONSTRAINT CK_Trn_NomAbonosIdEmpleado CHECK ((len([IdEmpleado]) > 0)))
CREATE TABLE Trn_NomAjustes ( 
TipNota VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
NContrato INT DEFAULT ((0)) NOT NULL,
IdPeriodo VARCHAR(8) NOT NULL,
FechaInicial SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME NOT NULL,
IdRegNom VARCHAR(30) NOT NULL,
NumLiquida INT DEFAULT ((0)) NOT NULL,
NumSemLiq INT DEFAULT ((0)) NOT NULL,
IdNom VARCHAR(4) NOT NULL,
TipoLiq CHAR(1) DEFAULT ('M') NOT NULL,
Observacion VARCHAR(2000),
NA_Estado INT DEFAULT ((0)) NOT NULL,
NA_Prefijo VARCHAR(20),
NA_Numero INT DEFAULT ((0)) NOT NULL,
NA_FecEnvio SMALLDATETIME,
NA_CUNE VARCHAR(500),
NA_QR IMAGE,
NE_Prefijo VARCHAR(20),
NE_Numero INT DEFAULT ((0)) NOT NULL,
NE_CUNE VARCHAR(500),
NE_QR IMAGE,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomAjustes PRIMARY KEY CLUSTERED (TipNota,NumNota,IdCia),
 CONSTRAINT CK_Trn_NomAjustesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NomAjustesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_NomAjustesIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_Trn_NomAjustesIdNom CHECK ((len([IdNom])>(0))),
 CONSTRAINT CK_Trn_NomAjustesIdPeriodo CHECK ((len([IdPeriodo])>(0))),
 CONSTRAINT CK_Trn_NomAjustesIdRegNom CHECK ((len([IdRegNom])>(0))),
 CONSTRAINT CK_Trn_NomAjustesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NomAjustesTipNota CHECK ((len([TipNota])>(0))),
 CONSTRAINT CK_Trn_NomAjustesTipoLiq CHECK ((len([TipoLiq])>(0))))
CREATE TABLE Trn_NomAjustesDet ( 
TipNota VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Detalle VARCHAR(250),
CantDevg DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantDed DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrUnitario MONEY DEFAULT ((0)) NOT NULL,
VrTotDevg MONEY DEFAULT ((0)) NOT NULL,
VrTotDed MONEY DEFAULT ((0)) NOT NULL,
Unidad VARCHAR(10) DEFAULT ('UNIDADES'),
ClaseLiq VARCHAR(10) DEFAULT ('NOMINA') NOT NULL,
VrOrigen MONEY DEFAULT ((0)) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DiasCalc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DiasNov DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
FecInicial SMALLDATETIME,
FecFinal SMALLDATETIME,
CodFondo VARCHAR(8),
NPrestamo INT DEFAULT ((0)) NOT NULL,
NCuota INT DEFAULT ((0)) NOT NULL,
OrigCargue VARCHAR(10),
VrBaseLiq MONEY DEFAULT ((0)) NOT NULL,
VrBasExceso MONEY DEFAULT ((0)),
NitTercero VARCHAR(16),
TipoIncLab VARCHAR(20)
 CONSTRAINT PK_Trn_NomAjustesDet PRIMARY KEY CLUSTERED (TipNota,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_NomAjustesDetClaseLiq CHECK ((len([ClaseLiq])>(0))),
 CONSTRAINT CK_Trn_NomAjustesDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NomAjustesDetIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_NomAjustesDetTipNota CHECK ((len([TipNota])>(0))))
CREATE TABLE Trn_NomAlqDet ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero VARCHAR(20) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
Apellido1 VARCHAR(50) NOT NULL,
Apellido2 VARCHAR(50),
Nombre1 VARCHAR(50) NOT NULL,
Nombre2 VARCHAR(50),
IdFonPen VARCHAR(8) NOT NULL,
IdFonSal VARCHAR(8) NOT NULL,
IdFonRie VARCHAR(8) NOT NULL,
IdCajCom VARCHAR(8) NOT NULL,
SalBasico MONEY DEFAULT (0) NOT NULL,
VrIBCPen MONEY DEFAULT (0) NOT NULL,
DiasPen DECIMAL(10,4) DEFAULT (0) NOT NULL,
TarifPen DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrPension MONEY DEFAULT (0) NOT NULL,
VrApoFsp MONEY DEFAULT (0) NOT NULL,
VrApoFsu MONEY DEFAULT (0) NOT NULL,
VrApoVolAfi MONEY DEFAULT (0) NOT NULL,
VrApoVolApt MONEY DEFAULT (0) NOT NULL,
VrNoReten MONEY DEFAULT (0) NOT NULL,
VrIBCSal MONEY DEFAULT (0) NOT NULL,
DiasSal DECIMAL(10,4) DEFAULT (0) NOT NULL,
TarifSal DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrSalud MONEY DEFAULT (0) NOT NULL,
VrUpc MONEY DEFAULT (0) NOT NULL,
VrIncap MONEY DEFAULT (0) NOT NULL,
VrLicencia MONEY DEFAULT (0) NOT NULL,
NumAutInc VARCHAR(30),
NumAutLic VARCHAR(30),
VrIBCRie MONEY DEFAULT (0) NOT NULL,
DiasRie DECIMAL(10,4) DEFAULT (0) NOT NULL,
TarifRie DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrRiesgos MONEY DEFAULT (0) NOT NULL,
VrIncIrp MONEY DEFAULT (0) NOT NULL,
NumAutIrp VARCHAR(30),
IdInstala VARCHAR(4) NOT NULL,
VrIBCRef MONEY DEFAULT (0) NOT NULL,
VrIBCCajas MONEY DEFAULT (0) NOT NULL,
DiasCom DECIMAL(10,4) DEFAULT (0) NOT NULL,
TarifCom DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrCajas MONEY DEFAULT (0) NOT NULL,
TarifSen DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrSena MONEY DEFAULT (0) NOT NULL,
TarifIcb DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrICBF MONEY DEFAULT (0) NOT NULL,
TarifEsap DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrESAP MONEY DEFAULT (0) NOT NULL,
TarifEdu DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrMinEdu MONEY DEFAULT (0) NOT NULL,
TarifFsp DECIMAL(10,4) DEFAULT (0) NOT NULL,
TarifFsu DECIMAL(10,4) DEFAULT (0) NOT NULL,
CdFonAvp VARCHAR(8),
VrIBCparaf MONEY DEFAULT ((0)) NOT NULL,
CantHoras INT DEFAULT ((0)) NOT NULL,
TipoSalario VARCHAR(10)
 CONSTRAINT PK_Trn_NomAlqDet PRIMARY KEY CLUSTERED (TipoLiq,Numero,Item),
 CONSTRAINT CK_Trn_NomAlqDetApellido1 CHECK ((len([Apellido1]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetIdCajCom CHECK ((len([IdCajCom]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetIdFonPen CHECK ((len([IdFonPen]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetIdFonRie CHECK ((len([IdFonRie]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetIdFonSal CHECK ((len([IdFonSal]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetIdInstala CHECK ((len([IdInstala]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetNombre1 CHECK ((len([Nombre1]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetNumero CHECK ((len([Numero]) > 0)),
 CONSTRAINT CK_Trn_NomAlqDetTipoLiq CHECK (([TipoLiq] = 'UNI' or ([TipoLiq] = 'COM' or ([TipoLiq] = 'RIE' or ([TipoLiq] = 'SAL' or [TipoLiq] = 'PEN'))))))
CREATE TABLE Trn_NomAlqNov ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero VARCHAR(20) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
NovIng INT DEFAULT (0) NOT NULL,
NovRet INT DEFAULT (0) NOT NULL,
NovTde INT DEFAULT (0) NOT NULL,
NovTae INT DEFAULT (0) NOT NULL,
NovTdp INT DEFAULT (0) NOT NULL,
NovTap INT DEFAULT (0) NOT NULL,
NovVsp INT DEFAULT (0) NOT NULL,
NovVte INT DEFAULT (0) NOT NULL,
NovVst INT DEFAULT (0) NOT NULL,
NovSln INT DEFAULT (0) NOT NULL,
NovIge INT DEFAULT (0) NOT NULL,
NovLma INT DEFAULT (0) NOT NULL,
NovVac INT DEFAULT (0) NOT NULL,
NovAvp INT DEFAULT (0) NOT NULL,
NovVct INT DEFAULT (0) NOT NULL,
NovIrp INT DEFAULT (0) NOT NULL,
CodNewPen VARCHAR(8),
CodNewSal VARCHAR(8),
CodNewIns VARCHAR(4),
CodNewRie VARCHAR(4),
CodNewGru VARCHAR(4),
DiasNov INT DEFAULT (0) NOT NULL,
DiasSan DECIMAL(14,4) DEFAULT (0) NOT NULL,
DiasDnrPen INT DEFAULT ((0)) NOT NULL,
DiasDnrSal INT DEFAULT ((0)) NOT NULL,
NovDsr INT DEFAULT ((0)) NOT NULL,
FecNovIng SMALLDATETIME,
FecNovRet SMALLDATETIME,
FecNovVsp SMALLDATETIME,
FecIniSln SMALLDATETIME,
FecFinSln SMALLDATETIME,
FecIniIge SMALLDATETIME,
FecFinIge SMALLDATETIME,
FecIniLma SMALLDATETIME,
FecFinLma SMALLDATETIME,
FecIniVac SMALLDATETIME,
FecFinVac SMALLDATETIME,
FecIniVct SMALLDATETIME,
FecFinVct SMALLDATETIME,
FecIniIrl SMALLDATETIME,
FecFinIrl SMALLDATETIME
 CONSTRAINT PK_Trn_NomAlqNov PRIMARY KEY CLUSTERED (TipoLiq,Numero,Item),
 CONSTRAINT CK_Trn_NomAlqNovIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomAlqNovNumero CHECK ((len([Numero]) > 0)),
 CONSTRAINT CK_Trn_NomAlqNovTipoLiq CHECK (([TipoLiq] = 'UNI' or ([TipoLiq] = 'COM' or ([TipoLiq] = 'RIE' or ([TipoLiq] = 'SAL' or [TipoLiq] = 'PEN'))))))
CREATE TABLE Trn_NomAlqNvd ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero VARCHAR(20) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
NContrato INT DEFAULT ((0)) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdNov VARCHAR(4) NOT NULL,
FechaInicio SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
OpcIBC VARCHAR(20),
IBCNovedad MONEY DEFAULT ((0)) NOT NULL,
IBCVac MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NomAlqNvd PRIMARY KEY CLUSTERED (TipoLiq,Numero,Item),
 CONSTRAINT CK_Trn_NomAlqNvdIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_NomAlqNvdIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_Trn_NomAlqNvdIdNov CHECK ((len([IdNov])>(0))),
 CONSTRAINT CK_Trn_NomAlqNvdNumero CHECK ((len([Numero])>(0))),
 CONSTRAINT CK_Trn_NomAlqNvdTipoLiq CHECK ((len([TipoLiq])>(0))))
CREATE TABLE Trn_NomAlqTot ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero VARCHAR(20) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipAdm VARCHAR(3) NOT NULL,
IdFondo VARCHAR(8) NOT NULL,
CodTipoApo CHAR(2),
VrTotalCot MONEY DEFAULT (0) NOT NULL,
VrTotalFsp MONEY DEFAULT (0) NOT NULL,
VrTotalFsu MONEY DEFAULT (0) NOT NULL,
VrTotalAva MONEY DEFAULT (0) NOT NULL,
VrTotalAve MONEY DEFAULT (0) NOT NULL,
VrTotalUpc MONEY DEFAULT (0) NOT NULL,
VrTotalLic MONEY DEFAULT (0) NOT NULL,
VrTotalInc MONEY DEFAULT (0) NOT NULL,
VrTotalOtr MONEY DEFAULT (0) NOT NULL,
DiasMora INT DEFAULT (0) NOT NULL,
TarifMora DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrIntMora MONEY DEFAULT (0) NOT NULL,
VrIMoraOtr MONEY DEFAULT (0) NOT NULL,
VrTotalSAF MONEY DEFAULT (0) NOT NULL,
VrSAFUpc MONEY DEFAULT (0) NOT NULL,
VrTotalPagar MONEY DEFAULT (0) NOT NULL,
VrTotalFon MONEY DEFAULT (0) NOT NULL,
TotalAfi INT DEFAULT (0) NOT NULL,
NumAutLic VARCHAR(30),
NumAutInc VARCHAR(30),
NumPlaSAF VARCHAR(20),
TipoReg INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_NomAlqTot PRIMARY KEY CLUSTERED (TipoLiq,Numero,Item),
 CONSTRAINT CK_Trn_NomAlqTotIdFondo CHECK ((len([IdFondo]) > 0)),
 CONSTRAINT CK_Trn_NomAlqTotNumero CHECK ((len([Numero]) > 0)),
 CONSTRAINT CK_Trn_NomAlqTotTipAdm CHECK (([TipAdm] = 'EDU' or ([TipAdm] = 'ESA' or ([TipAdm] = 'ICB' or ([TipAdm] = 'SEN' or ([TipAdm] = 'COM' or ([TipAdm] = 'RIE' or ([TipAdm] = 'SAL' or [TipAdm] = 'PEN')))))))),
 CONSTRAINT CK_Trn_NomAlqTotTipoLiq CHECK (([TipoLiq] = 'UNI' or ([TipoLiq] = 'COM' or ([TipoLiq] = 'RIE' or ([TipoLiq] = 'SAL' or [TipoLiq] = 'PEN'))))))
CREATE TABLE Trn_NomAstncia ( 
IdEmpleado VARCHAR(16) NOT NULL,
FechaDia SMALLDATETIME NOT NULL,
HHDiurno DECIMAL(10,4) DEFAULT (0) NOT NULL,
HHNocturno DECIMAL(10,4) DEFAULT (0) NOT NULL,
HEDiurno DECIMAL(10,4) DEFAULT (0) NOT NULL,
HENocturno DECIMAL(10,4) DEFAULT (0) NOT NULL,
TipoJrnada VARCHAR(10) DEFAULT ('NORMAL') NOT NULL,
EsDmncal BIT DEFAULT (0) NOT NULL,
Horario VARCHAR(30),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomAstncia PRIMARY KEY CLUSTERED (IdEmpleado,FechaDia),
 CONSTRAINT CK_Trn_NomAstnciaIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomAstnciaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomAstnciaTipoJrnada CHECK (([TipoJrnada] = 'SINCOMP' or ([TipoJrnada] = 'DSCSINCOMP' or ([TipoJrnada] = 'DESCANSO' or [TipoJrnada] = 'NORMAL')))))
CREATE TABLE Trn_NomAutoliq ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero VARCHAR(20) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
PerAutoliq VARCHAR(6) NOT NULL,
PerAutoSal VARCHAR(6) NOT NULL,
FechaPago SMALLDATETIME NOT NULL,
IdAportnte VARCHAR(16) NOT NULL,
Presentacion CHAR(1) DEFAULT ('C') NOT NULL,
CodCia CHAR(2),
CodFondo VARCHAR(8),
CodArp VARCHAR(8),
CodOper VARCHAR(10),
EsCorr BIT DEFAULT (0) NOT NULL,
PerCorr VARCHAR(6),
NumCorr VARCHAR(20),
TotalEmp INT DEFAULT (0) NOT NULL,
VrNomina MONEY DEFAULT (0) NOT NULL,
VrPension MONEY DEFAULT (0) NOT NULL,
VrSalud MONEY DEFAULT (0) NOT NULL,
VrRiesgos MONEY DEFAULT (0) NOT NULL,
VrCajas MONEY DEFAULT (0) NOT NULL,
VrSena MONEY DEFAULT (0) NOT NULL,
VrIcbf MONEY DEFAULT (0) NOT NULL,
VrEsap MONEY DEFAULT (0) NOT NULL,
VrMinEduc MONEY DEFAULT (0) NOT NULL,
TotalAfipen INT DEFAULT (0) NOT NULL,
TotalAfiSal INT DEFAULT (0) NOT NULL,
TotalAfiRie INT DEFAULT (0) NOT NULL,
TotalAfiCaj INT DEFAULT (0) NOT NULL,
TotalAfiSen INT DEFAULT (0) NOT NULL,
TotalAfiIcb INT DEFAULT (0) NOT NULL,
TotalAfiEsa INT DEFAULT (0) NOT NULL,
TotalAfiEduc INT DEFAULT (0) NOT NULL,
TotAdmPen INT DEFAULT (0) NOT NULL,
TotAdmSal INT DEFAULT (0) NOT NULL,
TotAdmRie INT DEFAULT (0) NOT NULL,
TotAdmCom INT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
LogAdmon VARCHAR(250),
RedoMiles BIT DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
TipoPlanilla VARCHAR(3) DEFAULT ('E') NOT NULL
 CONSTRAINT PK_Trn_NomAutoliq PRIMARY KEY CLUSTERED (TipoLiq,Numero),
 CONSTRAINT CK_Trn_NomAutoliqIdAportnte CHECK ((len([IdAportnte]) > 0)),
 CONSTRAINT CK_Trn_NomAutoliqIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NomAutoliqIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomAutoliqNumero CHECK ((len([Numero]) > 0)),
 CONSTRAINT CK_Trn_NomAutoliqPerAutoliq CHECK ((len([PerAutoliq]) > 0)),
 CONSTRAINT CK_Trn_NomAutoliqPerAutoSal CHECK ((len([PerAutoSal]) > 0)),
 CONSTRAINT CK_Trn_NomAutoliqPresentacion CHECK (([Presentacion] = 'D' or ([Presentacion] = 'U' or ([Presentacion] = 'C' or [Presentacion] = 'S')))),
 CONSTRAINT CK_Trn_NomAutoliqTipoLiq CHECK (([TipoLiq] = 'UNI' or ([TipoLiq] = 'COM' or ([TipoLiq] = 'RIE' or ([TipoLiq] = 'SAL' or [TipoLiq] = 'PEN'))))))
CREATE TABLE Trn_NomCAdmon ( 
IdEmpleado VARCHAR(16) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
ClaseAdmon VARCHAR(10) NOT NULL,
FecIniNov SMALLDATETIME,
NNovedad INT DEFAULT (0) NOT NULL,
IdFondo VARCHAR(8) NOT NULL,
IdFonNew VARCHAR(8) NOT NULL,
Observacion VARCHAR(100),
Anulado BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomCAdmon PRIMARY KEY CLUSTERED (IdEmpleado,Numero),
 CONSTRAINT CK_Trn_NomCAdmonClaseAdmon CHECK (([ClaseAdmon] = 'CAJAS' or ([ClaseAdmon] = 'CESANTIAS' or ([ClaseAdmon] = 'ARP' or ([ClaseAdmon] = 'EPS' or [ClaseAdmon] = 'PENSIONES'))))),
 CONSTRAINT CK_Trn_NomCAdmonIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomCAdmonIdFondo CHECK ((len([IdFondo]) > 0)),
 CONSTRAINT CK_Trn_NomCAdmonIdFonNew CHECK ((len([IdFonNew]) > 0)),
 CONSTRAINT CK_Trn_NomCAdmonIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_NomCertf ( 
IdEmpleado VARCHAR(16) NOT NULL,
NumCertf VARCHAR(20) NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
ClaseCert VARCHAR(10) DEFAULT ('OTRO') NOT NULL,
VrCertf MONEY DEFAULT (0) NOT NULL,
Observacion VARCHAR(100),
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomCertf PRIMARY KEY CLUSTERED (IdEmpleado,NumCertf),
 CONSTRAINT CK_Trn_NomCertfClaseCert CHECK ((len([ClaseCert])>(0))),
 CONSTRAINT CK_Trn_NomCertfIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomCertfIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomCertfnAnno CHECK (([nAnno]>=(2000) AND [nAnno]<=(2078))),
 CONSTRAINT CK_Trn_NomCertfnMes CHECK (([nMes]>=(0) AND [nMes]<=(12))),
 CONSTRAINT CK_Trn_NomCertfNumCertf CHECK ((len([NumCertf]) > 0)))
CREATE TABLE Trn_NomConAuto ( 
IdReg INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
VrAplicar MONEY DEFAULT (0) NOT NULL,
Modalidad CHAR(1) DEFAULT ('$') NOT NULL,
OrigenBase CHAR(2) DEFAULT ('0') NOT NULL,
FrecAplica VARCHAR(10) DEFAULT ('QUINCENAL') NOT NULL,
CedEmpleado VARCHAR(16),
CodNom VARCHAR(4),
CodDep VARCHAR(4),
CodCcto VARCHAR(16),
CodSubCos VARCHAR(16),
CritSelect VARCHAR(4000),
FecFinal SMALLDATETIME,
Exceptuar VARCHAR(8),
Observacion VARCHAR(50),
Inactivo BIT DEFAULT (0) NOT NULL,
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
NumPerMes INT DEFAULT (0) NOT NULL,
NitTercero VARCHAR(16),
AplicaPrima INT DEFAULT ((0)) NOT NULL,
AplicaVac INT DEFAULT ((0)) NOT NULL,
PdoAplicaEsp VARCHAR(8),
VrAplicaEsp MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NomConAuto PRIMARY KEY CLUSTERED (IdReg),
 CONSTRAINT CK_Trn_NomConAutoFrecAplica CHECK (([FrecAplica]='VACACIONES' OR [FrecAplica]='PRIMA' OR [FrecAplica]='TRIMESTRAL' OR [FrecAplica]='SEMESTRAL' OR [FrecAplica]='MENSUAL' OR [FrecAplica]='QUINCENAL' OR [FrecAplica]='BIMESTRAL')),
 CONSTRAINT CK_Trn_NomConAutoIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomConAutoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomConAutoModalidad CHECK (([Modalidad] = 'T' or ([Modalidad] = '%' or ([Modalidad] = '$' or ([Modalidad] = 'D' or [Modalidad] = 'H'))))),
 CONSTRAINT CK_Trn_NomConAutoOrigenBase CHECK (([OrigenBase] = '0' or ([OrigenBase] = 'SD' or ([OrigenBase] = 'TD' or ([OrigenBase] = 'SB' or [OrigenBase] = 'SM'))))))
CREATE TABLE Trn_NomDetalle ( 
IdPeriodo VARCHAR(8) NOT NULL,
KeyRegistro VARCHAR(30) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Detalle VARCHAR(100),
CantDevg DECIMAL(10,4) DEFAULT (0) NOT NULL,
CantDed DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrTotDevg MONEY DEFAULT (0) NOT NULL,
VrTotDed MONEY DEFAULT (0) NOT NULL,
Unidad VARCHAR(10) DEFAULT ('UNIDADES'),
ClaseLiq VARCHAR(10) DEFAULT ('NOMINA') NOT NULL,
VrOrigen MONEY DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
DiasCalc DECIMAL(10,4) DEFAULT (0) NOT NULL,
DiasNov DECIMAL(10,4) DEFAULT (0) NOT NULL,
CodFondo VARCHAR(8),
NPrestamo INT DEFAULT (0) NOT NULL,
NCuota INT DEFAULT (0) NOT NULL,
OrigCargue VARCHAR(10),
VrBaseLiq MONEY DEFAULT (0) NOT NULL,
VrBasExceso MONEY DEFAULT ((0)) NOT NULL,
NitTercero VARCHAR(16),
HoraInicial DATETIME,
HoraFinal DATETIME,
TipoIncLab VARCHAR(20)
 CONSTRAINT PK_Trn_NomDetalle PRIMARY KEY NONCLUSTERED (IdPeriodo,KeyRegistro,Item),
 CONSTRAINT CK_Trn_NomDetalleClaseLiq CHECK (([ClaseLiq] = 'LIQUDACION' or ([ClaseLiq] = 'NOMINA' or ([ClaseLiq] = 'PROVISION' or ([ClaseLiq] = 'APORTE' or [ClaseLiq] = 'NOVEDAD'))))),
 CONSTRAINT CK_Trn_NomDetalleIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomDetalleIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomDetalleIdPeriodo CHECK ((len([IdPeriodo]) > 0)),
 CONSTRAINT CK_Trn_NomDetalleKeyRegistro CHECK ((len([KeyRegistro]) > 0)))
CREATE TABLE Trn_NomDiario ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
ValorDia DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
DctoPension DECIMAL(14,6) DEFAULT ((0)),
DctoSalud DECIMAL(14,6) DEFAULT ((0)),
AporteRP DECIMAL(14,6) DEFAULT ((0)),
AporteParaf DECIMAL(14,6) DEFAULT ((0)),
PrestSocial DECIMAL(14,6) DEFAULT ((0)),
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomDiario PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_NomDiarioIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_Trn_NomDiarioIdUsuario CHECK ((len([IdUsuario])>(0))))
CREATE TABLE Trn_NomDotacion ( 
IdCia CHAR(2) NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipoDotac VARCHAR(10) DEFAULT ('DOTACION') NOT NULL,
TipoEntrega INT DEFAULT ((0)) NOT NULL,
PlazoEntrega INT DEFAULT ((0)) NOT NULL,
FecVence SMALLDATETIME,
TipoReg INT DEFAULT ((0)) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
Observacion VARCHAR(1000),
CritFiltros VARCHAR(250)
 CONSTRAINT PK_Trn_NomDotacion PRIMARY KEY CLUSTERED (IdCia,Numero),
 CONSTRAINT CK_Trn_NomDotacionIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NomDotacionIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NomDotacionTipoDotac CHECK ((len([TipoDotac])>(0))))
CREATE TABLE Trn_NomDotacionDet ( 
IdCia CHAR(2) NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
NContrato INT DEFAULT ((0)) NOT NULL,
IdPrend VARCHAR(4) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Unidad VARCHAR(10),
VrUnitario MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NomDotacionDet PRIMARY KEY CLUSTERED (IdCia,Numero,Item),
 CONSTRAINT CK_Trn_NomDotacionDetDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_NomDotacionDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NomDotacionDetIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_Trn_NomDotacionDetIdPrend CHECK ((len([IdPrend])>(0))))
CREATE TABLE Trn_NomFijos ( 
IdEmpleado VARCHAR(16) NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
VrSalarios MONEY DEFAULT (0) NOT NULL,
VrPrima MONEY DEFAULT (0) NOT NULL,
VrVacacnes MONEY DEFAULT (0) NOT NULL,
VrSIntExcto MONEY DEFAULT (0) NOT NULL,
VrOtrosIng MONEY DEFAULT (0) NOT NULL,
VrIngresos MONEY DEFAULT (0) NOT NULL,
VrPensiones MONEY DEFAULT (0) NOT NULL,
VrDedcido MONEY DEFAULT (0) NOT NULL,
VrExcento MONEY DEFAULT (0) NOT NULL,
VrCertEdu MONEY DEFAULT (0) NOT NULL,
VrCertVda MONEY DEFAULT (0) NOT NULL,
VrCertAFC MONEY DEFAULT (0) NOT NULL,
VrTotalBase MONEY DEFAULT (0) NOT NULL,
VrCertfcado MONEY DEFAULT (0) NOT NULL,
Periodos DECIMAL(10,4) DEFAULT (0) NOT NULL,
OrignPorc VARCHAR(10) DEFAULT ('MANUAL') NOT NULL,
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
VrSalud MONEY DEFAULT (0) NOT NULL,
IngNoSalario MONEY DEFAULT ((0)) NOT NULL,
PagosMedicPre MONEY DEFAULT ((0)) NOT NULL,
AportesVolPen MONEY DEFAULT ((0)) NOT NULL,
GastosRep MONEY DEFAULT ((0)) NOT NULL,
Indemnizac MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NomFijos PRIMARY KEY CLUSTERED (IdEmpleado,nAnno,nMes),
 CONSTRAINT CK_Trn_NomFijosIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomFijosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomFijosnAnno CHECK (([nAnno] >= 2000 and [nAnno] <= 2020)),
 CONSTRAINT CK_Trn_NomFijosnMes CHECK (([nMes] = 12 or [nMes] = 6)),
 CONSTRAINT CK_Trn_NomFijosOrignPorc CHECK (([OrignPorc] = 'MANUAL' or [OrignPorc] = 'CALCULADO')))
CREATE TABLE Trn_Nomina ( 
IdPeriodo VARCHAR(8) NOT NULL,
KeyRegistro VARCHAR(30) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
FecInicial SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
Cantidad DECIMAL(10,4) DEFAULT (0) NOT NULL,
CantNoRem DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrDevengado MONEY DEFAULT (0) NOT NULL,
VrDeducido MONEY DEFAULT (0) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdInstala VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdNom VARCHAR(4) NOT NULL,
VrSalario MONEY DEFAULT (0) NOT NULL,
VrATransMes MONEY DEFAULT (0) NOT NULL,
pVehiculo VARCHAR(10),
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
EsRetiro BIT DEFAULT (0) NOT NULL,
NLiqRet INT DEFAULT (0) NOT NULL,
TipoLiq CHAR(1) DEFAULT ('M') NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CdTipoCot VARCHAR(4),
SubTipo_Cot VARCHAR(3),
Sal_Integral BIT DEFAULT ((0)),
TipoIdent CHAR(1),
NotasAportante VARCHAR(250),
CantModifica INT DEFAULT ((0)) NOT NULL,
NE_Estado INT DEFAULT ((0)) NOT NULL,
NE_Prefijo VARCHAR(20),
NE_Numero INT DEFAULT ((0)) NOT NULL,
NE_FecEnvio DATETIME,
NE_CUNE VARCHAR(500),
NE_QR IMAGE
 CONSTRAINT PK_Trn_Nomina PRIMARY KEY CLUSTERED (IdPeriodo,KeyRegistro),
 CONSTRAINT CK_Trn_NominaIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NominaIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_NominaIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NominaIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NominaIdInstala CHECK ((len([IdInstala]) > 0)),
 CONSTRAINT CK_Trn_NominaIdNom CHECK ((len([IdNom]) > 0)),
 CONSTRAINT CK_Trn_NominaIdPeriodo CHECK ((len([IdPeriodo]) > 0)),
 CONSTRAINT CK_Trn_NominaIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_NominaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NominaKeyRegistro CHECK ((len([KeyRegistro]) > 0)),
 CONSTRAINT CK_Trn_NominaTipoLiq CHECK ((len([TipoLiq]) > 0)))
CREATE TABLE Trn_NomLiqDet ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Detalle VARCHAR(100),
FecUltLiq SMALLDATETIME NOT NULL,
FecInicial SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
Cantidad INT DEFAULT (0) NOT NULL,
VrLiquida MONEY DEFAULT (0) NOT NULL,
VrDeducido MONEY DEFAULT (0) NOT NULL,
FecIniPmd SMALLDATETIME,
FecFinPmd SMALLDATETIME,
DiasBase INT DEFAULT (0) NOT NULL,
DiasNoRem INT DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
NPrestamo INT DEFAULT (0) NOT NULL,
NCuota INT DEFAULT (0) NOT NULL,
LogPmdio VARCHAR(600),
IdEmpleado VARCHAR(16) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
pVehiculo VARCHAR(10),
IdDep VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdNom VARCHAR(4) NOT NULL,
VrSalario MONEY DEFAULT (0) NOT NULL,
VrParcial MONEY DEFAULT (0) NOT NULL,
NitTercero VARCHAR(16)
 CONSTRAINT PK_Trn_NomLiqDet PRIMARY KEY CLUSTERED (TipoLiq,Numero,Item),
 CONSTRAINT CK_Trn_NomLiqDetIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NomLiqDetIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomLiqDetIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_NomLiqDetIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomLiqDetIdNom CHECK ((len([IdNom]) > 0)),
 CONSTRAINT CK_Trn_NomLiqDetIdSubCos CHECK ((len([IdSubCos]) > 0)))
CREATE TABLE Trn_NomLiquida ( 
TipoLiq VARCHAR(3) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Semstre INT DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrTotDed MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(250),
Anulado BIT DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomLiquida PRIMARY KEY CLUSTERED (TipoLiq,Numero),
 CONSTRAINT CK_Trn_NomLiquidaIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NomLiquidaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomLiquidaTipoLiq CHECK (([TipoLiq]='VAC' OR [TipoLiq]='PRI' OR [TipoLiq]='CES' OR [TipoLiq]='PAR' OR [TipoLiq]='LPP')))
CREATE TABLE Trn_NomLogVeh ( 
IdEmpleado VARCHAR(16) NOT NULL,
NumReg INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
pVehAnterior VARCHAR(10),
NitPropAnt VARCHAR(16),
NitCondAnt VARCHAR(16),
pVehNew VARCHAR(10) NOT NULL,
NitPropNew VARCHAR(16) NOT NULL,
Observacion VARCHAR(100),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomLogVeh PRIMARY KEY CLUSTERED (IdEmpleado,NumReg),
 CONSTRAINT CK_Trn_NomLogVehIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomLogVehIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomLogVehNitPropNew CHECK ((len([NitPropNew]) > 0)),
 CONSTRAINT CK_Trn_NomLogVehpVehNew CHECK ((len([pVehNew]) > 0)))
CREATE TABLE Trn_NomNov ( 
IdPeriodo VARCHAR(8) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Detalle VARCHAR(100),
Cantidad DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrOrigen MONEY DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
OrigCargue VARCHAR(10) DEFAULT ('MANUAL') NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
NumDocRef VARCHAR(20),
Num_Contrato INT DEFAULT ((0)) NOT NULL,
Nit_Tercero VARCHAR(16),
HoraInicial DATETIME,
HoraFinal DATETIME
 CONSTRAINT PK_Trn_NomNov PRIMARY KEY CLUSTERED (IdPeriodo,IdEmpleado,Item),
 CONSTRAINT CK_Trn_NomNovIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomNovIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomNovIdPeriodo CHECK ((len([IdPeriodo]) > 0)),
 CONSTRAINT CK_Trn_NomNovIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomNovOrigCargue CHECK ((len([OrigCargue]) > 0)))
CREATE TABLE Trn_NomNovedad ( 
IdEmpleado VARCHAR(16) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
CantDias INT DEFAULT (0) NOT NULL,
DiaInicio INT DEFAULT (0) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('NOMINA') NOT NULL,
IdNov VARCHAR(4) NOT NULL,
CodInstla VARCHAR(4),
CodClsRie VARCHAR(4),
NumAutza VARCHAR(30),
CodNewFon VARCHAR(8),
CodOldFon VARCHAR(8),
VrCotVolAfi MONEY DEFAULT (0) NOT NULL,
VrCotVolApo MONEY DEFAULT (0) NOT NULL,
VrNoRetenido MONEY DEFAULT (0) NOT NULL,
TipoIncap CHAR(1),
Remnrado BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
FechaDcto SMALLDATETIME,
VrDescuento MONEY DEFAULT (0) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
TipoBaseLiq VARCHAR(3) DEFAULT ('IB')
 CONSTRAINT PK_Trn_NomNovedad PRIMARY KEY CLUSTERED (IdEmpleado,Numero),
 CONSTRAINT CK_Trn_NomNovedadIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomNovedadIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomNovedadIdNov CHECK ((len([IdNov]) > 0)),
 CONSTRAINT CK_Trn_NomNovedadIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomNovedadModalidad CHECK (([Modalidad] = 'SISS' or [Modalidad] = 'NOMINA')))
CREATE TABLE Trn_NomPrest ( 
NPrestamo INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
VrPrestamo MONEY DEFAULT (0) NOT NULL,
NumCuotas INT DEFAULT (0) NOT NULL,
VrCuota MONEY DEFAULT (0) NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
FrecDcto VARCHAR(10) DEFAULT ('QUINCENAL') NOT NULL,
Exceptuar VARCHAR(8),
TotPrestamo MONEY DEFAULT (0) NOT NULL,
TotAbonado MONEY DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(250),
Cxpagar BIT DEFAULT (0) NOT NULL,
DsctNom INT DEFAULT (0) NOT NULL,
DsctPri INT DEFAULT (0) NOT NULL,
DsctVac INT DEFAULT (0) NOT NULL,
DsctEspPer VARCHAR(8),
DsctEspVal MONEY DEFAULT (0) NOT NULL,
VrTmAbono MONEY DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
VrSaldo AS ([TotPrestamo] - [TotAbonado]),
NumPerMes INT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_NomPrest PRIMARY KEY CLUSTERED (NPrestamo),
 CONSTRAINT CK_Trn_NomPrestFrecDcto CHECK (([FrecDcto] = 'MENSUAL' or [FrecDcto] = 'QUINCENAL')),
 CONSTRAINT CK_Trn_NomPrestIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomPrestIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomPrestIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_NomPrmSalud ( 
IdEmpleado VARCHAR(16) NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
nMeses INT DEFAULT (0) NOT NULL,
VrPromedio MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_NomPrmSalud PRIMARY KEY CLUSTERED (IdEmpleado,nAnno),
 CONSTRAINT CK_Trn_NomPrmSaludIdEmpleado CHECK ((len([IdEmpleado]) > 0)))
CREATE TABLE Trn_NomProrrogas ( 
IdEmpleado VARCHAR(16) NOT NULL,
NumReg INT DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecAnterior SMALLDATETIME NOT NULL,
Indefinido BIT DEFAULT (0) NOT NULL,
CdTipCon VARCHAR(4) NOT NULL,
CdCargo VARCHAR(4) NOT NULL,
CdDep VARCHAR(4) NOT NULL,
CdArea VARCHAR(4) NOT NULL,
CdCCosto VARCHAR(16) NOT NULL,
CdSubCos VARCHAR(16) NOT NULL,
IdTipCon VARCHAR(4) NOT NULL,
IdCargo VARCHAR(4) NOT NULL,
IdArea VARCHAR(4) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Observacion VARCHAR(150),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomProrrogas PRIMARY KEY CLUSTERED (IdEmpleado,NumReg),
 CONSTRAINT CK_Trn_NomProrrogasCdArea CHECK ((len([CdArea]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasCdCargo CHECK ((len([CdCargo]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasCdCCosto CHECK ((len([CdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasCdDep CHECK ((len([CdDep]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasCdSubCos CHECK ((len([CdSubCos]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasCdTipCon CHECK ((len([CdTipCon]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdArea CHECK ((len([IdArea]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdTipCon CHECK ((len([IdTipCon]) > 0)),
 CONSTRAINT CK_Trn_NomProrrogasIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_NomRet ( 
IdEmpleado VARCHAR(16) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCausa VARCHAR(4) NOT NULL,
FecInicial SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
DiasTrab INT DEFAULT (0) NOT NULL,
DiasNoRem INT DEFAULT (0) NOT NULL,
VrTotDev MONEY DEFAULT (0) NOT NULL,
VrTotDed MONEY DEFAULT (0) NOT NULL,
VrTotCes MONEY DEFAULT (0) NOT NULL,
VrTotPri MONEY DEFAULT (0) NOT NULL,
VrTotVac MONEY DEFAULT (0) NOT NULL,
VrTotInt MONEY DEFAULT (0) NOT NULL,
VrTotInd MONEY DEFAULT (0) NOT NULL,
VrParCes MONEY DEFAULT (0) NOT NULL,
VrParInt MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrBaseCes MONEY DEFAULT (0) NOT NULL,
VrBaseVac MONEY DEFAULT (0) NOT NULL,
IdPeriodo VARCHAR(8) NOT NULL,
KeyReg VARCHAR(30) NOT NULL,
NPerVac INT DEFAULT (0) NOT NULL,
VrSalario MONEY DEFAULT (0) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdNom VARCHAR(4) NOT NULL,
TipoLiq CHAR(1) DEFAULT ('M'),
pVehiculo VARCHAR(10),
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(250),
Anulado BIT DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomRet PRIMARY KEY CLUSTERED (IdEmpleado,Numero),
 CONSTRAINT CK_Trn_NomRetIdCausa CHECK ((len([IdCausa]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdNom CHECK ((len([IdNom]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdPeriodo CHECK ((len([IdPeriodo]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_NomRetIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NomRetKeyReg CHECK ((len([KeyReg]) > 0)))
CREATE TABLE Trn_NomRetDet ( 
IdEmpleado VARCHAR(16) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Detalle VARCHAR(100),
Cantidad DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrDevngado MONEY DEFAULT (0) NOT NULL,
VrDeducido MONEY DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
DiasBase DECIMAL(10,4) DEFAULT (0) NOT NULL,
DiasNoRem DECIMAL(10,4) DEFAULT (0) NOT NULL,
FecUltLiq SMALLDATETIME NOT NULL,
FecDesde SMALLDATETIME NOT NULL,
FecHasta SMALLDATETIME NOT NULL,
FecIniPmd SMALLDATETIME,
FecFinPmd SMALLDATETIME,
GrupoLiq VARCHAR(15) NOT NULL,
NPrestamo INT DEFAULT (0) NOT NULL,
NCuota INT DEFAULT (0) NOT NULL,
LogPmdio VARCHAR(600),
ClaseLiq VARCHAR(10) NOT NULL,
CodFondo VARCHAR(8),
VrBaseLiq MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_NomRetDet PRIMARY KEY CLUSTERED (IdEmpleado,Numero,Item),
 CONSTRAINT CK_Trn_NomRetDetClaseLiq CHECK (([ClaseLiq] = 'LIQUDACION' or ([ClaseLiq] = 'NOVEDAD' or ([ClaseLiq] = 'APORTE' or ([ClaseLiq] = 'PROVISION' or [ClaseLiq] = 'NOMINA'))))),
 CONSTRAINT CK_Trn_NomRetDetGrupoLiq CHECK (([GrupoLiq] = 'DEVENGADO' or ([GrupoLiq] = 'DEDUCCION' or ([GrupoLiq] = 'INDEMNIZA' or ([GrupoLiq] = 'PRESTACION' or [GrupoLiq] = 'LIQUIDACION'))))),
 CONSTRAINT CK_Trn_NomRetDetIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomRetDetIdEmpleado CHECK ((len([IdEmpleado]) > 0)))
CREATE TABLE Trn_NomSueldos ( 
Numero INT DEFAULT ((0)) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NContrato INT DEFAULT ((0)) NOT NULL,
VrSueAnterior MONEY DEFAULT ((0)) NOT NULL,
VrSueNuevo MONEY DEFAULT ((0)) NOT NULL,
VrAtAnterior MONEY DEFAULT ((0)) NOT NULL,
VrAtNuevo MONEY DEFAULT ((0)) NOT NULL,
MetodoUp CHAR(1) DEFAULT ('%') NOT NULL,
Reemplzado BIT DEFAULT ((0)) NOT NULL,
FecUltAumto SMALLDATETIME,
CritSelect VARCHAR(250),
Observacion VARCHAR(100),
TipoActualiza VARCHAR(10),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NomSueldos PRIMARY KEY CLUSTERED (Numero,IdEmpleado),
 CONSTRAINT CK_Trn_NomSueldosIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_Trn_NomSueldosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NomSueldosMetodoUp CHECK (([MetodoUp]='$' OR [MetodoUp]='%')))
CREATE TABLE Trn_NomVac ( 
IdEmpleado VARCHAR(16) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
FecInicial SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
Cantidad DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrLiquida MONEY DEFAULT (0) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
FecIniPmd SMALLDATETIME,
FecFinPmd SMALLDATETIME,
DiasBase INT DEFAULT (0) NOT NULL,
DiasNoRem INT DEFAULT (0) NOT NULL,
DiasVac INT DEFAULT (0) NOT NULL,
NNovedad INT DEFAULT (0) NOT NULL,
NPeriodos INT DEFAULT (0) NOT NULL,
CantRem INT DEFAULT (0) NOT NULL,
VrRemndo MONEY DEFAULT (0) NOT NULL,
VrTotDed MONEY DEFAULT (0) NOT NULL,
VrSalario MONEY DEFAULT (0) NOT NULL,
pVehiculo VARCHAR(10),
DiasAjuste INT DEFAULT (0) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(250),
LogPmdio VARCHAR(600),
Anulado BIT DEFAULT (0) NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
LiqParcial BIT DEFAULT ((0)) NOT NULL,
DiasDom INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NomVac PRIMARY KEY CLUSTERED (IdEmpleado,Numero),
 CONSTRAINT CK_Trn_NomVacIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomVacIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NomVacIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_NomVacDet ( 
IdEmpleado VARCHAR(16) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Detalle VARCHAR(100),
Cantidad INT DEFAULT (0) NOT NULL,
VrDevgado MONEY DEFAULT (0) NOT NULL,
VrDeducido MONEY DEFAULT (0) NOT NULL,
Tarifa DECIMAL(10,4) DEFAULT (0) NOT NULL,
VrBaseLiq MONEY DEFAULT (0) NOT NULL,
VrCertfcado MONEY DEFAULT (0) NOT NULL,
VrPension MONEY DEFAULT (0) NOT NULL,
NPrestamo INT DEFAULT (0) NOT NULL,
NCuota INT DEFAULT (0) NOT NULL,
IdPeriodo VARCHAR(8) NOT NULL,
VrSalud MONEY DEFAULT (0) NOT NULL,
CodFondo VARCHAR(8)
 CONSTRAINT PK_Trn_NomVacDet PRIMARY KEY CLUSTERED (IdEmpleado,Numero,Item),
 CONSTRAINT CK_Trn_NomVacDetIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NomVacDetIdEmpleado CHECK ((len([IdEmpleado]) > 0)),
 CONSTRAINT CK_Trn_NomVacDetIdPeriodo CHECK ((len([IdPeriodo]) > 0)))
CREATE TABLE Trn_NomVehiculo ( 
IdPeriodo VARCHAR(8) NOT NULL,
IdEmpleado VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
CantDias INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NomVehiculo PRIMARY KEY CLUSTERED (IdPeriodo,IdEmpleado,IdVehiculo),
 CONSTRAINT CK_Trn_NomVehiculoIdEmpleado CHECK ((len([IdEmpleado])>(0))),
 CONSTRAINT CK_Trn_NomVehiculoIdPeriodo CHECK ((len([IdPeriodo])>(0))),
 CONSTRAINT CK_Trn_NomVehiculoIdVehiculo CHECK ((len([IdVehiculo])>(0))))
CREATE TABLE Trn_NotaProd ( 
TipDoc VARCHAR(3) DEFAULT ('NPR') NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrCostos MONEY DEFAULT ((0)) NOT NULL,
CantEnt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('ENSAMBLE') NOT NULL,
TipoProd INT DEFAULT ((0)) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_NotaProd PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_NotaProdIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_NotaProdIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_NotaProdModalidad CHECK (([Modalidad]='DESGLOSE' OR [Modalidad]='ENSAMBLE')),
 CONSTRAINT CK_Trn_NotaProdOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_NotaProdTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_NotaProdTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_Notas ( 
TipDoc VARCHAR(3) DEFAULT ('NDB') NOT NULL,
NumNota INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrCosto MONEY DEFAULT (0) NOT NULL,
VrSancion MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
VrAnticipo MONEY DEFAULT (0) NOT NULL,
Cantidad 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,
BaseRiv MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
CdCajero VARCHAR(11) DEFAULT ('0') NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
Referencia VARCHAR(50),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('00') NOT NULL,
FecDcm SMALLDATETIME,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
CdForma VARCHAR(4) DEFAULT ('0') NOT NULL,
NumCheque VARCHAR(20),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) DEFAULT ('0') NOT NULL,
PrestCaja BIT DEFAULT (0) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('NOTA') NOT NULL,
nRemesa INT DEFAULT (0) NOT NULL,
CdCiaRem CHAR(2),
ItemRem INT DEFAULT (0) 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,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
IdConcFE INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Notas PRIMARY KEY NONCLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_NotasCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_Trn_NotasCdCajero CHECK ((len([CdCajero]) > 0)),
 CONSTRAINT CK_Trn_NotasCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_NotasCdForma CHECK ((len([CdForma]) > 0)),
 CONSTRAINT CK_Trn_NotasCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_Trn_NotasIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_NotasIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NotasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_NotasIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_NotasIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_NotasIdCiaDcm CHECK ((len([IdCiaDcm]) > 0)),
 CONSTRAINT CK_Trn_NotasIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_NotasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NotasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NotasIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_NotasIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_NotasIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_NotasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NotasIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_NotasModalidad CHECK (([Modalidad] = 'VALES' or ([Modalidad] = 'CHEQUES' or ([Modalidad] = 'MORA' or ([Modalidad] = 'REMESAS' or ([Modalidad] = 'INVENTARIO' or [Modalidad] = 'NOTA')))))),
 CONSTRAINT CK_Trn_NotasOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_NotasTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_NotasTipDcm CHECK ((len([TipDcm]) > 0)),
 CONSTRAINT CK_Trn_NotasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_NotasBuses ( 
TipDoc VARCHAR(3) DEFAULT ('ND1') NOT NULL,
NumNota INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
ValorIva MONEY DEFAULT (0) NOT NULL,
ValorReteFte MONEY DEFAULT (0) NOT NULL,
ValorReteIca MONEY DEFAULT (0) NOT NULL,
ValorCosto MONEY DEFAULT (0) NOT NULL,
ValorSancion MONEY DEFAULT (0) NOT NULL,
ValorNeto MONEY DEFAULT (0) NOT NULL,
ValorAplicado MONEY DEFAULT (0) NOT NULL,
IdVendedor VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTarCom VARCHAR(4) NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
PrestCaja BIT DEFAULT (0) NOT NULL,
IntMora BIT DEFAULT (0) NOT NULL,
NumCheque VARCHAR(20),
IdBanco VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCargo VARCHAR(4) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(20),
TipDcm VARCHAR(3),
Documento INT DEFAULT (0),
IdCiaDoc CHAR(2),
BaseIva MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTarIva VARCHAR(4) NOT NULL,
IdTarRet VARCHAR(4) NOT NULL,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') 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,
IdConcFE INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_NotasBuses PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_NotasBusesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdTarCom CHECK ((len([IdTarCom]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdTarIva CHECK ((len([IdTarIva]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdTarRet CHECK ((len([IdTarRet]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesIdVendedor CHECK ((len([IdVendedor]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_NotasBusesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_OComb ( 
TipDoc VARCHAR(3) DEFAULT ('OCC') NOT NULL,
OCargue INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaDesp SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrSobretasa MONEY DEFAULT ((0)) NOT NULL,
VrImpGlobal MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarCom VARCHAR(4),
DirEnvio VARCHAR(250) NOT NULL,
IdLocal VARCHAR(8) NOT NULL,
LugarEnv VARCHAR(50),
DiasEntraga INT DEFAULT ((0)) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
NitEmpTrans VARCHAR(16) DEFAULT ('0') NOT NULL,
EmpTrans VARCHAR(150),
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
Referncia VARCHAR(50),
IdForma VARCHAR(4) NOT NULL,
DetallePago VARCHAR(150),
MulPlazos BIT DEFAULT ((0)) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('01') NOT NULL,
TipGui VARCHAR(3) DEFAULT ('GUI') NOT NULL,
Guia INT DEFAULT ((0)) NOT NULL,
IdCiaGui CHAR(2) DEFAULT ('01') NOT NULL,
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
FechaFact SMALLDATETIME,
AutzaMora INT DEFAULT ((0)) NOT NULL,
AutzaCupo INT DEFAULT ((0)) NOT NULL,
Aprobacion INT DEFAULT ((0)) NOT NULL,
FechaAprob SMALLDATETIME,
DetalleAprob VARCHAR(250),
CdUsuAprob VARCHAR(11),
IdTerminal VARCHAR(4),
OrigenAdd VARCHAR(10) NOT NULL,
ZonaFrontera INT DEFAULT ((0)) NOT NULL,
TipoOrden INT DEFAULT ((0)) NOT NULL,
Remolque VARCHAR(10),
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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,
VrImpCarbono MONEY DEFAULT ((0)) NOT NULL,
VrIvaIngProd MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_OComb PRIMARY KEY CLUSTERED (TipDoc,OCargue,IdCia),
 CONSTRAINT CK_Trn_OCombCdRuta CHECK ((len([CdRuta])>(0))),
 CONSTRAINT CK_Trn_OCombDirEnvio CHECK ((len([DirEnvio])>(0))),
 CONSTRAINT CK_Trn_OCombIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_OCombIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OCombIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OCombIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_OCombIdCiaGui CHECK ((len([IdCiaGui])>(0))),
 CONSTRAINT CK_Trn_OCombIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_OCombIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_OCombIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OCombIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_OCombIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OCombIdForma CHECK ((len([IdForma])>(0))),
 CONSTRAINT CK_Trn_OCombIdLocal CHECK ((len([IdLocal])>(0))),
 CONSTRAINT CK_Trn_OCombIdPlazo CHECK ((len([IdPlazo])>(0))),
 CONSTRAINT CK_Trn_OCombIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OCombIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_OCombIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_OCombNitEmpTrans CHECK ((len([NitEmpTrans])>(0))),
 CONSTRAINT CK_Trn_OCombOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OCombTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OCombTipFac CHECK ((len([TipFac])>(0))),
 CONSTRAINT CK_Trn_OCombTipGui CHECK ((len([TipGui])>(0))),
 CONSTRAINT CK_Trn_OCombTipPed CHECK ((len([TipPed])>(0))))
CREATE TABLE Trn_OCompra ( 
TipDoc VARCHAR(3) DEFAULT ('ODC') NOT NULL,
OCompra INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdProv VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrSobtasa MONEY DEFAULT ((0)) NOT NULL,
VrImpGlobal MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteICA MONEY DEFAULT ((0)) NOT NULL,
VrReteIVA MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdEmpresa VARCHAR(16) DEFAULT ('0') NOT NULL,
DirEntrega VARCHAR(250),
IdLocEtga VARCHAR(8) NOT NULL,
DiasEntraga INT DEFAULT ((0)) NOT NULL,
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdForma VARCHAR(4) NOT NULL,
DetallePago VARCHAR(100),
MulPlazos BIT DEFAULT ((0)) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CdMney VARCHAR(5),
NitEmpTrans VARCHAR(16),
EmpTrans VARCHAR(150),
LiqFletes BIT DEFAULT ((0)) NOT NULL,
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16),
TipEnt VARCHAR(3) DEFAULT ('ENT') NOT NULL,
Entrada INT DEFAULT ((0)) NOT NULL,
IdCiaEnt CHAR(2) DEFAULT ('01') NOT NULL,
NumAutoriza INT DEFAULT ((0)) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
Vigencia VARCHAR(10) DEFAULT ('NORMAL') NOT NULL,
NumAprob INT DEFAULT ((0)) NOT NULL,
FecAprob SMALLDATETIME,
CdUsuAprob VARCHAR(11),
NivelAprob INT DEFAULT ((0)) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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,
VrIvaMvc MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4)
 CONSTRAINT PK_Trn_OCompra PRIMARY KEY NONCLUSTERED (TipDoc,OCompra,IdCia),
 CONSTRAINT CK_Trn_OCompraIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_OCompraIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OCompraIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OCompraIdCiaEnt CHECK ((len([IdCiaEnt])>(0))),
 CONSTRAINT CK_Trn_OCompraIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OCompraIdEmpresa CHECK ((len([IdEmpresa])>(0))),
 CONSTRAINT CK_Trn_OCompraIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OCompraIdForma CHECK ((len([IdForma])>(0))),
 CONSTRAINT CK_Trn_OCompraIdLocEtga CHECK ((len([IdLocEtga])>(0))),
 CONSTRAINT CK_Trn_OCompraIdPlazo CHECK ((len([IdPlazo])>(0))),
 CONSTRAINT CK_Trn_OCompraIdProv CHECK ((len([IdProv])>(0))),
 CONSTRAINT CK_Trn_OCompraIdSubCos CHECK ((len([IdSubCos])>(0))),
 CONSTRAINT CK_Trn_OCompraIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OCompraModalidad CHECK (([Modalidad]='INSUMOS' OR ([Modalidad]='COMBUSTBLE' OR ([Modalidad]='INVENTARIO' OR [Modalidad]='MAYCOMB')))),
 CONSTRAINT CK_Trn_OCompraOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OCompraTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OCompraTipEnt CHECK ((len([TipEnt])>(0))),
 CONSTRAINT CK_Trn_OCompraVigencia CHECK (([Vigencia]='NORMAL' OR [Vigencia]='PERMANENTE')))
CREATE TABLE Trn_OilAcumCostos ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Periodo INT DEFAULT ((0)) NOT NULL,
CostoUnd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) NOT NULL
 CONSTRAINT PK_Trn_OilAcumCostos PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_OilAcumCostosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilAcumCostosIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilAcumCostosUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilAjustes ( 
TipDoc VARCHAR(3) NOT NULL,
NumProceso INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecProceso SMALLDATETIME NOT NULL,
TipOrden VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrden CHAR(2) NOT NULL,
TipoProceso VARCHAR(10) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CantEntradas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantSalidas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoEnt DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoSal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
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(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilAjustes PRIMARY KEY CLUSTERED (TipDoc,NumProceso,IdCia),
 CONSTRAINT CK_Trn_OilAjustesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdCiaOrden CHECK ((len([IdCiaOrden])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_OilAjustesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilAjustesOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilAjustesTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilAjustesTipoProceso CHECK ((len([TipoProceso])>(0))),
 CONSTRAINT CK_Trn_OilAjustesTipOrden CHECK ((len([TipOrden])>(0))))
CREATE TABLE Trn_OilAjustesProd ( 
TipDoc VARCHAR(3) NOT NULL,
NumProceso INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
Entradas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Salidas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipoProd VARCHAR(10),
Descripcion VARCHAR(500)
 CONSTRAINT PK_Trn_OilAjustesProd PRIMARY KEY CLUSTERED (TipDoc,NumProceso,IdCia,Item),
 CONSTRAINT CK_Trn_OilAjustesProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilAjustesProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilAjustesProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilAjustesProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilAjustesProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilCierres ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdCia CHAR(2) NOT NULL,
TipoProc VARCHAR(10) NOT NULL,
nAnno INT DEFAULT ((0)) NOT NULL,
Periodo INT DEFAULT ((0)) NOT NULL,
Estado INT DEFAULT ((0)) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilCierres PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_OilCierresIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCierresIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilCierresTipoProc CHECK ((len([TipoProc])>(0))))
CREATE TABLE Trn_OilCompra ( 
TipDoc VARCHAR(3) DEFAULT ('COC') NOT NULL,
NumCompra INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
NumFactura VARCHAR(15) NOT NULL,
FechaFac SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
MulPlazos BIT DEFAULT ((0)) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CxPagar BIT DEFAULT ((0)) NOT NULL,
SubTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Descuento DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Impuesto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Retencion DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ReteIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ReteIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IvaIngProd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
OtrosCargos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
OtrosDctos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Fletes DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseImp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseIvaIgp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRiv DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
Modalidad VARCHAR(10) NOT NULL,
FechaInicio SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME,
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
NumDev INT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
EstRegCosto INT DEFAULT ((0)) NOT NULL,
NumRegCosto INT DEFAULT ((0)) NOT NULL,
CiaRegCosto CHAR(2)
 CONSTRAINT PK_Trn_OilCompra PRIMARY KEY CLUSTERED (TipDoc,NumCompra,IdCia),
 CONSTRAINT CK_Trn_OilCompraIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdPlazo CHECK ((len([IdPlazo])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_OilCompraIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilCompraModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_OilCompraNumFactura CHECK ((len([NumFactura])>(0))),
 CONSTRAINT CK_Trn_OilCompraOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilCompraTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilCompraDesp ( 
TipDoc VARCHAR(3) DEFAULT ('COC') NOT NULL,
NumCompra INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCiaGuia CHAR(2) NOT NULL,
TipEnt VARCHAR(3) NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCiaEnt CHAR(2) NOT NULL,
ItemEnt INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
CantBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantEntrada DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
UMCargue VARCHAR(10),
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
NumTasas INT DEFAULT ((0)) NOT NULL,
TasaBrent DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TasaWti DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TRMdolar DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Puntos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
PrecioUnd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CdMoneda VARCHAR(5),
UMprecio VARCHAR(10)
 CONSTRAINT PK_Trn_OilCompraDesp PRIMARY KEY CLUSTERED (TipDoc,NumCompra,IdCia,Item),
 CONSTRAINT CK_Trn_OilCompraDespIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCompraDespIdCiaEnt CHECK ((len([IdCiaEnt])>(0))),
 CONSTRAINT CK_Trn_OilCompraDespIdCiaGuia CHECK ((len([IdCiaGuia])>(0))),
 CONSTRAINT CK_Trn_OilCompraDespIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilCompraDespTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilCompraDespTipEnt CHECK ((len([TipEnt])>(0))),
 CONSTRAINT CK_Trn_OilCompraDespUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilCompraProd ( 
TipDoc VARCHAR(3) DEFAULT ('COC') NOT NULL,
NumCompra INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUnit DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDcto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaDct DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarDct VARCHAR(4),
Descripcion VARCHAR(1000),
CdMoneda VARCHAR(5),
CantBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantEntrada DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UMCargue VARCHAR(10),
UMEntrada VARCHAR(10)
 CONSTRAINT PK_Trn_OilCompraProd PRIMARY KEY CLUSTERED (TipDoc,NumCompra,IdCia,Item),
 CONSTRAINT CK_Trn_OilCompraProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCompraProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilCompraProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilCompraProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilCostos ( 
TipProc VARCHAR(3) DEFAULT ('PCC') NOT NULL,
NumProceso INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaInicio SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME,
IdConcepto VARCHAR(4) NOT NULL,
NitProveedor VARCHAR(16) NOT NULL,
CodCiaFac CHAR(2) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
SubTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTransporte DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTraVacio DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
NumDev INT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(2000),
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilCostos PRIMARY KEY CLUSTERED (TipProc,NumProceso,IdCia),
 CONSTRAINT CK_Trn_OilCostosCodCiaFac CHECK ((len([CodCiaFac])>(0))),
 CONSTRAINT CK_Trn_OilCostosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCostosIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilCostosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilCostosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilCostosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilCostosNitProveedor CHECK ((len([NitProveedor])>(0))),
 CONSTRAINT CK_Trn_OilCostosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilCostosTipProc CHECK ((len([TipProc])>(0))))
CREATE TABLE Trn_OilCostosProd ( 
TipProc VARCHAR(3) DEFAULT ('PCC') NOT NULL,
NumProceso INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3) DEFAULT ('COC') NOT NULL,
NumCompra INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
ItemCom INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UMCargue VARCHAR(10),
CostoUnit DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_OilCostosProd PRIMARY KEY CLUSTERED (TipProc,NumProceso,IdCia,Item),
 CONSTRAINT CK_Trn_OilCostosProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCostosProdIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilCostosProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilCostosProdTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_OilCostosProdTipProc CHECK ((len([TipProc])>(0))),
 CONSTRAINT CK_Trn_OilCostosProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilCostoVen ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaInicio SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantDev DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDevFact DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
TipCom VARCHAR(3),
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(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilCostoVen PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_OilCostoVenIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilCostoVenProd ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipFact VARCHAR(3) NOT NULL,
NumFactura INT DEFAULT ((0)) NOT NULL,
IdCiaFact CHAR(2) NOT NULL,
ItemFact INT DEFAULT ((0)) NOT NULL,
FechaFact SMALLDATETIME NOT NULL,
TipGuia VARCHAR(3),
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCiaGuia CHAR(2),
FechaGuia SMALLDATETIME,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16),
IdVehiculo VARCHAR(10),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
TipoProd VARCHAR(10) NOT NULL
 CONSTRAINT PK_Trn_OilCostoVenProd PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_OilCostoVenProdDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdIdCiaFact CHECK ((len([IdCiaFact])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdTipFact CHECK ((len([TipFact])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdTipoProd CHECK ((len([TipoProd])>(0))),
 CONSTRAINT CK_Trn_OilCostoVenProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilDespClie ( 
TipDoc VARCHAR(3) NOT NULL,
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecCargue SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecDescargue SMALLDATETIME,
HorasVig DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
NitEmpTrans VARCHAR(16),
NomEmpTrans VARCHAR(150),
Remolque VARCHAR(10),
IdEstacion VARCHAR(4) NOT NULL,
IdLocOrigen VARCHAR(8) NOT NULL,
IdLocDestino VARCHAR(8) NOT NULL,
LugarOrigen VARCHAR(150),
DirDestino VARCHAR(250) NOT NULL,
NomContacto VARCHAR(150),
TelContacto VARCHAR(30),
emlContacto VARCHAR(100),
Modalidad VARCHAR(10) NOT NULL,
Referencia VARCHAR(50),
NumRemision VARCHAR(20),
DetSellos VARCHAR(500),
CodSicom VARCHAR(20),
ZonaFrontera INT DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
SubTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTransporte DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipOrden VARCHAR(3),
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrden CHAR(2),
EstFactura INT DEFAULT ((0)) NOT NULL,
TipFac VARCHAR(3) DEFAULT ('0') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
FechaFact SMALLDATETIME,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilDespClie PRIMARY KEY CLUSTERED (TipDoc,NumGuia,IdCia),
 CONSTRAINT CK_Trn_OilDespClieDirDestino CHECK ((len([DirDestino])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdEstacion CHECK ((len([IdEstacion])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdLocDestino CHECK ((len([IdLocDestino])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdLocOrigen CHECK ((len([IdLocOrigen])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilDespClieIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_OilDespClieModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_OilDespClieOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilDespClieTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilDespClieTipFac CHECK ((len([TipFac])>(0))))
CREATE TABLE Trn_OilDespClieProd ( 
TipDoc VARCHAR(3) NOT NULL,
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
TipoProd VARCHAR(10) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(1000) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
Temperatura DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TempLab DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UnidTemp CHAR(1),
ValorAPI DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
API_Corregido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Densidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorVCW DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
FactorTemp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
FleteUnd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodSicomPro VARCHAR(20),
IndMezcla INT DEFAULT ((0)) NOT NULL,
ItemMezcla INT DEFAULT ((0)) NOT NULL,
FactorMezcla DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_OilDespClieProd PRIMARY KEY CLUSTERED (TipDoc,NumGuia,IdCia,Item),
 CONSTRAINT CK_Trn_OilDespClieProdDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_OilDespClieProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDespClieProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilDespClieProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilDespClieProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilDespClieProdTipoProd CHECK ((len([TipoProd])>(0))),
 CONSTRAINT CK_Trn_OilDespClieProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilDevCompra ( 
TipDev VARCHAR(3) DEFAULT ('DCR') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('COC') NOT NULL,
NumCompra INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
NumFactura VARCHAR(15) NOT NULL,
CxPagar BIT DEFAULT ((0)) NOT NULL,
SubTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Descuento DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Impuesto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Retencion DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ReteIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ReteIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IvaIngProd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
OtrosCargos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
OtrosDctos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Fletes DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseImp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
BaseIvaIgp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRiv DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
Modalidad VARCHAR(10) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
ModdDev VARCHAR(10) NOT NULL,
Observacion VARCHAR(2000),
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilDevCompra PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_OilDevCompraIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraNumFactura CHECK ((len([NumFactura])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilDevCompraTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilDevComProd ( 
TipDev VARCHAR(3) DEFAULT ('DCR') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUnit DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDcto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaDct DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarDct VARCHAR(4),
Descripcion VARCHAR(1000),
CdMoneda VARCHAR(5),
CantBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantEntrada DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UMCargue VARCHAR(10),
UMEntrada VARCHAR(10)
 CONSTRAINT PK_Trn_OilDevComProd PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia,Item),
 CONSTRAINT CK_Trn_OilDevComProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDevComProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilDevComProdTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilDevComProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilDevCostos ( 
TipDev VARCHAR(3) DEFAULT ('DPC') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('PCC') NOT NULL,
NumProceso INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
SubTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTransporte DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTraVacio DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
ModdDev VARCHAR(10) NOT NULL,
Observacion VARCHAR(2000),
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilDevCostos PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_OilDevCostosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilDevCostosProd ( 
TipDev VARCHAR(3) DEFAULT ('DPC') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUnit DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_OilDevCostosProd PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia,Item),
 CONSTRAINT CK_Trn_OilDevCostosProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosProdTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilDevCostosProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilDevFacProd ( 
TipDev VARCHAR(3) NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaDct DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDcto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrRetFte DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrRetIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
FleteUnd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUnit DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ItemDet INT DEFAULT ((0)) NOT NULL,
TipoProd VARCHAR(10) NOT NULL,
TipGuia VARCHAR(3),
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCiaGuia CHAR(2),
CantGuia DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IndMezcla INT DEFAULT ((0)) NOT NULL,
ItemMezcla INT DEFAULT ((0)) NOT NULL,
FactorMezcla DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarDct VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodSicomPro VARCHAR(20),
CodBodega VARCHAR(4)
 CONSTRAINT PK_Trn_OilDevFacProd PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia,Item),
 CONSTRAINT CK_Trn_OilDevFacProdDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_OilDevFacProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilDevFacProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilDevFacProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilDevFacProdTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilDevFacProdTipoProd CHECK ((len([TipoProd])>(0))),
 CONSTRAINT CK_Trn_OilDevFacProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilEntrada ( 
TipEnt VARCHAR(3) NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCiaGuia CHAR(2) NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecDescargue SMALLDATETIME NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
NitEmpTrans VARCHAR(16),
NomEmpTrans VARCHAR(150),
Remolque VARCHAR(10),
ValorTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CtaPagar BIT DEFAULT ((0)) NOT NULL,
TipFactCxp VARCHAR(3),
NumFactura INT DEFAULT ((0)) NOT NULL,
IdCiaCxp CHAR(2),
TipoAju VARCHAR(3),
NumAjuInv INT DEFAULT ((0)) NOT NULL,
IdCiaAju CHAR(2),
CantAjuste DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
EstContable INT DEFAULT ((0)) NOT NULL,
CdConcepto VARCHAR(4),
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
NumFactTra INT DEFAULT ((0)) NOT NULL,
CdCiaFtr CHAR(2)
 CONSTRAINT PK_Trn_OilEntrada PRIMARY KEY CLUSTERED (TipEnt,NumEntrada,IdCia),
 CONSTRAINT CK_Trn_OilEntradaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdCiaGuia CHECK ((len([IdCiaGuia])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilEntradaIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_OilEntradaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilEntradaTipEnt CHECK ((len([TipEnt])>(0))))
CREATE TABLE Trn_OilEntradaProd ( 
TipEnt VARCHAR(3) NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
Temperatura DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UnidTemp CHAR(1),
ValorAPI DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorVCW DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
API_Corregido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Densidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantCargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TempCargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
API_Cargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VCW_Cargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UMCargue VARCHAR(10)
 CONSTRAINT PK_Trn_OilEntradaProd PRIMARY KEY CLUSTERED (TipEnt,NumEntrada,IdCia,Item),
 CONSTRAINT CK_Trn_OilEntradaProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilEntradaProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilEntradaProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilEntradaProdTipEnt CHECK ((len([TipEnt])>(0))),
 CONSTRAINT CK_Trn_OilEntradaProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilFacturaProd ( 
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaDct DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrDcto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrIva DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrRetFte DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrRetIca DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
FleteUnd DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUnit DECIMAL(16,6) DEFAULT ((0)),
Temperatura DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TempLab DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UnidTemp CHAR(1),
ValorAPI DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
API_Corregido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Densidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipoProd VARCHAR(10) NOT NULL,
TipGuia VARCHAR(3),
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCiaGuia CHAR(2),
CantGuia DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
IndMezcla INT DEFAULT ((0)) NOT NULL,
ItemMezcla INT DEFAULT ((0)) NOT NULL,
FactorMezcla DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
NumTasas INT DEFAULT ((0)) NOT NULL,
TasaBrent DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TasaWti DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TRMdolar DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Puntos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodTarIva VARCHAR(4),
CodTarDct VARCHAR(4),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CdMoneda VARCHAR(5),
CodSicomPro VARCHAR(20),
CodBodega VARCHAR(4)
 CONSTRAINT PK_Trn_OilFacturaProd PRIMARY KEY CLUSTERED (TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_OilFacturaProdDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_OilFacturaProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilFacturaProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilFacturaProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilFacturaProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilFacturaProdTipoProd CHECK ((len([TipoProd])>(0))),
 CONSTRAINT CK_Trn_OilFacturaProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilGuia ( 
TipDoc VARCHAR(3) NOT NULL,
NumGuia INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdEstacion VARCHAR(4),
IdProducto VARCHAR(16) NOT NULL,
CantBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
Temperatura DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UnidTemp CHAR(1),
ValorAPI DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorVCW DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantDescargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
APIDescargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TempDescargue DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
FecDescargue SMALLDATETIME,
NitEmpTrans VARCHAR(16),
NomEmpTrans VARCHAR(150),
NumRemision VARCHAR(20),
Remolque VARCHAR(10),
TipoEnt VARCHAR(3) NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCiaEnt CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
NumFactCom INT DEFAULT ((0)) NOT NULL,
CdCiaFco CHAR(2),
NumFactTra INT DEFAULT ((0)) NOT NULL,
CdCiaFtr CHAR(2)
 CONSTRAINT PK_Trn_OilGuia PRIMARY KEY CLUSTERED (TipDoc,NumGuia,IdCia),
 CONSTRAINT CK_Trn_OilGuiaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdCiaEnt CHECK ((len([IdCiaEnt])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilGuiaIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_OilGuiaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilGuiaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilGuiaTipoEnt CHECK ((len([TipoEnt])>(0))),
 CONSTRAINT CK_Trn_OilGuiaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilInvent ( 
TipEnt VARCHAR(3) DEFAULT ('EIN') NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Modalidad VARCHAR(10) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
NumFactura VARCHAR(15),
FechaFac SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CtaPagar BIT DEFAULT ((0)) NOT NULL,
EstContable INT DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
NumDev INT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilInvent PRIMARY KEY CLUSTERED (TipEnt,NumEntrada,IdCia),
 CONSTRAINT CK_Trn_OilInventIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilInventIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilInventIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilInventIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilInventIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilInventIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_OilInventIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilInventModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_OilInventOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilInventTipEnt CHECK ((len([TipEnt])>(0))))
CREATE TABLE Trn_OilInventDev ( 
TipDev VARCHAR(3) DEFAULT ('DVI') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipEnt VARCHAR(3) NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCiaDoc CHAR(2) NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CtaPagar BIT DEFAULT ((0)) NOT NULL,
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
ModdDev VARCHAR(10) NOT NULL,
Observacion VARCHAR(2000),
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilInventDev PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_OilInventDevIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilInventDevIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilInventDevIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilInventDevIdCiaDoc CHECK ((len([IdCiaDoc])>(0))),
 CONSTRAINT CK_Trn_OilInventDevIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilInventDevIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_OilInventDevIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilInventDevModdDev CHECK ((len([ModdDev])>(0))),
 CONSTRAINT CK_Trn_OilInventDevOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilInventDevTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilInventDevTipEnt CHECK ((len([TipEnt])>(0))))
CREATE TABLE Trn_OilInventDevp ( 
TipDev VARCHAR(3) NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipoProd VARCHAR(10),
Descripcion VARCHAR(500),
IdEstacion VARCHAR(4)
 CONSTRAINT PK_Trn_OilInventDevp PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia,Item),
 CONSTRAINT CK_Trn_OilInventDevpIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilInventDevpIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilInventDevpIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilInventDevpTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_OilInventDevpUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilInventProd ( 
TipEnt VARCHAR(3) NOT NULL,
NumEntrada INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipoProd VARCHAR(10),
Descripcion VARCHAR(500),
IdEstacion VARCHAR(4)
 CONSTRAINT PK_Trn_OilInventProd PRIMARY KEY CLUSTERED (TipEnt,NumEntrada,IdCia,Item),
 CONSTRAINT CK_Trn_OilInventProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilInventProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilInventProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilInventProdTipEnt CHECK ((len([TipEnt])>(0))),
 CONSTRAINT CK_Trn_OilInventProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilMediciones ( 
TipDoc VARCHAR(3) DEFAULT ('IFT') NOT NULL,
NumInvent INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecProceso SMALLDATETIME NOT NULL,
IdTurno VARCHAR(4) NOT NULL,
IdOperario VARCHAR(16),
NomOperario VARCHAR(150),
Modalidad VARCHAR(10) DEFAULT ('AJUSTE') NOT NULL,
TipDocAju VARCHAR(3),
AjuInvSob INT DEFAULT ((0)) NOT NULL,
AjuInvFal INT DEFAULT ((0)) NOT NULL,
IdCiaAin CHAR(2) DEFAULT ('00') NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
NumDev INT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
VolPT DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VolMP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
FecProcAnt SMALLDATETIME,
NumHoras DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumSalida INT DEFAULT ((0)) NOT NULL,
NumNcp INT DEFAULT ((0)) NOT NULL,
IdCiaNcp CHAR(2) DEFAULT ('00') NOT NULL
 CONSTRAINT PK_Trn_OilMediciones PRIMARY KEY CLUSTERED (TipDoc,NumInvent,IdCia),
 CONSTRAINT CK_Trn_OilMedicionesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesIdCiaAin CHECK ((len([IdCiaAin])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesIdTurno CHECK ((len([IdTurno])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilMedicionesTq ( 
TipDoc VARCHAR(3) DEFAULT ('IFT') NOT NULL,
NumInvent INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
NivelVol DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
TipoMed INT DEFAULT ((0)) NOT NULL,
AlturaTq DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndAforoC DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndAforoF DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Temperatura DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UnidTemp CHAR(1),
ValorAPI DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
API_Corregido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Densidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantAjuste DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TempLab DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VolMedido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VolNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Vol_Anterior DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantEntradas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantSalidas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
TipoProd VARCHAR(10),
Descripcion VARCHAR(500)
 CONSTRAINT PK_Trn_OilMedicionesTq PRIMARY KEY CLUSTERED (TipDoc,NumInvent,IdCia,Item),
 CONSTRAINT CK_Trn_OilMedicionesTqIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesTqIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesTqIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesTqTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilMedicionesTqUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilNotas ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
ValorTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
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(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilNotas PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_OilNotasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilNotasIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilNotasIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilNotasIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilNotasIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilNotasIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_OilNotasIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilNotasOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilNotasTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilNotasProd ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_OilNotasProd PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_OilNotasProdDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_OilNotasProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilNotasProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilNotasProdIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilNotasProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilNotasProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilSaldos ( 
IdProducto VARCHAR(16) NOT NULL,
IdTanque VARCHAR(4) NOT NULL,
IdCia CHAR(2) NOT NULL,
Periodo INT DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
Volumen DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UMvol VARCHAR(10) NOT NULL
 CONSTRAINT PK_Trn_OilSaldos PRIMARY KEY CLUSTERED (IdProducto,IdTanque,IdCia,Periodo),
 CONSTRAINT CK_Trn_OilSaldosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilSaldosIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilSaldosIdTanque CHECK ((len([IdTanque])>(0))),
 CONSTRAINT CK_Trn_OilSaldosUMvol CHECK ((len([UMvol])>(0))),
 CONSTRAINT CK_Trn_OilSaldosUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilTraslado ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaInicio SMALLDATETIME NOT NULL,
FechaFinal SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CantMP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantProducido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantConsumo DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantCrudoCom DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Total_MP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VU_MP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantBrutoMP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNetoMP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantFactMP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Total_TRA DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VU_TRA DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNetoTRA DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantFactTRA DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Total_TVacio DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VU_TVacio DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNetoTv DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantFactTv DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Total_Standby DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VU_Standby DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Cant_Standby DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Total_MOD DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Total_CIF DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
TipCom VARCHAR(3),
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(2000),
IdEstado VARCHAR(4) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_OilTraslado PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia),
 CONSTRAINT CK_Trn_OilTrasladoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoIdTercero CHECK ((len([IdTercero])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_OilTrasladoProd ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500) NOT NULL,
TipoProd VARCHAR(10) NOT NULL,
SaldoInicial DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
SaldoFinal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Entradas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Despachos DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
DespMezcla DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Salidas DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
AjuSobrante DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
AjuFaltante DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
PorcRend DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoAnt DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
SaldoMPAnt DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantProdAnt DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoMPAnt DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoMPMes DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUndMP DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUndTra DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoTotalTra DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoTotalSB DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoUndVco DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoTotalVco DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoTotalMod DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CostoTotalCif DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CodMezcla VARCHAR(16),
CdoSubMezcla VARCHAR(8),
Producido DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantVehTnsto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantBrutoDesp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNetoDesp DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantTraDesp DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_OilTrasladoProd PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_OilTrasladoProdDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoProdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoProdIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoProdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoProdTipoProd CHECK ((len([TipoProd])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoProdUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_OilTrasladoRubros ( 
TipDoc VARCHAR(3) NOT NULL,
NumNota INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
TipoRubro VARCHAR(10) NOT NULL,
CantBruto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
CantNeto DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrUnitario DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
VrTotal DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
UndMed VARCHAR(10) DEFAULT ('br') NOT NULL,
CodCueCP VARCHAR(16)
 CONSTRAINT PK_Trn_OilTrasladoRubros PRIMARY KEY CLUSTERED (TipDoc,NumNota,IdCia,Item),
 CONSTRAINT CK_Trn_OilTrasladoRubrosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoRubrosIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoRubrosTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoRubrosTipoRubro CHECK ((len([TipoRubro])>(0))),
 CONSTRAINT CK_Trn_OilTrasladoRubrosUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_Opedido ( 
TipDoc VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdClieFact VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrImpuesto MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrOtros MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrOtrDcto MONEY DEFAULT ((0)) NOT NULL,
VrSobretasa MONEY DEFAULT ((0)) NOT NULL,
VrImpGlobal MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarCom VARCHAR(4),
DirEnvio VARCHAR(250),
IdLocEnv VARCHAR(8) NOT NULL,
LugarEnvio VARCHAR(50),
DiasEntraga INT DEFAULT ((0)) NOT NULL,
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargoContac VARCHAR(50),
IdForma VARCHAR(4) NOT NULL,
DetallePago VARCHAR(100),
MulPlazos BIT DEFAULT ((0)) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
CdMney VARCHAR(5),
NitEmpTrans VARCHAR(16) DEFAULT ('0') NOT NULL,
EmpTrans VARCHAR(150),
AsignarVeh BIT DEFAULT ((0)) NOT NULL,
pVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
ListaPrec CHAR(1),
RefPedido VARCHAR(50),
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
Vigencia VARCHAR(10) DEFAULT ('NORMAL') NOT NULL,
NumAutoriza INT DEFAULT ((0)) NOT NULL,
NumAutCupo INT DEFAULT ((0)) NOT NULL,
NumAutCheq INT DEFAULT ((0)) NOT NULL,
NumAprob INT DEFAULT ((0)) NOT NULL,
IdCiaApr CHAR(2) DEFAULT ('01') NOT NULL,
FecAprob SMALLDATETIME,
DetalleAprob VARCHAR(250),
CdUsuAprob VARCHAR(11),
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
FechaFact SMALLDATETIME,
TipRem VARCHAR(3) DEFAULT ('REM') NOT NULL,
Remision INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
FechaRem SMALLDATETIME,
NumCotizac INT DEFAULT ((0)) NOT NULL,
CdCiaCotizac CHAR(2) DEFAULT ('00'),
OrigenAdd VARCHAR(10) NOT NULL,
ZonaFrontera INT DEFAULT ((0)) NOT NULL,
TipoTrans INT DEFAULT ((0)) NOT NULL,
TipoOrden VARCHAR(3) DEFAULT ('S'),
TipoModifica VARCHAR(10),
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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,
NumAutSicom VARCHAR(50),
VrImpCarbono MONEY DEFAULT ((0)) NOT NULL,
BaseIvaIgp MONEY DEFAULT ((0)) NOT NULL,
VrIvaIngProd MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Opedido PRIMARY KEY NONCLUSTERED (TipDoc,Pedido,IdCia),
 CONSTRAINT CK_Trn_OpedidoCdConductor CHECK ((len([CdConductor])>(0))),
 CONSTRAINT CK_Trn_OpedidoCdRuta CHECK ((len([CdRuta])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdCiaApr CHECK ((len([IdCiaApr])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdCiaFac CHECK ((len([IdCiaFac])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdClieFact CHECK ((len([IdClieFact])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdForma CHECK ((len([IdForma])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdLocEnv CHECK ((len([IdLocEnv])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdPlazo CHECK ((len([IdPlazo])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_OpedidoIdVend CHECK ((len([IdVend])>(0))),
 CONSTRAINT CK_Trn_OpedidoModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_OpedidoNitEmpTrans CHECK ((len([NitEmpTrans])>(0))),
 CONSTRAINT CK_Trn_OpedidoOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_OpedidopVehiculo CHECK ((len([pVehiculo])>(0))),
 CONSTRAINT CK_Trn_OpedidoTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_OpedidoTipFac CHECK ((len([TipFac])>(0))),
 CONSTRAINT CK_Trn_OpedidoTipRem CHECK ((len([TipRem])>(0))),
 CONSTRAINT CK_Trn_OpedidoVigencia CHECK (([Vigencia]='NORMAL' OR [Vigencia]='PERMANENTE')))
CREATE TABLE Trn_Pagos ( 
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,
IdForma VARCHAR(4) DEFAULT ('EFE') NOT NULL,
Detalle VARCHAR(150) NOT NULL,
VrPagado MONEY DEFAULT (0) NOT NULL,
VrCambio MONEY DEFAULT (0) NOT NULL,
EsCaja BIT DEFAULT (1) NOT NULL,
IdBanco VARCHAR(4) NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
NumForma VARCHAR(20),
FecForma SMALLDATETIME,
CtaForma VARCHAR(30),
Beneficiario VARCHAR(150),
Referncia1 VARCHAR(50),
Referncia2 VARCHAR(50),
CdLocal VARCHAR(8) DEFAULT ('0') NOT NULL,
NumAutoriza VARCHAR(30),
VrDenom MONEY DEFAULT (0) NOT NULL,
Cantidad INT DEFAULT (0) NOT NULL,
TipDenom CHAR(1) DEFAULT ('B') NOT NULL,
TipRef VARCHAR(3) DEFAULT ('0') NOT NULL,
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('00') NOT NULL,
ItemDoc INT DEFAULT (0) NOT NULL,
CdCta VARCHAR(4),
IdUsuario VARCHAR(11) NOT NULL,
CdProducto VARCHAR(16),
FE_Ticket BIT DEFAULT ((0)) NOT NULL,
Cant_Gals DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PrecioBase MONEY DEFAULT ((0)) NOT NULL,
PrecioUnit MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Pagos PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_PagosCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_PagosCdLocal CHECK ((len([CdLocal]) > 0)),
 CONSTRAINT CK_Trn_PagosDetalle CHECK ((len([Detalle]) > 0)),
 CONSTRAINT CK_Trn_PagosIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_Trn_PagosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_PagosIdCiaRef CHECK ((len([IdCiaRef]) > 0)),
 CONSTRAINT CK_Trn_PagosIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_Trn_PagosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_PagosNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_PagosTipDenom CHECK ((len([TipDenom]) > 0)),
 CONSTRAINT CK_Trn_PagosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_PagosTipRef CHECK ((len([TipRef]) > 0)))
CREATE TABLE Trn_PedImagenes ( 
TipDoc VARCHAR(3) DEFAULT ('PED') NOT NULL,
NumDoc INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
NomArchivo VARCHAR(150) NOT NULL,
BinArchivo IMAGE,
Descripcion VARCHAR(250)
 CONSTRAINT PK_Trn_PedImagenes PRIMARY KEY CLUSTERED (TipDoc,NumDoc,IdCia,Item),
 CONSTRAINT CK_Trn_PedImagenesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_PedImagenesNomArchivo CHECK ((len([NomArchivo])>(0))),
 CONSTRAINT CK_Trn_PedImagenesTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_PreCausacion ( 
CausacionID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('DIARIO') NOT NULL,
TotalCapital MONEY DEFAULT (0) NOT NULL,
TotalInteres MONEY DEFAULT (0) NOT NULL,
TotalCuota MONEY DEFAULT (0) NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdPropietario VARCHAR(16) DEFAULT ('0') NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('PRE'),
PrestamoID INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2),
NumCuota INT DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') NOT NULL,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_PreCausacion PRIMARY KEY CLUSTERED (CausacionID,IdCia),
 CONSTRAINT CK_Trn_PreCausacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_PreCausacionIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_PreCausacionIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_PreCausacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_PreCausacionIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_PreCausacionModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_PreCausacionTipCom CHECK ((len([TipCom]) > 0)))
CREATE TABLE Trn_PreCuotas ( 
TipDoc VARCHAR(3) DEFAULT ('PRE') NOT NULL,
PrestamoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NumCuota INT DEFAULT (0) NOT NULL,
FecCausa SMALLDATETIME NOT NULL,
FecVence SMALLDATETIME NOT NULL,
ValorCapital MONEY DEFAULT (0) NOT NULL,
ValorInteres MONEY DEFAULT (0) NOT NULL,
ValorCuota MONEY DEFAULT (0) NOT NULL,
CausacionID INT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_PreCuotas PRIMARY KEY CLUSTERED (TipDoc,PrestamoID,IdCia,NumCuota),
 CONSTRAINT CK_Trn_PreCuotasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_PreCuotasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_PreCuotasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_PresDetalle ( 
Numero INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
VrPresupuesto MONEY DEFAULT ((0)) NOT NULL,
SaldoAnterior MONEY DEFAULT ((0)) NOT NULL,
TotalDebitos MONEY DEFAULT ((0)) NOT NULL,
TotalCreditos MONEY DEFAULT ((0)) NOT NULL,
TipoNiif VARCHAR(10) NOT NULL,
CodCueNiif VARCHAR(16),
VrPrespNiif MONEY DEFAULT ((0)) NOT NULL,
CdUsuario VARCHAR(11) NOT NULL,
FecUpdate SMALLDATETIME NOT NULL,
SAnteriorNiif MONEY DEFAULT ((0)) NOT NULL,
DebitosNiif MONEY DEFAULT ((0)) NOT NULL,
CreditosNiif MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_PresDetalle PRIMARY KEY CLUSTERED (Numero,IdCia,Item),
 CONSTRAINT CK_Trn_PresDetalleCdUsuario CHECK ((len([CdUsuario])>(0))),
 CONSTRAINT CK_Trn_PresDetalleIdCCosto CHECK ((len([IdCCosto])>(0))),
 CONSTRAINT CK_Trn_PresDetalleIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_PresDetalleIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_Trn_PresDetalleIdSubCos CHECK ((len([IdSubCos])>(0))))
CREATE TABLE Trn_Prestamos ( 
TipDoc VARCHAR(3) DEFAULT ('PRE') NOT NULL,
PrestamoID INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecPrestamo SMALLDATETIME NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
TipoPlazo VARCHAR(10) DEFAULT ('MENSUAL') NOT NULL,
NumCuotas INT DEFAULT (0) NOT NULL,
DiasCausa VARCHAR(5) NOT NULL,
DiasVence VARCHAR(5) NOT NULL,
TipoCuota VARCHAR(10) DEFAULT ('VARIABLE') NOT NULL,
ValorPrestamo MONEY DEFAULT (0) NOT NULL,
TasaInteres DECIMAL(14,4) DEFAULT (0) NOT NULL,
TotalCausado MONEY DEFAULT (0) NOT NULL,
TotalInteres MONEY DEFAULT (0) NOT NULL,
UltimaCuota INT DEFAULT (0) NOT NULL,
Cancelado BIT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
Referencia VARCHAR(20),
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
TipCom VARCHAR(3) DEFAULT ('0') NOT NULL,
Comprobante INT DEFAULT (0) NOT NULL,
IdCiaCom CHAR(2) DEFAULT ('00') 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_Prestamos PRIMARY KEY CLUSTERED (TipDoc,PrestamoID,IdCia),
 CONSTRAINT CK_Trn_PrestamosDiasCausa CHECK ((len([DiasCausa]) > 0)),
 CONSTRAINT CK_Trn_PrestamosDiasVence CHECK ((len([DiasVence]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_PrestamosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_PrestamosTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_PrestamosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_PrestamosTipoCuota CHECK (([TipoCuota] = 'FIJA' or [TipoCuota] = 'VARIABLE')),
 CONSTRAINT CK_Trn_PrestamosTipoPlazo CHECK (([TipoPlazo] = 'QUINCENAL' or [TipoPlazo] = 'MENSUAL')))
CREATE TABLE Trn_Presupuesto ( 
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) 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,
TipoPsto INT DEFAULT (0) NOT NULL,
DetCentros BIT DEFAULT (1) NOT NULL
 CONSTRAINT PK_Trn_Presupuesto PRIMARY KEY CLUSTERED (Numero,IdCia),
 CONSTRAINT CK_Trn_PresupuestoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_PresupuestoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_PresupuestoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_PresupuestoIdUsuario CHECK ((len([IdUsuario]) > 0)))
CREATE TABLE Trn_ProdConsDet ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
NumTalla VARCHAR(30) NOT NULL,
CantPedido DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantAprob DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdBodTdo VARCHAR(4) NOT NULL,
Tallas BIT DEFAULT ((0)) NOT NULL,
IdUnd VARCHAR(4) NOT NULL
 CONSTRAINT PK_Trn_ProdConsDet PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsDetCdBodTdo CHECK ((len([CdBodTdo])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdConsDetTipPed CHECK ((len([TipPed])>(0))))
CREATE TABLE Trn_ProdConsIns ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdInsumo VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTraslado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantConsumo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantDevuelto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdBodTdo VARCHAR(4) NOT NULL,
TipTdo VARCHAR(3),
Traslado INT DEFAULT ((0)) NOT NULL,
IdCiaTdo CHAR(2),
IdTipProc VARCHAR(4) NOT NULL
 CONSTRAINT PK_Trn_ProdConsIns PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsInsCdBodTdo CHECK ((len([CdBodTdo])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsIdInsumo CHECK ((len([IdInsumo])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdConsInsu ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdInsumo VARCHAR(16) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantOrden DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdBodTdo VARCHAR(4) NOT NULL,
CantPed DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSalidas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CostoUntSai MONEY DEFAULT ((0)) NOT NULL,
TipTdo VARCHAR(3),
Traslado INT DEFAULT ((0)) NOT NULL,
IdCiaTdo CHAR(2)
 CONSTRAINT PK_Trn_ProdConsInsu PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsInsuCdBodTdo CHECK ((len([CdBodTdo])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuIdInsumo CHECK ((len([IdInsumo])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdConsInsuTipPed CHECK ((len([TipPed])>(0))))
CREATE TABLE Trn_ProdConsolida ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdBodDest VARCHAR(4),
IdBodIns VARCHAR(4) NOT NULL,
CdBodInsDest VARCHAR(4),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
CritPedidos VARCHAR(500),
Observacion VARCHAR(2000),
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_ProdConsolida PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia),
 CONSTRAINT CK_Trn_ProdConsolidaIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaIdBodIns CHECK ((len([IdBodIns])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_ProdConsolidaTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdConsPed ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
TipTdo VARCHAR(3),
Traslado INT DEFAULT ((0)) NOT NULL,
IdCiaTdo CHAR(2),
NumTdoIns INT DEFAULT ((0)) NOT NULL,
CdCiaIns CHAR(2)
 CONSTRAINT PK_Trn_ProdConsPed PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsPedIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsPedIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_ProdConsPedTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdConsPedTipPed CHECK ((len([TipPed])>(0))))
CREATE TABLE Trn_ProdConsProc ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
NumTalla VARCHAR(30) NOT NULL,
CantAprob DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSaldo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Tallas BIT DEFAULT ((0)) NOT NULL,
ProcFinal BIT DEFAULT ((0)) NOT NULL,
VrCostoEst MONEY DEFAULT ((0)) NOT NULL,
EdoOrden INT DEFAULT ((0)) NOT NULL,
TipOrden VARCHAR(3),
NumOrden INT DEFAULT ((0)) NOT NULL,
CdCiaOrden CHAR(2),
CantOrden DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdConsProc PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsProcIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdConsProcTipPed CHECK ((len([TipPed])>(0))))
CREATE TABLE Trn_ProdConsTallas ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipoReg VARCHAR(3) NOT NULL,
ItemDet INT DEFAULT ((0)) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
CantPed DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdConsTallas PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsTallasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsTallasNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdConsTallasTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdConsTallasTipoReg CHECK ((len([TipoReg])>(0))))
CREATE TABLE Trn_ProdConsTdo ( 
TipDoc VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
NumTalla VARCHAR(30) NOT NULL,
CantPedido DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantAprob DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Existencias DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantTdo DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Tallas BIT DEFAULT ((0)) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
TipTdo VARCHAR(3),
Traslado INT DEFAULT ((0)) NOT NULL,
IdCiaTdo CHAR(2)
 CONSTRAINT PK_Trn_ProdConsTdo PRIMARY KEY CLUSTERED (TipDoc,NumCons,IdCia,Item),
 CONSTRAINT CK_Trn_ProdConsTdoIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_ProdConsTdoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdConsTdoIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdConsTdoIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_ProdConsTdoNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdConsTdoTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdEntrega ( 
TipDoc VARCHAR(3) DEFAULT ('OEP') NOT NULL,
NumEntrega INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipOrden VARCHAR(3) DEFAULT ('OPP') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrden CHAR(2) NOT NULL,
FecEntrega SMALLDATETIME NOT NULL,
CostoTotal MONEY DEFAULT ((0)) NOT NULL,
Descuento MONEY DEFAULT ((0)) NOT NULL,
CantTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TipoEntrega VARCHAR(10) NOT NULL,
NitTercero VARCHAR(16),
NomContacto VARCHAR(150),
TelContacto VARCHAR(30),
EdoOrden INT DEFAULT ((0)) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
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,
CodConcepto VARCHAR(4),
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2),
NumDev INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdEntrega PRIMARY KEY CLUSTERED (TipDoc,NumEntrega,IdCia),
 CONSTRAINT CK_Trn_ProdEntregaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaIdCiaOrden CHECK ((len([IdCiaOrden])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaTipoEntrega CHECK ((len([TipoEntrega])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaTipOrden CHECK ((len([TipOrden])>(0))))
CREATE TABLE Trn_ProdEntregaDei ( 
TipDev VARCHAR(3) DEFAULT ('DEP') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemEnt INT DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CostoUnit MONEY DEFAULT ((0)) NOT NULL,
VrDcto MONEY DEFAULT ((0)) NOT NULL,
Tallas BIT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(500)
 CONSTRAINT PK_Trn_ProdEntregaDei PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia,Item),
 CONSTRAINT CK_Trn_ProdEntregaDeiIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDeiTipDev CHECK ((len([TipDev])>(0))))
CREATE TABLE Trn_ProdEntregaDet ( 
TipDoc VARCHAR(3) DEFAULT ('OEP') NOT NULL,
NumEntrega INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOrden VARCHAR(3) DEFAULT ('OPP') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrden CHAR(2) NOT NULL,
ItemOrden INT DEFAULT ((0)) NOT NULL,
CantOrden DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Defectuoso DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Rechazado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CostoUnit MONEY DEFAULT ((0)) NOT NULL,
VrDcto MONEY DEFAULT ((0)) NOT NULL,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('00') NOT NULL,
ItemPed INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
Descripcion VARCHAR(500),
CdTipProc VARCHAR(4),
Tallas BIT DEFAULT ((0)) NOT NULL,
ProcFinal BIT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(500)
 CONSTRAINT PK_Trn_ProdEntregaDet PRIMARY KEY CLUSTERED (TipDoc,NumEntrega,IdCia,Item),
 CONSTRAINT CK_Trn_ProdEntregaDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDetIdCiaOrden CHECK ((len([IdCiaOrden])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDetIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDetIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDetTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDetTipOrden CHECK ((len([TipOrden])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDetTipPed CHECK ((len([TipPed])>(0))))
CREATE TABLE Trn_ProdEntregaDev ( 
TipDev VARCHAR(3) DEFAULT ('DEP') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipDocEnt VARCHAR(3) DEFAULT ('OEP') NOT NULL,
NumEntrega INT DEFAULT ((0)) NOT NULL,
IdCiaEnt CHAR(2) NOT NULL,
CostoTotal MONEY DEFAULT ((0)) NOT NULL,
Descuento MONEY DEFAULT ((0)) NOT NULL,
CantTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NitTercero VARCHAR(16),
CodConcepto VARCHAR(4),
TipCom VARCHAR(3),
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2),
Observacion VARCHAR(2000),
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_ProdEntregaDev PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_ProdEntregaDevIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDevIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDevIdCiaEnt CHECK ((len([IdCiaEnt])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDevIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDevOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDevTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDevTipDocEnt CHECK ((len([TipDocEnt])>(0))))
CREATE TABLE Trn_ProdEntregaDtl ( 
TipDev VARCHAR(3) DEFAULT ('DEP') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemDet INT DEFAULT ((0)) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdEntregaDtl PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia,Item),
 CONSTRAINT CK_Trn_ProdEntregaDtlIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDtlNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaDtlTipDev CHECK ((len([TipDev])>(0))))
CREATE TABLE Trn_ProdEntregaInsu ( 
TipDoc VARCHAR(3) DEFAULT ('OEP') NOT NULL,
NumEntrega INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemCons INT DEFAULT ((0)) NOT NULL,
IdInsumo VARCHAR(16) NOT NULL,
CantTraslado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantSobrante DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CdBodOrig VARCHAR(4) NOT NULL,
CdBodTdo VARCHAR(4) NOT NULL,
TipTdo VARCHAR(3),
Traslado INT DEFAULT ((0)) NOT NULL,
IdCiaTdo CHAR(2),
CdTipProc VARCHAR(4)
 CONSTRAINT PK_Trn_ProdEntregaInsu PRIMARY KEY CLUSTERED (TipDoc,NumEntrega,IdCia,Item),
 CONSTRAINT CK_Trn_ProdEntregaInsuCdBodOrig CHECK ((len([CdBodOrig])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaInsuCdBodTdo CHECK ((len([CdBodTdo])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaInsuIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaInsuIdInsumo CHECK ((len([IdInsumo])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaInsuTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdEntregaTallas ( 
TipDoc VARCHAR(3) DEFAULT ('OEP') NOT NULL,
NumEntrega INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemDet INT DEFAULT ((0)) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Defectuoso DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Rechazado DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdEntregaTallas PRIMARY KEY CLUSTERED (TipDoc,NumEntrega,IdCia,Item),
 CONSTRAINT CK_Trn_ProdEntregaTallasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaTallasNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdEntregaTallasTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdOrden ( 
TipDoc VARCHAR(3) DEFAULT ('OPP') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipCons VARCHAR(3) DEFAULT ('CPP') NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCiaCons CHAR(2) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('PRODUCCION') NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
IdTaller VARCHAR(4) NOT NULL,
CostoTotal MONEY DEFAULT ((0)),
ConPago BIT DEFAULT ((0)) NOT NULL,
EdoOrden INT DEFAULT ((0)) NOT NULL,
FecEntrega SMALLDATETIME,
NitTercero VARCHAR(16),
NomContacto VARCHAR(150),
TelContacto VARCHAR(30),
ProcFinal BIT DEFAULT ((0)),
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(2000),
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,
Num_Entrega INT DEFAULT ((0)) NOT NULL,
CdCiaEnt CHAR(2)
 CONSTRAINT PK_Trn_ProdOrden PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_ProdOrdenIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenIdCiaCons CHECK ((len([IdCiaCons])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenIdTaller CHECK ((len([IdTaller])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenTipCons CHECK ((len([TipCons])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdOrdenDet ( 
TipDoc VARCHAR(3) DEFAULT ('OPP') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipCons VARCHAR(3) NOT NULL,
NumCons INT DEFAULT ((0)) NOT NULL,
IdCiaCons CHAR(2) NOT NULL,
ItemCons INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
NumTalla VARCHAR(30),
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CostoEst MONEY DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(500),
Terminado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Defectuoso DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Rechazado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
MotivoDev VARCHAR(500),
ItemEnt INT DEFAULT ((0)) NOT NULL,
TipEntInv VARCHAR(3),
NumEntrada INT DEFAULT ((0)) NOT NULL,
CdCiaEnt CHAR(2),
ItemKdxEnt INT DEFAULT ((0)) NOT NULL,
CantEntrada DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdOrdenDet PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_ProdOrdenDetIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenDetIdCiaCons CHECK ((len([IdCiaCons])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenDetIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenDetTipCons CHECK ((len([TipCons])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenDetTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdOrdenSal ( 
TipDoc VARCHAR(3) DEFAULT ('OPP') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipSal VARCHAR(3) DEFAULT ('SAL') NOT NULL,
NumSalida INT DEFAULT ((0)) NOT NULL,
IdCiaSal CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_Trn_ProdOrdenSal PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_ProdOrdenSalIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenSalIdCiaSal CHECK ((len([IdCiaSal])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenSalTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenSalTipSal CHECK ((len([TipSal])>(0))))
CREATE TABLE Trn_ProdOrdenTallas ( 
TipDoc VARCHAR(3) DEFAULT ('OPP') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemOrden INT DEFAULT ((0)) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Terminado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Defectuoso DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Rechazado DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantEntrada DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdOrdenTallas PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_ProdOrdenTallasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenTallasNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_ProdOrdenTallasTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdPedidoInsu ( 
TipDoc VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
ItemDet INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdInsumo VARCHAR(16) NOT NULL,
IdTipProc VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantPed DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantAprob DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ProdPedidoInsu PRIMARY KEY CLUSTERED (TipDoc,Pedido,IdCia,Item),
 CONSTRAINT CK_Trn_ProdPedidoInsuIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_ProdPedidoInsuIdInsumo CHECK ((len([IdInsumo])>(0))),
 CONSTRAINT CK_Trn_ProdPedidoInsuIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_ProdPedidoInsuIdTipProc CHECK ((len([IdTipProc])>(0))),
 CONSTRAINT CK_Trn_ProdPedidoInsuTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_ProdTarf ( 
Tipo VARCHAR(3) DEFAULT ('PRE') NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
FecInicial SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
CdCia CHAR(2) DEFAULT ('00') NOT NULL,
CdLinea VARCHAR(8) DEFAULT ('0') NOT NULL,
CdGrupo VARCHAR(8) DEFAULT ('0') NOT NULL,
CdSubgrupo VARCHAR(8) DEFAULT ('0') NOT NULL,
CdMarca VARCHAR(4) DEFAULT ('0') NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
SimbTfa CHAR(1) DEFAULT ('%') NOT NULL,
LtaPre CHAR(1) DEFAULT ('0') NOT NULL,
CdTarifa VARCHAR(4),
CdClie VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
CdVend VARCHAR(16) DEFAULT ('0') NOT NULL,
CdCiudad VARCHAR(8) DEFAULT ('0') NOT NULL,
CdZona VARCHAR(4) DEFAULT ('0') NOT NULL,
CdSzona VARCHAR(4) DEFAULT ('0') NOT NULL,
CdGruCli VARCHAR(4) DEFAULT ('0') NOT NULL,
OtrosCrit VARCHAR(250),
Anulado BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CodBod VARCHAR(4)
 CONSTRAINT PK_Trn_ProdTarf PRIMARY KEY CLUSTERED (Tipo,Numero),
 CONSTRAINT CK_Trn_ProdTarfCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfCdCia CHECK ((len([CdCia]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfCdClie CHECK ((len([CdClie]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfCdSubgrupo CHECK ((len([CdSubgrupo]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfCdVend CHECK ((len([CdVend]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_ProdTarfSimbTfa CHECK (([SimbTfa] = '$' or [SimbTfa] = '%')),
 CONSTRAINT CK_Trn_ProdTarfTipo CHECK (([Tipo] = 'COM' or [Tipo] = 'PRE')))
CREATE TABLE Trn_Puntos ( 
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,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
PuntFactura DECIMAL(14,4) DEFAULT (0) NOT NULL,
PuntExtra DECIMAL(14,4) DEFAULT (0) NOT NULL,
PuntRedim DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdProgrma INT DEFAULT (0) NOT NULL,
NumTarjeta VARCHAR(20) NOT NULL,
Detalles VARCHAR(50),
Referncia VARCHAR(50)
 CONSTRAINT PK_Trn_Puntos PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_PuntosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_PuntosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_PuntosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_PuntosNumTarjeta CHECK ((len([NumTarjeta]) > 0)),
 CONSTRAINT CK_Trn_PuntosTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_RadicaVales ( 
TipDoc VARCHAR(3) DEFAULT ('VAL') NOT NULL,
nRadica INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
TotalPagos MONEY DEFAULT (0) NOT NULL,
TotalCobros MONEY DEFAULT (0) NOT NULL,
Referencia VARCHAR(50),
CxPagar BIT DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_RadicaVales PRIMARY KEY CLUSTERED (TipDoc,nRadica,IdCia),
 CONSTRAINT CK_Trn_RadicaValesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_RadicaValesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_RecAfavor ( 
TipDoc VARCHAR(3) DEFAULT ('REC') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
VrAFavor MONEY DEFAULT (0) NOT NULL,
VrOtrosDb MONEY DEFAULT (0) NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL
 CONSTRAINT PK_Trn_RecAfavor PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia),
 CONSTRAINT CK_Trn_RecAfavorIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RecAfavorIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RecAfavorIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_RecAfavorIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_RecAfavorTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_RecBuses ( 
TipDoc VARCHAR(3) DEFAULT ('RC1') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('CARTULINA') NOT NULL,
TipCar VARCHAR(3) DEFAULT ('CAR') NOT NULL,
Cartulina INT DEFAULT (0) NOT NULL,
IdCiaCar CHAR(2) DEFAULT ('00') NOT NULL,
IdVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
CentInicial INT DEFAULT (0) NOT NULL,
CentFinal INT DEFAULT (0) NOT NULL,
NPasajeros INT DEFAULT (0) NOT NULL,
Recorridos INT DEFAULT (0) NOT NULL,
ValorRecibido MONEY DEFAULT (0) NOT NULL,
ValorTotal MONEY DEFAULT (0) NOT NULL,
ValorDcto MONEY DEFAULT (0) NOT NULL,
ValorReteFte MONEY DEFAULT (0) NOT NULL,
ValorReteIva MONEY DEFAULT (0) NOT NULL,
ValorReteIca MONEY DEFAULT (0) NOT NULL,
ValorOtros MONEY DEFAULT (0) NOT NULL,
ValorOtrosDct MONEY DEFAULT (0) NOT NULL,
ValorPagMas MONEY DEFAULT (0) NOT NULL,
ValorNeto MONEY DEFAULT (0) NOT NULL,
ValorAplicado MONEY DEFAULT (0) NOT NULL,
ValorAnticipo MONEY DEFAULT (0) NOT NULL,
ValorAbono MONEY DEFAULT (0) NOT NULL,
TotalProducido MONEY DEFAULT (0) NOT NULL,
TotalGastos MONEY DEFAULT (0) NOT NULL,
TotalAhorro MONEY DEFAULT (0) NOT NULL,
TotalOtros MONEY DEFAULT (0) NOT NULL,
TotalVales MONEY DEFAULT (0) NOT NULL,
TotalAbono MONEY DEFAULT (0) NOT NULL,
ValorPasaje MONEY DEFAULT (0) NOT NULL,
IdVendedor VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTarCom VARCHAR(4) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdCta VARCHAR(4) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
NumCheque VARCHAR(20),
IdBanco VARCHAR(4) NOT NULL,
Referencia VARCHAR(20),
BaseIva MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseOtr MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaOtr DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTarIva VARCHAR(4) NOT NULL,
IdTarRet VARCHAR(4) NOT NULL,
IdTarOtr VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
IdRelevador VARCHAR(16) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_RecBuses PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia),
 CONSTRAINT CK_Trn_RecBusesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCiaCar CHECK ((len([IdCiaCar]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdCta CHECK ((len([IdCta]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdRelevador CHECK ((len([IdRelevador]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdTarCom CHECK ((len([IdTarCom]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdTarIva CHECK ((len([IdTarIva]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdTarOtr CHECK ((len([IdTarOtr]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdTarRet CHECK ((len([IdTarRet]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_RecBusesIdVendedor CHECK ((len([IdVendedor]) > 0)),
 CONSTRAINT CK_Trn_RecBusesModalidad CHECK (([Modalidad] = 'OTROS' or ([Modalidad] = 'VC' or [Modalidad] = 'CARTULINA'))),
 CONSTRAINT CK_Trn_RecBusesTipCar CHECK ((len([TipCar]) > 0)),
 CONSTRAINT CK_Trn_RecBusesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_RecBusesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_RecCheques ( 
TipDoc VARCHAR(3) DEFAULT ('CHE') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
PlacaVehic VARCHAR(10),
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_RecCheques PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia),
 CONSTRAINT CK_Trn_RecChequesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RecChequesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RecChequesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_RecChequesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_RecChequesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_RecChequesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_RecChequesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RecChequesOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_RecChequesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_RecChequesTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_RecDvf ( 
TipDoc VARCHAR(3) DEFAULT ('REC') NOT NULL,
Recibo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT NOT NULL,
TipDev VARCHAR(3) DEFAULT ('DFC') NOT NULL,
Devolucion INT DEFAULT ((0)) NOT NULL,
IdCiaDev CHAR(2) DEFAULT ('01') NOT NULL,
VrNetoDev MONEY DEFAULT ((0)),
VrAbono MONEY DEFAULT ((0))
 CONSTRAINT PK_Trn_RecDvf PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_RecDvfIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_RecDvfIdCiaDev CHECK ((len([IdCiaDev])>(0))),
 CONSTRAINT CK_Trn_RecDvfTipDev CHECK ((len([TipDev])>(0))),
 CONSTRAINT CK_Trn_RecDvfTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_RecFactura ( 
TipRec VARCHAR(3) NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
ItemDoc INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdCargo VARCHAR(4) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
ValorAbono MONEY DEFAULT (0) NOT NULL,
Devolucion MONEY DEFAULT (0) NOT NULL,
Descuento MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
VehPropio BIT DEFAULT (0) NOT NULL,
IdVendedor VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
Detalle VARCHAR(100),
FecPago SMALLDATETIME NOT NULL,
AplAntcpo BIT DEFAULT (0) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_RecFactura PRIMARY KEY CLUSTERED (TipRec,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_RecFacturaIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdCargo CHECK ((len([IdCargo]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaIdVendedor CHECK ((len([IdVendedor]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_RecFacturaTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_Recibos ( 
TipDoc VARCHAR(3) DEFAULT ('REC') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
FecPago SMALLDATETIME NOT NULL,
VrRecibido MONEY DEFAULT (0) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteICA MONEY DEFAULT (0) NOT NULL,
VrReteIVA MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrAhorro MONEY DEFAULT (0) NOT NULL,
VrPagosMas MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
VrAplicado MONEY DEFAULT (0) NOT NULL,
VrAnticipo MONEY DEFAULT (0) NOT NULL,
VrEfectivo MONEY DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseRiv MONEY DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaRiv DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarRiv VARCHAR(4),
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdCajero VARCHAR(11) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
IdLocal VARCHAR(8) NOT NULL,
EnEfectivo BIT DEFAULT (0) NOT NULL,
CdForma VARCHAR(4),
NumForma VARCHAR(20),
DetallePago VARCHAR(250),
CdBanco VARCHAR(4) DEFAULT ('0') NOT NULL,
CdCta VARCHAR(4) DEFAULT ('0') NOT NULL,
Referencia VARCHAR(50),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('00') NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('CLIENTES') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
VrDevFact MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Recibos PRIMARY KEY NONCLUSTERED (TipDoc,Recibo,IdCia),
 CONSTRAINT CK_Trn_RecibosCdBanco CHECK ((len([CdBanco]) > 0)),
 CONSTRAINT CK_Trn_RecibosCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_RecibosCdCta CHECK ((len([CdCta]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCajero CHECK ((len([IdCajero]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCiaDcm CHECK ((len([IdCiaDcm]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdLocal CHECK ((len([IdLocal]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RecibosIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_RecibosModalidad CHECK (([Modalidad] = 'OTROS' or [Modalidad] = 'CLIENTES')),
 CONSTRAINT CK_Trn_RecibosOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_RecibosTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_RecibosTipDcm CHECK ((len([TipDcm]) > 0)),
 CONSTRAINT CK_Trn_RecibosTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_RecTanqueos ( 
TipDoc VARCHAR(3) DEFAULT ('REC') NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Documento VARCHAR(10) NOT NULL,
IdTipoCom VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
ValorUnitario MONEY DEFAULT (0) NOT NULL,
IdEstacion VARCHAR(4) NOT NULL
 CONSTRAINT PK_Trn_RecTanqueos PRIMARY KEY CLUSTERED (TipDoc,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_RecTanqueosDocumento CHECK ((len([Documento]) > 0)),
 CONSTRAINT CK_Trn_RecTanqueosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RecTanqueosIdEstacion CHECK ((len([IdEstacion]) > 0)),
 CONSTRAINT CK_Trn_RecTanqueosIdTipoCom CHECK ((len([IdTipoCom]) > 0)),
 CONSTRAINT CK_Trn_RecTanqueosTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_Remision ( 
TipDoc VARCHAR(3) DEFAULT ('REM') NOT NULL,
Remision INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaDesp SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrOtrDcto MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
TarifaCom DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarCom VARCHAR(4),
DirEnvio VARCHAR(250),
IdLocEnv VARCHAR(8) NOT NULL,
DiasEntraga INT DEFAULT (0) NOT NULL,
NitContac VARCHAR(16),
NomContac VARCHAR(150),
TelContac VARCHAR(20),
emlContac VARCHAR(100),
CargoContac VARCHAR(50),
IdForma VARCHAR(4) NOT NULL,
DetallePago VARCHAR(100),
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
NitEmpTrans VARCHAR(16) DEFAULT ('0') NOT NULL,
EmpTrans VARCHAR(150),
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
DetalleEnvio VARCHAR(250),
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('01') NOT NULL,
FechaFact SMALLDATETIME,
TipPed VARCHAR(3) DEFAULT ('PED') NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('01') NOT NULL,
FechaPed SMALLDATETIME,
NumAutoriza INT DEFAULT (0) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('NORMAL') NOT NULL,
NumAprob INT DEFAULT (0) NOT NULL,
FecAprob SMALLDATETIME,
CdUsuAprob VARCHAR(11),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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_Remision PRIMARY KEY CLUSTERED (TipDoc,Remision,IdCia),
 CONSTRAINT CK_Trn_RemisionCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_RemisionCdRuta CHECK ((len([CdRuta]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdCiaFac CHECK ((len([IdCiaFac]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdCiaPed CHECK ((len([IdCiaPed]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdForma CHECK ((len([IdForma]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdLocEnv CHECK ((len([IdLocEnv]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RemisionIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_RemisionModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_RemisionNitEmpTrans CHECK ((len([NitEmpTrans]) > 0)),
 CONSTRAINT CK_Trn_RemisionOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_RemisionTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_RemisionTipFac CHECK ((len([TipFac]) > 0)),
 CONSTRAINT CK_Trn_RemisionTipPed CHECK ((len([TipPed]) > 0)))
CREATE TABLE Trn_ReqDetalle ( 
TipDoc VARCHAR(3) NOT NULL,
Requisicion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
CdProducto VARCHAR(16) DEFAULT ('0') NOT NULL,
Descripcion VARCHAR(250),
IdSubgrupo VARCHAR(8) NOT NULL,
CdBodega VARCHAR(4) DEFAULT ('0') NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('0') NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2) DEFAULT ('00') NOT NULL,
TipSal VARCHAR(3) DEFAULT ('0') NOT NULL,
NSalida INT DEFAULT (0) NOT NULL,
IdCiaSal CHAR(2) DEFAULT ('00') NOT NULL,
FechaSal SMALLDATETIME,
Referencia VARCHAR(250),
CantSalida DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantDevSal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodCCtoDet VARCHAR(16),
CodSCtoDet VARCHAR(16),
PlacaVehDet VARCHAR(10),
Cant_Orden DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_ReqDetalle PRIMARY KEY CLUSTERED (TipDoc,Requisicion,IdCia,Item),
 CONSTRAINT CK_Trn_ReqDetalleCdBodega CHECK ((len([CdBodega]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleCdProducto CHECK ((len([CdProducto]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleIdCiaOrd CHECK ((len([IdCiaOrd]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleIdCiaSal CHECK ((len([IdCiaSal]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleIdSubgrupo CHECK ((len([IdSubgrupo]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleTipOrd CHECK ((len([TipOrd]) > 0)),
 CONSTRAINT CK_Trn_ReqDetalleTipSal CHECK ((len([TipSal]) > 0)))
CREATE TABLE Trn_Requisicion ( 
TipDoc VARCHAR(3) DEFAULT ('REQ') NOT NULL,
Requisicion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdRespons VARCHAR(16) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
IdDep VARCHAR(4) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCont CHAR(2) NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('CONSUMO') NOT NULL,
DirEntrega VARCHAR(250),
IdLocEnt VARCHAR(8) NOT NULL,
TipSal VARCHAR(3) DEFAULT ('0') NOT NULL,
NumSalida INT DEFAULT (0) NOT NULL,
IdCiaSal CHAR(2) DEFAULT ('01') NOT NULL,
FechaSal SMALLDATETIME,
NumAprob INT DEFAULT (0) NOT NULL,
FecAprob SMALLDATETIME,
CdUsuAprob VARCHAR(11),
NomContacto VARCHAR(150),
TelsContacto VARCHAR(50),
EmailContacto VARCHAR(100),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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,
Num_Vehic VARCHAR(10),
Num_Trailer VARCHAR(10),
TipoVigencia VARCHAR(10) DEFAULT ('NORMAL'),
NivelAprob INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Requisicion PRIMARY KEY CLUSTERED (TipDoc,Requisicion,IdCia),
 CONSTRAINT CK_Trn_RequisicionCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdCiaCont CHECK ((len([IdCiaCont]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdCiaSal CHECK ((len([IdCiaSal]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdDep CHECK ((len([IdDep]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdLocEnt CHECK ((len([IdLocEnt]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdRespons CHECK ((len([IdRespons]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_RequisicionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_RequisicionModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_RequisicionNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_RequisicionOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_RequisicionTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_RequisicionTipSal CHECK ((len([TipSal]) > 0)))
CREATE TABLE Trn_SaiArticulos ( 
TipDoc VARCHAR(3) DEFAULT ('SAI') NOT NULL,
Salida INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipEnt VARCHAR(3) DEFAULT ('COM') NOT NULL,
Entrada INT DEFAULT (0) NOT NULL,
IdCiaEnt CHAR(2) DEFAULT ('01') NOT NULL,
ItemEnt INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_SaiArticulos PRIMARY KEY CLUSTERED (TipDoc,Salida,IdCia,Item),
 CONSTRAINT CK_Trn_SaiArticulosIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_SaiArticulosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_SaiArticulosIdCiaEnt CHECK ((len([IdCiaEnt]) > 0)),
 CONSTRAINT CK_Trn_SaiArticulosIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_SaiArticulosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_SaiArticulosTipEnt CHECK ((len([TipEnt]) > 0)))
CREATE TABLE Trn_Salidas ( 
TipDoc VARCHAR(3) DEFAULT ('SAL') NOT NULL,
Salida INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
VrCostos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarIva VARCHAR(4),
TipOrd VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
pVehiculo VARCHAR(10),
CdConductor VARCHAR(16) DEFAULT ('0') NOT NULL,
CdDep VARCHAR(4) DEFAULT ('0') NOT NULL,
NContrato INT DEFAULT (0) NOT NULL,
IdCiaCont CHAR(2) DEFAULT ('00') NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
ModRequis VARCHAR(10) DEFAULT ('0') NOT NULL,
DirEntrega VARCHAR(250),
IdLocEnt VARCHAR(8) DEFAULT ('0') NOT NULL,
GuiaComb INT DEFAULT (0) NOT NULL,
CdCiaGuia CHAR(2),
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
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,
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
NumDotac INT DEFAULT ((0)) NOT NULL,
DiaVigDot INT DEFAULT ((0)) NOT NULL,
FecVigDot SMALLDATETIME,
EdoDocEnt INT DEFAULT ((0)) NOT NULL,
NumDocEnt INT DEFAULT ((0)) NOT NULL,
CiaDocEnt CHAR(2)
 CONSTRAINT PK_Trn_Salidas PRIMARY KEY NONCLUSTERED (TipDoc,Salida,IdCia),
 CONSTRAINT CK_Trn_SalidasCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_SalidasCdConductor CHECK ((len([CdConductor]) > 0)),
 CONSTRAINT CK_Trn_SalidasCdDep CHECK ((len([CdDep]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdCiaOrd CHECK ((len([IdCiaOrd]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdLocEnt CHECK ((len([IdLocEnt]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_SalidasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_SalidasModalidad CHECK (([Modalidad]='REPUESTOS' OR [Modalidad]='INSUMOS' OR [Modalidad]='COMBUSTBLE' OR [Modalidad]='MAYCOMB' OR [Modalidad]='ADITIVO' OR [Modalidad]='INVENTARIO')),
 CONSTRAINT CK_Trn_SalidasModRequis CHECK ((len([ModRequis]) > 0)),
 CONSTRAINT CK_Trn_SalidasNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_Trn_SalidasOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_SalidasTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_SalidasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_SalidasTipOrd CHECK ((len([TipOrd]) > 0)))
CREATE TABLE Trn_Seriales ( 
IdProducto VARCHAR(16) NOT NULL,
NumSerial VARCHAR(30) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
FecEntrada SMALLDATETIME NOT NULL,
FecSalida SMALLDATETIME,
NitProv VARCHAR(16),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
Referncia1 VARCHAR(50),
Referncia2 VARCHAR(50),
FecRef1 SMALLDATETIME,
FecRef2 SMALLDATETIME,
Ubicacion VARCHAR(50),
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_Seriales PRIMARY KEY CLUSTERED (IdProducto,NumSerial,IdCia),
 CONSTRAINT CK_Trn_SerialesIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_SerialesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_SerialesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_SerialesIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_SerialesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_SerialesNumSerial CHECK ((len([NumSerial]) > 0)))
CREATE TABLE Trn_SerMov ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
NumSerial VARCHAR(30) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
CdUbic VARCHAR(10),
Linea INT DEFAULT (0) NOT NULL,
Movimiento VARCHAR(3) DEFAULT ('ENT') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
Observacion VARCHAR(150),
Referencia VARCHAR(50)
 CONSTRAINT PK_Trn_SerMov PRIMARY KEY NONCLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_SerMovIdBodega CHECK ((len([IdBodega]) > 0)),
 CONSTRAINT CK_Trn_SerMovIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_SerMovIdProducto CHECK ((len([IdProducto]) > 0)),
 CONSTRAINT CK_Trn_SerMovMovimiento CHECK (([Movimiento] = 'SAL' or [Movimiento] = 'ENT')),
 CONSTRAINT CK_Trn_SerMovNumSerial CHECK ((len([NumSerial]) > 0)),
 CONSTRAINT CK_Trn_SerMovTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_SobDetalle ( 
IdDec VARCHAR(4) NOT NULL,
NumDeclara INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Concepto VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrLiquida MONEY DEFAULT (0) NOT NULL,
VrPrecio MONEY DEFAULT (0) NOT NULL,
ClaseProd VARCHAR(20),
TarifGalon DECIMAL(14,4) DEFAULT (0) NOT NULL,
PorcBase DECIMAL(14,4) DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_SobDetalle PRIMARY KEY CLUSTERED (IdDec,NumDeclara,Item),
 CONSTRAINT CK_Trn_SobDetalleConcepto CHECK ((len([Concepto]) > 0)),
 CONSTRAINT CK_Trn_SobDetalleIdDec CHECK ((len([IdDec]) > 0)))
CREATE TABLE Trn_Sobretasas ( 
IdDec VARCHAR(4) NOT NULL,
NumDeclara INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
nAnno INT DEFAULT (0) NOT NULL,
nMes INT DEFAULT (0) NOT NULL,
IdEnterr VARCHAR(8) NOT NULL,
TipoEntidad VARCHAR(10) NOT NULL,
VrSobretasa MONEY DEFAULT (0) NOT NULL,
VrSanciones MONEY DEFAULT (0) NOT NULL,
VrCompensa MONEY DEFAULT (0) NOT NULL,
VrIntMora MONEY DEFAULT (0) NOT NULL,
VrTotalPagar MONEY DEFAULT (0) NOT NULL,
VrFondoSubs MONEY DEFAULT (0) NOT NULL,
VrRecaudoDep MONEY DEFAULT (0) NOT NULL,
NitDeclara VARCHAR(16) NOT NULL,
DvDeclara CHAR(1),
CedDeclara VARCHAR(16) NOT NULL,
Declarante VARCHAR(250),
DirEntidad VARCHAR(250),
EmailEnt VARCHAR(100),
NomRepres VARCHAR(150),
CargoRepres VARCHAR(50),
TipoFirma INT DEFAULT (0) NOT NULL,
NitRevisor VARCHAR(16),
NomRevisor VARCHAR(150),
TpRevisor VARCHAR(20),
NumCheque VARCHAR(30),
CodBanco VARCHAR(4),
IdClase VARCHAR(4) NOT NULL,
NumCuenta VARCHAR(30),
IdBanco VARCHAR(4) NOT NULL,
CdLocCue VARCHAR(8),
TitularCuenta VARCHAR(150),
VrEfectivo MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrTransf MONEY DEFAULT (0) NOT NULL,
VrPagado MONEY DEFAULT (0) NOT NULL,
Estado INT DEFAULT (0) NOT NULL,
Adhesivo VARCHAR(30),
FechaPago SMALLDATETIME,
EsCorr BIT DEFAULT (0) NOT NULL,
NumCorr VARCHAR(30),
FecCorr SMALLDATETIME,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
CodCta VARCHAR(4),
TipEgreso VARCHAR(3),
NumEgreso INT DEFAULT (0),
CiaEgreso CHAR(2)
 CONSTRAINT PK_Trn_Sobretasas PRIMARY KEY CLUSTERED (IdDec,NumDeclara),
 CONSTRAINT CK_Trn_SobretasasCedDeclara CHECK ((len([CedDeclara]) > 0)),
 CONSTRAINT CK_Trn_SobretasasIdBanco CHECK ((len([IdBanco]) > 0)),
 CONSTRAINT CK_Trn_SobretasasIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Trn_SobretasasIdDec CHECK ((len([IdDec]) > 0)),
 CONSTRAINT CK_Trn_SobretasasIdEnterr CHECK ((len([IdEnterr]) > 0)),
 CONSTRAINT CK_Trn_SobretasasIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_SobretasasnAnno CHECK (([nAnno] >= 1990 and [nAnno] <= 2050)),
 CONSTRAINT CK_Trn_SobretasasNitDeclara CHECK ((len([NitDeclara]) > 0)),
 CONSTRAINT CK_Trn_SobretasasnMes CHECK (([nMes] >= 0 and [nMes] <= 12)),
 CONSTRAINT CK_Trn_SobretasasTipoEntidad CHECK ((len([TipoEntidad]) > 0)))
CREATE TABLE Trn_Tallajes ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdCia CHAR(2) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Pedidos DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_Tallajes PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_TallajesIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_TallajesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TallajesIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_TallajesIdUbic CHECK ((len([IdUbic])>(0))),
 CONSTRAINT CK_Trn_TallajesNumTalla CHECK ((len([NumTalla])>(0))))
CREATE TABLE Trn_TallasMov ( 
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,
ItemKdx INT DEFAULT ((0)) NOT NULL,
IdProducto VARCHAR(16) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdUbic VARCHAR(10) NOT NULL,
NumTalla VARCHAR(30) NOT NULL,
Entradas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Salidas DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantPedido DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantRem DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantFactura DECIMAL(14,4) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TallasMov PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_TallasMovIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_TallasMovIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TallasMovIdProducto CHECK ((len([IdProducto])>(0))),
 CONSTRAINT CK_Trn_TallasMovIdUbic CHECK ((len([IdUbic])>(0))),
 CONSTRAINT CK_Trn_TallasMovNumTalla CHECK ((len([NumTalla])>(0))),
 CONSTRAINT CK_Trn_TallasMovTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_tasas ( 
IdMneda VARCHAR(5) NOT NULL,
IdMnedaD VARCHAR(5) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TasaDia DECIMAL(14,6) DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_tasas PRIMARY KEY CLUSTERED (IdMneda,IdMnedaD,Fecha),
 CONSTRAINT CK_Trn_tasasIdMneda CHECK ((len([IdMneda]) > 0)),
 CONSTRAINT CK_Trn_tasasIdMnedaD CHECK ((len([IdMnedaD]) > 0)))
CREATE TABLE Trn_TasasDia ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdTasa VARCHAR(4) NOT NULL,
Valor DECIMAL(16,6) DEFAULT ((0)) NOT NULL,
Unidad VARCHAR(50) NOT NULL,
UM_tasa VARCHAR(10) DEFAULT ('br')
 CONSTRAINT PK_Trn_TasasDia PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_TasasDiaIdTasa CHECK ((len([IdTasa])>(0))),
 CONSTRAINT CK_Trn_TasasDiaUnidad CHECK ((len([Unidad])>(0))))
CREATE TABLE Trn_TasasOro ( 
Fecha SMALLDATETIME NOT NULL,
Quilate INT DEFAULT ((0)) NOT NULL,
VrGramo DECIMAL(16,6) DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TasasOro PRIMARY KEY CLUSTERED (Fecha,Quilate))
CREATE TABLE Trn_TraAntAbonos ( 
TipDoc VARCHAR(3) DEFAULT ('ODP') 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 ('ANT') 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,
Detalle VARCHAR(100),
CdCuentaAnt VARCHAR(16)
 CONSTRAINT PK_Trn_TraAntAbonos PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_TraAntAbonosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraAntAbonosIdCiaAnt CHECK ((len([IdCiaAnt]) > 0)),
 CONSTRAINT CK_Trn_TraAntAbonosTipAnt CHECK ((len([TipAnt]) > 0)),
 CONSTRAINT CK_Trn_TraAntAbonosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraAntAbonosTipoAplica CHECK ((len([TipoAplica]) > 0)))
CREATE TABLE Trn_TraAnticipos ( 
TipDoc VARCHAR(3) DEFAULT ('ANT') NOT NULL,
Anticipo INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrAbonado MONEY DEFAULT ((0)) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('EGRESO') 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),
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
FechaVence SMALLDATETIME,
NumPresAnt INT DEFAULT ((0)) NOT NULL,
PreAnticipo INT DEFAULT ((0)) NOT NULL,
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,
NumCargue INT DEFAULT ((0)) NOT NULL,
CiaCargue CHAR(2) DEFAULT ('00'),
VrDeduccion MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraAnticipos PRIMARY KEY CLUSTERED (TipDoc,Anticipo,IdCia),
 CONSTRAINT CK_Trn_TraAnticiposIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdCiaMuc CHECK ((len([IdCiaMuc])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdCta CHECK ((len([IdCta])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdCuenta CHECK ((len([IdCuenta])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposModalidad CHECK (([Modalidad]='C_ENTREGA' OR ([Modalidad]='EGRESO' OR [Modalidad]='COMBUSTBLE'))),
 CONSTRAINT CK_Trn_TraAnticiposOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposTipMuc CHECK ((len([TipMuc])>(0))),
 CONSTRAINT CK_Trn_TraAnticiposTipoPago CHECK (([TipoPago]='CREDITO' OR ([TipoPago]='GALONES' OR ([TipoPago]='TRANS' OR ([TipoPago]='CHEQUE' OR [TipoPago]='EFECTIVO'))))))
CREATE TABLE Trn_TraCauDetalle ( 
TipDoc VARCHAR(3) DEFAULT ('CCD') NOT NULL,
Causacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
TipoConc VARCHAR(10) DEFAULT ('CTACOBRAR') NOT NULL,
VrDebito MONEY DEFAULT ((0)) NOT NULL,
VrCredito MONEY DEFAULT ((0)) NOT NULL,
CdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
pVehiculo VARCHAR(10),
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
VrBase MONEY DEFAULT ((0)) NOT NULL,
TarifBase DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Referencia VARCHAR(50),
TipDocRef VARCHAR(3),
DocRef INT DEFAULT ((0)) NOT NULL,
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT ((0)) NOT NULL,
FecVence SMALLDATETIME NOT NULL,
EstadoReg INT DEFAULT ((0)) NOT NULL,
TipoLiq VARCHAR(3),
NumLiquida INT DEFAULT ((0)) NOT NULL,
CiaLiquida CHAR(2),
VrAbonado MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraCauDetalle PRIMARY KEY CLUSTERED (TipDoc,Causacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraCauDetalleCdCuenta CHECK ((len([CdCuenta])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleDescripcion CHECK ((len([Descripcion])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleNitTercero CHECK ((len([NitTercero])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))),
 CONSTRAINT CK_Trn_TraCauDetalleTipoConc CHECK ((len([TipoConc])>(0))))
CREATE TABLE Trn_TraCausacion ( 
TipDoc VARCHAR(3) DEFAULT ('CCD') NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdProv VARCHAR(16) NOT NULL,
Factura VARCHAR(20) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
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_TraCausacion PRIMARY KEY CLUSTERED (TipDoc,Causacion,IdCia),
 CONSTRAINT CK_Trn_TraCausacionFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraCausacionTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraConceptos ( 
TipDoc VARCHAR(3) NOT NULL,
Documento INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Tarifa DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoConc VARCHAR(10) DEFAULT ('DEDUCCION') NOT NULL,
RubroConcep VARCHAR(20) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
TarifIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
CdCuenta VARCHAR(16) DEFAULT ('0') NOT NULL,
NitTercero VARCHAR(16) DEFAULT ('0'),
CdTipoEsc VARCHAR(4),
FechaNov SMALLDATETIME,
VrBase MONEY DEFAULT (0) NOT NULL,
TipoTarif CHAR(1) DEFAULT ('$') NOT NULL,
RefConc VARCHAR(50),
Fijos BIT DEFAULT (0) NOT NULL,
IncBaseRet INT DEFAULT ((0)) NOT NULL,
Referencia2 VARCHAR(50),
Referencia3 VARCHAR(50)
 CONSTRAINT PK_Trn_TraConceptos PRIMARY KEY CLUSTERED (TipDoc,Documento,IdCia,Item),
 CONSTRAINT CK_Trn_TraConceptosCdCuenta CHECK ((len([CdCuenta]) > 0)),
 CONSTRAINT CK_Trn_TraConceptosDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Trn_TraConceptosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraConceptosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraConceptosRubroConcep CHECK ((len([RubroConcep]) > 0)),
 CONSTRAINT CK_Trn_TraConceptosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraConceptosTipoConc CHECK ((len([TipoConc]) > 0)))
CREATE TABLE Trn_TraCumplido ( 
TipDoc VARCHAR(3) DEFAULT ('CUM') NOT NULL,
Cumplido INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
DiasPlazo INT DEFAULT ((0)) NOT NULL,
FecPago SMALLDATETIME NOT NULL,
TipoMargen VARCHAR(10) DEFAULT ('UNIDAD') NOT NULL,
MargenFalt DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
UndCalcFalt VARCHAR(10) DEFAULT ('PESO'),
TarifFaltPago MONEY DEFAULT ((0)) NOT NULL,
TarifFaltCobro MONEY DEFAULT ((0)) NOT NULL,
NRadicaDoc INT DEFAULT ((0)) NOT NULL,
IdCiaRadic CHAR(2),
CdCiaOfic CHAR(2),
FecRadic SMALLDATETIME,
CdRuta VARCHAR(4),
CdOrigen VARCHAR(8),
CdDestino VARCHAR(8),
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
TipoComp VARCHAR(3),
NumComp INT DEFAULT ((0)) NOT NULL,
CodConcepto VARCHAR(4),
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,
TipoCumpMT VARCHAR(3),
MotivoSusp VARCHAR(3),
ConsecSusp VARCHAR(3),
VrAdicCargue DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
VrAdicDescargue DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
VrAdicFlete DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
MotivoVrAdic VARCHAR(3),
VrDctoFlete DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
MotivoVrDcto VARCHAR(3),
VrAdicAnticipo DECIMAL(16,4) DEFAULT ((0)) NOT NULL,
FecEntregaDoc SMALLDATETIME,
NumRadicaMT DECIMAL(14,2) DEFAULT ((0)) NOT NULL,
MvoAnulaCump VARCHAR(5),
ObservAnulado VARCHAR(250),
NumViajesCum INT DEFAULT ((0)),
PesoLiqPago INT DEFAULT ((0)) NOT NULL,
PesoLiqFact INT DEFAULT ((0)) NOT NULL,
CdPlazoPago VARCHAR(4)
 CONSTRAINT PK_Trn_TraCumplido PRIMARY KEY CLUSTERED (TipDoc,Cumplido,IdCia),
 CONSTRAINT CK_Trn_TraCumplidoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoIdCiaMuc CHECK ((len([IdCiaMuc])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoModalidad CHECK (([Modalidad]='PARCIAL' OR [Modalidad]='TOTAL')),
 CONSTRAINT CK_Trn_TraCumplidoOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoTipMuc CHECK ((len([TipMuc])>(0))),
 CONSTRAINT CK_Trn_TraCumplidoTipoMargen CHECK ((len([TipoMargen])>(0))))
CREATE TABLE Trn_TraCumRadDoc ( 
NumRadica INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NitCliente VARCHAR(16) NOT NULL,
ItemDoc INT DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(250),
Radicado BIT DEFAULT ((0)) NOT NULL,
Referencia VARCHAR(50),
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraCumRadDoc PRIMARY KEY CLUSTERED (NumRadica,IdCia,Item),
 CONSTRAINT CK_Trn_TraCumRadDocIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraCumRadDocIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraCumRadDocNitCliente CHECK ((len([NitCliente])>(0))))
CREATE TABLE Trn_TraCumRadica ( 
NumRadica INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
CdCiaRad CHAR(2) DEFAULT ('01') NOT NULL,
DocAnexos VARCHAR(1000),
CantDoc INT DEFAULT (0) NOT NULL,
FormaEnvio VARCHAR(50),
NomRadica VARCHAR(150),
CedRadica VARCHAR(16),
Funcionario VARCHAR(150),
Observacion VARCHAR(2000),
NumeroCum INT DEFAULT (0) NOT NULL,
IdCiaCum CHAR(2) DEFAULT ('00') NOT NULL,
FechaCum SMALLDATETIME,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraCumRadica PRIMARY KEY CLUSTERED (NumRadica,IdCia),
 CONSTRAINT CK_Trn_TraCumRadicaCdCiaRad CHECK ((len([CdCiaRad]) > 0)),
 CONSTRAINT CK_Trn_TraCumRadicaIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraCumRadicaIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraCumRadicaIdCiaCum CHECK ((len([IdCiaCum]) > 0)),
 CONSTRAINT CK_Trn_TraCumRadicaIdCiaMuc CHECK ((len([IdCiaMuc]) > 0)),
 CONSTRAINT CK_Trn_TraCumRadicaIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraCumRadicaTipMuc CHECK ((len([TipMuc]) > 0)))
CREATE TABLE Trn_TraCumRemesas ( 
TipDoc VARCHAR(3) DEFAULT ('CUM') NOT NULL,
Cumplido 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,
ItemRem INT DEFAULT (0) NOT NULL,
Cantidad 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,
Cases INT DEFAULT (0) NOT NULL,
Cajas INT DEFAULT (0) NOT NULL,
Palets INT DEFAULT (0) NOT NULL,
TarifClie MONEY DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
UndTarifClie VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndTarifPago VARCHAR(10) DEFAULT ('PESO') NOT NULL,
CantCargue DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoCargue DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolCargue DECIMAL(14,4) DEFAULT (0) NOT NULL,
CasesCargue INT DEFAULT (0) NOT NULL,
CajasCargue INT DEFAULT (0) NOT NULL,
PaletsCargue INT DEFAULT (0) NOT NULL,
EstadoCump INT DEFAULT (1) NOT NULL,
Remision DECIMAL(18,2) DEFAULT (0) NOT NULL,
DocCliente VARCHAR(30),
Referencia1 VARCHAR(50),
Referencia2 VARCHAR(50),
Referencia3 VARCHAR(50),
Detalle VARCHAR(250),
TarifFlete MONEY DEFAULT ((0)) NOT NULL,
TipoCumRemesa VARCHAR(3),
MotivoSuspRem VARCHAR(3),
HoraLlegaCargue SMALLDATETIME,
HoraEntraCargue SMALLDATETIME,
HoraSaleCargue SMALLDATETIME,
HoraLlegaDescargue SMALLDATETIME,
HoraEntraDescargue SMALLDATETIME,
HoraSaleDescargue SMALLDATETIME,
CodCCosto VARCHAR(16),
CodSubCos VARCHAR(16),
NitClieRem VARCHAR(16)
 CONSTRAINT PK_Trn_TraCumRemesas PRIMARY KEY CLUSTERED (TipDoc,Cumplido,IdCia,Item),
 CONSTRAINT CK_Trn_TraCumRemesasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasTipRem CHECK ((len([TipRem]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasUndTarifClie CHECK ((len([UndTarifClie]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasUndTarifPago CHECK ((len([UndTarifPago]) > 0)),
 CONSTRAINT CK_Trn_TraCumRemesasUndVol CHECK ((len([UndVol]) > 0)))
CREATE TABLE Trn_TraDecAduana ( 
TipDoc VARCHAR(3) DEFAULT ('DTA') NOT NULL,
NumDeclara INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdAduCarga VARCHAR(4) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdAduOrigen VARCHAR(4) NOT NULL,
IdAduDestino VARCHAR(4) NOT NULL,
IdAduFrontera VARCHAR(4),
IdDeclarante VARCHAR(16) NOT NULL,
Declarante VARCHAR(150) NOT NULL,
DirDeclara VARCHAR(250),
CdLocalDec VARCHAR(8),
IdRemitente VARCHAR(16) NOT NULL,
Remitente VARCHAR(150) NOT NULL,
DirOrigen VARCHAR(250),
CdLocalRem VARCHAR(8),
IdDestinatario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(150) NOT NULL,
DirDestino VARCHAR(250),
CdLocalDest VARCHAR(8),
IdConsig VARCHAR(16) NOT NULL,
Consignatario VARCHAR(150),
DirConsig VARCHAR(250),
CdLocalConsig VARCHAR(8),
IdMoneda VARCHAR(5) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
DocAnexos VARCHAR(500),
Vehiculos VARCHAR(250),
Remolques VARCHAR(250),
Manifiestos VARCHAR(100),
Contenedores VARCHAR(500),
Precintos VARCHAR(250),
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,
Negociacion VARCHAR(1000),
CondicPago VARCHAR(1000)
 CONSTRAINT PK_Trn_TraDecAduana PRIMARY KEY CLUSTERED (TipDoc,NumDeclara,IdCia),
 CONSTRAINT CK_Trn_TraDecAduanaDeclarante CHECK ((len([Declarante])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaDestinatario CHECK ((len([Destinatario])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdAduCarga CHECK ((len([IdAduCarga])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdAduDestino CHECK ((len([IdAduDestino])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdAduOrigen CHECK ((len([IdAduOrigen])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdConsig CHECK ((len([IdConsig])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdDeclarante CHECK ((len([IdDeclarante])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdDestinatario CHECK ((len([IdDestinatario])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdRemitente CHECK ((len([IdRemitente])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaRemitente CHECK ((len([Remitente])>(0))),
 CONSTRAINT CK_Trn_TraDecAduanaTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraDecMcia ( 
TipDoc VARCHAR(3) NOT NULL,
NumDeclara INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2) NOT NULL,
CdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorMcia MONEY DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
UndVol VARCHAR(10),
Bultos VARCHAR(150),
DescripUnid VARCHAR(500)
 CONSTRAINT PK_Trn_TraDecMcia PRIMARY KEY CLUSTERED (TipDoc,NumDeclara,IdCia,Item),
 CONSTRAINT CK_Trn_TraDecMciaCdMercancia CHECK ((len([CdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaDescripMcias CHECK ((len([DescripMcias])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdCiaOrd CHECK ((len([IdCiaOrd])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdEmp CHECK ((len([IdEmp])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdNat CHECK ((len([IdNat])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaTipOrd CHECK ((len([TipOrd])>(0))),
 CONSTRAINT CK_Trn_TraDecMciaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_TraDespachos ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecCargue SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
NitRemite VARCHAR(16) NOT NULL,
Remitente VARCHAR(250) NOT NULL,
NitDestntario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(250) DEFAULT ('varios') NOT NULL,
DescMcia VARCHAR(150),
PesoTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2) DEFAULT ('00') NOT NULL,
Remesa INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
Estado INT DEFAULT (0) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraDespachos PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia),
 CONSTRAINT CK_Trn_TraDespachosDestinatario CHECK ((len([Destinatario]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdCiaOrd CHECK ((len([IdCiaOrd]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdDestino CHECK ((len([IdDestino]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdOrigen CHECK ((len([IdOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosNitDestntario CHECK ((len([NitDestntario]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosNitRemite CHECK ((len([NitRemite]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosRemitente CHECK ((len([Remitente]) > 0)),
 CONSTRAINT CK_Trn_TraDespachosTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraDespProgram ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
CdRuta VARCHAR(4) NOT NULL,
IdPunto INT DEFAULT (0) NOT NULL,
HoraProg SMALLDATETIME NOT NULL,
TipoProg INT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
ObservProg VARCHAR(250)
 CONSTRAINT PK_Trn_TraDespProgram PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraDespProgramCdRuta CHECK ((len([CdRuta]) > 0)),
 CONSTRAINT CK_Trn_TraDespProgramIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDespProgramIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDespProgramTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraDevAnt ( 
TipDev VARCHAR(3) DEFAULT ('DVA') 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 ('ANT') NOT NULL,
Anticipo INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) 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_TraDevAnt PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevAntCdCta CHECK ((len([CdCta]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntCdCuenta CHECK ((len([CdCuenta]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntModdDev CHECK ((len([ModdDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevAntTipDoc CHECK ((len([TipDoc]) > 0)))
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))))
CREATE TABLE Trn_TraDevCau ( 
TipDev VARCHAR(3) DEFAULT ('DCC') 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 ('CCD') NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdProv VARCHAR(16) NOT NULL,
Factura VARCHAR(20) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
VrOtros MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) 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_TraDevCau PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevCauFactura CHECK ((len([Factura]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdProv CHECK ((len([IdProv]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_TraDevCauOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevCauTipDoc CHECK ((len([TipDoc]) > 0)))
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))))
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))))
CREATE TABLE Trn_TraDevLeg ( 
TipDev VARCHAR(3) DEFAULT ('DLG') 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 ('LGA') NOT NULL,
Liquidacion INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('PROPIOS') NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
NitEmpresa VARCHAR(16),
VrAnticipos MONEY DEFAULT (0) NOT NULL,
VrGastos MONEY DEFAULT (0) NOT NULL,
VrCombustible MONEY DEFAULT (0) NOT NULL,
VrDiferencia MONEY DEFAULT (0) NOT NULL,
VrOtrosCred MONEY DEFAULT (0) NOT NULL,
galsComb DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT (0) 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_TraDevLeg PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevLegIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdCiaMuc CHECK ((len([IdCiaMuc]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegModdDev CHECK ((len([ModdDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevLegTipMuc CHECK ((len([TipMuc]) > 0)))
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))))
CREATE TABLE Trn_TraDevLiq ( 
TipDev VARCHAR(3) DEFAULT ('DLQ') 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 ('LIQ') NOT NULL,
Liquidacion INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VrTotal MONEY DEFAULT (0) 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_TraDevLiq PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevLiqIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqModdDev CHECK ((len([ModdDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevLiqTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraDevOdp ( 
TipDev VARCHAR(3) DEFAULT ('DOP') 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 ('ODP') NOT NULL,
OrdPago INT DEFAULT (0) NOT NULL,
IdCiaDoc CHAR(2) DEFAULT ('01') NOT NULL,
FecDoc SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
ModdDev VARCHAR(10) DEFAULT ('TOTAL') 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,
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_TraDevOdp PRIMARY KEY CLUSTERED (TipDev,Devolucion,IdCia),
 CONSTRAINT CK_Trn_TraDevOdpIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdCiaDoc CHECK ((len([IdCiaDoc]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpModdDev CHECK (([ModdDev] = 'PARCIAL' or [ModdDev] = 'TOTAL')),
 CONSTRAINT CK_Trn_TraDevOdpOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpTipDev CHECK ((len([TipDev]) > 0)),
 CONSTRAINT CK_Trn_TraDevOdpTipDoc CHECK ((len([TipDoc]) > 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)))
CREATE TABLE Trn_TraEgrOrden ( 
TipCom VARCHAR(3) NOT NULL,
NumEgreso INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipOdp VARCHAR(3) DEFAULT ('ODP') NOT NULL,
OrdPago INT DEFAULT (0) NOT NULL,
IdCiaOdp CHAR(2) DEFAULT ('01') NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Trn_TraEgrOrden PRIMARY KEY CLUSTERED (TipCom,NumEgreso,IdCia,Item),
 CONSTRAINT CK_Trn_TraEgrOrdenIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraEgrOrdenIdCiaOdp CHECK ((len([IdCiaOdp]) > 0)),
 CONSTRAINT CK_Trn_TraEgrOrdenTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraEgrOrdenTipOdp CHECK ((len([TipOdp]) > 0)))
CREATE TABLE Trn_TraFacRemesas ( 
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoReg INT DEFAULT (0) NOT NULL,
FechaFact SMALLDATETIME NOT NULL,
TipRem VARCHAR(3) DEFAULT ('RMT') NOT NULL,
Remesa INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
ItemRem INT DEFAULT (0) NOT NULL,
FecRemesa SMALLDATETIME NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrCosto MONEY DEFAULT (0) NOT NULL,
UndTarifa VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndCosto VARCHAR(10) DEFAULT ('PESO') 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,
Cases INT DEFAULT (0) NOT NULL,
Cajas INT DEFAULT (0) NOT NULL,
Palets INT DEFAULT (0) NOT NULL,
TarifaIva DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrImpuesto MONEY DEFAULT (0) NOT NULL,
TarifaDct DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrReteIca MONEY DEFAULT (0) NOT NULL,
VrFaltante MONEY DEFAULT (0) NOT NULL,
Remision DECIMAL(18,2) DEFAULT (0) NOT NULL,
DocCliente VARCHAR(30) NOT NULL,
Referencia1 VARCHAR(50),
Referencia2 VARCHAR(50),
Referencia3 VARCHAR(50),
CdMercancia VARCHAR(16) DEFAULT ('0') NOT NULL,
CdConcepto VARCHAR(4) NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
NitTercero VARCHAR(16) DEFAULT ('0') NOT NULL,
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
pVehiculo VARCHAR(10) DEFAULT ('0') NOT NULL,
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
Anulado INT DEFAULT (0) NOT NULL,
TipDocRef VARCHAR(3),
NumDocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('01'),
FecDocRef SMALLDATETIME,
CantidadFalt DECIMAL(14,4) DEFAULT (0) NOT NULL,
UnidadFalt VARCHAR(10),
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
CodTarDct VARCHAR(4),
NumPedRem INT DEFAULT (0) NOT NULL,
CiaPedRem CHAR(2) DEFAULT ('00'),
VrDeclMcia MONEY DEFAULT ((0)) NOT NULL,
TarifaSeg DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrSeguroRem MONEY DEFAULT ((0)) NOT NULL,
NitAsegurad VARCHAR(16),
CantPago DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrAutRetIca MONEY DEFAULT ((0)) NOT NULL,
RemTransb INT DEFAULT ((0)) NOT NULL,
CostoAdicTbdo MONEY DEFAULT ((0)) NOT NULL,
NitMucTbdo VARCHAR(16)
 CONSTRAINT PK_Trn_TraFacRemesas PRIMARY KEY CLUSTERED (TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_TraFacRemesasCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasCdConcepto CHECK ((len([CdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasCdMercancia CHECK ((len([CdMercancia]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasDocCliente CHECK ((len([DocCliente]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasIdDestino CHECK ((len([IdDestino]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasIdOrigen CHECK ((len([IdOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasNitTercero CHECK ((len([NitTercero]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesaspVehiculo CHECK ((len([pVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasTipoAfiVehic CHECK ((len([TipoAfiVehic]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasTipRem CHECK ((len([TipRem]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasUndCosto CHECK ((len([UndCosto]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasUndTarifa CHECK ((len([UndTarifa]) > 0)),
 CONSTRAINT CK_Trn_TraFacRemesasUndVol CHECK ((len([UndVol]) > 0)))
CREATE TABLE Trn_TraInfViajes ( 
TipDoc VARCHAR(3) DEFAULT ('OCV') NOT NULL,
NumViaje INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdRuta VARCHAR(4) 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,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumManif INT DEFAULT ((0)) NOT NULL,
IdCiaManif CHAR(2) DEFAULT ('00') NOT NULL,
NumMintrans DECIMAL(14,2) DEFAULT ((0)) NOT NULL,
MvoAnulacion VARCHAR(5),
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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_TraInfViajes PRIMARY KEY CLUSTERED (TipDoc,NumViaje,IdCia),
 CONSTRAINT CK_Trn_TraInfViajesIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdCiaManif CHECK ((len([IdCiaManif])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdRuta CHECK ((len([IdRuta])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))))
CREATE TABLE Trn_TraInfViajesOrd ( 
TipDoc VARCHAR(3) DEFAULT ('OCV') NOT NULL,
NumViaje INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOrden VARCHAR(3) DEFAULT ('OCT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2) DEFAULT ('01') NOT NULL,
ItemOrd INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraInfViajesOrd PRIMARY KEY CLUSTERED (TipDoc,NumViaje,IdCia,Item),
 CONSTRAINT CK_Trn_TraInfViajesOrdIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesOrdIdCiaOrd CHECK ((len([IdCiaOrd])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesOrdTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraInfViajesOrdTipOrden CHECK ((len([TipOrden])>(0))))
CREATE TABLE Trn_TraLiqDetalle ( 
TipDoc VARCHAR(3) DEFAULT ('LGA') NOT NULL,
Liquidacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
DescConcepto VARCHAR(250) NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
VrDebito MONEY DEFAULT (0) NOT NULL,
VrCredito MONEY DEFAULT (0) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
CodAgncia VARCHAR(16),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16),
pVehiculo VARCHAR(10),
RubroConc VARCHAR(10) DEFAULT ('GASTO') NOT NULL,
VrBase MONEY DEFAULT (0) NOT NULL,
TarifBase DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantComb DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipFac VARCHAR(3),
Factura VARCHAR(15),
IdCiaFac CHAR(2) DEFAULT ('01'),
ItemFac INT DEFAULT (0) NOT NULL,
FecVence SMALLDATETIME,
RefConcep VARCHAR(50),
TipSop VARCHAR(3),
NumSoporte INT DEFAULT ((0)) NOT NULL,
IdCiaSop CHAR(2),
DocSop BIT DEFAULT ((0)) NOT NULL,
TipoImp VARCHAR(4),
CodTarImp VARCHAR(4),
ItemBase INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraLiqDetalle PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraLiqDetalleDescConcepto CHECK ((len([DescConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraLiqDetalleIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraLiqDetalleIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraLiqDetalleIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_TraLiqDetalleIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_TraLiqDetalleRubroConc CHECK ((len([RubroConc]) > 0)),
 CONSTRAINT CK_Trn_TraLiqDetalleTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraLiqManif ( 
TipDoc VARCHAR(3) DEFAULT ('LGA') NOT NULL,
Liquidacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL
 CONSTRAINT PK_Trn_TraLiqManif PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraLiqManifIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraLiqManifIdCiaMuc CHECK ((len([IdCiaMuc])>(0))),
 CONSTRAINT CK_Trn_TraLiqManifTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraLiqManifTipMuc CHECK ((len([TipMuc])>(0))))
CREATE TABLE Trn_TraLiquida ( 
TipDoc VARCHAR(3) DEFAULT ('LIQ') NOT NULL,
Liquidacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
VrTotal MONEY DEFAULT ((0)) NOT NULL,
CxPagar BIT DEFAULT ((0)) NOT NULL,
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,
FecIniCau SMALLDATETIME,
FecFinCau SMALLDATETIME,
FecIniOdp SMALLDATETIME,
FecFinOdp SMALLDATETIME,
ModLiquida VARCHAR(10) DEFAULT ('TERCERO'),
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_TraLiquida PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia),
 CONSTRAINT CK_Trn_TraLiquidaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraLiquidaDed ( 
TipDoc VARCHAR(3) DEFAULT ('LIQ') NOT NULL,
Liquidacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipCau VARCHAR(3) DEFAULT ('CCD') NOT NULL,
Causacion INT DEFAULT (0) NOT NULL,
IdCiaCau CHAR(2) DEFAULT ('01') NOT NULL,
ItemCau INT DEFAULT (0) NOT NULL,
FechaCau SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
NitPoseedor VARCHAR(16) DEFAULT ('0') NOT NULL,
pVehiculo VARCHAR(10),
EsVence BIT DEFAULT (0) NOT NULL,
TipOdp VARCHAR(3) DEFAULT ('ODP'),
OrdenPago INT DEFAULT (0) NOT NULL,
IdCiaOdp CHAR(2),
TipMuc VARCHAR(3) DEFAULT ('MUC'),
Manifiesto INT DEFAULT (0) NOT NULL,
IdCiaMuc CHAR(2),
VrSaldoOrden MONEY DEFAULT (0) NOT NULL,
CdCuenta VARCHAR(16),
CdCuePagar VARCHAR(16),
NumFactura VARCHAR(20),
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16)
 CONSTRAINT PK_Trn_TraLiquidaDed PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraLiquidaDedDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Trn_TraLiquidaDedIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraLiquidaDedIdCiaCau CHECK ((len([IdCiaCau]) > 0)),
 CONSTRAINT CK_Trn_TraLiquidaDedIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraLiquidaDedNitPoseedor CHECK ((len([NitPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraLiquidaDedTipCau CHECK ((len([TipCau]) > 0)),
 CONSTRAINT CK_Trn_TraLiquidaDedTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraLiquidaOdp ( 
TipDoc VARCHAR(3) DEFAULT ('LIQ') NOT NULL,
Liquidacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOdp VARCHAR(3) DEFAULT ('ODP') NOT NULL,
OrdPago INT DEFAULT ((0)) NOT NULL,
IdCiaOdp CHAR(2) DEFAULT ('01') NOT NULL,
VrAbonado MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraLiquidaOdp PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraLiquidaOdpIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOdpIdCiaOdp CHECK ((len([IdCiaOdp])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOdpTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOdpTipOdp CHECK ((len([TipOdp])>(0))))
CREATE TABLE Trn_TraLiquidaOtr ( 
TipDoc VARCHAR(3) DEFAULT ('LIQ') NOT NULL,
Liquidacion INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipCau VARCHAR(3) DEFAULT ('CCD') NOT NULL,
Causacion INT DEFAULT ((0)) NOT NULL,
IdCiaCau CHAR(2) DEFAULT ('01') NOT NULL,
ItemCau INT DEFAULT ((0)) NOT NULL,
Factura VARCHAR(15),
ItemFac INT DEFAULT ((0)) NOT NULL,
IdProveedor VARCHAR(16) NOT NULL,
pVehiculo VARCHAR(10),
VrAbono MONEY DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraLiquidaOtr PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia,Item),
 CONSTRAINT CK_Trn_TraLiquidaOtrIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOtrIdCiaCau CHECK ((len([IdCiaCau])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOtrIdProveedor CHECK ((len([IdProveedor])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOtrTipCau CHECK ((len([TipCau])>(0))),
 CONSTRAINT CK_Trn_TraLiquidaOtrTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraLiqViajes ( 
TipDoc VARCHAR(3) DEFAULT ('LGA') NOT NULL,
Liquidacion INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('PROPIOS') NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
FechaMuc SMALLDATETIME NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
NitEmpresa VARCHAR(16) DEFAULT ('0') NOT NULL,
VrAnticipos MONEY DEFAULT (0) NOT NULL,
VrGastos MONEY DEFAULT (0) NOT NULL,
VrCombustible MONEY DEFAULT (0) NOT NULL,
VrOtrosCred MONEY DEFAULT (0) NOT NULL,
VrDiferencia MONEY DEFAULT (0) NOT NULL,
galsComb DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
IdLocOrigen VARCHAR(8) NOT NULL,
IdLocDestino VARCHAR(8) NOT NULL,
Referencia VARCHAR(50),
DescMcias VARCHAR(150),
kmtInicial DECIMAL(14,4) DEFAULT (0) NOT NULL,
kmtFinal DECIMAL(14,4) DEFAULT (0) NOT NULL,
EstFactura INT DEFAULT (0) NOT NULL,
TipDocRef VARCHAR(3) DEFAULT ('0') NOT NULL,
NumDocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('00') NOT NULL,
FecDocRef SMALLDATETIME,
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,
LiqMixto BIT DEFAULT ((0)) NOT NULL,
Num_Ppto INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraLiqViajes PRIMARY KEY CLUSTERED (TipDoc,Liquidacion,IdCia),
 CONSTRAINT CK_Trn_TraLiqViajesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdCiaMuc CHECK ((len([IdCiaMuc]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdCiaRef CHECK ((len([IdCiaRef]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdLocDestino CHECK ((len([IdLocDestino]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdLocOrigen CHECK ((len([IdLocOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesNitEmpresa CHECK ((len([NitEmpresa]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesTipDocRef CHECK ((len([TipDocRef]) > 0)),
 CONSTRAINT CK_Trn_TraLiqViajesTipMuc CHECK ((len([TipMuc]) > 0)))
CREATE TABLE Trn_TraManifAnexo ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
kmsTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrFleteTon MONEY DEFAULT ((0)) NOT NULL,
TipoRuta VARCHAR(10) DEFAULT ('URBANO'),
CdLocTrao VARCHAR(8),
CdLocTrad VARCHAR(8),
KmsTraOri DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
KmsTraDes DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdMneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
VrTasa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NomRemite VARCHAR(150),
NomDestino VARCHAR(150),
LugarFletes VARCHAR(100),
NumAnticipo INT DEFAULT ((0)) NOT NULL,
NumCheque VARCHAR(20),
TipoMintrans VARCHAR(10) DEFAULT ('GENERAL'),
MucMintrans INT DEFAULT ((0)) NOT NULL,
ContIntegral INT DEFAULT ((0)) NOT NULL,
VolumenCarga DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumPoliza VARCHAR(30),
CdBodDtno VARCHAR(4),
TipoTrslado INT DEFAULT ((0)),
MvoAnulacion VARCHAR(5),
MvoSuspension VARCHAR(5),
WsSeguro BIT DEFAULT ((0)),
NumRadSeguro DECIMAL(18,2) DEFAULT ((0)),
PuntosRuta DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CantViajes INT DEFAULT ((0)),
Transbordo INT DEFAULT ((0)) NOT NULL,
NumMucAnu INT DEFAULT ((0)) NOT NULL,
CiaMucAnu CHAR(2),
AceptaFirma BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraManifAnexo PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia),
 CONSTRAINT CK_Trn_TraManifAnexoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifAnexoIdMneda CHECK ((len([IdMneda])>(0))),
 CONSTRAINT CK_Trn_TraManifAnexoTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraManifiesto ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecEntrega SMALLDATETIME,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
IdRutaFle VARCHAR(4),
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
nRemolque VARCHAR(10),
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteIca MONEY DEFAULT ((0)) NOT NULL,
VrDescuento MONEY DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
VrAntAdic MONEY DEFAULT ((0)) NOT NULL,
VrNeto MONEY DEFAULT ((0)) NOT NULL,
VrPagos MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrDctos MONEY DEFAULT ((0)) NOT NULL,
TarifaFlete MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
BaseRet MONEY DEFAULT ((0)) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
IdLocFletes VARCHAR(8) NOT NULL,
FechaPago SMALLDATETIME,
PagoCargue VARCHAR(50) NOT NULL,
PagoDescargue VARCHAR(50) NOT NULL,
NumMintrans DECIMAL(14,2) DEFAULT ((0)) NOT NULL,
EdoMintrans VARCHAR(5),
Remesa INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('00') NOT NULL,
Cumplido INT DEFAULT ((0)) NOT NULL,
IdCiaCump CHAR(2) DEFAULT ('00') NOT NULL,
FechaCump SMALLDATETIME,
EstCumplido INT DEFAULT ((0)) NOT NULL,
TipOdp VARCHAR(3) DEFAULT ('0') NOT NULL,
OrdPago INT DEFAULT ((0)) NOT NULL,
IdCiaOdp CHAR(2) DEFAULT ('00') NOT NULL,
FechaOdp SMALLDATETIME,
EstOrden INT DEFAULT ((0)) NOT NULL,
VrFleteNeto MONEY DEFAULT ((0)) NOT NULL,
TipInfVia VARCHAR(3),
NumViaje INT DEFAULT ((0)) NOT NULL,
CiaInfViaje CHAR(2),
CdCatPeaje VARCHAR(4),
OrigenAdd VARCHAR(10) NOT NULL,
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,
FecDev SMALLDATETIME,
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,
CdCondRelev VARCHAR(16)
 CONSTRAINT PK_Trn_TraManifiesto PRIMARY KEY NONCLUSTERED (TipDoc,Manifiesto,IdCia),
 CONSTRAINT CK_Trn_TraManifiestoIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdCiaCump CHECK ((len([IdCiaCump])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdCiaOdp CHECK ((len([IdCiaOdp])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdLocFletes CHECK ((len([IdLocFletes])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdPoseedor CHECK ((len([IdPoseedor])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdPropietario CHECK ((len([IdPropietario])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdRuta CHECK ((len([IdRuta])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoPagoCargue CHECK ((len([PagoCargue])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoPagoDescargue CHECK ((len([PagoDescargue])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))),
 CONSTRAINT CK_Trn_TraManifiestoTipOdp CHECK ((len([TipOdp])>(0))))
CREATE TABLE Trn_TraManifInt ( 
TipDoc VARCHAR(3) DEFAULT ('MCI') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
nRemolque VARCHAR(10),
IdConductor VARCHAR(16) NOT NULL,
IdCondRelev VARCHAR(16),
NatCarga VARCHAR(50),
CdAduana VARCHAR(4),
CdAduanaDest VARCHAR(4),
IdMoneda VARCHAR(5) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumMuc INT DEFAULT ((0)) NOT NULL,
CdCiaMuc CHAR(2) NOT NULL,
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,
Negociacion VARCHAR(1000)
 CONSTRAINT PK_Trn_TraManifInt PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia),
 CONSTRAINT CK_Trn_TraManifIntCdCiaMuc CHECK ((len([CdCiaMuc])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraManifIntIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraManifIntOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraManifIntCon ( 
TipDoc VARCHAR(3) DEFAULT ('MCI') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTipoCon VARCHAR(4) NOT NULL,
NumCont VARCHAR(50) NOT NULL,
PesoCont DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
IdTipoPre VARCHAR(4) NOT NULL,
NumPrecinto VARCHAR(50) NOT NULL,
ColorPrecinto VARCHAR(50) NOT NULL
 CONSTRAINT PK_Trn_TraManifIntCon PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifIntConColorPrecinto CHECK ((len([ColorPrecinto])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConIdTipoCon CHECK ((len([IdTipoCon])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConIdTipoPre CHECK ((len([IdTipoPre])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConNumCont CHECK ((len([NumCont])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConNumPrecinto CHECK ((len([NumPrecinto])>(0))),
 CONSTRAINT CK_Trn_TraManifIntConTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraManifIntMcia ( 
TipDoc VARCHAR(3) DEFAULT ('MCI') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCiaOrd CHAR(2) NOT NULL,
CdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorMcia MONEY DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
UndVol VARCHAR(10),
Bultos VARCHAR(150),
DescripUnid VARCHAR(500)
 CONSTRAINT PK_Trn_TraManifIntMcia PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifIntMciaCdMercancia CHECK ((len([CdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaDescripMcias CHECK ((len([DescripMcias])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdCiaOrd CHECK ((len([IdCiaOrd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdEmp CHECK ((len([IdEmp])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdNat CHECK ((len([IdNat])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaTipOrd CHECK ((len([TipOrd])>(0))),
 CONSTRAINT CK_Trn_TraManifIntMciaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_TraManifMod ( 
TipDoc VARCHAR(3) NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
VrFleteTotal MONEY DEFAULT ((0)) NOT NULL,
VrRetencion MONEY DEFAULT ((0)) NOT NULL,
VrReteIca MONEY DEFAULT ((0)) NOT NULL,
VrAnticipo MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumCump INT DEFAULT ((0)) NOT NULL,
CdCiaCump CHAR(2) DEFAULT ('00') NOT NULL,
IdLugarPago VARCHAR(8),
FechaPago SMALLDATETIME,
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraManifMod PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifModCdCiaCump CHECK ((len([CdCiaCump])>(0))),
 CONSTRAINT CK_Trn_TraManifModIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraManifModIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraManifModTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraManifPrec ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdTipoPre VARCHAR(4) NOT NULL,
NumPrecinto VARCHAR(50) NOT NULL,
ColorPrecinto VARCHAR(50) NOT NULL,
Sellos VARCHAR(150)
 CONSTRAINT PK_Trn_TraManifPrec PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifPrecColorPrecinto CHECK ((len([ColorPrecinto])>(0))),
 CONSTRAINT CK_Trn_TraManifPrecIdTipoPre CHECK ((len([IdTipoPre])>(0))),
 CONSTRAINT CK_Trn_TraManifPrecNumPrecinto CHECK ((len([NumPrecinto])>(0))))
CREATE TABLE Trn_TraManifRem ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto 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,
ItemRem INT DEFAULT (0) NOT NULL,
TarifTabla MONEY DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
RemMintrans DECIMAL(14,2) DEFAULT (0) NOT NULL,
EdoRemMin VARCHAR(5),
CodBodDtno VARCHAR(4),
TipTraslado INT DEFAULT ((0)),
HorasCargue DECIMAL(14,4) DEFAULT ((0)),
HorasDesc DECIMAL(14,4) DEFAULT ((0)),
FecInicioCargue SMALLDATETIME,
FecFinCargue SMALLDATETIME,
FecIniciodesc SMALLDATETIME,
FecFindesc SMALLDATETIME,
TiempoCargue DECIMAL(14,4) DEFAULT ((0)),
TiempoDesc DECIMAL(14,4) DEFAULT ((0)),
FecLlegCargue SMALLDATETIME,
FecSalidaCargue SMALLDATETIME,
FecLlegdesc SMALLDATETIME,
FecSalidadesc SMALLDATETIME
 CONSTRAINT PK_Trn_TraManifRem PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraManifRemIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraManifRemIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraManifRemTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraManifRemTipRem CHECK ((len([TipRem]) > 0)))
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))))
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,
TipoAncpo VARCHAR(10) DEFAULT ('EGRESO'),
NumPresAnt INT DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) 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))))
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))))
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))))
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))))
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,
TipEgr VARCHAR(3),
Egreso INT DEFAULT ((0)) NOT NULL,
IdCiaEgr CHAR(2),
NumCheque VARCHAR(20),
VrConcCargos MONEY DEFAULT ((0)) NOT NULL,
VrConcDed MONEY DEFAULT ((0)) NOT NULL,
CdCCosto VARCHAR(16),
CdSubCos VARCHAR(16)
 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))))
CREATE TABLE Trn_TraOrdenManif ( 
TipDoc VARCHAR(3) DEFAULT ('ODP') NOT NULL,
OrdPago INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
VrTotalFletes MONEY DEFAULT (0) NOT NULL,
VrDescuento MONEY DEFAULT (0) NOT NULL,
VrRetencion MONEY DEFAULT (0) NOT NULL,
VrReteIca MONEY DEFAULT (0) NOT NULL,
VrAnticipos MONEY DEFAULT (0) NOT NULL,
VrFaltantes MONEY DEFAULT (0) NOT NULL,
VrSeguros MONEY DEFAULT (0) NOT NULL,
VrFondos MONEY DEFAULT (0) NOT NULL,
VrAportes MONEY DEFAULT (0) NOT NULL,
VrOtrosDctos MONEY DEFAULT (0) NOT NULL,
VrImpuestos MONEY DEFAULT (0) NOT NULL,
VrEstampilla MONEY DEFAULT (0) NOT NULL,
VrOtrosPagos MONEY DEFAULT (0) NOT NULL,
VrNeto MONEY DEFAULT (0) NOT NULL,
TarifaTabla MONEY DEFAULT (0) NOT NULL,
TarifaFlete MONEY DEFAULT (0) NOT NULL,
UnidTarifa VARCHAR(10) DEFAULT ('PESO'),
PesoTotal DECIMAL(14,4) DEFAULT (0) NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoOrigen DECIMAL(14,4) DEFAULT (0) NOT NULL,
UnidOrigen DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolOrigen DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoDestino DECIMAL(14,4) DEFAULT (0) NOT NULL,
UnidDestino DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolDestino DECIMAL(14,4) DEFAULT (0) NOT NULL,
BaseRet MONEY DEFAULT (0) NOT NULL,
BaseIca MONEY DEFAULT (0) NOT NULL,
BaseSeg MONEY DEFAULT (0) NOT NULL,
BaseImp MONEY DEFAULT (0) NOT NULL,
TarifaRet DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaIca DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaSeg DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifaImp DECIMAL(14,4) DEFAULT (0) NOT NULL,
CodTarRet VARCHAR(4),
CodTarIca VARCHAR(4),
TipoLiq INT DEFAULT (0) NOT NULL,
TipEgr VARCHAR(3),
Egreso INT DEFAULT (0) NOT NULL,
IdCiaEgr CHAR(2),
NumCheque VARCHAR(20),
Referencia VARCHAR(50),
CantFaltante DECIMAL(14,4) DEFAULT (0) NOT NULL,
UnidadFalt VARCHAR(10) DEFAULT ('PESO'),
TolFaltNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrConcPagos MONEY DEFAULT (0) NOT NULL,
VrConcDctos MONEY DEFAULT (0) NOT NULL,
VrConcFondo MONEY DEFAULT (0) NOT NULL,
VrConcSeguro MONEY DEFAULT (0) NOT NULL,
VrConcAporte MONEY DEFAULT (0) NOT NULL,
VrConcImpuesto MONEY DEFAULT (0) NOT NULL,
EdoLiqCausac INT DEFAULT (0) NOT NULL,
VrRemesas MONEY DEFAULT (0) NOT NULL,
VrRecCaja MONEY DEFAULT (0) NOT NULL,
CdForma VARCHAR(4),
FechaEgr SMALLDATETIME,
VrSeguroRc MONEY DEFAULT ((0)) NOT NULL,
VrReteCREE MONEY DEFAULT ((0)) NOT NULL,
TarifaRtc DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
CodTarRtc VARCHAR(4),
CdCenCosto VARCHAR(16),
CdSubCenCos VARCHAR(16),
CodTarifAvta VARCHAR(4),
TarifaAvta DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
VrImpAvTa MONEY DEFAULT ((0)) NOT NULL,
VrDctoPago MONEY DEFAULT ((0)) NOT NULL,
CodTarifDcpp VARCHAR(4)
 CONSTRAINT PK_Trn_TraOrdenManif PRIMARY KEY CLUSTERED (TipDoc,OrdPago,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenManifIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifIdCiaMuc CHECK ((len([IdCiaMuc]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenManifTipMuc CHECK ((len([TipMuc]) > 0)))
CREATE TABLE Trn_TraOrdenOper ( 
TipDoc VARCHAR(3) NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdOperario VARCHAR(16) NOT NULL
 CONSTRAINT PK_Trn_TraOrdenOper PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenOperIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraOrdenOperIdOperario CHECK ((len([IdOperario])>(0))),
 CONSTRAINT CK_Trn_TraOrdenOperTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraOrdenPago ( 
TipDoc VARCHAR(3) DEFAULT ('ODP') NOT NULL,
OrdPago INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('GENERAL') NOT NULL,
LiqRemesas BIT DEFAULT (0) NOT NULL,
CxPagar BIT DEFAULT (0) NOT NULL,
MulPlazos BIT DEFAULT (0) NOT NULL,
IdPlazo VARCHAR(4) NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
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_TraOrdenPago PRIMARY KEY NONCLUSTERED (TipDoc,OrdPago,IdCia),
 CONSTRAINT CK_Trn_TraOrdenPagoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoIdPlazo CHECK ((len([IdPlazo]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoModalidad CHECK (([Modalidad] = 'MULTIPLE' or [Modalidad] = 'GENERAL')),
 CONSTRAINT CK_Trn_TraOrdenPagoOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenPagoTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraOrdenRemesas ( 
TipDoc VARCHAR(3) DEFAULT ('ODP') NOT NULL,
OrdPago INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipMuc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCiaMuc CHAR(2) DEFAULT ('01') NOT NULL,
TipRem VARCHAR(3) DEFAULT ('RMT') NOT NULL,
Remesa INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
ItemRem INT DEFAULT (0) NOT NULL,
Cantidad 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,
Cases INT DEFAULT (0) NOT NULL,
Cajas INT DEFAULT (0) NOT NULL,
Palets INT DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifTabla MONEY DEFAULT (0) NOT NULL,
UndTarifa VARCHAR(10) DEFAULT ('PESO') NOT NULL,
Detalle VARCHAR(250)
 CONSTRAINT PK_Trn_TraOrdenRemesas PRIMARY KEY CLUSTERED (TipDoc,OrdPago,IdCia,Item),
 CONSTRAINT CK_Trn_TraOrdenRemesasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasIdCiaMuc CHECK ((len([IdCiaMuc]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasTipMuc CHECK ((len([TipMuc]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasTipRem CHECK ((len([TipRem]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasUndTarifa CHECK ((len([UndTarifa]) > 0)),
 CONSTRAINT CK_Trn_TraOrdenRemesasUndVol CHECK ((len([UndVol]) > 0)))
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,
NumAprob INT DEFAULT ((0)),
IdCiaApr CHAR(2) DEFAULT ('00'),
FecAprob SMALLDATETIME,
UsuAprob VARCHAR(11),
ObservAprob VARCHAR(250),
CdRuta VARCHAR(4),
IdOrigen VARCHAR(8),
Cantkms INT DEFAULT ((0)) NOT NULL,
NumCump INT DEFAULT ((0)) NOT NULL,
CdCiaCum CHAR(2),
CdTarIva VARCHAR(4),
CdTarRiv VARCHAR(4),
CdTarRet VARCHAR(4),
CdTarIca VARCHAR(4),
CdTarRtc VARCHAR(4)
 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))))
CREATE TABLE Trn_TraPedAnexo ( 
TipDoc VARCHAR(3) DEFAULT ('PDT') NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
NomCliente VARCHAR(150),
NomRemite VARCHAR(150),
NomDestino VARCHAR(150),
LugarCargue VARCHAR(150),
LugarDescargue VARCHAR(150),
NomContacto VARCHAR(150),
TelContacto VARCHAR(30),
emlContacto VARCHAR(100),
ContacDestino VARCHAR(150),
TelContacDest VARCHAR(30),
emlContacDest VARCHAR(100),
PolizaEsp BIT DEFAULT (0) NOT NULL,
NumPolizaEsp VARCHAR(50),
NitCiaPoliza VARCHAR(16),
NomCiaPoliza VARCHAR(150),
FecVencePol SMALLDATETIME,
VrLimiteDesp MONEY DEFAULT (0) NOT NULL,
Seguros VARCHAR(10) DEFAULT ('EMPRESA') NOT NULL,
Cargue VARCHAR(20) DEFAULT ('CLIENTE') NOT NULL,
Descargue VARCHAR(20) DEFAULT ('CLIENTE') NOT NULL,
CdTipoEsc VARCHAR(4) DEFAULT ('0'),
NitSIA VARCHAR(16),
NombreSIA VARCHAR(150),
ContactoSIA VARCHAR(150),
TelContacSIA VARCHAR(30),
TipoRuta VARCHAR(10) DEFAULT ('NACIONAL') NOT NULL,
TipoTrans VARCHAR(10) DEFAULT ('GENERAL') NOT NULL,
Embarque VARCHAR(10) DEFAULT ('SUELTA') NOT NULL,
CdTipCarga VARCHAR(4),
DevContenedor BIT DEFAULT (0) NOT NULL,
IdLocCont VARCHAR(8),
PatioCont VARCHAR(50),
CdTipoVeh VARCHAR(4) DEFAULT ('0') NOT NULL,
MargenFalt DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoMargen VARCHAR(10) DEFAULT ('UNIDAD') NOT NULL,
UndCalcFalt VARCHAR(10) DEFAULT ('PESO'),
TarifFaltPago MONEY DEFAULT (0) NOT NULL,
TarifFaltCobro MONEY DEFAULT (0) NOT NULL,
EmbAdicional VARCHAR(150),
CdRutaTarif VARCHAR(4),
TipoServicio VARCHAR(10),
CodTipoOper VARCHAR(4)
 CONSTRAINT PK_Trn_TraPedAnexo PRIMARY KEY CLUSTERED (TipDoc,Pedido,IdCia),
 CONSTRAINT CK_Trn_TraPedAnexoCargue CHECK ((len([Cargue]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoCdTipoVeh CHECK ((len([CdTipoVeh]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoDescargue CHECK ((len([Descargue]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoEmbarque CHECK ((len([Embarque]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoSeguros CHECK ((len([Seguros]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoTipoMargen CHECK ((len([TipoMargen]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoTipoRuta CHECK ((len([TipoRuta]) > 0)),
 CONSTRAINT CK_Trn_TraPedAnexoTipoTrans CHECK ((len([TipoTrans]) > 0)))
CREATE TABLE Trn_TraPedido ( 
TipDoc VARCHAR(3) DEFAULT ('PDT') NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecEntrega SMALLDATETIME,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdClieFact VARCHAR(16) NOT NULL,
IdRemitente VARCHAR(16) NOT NULL,
IdDestinatario VARCHAR(16) NOT NULL,
IdLocOrigen VARCHAR(8) NOT NULL,
IdLocDestino VARCHAR(8) NOT NULL,
IdVend VARCHAR(16) NOT NULL,
IdTarifCom VARCHAR(4) DEFAULT ('0') NOT NULL,
Modalidad VARCHAR(10) NOT NULL,
Vigencia VARCHAR(10) DEFAULT ('NORMAL') NOT NULL,
TipoTarifa VARCHAR(10) DEFAULT ('PEDIDO') NOT NULL,
VrCobro MONEY DEFAULT (0) NOT NULL,
VrPagos MONEY DEFAULT (0) NOT NULL,
VrFletes MONEY DEFAULT (0) NOT NULL,
VrCargue MONEY DEFAULT (0) NOT NULL,
VrDesCargue MONEY DEFAULT (0) NOT NULL,
VrEscolta MONEY DEFAULT (0) NOT NULL,
VrDevContdor MONEY DEFAULT (0) NOT NULL,
VrTraUrbano MONEY DEFAULT (0) NOT NULL,
VrEmbalajes MONEY DEFAULT (0) NOT NULL,
VrCargos MONEY DEFAULT (0) NOT NULL,
VrDctos MONEY DEFAULT (0) NOT NULL,
VrDeclarado MONEY DEFAULT (0) NOT NULL,
VrSeguro MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
CantDesp DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdMneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
VrTasa DECIMAL(14,4) DEFAULT (0) NOT NULL,
Cotizacion INT DEFAULT (0) NOT NULL,
IdCiaCot CHAR(2) DEFAULT ('00') NOT NULL,
NumAprob INT DEFAULT (0) NOT NULL,
IdCiaApr CHAR(2) DEFAULT ('01') NOT NULL,
FecAprob SMALLDATETIME,
TipOdc VARCHAR(3) DEFAULT ('OCT') NOT NULL,
OCargue INT DEFAULT (0) NOT NULL,
IdCiaOdc CHAR(2) DEFAULT ('01') NOT NULL,
FechaOdc SMALLDATETIME,
TipRem VARCHAR(3) DEFAULT ('RMT') NOT NULL,
Remesa INT DEFAULT (0) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
FechaRem SMALLDATETIME,
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('00') NOT NULL,
FechaFac SMALLDATETIME,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
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_TraPedido PRIMARY KEY CLUSTERED (TipDoc,Pedido,IdCia),
 CONSTRAINT CK_Trn_TraPedidoIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCiaApr CHECK ((len([IdCiaApr]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCiaFac CHECK ((len([IdCiaFac]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCiaOdc CHECK ((len([IdCiaOdc]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCiaRem CHECK ((len([IdCiaRem]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdClieFact CHECK ((len([IdClieFact]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdDestinatario CHECK ((len([IdDestinatario]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdLocDestino CHECK ((len([IdLocDestino]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdLocOrigen CHECK ((len([IdLocOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdMneda CHECK ((len([IdMneda]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdRemitente CHECK ((len([IdRemitente]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdTarifCom CHECK ((len([IdTarifCom]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoModalidad CHECK ((len([Modalidad]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoTipFac CHECK ((len([TipFac]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoTipOdc CHECK ((len([TipOdc]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoTipoTarifa CHECK ((len([TipoTarifa]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoTipRem CHECK ((len([TipRem]) > 0)),
 CONSTRAINT CK_Trn_TraPedidoVigencia CHECK (([Vigencia] = 'NORMAL' or [Vigencia] = 'PERMANENTE')))
CREATE TABLE Trn_TraPedMcias ( 
TipDoc VARCHAR(3) DEFAULT ('PDT') NOT NULL,
Pedido INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
dmsAlto DECIMAL(14,4) DEFAULT (0) NOT NULL,
dmsAncho DECIMAL(14,4) DEFAULT (0) NOT NULL,
dmsLargo DECIMAL(14,4) DEFAULT (0) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndVol VARCHAR(10) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) DEFAULT ('0') NOT NULL,
IdNat VARCHAR(4) NOT NULL,
IdMnjo VARCHAR(4) NOT NULL,
IdTmcia VARCHAR(4) NOT NULL,
CdRango VARCHAR(4),
Cases INT DEFAULT (0) NOT NULL,
Cajas INT DEFAULT (0) NOT NULL,
Palets INT DEFAULT (0) NOT NULL,
NitRemite VARCHAR(16) NOT NULL,
Remitente VARCHAR(250) NOT NULL,
DirOrigen VARCHAR(250) NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
NitDestntario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(250) DEFAULT ('varios') NOT NULL,
DirDestino VARCHAR(250) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
TarifClie MONEY DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifTabla MONEY DEFAULT (0) NOT NULL,
VrDeclarado MONEY DEFAULT (0) NOT NULL,
VrSeguro MONEY DEFAULT (0) NOT NULL,
TarifSeguro DECIMAL(14,4) DEFAULT (0) NOT NULL,
Referencia1 VARCHAR(50),
Referencia2 VARCHAR(50),
Contenedor1 VARCHAR(50),
Contenedor2 VARCHAR(50),
UndTarifa VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndTarifPago VARCHAR(10) DEFAULT ('PESO') NOT NULL,
DocCliente VARCHAR(30),
Referencia3 VARCHAR(50),
CdTipoVehic VARCHAR(4),
Tipo_Servicio VARCHAR(10),
SedeRem VARCHAR(10),
SedeDest VARCHAR(10)
 CONSTRAINT PK_Trn_TraPedMcias PRIMARY KEY CLUSTERED (TipDoc,Pedido,IdCia,Item),
 CONSTRAINT CK_Trn_TraPedMciasDescripMcias CHECK ((len([DescripMcias]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasDestinatario CHECK ((len([Destinatario]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasDirDestino CHECK ((len([DirDestino]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasDirOrigen CHECK ((len([DirOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdDestino CHECK ((len([IdDestino]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdEmbalaje CHECK ((len([IdEmp]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdMercancia CHECK ((len([IdMercancia]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdMnjo CHECK ((len([IdMnjo]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdNat CHECK ((len([IdNat]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdOrigen CHECK ((len([IdOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdTmcia CHECK ((len([IdTmcia]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasRemitente CHECK ((len([Remitente]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasUndTarifPago CHECK ((len([UndTarifPago]) > 0)),
 CONSTRAINT CK_Trn_TraPedMciasUndVol CHECK ((len([UndVol]) > 0)))
CREATE TABLE Trn_TraPorteInt ( 
TipDoc VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
FecCargue SMALLDATETIME NOT NULL,
FecEntrega SMALLDATETIME,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
IdNotificado VARCHAR(16) NOT NULL,
Notificado VARCHAR(150) NOT NULL,
IdRemitente VARCHAR(16) NOT NULL,
Remitente VARCHAR(150) NOT NULL,
DirOrigen VARCHAR(250),
IdDestinatario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(150) NOT NULL,
DirDestino VARCHAR(250),
IdConsig VARCHAR(16) NOT NULL,
Consignatario VARCHAR(150),
DirConsig VARCHAR(250),
InsTransporte VARCHAR(1000),
DocRemitente VARCHAR(500),
IdMoneda VARCHAR(5) NOT NULL,
ValorTotal MONEY DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
CdCiaManif CHAR(2),
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,
Negociacion VARCHAR(1000),
Condic_Pago VARCHAR(1000)
 CONSTRAINT PK_Trn_TraPorteInt PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_TraPorteIntDestinatario CHECK ((len([Destinatario])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdConsig CHECK ((len([IdConsig])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdDestinatario CHECK ((len([IdDestinatario])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdDestino CHECK ((len([IdDestino])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdNotificado CHECK ((len([IdNotificado])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdOrigen CHECK ((len([IdOrigen])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdRemitente CHECK ((len([IdRemitente])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntNotificado CHECK ((len([Notificado])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntRemitente CHECK ((len([Remitente])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraPorteIntGas ( 
TipDoc VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
MontoRem MONEY DEFAULT ((0)) NOT NULL,
IdMonRem VARCHAR(4) NOT NULL,
MontoDest MONEY DEFAULT ((0)) NOT NULL,
IdMonDest VARCHAR(4) NOT NULL
 CONSTRAINT PK_Trn_TraPorteIntGas PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraPorteIntGasIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasIdConcepto CHECK ((len([IdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasIdMonDest CHECK ((len([IdMonDest])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasIdMonRem CHECK ((len([IdMonRem])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntGasTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraPorteIntMcia ( 
TipDoc VARCHAR(3) DEFAULT ('CPI') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
CdMercancia VARCHAR(16) NOT NULL,
DescripMcias VARCHAR(500) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoBruto DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
ValorMcia MONEY DEFAULT ((0)) NOT NULL,
IdMoneda VARCHAR(5) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
UndVol VARCHAR(10),
Bultos VARCHAR(150),
Observacion VARCHAR(1000),
DescripUnid VARCHAR(500)
 CONSTRAINT PK_Trn_TraPorteIntMcia PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraPorteIntMciaCdMercancia CHECK ((len([CdMercancia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaDescripMcias CHECK ((len([DescripMcias])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdEmp CHECK ((len([IdEmp])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdMoneda CHECK ((len([IdMoneda])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdNat CHECK ((len([IdNat])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaIdUnd CHECK ((len([IdUnd])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraPorteIntMciaUndMed CHECK ((len([UndMed])>(0))))
CREATE TABLE Trn_TraPresAnt ( 
NumPsto INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
TipoRuta VARCHAR(10) DEFAULT ('CIUDAD') NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
FecInicio SMALLDATETIME NOT NULL,
FecFinal SMALLDATETIME NOT NULL,
VrGastos MONEY DEFAULT (0) NOT NULL,
VrComb MONEY DEFAULT (0) NOT NULL,
VrPeajes MONEY DEFAULT (0) NOT NULL,
VrAnticipo MONEY DEFAULT (0) NOT NULL,
CdCat VARCHAR(4) NOT NULL,
CdTipoVeh VARCHAR(4) DEFAULT ('0') NOT NULL,
TipoAfilVeh VARCHAR(10) DEFAULT ('0') NOT NULL,
CdTipoMot VARCHAR(4) DEFAULT ('0') NOT NULL,
CdCom VARCHAR(4) DEFAULT ('0') NOT NULL,
CdRango VARCHAR(4),
ValorFijo BIT DEFAULT (0) NOT NULL,
Observacion VARCHAR(250),
Inactivo BIT DEFAULT (0) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
FechaAct SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
NitCliente VARCHAR(16),
CdMercancia VARCHAR(16),
TipoServicio INT DEFAULT ((0)) NOT NULL,
Cantgalones DECIMAL(14,4) DEFAULT ((0)),
VrExtralegal MONEY DEFAULT ((0)),
CdTipoCarr VARCHAR(4)
 CONSTRAINT PK_Trn_TraPresAnt PRIMARY KEY CLUSTERED (NumPsto),
 CONSTRAINT CK_Trn_TraPresAntCdCat CHECK ((len([CdCat]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntCdCom CHECK ((len([CdCom]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntCdTipoMot CHECK ((len([CdTipoMot]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntCdTipoVeh CHECK ((len([CdTipoVeh]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntIdDestino CHECK ((len([IdDestino]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntIdOrigen CHECK ((len([IdOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraPresAntTipoAfilVeh CHECK ((len([TipoAfilVeh]) > 0)))
CREATE TABLE Trn_TraPresItems ( 
NumPsto INT DEFAULT (0) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
Descripcion VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
VrUnitario MONEY DEFAULT (0) NOT NULL,
VrTotal MONEY DEFAULT (0) NOT NULL,
TipoRubro VARCHAR(10) DEFAULT ('GASTO') NOT NULL,
CdClase VARCHAR(4),
NitTercero VARCHAR(16),
CdTipOper VARCHAR(4)
 CONSTRAINT PK_Trn_TraPresItems PRIMARY KEY CLUSTERED (NumPsto,Item),
 CONSTRAINT CK_Trn_TraPresItemsDescripcion CHECK ((len([Descripcion]) > 0)),
 CONSTRAINT CK_Trn_TraPresItemsIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TraPresItemsTipoRubro CHECK ((len([TipoRubro]) > 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_TraRemAnexo ( 
TipDoc VARCHAR(3) DEFAULT ('RMT') NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
IdTarifCom VARCHAR(4) DEFAULT ('0') NOT NULL,
NomCliente VARCHAR(150),
NomRemite VARCHAR(150),
NomDestino VARCHAR(150),
LugarCargue VARCHAR(150),
LugarDescargue VARCHAR(150),
NomContacto VARCHAR(150),
TelContacto VARCHAR(30),
emlContacto VARCHAR(100),
ContacDestino VARCHAR(150),
TelContacDest VARCHAR(30),
emlContacDest VARCHAR(100),
TomadorPoliza CHAR(1) DEFAULT ('N') NOT NULL,
PolizaSeguro VARCHAR(50),
NitCiaPoliza VARCHAR(16),
NomCiaPoliza VARCHAR(150),
FecVencePol SMALLDATETIME,
ManifMintrans DECIMAL(14,2) DEFAULT (0) NOT NULL,
RemMintrans DECIMAL(14,2) DEFAULT (0) NOT NULL,
TipSal VARCHAR(3),
NumSalida INT DEFAULT (0) NOT NULL,
IdCiaSal CHAR(2) DEFAULT ('00'),
NumInvent INT DEFAULT (0) NOT NULL,
IdCiaInv CHAR(2) DEFAULT ('00'),
TipoRuta VARCHAR(10) DEFAULT ('URBANO') NOT NULL,
TipoMintrans VARCHAR(10) DEFAULT ('GENERAL'),
NitEmpTransp VARCHAR(16),
NumFactEmp VARCHAR(20),
MvoAnulacion VARCHAR(3),
PactoCargue BIT DEFAULT ((0)) NOT NULL,
HorasPactoCargue INT DEFAULT ((0)) NOT NULL,
MinPactoCargue INT DEFAULT ((0)) NOT NULL,
HoraCitaCargue SMALLDATETIME,
HoraLlegaCargue SMALLDATETIME,
HoraEntraCargue SMALLDATETIME,
HoraSaleCargue SMALLDATETIME,
PactoDescargue BIT DEFAULT ((0)) NOT NULL,
HorasPactoDescargue INT DEFAULT ((0)) NOT NULL,
MinPactoDescargue INT DEFAULT ((0)) NOT NULL,
HoraCitaDescargue SMALLDATETIME,
HoraLlegaDescargue SMALLDATETIME,
HoraEntraDescargue SMALLDATETIME,
HoraSaleDescargue SMALLDATETIME,
TipoDevRemesa VARCHAR(3),
CodCiuTransb VARCHAR(8),
MvoTransbordo VARCHAR(3),
CantViajes INT DEFAULT ((0)),
TipOrdMud VARCHAR(3),
ItemOsm INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraRemAnexo PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_TraRemAnexoIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraRemAnexoIdTarifCom CHECK ((len([IdTarifCom]) > 0)),
 CONSTRAINT CK_Trn_TraRemAnexoIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_TraRemAnexoTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraRemAnexoTipoRuta CHECK ((len([TipoRuta]) > 0)),
 CONSTRAINT CK_Trn_TraRemAnexoTomadorPoliza CHECK ((len([TomadorPoliza]) > 0)))
CREATE TABLE Trn_TraRemCancela ( 
Id BIGINT IDENTITY ( 1,1 ) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipDoc VARCHAR(3) NOT NULL,
Factura INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
TipRem VARCHAR(3) DEFAULT ('RMT') NOT NULL,
Remesa INT DEFAULT ((0)) NOT NULL,
IdCiaRem CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Observacion VARCHAR(500),
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_TraRemCancela PRIMARY KEY NONCLUSTERED (Id),
 CONSTRAINT CK_Trn_TraRemCancelaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraRemCancelaIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_TraRemCancelaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraRemCancelaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraRemCancelaTipRem CHECK ((len([TipRem])>(0))))
CREATE TABLE Trn_TraRemCntdor ( 
TipDoc VARCHAR(3) DEFAULT ('RMT') NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdTipoCon VARCHAR(4) NOT NULL,
NumContdor VARCHAR(50) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdTipoPre VARCHAR(4) NOT NULL,
NumPrecinto VARCHAR(30) NOT NULL,
ColorPrecinto VARCHAR(20) NOT NULL,
Sellos VARCHAR(150),
Peligroso BIT DEFAULT (0) NOT NULL,
Perecedero BIT DEFAULT (0) NOT NULL,
Toxico BIT DEFAULT (0) NOT NULL,
Inflamable BIT DEFAULT (0) NOT NULL,
Difmanejo BIT DEFAULT (0) NOT NULL,
Fragil BIT DEFAULT (0) NOT NULL,
DevCont BIT DEFAULT (0) NOT NULL,
CdLocCont VARCHAR(8),
PatioCont VARCHAR(50),
Observacion VARCHAR(150),
NumSalidaSello INT DEFAULT ((0)),
CdCiaSalSello CHAR(2),
ItemSalSello INT DEFAULT ((0)),
CdProdSalida VARCHAR(16),
NumSerialSello VARCHAR(30),
NumComodato VARCHAR(50),
FecVenceCom SMALLDATETIME
 CONSTRAINT PK_Trn_TraRemCntdor PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraRemCntdorColorPrecinto CHECK ((len([ColorPrecinto]) > 0)),
 CONSTRAINT CK_Trn_TraRemCntdorIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraRemCntdorIdTipoCon CHECK ((len([IdTipoCon]) > 0)),
 CONSTRAINT CK_Trn_TraRemCntdorIdTipoPre CHECK ((len([IdTipoPre]) > 0)),
 CONSTRAINT CK_Trn_TraRemCntdorNumContdor CHECK ((len([NumContdor]) > 0)),
 CONSTRAINT CK_Trn_TraRemCntdorNumPrecinto CHECK ((len([NumPrecinto]) > 0)),
 CONSTRAINT CK_Trn_TraRemCntdorTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_TraRemesa ( 
TipDoc VARCHAR(3) DEFAULT ('RMT') NOT NULL,
NumOrden INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
FecEntrega SMALLDATETIME,
HoraLlegada SMALLDATETIME,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdClieFact VARCHAR(16) NOT NULL,
IdRemitente VARCHAR(16) NOT NULL,
IdDestinatario VARCHAR(16) NOT NULL,
IdLocOrigen VARCHAR(8) NOT NULL,
IdLocDestino VARCHAR(8) NOT NULL,
IdLocFletes VARCHAR(8) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
nRemolque VARCHAR(10),
TipoAfiVehic VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
Modalidad VARCHAR(10) NOT NULL,
TipoTarifa VARCHAR(10) DEFAULT ('TABLA') NOT NULL,
VrCobro MONEY DEFAULT ((0)) NOT NULL,
VrPagos MONEY DEFAULT ((0)) NOT NULL,
VrFletes MONEY DEFAULT ((0)) NOT NULL,
VrCargue MONEY DEFAULT ((0)) NOT NULL,
VrDesCargue MONEY DEFAULT ((0)) NOT NULL,
VrEscolta MONEY DEFAULT ((0)) NOT NULL,
VrDevContdor MONEY DEFAULT ((0)) NOT NULL,
VrTraUrbano MONEY DEFAULT ((0)) NOT NULL,
VrEmbalajes MONEY DEFAULT ((0)) NOT NULL,
VrCargos MONEY DEFAULT ((0)) NOT NULL,
VrDctos MONEY DEFAULT ((0)) NOT NULL,
VrDeclarado MONEY DEFAULT ((0)) NOT NULL,
VrSeguro MONEY DEFAULT ((0)) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Items INT DEFAULT ((0)) NOT NULL,
IdMneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
VrTasa DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
NumPedido INT DEFAULT ((0)) NOT NULL,
IdCiaPed CHAR(2) DEFAULT ('01') NOT NULL,
FechaPed SMALLDATETIME,
TipDcm VARCHAR(3) DEFAULT ('0') NOT NULL,
NumDocmto INT DEFAULT ((0)) NOT NULL,
IdCiaDcm CHAR(2) DEFAULT ('01') NOT NULL,
FechaDcm SMALLDATETIME,
NumManif INT DEFAULT ((0)) NOT NULL,
IdCiaManif CHAR(2) DEFAULT ('00') NOT NULL,
EstCumplido INT DEFAULT ((0)) NOT NULL,
EstFactura INT DEFAULT ((0)) NOT NULL,
CdConcepto VARCHAR(4) DEFAULT ('0') NOT NULL,
CdRutaTarif VARCHAR(4),
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,
CdBodega VARCHAR(4),
TipCom VARCHAR(3) NOT NULL,
Comprobante INT DEFAULT ((0)) NOT NULL,
IdCiaCom CHAR(2) NOT NULL,
OrigenAdd VARCHAR(10) NOT NULL,
Anulado BIT DEFAULT ((0)) NOT NULL,
FecDev SMALLDATETIME,
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,
VigenciaOdc INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraRemesa PRIMARY KEY NONCLUSTERED (TipDoc,NumOrden,IdCia),
 CONSTRAINT CK_Trn_TraRemesaCdConcepto CHECK ((len([CdConcepto])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdAgencia CHECK ((len([IdAgencia])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCiaCom CHECK ((len([IdCiaCom])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCiaDcm CHECK ((len([IdCiaDcm])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCiaManif CHECK ((len([IdCiaManif])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCiaPed CHECK ((len([IdCiaPed])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdClieFact CHECK ((len([IdClieFact])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdCliente CHECK ((len([IdCliente])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdDestinatario CHECK ((len([IdDestinatario])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdLocDestino CHECK ((len([IdLocDestino])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdLocFletes CHECK ((len([IdLocFletes])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdLocOrigen CHECK ((len([IdLocOrigen])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdMneda CHECK ((len([IdMneda])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdRemitente CHECK ((len([IdRemitente])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraRemesaIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraRemesaModalidad CHECK ((len([Modalidad])>(0))),
 CONSTRAINT CK_Trn_TraRemesaOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraRemesaTipCom CHECK ((len([TipCom])>(0))),
 CONSTRAINT CK_Trn_TraRemesaTipDcm CHECK ((len([TipDcm])>(0))),
 CONSTRAINT CK_Trn_TraRemesaTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraRemesaTipoAfiVehic CHECK ((len([TipoAfiVehic])>(0))),
 CONSTRAINT CK_Trn_TraRemesaTipoTarifa CHECK ((len([TipoTarifa])>(0))))
CREATE TABLE Trn_TraRemMcias ( 
TipDoc VARCHAR(3) DEFAULT ('RMT') 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,
DescripMcias VARCHAR(250) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoNeto DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
dmsAlto DECIMAL(14,4) DEFAULT (0) NOT NULL,
dmsAncho DECIMAL(14,4) DEFAULT (0) NOT NULL,
dmsLargo DECIMAL(14,4) DEFAULT (0) NOT NULL,
Volumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndVol VARCHAR(10) NOT NULL,
IdUnd VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
IdNat VARCHAR(4) NOT NULL,
IdTmcia VARCHAR(4) NOT NULL,
IdMnjo VARCHAR(4) NOT NULL,
CdRango VARCHAR(4),
Cases INT DEFAULT (0) NOT NULL,
Cajas INT DEFAULT (0) NOT NULL,
Palets INT DEFAULT (0) NOT NULL,
NitRemite VARCHAR(16) NOT NULL,
Remitente VARCHAR(250) NOT NULL,
DirOrigen VARCHAR(250) NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
NitDestntario VARCHAR(16) NOT NULL,
Destinatario VARCHAR(250) DEFAULT ('varios') NOT NULL,
DirDestino VARCHAR(250) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
TarifClie MONEY DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifTabla MONEY DEFAULT (0) NOT NULL,
VrDeclarado MONEY DEFAULT (0) NOT NULL,
VrSeguro MONEY DEFAULT (0) NOT NULL,
TarifSeguro DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndTarifa VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndTarifPago VARCHAR(10) DEFAULT ('PESO') NOT NULL,
Remision DECIMAL(18,2) DEFAULT (0) NOT NULL,
DocCliente VARCHAR(30) DEFAULT ('0') NOT NULL,
Referencia1 VARCHAR(50),
Referencia2 VARCHAR(50),
Referencia3 VARCHAR(50),
Contenedor1 VARCHAR(50),
Contenedor2 VARCHAR(50),
CdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
Cumplido INT DEFAULT (0) NOT NULL,
IdCiaCump CHAR(2) DEFAULT ('01') NOT NULL,
FechaCump SMALLDATETIME,
DetalleCump VARCHAR(250),
CantidadCump DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoCump DECIMAL(14,4) DEFAULT (0) NOT NULL,
VolCump DECIMAL(14,4) DEFAULT (0) NOT NULL,
CasesCump INT DEFAULT (0) NOT NULL,
CajasCump INT DEFAULT (0) NOT NULL,
PaletsCump INT DEFAULT (0) NOT NULL,
TarifCump MONEY DEFAULT (0) NOT NULL,
PagoCump MONEY DEFAULT (0) NOT NULL,
UndTarCump VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndTarPagoCump VARCHAR(10) DEFAULT ('PESO'),
TipFac VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('00') NOT NULL,
FechaFac SMALLDATETIME,
TarifClieFac MONEY DEFAULT (0) NOT NULL,
TipOdp VARCHAR(3) DEFAULT ('0') NOT NULL,
NumeroOdp INT DEFAULT (0) NOT NULL,
IdCiaOdp CHAR(2) DEFAULT ('00') NOT NULL,
TarifOdp MONEY DEFAULT (0) NOT NULL,
PesoCont DECIMAL(14,4) DEFAULT (0) NOT NULL,
SedeRem VARCHAR(10),
SedeDest VARCHAR(10),
TipDocInv VARCHAR(3),
NumDocInv INT DEFAULT ((0)) NOT NULL,
IdCiaDocInv CHAR(2) DEFAULT ('00'),
ItemDocInv INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraRemMcias PRIMARY KEY CLUSTERED (TipDoc,NumOrden,IdCia,Item),
 CONSTRAINT CK_Trn_TraRemMciasCdAgencia CHECK ((len([CdAgencia]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasDescripMcias CHECK ((len([DescripMcias]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasDestinatario CHECK ((len([Destinatario]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasDirDestino CHECK ((len([DirDestino]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasDirOrigen CHECK ((len([DirOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasDocCliente CHECK ((len([DocCliente]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdCiaCump CHECK ((len([IdCiaCump]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdCiaFac CHECK ((len([IdCiaFac]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdCiaOdp CHECK ((len([IdCiaOdp]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdDestino CHECK ((len([IdDestino]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdEmp CHECK ((len([IdEmp]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdMercancia CHECK ((len([IdMercancia]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdMnjo CHECK ((len([IdMnjo]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdNat CHECK ((len([IdNat]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdOrigen CHECK ((len([IdOrigen]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdTmcia CHECK ((len([IdTmcia]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasNitDestntario CHECK ((len([NitDestntario]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasNitRemite CHECK ((len([NitRemite]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasRemitente CHECK ((len([Remitente]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasTipFac CHECK ((len([TipFac]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasTipOdp CHECK ((len([TipOdp]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasUndTarCump CHECK ((len([UndTarCump]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasUndTarifa CHECK ((len([UndTarifa]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasUndTarifPago CHECK ((len([UndTarifPago]) > 0)),
 CONSTRAINT CK_Trn_TraRemMciasUndVol CHECK ((len([UndVol]) > 0)))
CREATE TABLE Trn_TraReportes ( 
TipDoc VARCHAR(3) DEFAULT ('MUC') NOT NULL,
Manifiesto INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
CdRuta VARCHAR(4) NOT NULL,
IdPunto INT DEFAULT (0) NOT NULL,
FecReporte SMALLDATETIME NOT NULL,
TipoRep VARCHAR(10) NOT NULL,
EstadoRep INT DEFAULT (0) NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
CdNovedad VARCHAR(4),
ObservRep VARCHAR(250),
TipoPunto VARCHAR(10),
CdPuesto VARCHAR(4),
NomConductor VARCHAR(150)
 CONSTRAINT PK_Trn_TraReportes PRIMARY KEY CLUSTERED (TipDoc,Manifiesto,IdCia,Item),
 CONSTRAINT CK_Trn_TraReportesCdRuta CHECK ((len([CdRuta]) > 0)),
 CONSTRAINT CK_Trn_TraReportesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraReportesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraReportesTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_TraReportesTipoRep CHECK ((len([TipoRep]) > 0)))
CREATE TABLE Trn_Traslados ( 
TipDoc VARCHAR(3) DEFAULT ('NTS') NOT NULL,
Traslado INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConcepto VARCHAR(4) NOT NULL,
IdTercero VARCHAR(16) NOT NULL,
VrSubTotal MONEY DEFAULT (0) NOT NULL,
Cantidad DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumDcmto INT DEFAULT (0) NOT NULL,
NumOrden INT DEFAULT (0) NOT NULL,
IdCCosto VARCHAR(16) NOT NULL,
IdSubCos VARCHAR(16) NOT NULL,
Modalidad VARCHAR(10) DEFAULT ('INVENTARIO') 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,
TdOrden VARCHAR(3),
CdCiaOrden CHAR(2)
 CONSTRAINT PK_Trn_Traslados PRIMARY KEY CLUSTERED (TipDoc,Traslado,IdCia),
 CONSTRAINT CK_Trn_TrasladosIdCCosto CHECK ((len([IdCCosto]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdCiaCom CHECK ((len([IdCiaCom]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdCiaCrea CHECK ((len([IdCiaCrea]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdSubCos CHECK ((len([IdSubCos]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdTercero CHECK ((len([IdTercero]) > 0)),
 CONSTRAINT CK_Trn_TrasladosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TrasladosModalidad CHECK (([Modalidad] = 'INSUMOS' or ([Modalidad] = 'INVENTARIO' or ([Modalidad] = 'COMBUSTBLE' or [Modalidad] = 'MEZCLA')))),
 CONSTRAINT CK_Trn_TrasladosOrigenAdd CHECK ((len([OrigenAdd]) > 0)),
 CONSTRAINT CK_Trn_TrasladosTipCom CHECK ((len([TipCom]) > 0)),
 CONSTRAINT CK_Trn_TrasladosTipDoc CHECK ((len([TipDoc]) > 0)))
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 Trn_TraTrasladoRem ( 
TipDoc VARCHAR(3) DEFAULT ('TRR') NOT NULL,
Traslado 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,
ItemRem INT DEFAULT ((0)) NOT NULL,
CdBodega VARCHAR(4) NOT NULL,
EdoRecibido INT DEFAULT ((0)) NOT NULL,
Comentarios VARCHAR(250),
CdNovedad VARCHAR(4)
 CONSTRAINT PK_Trn_TraTrasladoRem PRIMARY KEY CLUSTERED (TipDoc,Traslado,IdCia,Item),
 CONSTRAINT CK_Trn_TraTrasladoRemCdBodega CHECK ((len([CdBodega])>(0))),
 CONSTRAINT CK_Trn_TraTrasladoRemIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraTrasladoRemIdCiaRem CHECK ((len([IdCiaRem])>(0))),
 CONSTRAINT CK_Trn_TraTrasladoRemTipDoc CHECK ((len([TipDoc])>(0))),
 CONSTRAINT CK_Trn_TraTrasladoRemTipRem CHECK ((len([TipRem])>(0))))
CREATE TABLE Trn_TraTraslados ( 
TipDoc VARCHAR(3) DEFAULT ('TRR') NOT NULL,
Traslado INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FecDespacho SMALLDATETIME NOT NULL,
TipoTraslado INT DEFAULT ((0)) NOT NULL,
IdBodega VARCHAR(4) NOT NULL,
IdBodDtno VARCHAR(4) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
Cantidad INT DEFAULT ((0)) NOT NULL,
PesoTotal DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
Manifiesto INT DEFAULT ((0)) NOT NULL,
CdCiaMuc CHAR(2),
EstadoRec INT DEFAULT ((0)) NOT NULL,
FechaRec SMALLDATETIME,
CedRecibido VARCHAR(16),
NomRecibido VARCHAR(150),
Observacion VARCHAR(1000),
OrigenAdd VARCHAR(10) NOT NULL,
TimeSys SMALLDATETIME NOT NULL,
IdCiaCrea CHAR(2) DEFAULT ('01') NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_TraTraslados PRIMARY KEY CLUSTERED (TipDoc,Traslado,IdCia),
 CONSTRAINT CK_Trn_TraTrasladosIdBodDtno CHECK ((len([IdBodDtno])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosIdBodega CHECK ((len([IdBodega])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosIdCia CHECK ((len([IdCia])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosIdCiaCrea CHECK ((len([IdCiaCrea])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosOrigenAdd CHECK ((len([OrigenAdd])>(0))),
 CONSTRAINT CK_Trn_TraTrasladosTipDoc CHECK ((len([TipDoc])>(0))))
CREATE TABLE Trn_TraTurn ( 
Numero INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('00') NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IndTurno INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
nRemolque VARCHAR(10),
Estado INT DEFAULT (0) NOT NULL,
TipOrd VARCHAR(3) DEFAULT ('0'),
NumOrden INT DEFAULT (0) NOT NULL,
IdCiaOrd CHAR(2),
FecOrden SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
FechaCrea SMALLDATETIME,
NitCliente VARCHAR(16),
SedeClie VARCHAR(10),
Autorizac INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Trn_TraTurn PRIMARY KEY NONCLUSTERED (Numero,IdCia),
 CONSTRAINT CK_Trn_TraTurnIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_TraTurnIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_TraTurnIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_TraTurnIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE Trn_Vales ( 
TipDoc VARCHAR(3) DEFAULT ('VAL') NOT NULL,
nRadica INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
TipoRango VARCHAR(3) NOT NULL,
IdRango INT DEFAULT (0) NOT NULL,
NumSerie VARCHAR(5) NOT NULL,
NumForma INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
HoraServ VARCHAR(10) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdCuenta VARCHAR(16) NOT NULL,
NumMovil VARCHAR(10) NOT NULL,
CentCosto VARCHAR(50) DEFAULT ('0') NOT NULL,
Unidades DECIMAL(14,4) DEFAULT (0) NOT NULL,
HoraRec DECIMAL(14,4) DEFAULT (0) NOT NULL,
HoraEspera DECIMAL(14,4) DEFAULT (0) NOT NULL,
FactUnid BIT DEFAULT (0) NOT NULL,
FactRutas BIT DEFAULT (0) NOT NULL,
FactHoras BIT DEFAULT (0) NOT NULL,
VrPago MONEY DEFAULT (0) NOT NULL,
VrCobro MONEY DEFAULT (0) NOT NULL,
PlacaVeh VARCHAR(10),
CdConductor VARCHAR(16),
NomConductor VARCHAR(150),
CantPasaj INT DEFAULT (0) NOT NULL,
Usuarios VARCHAR(1000),
TipFac VARCHAR(3) DEFAULT ('0') NOT NULL,
NumFactura INT DEFAULT (0) NOT NULL,
IdCiaFac CHAR(2) DEFAULT ('00') NOT NULL,
FechaFac SMALLDATETIME,
Anulado BIT DEFAULT (0) NOT NULL,
NumDev INT DEFAULT (0) NOT NULL,
FecDev SMALLDATETIME,
Observacion VARCHAR(1000),
FechaUp SMALLDATETIME,
CdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_Vales PRIMARY KEY CLUSTERED (TipDoc,nRadica,IdCia,Item),
 CONSTRAINT CK_Trn_ValesCdUsuario CHECK ((len([CdUsuario]) > 0)),
 CONSTRAINT CK_Trn_ValesCentCosto CHECK ((len([CentCosto]) > 0)),
 CONSTRAINT CK_Trn_ValesHoraServ CHECK ((len([HoraServ]) > 0)),
 CONSTRAINT CK_Trn_ValesIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_ValesIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ValesIdCiaFac CHECK ((len([IdCiaFac]) > 0)),
 CONSTRAINT CK_Trn_ValesIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_ValesIdCuenta CHECK ((len([IdCuenta]) > 0)),
 CONSTRAINT CK_Trn_ValesNumMovil CHECK ((len([NumMovil]) > 0)),
 CONSTRAINT CK_Trn_ValesNumSerie CHECK ((len([NumSerie]) > 0)),
 CONSTRAINT CK_Trn_ValesTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_ValesTipFac CHECK ((len([TipFac]) > 0)),
 CONSTRAINT CK_Trn_ValesTipoRango CHECK ((len([TipoRango]) > 0)))
CREATE TABLE Trn_ValesRutas ( 
TipDoc VARCHAR(3) DEFAULT ('VAL') NOT NULL,
nRadica INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
IdRuta VARCHAR(4) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifCobro MONEY DEFAULT (0) NOT NULL,
DescripRuta VARCHAR(50)
 CONSTRAINT PK_Trn_ValesRutas PRIMARY KEY CLUSTERED (TipDoc,nRadica,IdCia,Item,IdRuta),
 CONSTRAINT CK_Trn_ValesRutasIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_ValesRutasIdRuta CHECK ((len([IdRuta]) > 0)),
 CONSTRAINT CK_Trn_ValesRutasTipDoc CHECK ((len([TipDoc]) > 0)))
CREATE TABLE Trn_VehConductor ( 
IdVehiculo VARCHAR(10) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdCondNuevo VARCHAR(16) NOT NULL,
Observacion VARCHAR(150),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_VehConductor PRIMARY KEY CLUSTERED (IdVehiculo,Numero),
 CONSTRAINT CK_Trn_VehConductorIdCondNuevo CHECK ((len([IdCondNuevo]) > 0)),
 CONSTRAINT CK_Trn_VehConductorIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_Trn_VehConductorIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_VehConductorIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_VehConductorIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE Trn_VehLecturas ( 
TipDoc VARCHAR(3) DEFAULT ('LKM') NOT NULL,
Numero INT DEFAULT ((0)) NOT NULL,
IdCia CHAR(2) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipoUnidad VARCHAR(3) DEFAULT ('V') NOT NULL,
pVehiculo VARCHAR(10) NOT NULL,
KmsAnterior INT DEFAULT ((0)) NOT NULL,
KmsActual INT DEFAULT ((0)) NOT NULL,
Kms2Anterior INT DEFAULT ((0)) NOT NULL,
Kms2Actual INT DEFAULT ((0)) NOT NULL,
TipoLectura VARCHAR(10) DEFAULT ('MANUAL') NOT NULL,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_VehLecturas PRIMARY KEY CLUSTERED (TipDoc,Numero,IdCia,Item),
 CONSTRAINT CK_Trn_VehLecturasIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_Trn_VehLecturaspVehiculo CHECK ((len([pVehiculo])>(0))),
 CONSTRAINT CK_Trn_VehLecturasTipoLectura CHECK ((len([TipoLectura])>(0))),
 CONSTRAINT CK_Trn_VehLecturasTipoUnidad CHECK ((len([TipoUnidad])>(0))))
CREATE TABLE Trn_VehNumOrden ( 
IdVehiculo VARCHAR(10) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
NumOrden VARCHAR(10) NOT NULL,
NuevoNum VARCHAR(10) NOT NULL,
Observacion VARCHAR(250),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_VehNumOrden PRIMARY KEY CLUSTERED (IdVehiculo,Numero),
 CONSTRAINT CK_Trn_VehNumOrdenIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_VehNumOrdenIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_VehNumOrdenNuevoNum CHECK ((len([NuevoNum]) > 0)),
 CONSTRAINT CK_Trn_VehNumOrdenNumOrden CHECK ((len([NumOrden]) > 0)))
CREATE TABLE Trn_VehTraspasos ( 
IdVehiculo VARCHAR(10) NOT NULL,
Numero INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
IdPpd VARCHAR(4) NOT NULL,
IdPropietario VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdPropNuevo VARCHAR(16) NOT NULL,
IdPoseeNuevo VARCHAR(16) NOT NULL,
IdNewPpd VARCHAR(4) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
VrComercial MONEY DEFAULT (0) NOT NULL,
VrCupo MONEY DEFAULT (0) NOT NULL,
VrAsegurado MONEY DEFAULT (0) NOT NULL,
Observacion VARCHAR(150),
TipoAfil VARCHAR(10) DEFAULT ('TERCEROS') NOT NULL,
TipoAfilNew VARCHAR(10),
TimeSys SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Trn_VehTraspasos PRIMARY KEY CLUSTERED (IdVehiculo,Numero),
 CONSTRAINT CK_Trn_VehTraspasosIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdNewPpd CHECK ((len([IdNewPpd]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdPoseeNuevo CHECK ((len([IdPoseeNuevo]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdPpd CHECK ((len([IdPpd]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdPropNuevo CHECK ((len([IdPropNuevo]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_Trn_VehTraspasosTipoAfil CHECK ((len([TipoAfil]) > 0)))
CREATE TABLE Trn_VencAbonos ( 
TipRec VARCHAR(3) NOT NULL,
Recibo INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (0) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCiaFac CHAR(2) NOT NULL,
ItemFac INT DEFAULT (0) NOT NULL,
VrAbono MONEY DEFAULT (0) NOT NULL,
VrDescto MONEY DEFAULT (0) NOT NULL,
VrBaseCms MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
Detalle VARCHAR(150),
FecPago SMALLDATETIME NOT NULL,
TipoAplica VARCHAR(10) DEFAULT ('FACTURA') NOT NULL,
TimeSys SMALLDATETIME NOT NULL
 CONSTRAINT PK_Trn_VencAbonos PRIMARY KEY NONCLUSTERED (TipRec,Recibo,IdCia,Item),
 CONSTRAINT CK_Trn_VencAbonosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_VencAbonosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_VencAbonosIdCiaFac CHECK ((len([IdCiaFac]) > 0)),
 CONSTRAINT CK_Trn_VencAbonosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_VencAbonosIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_VencAbonosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_VencAbonosTipoAplica CHECK (([TipoAplica] = 'OTRO' or ([TipoAplica] = 'ANTICIPO' or [TipoAplica] = 'FACTURA'))),
 CONSTRAINT CK_Trn_VencAbonosTipRec CHECK ((len([TipRec]) > 0)))
CREATE TABLE Trn_Vencimientos ( 
TipDoc VARCHAR(3) DEFAULT ('FCR') NOT NULL,
Factura INT DEFAULT (0) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
Item INT DEFAULT (1) NOT NULL,
Fecha SMALLDATETIME NOT NULL,
FechaVence SMALLDATETIME NOT NULL,
VrFactura MONEY DEFAULT (0) NOT NULL,
VrAbonado MONEY DEFAULT (0) NOT NULL,
IdCliente VARCHAR(16) NOT NULL,
IdAgencia VARCHAR(16) DEFAULT ('0') NOT NULL,
IdVend VARCHAR(16) NOT NULL,
Comision DECIMAL(14,4) DEFAULT (0) NOT NULL,
TarifDcto DECIMAL(14,4) DEFAULT (0) NOT NULL,
TipoDcto CHAR(1) DEFAULT ('%') NOT NULL,
TipoBase VARCHAR(10) DEFAULT ('TOTAL') NOT NULL,
FecLmtDcto SMALLDATETIME,
IdConcepto VARCHAR(4) NOT NULL,
Referencia VARCHAR(50),
Detalle VARCHAR(150),
TipRef VARCHAR(3) DEFAULT ('0') NOT NULL,
DocRef INT DEFAULT (0) NOT NULL,
IdCiaRef CHAR(2) DEFAULT ('00') NOT NULL,
FecUltPago SMALLDATETIME,
NumNota INT DEFAULT (0) NOT NULL,
IdCiaNot CHAR(2) DEFAULT ('00') NOT NULL,
TarifInt DECIMAL(14,4) DEFAULT (0) NOT NULL,
FecLiqMora SMALLDATETIME,
FecPlazoCal SMALLDATETIME
 CONSTRAINT PK_Trn_Vencimientos PRIMARY KEY NONCLUSTERED (TipDoc,Factura,IdCia,Item),
 CONSTRAINT CK_Trn_VencimientosIdAgencia CHECK ((len([IdAgencia]) > 0)),
 CONSTRAINT CK_Trn_VencimientosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Trn_VencimientosIdCiaNot CHECK ((len([IdCiaNot]) > 0)),
 CONSTRAINT CK_Trn_VencimientosIdCiaRef CHECK ((len([IdCiaRef]) > 0)),
 CONSTRAINT CK_Trn_VencimientosIdCliente CHECK ((len([IdCliente]) > 0)),
 CONSTRAINT CK_Trn_VencimientosIdConcepto CHECK ((len([IdConcepto]) > 0)),
 CONSTRAINT CK_Trn_VencimientosIdVend CHECK ((len([IdVend]) > 0)),
 CONSTRAINT CK_Trn_VencimientosTipDoc CHECK ((len([TipDoc]) > 0)),
 CONSTRAINT CK_Trn_VencimientosTipoBase CHECK (([TipoBase] = 'SUBTOTAL' or ([TipoBase] = 'VCMTO' or [TipoBase] = 'TOTAL'))),
 CONSTRAINT CK_Trn_VencimientosTipoDcto CHECK (([TipoDcto] = '$' or [TipoDcto] = '%')),
 CONSTRAINT CK_Trn_VencimientosTipRef CHECK ((len([TipRef]) > 0)))
CREATE TABLE Turnos ( 
IdTurno VARCHAR(4) NOT NULL,
Turno VARCHAR(50) NOT NULL,
HoraInicial VARCHAR(10),
HoraFinal VARCHAR(10),
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_Turnos PRIMARY KEY CLUSTERED (IdTurno),
 CONSTRAINT CK_TurnosTurno CHECK ((len([Turno])>(0))))
CREATE TABLE UndMed ( 
IdUnd VARCHAR(4) NOT NULL,
Unidad VARCHAR(50) NOT NULL,
IdMat VARCHAR(4) NOT NULL,
IdEmp VARCHAR(4) NOT NULL,
FormRecp VARCHAR(10) DEFAULT ('FLEXIBLE') NOT NULL,
ClaseEmp VARCHAR(10) DEFAULT ('UNIDAD') NOT NULL,
DimAlto DECIMAL(14,4) DEFAULT (0) NOT NULL,
DimAncho DECIMAL(14,4) DEFAULT (0) NOT NULL,
DimLargo DECIMAL(14,4) DEFAULT (0) NOT NULL,
DimVolm DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndMed VARCHAR(10) NOT NULL,
PesoEpq DECIMAL(14,4) DEFAULT (0) NOT NULL,
CapcMax DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndCapc VARCHAR(10) NOT NULL,
SimbUnd VARCHAR(10),
Observ VARCHAR(250),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_UndMed PRIMARY KEY CLUSTERED (IdUnd),
 CONSTRAINT CK_UndMedClaseEmp CHECK (([ClaseEmp] = 'CONTENEDOR' or ([ClaseEmp] = 'EMBALAJE' or ([ClaseEmp] = 'SECUNDARIO' or ([ClaseEmp] = 'PRIMARIO' or [ClaseEmp] = 'UNIDAD'))))),
 CONSTRAINT CK_UndMedFormRecp CHECK (([FormRecp] = 'RECTNGULAR' or ([FormRecp] = 'BOTELLA' or ([FormRecp] = 'CILINDRO' or [FormRecp] = 'FLEXIBLE')))),
 CONSTRAINT CK_UndMedIdEmp CHECK ((len([IdEmp]) > 0)),
 CONSTRAINT CK_UndMedIdMat CHECK ((len([IdMat]) > 0)),
 CONSTRAINT CK_UndMedIdUnd CHECK ((len([IdUnd]) > 0)),
 CONSTRAINT CK_UndMedUndCapc CHECK ((len([UndCapc]) > 0)),
 CONSTRAINT CK_UndMedUndMed CHECK ((len([UndMed]) > 0)),
 CONSTRAINT CK_UndMedUnidad CHECK ((len([Unidad]) > 0)))
CREATE TABLE UpdateRuta ( 
Id INT IDENTITY ( 1,1 ) NOT NULL,
IdModulo INT NOT NULL,
ruta VARCHAR(250)
 CONSTRAINT PK_UpdateRuta PRIMARY KEY CLUSTERED (Id))
CREATE TABLE UpdateVersion ( 
Id INT DEFAULT ((0)) NOT NULL,
Modulo VARCHAR(30) NOT NULL,
VersionModulo INT DEFAULT ((0))
 CONSTRAINT PK_UpdateVersion PRIMARY KEY CLUSTERED (Id))
CREATE TABLE Veh_Contrato ( 
NumContrato INT DEFAULT (0) NOT NULL,
IdVehiculo VARCHAR(10) NOT NULL,
IdAdmon VARCHAR(4) NOT NULL,
IdTipCon VARCHAR(4) NOT NULL,
FecIngreso SMALLDATETIME NOT NULL,
FecRetiro SMALLDATETIME,
FecVigencia SMALLDATETIME,
Observaciones VARCHAR(250),
NumPagare VARCHAR(20),
ArchPagare VARCHAR(50),
FecUpdate SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Veh_Contrato PRIMARY KEY CLUSTERED (NumContrato),
 CONSTRAINT CK_Veh_ContratoIdAdmon CHECK ((len([IdAdmon]) > 0)),
 CONSTRAINT CK_Veh_ContratoIdTipCon CHECK ((len([IdTipCon]) > 0)),
 CONSTRAINT CK_Veh_ContratoIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Veh_ContratoIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE Veh_Cupos ( 
IdVehiculo VARCHAR(10) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
ValorCupo MONEY DEFAULT (0) NOT NULL,
ValorSaldo MONEY DEFAULT (0) NOT NULL,
FecUpdate SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_Veh_Cupos PRIMARY KEY CLUSTERED (IdVehiculo,IdClase),
 CONSTRAINT CK_Veh_CuposIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Veh_CuposIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_Veh_CuposIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE Veh_Saldos ( 
IdVehiculo VARCHAR(10) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
IdCia CHAR(2) DEFAULT ('01') NOT NULL,
ValorSaldo MONEY DEFAULT (0) NOT NULL
 CONSTRAINT PK_Veh_Saldos PRIMARY KEY CLUSTERED (IdVehiculo,IdClase,IdCia),
 CONSTRAINT CK_Veh_SaldosIdCia CHECK ((len([IdCia]) > 0)),
 CONSTRAINT CK_Veh_SaldosIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_Veh_SaldosIdVehiculo CHECK ((len([IdVehiculo]) > 0)))
CREATE TABLE VehClientes ( 
IdVehiculo VARCHAR(10) NOT NULL,
NumVeh VARCHAR(10) NOT NULL,
IdTipoVeh VARCHAR(4) NOT NULL,
IdMarca VARCHAR(4) NOT NULL,
LinMarca VARCHAR(30) NOT NULL,
ColorVeh VARCHAR(30) NOT NULL,
IdTipoMot VARCHAR(4) NOT NULL,
Modelo VARCHAR(4) NOT NULL,
ClaseMat VARCHAR(10) DEFAULT ('PARTICULAR') NOT NULL,
Cilind DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCom VARCHAR(4) NOT NULL,
IdLub VARCHAR(4) NOT NULL,
IdMarLub VARCHAR(4) NOT NULL,
IdTlla VARCHAR(4) NOT NULL,
IdMarlla VARCHAR(4) NOT NULL,
IdFiltro VARCHAR(4) NOT NULL,
IdMarFil VARCHAR(4) NOT NULL,
NumSoat VARCHAR(30) NOT NULL,
FecSoat SMALLDATETIME NOT NULL,
VigSoat SMALLDATETIME NOT NULL,
NitEmpSoat VARCHAR(16),
RevTecMec VARCHAR(30),
FecTecMec SMALLDATETIME,
VigTecMec SMALLDATETIME,
CertGases VARCHAR(30),
FecCertGas SMALLDATETIME,
VigCertGas SMALLDATETIME,
KmInicial INT DEFAULT (0) NOT NULL,
KmActual INT DEFAULT (0) NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CondPago VARCHAR(10) DEFAULT ('CONTADO') NOT NULL,
NumCredito VARCHAR(30) DEFAULT ('0') NOT NULL,
Observacion VARCHAR(250),
PathFoto VARCHAR(30),
FecPriServ SMALLDATETIME,
FecUltServ SMALLDATETIME,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_VehClientes PRIMARY KEY CLUSTERED (IdVehiculo),
 CONSTRAINT CK_VehClientesClaseMat CHECK (([ClaseMat] = 'PUBLICO' or [ClaseMat] = 'PARTICULAR')),
 CONSTRAINT CK_VehClientesColorVeh CHECK ((len([ColorVeh]) > 0)),
 CONSTRAINT CK_VehClientesCondPago CHECK ((len([CondPago]) > 0)),
 CONSTRAINT CK_VehClientesIdCom CHECK ((len([IdCom]) > 0)),
 CONSTRAINT CK_VehClientesIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_VehClientesIdFiltro CHECK ((len([IdFiltro]) > 0)),
 CONSTRAINT CK_VehClientesIdLub CHECK ((len([IdLub]) > 0)),
 CONSTRAINT CK_VehClientesIdMarca CHECK ((len([IdMarca]) > 0)),
 CONSTRAINT CK_VehClientesIdMarFil CHECK ((len([IdMarFil]) > 0)),
 CONSTRAINT CK_VehClientesIdMarlla CHECK ((len([IdMarlla]) > 0)),
 CONSTRAINT CK_VehClientesIdMarLub CHECK ((len([IdMarLub]) > 0)),
 CONSTRAINT CK_VehClientesIdTipoMot CHECK ((len([IdTipoMot]) > 0)),
 CONSTRAINT CK_VehClientesIdTipoVeh CHECK ((len([IdTipoVeh]) > 0)),
 CONSTRAINT CK_VehClientesIdTlla CHECK ((len([IdTlla]) > 0)),
 CONSTRAINT CK_VehClientesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_VehClientesIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_VehClientesLinMarca CHECK ((len([LinMarca]) > 0)),
 CONSTRAINT CK_VehClientesModelo CHECK ((len([Modelo]) > 0)),
 CONSTRAINT CK_VehClientesNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_VehClientesNumCredito CHECK ((len([NumCredito]) > 0)),
 CONSTRAINT CK_VehClientesNumSoat CHECK ((len([NumSoat]) > 0)),
 CONSTRAINT CK_VehClientesNumVeh CHECK ((len([NumVeh]) > 0)))
CREATE TABLE VehConductores ( 
IdVehiculo VARCHAR(10) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
CedConductor VARCHAR(16) NOT NULL,
TipoCond VARCHAR(10) DEFAULT ('TITULAR') NOT NULL,
FechaIng SMALLDATETIME NOT NULL,
EstadoCond INT DEFAULT (1) NOT NULL
 CONSTRAINT PK_VehConductores PRIMARY KEY CLUSTERED (IdVehiculo,Item),
 CONSTRAINT CK_VehConductoresCedConductor CHECK ((len([CedConductor]) > 0)),
 CONSTRAINT CK_VehConductoresIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_VehConductoresTipoCond CHECK ((len([TipoCond]) > 0)))
CREATE TABLE VehHoras ( 
TipoUnidad CHAR(1) DEFAULT ('V') NOT NULL,
NumUnidad VARCHAR(10) NOT NULL,
CantHoras INT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_VehHoras PRIMARY KEY CLUSTERED (TipoUnidad,NumUnidad),
 CONSTRAINT CK_VehHorasNumUnidad CHECK ((len([NumUnidad])>(0))),
 CONSTRAINT CK_VehHorasTipoUnidad CHECK ((len([TipoUnidad])>(0))))
CREATE TABLE Vehiculos ( 
IdVehiculo VARCHAR(10) NOT NULL,
NumVeh VARCHAR(10) NOT NULL,
ClaseVeh VARCHAR(10) DEFAULT ('CARGA') NOT NULL,
IdTipoVeh VARCHAR(4) NOT NULL,
IdMarca VARCHAR(4) NOT NULL,
IdLinea VARCHAR(10) NOT NULL,
IdColor VARCHAR(4) NOT NULL,
IdTipoMot VARCHAR(4) NOT NULL,
IdCrceria VARCHAR(4) NOT NULL,
Modelo VARCHAR(4) NOT NULL,
FecRep SMALLDATETIME,
Config VARCHAR(5) NOT NULL,
VehArtic BIT DEFAULT (0) NOT NULL,
NumLlan INT DEFAULT (0) NOT NULL,
NumLlans INT DEFAULT (0) NOT NULL,
IdCat VARCHAR(4) NOT NULL,
CdCatv VARCHAR(4),
ClaseMat VARCHAR(10) DEFAULT ('PARTICULAR') NOT NULL,
Cilind DECIMAL(14,4) DEFAULT (0) NOT NULL,
CapTanq DECIMAL(14,4) DEFAULT (0) NOT NULL,
IdCom VARCHAR(4) NOT NULL,
IdLub VARCHAR(4) NOT NULL,
IdTlla VARCHAR(4) NOT NULL,
IdMarlla VARCHAR(4) NOT NULL,
PesoVacio DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoMax DECIMAL(14,4) DEFAULT (0) NOT NULL,
NumMotor VARCHAR(30) NOT NULL,
SerieChasis VARCHAR(30),
NumSerie VARCHAR(30),
CdRemque VARCHAR(10),
Longitud DECIMAL(14,4) DEFAULT (0) NOT NULL,
CarrAlto DECIMAL(14,4) DEFAULT (0) NOT NULL,
CarrAncho DECIMAL(14,4) DEFAULT (0) NOT NULL,
CarrLargo DECIMAL(14,4) DEFAULT (0) NOT NULL,
CarrCapac DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndCapc VARCHAR(10) DEFAULT ('TONELADAS') NOT NULL,
Comptmtos INT DEFAULT (0) NOT NULL,
CapComp VARCHAR(50),
PasjerosPie INT DEFAULT (0) NOT NULL,
PasjerosSen INT DEFAULT (0) NOT NULL,
NitEmpresa VARCHAR(16),
IdPropietario VARCHAR(16) NOT NULL,
IdPoseedor VARCHAR(16) NOT NULL,
IdConductor VARCHAR(16) NOT NULL,
IdPpd VARCHAR(4) NOT NULL,
TipoAfil VARCHAR(10) DEFAULT ('PROPIO') NOT NULL,
Adquisc VARCHAR(10) DEFAULT ('NUEVO') NOT NULL,
NitProv VARCHAR(16),
FecCompra SMALLDATETIME NOT NULL,
VrComcial MONEY DEFAULT (0) NOT NULL,
VrAseg MONEY DEFAULT (0) NOT NULL,
VrAvaludo MONEY DEFAULT (0) NOT NULL,
VidaUtil INT DEFAULT (0) NOT NULL,
FecSalida SMALLDATETIME,
NContrato INT DEFAULT (0) NOT NULL,
IdAdmon VARCHAR(4) NOT NULL,
IdNiv VARCHAR(4) NOT NULL,
IdGrupo VARCHAR(4) NOT NULL,
CdGrupR VARCHAR(4),
CdTarifa VARCHAR(4),
FecIngreso SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME,
FecRetiro SMALLDATETIME,
NumSoat VARCHAR(30) NOT NULL,
FecSoat SMALLDATETIME NOT NULL,
VigSoat SMALLDATETIME NOT NULL,
NitEmpSoat VARCHAR(16),
TarjProp VARCHAR(30),
FecTProp SMALLDATETIME,
VigTProp SMALLDATETIME,
CdLugTp VARCHAR(8),
Ulttramite VARCHAR(150),
RespCivil VARCHAR(30),
FecRCivil SMALLDATETIME,
VigRCivil SMALLDATETIME,
RegNalCarga VARCHAR(30),
FecRegNal SMALLDATETIME,
VigRegNal SMALLDATETIME,
RevTecMec VARCHAR(30),
FecTecMec SMALLDATETIME,
VigTecMec SMALLDATETIME,
CertGases VARCHAR(30),
FecCertGas SMALLDATETIME,
VigCertGas SMALLDATETIME,
TarjOper VARCHAR(30),
FecTarjOper SMALLDATETIME,
VigTarjOper SMALLDATETIME,
KmInicial INT DEFAULT (0) NOT NULL,
KmActual INT DEFAULT (0) NOT NULL,
Km2Actual INT DEFAULT (0) NOT NULL,
Regtradora BIT DEFAULT (0) NOT NULL,
CentInicial INT DEFAULT (0) NOT NULL,
CentFinal INT DEFAULT (0) NOT NULL,
VrLmtCred MONEY DEFAULT (0) NOT NULL,
VrSaldoAct MONEY DEFAULT (0) NOT NULL,
Descripcion VARCHAR(100),
Observacion VARCHAR(250),
CdCenSer VARCHAR(4),
CdLocal VARCHAR(8),
Ubicacion VARCHAR(100),
PathFoto VARCHAR(30),
FecPriServ SMALLDATETIME,
FecUltServ SMALLDATETIME,
FecUltAcc SMALLDATETIME,
TieneAcc BIT DEFAULT (0) NOT NULL,
FecPagImp SMALLDATETIME,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaAdd SMALLDATETIME NOT NULL,
FechaUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
ValorCupo MONEY DEFAULT (0) NOT NULL,
ObligaTProd BIT DEFAULT (0) NOT NULL,
GarantiaAcc BIT DEFAULT (0) NOT NULL,
DocCompleta BIT DEFAULT (0) NOT NULL,
CertMovilizacion VARCHAR(20),
FecCertMovil SMALLDATETIME,
VigCertMovil SMALLDATETIME,
CdRutaHab VARCHAR(4),
DeclaracImp VARCHAR(50),
TipoIngreso VARCHAR(4),
IdOrgTra VARCHAR(8),
GPSoperador VARCHAR(250),
GPSUsuario VARCHAR(50),
GPSClave VARCHAR(50),
CantFiltros DECIMAL(14,4) DEFAULT ((0)) NOT NULL,
GPSIdOper VARCHAR(16)
 CONSTRAINT PK_Vehiculos PRIMARY KEY CLUSTERED (IdVehiculo),
 CONSTRAINT CK_VehiculosAdquisc CHECK (([Adquisc] = 'OTRO' or ([Adquisc] = 'REPARADO' or ([Adquisc] = 'USADO' or [Adquisc] = 'NUEVO')))),
 CONSTRAINT CK_VehiculosClaseMat CHECK (([ClaseMat] = 'PUBLICO' or [ClaseMat] = 'PARTICULAR')),
 CONSTRAINT CK_VehiculosClaseVeh CHECK (([ClaseVeh] = 'MOTO' or ([ClaseVeh] = 'ESPECIAL' or ([ClaseVeh] = 'MAQPESADA' or ([ClaseVeh] = 'MAQAGRI' or ([ClaseVeh] = 'PASAJEROS' or [ClaseVeh] = 'CARGA')))))),
 CONSTRAINT CK_VehiculosComptmtos CHECK (([Comptmtos] >= 0 and [Comptmtos] <= 5)),
 CONSTRAINT CK_VehiculosConfig CHECK ((len([Config]) > 0)),
 CONSTRAINT CK_VehiculosIdAdmon CHECK ((len([IdAdmon]) > 0)),
 CONSTRAINT CK_VehiculosIdCat CHECK ((len([IdCat]) > 0)),
 CONSTRAINT CK_VehiculosIdColor CHECK ((len([IdColor]) > 0)),
 CONSTRAINT CK_VehiculosIdCom CHECK ((len([IdCom]) > 0)),
 CONSTRAINT CK_VehiculosIdConductor CHECK ((len([IdConductor]) > 0)),
 CONSTRAINT CK_VehiculosIdCrceria CHECK ((len([IdCrceria]) > 0)),
 CONSTRAINT CK_VehiculosIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_VehiculosIdGrupo CHECK ((len([IdGrupo]) > 0)),
 CONSTRAINT CK_VehiculosIdLinea CHECK ((len([IdLinea]) > 0)),
 CONSTRAINT CK_VehiculosIdLub CHECK ((len([IdLub]) > 0)),
 CONSTRAINT CK_VehiculosIdMarca CHECK ((len([IdMarca]) > 0)),
 CONSTRAINT CK_VehiculosIdMarlla CHECK ((len([IdMarlla]) > 0)),
 CONSTRAINT CK_VehiculosIdNiv CHECK ((len([IdNiv]) > 0)),
 CONSTRAINT CK_VehiculosIdPoseedor CHECK ((len([IdPoseedor]) > 0)),
 CONSTRAINT CK_VehiculosIdPpd CHECK ((len([IdPpd]) > 0)),
 CONSTRAINT CK_VehiculosIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_VehiculosIdTipoMot CHECK ((len([IdTipoMot]) > 0)),
 CONSTRAINT CK_VehiculosIdTipoVeh CHECK ((len([IdTipoVeh]) > 0)),
 CONSTRAINT CK_VehiculosIdTlla CHECK ((len([IdTlla]) > 0)),
 CONSTRAINT CK_VehiculosIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_VehiculosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_VehiculosModelo CHECK ((len([Modelo]) > 0)),
 CONSTRAINT CK_VehiculosNumLlan CHECK (([NumLlan] >= 0 and [NumLlan] <= 99)),
 CONSTRAINT CK_VehiculosNumLlans CHECK (([NumLlans] >= 0 and [NumLlans] <= 99)),
 CONSTRAINT CK_VehiculosNumMotor CHECK ((len([NumMotor]) > 0)),
 CONSTRAINT CK_VehiculosNumSoat CHECK ((len([NumSoat]) > 0)),
 CONSTRAINT CK_VehiculosNumVeh CHECK ((len([NumVeh]) > 0)),
 CONSTRAINT CK_VehiculosTipoAfil CHECK (([TipoAfil] = 'OTRO' or ([TipoAfil] = 'TERCEROS' or ([TipoAfil] = 'AFILIADO' or [TipoAfil] = 'PROPIO')))),
 CONSTRAINT CK_VehiculosUndCapc CHECK (([UndCapc] = 'UNIDADES' or ([UndCapc] = 'SILLAS' or ([UndCapc] = 'LITROS' or ([UndCapc] = 'GALONES' or ([UndCapc] = 'KILOS' or [UndCapc] = 'TONELADAS')))))))
CREATE TABLE VehPartes ( 
IdVehiculo VARCHAR(10) NOT NULL,
NumParte VARCHAR(20) NOT NULL,
DescripParte VARCHAR(250) NOT NULL,
IdSistema VARCHAR(4) NOT NULL,
TipoControl INT DEFAULT ((0)) NOT NULL,
Intervalo_km INT DEFAULT ((0)) NOT NULL,
Intervalo_dias INT DEFAULT ((0)) NOT NULL,
Intervalo_Horas INT DEFAULT ((0)) NOT NULL,
kmActual INT DEFAULT ((0)) NOT NULL,
kmManual INT DEFAULT ((0)) NOT NULL,
kmSat INT DEFAULT ((0)) NOT NULL,
kmCambio INT DEFAULT ((0)) NOT NULL,
kmCambioMan INT DEFAULT ((0)) NOT NULL,
kmCambioSat INT DEFAULT ((0)) NOT NULL,
FechaCambio SMALLDATETIME,
CdProdRep VARCHAR(16),
TipoUnidad CHAR(1) DEFAULT ('V') NOT NULL,
TipoParte VARCHAR(10) DEFAULT ('ORIGINAL') NOT NULL,
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL,
FechaRetiro SMALLDATETIME,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL,
HorasTrab INT DEFAULT ((0)) NOT NULL,
HsUltCambio INT DEFAULT ((0)) NOT NULL,
MarcaParte VARCHAR(20),
ModeloParte VARCHAR(20),
NumSerie VARCHAR(30)
 CONSTRAINT PK_VehPartes PRIMARY KEY CLUSTERED (IdVehiculo,NumParte),
 CONSTRAINT CK_VehPartesDescripParte CHECK ((len([DescripParte])>(0))),
 CONSTRAINT CK_VehPartesIdEstado CHECK ((len([IdEstado])>(0))),
 CONSTRAINT CK_VehPartesIdSistema CHECK ((len([IdSistema])>(0))),
 CONSTRAINT CK_VehPartesIdUsuario CHECK ((len([IdUsuario])>(0))),
 CONSTRAINT CK_VehPartesIdVehiculo CHECK ((len([IdVehiculo])>(0))),
 CONSTRAINT CK_VehPartesNumParte CHECK ((len([NumParte])>(0))),
 CONSTRAINT CK_VehPartesTipoParte CHECK ((len([TipoParte])>(0))),
 CONSTRAINT CK_VehPartesTipoUnidad CHECK ((len([TipoUnidad])>(0))))
CREATE TABLE VehPolizas ( 
IdVehiculo VARCHAR(10) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
Numero VARCHAR(30) NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME NOT NULL,
NitCompania VARCHAR(16),
Valor MONEY DEFAULT (0) NOT NULL,
Comntarios VARCHAR(100),
DiasAviso INT DEFAULT (15) NOT NULL
 CONSTRAINT PK_VehPolizas PRIMARY KEY CLUSTERED (IdVehiculo,IdClase),
 CONSTRAINT CK_VehPolizasIdClase CHECK ((len([IdClase]) > 0)),
 CONSTRAINT CK_VehPolizasIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_VehPolizasNumero CHECK ((len([Numero]) > 0)))
CREATE TABLE VehPropietarios ( 
IdVehiculo VARCHAR(10) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
NitPropietario VARCHAR(16) NOT NULL,
PorcPartic DECIMAL(14,4) DEFAULT (0) NOT NULL,
FechaIng SMALLDATETIME,
EstadoProp INT DEFAULT (0)
 CONSTRAINT PK_VehPropietarios PRIMARY KEY CLUSTERED (IdVehiculo,Item),
 CONSTRAINT CK_VehPropietariosIdVehiculo CHECK ((len([IdVehiculo]) > 0)),
 CONSTRAINT CK_VehPropietariosNitPropietario CHECK ((len([NitPropietario]) > 0)))
CREATE TABLE VehRemolq ( 
IdRemque VARCHAR(10) NOT NULL,
IdMarca VARCHAR(4) NOT NULL,
IdColor VARCHAR(4) NOT NULL,
IdCrceria VARCHAR(4) NOT NULL,
Modelo VARCHAR(4) NOT NULL,
NEjes INT DEFAULT (0) NOT NULL,
nLlantas INT DEFAULT (0) NOT NULL,
ConfEjes VARCHAR(5),
Altura DECIMAL(14,4) DEFAULT (0) NOT NULL,
Ancho DECIMAL(14,4) DEFAULT (0) NOT NULL,
Largo DECIMAL(14,4) DEFAULT (0) NOT NULL,
Vlumen DECIMAL(14,4) DEFAULT (0) NOT NULL,
PesoKg DECIMAL(14,4) DEFAULT (0) NOT NULL,
Capneta DECIMAL(14,4) DEFAULT (0) NOT NULL,
UndCapc VARCHAR(10) DEFAULT ('TONELADAS') NOT NULL,
NumComp INT DEFAULT (0) NOT NULL,
CapcComp VARCHAR(50),
NumSerial VARCHAR(30),
IdPropietario VARCHAR(16) NOT NULL,
NitProv VARCHAR(16),
FecCompra SMALLDATETIME NOT NULL,
VidaUtil INT DEFAULT (0) NOT NULL,
VrComercial MONEY DEFAULT (0) NOT NULL,
VrAvaludo MONEY DEFAULT (0) NOT NULL,
VrAsegurado MONEY DEFAULT (0) NOT NULL,
Kilmetraje INT DEFAULT (0) NOT NULL,
EquipoAdic VARCHAR(50),
Descripcion VARCHAR(100),
CdCenSer VARCHAR(4),
CdLocal VARCHAR(8),
Ubicacion VARCHAR(100),
Observacion VARCHAR(250),
IdEstado VARCHAR(4) NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FecAdd SMALLDATETIME NOT NULL,
FecUpdate SMALLDATETIME,
IdUsuario VARCHAR(11) NOT NULL,
TarjetaProp VARCHAR(30),
FecTarjProp SMALLDATETIME,
VigTarjProp SMALLDATETIME,
Hidrostatica VARCHAR(30),
FecPruebaHid SMALLDATETIME,
VigPruebaHid SMALLDATETIME,
kmRuta INT DEFAULT ((0)),
kmOtro INT DEFAULT ((0)),
Kingpin VARCHAR(50),
FecKingpin SMALLDATETIME,
VigKingpin SMALLDATETIME,
ArcFotoRem VARCHAR(50),
FecVigExtintor SMALLDATETIME,
CdLocTarj VARCHAR(8)
 CONSTRAINT PK_VehRemolq PRIMARY KEY CLUSTERED (IdRemque),
 CONSTRAINT CK_VehRemolqIdColor CHECK ((len([IdColor]) > 0)),
 CONSTRAINT CK_VehRemolqIdCrceria CHECK ((len([IdCrceria]) > 0)),
 CONSTRAINT CK_VehRemolqIdEstado CHECK ((len([IdEstado]) > 0)),
 CONSTRAINT CK_VehRemolqIdMarca CHECK ((len([IdMarca]) > 0)),
 CONSTRAINT CK_VehRemolqIdPropietario CHECK ((len([IdPropietario]) > 0)),
 CONSTRAINT CK_VehRemolqIdRemque CHECK ((len([IdRemque]) > 0)),
 CONSTRAINT CK_VehRemolqIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_VehRemolqModelo CHECK ((len([Modelo]) > 0)),
 CONSTRAINT CK_VehRemolqNumComp CHECK (([NumComp] >= 0 and [NumComp] <= 5)),
 CONSTRAINT CK_VehRemolqUndCapc CHECK (([UndCapc] = 'UNIDADES' or ([UndCapc] = 'SILLAS' or ([UndCapc] = 'LITROS' or ([UndCapc] = 'GALONES' or ([UndCapc] = 'KILOS' or [UndCapc] = 'TONELADAS')))))))
CREATE TABLE VehRemPolizas ( 
IdRemque VARCHAR(10) NOT NULL,
IdClase VARCHAR(4) NOT NULL,
Numero VARCHAR(30) NOT NULL,
FecEmision SMALLDATETIME NOT NULL,
FecVigencia SMALLDATETIME NOT NULL,
NitCompania VARCHAR(16),
Valor MONEY DEFAULT ((0)) NOT NULL,
Comntarios VARCHAR(250),
DiasAviso INT DEFAULT ((15)) NOT NULL
 CONSTRAINT PK_VehRemPolizas PRIMARY KEY CLUSTERED (IdRemque,IdClase),
 CONSTRAINT CK_VehRemPolizasIdClase CHECK ((len([IdClase])>(0))),
 CONSTRAINT CK_VehRemPolizasIdRemque CHECK ((len([IdRemque])>(0))),
 CONSTRAINT CK_VehRemPolizasNumero CHECK ((len([Numero])>(0))))
CREATE TABLE Zonas ( 
IdZona VARCHAR(4) NOT NULL,
Zona VARCHAR(50) NOT NULL,
CdSubCos VARCHAR(16) DEFAULT ('0'),
Inactivo BIT DEFAULT (0) NOT NULL
 CONSTRAINT PK_Zonas PRIMARY KEY CLUSTERED (IdZona),
 CONSTRAINT CK_ZonasIdZona CHECK ((len([IdZona]) > 0)),
 CONSTRAINT CK_ZonasZona CHECK ((len([Zona]) > 0)))
GO
ALTER TABLE Activos ADD 
 CONSTRAINT FK_Activos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Activos_AfCausales FOREIGN KEY (IdCausal) REFERENCES [dbo].[AfCausales] (IdCausal),
 CONSTRAINT FK_Activos_AfEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[AfEstados] (IdEstado),
 CONSTRAINT FK_Activos_AfGrupos FOREIGN KEY (IdGrupo) REFERENCES [dbo].[AfGrupos] (IdGrupo),
 CONSTRAINT FK_Activos_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Activos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Activos_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Activos_Instalaciones FOREIGN KEY (IdInstala) REFERENCES [dbo].[Instalaciones] (IdInstala),
 CONSTRAINT FK_Activos_Terceros FOREIGN KEY (IdRespons) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Activos_Terceros1 FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_ActivosCodInvent ON Activos(CodInvent)
 CREATE NONCLUSTERED INDEX IX_ActivosCodBarras ON Activos(CodBarras)
 CREATE NONCLUSTERED INDEX IX_ActivosNumSerie ON Activos(NumSerie)
 CREATE NONCLUSTERED INDEX IX_ActivosIdGrupo ON Activos(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_ActivosIdInstala ON Activos(IdInstala)
 CREATE NONCLUSTERED INDEX IX_ActivosIdRespons ON Activos(IdRespons)
 CREATE NONCLUSTERED INDEX IX_ActivosIdCia ON Activos(IdCia)
 CREATE NONCLUSTERED INDEX IX_ActivosIdDep ON Activos(IdDep)
 CREATE NONCLUSTERED INDEX IX_ActivosNomActivo ON Activos(NomActivo)

GO
ALTER TABLE Activos_Anexo ADD 
 CONSTRAINT FK_Activos_Anexo_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo)
GO
 CREATE NONCLUSTERED INDEX IX_Activos_AnexoIdCuenta ON Activos_Anexo(IdCuenta)

GO
ALTER TABLE Activos_Partes ADD 
 CONSTRAINT FK_Activos_Partes_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Activos_Partes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Activos_Partes_AfEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[AfEstados] (IdEstado)
GO
ALTER TABLE AcuAnticipos ADD 
 CONSTRAINT FK_AcuAnticipos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuAnticipos_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuCaja ADD 
 CONSTRAINT FK_AcuCaja_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_AcuCaja_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE AcuCajaBuses ADD 
 CONSTRAINT FK_AcuCajaBuses_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_AcuCajaBuses_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE AcuClientes ADD 
 CONSTRAINT FK_AcuClientes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuClientes_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuCuentas ADD 
 CONSTRAINT FK_AcuCuentas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentas_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE AcuCuentasAge ADD 
 CONSTRAINT FK_AcuCuentasAge_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentasAge_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_AcuCuentasAge_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuCuentasAux ADD 
 CONSTRAINT FK_AcuCuentasAux_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentasAux_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
 CREATE CLUSTERED INDEX IX_AcuCuentasAuxIdCuenta ON AcuCuentasAux(nAnno,nMes,IdCuenta,IdCia,Id)
 CREATE NONCLUSTERED INDEX IX_AcuCuentasAuxCodAgncia ON AcuCuentasAux(CodAgncia)
 CREATE NONCLUSTERED INDEX IX_AcuCuentasAuxIdSubCos ON AcuCuentasAux(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_AcuCuentasAuxIdTercero ON AcuCuentasAux(IdTercero)
 CREATE NONCLUSTERED INDEX IX_AcuCuentasAuxIdCCosto ON AcuCuentasAux(IdCCosto)

GO
ALTER TABLE AcuCuentasCc ADD 
 CONSTRAINT FK_AcuCuentasCc_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_AcuCuentasCc_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentasCc_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE AcuCuentasNit ADD 
 CONSTRAINT FK_AcuCuentasNit_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentasNit_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_AcuCuentasNit_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuCuentasVeh ADD 
 CONSTRAINT FK_AcuCuentasVeh_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentasVeh_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE AcuCuentasVeht ADD 
 CONSTRAINT FK_AcuCuentasVeht_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuCuentasVeht_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
 CREATE CLUSTERED INDEX IX_AcuCuentasVehtIdVehiculo ON AcuCuentasVeht(nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo)

GO
ALTER TABLE AcuFisCuentas ADD 
 CONSTRAINT FK_AcuFisCuentas_Companias FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta),
 CONSTRAINT FK_AcuFisCuentas_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
ALTER TABLE AcuFisCuentasAge ADD 
 CONSTRAINT FK_AcuFisCuentasAge_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuFisCuentasAge_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta),
 CONSTRAINT FK_AcuFisCuentasAge_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuFisCuentasAux ADD 
 CONSTRAINT FK_AcuFisCuentasAux_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuFisCuentasAux_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
 CREATE CLUSTERED INDEX IX_AcuFisCuentasAuxIdCuenta ON AcuFisCuentasAux(nAnno,nMes,IdCuenta,IdCia,Id)
 CREATE NONCLUSTERED INDEX IX_AcuFisCuentasAuxCodAgncia ON AcuFisCuentasAux(CodAgncia)
 CREATE NONCLUSTERED INDEX IX_AcuFisCuentasAuxIdSubCos ON AcuFisCuentasAux(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_AcuFisCuentasAuxIdTercero ON AcuFisCuentasAux(IdTercero)
 CREATE NONCLUSTERED INDEX IX_AcuFisCuentasAuxIdCCosto ON AcuFisCuentasAux(IdCCosto)

GO
ALTER TABLE AcuFisCuentasCc ADD 
 CONSTRAINT FK_AcuFisCuentasCc_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_AcuFisCuentasCc_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuFisCuentasCc_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
ALTER TABLE AcuFisCuentasNit ADD 
 CONSTRAINT FK_AcuFisCuentasNit_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuFisCuentasNit_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta),
 CONSTRAINT FK_AcuFisCuentasNit_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuFisCuentasVeh ADD 
 CONSTRAINT FK_AcuFisCuentasVeh_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuFisCuentasVeh_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
ALTER TABLE AcuFisCuentasVeht ADD 
 CONSTRAINT FK_AcuFisCuentasVeht_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuFisCuentasVeht_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
 CREATE CLUSTERED INDEX IX_AcuFisCuentasVehtIdVehiculo ON AcuFisCuentasVeht(nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo)

GO
ALTER TABLE AcuInventario ADD 
 CONSTRAINT FK_AcuInventario_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_AcuInventario_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuInventario_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE AcuInvLotes ADD 
 CONSTRAINT FK_AcuInvLotes_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_AcuInvLotes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuInvLotes_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE AcuInvTallas ADD 
 CONSTRAINT FK_AcuInvTallas_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_AcuInvTallas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuInvTallas_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE CLUSTERED INDEX IX_AcuInvTallasNumTalla ON AcuInvTallas(nAnno,nMes,IdCia,IdProducto,IdBodega,NumTalla)

GO
ALTER TABLE AcuInvTanques ADD 
 CONSTRAINT FK_AcuInvTanques_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuInvTanques_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_AcuInvTanques_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque)
GO
ALTER TABLE AcuInvUbica ADD 
 CONSTRAINT FK_AcuInvUbica_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuInvUbica_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE AcuNiifCuentas ADD 
 CONSTRAINT FK_AcuNiifCuentas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentas_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
ALTER TABLE AcuNiifCuentasAge ADD 
 CONSTRAINT FK_AcuNiifCuentasAge_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentasAge_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta),
 CONSTRAINT FK_AcuNiifCuentasAge_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuNiifCuentasAux ADD 
 CONSTRAINT FK_AcuNiifCuentasAux_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentasAux_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
 CREATE CLUSTERED INDEX IX_AcuNiifCuentasAuxIdCuenta ON AcuNiifCuentasAux(nAnno,nMes,IdCuenta,IdCia,Id)
 CREATE NONCLUSTERED INDEX IX_AcuNiifCuentasAuxCodAgncia ON AcuNiifCuentasAux(CodAgncia)
 CREATE NONCLUSTERED INDEX IX_AcuNiifCuentasAuxIdSubCos ON AcuNiifCuentasAux(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_AcuNiifCuentasAuxIdCCosto ON AcuNiifCuentasAux(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_AcuNiifCuentasAuxIdTercero ON AcuNiifCuentasAux(IdTercero)

GO
ALTER TABLE AcuNiifCuentasCc ADD 
 CONSTRAINT FK_AcuNiifCuentasCc_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_AcuNiifCuentasCc_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentasCc_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
ALTER TABLE AcuNiifCuentasNit ADD 
 CONSTRAINT FK_AcuNiifCuentasNit_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentasNit_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta),
 CONSTRAINT FK_AcuNiifCuentasNit_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuNiifCuentasVeh ADD 
 CONSTRAINT FK_AcuNiifCuentasVeh_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentasVeh_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
ALTER TABLE AcuNiifCuentasVeht ADD 
 CONSTRAINT FK_AcuNiifCuentasVeht_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuNiifCuentasVeht_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta)
GO
 CREATE CLUSTERED INDEX IX_AcuNiifCuentasVehtIdVehiculo ON AcuNiifCuentasVeht(nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo)

GO
ALTER TABLE AcuOrdenes ADD 
 CONSTRAINT FK_AcuOrdenes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuOrdenes_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE AcuPrestamos ADD 
 CONSTRAINT FK_AcuPrestamos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuPrestamos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_AcuPrestamosIdCliente ON AcuPrestamos(IdCliente,IdAgencia)

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)
GO
 CREATE CLUSTERED INDEX IX_AcuPrestamosLinIdCliente ON AcuPrestamosLin(nAnno,nMes,IdCia,IdCliente,IdLinea)

GO
ALTER TABLE AcuPropietarios ADD 
 CONSTRAINT FK_AcuPropietarios_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_AcuPropietarios_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_AcuPropietarios_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_AcuPropietariosnAnno ON AcuPropietarios(nAnno,nMes,IdCia,IdPropietario,IdVehiculo)

GO
ALTER TABLE adm_Paises ADD 
 CONSTRAINT FK_adm_Paises_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda)
GO
 CREATE NONCLUSTERED INDEX IX_adm_PaisesIdMneda ON adm_Paises(IdMneda)

GO
ALTER TABLE adm_Permisos ADD 
 CONSTRAINT FK_adm_Permisos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_adm_Permisos_Sys_ObjetosApp FOREIGN KEY (IdObj) REFERENCES [dbo].[Sys_ObjetosApp] (IdObj)
GO
ALTER TABLE adm_PermisosRoles ADD 
 CONSTRAINT FK_adm_PermisosRoles_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_adm_PermisosRoles_Sys_Roles FOREIGN KEY (IdObj,IdRole) REFERENCES [dbo].[Sys_Roles] (IdObj,IdRole)
GO
 CREATE NONCLUSTERED INDEX IX_adm_PermisosRolesIdRole ON adm_PermisosRoles(IdRole)
 CREATE NONCLUSTERED INDEX IX_adm_PermisosRolesIdObj ON adm_PermisosRoles(IdObj)

GO
ALTER TABLE adm_Registro ADD 
 CONSTRAINT FK_adm_Registro_adm_Paises FOREIGN KEY (IdPais) REFERENCES [dbo].[adm_Paises] (IdPais),
 CONSTRAINT FK_adm_Registro_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_adm_Registro_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_adm_Registro_Terceros FOREIGN KEY (IdEmpresa) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_adm_RegistroIdCia ON adm_Registro(IdCia)
 CREATE NONCLUSTERED INDEX IX_adm_RegistroNitEmpresa ON adm_Registro(NitEmpresa)
 CREATE NONCLUSTERED INDEX IX_adm_RegistroIdPais ON adm_Registro(IdPais)
 CREATE NONCLUSTERED INDEX IX_adm_RegistroIdEmpresa ON adm_Registro(IdEmpresa)

GO
ALTER TABLE adm_UOpciones ADD 
 CONSTRAINT FK_adm_UOpciones_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_adm_UOpcionesIdUsuario ON adm_UOpciones(IdUsuario)

GO
ALTER TABLE adm_Usuarios ADD 
 CONSTRAINT FK_adm_Usuarios_Cargos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Cargos] (IdCargo),
 CONSTRAINT FK_adm_Usuarios_Sys_Estaciones FOREIGN KEY (IdEstacion) REFERENCES [dbo].[Sys_Estaciones] (IdEstacion),
 CONSTRAINT FK_adm_Usuarios_Sys_GruposUsu FOREIGN KEY (IdGrupo) REFERENCES [dbo].[Sys_GruposUsu] (IdGrupo)
GO
 CREATE NONCLUSTERED INDEX IX_adm_UsuariosIdGrupo ON adm_Usuarios(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_adm_UsuariosIdCargo ON adm_Usuarios(IdCargo)

GO
ALTER TABLE adm_Usucaja ADD 
 CONSTRAINT FK_adm_Usucaja_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_adm_Usucaja_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_adm_Usucaja_Sys_TFmtos FOREIGN KEY (nFormato) REFERENCES [dbo].[Sys_TFmtos] (nFormato),
 CONSTRAINT FK_adm_Usucaja_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_adm_UsucajaIdConcepto ON adm_Usucaja(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_adm_UsucajaCdBodega ON adm_Usucaja(CdBodega)
 CREATE NONCLUSTERED INDEX IX_adm_UsucajaIdVend ON adm_Usucaja(IdVend)

GO
ALTER TABLE Aduanas ADD 
 CONSTRAINT FK_Aduanas_adm_Paises FOREIGN KEY (IdPais) REFERENCES [dbo].[adm_Paises] (IdPais)
GO
ALTER TABLE AfGrupos ADD 
 CONSTRAINT FK_AfGrupos_AfLineas FOREIGN KEY (IdLinea) REFERENCES [dbo].[AfLineas] (IdLinea)
GO
ALTER TABLE AfGruposCue ADD 
 CONSTRAINT FK_AfGruposCue_AfClasesCue FOREIGN KEY (IdClase) REFERENCES [dbo].[AfClasesCue] (IdClase),
 CONSTRAINT FK_AfGruposCue_AfGrupos FOREIGN KEY (IdGrupo) REFERENCES [dbo].[AfGrupos] (IdGrupo)
GO
ALTER TABLE Agencias ADD 
 CONSTRAINT FK_Agencias_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Agencias_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_Agencias_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Agencias_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Agencias_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Agencias_Subzonas FOREIGN KEY (IdSzona) REFERENCES [dbo].[Subzonas] (IdSzona),
 CONSTRAINT FK_Agencias_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Agencias_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_AgenciasIdClie ON Agencias(IdClie)
 CREATE NONCLUSTERED INDEX IX_AgenciasIdLocal ON Agencias(IdLocal)
 CREATE NONCLUSTERED INDEX IX_AgenciasIdUsuario ON Agencias(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_AgenciasFecIngreso ON Agencias(FecIngreso)
 CREATE NONCLUSTERED INDEX IX_AgenciasNContrato ON Agencias(NContrato)

GO
ALTER TABLE AgenDocumentos ADD 
 CONSTRAINT FK_AgenDocumentos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_AgenDocumentos_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_AgenDocumentos_ClaseDocAgenc FOREIGN KEY (IdDoc) REFERENCES [dbo].[ClaseDocAgenc] (IdDoc)
GO
ALTER TABLE Areas ADD 
 CONSTRAINT FK_Areas_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto)
GO
 CREATE NONCLUSTERED INDEX IX_AreasIdCCosto ON Areas(IdCCosto)

GO
ALTER TABLE Bancos ADD 
 CONSTRAINT FK_Bancos_ClaseBan FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseBan] (IdClase)
GO
 CREATE NONCLUSTERED INDEX IX_BancosIdClase ON Bancos(IdClase)

GO
ALTER TABLE BodegasCias ADD 
 CONSTRAINT FK_BodegasCias_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_BodegasCias_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE BodUbic ADD 
 CONSTRAINT FK_BodUbic_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_BodUbic_Sys_Um FOREIGN KEY (UndCapc) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_BodUbic_Sys_Um1 FOREIGN KEY (UndPes) REFERENCES [dbo].[Sys_Um] (UndMed)
GO
 CREATE NONCLUSTERED INDEX IX_BodUbicIdBodega ON BodUbic(IdBodega)
 CREATE NONCLUSTERED INDEX IX_BodUbicUndCapc ON BodUbic(UndCapc)
 CREATE NONCLUSTERED INDEX IX_BodUbicUndPes ON BodUbic(UndPes)
 CREATE NONCLUSTERED INDEX IX_BodUbicPasillo ON BodUbic(Pasillo,Nivel,Profdad)

GO
ALTER TABLE CentrosServ ADD 
 CONSTRAINT FK_CentrosServ_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal)
GO
 CREATE NONCLUSTERED INDEX IX_CentrosServIdLocal ON CentrosServ(IdLocal)

GO
ALTER TABLE ClieContado ADD 
 CONSTRAINT FK_ClieContado_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal)
GO
ALTER TABLE Companias ADD 
 CONSTRAINT FK_Companias_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Companias_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Companias_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos)
GO
 CREATE NONCLUSTERED INDEX IX_CompaniasIdLocal ON Companias(IdLocal)

GO
ALTER TABLE CompListas ADD 
 CONSTRAINT FK_CompListas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE ConcDivCia ADD 
 CONSTRAINT FK_ConcDivCia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ConcDivCia_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto)
GO
ALTER TABLE ConcDivCue ADD 
 CONSTRAINT FK_ConcDivCue_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_ConcDivCue_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
 CREATE NONCLUSTERED INDEX IX_ConcDivCueIdCuenta ON ConcDivCue(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_ConcDivCueIdConcepto ON ConcDivCue(IdConcepto)

GO
 CREATE NONCLUSTERED INDEX IX_ConcDiversosGrupo ON ConcDiversos(Grupo)
 CREATE NONCLUSTERED INDEX IX_ConcDiversosIdUsuario ON ConcDiversos(IdUsuario)

GO
ALTER TABLE Conceptos ADD 
 CONSTRAINT FK_Conceptos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Conceptos_Sys_TiposDoc FOREIGN KEY (IdDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Conceptos_TiposCom FOREIGN KEY (IdCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
 CREATE NONCLUSTERED INDEX IX_ConceptosIdDoc ON Conceptos(IdDoc)
 CREATE NONCLUSTERED INDEX IX_ConceptosIdCom ON Conceptos(IdCom)
 CREATE NONCLUSTERED INDEX IX_ConceptosIdUsuario ON Conceptos(IdUsuario)

GO
ALTER TABLE ConceptosAdmon ADD 
 CONSTRAINT FK_ConceptosAdmon_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_ConceptosAdmon_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_ConceptosAdmon_TiposAdm FOREIGN KEY (IdAdmon) REFERENCES [dbo].[TiposAdm] (IdAdmon)
GO
ALTER TABLE ConceptosCia ADD 
 CONSTRAINT FK_ConceptosCia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE ConceptosCue ADD 
 CONSTRAINT FK_ConceptosCue_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_ConceptosCue_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
 CREATE NONCLUSTERED INDEX IX_ConceptosCueIdConcepto ON ConceptosCue(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_ConceptosCueIdCuenta ON ConceptosCue(IdCuenta)

GO
ALTER TABLE ConceptosTrib ADD 
 CONSTRAINT FK_ConceptosTrib_ClaseTar FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseTar] (IdClase)
GO
ALTER TABLE CtasCorrCia ADD 
 CONSTRAINT FK_CtasCorrCia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE CtasCorrientes ADD 
 CONSTRAINT FK_CtasCorrientes_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_CtasCorrientes_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
 CREATE NONCLUSTERED INDEX IX_CtasCorrientesIdBanco ON CtasCorrientes(IdBanco)
 CREATE NONCLUSTERED INDEX IX_CtasCorrientesIdCuenta ON CtasCorrientes(IdCuenta)

GO
ALTER TABLE Departamentos ADD 
 CONSTRAINT FK_Departamentos_adm_Paises FOREIGN KEY (IdPais) REFERENCES [dbo].[adm_Paises] (IdPais)
GO
 CREATE NONCLUSTERED INDEX IX_DepartamentosIdPais ON Departamentos(IdPais)

GO
ALTER TABLE Dependencias ADD 
 CONSTRAINT FK_Dependencias_Areas FOREIGN KEY (IdArea) REFERENCES [dbo].[Areas] (IdArea),
 CONSTRAINT FK_Dependencias_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos)
GO
 CREATE NONCLUSTERED INDEX IX_DependenciasIdArea ON Dependencias(IdArea)
 CREATE NONCLUSTERED INDEX IX_DependenciasIdSubCos ON Dependencias(IdSubCos)

GO
ALTER TABLE Diferidos ADD 
 CONSTRAINT FK_Diferidos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Diferidos_AfCausales FOREIGN KEY (IdCausal) REFERENCES [dbo].[AfCausales] (IdCausal),
 CONSTRAINT FK_Diferidos_AfEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[AfEstados] (IdEstado),
 CONSTRAINT FK_Diferidos_AfGrupos FOREIGN KEY (IdGrupo) REFERENCES [dbo].[AfGrupos] (IdGrupo),
 CONSTRAINT FK_Diferidos_AfTiposDif FOREIGN KEY (IdTipDif) REFERENCES [dbo].[AfTiposDif] (IdTipDif),
 CONSTRAINT FK_Diferidos_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Diferidos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Diferidos_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Diferidos_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Diferidos_Terceros FOREIGN KEY (IdRespons) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Diferidos_Terceros1 FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_DiferidosNomDiferido ON Diferidos(NomDiferido)
 CREATE NONCLUSTERED INDEX IX_DiferidosIdGrupo ON Diferidos(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_DiferidosIdCCosto ON Diferidos(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_DiferidosIdRespons ON Diferidos(IdRespons)
 CREATE NONCLUSTERED INDEX IX_DiferidosFecInicio ON Diferidos(FecInicio)

GO
ALTER TABLE Emp_Beneficiarios ADD 
 CONSTRAINT FK_Emp_Beneficiarios_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
ALTER TABLE Emp_Centros ADD 
 CONSTRAINT FK_Emp_Centros_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Emp_Centros_Emp_Contrato FOREIGN KEY (NContrato) REFERENCES [dbo].[Emp_Contrato] (NContrato)
GO
 CREATE CLUSTERED INDEX IX_Emp_CentrosIdCCosto ON Emp_Centros(NContrato,IdCCosto)

GO
ALTER TABLE Emp_Contrato ADD 
 CONSTRAINT FK_Emp_Contrato_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Emp_Contrato_Areas FOREIGN KEY (IdArea) REFERENCES [dbo].[Areas] (IdArea),
 CONSTRAINT FK_Emp_Contrato_Cargos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Cargos] (IdCargo),
 CONSTRAINT FK_Emp_Contrato_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Emp_Contrato_ClaseRie FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseRie] (IdClase),
 CONSTRAINT FK_Emp_Contrato_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Emp_Contrato_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Emp_Contrato_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Emp_Contrato_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Emp_Contrato_GruposAR FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposAR] (IdGrupo),
 CONSTRAINT FK_Emp_Contrato_Instalaciones FOREIGN KEY (IdInstala) REFERENCES [dbo].[Instalaciones] (IdInstala),
 CONSTRAINT FK_Emp_Contrato_Jornadas FOREIGN KEY (IdJornada) REFERENCES [dbo].[Jornadas] (IdJornada),
 CONSTRAINT FK_Emp_Contrato_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Emp_Contrato_TiposCon FOREIGN KEY (IdTipCon) REFERENCES [dbo].[TiposCon] (IdTipCon),
 CONSTRAINT FK_Emp_Contrato_TiposCot FOREIGN KEY (IdCot) REFERENCES [dbo].[TiposCot] (IdCot),
 CONSTRAINT FK_Emp_Contrato_TiposNom FOREIGN KEY (IdNom) REFERENCES [dbo].[TiposNom] (IdNom)
GO
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdEmpleado ON Emp_Contrato(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdTipCon ON Emp_Contrato(IdTipCon)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdCargo ON Emp_Contrato(IdCargo)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdJornada ON Emp_Contrato(IdJornada)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdArea ON Emp_Contrato(IdArea)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdDep ON Emp_Contrato(IdDep)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdInstala ON Emp_Contrato(IdInstala)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdCCosto ON Emp_Contrato(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdSubCos ON Emp_Contrato(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdCia ON Emp_Contrato(IdCia)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdNom ON Emp_Contrato(IdNom)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdEstado ON Emp_Contrato(IdEstado)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdUsuario ON Emp_Contrato(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Emp_ContratoIdClase ON Emp_Contrato(IdClase)

GO
ALTER TABLE Emp_Estudios ADD 
 CONSTRAINT FK_Emp_Estudios_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE NONCLUSTERED INDEX IX_Emp_EstudiosIdEmpleado ON Emp_Estudios(IdEmpleado)

GO
ALTER TABLE Emp_ExpLaboral ADD 
 CONSTRAINT FK_Emp_ExpLaboral_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
ALTER TABLE Emp_Parientes ADD 
 CONSTRAINT FK_Emp_Parientes_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
ALTER TABLE Empleados ADD 
 CONSTRAINT FK_Empleados_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Empleados_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Empleados_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_Empleados_EstadoCiv FOREIGN KEY (IdEstCivil) REFERENCES [dbo].[EstadoCiv] (IdEstado),
 CONSTRAINT FK_Empleados_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_Empleados_ExpLicencias FOREIGN KEY (IdLugar) REFERENCES [dbo].[ExpLicencias] (IdLugar),
 CONSTRAINT FK_Empleados_Fondos FOREIGN KEY (IdFonPen) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Empleados_Fondos1 FOREIGN KEY (IdFonEps) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Empleados_Fondos2 FOREIGN KEY (IdFonArp) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Empleados_Fondos3 FOREIGN KEY (IdFonCes) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Empleados_Fondos4 FOREIGN KEY (IdCajaCom) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Empleados_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Empleados_Localidades1 FOREIGN KEY (IdLugarCed) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Empleados_Profesiones FOREIGN KEY (IdProf) REFERENCES [dbo].[Profesiones] (IdProf)
GO
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdLugarCed ON Empleados(IdLugarCed)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdLocal ON Empleados(IdLocal)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdEstCivil ON Empleados(IdEstCivil)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdLugar ON Empleados(IdLugar)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdProf ON Empleados(IdProf)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdFonPen ON Empleados(IdFonPen)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdFonEps ON Empleados(IdFonEps)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdFonArp ON Empleados(IdFonArp)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdFonCes ON Empleados(IdFonCes)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdCajaCom ON Empleados(IdCajaCom)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdClase ON Empleados(IdClase)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdBanco ON Empleados(IdBanco)
 CREATE NONCLUSTERED INDEX IX_EmpleadosNContrato ON Empleados(NContrato)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdEstado ON Empleados(IdEstado)
 CREATE NONCLUSTERED INDEX IX_EmpleadosIdUsuario ON Empleados(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_EmpleadosApellidos ON Empleados(Apellidos,Nombres)

GO
ALTER TABLE Fijos ADD 
 CONSTRAINT FK_Fijos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
ALTER TABLE Fijos_Cla ADD 
 CONSTRAINT FK_Fijos_Cla_Fijos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Fijos] (IdCargo)
GO
ALTER TABLE Fijos_Cue ADD 
 CONSTRAINT FK_Fijos_Cue_Fijos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Fijos] (IdCargo),
 CONSTRAINT FK_Fijos_Cue_TiposAdm FOREIGN KEY (IdAdmon) REFERENCES [dbo].[TiposAdm] (IdAdmon)
GO
ALTER TABLE Fijos_Veh ADD 
 CONSTRAINT FK_Fijos_Veh_Fijos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Fijos] (IdCargo),
 CONSTRAINT FK_Fijos_Veh_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
ALTER TABLE FinClieSaldos ADD 
 CONSTRAINT FK_FinClieSaldos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_FinClieSaldos_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE FinClieSaldosLin ADD 
 CONSTRAINT FK_FinClieSaldosLin_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_FinClieSaldosLin_LineasCred FOREIGN KEY (IdLinea) REFERENCES [dbo].[LineasCred] (IdLinea),
 CONSTRAINT FK_FinClieSaldosLin_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE FinConcFactura ADD 
 CONSTRAINT FK_FinConcFactura_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_FinConcFactura_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE Fondos ADD 
 CONSTRAINT FK_Fondos_ClaseFon FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseFon] (IdClase),
 CONSTRAINT FK_Fondos_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_FondosIdClase ON Fondos(IdClase)
 CREATE NONCLUSTERED INDEX IX_FondosIdTercero ON Fondos(IdTercero)

GO
ALTER TABLE FormasCue ADD 
 CONSTRAINT FK_FormasCue_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_FormasCue_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_FormasCue_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE Grupos ADD 
 CONSTRAINT FK_Grupos_Lineas FOREIGN KEY (IdLinea) REFERENCES [dbo].[Lineas] (IdLinea)
GO
 CREATE NONCLUSTERED INDEX IX_GruposIdLinea ON Grupos(IdLinea)

GO
ALTER TABLE Instalaciones ADD 
 CONSTRAINT FK_Instalaciones_ClaseRie FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseRie] (IdClase)
GO
 CREATE NONCLUSTERED INDEX IX_InstalacionesIdClase ON Instalaciones(IdClase)

GO
ALTER TABLE JurCalifica ADD 
 CONSTRAINT FK_JurCalifica_JurClaseAcc FOREIGN KEY (IdClase) REFERENCES [dbo].[JurClaseAcc] (IdClase)
GO
ALTER TABLE JurCausales ADD 
 CONSTRAINT FK_JurCausales_JurTipos FOREIGN KEY (IdTipoPro) REFERENCES [dbo].[JurTipos] (IdTipoPro)
GO
ALTER TABLE JurPreguntas ADD 
 CONSTRAINT FK_JurPreguntas_JurTipos FOREIGN KEY (IdTipoPro) REFERENCES [dbo].[JurTipos] (IdTipoPro)
GO
ALTER TABLE LineasCredCue ADD 
 CONSTRAINT FK_LineasCredCue_LineasCred FOREIGN KEY (IdLinea) REFERENCES [dbo].[LineasCred] (IdLinea),
 CONSTRAINT FK_LineasCredCue_TiposTerc FOREIGN KEY (IdTipoTerc) REFERENCES [dbo].[TiposTerc] (IdTipoTerc)
GO
ALTER TABLE Localidades ADD 
 CONSTRAINT FK_Localidades_Departamentos FOREIGN KEY (IdDep) REFERENCES [dbo].[Departamentos] (IdDep)
GO
 CREATE NONCLUSTERED INDEX IX_LocalidadesIdDep ON Localidades(IdDep)

GO
ALTER TABLE Log_Nomina ADD 
 CONSTRAINT FK_Log_Nomina_TiposNom FOREIGN KEY (IdNom) REFERENCES [dbo].[TiposNom] (IdNom)
GO
ALTER TABLE Log_Periodos ADD 
 CONSTRAINT FK_Log_Periodos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
ALTER TABLE MarcasLin ADD 
 CONSTRAINT FK_MarcasLin_Marcas FOREIGN KEY (IdMarca) REFERENCES [dbo].[Marcas] (IdMarca)
GO
 CREATE NONCLUSTERED INDEX IX_MarcasLinIdMarca ON MarcasLin(IdMarca)

GO
ALTER TABLE MayBonCuentas ADD 
 CONSTRAINT FK_MayBonCuentas_MayTiposBonif FOREIGN KEY (IdBonif) REFERENCES [dbo].[MayTiposBonif] (IdBonif),
 CONSTRAINT FK_MayBonCuentas_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE MayItemsInv ADD 
 CONSTRAINT FK_MayItemsInv_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed)
GO
 CREATE NONCLUSTERED INDEX IX_MayItemsInvCdProducto ON MayItemsInv(CdProducto)

GO
ALTER TABLE Mercancias ADD 
 CONSTRAINT FK_Mercancias_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Mercancias_Empaques FOREIGN KEY (IdEmp) REFERENCES [dbo].[Empaques] (IdEmp),
 CONSTRAINT FK_Mercancias_EstadoPro FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoPro] (IdEstado),
 CONSTRAINT FK_Mercancias_GruposMcia FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposMcia] (IdGrupo),
 CONSTRAINT FK_Mercancias_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Mercancias_TiposMcia FOREIGN KEY (IdTmcia) REFERENCES [dbo].[TiposMcia] (IdTmcia),
 CONSTRAINT FK_Mercancias_TiposMnjo FOREIGN KEY (IdMnjo) REFERENCES [dbo].[TiposMnjo] (IdMnjo),
 CONSTRAINT FK_Mercancias_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Mercancias_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_MercanciasCodigoMcia ON Mercancias(CodigoMcia)

GO
ALTER TABLE MttoConceptos ADD 
 CONSTRAINT FK_MttoConceptos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_MttoConceptos_MttoSistemas FOREIGN KEY (IdSistema) REFERENCES [dbo].[MttoSistemas] (IdSistema),
 CONSTRAINT FK_MttoConceptos_MttoTipos FOREIGN KEY (IdMtto) REFERENCES [dbo].[MttoTipos] (IdMtto)
GO
ALTER TABLE MttoConcProductos ADD 
 CONSTRAINT FK_MttoConcProductos_MttoConceptos FOREIGN KEY (IdConc) REFERENCES [dbo].[MttoConceptos] (IdConc),
 CONSTRAINT FK_MttoConcProductos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE MttoControles ADD 
 CONSTRAINT FK_MttoControles_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_MttoControles_MttoConceptos FOREIGN KEY (IdConc) REFERENCES [dbo].[MttoConceptos] (IdConc)
GO
ALTER TABLE MttoInspecciones ADD 
 CONSTRAINT FK_MttoInspecciones_MttoSistemas FOREIGN KEY (IdSistema) REFERENCES [dbo].[MttoSistemas] (IdSistema),
 CONSTRAINT FK_MttoInspecciones_MttoTipos FOREIGN KEY (IdMtto) REFERENCES [dbo].[MttoTipos] (IdMtto)
GO
ALTER TABLE MttoInspecRangos ADD 
 CONSTRAINT FK_MttoInspecRangos_MttoInspecciones FOREIGN KEY (IdInspec) REFERENCES [dbo].[MttoInspecciones] (IdInspec)
GO
ALTER TABLE MudArticulos ADD 
 CONSTRAINT FK_MudArticulos_MudSecciones FOREIGN KEY (IdSeccion) REFERENCES [dbo].[MudSecciones] (IdSeccion)
GO
ALTER TABLE NomAportante ADD 
 CONSTRAINT FK_NomAportante_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_NomAportante_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_NomAportante_Terceros FOREIGN KEY (IdRepLegal) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_NomAportanteIdAportnte ON NomAportante(IdAportnte)
 CREATE NONCLUSTERED INDEX IX_NomAportanteIdRepLegal ON NomAportante(IdRepLegal)
 CREATE NONCLUSTERED INDEX IX_NomAportanteIdLocal ON NomAportante(IdLocal)
 CREATE NONCLUSTERED INDEX IX_NomAportanteIdUsuario ON NomAportante(IdUsuario)

GO
ALTER TABLE NomCapacitaciones ADD 
 CONSTRAINT FK_NomCapacitaciones_ClaseCapac FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCapac] (IdClase)
GO
ALTER TABLE NomConceptos ADD 
 CONSTRAINT FK_NomConceptos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_NomConceptosClaseCon ON NomConceptos(ClaseCon)
 CREATE NONCLUSTERED INDEX IX_NomConceptosIdUsuario ON NomConceptos(IdUsuario)

GO
ALTER TABLE NomConCuentas ADD 
 CONSTRAINT FK_NomConCuentas_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_NomConCuentas_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
 CREATE NONCLUSTERED INDEX IX_NomConCuentasNClase ON NomConCuentas(NClase)
 CREATE NONCLUSTERED INDEX IX_NomConCuentasIdCuenta ON NomConCuentas(IdCuenta)

GO
ALTER TABLE NomConOpciones ADD 
 CONSTRAINT FK_NomConOpciones_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto)
GO
 CREATE NONCLUSTERED INDEX IX_NomConOpcionesIdConcepto ON NomConOpciones(IdConcepto)

GO
ALTER TABLE NomTablaRet ADD 
 CONSTRAINT FK_NomTablaRet_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_NomTablaRetIdUsuario ON NomTablaRet(IdUsuario)

GO
 CREATE NONCLUSTERED INDEX IX_NomVehiculosNumVeh ON NomVehiculos(NumVeh)

GO
ALTER TABLE OrgTransito ADD 
 CONSTRAINT FK_OrgTransito_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal)
GO
ALTER TABLE PeajesTarf ADD 
 CONSTRAINT FK_PeajesTarf_PeajesCat FOREIGN KEY (IdCat) REFERENCES [dbo].[PeajesCat] (IdCat),
 CONSTRAINT FK_PeajesTarf_PeajesClase FOREIGN KEY (IdClase) REFERENCES [dbo].[PeajesClase] (IdClase)
GO
ALTER TABLE PlantillasCcto ADD 
 CONSTRAINT FK_PlantillasCcto_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_PlantillasCcto_PlantillasConc FOREIGN KEY (IdPlantilla,Item) REFERENCES [dbo].[PlantillasConc] (IdPlantilla,Item)
GO
ALTER TABLE PlantillasConc ADD 
 CONSTRAINT FK_PlantillasConc_Plantillas FOREIGN KEY (IdPlantilla) REFERENCES [dbo].[Plantillas] (IdPlantilla),
 CONSTRAINT FK_PlantillasConc_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE Polizas ADD 
 CONSTRAINT FK_Polizas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_PolizasNitCompania ON Polizas(NitCompania)
 CREATE NONCLUSTERED INDEX IX_PolizasNitTomador ON Polizas(NitTomador)
 CREATE NONCLUSTERED INDEX IX_PolizasNitAseg ON Polizas(NitAseg)
 CREATE NONCLUSTERED INDEX IX_PolizasNitBenef ON Polizas(NitBenef)

GO
ALTER TABLE ProdAditivos ADD 
 CONSTRAINT FK_ProdAditivos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdAditivos_ProdMcias1 FOREIGN KEY (IdAditivo) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE ProdCodigos ADD 
 CONSTRAINT FK_ProdCodigos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdCodigosIdProducto ON ProdCodigos(IdProducto)

GO
ALTER TABLE ProdCombo ADD 
 CONSTRAINT FK_ProdCombo_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdCombo_ProdMcias1 FOREIGN KEY (IdProdBas) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdComboIdProdBas ON ProdCombo(IdProdBas)

GO
ALTER TABLE ProdCompanias ADD 
 CONSTRAINT FK_ProdCompanias_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdCompanias_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE ProdCostos ADD 
 CONSTRAINT FK_ProdCostos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdCostos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdCostosIdProducto ON ProdCostos(IdProducto)
 CREATE NONCLUSTERED INDEX IX_ProdCostosIdCia ON ProdCostos(IdCia)

GO
ALTER TABLE ProdCueCrudo ADD 
 CONSTRAINT FK_ProdCueCrudo_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE UNIQUE CLUSTERED INDEX IX_ProdEstandaresCodigo ON ProdEstandares(Codigo)

GO
ALTER TABLE ProdImpFron ADD 
 CONSTRAINT FK_ProdImpFron_ClaseTar FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseTar] (IdClase),
 CONSTRAINT FK_ProdImpFron_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdImpFronIdLocal ON ProdImpFron(IdLocal)

GO
ALTER TABLE ProdImptos ADD 
 CONSTRAINT FK_ProdImptos_ClaseTar FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseTar] (IdClase),
 CONSTRAINT FK_ProdImptos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdImptosIdClase ON ProdImptos(IdClase)

GO
ALTER TABLE ProdInsumos ADD 
 CONSTRAINT FK_ProdInsumos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdInsumos_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc)
GO
 CREATE CLUSTERED INDEX IX_ProdInsumosIdProducto ON ProdInsumos(IdProducto,IdInsumo,Item)

GO
ALTER TABLE ProdMcias ADD 
 CONSTRAINT FK_ProdMcias_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_ProdMcias_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_ProdMcias_BodUbic FOREIGN KEY (IdUbic) REFERENCES [dbo].[BodUbic] (IdUbic),
 CONSTRAINT FK_ProdMcias_Empaques FOREIGN KEY (IdEmp) REFERENCES [dbo].[Empaques] (IdEmp),
 CONSTRAINT FK_ProdMcias_EstadoPro FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoPro] (IdEstado),
 CONSTRAINT FK_ProdMcias_Marcas FOREIGN KEY (IdMarca) REFERENCES [dbo].[Marcas] (IdMarca),
 CONSTRAINT FK_ProdMcias_SubGrupos FOREIGN KEY (IdSubgrupo) REFERENCES [dbo].[SubGrupos] (IdSubgrupo),
 CONSTRAINT FK_ProdMcias_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_ProdMcias_Tablapor FOREIGN KEY (IdTarIva) REFERENCES [dbo].[Tablapor] (IdTarifa),
 CONSTRAINT FK_ProdMcias_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_ProdMcias_TiposMcia FOREIGN KEY (IdTmcia) REFERENCES [dbo].[TiposMcia] (IdTmcia),
 CONSTRAINT FK_ProdMcias_TiposMnjo FOREIGN KEY (IdMnjo) REFERENCES [dbo].[TiposMnjo] (IdMnjo),
 CONSTRAINT FK_ProdMcias_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_ProdMcias_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd),
 CONSTRAINT FK_ProdMcias_UndMed1 FOREIGN KEY (IdUndP) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_ProdMciasDescripProd ON ProdMcias(DescripProd)
 CREATE NONCLUSTERED INDEX IX_ProdMciasCodBarras ON ProdMcias(CodBarras)
 CREATE NONCLUSTERED INDEX IX_ProdMciasReferencia ON ProdMcias(Referencia)
 CREATE NONCLUSTERED INDEX IX_ProdMciasTipoRef ON ProdMcias(TipoRef)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdSubgrupo ON ProdMcias(IdSubgrupo)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdMarca ON ProdMcias(IdMarca)
 CREATE NONCLUSTERED INDEX IX_ProdMciasUndMed ON ProdMcias(UndMed)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdUnd ON ProdMcias(IdUnd)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdEmp ON ProdMcias(IdEmp)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdNat ON ProdMcias(IdNat)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdMnjo ON ProdMcias(IdMnjo)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdTmcia ON ProdMcias(IdTmcia)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdBodega ON ProdMcias(IdBodega)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdProv ON ProdMcias(IdProv)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdEstado ON ProdMcias(IdEstado)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdTarIva ON ProdMcias(IdTarIva)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdUsuario ON ProdMcias(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdUndP ON ProdMcias(IdUndP)
 CREATE NONCLUSTERED INDEX IX_ProdMciasIdUbic ON ProdMcias(IdUbic)

GO
ALTER TABLE ProdNiveles ADD 
 CONSTRAINT FK_ProdNiveles_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdNiveles_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE ProdPrecCom ADD 
 CONSTRAINT FK_ProdPrecCom_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdPrecCom_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdPrecComnAnno ON ProdPrecCom(nAnno,nMes)

GO
ALTER TABLE ProdPrecCrudo ADD 
 CONSTRAINT FK_ProdPrecCrudo_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdPrecCrudo_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdPrecCrudo_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_ProdPrecCrudoIdProducto ON ProdPrecCrudo(IdProducto)
 CREATE NONCLUSTERED INDEX IX_ProdPrecCrudoFecInicio ON ProdPrecCrudo(FecInicio)

GO
ALTER TABLE ProdPrecCrudoFmla ADD 
 CONSTRAINT FK_ProdPrecCrudoFmla_ProdPrecCrudo FOREIGN KEY (TipoTarif,Numero) REFERENCES [dbo].[ProdPrecCrudo] (TipoTarif,Numero)
GO
ALTER TABLE ProdPrecios ADD 
 CONSTRAINT FK_ProdPrecios_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_ProdPrecios_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdPrecios_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdPrecios_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
ALTER TABLE ProdProcesos ADD 
 CONSTRAINT FK_ProdProcesos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdProcesos_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc)
GO
 CREATE CLUSTERED INDEX IX_ProdProcesosIdProducto ON ProdProcesos(IdProducto,IdTipProc,Item)

GO
ALTER TABLE ProdProvee ADD 
 CONSTRAINT FK_ProdProvee_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdProvee_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_ProdProvee_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_ProdProveeIdProv ON ProdProvee(IdProv)
 CREATE NONCLUSTERED INDEX IX_ProdProveeIdCia ON ProdProvee(IdCia)

GO
ALTER TABLE ProdSaldos ADD 
 CONSTRAINT FK_ProdSaldos_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_ProdSaldos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdSaldos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdSaldosIdProducto ON ProdSaldos(IdProducto)
 CREATE NONCLUSTERED INDEX IX_ProdSaldosIdBodega ON ProdSaldos(IdBodega)
 CREATE NONCLUSTERED INDEX IX_ProdSaldosIdCia ON ProdSaldos(IdCia)

GO
ALTER TABLE ProdSaldoUbc ADD 
 CONSTRAINT FK_ProdSaldoUbc_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_ProdSaldoUbc_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_ProdSaldoUbcIdProducto ON ProdSaldoUbc(IdProducto)
 CREATE NONCLUSTERED INDEX IX_ProdSaldoUbcIdUbic ON ProdSaldoUbc(IdUbic)
 CREATE NONCLUSTERED INDEX IX_ProdSaldoUbcIdCia ON ProdSaldoUbc(IdCia)

GO
ALTER TABLE Puc ADD 
 CONSTRAINT FK_Puc_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_PucIdUsuario ON Puc(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_PucRenDec ON Puc(RenDec)
 CREATE NONCLUSTERED INDEX IX_PucFmtDian ON Puc(FmtDian)
 CREATE NONCLUSTERED INDEX IX_PucConDian ON Puc(ConDian)

GO
ALTER TABLE PucNiif ADD 
 CONSTRAINT FK_PucNiif_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
ALTER TABLE Puestos ADD 
 CONSTRAINT FK_Puestos_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal)
GO
 CREATE NONCLUSTERED INDEX IX_PuestosIdLocal ON Puestos(IdLocal)
 CREATE NONCLUSTERED INDEX IX_PuestosTagPuesto ON Puestos(TagPuesto)

GO
ALTER TABLE PuntBases ADD 
 CONSTRAINT FK_PuntBases_PuntProg FOREIGN KEY (IdProgrma) REFERENCES [dbo].[PuntProg] (IdProgrma)
GO
ALTER TABLE PuntFormas ADD 
 CONSTRAINT FK_PuntFormas_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_PuntFormas_PuntProg FOREIGN KEY (IdProgrma) REFERENCES [dbo].[PuntProg] (IdProgrma)
GO
ALTER TABLE PuntPremios ADD 
 CONSTRAINT FK_PuntPremios_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_PuntPremios_PuntProg FOREIGN KEY (IdProgrma) REFERENCES [dbo].[PuntProg] (IdProgrma)
GO
 CREATE NONCLUSTERED INDEX IX_PuntPremiosIdProducto ON PuntPremios(IdProducto)

GO
ALTER TABLE PuntProg ADD 
 CONSTRAINT FK_PuntProg_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_PuntProgFecInicial ON PuntProg(FecInicial)
 CREATE NONCLUSTERED INDEX IX_PuntProgFecFinal ON PuntProg(FecFinal)

GO
ALTER TABLE PuntTarjetas ADD 
 CONSTRAINT FK_PuntTarjetas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_PuntTarjetas_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_PuntTarjetasIdClie ON PuntTarjetas(IdClie)
 CREATE NONCLUSTERED INDEX IX_PuntTarjetasFecha ON PuntTarjetas(Fecha)
 CREATE NONCLUSTERED INDEX IX_PuntTarjetasFecUltCompra ON PuntTarjetas(FecUltCompra)

GO
ALTER TABLE Rutas ADD 
 CONSTRAINT FK_Rutas_Localidades FOREIGN KEY (IdLocOri) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Rutas_Localidades1 FOREIGN KEY (IdLocDes) REFERENCES [dbo].[Localidades] (IdLocal)
GO
 CREATE NONCLUSTERED INDEX IX_RutasIdLocOri ON Rutas(IdLocOri)
 CREATE NONCLUSTERED INDEX IX_RutasIdLocDes ON Rutas(IdLocDes)

GO
ALTER TABLE RutasPlan ADD 
 CONSTRAINT FK_RutasPlan_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_RutasPlan_Rutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[Rutas] (IdRuta)
GO
 CREATE NONCLUSTERED INDEX IX_RutasPlanIdLocal ON RutasPlan(IdLocal)

GO
ALTER TABLE RutasTramos ADD 
 CONSTRAINT FK_RutasTramos_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_RutasTramos_Rutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[Rutas] (IdRuta)
GO
ALTER TABLE SobEntidades ADD 
 CONSTRAINT FK_SobEntidades_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_SobEntidades_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase)
GO
 CREATE NONCLUSTERED INDEX IX_SobEntidadesNitEntidad ON SobEntidades(NitEntidad)

GO
ALTER TABLE SobProductos ADD 
 CONSTRAINT FK_SobProductos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE SubCentros ADD 
 CONSTRAINT FK_SubCentros_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto)
GO
 CREATE NONCLUSTERED INDEX IX_SubCentrosIdCCosto ON SubCentros(IdCCosto)

GO
ALTER TABLE SubGrupos ADD 
 CONSTRAINT FK_SubGrupos_Grupos FOREIGN KEY (IdGrupo) REFERENCES [dbo].[Grupos] (IdGrupo)
GO
 CREATE NONCLUSTERED INDEX IX_SubGruposIdGrupo ON SubGrupos(IdGrupo)

GO
ALTER TABLE SubGruposAgenc ADD 
 CONSTRAINT FK_SubGruposAgenc_GruposAgenc FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposAgenc] (IdGrupo)
GO
ALTER TABLE SubgruposCc ADD 
 CONSTRAINT FK_SubgruposCc_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_SubgruposCc_SubGrupos FOREIGN KEY (IdSubgrupo) REFERENCES [dbo].[SubGrupos] (IdSubgrupo)
GO
ALTER TABLE SubgruposCue ADD 
 CONSTRAINT FK_SubgruposCue_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_SubgruposCue_SubGrupos FOREIGN KEY (IdSubgrupo) REFERENCES [dbo].[SubGrupos] (IdSubgrupo)
GO
 CREATE NONCLUSTERED INDEX IX_SubgruposCueIdCuenta ON SubgruposCue(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_SubgruposCueIdSubgrupo ON SubgruposCue(IdSubgrupo)

GO
ALTER TABLE Subzonas ADD 
 CONSTRAINT FK_Subzonas_Zonas FOREIGN KEY (IdZona) REFERENCES [dbo].[Zonas] (IdZona)
GO
 CREATE NONCLUSTERED INDEX IX_SubzonasIdZona ON Subzonas(IdZona)

GO
ALTER TABLE Sys_FmtDoc ADD 
 CONSTRAINT FK_Sys_FmtDoc_Sys_TiposDoc FOREIGN KEY (IdDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Sys_FmtDocIdDoc ON Sys_FmtDoc(IdDoc)
 CREATE NONCLUSTERED INDEX IX_Sys_FmtDocIdForma ON Sys_FmtDoc(IdForma)

GO
ALTER TABLE Sys_FmtFactura ADD 
 CONSTRAINT FK_Sys_FmtFactura_Sys_TFmtos FOREIGN KEY (nFormato) REFERENCES [dbo].[Sys_TFmtos] (nFormato),
 CONSTRAINT FK_Sys_FmtFactura_Sys_TiposDoc FOREIGN KEY (IdDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
ALTER TABLE Sys_ObjetosApp ADD 
 CONSTRAINT FK_Sys_ObjetosApp_Sys_GruposObj FOREIGN KEY (IdGrupo) REFERENCES [dbo].[Sys_GruposObj] (IdGrupo)
GO
 CREATE NONCLUSTERED INDEX IX_Sys_ObjetosAppIdGrupo ON Sys_ObjetosApp(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_Sys_ObjetosAppSubModulo ON Sys_ObjetosApp(SubModulo)

GO
ALTER TABLE Sys_Relaciones ADD 
 CONSTRAINT FK_Sys_Relaciones_Sys_Entidades FOREIGN KEY (IdTabla) REFERENCES [dbo].[Sys_Entidades] (IdTabla)
GO
 CREATE NONCLUSTERED INDEX IX_Sys_RelacionesIdTabla ON Sys_Relaciones(IdTabla)

GO
ALTER TABLE Sys_ReportSub ADD 
 CONSTRAINT FK_Sys_ReportSub_Sys_ReportFmto FOREIGN KEY (TipoRep,Formato) REFERENCES [dbo].[Sys_ReportFmto] (TipoRep,Formato)
GO
ALTER TABLE Sys_ReportSubPmt ADD 
 CONSTRAINT FK_Sys_ReportSubPmt_Sys_ReportSub FOREIGN KEY (TipoRep,Formato,NombreSub) REFERENCES [dbo].[Sys_ReportSub] (TipoRep,Formato,NombreSub)
GO
 CREATE NONCLUSTERED INDEX IX_Sys_ReportSubPmtFormato ON Sys_ReportSubPmt(TipoRep,Formato,NombreSub)

GO
ALTER TABLE Sys_Roles ADD 
 CONSTRAINT FK_Sys_Roles_Sys_ObjetosApp FOREIGN KEY (IdObj) REFERENCES [dbo].[Sys_ObjetosApp] (IdObj)
GO
 CREATE NONCLUSTERED INDEX IX_Sys_RolesIdObj ON Sys_Roles(IdObj)

GO
ALTER TABLE Sys_TiposDocCue ADD 
 CONSTRAINT FK_Sys_TiposDocCue_Sys_TiposDoc FOREIGN KEY (IdDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Sys_TiposDocCueIdDoc ON Sys_TiposDocCue(IdDoc)

GO
ALTER TABLE Tablapor ADD 
 CONSTRAINT FK_Tablapor_ClaseTar FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseTar] (IdClase)
GO
 CREATE NONCLUSTERED INDEX IX_TablaporIdClase ON Tablapor(IdClase)

GO
ALTER TABLE Talleres ADD 
 CONSTRAINT FK_Talleres_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal)
GO
ALTER TABLE TanqAforo ADD 
 CONSTRAINT FK_TanqAforo_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque)
GO
ALTER TABLE TanqAforoFrac ADD 
 CONSTRAINT FK_TanqAforoFrac_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque)
GO
ALTER TABLE TanqDispens ADD 
 CONSTRAINT FK_TanqDispens_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque)
GO
 CREATE NONCLUSTERED INDEX IX_TanqDispensIdTanque ON TanqDispens(IdTanque)

GO
ALTER TABLE TanqSaldos ADD 
 CONSTRAINT FK_TanqSaldos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_TanqSaldos_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque)
GO
 CREATE NONCLUSTERED INDEX IX_TanqSaldosIdTanque ON TanqSaldos(IdTanque)
 CREATE NONCLUSTERED INDEX IX_TanqSaldosIdCia ON TanqSaldos(IdCia)

GO
ALTER TABLE Tanques ADD 
 CONSTRAINT FK_Tanques_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_TanquesIdProducto ON Tanques(IdProducto)

GO
ALTER TABLE TarifAnticipos ADD 
 CONSTRAINT FK_TarifAnticipos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
ALTER TABLE TarifasFleMay ADD 
 CONSTRAINT FK_TarifasFleMay_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TarifasFleMay_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia)
GO
ALTER TABLE TarifasFletes ADD 
 CONSTRAINT FK_TarifasFletes_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_TarifasFletes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TarifasFletes_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TarifasFletes_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal)
GO
 CREATE NONCLUSTERED INDEX IX_TarifasFletesNitCliente ON TarifasFletes(NitCliente)
 CREATE NONCLUSTERED INDEX IX_TarifasFletesIdOrigen ON TarifasFletes(IdOrigen,IdDestino)

GO
ALTER TABLE TarifasMasivo ADD 
 CONSTRAINT FK_TarifasMasivo_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TarifasMasivo_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TarifasMasivo_TiposVeh FOREIGN KEY (IdTipoVeh) REFERENCES [dbo].[TiposVeh] (IdTipoVeh)
GO
ALTER TABLE TarifasPaq ADD 
 CONSTRAINT FK_TarifasPaq_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TarifasPaq_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal)
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)
GO
 CREATE CLUSTERED INDEX IX_TarifasServIdCliente ON TarifasServ(IdCliente,IdMercancia,IdEstacion,UndMed)

GO
ALTER TABLE TarifCuentas ADD 
 CONSTRAINT FK_TarifCuentas_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_TarifCuentas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
ALTER TABLE TaxTarifClie ADD 
 CONSTRAINT FK_TaxTarifClie_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercClieAlmac ADD 
 CONSTRAINT FK_TercClieAlmac_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_TercClieAlmac_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercClieCia ADD 
 CONSTRAINT FK_TercClieCia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_TercClieCia_TercCliente FOREIGN KEY (IdClie) REFERENCES [dbo].[TercCliente] (IdClie)
GO
ALTER TABLE TercClieCond ADD 
 CONSTRAINT FK_TercClieCond_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercClieCupos ADD 
 CONSTRAINT FK_TercClieCupos_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercClieDoc ADD 
 CONSTRAINT FK_TercClieDoc_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_TercClieDocIdCliente ON TercClieDoc(IdCliente,Item)

GO
ALTER TABLE TercClieGarant ADD 
 CONSTRAINT FK_TercClieGarant_LineasCred FOREIGN KEY (IdLinea) REFERENCES [dbo].[LineasCred] (IdLinea),
 CONSTRAINT FK_TercClieGarant_TercCliePrestamo FOREIGN KEY (IdClie,IdAgencia) REFERENCES [dbo].[TercCliePrestamo] (IdClie,IdAgencia)
GO
ALTER TABLE TercClieLineas ADD 
 CONSTRAINT FK_TercClieLineas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercClieLineas_LineasCred FOREIGN KEY (IdLinea) REFERENCES [dbo].[LineasCred] (IdLinea),
 CONSTRAINT FK_TercClieLineas_TasasInteres FOREIGN KEY (IdTasa) REFERENCES [dbo].[TasasInteres] (IdTasa),
 CONSTRAINT FK_TercClieLineas_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercCliente ADD 
 CONSTRAINT FK_TercCliente_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercCliente_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_TercCliente_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_TercCliente_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_TercCliente_Estratos FOREIGN KEY (IdEstrato) REFERENCES [dbo].[Estratos] (IdEstrato),
 CONSTRAINT FK_TercCliente_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_TercCliente_GruposCli FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposCli] (IdGrupo),
 CONSTRAINT FK_TercCliente_Localidades FOREIGN KEY (IdLocEnv) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TercCliente_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_TercCliente_Rutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[Rutas] (IdRuta),
 CONSTRAINT FK_TercCliente_Subzonas FOREIGN KEY (IdSzona) REFERENCES [dbo].[Subzonas] (IdSzona),
 CONSTRAINT FK_TercCliente_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercCliente_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_TercClienteIdLocEnv ON TercCliente(IdLocEnv)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdSzona ON TercCliente(IdSzona)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdGrupo ON TercCliente(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdPlazo ON TercCliente(IdPlazo)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdForma ON TercCliente(IdForma)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdEstrato ON TercCliente(IdEstrato)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdVend ON TercCliente(IdVend)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdRuta ON TercCliente(IdRuta)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdClase ON TercCliente(IdClase)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdBanco ON TercCliente(IdBanco)
 CREATE NONCLUSTERED INDEX IX_TercClienteUidClie ON TercCliente(UidClie)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdEstado ON TercCliente(IdEstado)
 CREATE NONCLUSTERED INDEX IX_TercClienteIdUsuario ON TercCliente(IdUsuario)

GO
ALTER TABLE TercCliePreRef ADD 
 CONSTRAINT FK_TercCliePreRef_TercCliePrestamo FOREIGN KEY (IdClie,IdAgencia) REFERENCES [dbo].[TercCliePrestamo] (IdClie,IdAgencia)
GO
ALTER TABLE TercCliePrestamo ADD 
 CONSTRAINT FK_TercCliePrestamo_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercCliePrestamo_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_TercCliePrestamo_GruposCli FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposCli] (IdGrupo),
 CONSTRAINT FK_TercCliePrestamo_Localidades FOREIGN KEY (IdLocalAge) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TercCliePrestamo_Subzonas FOREIGN KEY (IdSzona) REFERENCES [dbo].[Subzonas] (IdSzona),
 CONSTRAINT FK_TercCliePrestamo_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercCliePrestamo_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercCliePrestamo_TiposTerc FOREIGN KEY (IdTipoTerc) REFERENCES [dbo].[TiposTerc] (IdTipoTerc)
GO
ALTER TABLE TercClieRef ADD 
 CONSTRAINT FK_TercClieRef_TercCliente FOREIGN KEY (IdClie) REFERENCES [dbo].[TercCliente] (IdClie)
GO
ALTER TABLE TercClieSalarios ADD 
 CONSTRAINT FK_TercClieSalarios_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercClieSaldos ADD 
 CONSTRAINT FK_TercClieSaldos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_TercClieSaldos_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_TercClieSaldosIdClie ON TercClieSaldos(IdClie)
 CREATE NONCLUSTERED INDEX IX_TercClieSaldosIdCia ON TercClieSaldos(IdCia)

GO
ALTER TABLE TercClieVeh ADD 
 CONSTRAINT FK_TercClieVeh_TercCliente FOREIGN KEY (IdClie) REFERENCES [dbo].[TercCliente] (IdClie)
GO
ALTER TABLE TercCndCapac ADD 
 CONSTRAINT FK_TercCndCapac_ClaseCapac FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCapac] (IdClase),
 CONSTRAINT FK_TercCndCapac_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercCndContrato ADD 
 CONSTRAINT FK_TercCndContrato_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercCndContrato_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercCndContrato_TiposCon FOREIGN KEY (IdTipCon) REFERENCES [dbo].[TiposCon] (IdTipCon),
 CONSTRAINT FK_TercCndContrato_TiposMod FOREIGN KEY (IdModd) REFERENCES [dbo].[TiposMod] (IdModd)
GO
 CREATE NONCLUSTERED INDEX IX_TercCndContratoIdConductor ON TercCndContrato(IdConductor)

GO
ALTER TABLE TercCndDoc ADD 
 CONSTRAINT FK_TercCndDoc_ClaseDocCond FOREIGN KEY (IdDoc) REFERENCES [dbo].[ClaseDocCond] (IdDoc),
 CONSTRAINT FK_TercCndDoc_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercCndReferencias ADD 
 CONSTRAINT FK_TercCndReferencias_TercCndtores FOREIGN KEY (IdConductor) REFERENCES [dbo].[TercCndtores] (IdConductor)
GO
ALTER TABLE TercCndTarjetas ADD 
 CONSTRAINT FK_TercCndTarjetas_TercCndtores FOREIGN KEY (IdConductor) REFERENCES [dbo].[TercCndtores] (IdConductor)
GO
 CREATE NONCLUSTERED INDEX IX_TercCndTarjetasNumeroTarj ON TercCndTarjetas(NumeroTarj)

GO
ALTER TABLE TercCndtores ADD 
 CONSTRAINT FK_TercCndtores_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercCndtores_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_TercCndtores_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_TercCndtores_EstadoCiv FOREIGN KEY (IdEstCivil) REFERENCES [dbo].[EstadoCiv] (IdEstado),
 CONSTRAINT FK_TercCndtores_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_TercCndtores_ExpLicencias FOREIGN KEY (IdLugar) REFERENCES [dbo].[ExpLicencias] (IdLugar),
 CONSTRAINT FK_TercCndtores_GruposCli FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposCli] (IdGrupo),
 CONSTRAINT FK_TercCndtores_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercCndtores_TiposMod FOREIGN KEY (IdModd) REFERENCES [dbo].[TiposMod] (IdModd)
GO
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdGrupo ON TercCndtores(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresLicencia ON TercCndtores(Licencia)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdLugar ON TercCndtores(IdLugar)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdClase ON TercCndtores(IdClase)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdBanco ON TercCndtores(IdBanco)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdEstado ON TercCndtores(IdEstado)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdUsuario ON TercCndtores(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdModd ON TercCndtores(IdModd)
 CREATE NONCLUSTERED INDEX IX_TercCndtoresIdEstCivil ON TercCndtores(IdEstCivil)

GO
ALTER TABLE TercCuentas ADD 
 CONSTRAINT FK_TercCuentas_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_TercCuentas_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_TercCuentas_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_TercDactilarIdTercero ON TercDactilar(IdTercero,Item)

GO
ALTER TABLE Terceros ADD 
 CONSTRAINT FK_Terceros_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Terceros_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_Terceros_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Terceros_Localidades1 FOREIGN KEY (IdLugarCed) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Terceros_Profesiones FOREIGN KEY (IdProf) REFERENCES [dbo].[Profesiones] (IdProf),
 CONSTRAINT FK_Terceros_RegimenDian FOREIGN KEY (IdRegimen) REFERENCES [dbo].[RegimenDian] (IdRegimen),
 CONSTRAINT FK_Terceros_SectoresEco FOREIGN KEY (IdSector) REFERENCES [dbo].[SectoresEco] (IdSector)
GO
 CREATE NONCLUSTERED INDEX IX_TercerosRazonSocial ON Terceros(RazonSocial)
 CREATE NONCLUSTERED INDEX IX_TercerosIdLocal ON Terceros(IdLocal)
 CREATE NONCLUSTERED INDEX IX_TercerosIdSector ON Terceros(IdSector)

GO
ALTER TABLE TercOperarios ADD 
 CONSTRAINT FK_TercOperarios_Terceros FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercOperarios_TiposOperarios FOREIGN KEY (IdTipoOper) REFERENCES [dbo].[TiposOperarios] (IdOper)
GO
ALTER TABLE TercPropietario ADD 
 CONSTRAINT FK_TercPropietario_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercPropietario_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_TercPropietario_GruposPro FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposPro] (IdGrupo),
 CONSTRAINT FK_TercPropietario_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercPropietario_TiposAdm FOREIGN KEY (IdAdmon) REFERENCES [dbo].[TiposAdm] (IdAdmon),
 CONSTRAINT FK_TercPropietario_TiposCon FOREIGN KEY (IdTipCon) REFERENCES [dbo].[TiposCon] (IdTipCon)
GO
ALTER TABLE TercProvee ADD 
 CONSTRAINT FK_TercProvee_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercProvee_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_TercProvee_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_TercProvee_EstadoTer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoTer] (IdEstado),
 CONSTRAINT FK_TercProvee_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_TercProvee_GruposCli FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposCli] (IdGrupo),
 CONSTRAINT FK_TercProvee_Localidades FOREIGN KEY (IdLocOrd) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TercProvee_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_TercProvee_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_TercProveeIdGrupo ON TercProvee(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdLocOrd ON TercProvee(IdLocOrd)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdPlazo ON TercProvee(IdPlazo)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdForma ON TercProvee(IdForma)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdClase ON TercProvee(IdClase)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdBanco ON TercProvee(IdBanco)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdEstado ON TercProvee(IdEstado)
 CREATE NONCLUSTERED INDEX IX_TercProveeIdUsuario ON TercProvee(IdUsuario)

GO
ALTER TABLE TercRespFiscal ADD 
 CONSTRAINT FK_TercRespFiscal_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_TercRespFiscal_TiposRespFis FOREIGN KEY (IdResFis) REFERENCES [dbo].[TiposRespFis] (IdResFis)
GO
ALTER TABLE TercSedes ADD 
 CONSTRAINT FK_TercSedes_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE TercVendedor ADD 
 CONSTRAINT FK_TercVendedor_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TercVendedor_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_TercVendedor_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_TercVendedor_GruposCli FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposCli] (IdGrupo),
 CONSTRAINT FK_TercVendedor_Subzonas FOREIGN KEY (IdSzona) REFERENCES [dbo].[Subzonas] (IdSzona),
 CONSTRAINT FK_TercVendedor_Tablapor FOREIGN KEY (IdTarCms) REFERENCES [dbo].[Tablapor] (IdTarifa),
 CONSTRAINT FK_TercVendedor_Tablapor1 FOREIGN KEY (IdTarCm2) REFERENCES [dbo].[Tablapor] (IdTarifa),
 CONSTRAINT FK_TercVendedor_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdTarCms ON TercVendedor(IdTarCms)
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdTarCm2 ON TercVendedor(IdTarCm2)
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdSzona ON TercVendedor(IdSzona)
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdGrupo ON TercVendedor(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdUsuario ON TercVendedor(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdClase ON TercVendedor(IdClase)
 CREATE NONCLUSTERED INDEX IX_TercVendedorIdBanco ON TercVendedor(IdBanco)

GO
ALTER TABLE TiposCom ADD 
 CONSTRAINT FK_TiposCom_Diarios FOREIGN KEY (IdDiario) REFERENCES [dbo].[Diarios] (IdDiario)
GO
 CREATE NONCLUSTERED INDEX IX_TiposComIdDiario ON TiposCom(IdDiario)

GO
ALTER TABLE TiposComAgenc ADD 
 CONSTRAINT FK_TiposComAgenc_TiposAgenc FOREIGN KEY (IdTipAgenc) REFERENCES [dbo].[TiposAgenc] (IdTipAgenc)
GO
ALTER TABLE TiposComCons ADD 
 CONSTRAINT FK_TiposComCons_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_TiposComCons_TiposCom FOREIGN KEY (IdCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
ALTER TABLE TiposComFmt ADD 
 CONSTRAINT FK_TiposComFmt_TiposCom FOREIGN KEY (IdCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
ALTER TABLE TiposComNiif ADD 
 CONSTRAINT FK_TiposComNiif_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_TiposComNiif_TiposCom FOREIGN KEY (IdCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
ALTER TABLE TiposDocCons ADD 
 CONSTRAINT FK_TiposDocCons_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_TiposDocCons_Sys_TiposDoc FOREIGN KEY (IdDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
ALTER TABLE TiposVehFactor ADD 
 CONSTRAINT FK_TiposVehFactor_TiposVeh FOREIGN KEY (IdTipoVeh) REFERENCES [dbo].[TiposVeh] (IdTipoVeh)
GO
 CREATE NONCLUSTERED INDEX IX_tm_AfAmttmIdDiferido ON tm_AfAmt(tmIdDiferido)
 CREATE NONCLUSTERED INDEX IX_tm_AfAmttmIdCia ON tm_AfAmt(tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AfDeptmIdActivo ON tm_AfDep(tmIdActivo)
 CREATE NONCLUSTERED INDEX IX_tm_AfDeptmIdCia ON tm_AfDep(tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AfIngresotmIdActivo ON tm_AfIngreso(tmIdActivo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AfRetirotmIdActivo ON tm_AfRetiro(tmIdActivo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AfTrasladotmIdActivo ON tm_AfTraslado(tmIdActivo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdEmpleado ON tm_Aportes(tmIdEmpleado)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmNContto ON tm_Aportes(tmNContto)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdInstala ON tm_Aportes(tmIdInstala)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdDep ON tm_Aportes(tmIdDep)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdCCosto ON tm_Aportes(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdSubCos ON tm_Aportes(tmIdSubCos)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdNom ON tm_Aportes(tmIdNom)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdFonPen ON tm_Aportes(tmIdFonPen)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdFonSal ON tm_Aportes(tmIdFonSal)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdFonRie ON tm_Aportes(tmIdFonRie)
 CREATE NONCLUSTERED INDEX IX_tm_AportestmIdFonCaj ON tm_Aportes(tmIdFonCaj)

GO
 CREATE CLUSTERED INDEX IX_tm_AutNovDettmIdEmpleado ON tm_AutNovDet(tmIdEmpleado,tmNContrato,tmIdConcepto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AutTottmTipAdm ON tm_AutTot(tmTipAdm)
 CREATE NONCLUSTERED INDEX IX_tm_AutTottmIdFondo ON tm_AutTot(tmIdFondo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_AuxInvtmIdProducto ON tm_AuxInv(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_AuxInvtmIdCia ON tm_AuxInv(tmIdCia)

GO
 CREATE CLUSTERED INDEX IX_tm_AuxInvUbictmIdProducto ON tm_AuxInvUbic(tmEst,tmIdProducto,tmIdBodega,tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_BalAcumtmIdCia ON tm_BalAcum(tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_BalAcumtmIdTercero ON tm_BalAcum(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_BalAcumtmIdVehiculo ON tm_BalAcum(tmIdVehiculo)
 CREATE NONCLUSTERED INDEX IX_tm_BalAcumtmIdCCosto ON tm_BalAcum(tmIdCCosto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_BalComtmIdCuenta ON tm_BalCom(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_BalComtmIdTercero ON tm_BalCom(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_BalComtmIdCCosto ON tm_BalCom(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_BalComtmCodAgncia ON tm_BalCom(tmCodAgncia)

GO
 CREATE CLUSTERED INDEX IX_tm_BalComNiiftmIdCuenta ON tm_BalComNiif(tmIdCuenta,tmIdCia,tmTipo,tmIdTercero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_BalComparatmIdCuenta ON tm_BalCompara(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_BalComparatmIdCia ON tm_BalCompara(tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_BalComparatmIdTercero ON tm_BalCompara(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_BalComparatmIdCCosto ON tm_BalCompara(tmIdCCosto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_BalGentmIdCuenta ON tm_BalGen(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_BalGentmIdCia ON tm_BalGen(tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_BalPsptoIdCuenta ON tm_BalPspto(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_BalPsptoIdCCosto ON tm_BalPspto(IdCuenta,IdCCosto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CajaFecha ON tm_Caja(Fecha)
 CREATE NONCLUSTERED INDEX IX_tm_CajaIdTercero ON tm_Caja(IdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_CajaIdAgencia ON tm_Caja(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_tm_CajaIdCajero ON tm_Caja(IdCajero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CarteraFactura ON tm_Cartera(TipDoc,Factura,IdCia,Item)
 CREATE NONCLUSTERED INDEX IX_tm_CarteraFecha ON tm_Cartera(Fecha)
 CREATE NONCLUSTERED INDEX IX_tm_CarteraIdCliente ON tm_Cartera(IdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_CarteraIdVend ON tm_Cartera(IdVend)

GO
 CREATE NONCLUSTERED INDEX IX_tm_ccCuponestmIdVehiculo ON tm_ccCupones(tmIdVehiculo)
 CREATE NONCLUSTERED INDEX IX_tm_ccCuponestmDocumento ON tm_ccCupones(tmTipDoc,tmDocumento,tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_ccCuponestmIdPropietario ON tm_ccCupones(tmIdPropietario)

GO
 CREATE NONCLUSTERED INDEX IX_tm_cheqtmIdBanco ON tm_cheq(tmIdBanco)
 CREATE NONCLUSTERED INDEX IX_tm_cheqtmFecha ON tm_cheq(tmFecha)
 CREATE NONCLUSTERED INDEX IX_tm_cheqtmFecPago ON tm_cheq(tmFecPago)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CombotmIdProducto ON tm_Combo(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_CombotmIdProdBase ON tm_Combo(tmIdProdBase)
 CREATE NONCLUSTERED INDEX IX_tm_CombotmLinea ON tm_Combo(tmLinea)

GO
 CREATE NONCLUSTERED INDEX IX_tm_ComisionesFecha ON tm_Comisiones(Fecha)
 CREATE NONCLUSTERED INDEX IX_tm_ComisionesIdVend ON tm_Comisiones(IdVend)
 CREATE NONCLUSTERED INDEX IX_tm_ComisionesIdTercero ON tm_Comisiones(IdTercero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_ComptmNumero ON tm_Comp(tmNumero,tmItem)
 CREATE NONCLUSTERED INDEX IX_tm_ComptmIdCuenta ON tm_Comp(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_ComptmIdTercero ON tm_Comp(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_ComptmIdVehiculo ON tm_Comp(tmIdVehiculo)
 CREATE NONCLUSTERED INDEX IX_tm_ComptmIdCCosto ON tm_Comp(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_ComptmIdSubCos ON tm_Comp(tmIdSubCos)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CompautmIdCuenta ON tm_Compau(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_CompautmIdTercero ON tm_Compau(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_CompautmIdVehiculo ON tm_Compau(tmIdVehiculo)
 CREATE NONCLUSTERED INDEX IX_tm_CompautmIdCCosto ON tm_Compau(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_CompautmIdSubCos ON tm_Compau(tmIdSubCos)

GO
 CREATE NONCLUSTERED INDEX IX_tm_ContratostmContrato ON tm_Contratos(tmContrato,tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CxcAbonostmFactura ON tm_CxcAbonos(tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac)
 CREATE NONCLUSTERED INDEX IX_tm_CxcAbonostmIdCliente ON tm_CxcAbonos(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_CxcAbonostmIdVend ON tm_CxcAbonos(tmIdVend)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CxCobrartmFecVence ON tm_CxCobrar(tmFecVence)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CxPagartmIdProveedor ON tm_CxPagar(tmIdProveedor)
 CREATE NONCLUSTERED INDEX IX_tm_CxPagartmIdCuenta ON tm_CxPagar(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_CxPagartmDocumento ON tm_CxPagar(tmDocumento)

GO
 CREATE NONCLUSTERED INDEX IX_tm_CxpAplicatmIdProveedor ON tm_CxpAplica(tmIdProveedor)
 CREATE NONCLUSTERED INDEX IX_tm_CxpAplicatmIdCuenta ON tm_CxpAplica(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_CxpAplicatmFactura ON tm_CxpAplica(tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmIdProveedor)

GO
 CREATE NONCLUSTERED INDEX IX_tm_DetCuetmConcepto ON tm_DetCue(tmConcepto)
 CREATE NONCLUSTERED INDEX IX_tm_DetCuetmIdCuenta ON tm_DetCue(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_DetCuetmIdTercero ON tm_DetCue(tmIdTercero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_DiarioNumero ON tm_Diario(TipDoc,Numero,IdCia)
 CREATE NONCLUSTERED INDEX IX_tm_DiarioIdTercero ON tm_Diario(IdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_DiarioIdCajero ON tm_Diario(IdCajero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_DifIngresotmIdDiferido ON tm_DifIngreso(tmIdDiferido)

GO
 CREATE NONCLUSTERED INDEX IX_tm_EdsFormastmTipoRango ON tm_EdsFormas(tmTipoRango)
 CREATE NONCLUSTERED INDEX IX_tm_EdsFormastmIdForma ON tm_EdsFormas(tmIdForma)
 CREATE NONCLUSTERED INDEX IX_tm_EdsFormastmIdRango ON tm_EdsFormas(tmIdRango)
 CREATE NONCLUSTERED INDEX IX_tm_EdsFormastmNumForma ON tm_EdsFormas(tmNumSerie,tmNumForma)

GO
 CREATE NONCLUSTERED INDEX IX_tm_EstadoGyptmIdCuenta ON tm_EstadoGyp(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_EstadoGyptmIdTercero ON tm_EstadoGyp(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_EstadoGyptmIdCCosto ON tm_EstadoGyp(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_EstadoGyptmIdSubCos ON tm_EstadoGyp(tmIdSubCos)

GO
 CREATE NONCLUSTERED INDEX IX_tm_EstClientestmIdCliente ON tm_EstClientes(tmIdCliente)

GO
 CREATE NONCLUSTERED INDEX IX_tm_EstCueCtetmIdCliente ON tm_EstCueCte(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_EstCueCtetmIdVehiculo ON tm_EstCueCte(tmIdVehiculo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_EVcautmFecha ON tm_EVcau(tmFecha)
 CREATE NONCLUSTERED INDEX IX_tm_EVcautmIdCliente ON tm_EVcau(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_EVcautmIdVehiculo ON tm_EVcau(tmIdVehiculo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_EVrectmIdCliente ON tm_EVrec(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_EVrectmIdVehiculo ON tm_EVrec(tmIdVehiculo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_ForItemstmIdProducto ON tm_ForItems(tmIdProducto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_InfDiarioNumero ON tm_InfDiario(TipDoc,Numero,IdCia)
 CREATE NONCLUSTERED INDEX IX_tm_InfDiarioFecha ON tm_InfDiario(Fecha)
 CREATE NONCLUSTERED INDEX IX_tm_InfDiarioIdTercero ON tm_InfDiario(IdTercero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmNMes ON tm_Ingresos(tmNMes)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdEmpleado ON tm_Ingresos(tmIdEmpleado)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdConcepto ON tm_Ingresos(tmIdConcepto)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmNContrato ON tm_Ingresos(tmNContrato)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdDep ON tm_Ingresos(tmIdDep)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdCCosto ON tm_Ingresos(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdSubCos ON tm_Ingresos(tmIdSubCos)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdNom ON tm_Ingresos(tmIdNom)
 CREATE NONCLUSTERED INDEX IX_tm_IngresostmIdInstala ON tm_Ingresos(tmIdInstala)

GO
 CREATE NONCLUSTERED INDEX IX_tm_IntNominatmIdEmpleado ON tm_IntNomina(tmIdEmpleado)

GO
 CREATE NONCLUSTERED INDEX IX_tm_KarUbitmIdProducto ON tm_KarUbi(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_KarUbitmIdBodega ON tm_KarUbi(tmIdBodega)
 CREATE NONCLUSTERED INDEX IX_tm_KarUbitmIdUbic ON tm_KarUbi(tmIdUbic)
 CREATE NONCLUSTERED INDEX IX_tm_KarUbitmLinea ON tm_KarUbi(tmLinea)

GO
 CREATE NONCLUSTERED INDEX IX_tm_KdextmIdProducto ON tm_Kdex(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_KdextmIdBodega ON tm_Kdex(tmIdBodega)
 CREATE NONCLUSTERED INDEX IX_tm_KdextmIdUnd ON tm_Kdex(tmIdUnd)
 CREATE NONCLUSTERED INDEX IX_tm_KdextmIdVend ON tm_Kdex(tmIdVend)
 CREATE NONCLUSTERED INDEX IX_tm_KdextmIdTercero ON tm_Kdex(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_KdextmItemCbo ON tm_Kdex(tmItemCbo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_LibOftmIdCuenta ON tm_LibOf(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_LibOftmIdTercero ON tm_LibOf(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_LibOftmIdCCosto ON tm_LibOf(tmIdCCosto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_LottmLinea ON tm_Lot(tmLinea)
 CREATE NONCLUSTERED INDEX IX_tm_LottmNumLote ON tm_Lot(tmNumLote)
 CREATE NONCLUSTERED INDEX IX_tm_LottmIdProducto ON tm_Lot(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_LottmIdBodega ON tm_Lot(tmIdBodega)
 CREATE NONCLUSTERED INDEX IX_tm_LottmFecVence ON tm_Lot(tmFecVence)

GO
 CREATE NONCLUSTERED INDEX IX_tm_MovClientestmFecha ON tm_MovClientes(tmFecha)
 CREATE NONCLUSTERED INDEX IX_tm_MovClientestmIdCliente ON tm_MovClientes(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_MovClientestmIdAgencia ON tm_MovClientes(tmIdAgencia)
 CREATE NONCLUSTERED INDEX IX_tm_MovClientestmIdVend ON tm_MovClientes(tmEst,tmIdVend)
 CREATE NONCLUSTERED INDEX IX_tm_MovClientestmTimeSys ON tm_MovClientes(tmTimeSys)

GO
 CREATE CLUSTERED INDEX IX_tm_MovCueIdCuenta ON tm_MovCue(tmEst,IdCuenta,Id)

GO
 CREATE NONCLUSTERED INDEX IX_tm_MovInventtmIdCliente ON tm_MovInvent(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_MovInventtmIdProducto ON tm_MovInvent(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_MovInventtmIdCia ON tm_MovInvent(tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_MovInventtmFecha ON tm_MovInvent(tmFecha)

GO
 CREATE NONCLUSTERED INDEX IX_tm_MovTanquestmIdProducto ON tm_MovTanques(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_MovTanquestmFecha ON tm_MovTanques(tmFecha)

GO
 CREATE NONCLUSTERED INDEX IX_tm_MovVentastmIdProducto ON tm_MovVentas(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_MovVentastmIdCliente ON tm_MovVentas(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_MovVentastmFecha ON tm_MovVentas(tmFecha)

GO
 CREATE NONCLUSTERED INDEX IX_tm_NiifComtmIdVehiculo ON tm_NiifCom(tmIdVehiculo)
 CREATE NONCLUSTERED INDEX IX_tm_NiifComtmIdTercero ON tm_NiifCom(tmIdTercero)
 CREATE NONCLUSTERED INDEX IX_tm_NiifComtmIdCCosto ON tm_NiifCom(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_NiifComtmCodAgncia ON tm_NiifCom(tmCodAgncia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_NiifGentmIdCuenta ON tm_NiifGen(tmIdCuenta)
 CREATE NONCLUSTERED INDEX IX_tm_NiifGentmIdCia ON tm_NiifGen(tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_NiifGyptmIdTercero ON tm_NiifGyp(tmIdTercero,tmCodAgncia)
 CREATE NONCLUSTERED INDEX IX_tm_NiifGyptmIdCCosto ON tm_NiifGyp(tmIdCCosto)
 CREATE NONCLUSTERED INDEX IX_tm_NiifGyptmIdSubCos ON tm_NiifGyp(tmIdSubCos)

GO
 CREATE CLUSTERED INDEX IX_tm_NiifLibtmIdCuenta ON tm_NiifLib(tmEst,tmTipCom,tmIdCuenta,tmIdTercero,tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_NiifLibtmIdCCosto ON tm_NiifLib(tmIdCCosto,tmIdSubCos)

GO
 CREATE CLUSTERED INDEX IX_tm_NiifMovIdCuenta ON tm_NiifMov(tmEst,IdCuenta,Id)

GO
 CREATE NONCLUSTERED INDEX IX_tm_NomHorastmNContrato ON tm_NomHoras(tmNContrato)
 CREATE NONCLUSTERED INDEX IX_tm_NomHorastmIdEmpleado ON tm_NomHoras(tmIdEmpleado)
 CREATE NONCLUSTERED INDEX IX_tm_NomHorastmIdCCosto ON tm_NomHoras(tmIdCCosto)

GO
 CREATE NONCLUSTERED INDEX IX_tm_NominatmIdEmpleado ON tm_Nomina(tmIdEmpleado)
 CREATE NONCLUSTERED INDEX IX_tm_NominatmItem ON tm_Nomina(tmItem)
 CREATE NONCLUSTERED INDEX IX_tm_NominatmIdConcepto ON tm_Nomina(tmIdConcepto)
 CREATE NONCLUSTERED INDEX IX_tm_NominatmClaseCon ON tm_Nomina(tmClaseCon)
 CREATE NONCLUSTERED INDEX IX_tm_NominatmClaseLiq ON tm_Nomina(tmClaseLiq)
 CREATE NONCLUSTERED INDEX IX_tm_NominatmNPrestamo ON tm_Nomina(tmNPrestamo)

GO
 CREATE NONCLUSTERED INDEX IX_tm_NomRestmNContrato ON tm_NomRes(tmNContrato)
 CREATE NONCLUSTERED INDEX IX_tm_NomRestmIdEmpleado ON tm_NomRes(tmIdEmpleado)

GO
 CREATE NONCLUSTERED INDEX IX_tm_PagostmIdForma ON tm_Pagos(tmIdForma)
 CREATE NONCLUSTERED INDEX IX_tm_PagostmIdBanco ON tm_Pagos(tmIdBanco)
 CREATE NONCLUSTERED INDEX IX_tm_PagostmNitCliente ON tm_Pagos(tmNitCliente)
 CREATE NONCLUSTERED INDEX IX_tm_PagostmDocRef ON tm_Pagos(tmTipRef,tmDocRef,tmIdCiaRef)

GO
 CREATE NONCLUSTERED INDEX IX_tm_PreCarteraIdCliente ON tm_PreCartera(IdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_PreCarteraIdVend ON tm_PreCartera(IdVend)
 CREATE NONCLUSTERED INDEX IX_tm_PreCarteraIdAgencia ON tm_PreCartera(IdAgencia)

GO
 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)

GO
 CREATE NONCLUSTERED INDEX IX_tm_PreIntMoratmIdCliente ON tm_PreIntMora(tmIdCliente)
 CREATE NONCLUSTERED INDEX IX_tm_PreIntMoratmPrestamo ON tm_PreIntMora(tmTipDoc,tmPrestamo,tmIdCia,tmItemPre)

GO
 CREATE NONCLUSTERED INDEX IX_tm_PreMovitmFecha ON tm_PreMovi(tmFecha)
 CREATE NONCLUSTERED INDEX IX_tm_PreMovitmIdCliente ON tm_PreMovi(tmIdCliente)

GO
 CREATE NONCLUSTERED INDEX IX_tm_RecAplicatmDocumento ON tm_RecAplica(tmTipoDoc,tmDocumento,tmIdCiaDoc,tmItemDoc)

GO
 CREATE NONCLUSTERED INDEX IX_tm_ResMensualtmCodigo ON tm_ResMensual(tmCodigo)
 CREATE NONCLUSTERED INDEX IX_tm_ResMensualtmIdCia ON tm_ResMensual(tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_ResMensualtmIdTercero ON tm_ResMensual(tmIdTercero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_SaldostmIdCuenta ON tm_Saldos(tmIdCuenta,tmIdTercero)

GO
 CREATE NONCLUSTERED INDEX IX_tm_SemanastmVehiculo ON tm_Semanas(tmVehiculo,tmSemana)

GO
 CREATE NONCLUSTERED INDEX IX_tm_SertmIdProducto ON tm_Ser(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_SertmNumSerial ON tm_Ser(tmNumSerial)
 CREATE NONCLUSTERED INDEX IX_tm_SertmIdCia ON tm_Ser(tmIdCia)
 CREATE NONCLUSTERED INDEX IX_tm_SertmIdBodega ON tm_Ser(tmIdBodega)
 CREATE NONCLUSTERED INDEX IX_tm_SertmIdEstado ON tm_Ser(tmIdEstado)
 CREATE NONCLUSTERED INDEX IX_tm_SertmLinea ON tm_Ser(tmLinea)

GO
 CREATE NONCLUSTERED INDEX IX_tm_TraAnttmAnticipo ON tm_TraAnt(tmTipAnt,tmAnticipo,tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_TraDetConctmIdConcepto ON tm_TraDetConc(tmIdConcepto)
 CREATE NONCLUSTERED INDEX IX_tm_TraDetConctmCdCuenta ON tm_TraDetConc(tmCdCuenta)

GO
 CREATE CLUSTERED INDEX IX_tm_TraInfOperIdVehiculo ON tm_TraInfOper(IdEst,IdOperario,IdVehiculo)

GO
 CREATE CLUSTERED INDEX IX_tm_TraMovAntIdPoseedor ON tm_TraMovAnt(IdEst,IdPoseedor,IdVehiculo,IdCia)
 CREATE NONCLUSTERED INDEX IX_tm_TraMovAntNumero ON tm_TraMovAnt(TipDoc,Numero,IdCia)

GO
 CREATE CLUSTERED INDEX IX_tm_TraMovLiquidatmFecha ON tm_TraMovLiquida(tmEst,tmFecha,tmIdPoseedor,tmIdVehiculo,tmIdCia)

GO
 CREATE NONCLUSTERED INDEX IX_tm_TraRemCumtmRemesa ON tm_TraRemCum(tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem)

GO
 CREATE NONCLUSTERED INDEX IX_tm_TraRemFacttmRemesa ON tm_TraRemFact(tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem)

GO
 CREATE NONCLUSTERED INDEX IX_tm_vencetmIdPropietario ON tm_vence(tmIdPropietario)
 CREATE NONCLUSTERED INDEX IX_tm_vencetmIdVehiculo ON tm_vence(tmIdVehiculo)
 CREATE NONCLUSTERED INDEX IX_tm_vencetmFecEmision ON tm_vence(tmFecEmision)

GO
 CREATE NONCLUSTERED INDEX IX_tm_VentastmIdProducto ON tm_Ventas(tmIdProducto)
 CREATE NONCLUSTERED INDEX IX_tm_VentastmTipDoc ON tm_Ventas(tmTipDoc)
 CREATE NONCLUSTERED INDEX IX_tm_VentastmIdCliente ON tm_Ventas(tmIdCliente)

GO
ALTER TABLE tm_VentasCom ADD 
 CONSTRAINT FK_tm_VentasCom_tm_Ventas FOREIGN KEY (tmEst,tmItem) REFERENCES [dbo].[tm_Ventas] (tmEst,tmItem)
GO
ALTER TABLE tm_VentasDet ADD 
 CONSTRAINT FK_tm_VentasDet_tm_Ventas FOREIGN KEY (tmEst,tmItem) REFERENCES [dbo].[tm_Ventas] (tmEst,tmItem)
GO
ALTER TABLE tm_VentasRes ADD 
 CONSTRAINT FK_tm_VentasRes_tm_Ventas FOREIGN KEY (tmEst,tmItem) REFERENCES [dbo].[tm_Ventas] (tmEst,tmItem)
GO
ALTER TABLE TraConcCausac ADD 
 CONSTRAINT FK_TraConcCausac_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta)
GO
ALTER TABLE TraFijos ADD 
 CONSTRAINT FK_TraFijos_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto)
GO
ALTER TABLE Trn_AfAmortiza ADD 
 CONSTRAINT FK_Trn_AfAmortiza_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfAmortizaFecha ON Trn_AfAmortiza(Fecha)

GO
ALTER TABLE Trn_AfAmtComp ADD 
 CONSTRAINT FK_Trn_AfAmtComp_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_AfAmtComp_Trn_AfAmortiza FOREIGN KEY (Numero) REFERENCES [dbo].[Trn_AfAmortiza] (Numero)
GO
ALTER TABLE Trn_AfAmtDetalle ADD 
 CONSTRAINT FK_Trn_AfAmtDetalle_Diferidos FOREIGN KEY (IdDiferido) REFERENCES [dbo].[Diferidos] (IdDiferido),
 CONSTRAINT FK_Trn_AfAmtDetalle_Trn_AfAmortiza FOREIGN KEY (Numero) REFERENCES [dbo].[Trn_AfAmortiza] (Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfAmtDetalleIdDiferido ON Trn_AfAmtDetalle(IdDiferido)

GO
ALTER TABLE Trn_AfDeprecCom ADD 
 CONSTRAINT FK_Trn_AfDeprecCom_Trn_AfDeprecia FOREIGN KEY (Numero) REFERENCES [dbo].[Trn_AfDeprecia] (Numero)
GO
ALTER TABLE Trn_AfDeprecia ADD 
 CONSTRAINT FK_Trn_AfDeprecia_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_AfDeprecia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfDepreciaFecha ON Trn_AfDeprecia(Fecha)

GO
ALTER TABLE Trn_AfDetalle ADD 
 CONSTRAINT FK_Trn_AfDetalle_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfDetalle_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_AfDetalle_Trn_AfDeprecia FOREIGN KEY (Numero) REFERENCES [dbo].[Trn_AfDeprecia] (Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfDetalleIdActivo ON Trn_AfDetalle(IdActivo)
 CREATE NONCLUSTERED INDEX IX_Trn_AfDetalleIdCia ON Trn_AfDetalle(IdCia)

GO
ALTER TABLE Trn_AfDifIngreso ADD 
 CONSTRAINT FK_Trn_AfDifIngreso_Diferidos FOREIGN KEY (IdDiferido) REFERENCES [dbo].[Diferidos] (IdDiferido),
 CONSTRAINT FK_Trn_AfDifIngreso_Trn_AfDifMovi FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfDifMovi] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfDifIngresoIdDiferido ON Trn_AfDifIngreso(IdDiferido)

GO
ALTER TABLE Trn_AfDifMovi ADD 
 CONSTRAINT FK_Trn_AfDifMovi_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_AfDifMovi_AfTiposMov FOREIGN KEY (IdMov) REFERENCES [dbo].[AfTiposMov] (IdMov),
 CONSTRAINT FK_Trn_AfDifMovi_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_AfDifMoviFecha ON Trn_AfDifMovi(Fecha,IdMov,Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_AfDifMoviComprobante ON Trn_AfDifMovi(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_AfDifRetiro ADD 
 CONSTRAINT FK_Trn_AfDifRetiro_AfCausales FOREIGN KEY (IdCausal) REFERENCES [dbo].[AfCausales] (IdCausal),
 CONSTRAINT FK_Trn_AfDifRetiro_Diferidos FOREIGN KEY (IdDiferido) REFERENCES [dbo].[Diferidos] (IdDiferido),
 CONSTRAINT FK_Trn_AfDifRetiro_Trn_AfDifMovi FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfDifMovi] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfDifRetiroIdDiferido ON Trn_AfDifRetiro(IdDiferido)

GO
ALTER TABLE Trn_AfDifTraslado ADD 
 CONSTRAINT FK_Trn_AfDifTraslado_AfGrupos FOREIGN KEY (IdGrupo) REFERENCES [dbo].[AfGrupos] (IdGrupo),
 CONSTRAINT FK_Trn_AfDifTraslado_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_AfDifTraslado_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_AfDifTraslado_Diferidos FOREIGN KEY (IdDiferido) REFERENCES [dbo].[Diferidos] (IdDiferido),
 CONSTRAINT FK_Trn_AfDifTraslado_Trn_AfDifMovi FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfDifMovi] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfDifTrasladoIdDiferido ON Trn_AfDifTraslado(IdDiferido)

GO
ALTER TABLE Trn_AfDifValoriza ADD 
 CONSTRAINT FK_Trn_AfDifValoriza_Diferidos FOREIGN KEY (IdDiferido) REFERENCES [dbo].[Diferidos] (IdDiferido),
 CONSTRAINT FK_Trn_AfDifValoriza_Trn_AfDifMovi FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfDifMovi] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfDifValorizaIdDiferido ON Trn_AfDifValoriza(IdDiferido)

GO
ALTER TABLE Trn_AfMantnmto ADD 
 CONSTRAINT FK_Trn_AfMantnmto_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfMantnmto_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_AfMantnmto_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_AfMantnmtoFecha ON Trn_AfMantnmto(Fecha,IdActivo)
 CREATE NONCLUSTERED INDEX IX_Trn_AfMantnmtoIdCia ON Trn_AfMantnmto(IdCia)

GO
ALTER TABLE Trn_AfMovimiento ADD 
 CONSTRAINT FK_Trn_AfMovimiento_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_AfMovimiento_AfTiposMov FOREIGN KEY (IdMov) REFERENCES [dbo].[AfTiposMov] (IdMov),
 CONSTRAINT FK_Trn_AfMovimiento_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_AfMovimientoFecha ON Trn_AfMovimiento(Fecha,IdMov,Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_AfMovimientoComprobante ON Trn_AfMovimiento(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_AfMovIngreso ADD 
 CONSTRAINT FK_Trn_AfMovIngreso_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfMovIngreso_Trn_AfMovimiento FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfMovimiento] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfMovIngresoIdActivo ON Trn_AfMovIngreso(IdActivo)

GO
ALTER TABLE Trn_AfMovRetiro ADD 
 CONSTRAINT FK_Trn_AfMovRetiro_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfMovRetiro_AfCausales FOREIGN KEY (IdCausal) REFERENCES [dbo].[AfCausales] (IdCausal),
 CONSTRAINT FK_Trn_AfMovRetiro_Trn_AfMovimiento FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfMovimiento] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfMovRetiroIdActivo ON Trn_AfMovRetiro(IdActivo)

GO
ALTER TABLE Trn_AfMovTraslado ADD 
 CONSTRAINT FK_Trn_AfMovTraslado_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfMovTraslado_AfGrupos FOREIGN KEY (IdGrupo) REFERENCES [dbo].[AfGrupos] (IdGrupo),
 CONSTRAINT FK_Trn_AfMovTraslado_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_AfMovTraslado_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_AfMovTraslado_Instalaciones FOREIGN KEY (IdInstala) REFERENCES [dbo].[Instalaciones] (IdInstala),
 CONSTRAINT FK_Trn_AfMovTraslado_Terceros FOREIGN KEY (IdRespons) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_AfMovTraslado_Trn_AfMovimiento FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfMovimiento] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfMovTrasladoIdActivo ON Trn_AfMovTraslado(IdActivo)
 CREATE NONCLUSTERED INDEX IX_Trn_AfMovTrasladoIdCCosto ON Trn_AfMovTraslado(IdCCosto)

GO
ALTER TABLE Trn_AfMovValoriza ADD 
 CONSTRAINT FK_Trn_AfMovValoriza_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfMovValoriza_Trn_AfMovimiento FOREIGN KEY (IdMov,Numero,IdCia) REFERENCES [dbo].[Trn_AfMovimiento] (IdMov,Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfMovValorizaIdActivo ON Trn_AfMovValoriza(IdActivo)

GO
ALTER TABLE Trn_AfPartes ADD 
 CONSTRAINT FK_Trn_AfPartes_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfPartesIdActivo ON Trn_AfPartes(IdActivo,IdParte)

GO
ALTER TABLE Trn_AfPignora ADD 
 CONSTRAINT FK_Trn_AfPignora_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo),
 CONSTRAINT FK_Trn_AfPignora_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfPignoraFecha ON Trn_AfPignora(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_AfPignoraIdActivo ON Trn_AfPignora(IdActivo)

GO
ALTER TABLE Trn_AfUnidades ADD 
 CONSTRAINT FK_Trn_AfUnidades_Activos FOREIGN KEY (IdActivo) REFERENCES [dbo].[Activos] (IdActivo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AfUnidadesIdActivo ON Trn_AfUnidades(IdActivo,Fecha)

GO
ALTER TABLE Trn_AjuInv ADD 
 CONSTRAINT FK_Trn_AjuInv_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_AjuInv_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_AjuInv_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_AjuInv_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_AjuInv_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_AjuInv_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_AjuInv_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_AjuInv_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_AjuInv_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AjuInvFecha ON Trn_AjuInv(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_AjuInvIdConcepto ON Trn_AjuInv(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_AjuInvIdTercero ON Trn_AjuInv(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_AjuInvNumOrden ON Trn_AjuInv(NumOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_AjuInvModalidad ON Trn_AjuInv(Modalidad)
 CREATE NONCLUSTERED INDEX IX_Trn_AjuInvComprobante ON Trn_AjuInv(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_Aprobacion ADD 
 CONSTRAINT FK_Trn_Aprobacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Aprobacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Aprobacion_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Aprobacion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Aprobacion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Aprobacion_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AprobacionFecha ON Trn_Aprobacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_AprobacionPedido ON Trn_Aprobacion(TipoPed,Pedido,IdCiaPed)
 CREATE NONCLUSTERED INDEX IX_Trn_AprobacionIdCliente ON Trn_Aprobacion(IdCliente)

GO
ALTER TABLE Trn_Autoriza ADD 
 CONSTRAINT FK_Trn_Autoriza_adm_Usuarios FOREIGN KEY (IdUsuarioAut) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Autoriza_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Autoriza_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Autoriza_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Autoriza_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Autoriza_Sys_Autoriza FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Sys_Autoriza] (IdConcepto),
 CONSTRAINT FK_Trn_Autoriza_Sys_Estaciones FOREIGN KEY (IdEstacion) REFERENCES [dbo].[Sys_Estaciones] (IdEstacion),
 CONSTRAINT FK_Trn_Autoriza_Sys_TiposDoc FOREIGN KEY (TipAut) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_AutorizaFecha ON Trn_Autoriza(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_AutorizaIdConcepto ON Trn_Autoriza(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_AutorizaNumAutoriza ON Trn_Autoriza(NumAutoriza)
 CREATE NONCLUSTERED INDEX IX_Trn_AutorizaIdUsuarioAut ON Trn_Autoriza(IdUsuarioAut)
 CREATE NONCLUSTERED INDEX IX_Trn_AutorizaNitTercero ON Trn_Autoriza(NitTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_AutorizaDocumento ON Trn_Autoriza(TipoDoc,Documento,IdCiaDoc)

GO
ALTER TABLE Trn_Causacion ADD 
 CONSTRAINT FK_Trn_Causacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Causacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Causacion_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Causacion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Causacion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Causacion_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Causacion_Terceros1 FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Causacion_Terceros2 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Causacion_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_CausacionFecha ON Trn_Causacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_CausacionIdProveedor ON Trn_Causacion(IdProveedor)
 CREATE NONCLUSTERED INDEX IX_Trn_CausacionIdPropietario ON Trn_Causacion(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_CausacionComprobante ON Trn_Causacion(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_CausacVence ADD 
 CONSTRAINT FK_Trn_CausacVence_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Trn_CausacVence_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CausacVence_Fijos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Fijos] (IdCargo),
 CONSTRAINT FK_Trn_CausacVence_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_CausacVence_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_CausacVence_Terceros1 FOREIGN KEY (IdVendedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_CausacVence_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE CLUSTERED INDEX IX_Trn_CausacVenceIdCliente ON Trn_CausacVence(FecEmision,IdCia,IdCliente,IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_CausacVenceFecEmision ON Trn_CausacVence(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_CausacVenceFecVence ON Trn_CausacVence(FecVence)
 CREATE NONCLUSTERED INDEX IX_Trn_CausacVenceIdVehiculo ON Trn_CausacVence(IdVehiculo)

GO
ALTER TABLE Trn_CausaVales ADD 
 CONSTRAINT FK_Trn_CausaVales_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_CausaVales_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CausaVales_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CausaVales_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_CausaVales_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_CausaVales_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_CausaVales_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_CausaVales_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_CausaValesFecha ON Trn_CausaVales(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_CausaValesIdCliente ON Trn_CausaVales(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_CausaValesComprobante ON Trn_CausaVales(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_Cheques ADD 
 CONSTRAINT FK_Trn_Cheques_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Cheques_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Trn_Cheques_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Cheques_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Cheques_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Cheques_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesFecha ON Trn_Cheques(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesFecPago ON Trn_Cheques(FecPago)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesNitCliente ON Trn_Cheques(NitCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesCdVend ON Trn_Cheques(CdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesIdLocal ON Trn_Cheques(IdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesRecibo ON Trn_Cheques(TipRec,Recibo)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesDocumento ON Trn_Cheques(TipDoc,Documento,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_ChequesNumConsig ON Trn_Cheques(TipCon,NumConsig,IdCiaCon)

GO
ALTER TABLE Trn_ComDetalle ADD 
 CONSTRAINT FK_Trn_ComDetalle_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_ComDetalle_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_ComDetalle_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ComDetalle_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ComDetalle_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_ComDetalle_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_ComDetalle_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_ComDetalle_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom),
 CONSTRAINT FK_Trn_ComDetalle_Trn_Comprobantes FOREIGN KEY (TipCom,Comprobante,IdCia) REFERENCES [dbo].[Trn_Comprobantes] (TipCom,Comprobante,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_ComDetalleFechaIdCuenta ON Trn_ComDetalle(Fecha,IdCuenta,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_ComDetalleCodAgncia ON Trn_ComDetalle(IdTercero,CodAgncia)
 CREATE NONCLUSTERED INDEX IX_Trn_ComDetalleIdTercero ON Trn_ComDetalle(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_ComDetalleIdVehiculo ON Trn_ComDetalle(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_ComDetalleIdCCosto ON Trn_ComDetalle(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_ComDetalleIdSubCos ON Trn_ComDetalle(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_ComDetalleDocumento ON Trn_ComDetalle(TipDoc,Documento,IdCiaDoc)

GO
ALTER TABLE Trn_ComFactura ADD 
 CONSTRAINT FK_Trn_ComFactura_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ComFactura_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_ComFactura_Sys_TiposDoc FOREIGN KEY (TipFac) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_ComFactura_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_ComFacturaFecEmision ON Trn_ComFactura(FecEmision,IdCuenta,IdProveedor)
 CREATE NONCLUSTERED INDEX IX_Trn_ComFacturaDocumento ON Trn_ComFactura(TipDoc,Documento,IdCiaDoc)

GO
ALTER TABLE Trn_CompCaja ADD 
 CONSTRAINT FK_Trn_CompCaja_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_CompCaja_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_CompCaja_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_CompCaja_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CompCaja_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CompCaja_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_CompCaja_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_CompCaja_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_CompCaja_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaFecha ON Trn_CompCaja(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaIdTercero ON Trn_CompCaja(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaComprobante ON Trn_CompCaja(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_CompCajaDet ADD 
 CONSTRAINT FK_Trn_CompCajaDet_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CompCajaDet_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_CompCajaDet_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_CompCajaDet_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_CompCajaDet_Trn_CompCaja FOREIGN KEY (TipDoc,Recibo,IdCia) REFERENCES [dbo].[Trn_CompCaja] (TipDoc,Recibo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaDetIdCuenta ON Trn_CompCajaDet(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaDetNitTercero ON Trn_CompCajaDet(NitTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaDetCdCCosto ON Trn_CompCajaDet(CdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_CompCajaDetIdConcepto ON Trn_CompCajaDet(IdConcepto)

GO
ALTER TABLE Trn_CompGastos ADD 
 CONSTRAINT FK_Trn_CompGastos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_CompGastos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CompGastos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_CompGastos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_CompGastos_Plantillas FOREIGN KEY (IdPlantilla) REFERENCES [dbo].[Plantillas] (IdPlantilla),
 CONSTRAINT FK_Trn_CompGastos_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_CompGastos_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_CompGastosFecha ON Trn_CompGastos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_CompGastosIdPlantilla ON Trn_CompGastos(IdPlantilla)
 CREATE NONCLUSTERED INDEX IX_Trn_CompGastosIdTercero ON Trn_CompGastos(IdTercero)

GO
ALTER TABLE Trn_Comprobantes ADD 
 CONSTRAINT FK_Trn_Comprobantes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Comprobantes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Comprobantes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Comprobantes_Companias2 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Comprobantes_CtasCorrientes FOREIGN KEY (IdCta) REFERENCES [dbo].[CtasCorrientes] (IdCta),
 CONSTRAINT FK_Trn_Comprobantes_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Comprobantes_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Comprobantes_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Comprobantes_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
 CREATE CLUSTERED INDEX IX_Trn_ComprobantesFecha ON Trn_Comprobantes(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_ComprobantesIdTercero ON Trn_Comprobantes(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_ComprobantesIdCta ON Trn_Comprobantes(IdCta)
 CREATE NONCLUSTERED INDEX IX_Trn_ComprobantesDocumento ON Trn_Comprobantes(TipDoc,Documento,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_ComprobantesIdUsuario ON Trn_Comprobantes(IdUsuario)

GO
ALTER TABLE Trn_Consigna ADD 
 CONSTRAINT FK_Trn_Consigna_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Consigna_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Consigna_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Consigna_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Consigna_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Consigna_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Consigna_CtasCorrientes FOREIGN KEY (IdCta) REFERENCES [dbo].[CtasCorrientes] (IdCta),
 CONSTRAINT FK_Trn_Consigna_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Consigna_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_Consigna_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Consigna_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaFecha ON Trn_Consigna(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaIdConcepto ON Trn_Consigna(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaIdCuenta ON Trn_Consigna(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaIdCta ON Trn_Consigna(IdCta)
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaIdCliente ON Trn_Consigna(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaNumConsigna ON Trn_Consigna(NumConsigna)
 CREATE NONCLUSTERED INDEX IX_Trn_ConsignaComprobante ON Trn_Consigna(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_Cotizacion ADD 
 CONSTRAINT FK_Trn_Cotizacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Cotizacion_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Cotizacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Cotizacion_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Cotizacion_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Cotizacion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Cotizacion_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_Cotizacion_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Cotizacion_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_Cotizacion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Cotizacion_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Cotizacion_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionTipDoc ON Trn_Cotizacion(TipDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionFecha ON Trn_Cotizacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionFechaVence ON Trn_Cotizacion(FechaVence)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdCliente ON Trn_Cotizacion(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdConcepto ON Trn_Cotizacion(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdAgencia ON Trn_Cotizacion(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdVend ON Trn_Cotizacion(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdLocal ON Trn_Cotizacion(IdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdForma ON Trn_Cotizacion(IdForma)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdPlazo ON Trn_Cotizacion(IdPlazo)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionFactura ON Trn_Cotizacion(TipFac,Factura,IdCiaFac)
 CREATE NONCLUSTERED INDEX IX_Trn_CotizacionIdEstado ON Trn_Cotizacion(IdEstado)

GO
ALTER TABLE Trn_Despachos ADD 
 CONSTRAINT FK_Trn_Despachos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Despachos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Despachos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Despachos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Despachos_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Despachos_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Despachos_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DespachosFecha ON Trn_Despachos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DespachosIdVehiculo ON Trn_Despachos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_DespachosIdPropietario ON Trn_Despachos(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_DespachosIdConductor ON Trn_Despachos(IdConductor)

GO
ALTER TABLE Trn_DetCuentas ADD 
 CONSTRAINT FK_Trn_DetCuentas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DetCuentas_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_DetCuentas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DetCuentas_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DetCuentasIdCuenta ON Trn_DetCuentas(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_Trn_DetCuentasIdTercero ON Trn_DetCuentas(IdTercero)

GO
ALTER TABLE Trn_DevCaj ADD 
 CONSTRAINT FK_Trn_DevCaj_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevCaj_adm_Usuarios1 FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevCaj_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevCaj_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevCaj_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevCaj_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevCaj_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevCaj_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevCaj_Sys_TiposDoc1 FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevCaj_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevCaj_Trn_CompCaja FOREIGN KEY (TipDoc,Recibo,IdCiaDoc) REFERENCES [dbo].[Trn_CompCaja] (TipDoc,Recibo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajFecha ON Trn_DevCaj(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajIdConcepto ON Trn_DevCaj(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajRecibo ON Trn_DevCaj(TipDoc,Recibo,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajFecDoc ON Trn_DevCaj(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajIdTercero ON Trn_DevCaj(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajIdCajero ON Trn_DevCaj(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCajComprobante ON Trn_DevCaj(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevCausacion ADD 
 CONSTRAINT FK_Trn_DevCausacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevCausacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevCausacion_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevCausacion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevCausacion_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevCausacion_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevCausacion_Terceros1 FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevCausacion_Terceros2 FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevCausacion_Trn_Causacion FOREIGN KEY (TipDoc,Documento,IdCiaDoc) REFERENCES [dbo].[Trn_Causacion] (TipDoc,Documento,IdCia),
 CONSTRAINT FK_Trn_DevCausacion_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevCausacionFecha ON Trn_DevCausacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCausacionDocumento ON Trn_DevCausacion(TipDoc,Documento,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCausacionIdVehiculo ON Trn_DevCausacion(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCausacionIdPropietario ON Trn_DevCausacion(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCausacionComprobante ON Trn_DevCausacion(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevCns ADD 
 CONSTRAINT FK_Trn_DevCns_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevCns_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevCns_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevCns_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevCns_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevCns_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevCns_CtasCorrientes FOREIGN KEY (IdCta) REFERENCES [dbo].[CtasCorrientes] (IdCta),
 CONSTRAINT FK_Trn_DevCns_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevCns_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_DevCns_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevCns_Sys_TiposDoc1 FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevCns_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevCns_Trn_Consigna FOREIGN KEY (TipDoc,Consignacion,IdCiaDoc) REFERENCES [dbo].[Trn_Consigna] (TipDoc,Consignacion,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsFecha ON Trn_DevCns(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsConsignacion ON Trn_DevCns(TipDoc,Consignacion,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsFecDoc ON Trn_DevCns(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsIdCta ON Trn_DevCns(IdCta)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsIdCliente ON Trn_DevCns(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsIdCajero ON Trn_DevCns(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevCnsComprobante ON Trn_DevCns(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevEnt ADD 
 CONSTRAINT FK_Trn_DevEnt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevEnt_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevEnt_Companias1 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevEnt_Companias2 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevEnt_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevEnt_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevEnt_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevEnt_Sys_TiposDoc1 FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevEnt_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevEnt_Trn_Entradas FOREIGN KEY (TipDoc,Entrada,IdCiaDoc) REFERENCES [dbo].[Trn_Entradas] (TipDoc,Entrada,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_DevEntFecha ON Trn_DevEnt(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_DevEntFactura ON Trn_DevEnt(Factura)
 CREATE NONCLUSTERED INDEX IX_Trn_DevEntIdConcepto ON Trn_DevEnt(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevEntEntrada ON Trn_DevEnt(TipDoc,Entrada,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevEntIdProv ON Trn_DevEnt(IdProv)

GO
ALTER TABLE Trn_DevFco ADD 
 CONSTRAINT FK_Trn_DevFco_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevFco_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevFco_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevFco_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFco_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFco_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevFco_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevFco_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_DevFco_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevFco_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevFco_Trn_Factcon FOREIGN KEY (TipDoc,Factura,IdCiaDoc) REFERENCES [dbo].[Trn_Factcon] (TipDoc,Factura,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_DevFcoFecha ON Trn_DevFco(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoIdConcepto ON Trn_DevFco(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoFactura ON Trn_DevFco(TipDoc,Factura,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFconClieCon ON Trn_DevFco(nClieCon)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoIdCajero ON Trn_DevFco(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoIdVend ON Trn_DevFco(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoPedido ON Trn_DevFco(Pedido,IdCiaPed)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoRemision ON Trn_DevFco(Remision,IdCiaRem)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcoComprobante ON Trn_DevFco(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevFcr ADD 
 CONSTRAINT FK_Trn_DevFcr_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevFcr_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_DevFcr_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevFcr_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFcr_Companias1 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFcr_Companias2 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFcr_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevFcr_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevFcr_Localidades FOREIGN KEY (IdLocEnv) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_DevFcr_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevFcr_Sys_TiposDoc1 FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevFcr_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevFcr_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevFcr_Trn_Facturas FOREIGN KEY (TipDoc,Factura,IdCiaDoc) REFERENCES [dbo].[Trn_Facturas] (TipDoc,Factura,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_DevFcrFecha ON Trn_DevFcr(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrFactura ON Trn_DevFcr(TipDoc,Factura,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrFecDoc ON Trn_DevFcr(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrIdCliente ON Trn_DevFcr(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrIdVend ON Trn_DevFcr(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrPedido ON Trn_DevFcr(Pedido,IdCiaPed)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrComprobante ON Trn_DevFcr(TipCom,Comprobante,IdCiaCom)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFcrRemision ON Trn_DevFcr(Remision,IdCiaRem)

GO
ALTER TABLE Trn_DevFvc ADD 
 CONSTRAINT FK_Trn_DevFvc_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevFvc_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFvc_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevFvc_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevFvc_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevFvc_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevFvc_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevFvc_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevFvc_Trn_CausaVales FOREIGN KEY (TipDoc,Factura,IdCiaDoc) REFERENCES [dbo].[Trn_CausaVales] (TipDoc,Documento,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevFvcFecha ON Trn_DevFvc(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFvcIdCliente ON Trn_DevFvc(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFvcFactura ON Trn_DevFvc(TipDoc,Factura,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevFvcComprobante ON Trn_DevFvc(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevNpr ADD 
 CONSTRAINT FK_Trn_DevNpr_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevNpr_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevNpr_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevNpr_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevNpr_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevNpr_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevNpr_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_DevNpr_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevNpr_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevNpr_Trn_NotaProd FOREIGN KEY (TipDoc,NumNota,IdCiaDoc) REFERENCES [dbo].[Trn_NotaProd] (TipDoc,NumNota,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprFecha ON Trn_DevNpr(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprIdConcepto ON Trn_DevNpr(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprNumNota ON Trn_DevNpr(TipDoc,NumNota,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprIdTercero ON Trn_DevNpr(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprNumOrden ON Trn_DevNpr(NumOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprIdCCosto ON Trn_DevNpr(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprIdSubCos ON Trn_DevNpr(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_DevNprComprobante ON Trn_DevNpr(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevPas ADD 
 CONSTRAINT FK_Trn_DevPas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevPas_adm_Usuarios1 FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevPas_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevPas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevPas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevPas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevPas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevPas_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevPas_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevPas_Trn_EdsCalibra FOREIGN KEY (TipDoc,nNota,IdCiaDoc) REFERENCES [dbo].[Trn_EdsCalibra] (TipDoc,nNota,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevPasFecha ON Trn_DevPas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPasIdConcepto ON Trn_DevPas(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPasnNota ON Trn_DevPas(TipDoc,nNota,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPasFecDoc ON Trn_DevPas(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPasIdCajero ON Trn_DevPas(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPasComprobante ON Trn_DevPas(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevPla ADD 
 CONSTRAINT FK_Trn_DevPla_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevPla_adm_Usuarios1 FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevPla_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevPla_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevPla_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevPla_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevPla_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevPla_Jornadas FOREIGN KEY (IdJornada) REFERENCES [dbo].[Jornadas] (IdJornada),
 CONSTRAINT FK_Trn_DevPla_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevPla_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevPla_Trn_EdsCortes FOREIGN KEY (TipDoc,Planilla,IdCiaDoc) REFERENCES [dbo].[Trn_EdsCortes] (TipDoc,Planilla,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaFecha ON Trn_DevPla(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaIdConcepto ON Trn_DevPla(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaPlanilla ON Trn_DevPla(TipDoc,Planilla,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaFecDoc ON Trn_DevPla(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaIdJornada ON Trn_DevPla(IdJornada)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaIdCajero ON Trn_DevPla(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaNumCorte ON Trn_DevPla(NumCorte)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPlaComprobante ON Trn_DevPla(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevPrestamos ADD 
 CONSTRAINT FK_Trn_DevPrestamos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevPrestamos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevPrestamos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevPrestamos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevPrestamos_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevPrestamos_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevPrestamos_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevPrestamos_Trn_Prestamos FOREIGN KEY (TipDoc,Prestamo,IdCiaDoc) REFERENCES [dbo].[Trn_Prestamos] (TipDoc,PrestamoID,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevPrestamosFecha ON Trn_DevPrestamos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPrestamosPrestamo ON Trn_DevPrestamos(TipDoc,Prestamo,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPrestamosIdVehiculo ON Trn_DevPrestamos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_DevPrestamosIdPropietario ON Trn_DevPrestamos(IdPropietario)

GO
ALTER TABLE Trn_DevRec ADD 
 CONSTRAINT FK_Trn_DevRec_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevRec_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevRec_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_DevRec_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevRec_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevRec_Companias1 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevRec_Companias2 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevRec_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevRec_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevRec_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_DevRec_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevRec_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevRec_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevRec_Trn_Recibos FOREIGN KEY (TipDoc,Recibo,IdCiaDoc) REFERENCES [dbo].[Trn_Recibos] (TipDoc,Recibo,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_DevRecFecha ON Trn_DevRec(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecIdConcepto ON Trn_DevRec(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecRecibo ON Trn_DevRec(TipDoc,Recibo,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecFecDoc ON Trn_DevRec(FecDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecIdCliente ON Trn_DevRec(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecIdCajero ON Trn_DevRec(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecIdVend ON Trn_DevRec(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecComprobante ON Trn_DevRec(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevRecBuses ADD 
 CONSTRAINT FK_Trn_DevRecBuses_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevRecBuses_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Trn_DevRecBuses_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Trn_DevRecBuses_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevRecBuses_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevRecBuses_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevRecBuses_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevRecBuses_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevRecBuses_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevRecBuses_Terceros2 FOREIGN KEY (IdVendedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevRecBuses_Trn_RecBuses FOREIGN KEY (TipDoc,Recibo,IdCiaDoc) REFERENCES [dbo].[Trn_RecBuses] (TipDoc,Recibo,IdCia),
 CONSTRAINT FK_Trn_DevRecBuses_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecBusesFecha ON Trn_DevRecBuses(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecBusesRecibo ON Trn_DevRecBuses(TipDoc,Recibo,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecBusesIdCliente ON Trn_DevRecBuses(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecBusesIdVehiculo ON Trn_DevRecBuses(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_DevRecBusesComprobante ON Trn_DevRecBuses(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_DevSal ADD 
 CONSTRAINT FK_Trn_DevSal_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevSal_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_DevSal_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevSal_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevSal_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevSal_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevSal_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_DevSal_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevSal_Sys_TiposDoc1 FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevSal_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevSal_Trn_Salidas FOREIGN KEY (TipDoc,Salida,IdCiaDoc) REFERENCES [dbo].[Trn_Salidas] (TipDoc,Salida,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_DevSalFecha ON Trn_DevSal(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalIdConcepto ON Trn_DevSal(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalSalida ON Trn_DevSal(TipDoc,Salida,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalIdTercero ON Trn_DevSal(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalNumOrden ON Trn_DevSal(TipOrd,NumOrden,IdCiaOrd)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalComprobante ON Trn_DevSal(TipCom,Comprobante,IdCiaCom)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalNContrato ON Trn_DevSal(NContrato,IdCiaCont)
 CREATE NONCLUSTERED INDEX IX_Trn_DevSalNitCliente ON Trn_DevSal(NitCliente)

GO
ALTER TABLE Trn_DevVal ADD 
 CONSTRAINT FK_Trn_DevVal_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DevVal_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DevVal_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_DevVal_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DevVal_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DevVal_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_DevVal_Trn_RadicaVales FOREIGN KEY (TipDoc,nRadica,IdCiaDoc) REFERENCES [dbo].[Trn_RadicaVales] (TipDoc,nRadica,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DevValFecha ON Trn_DevVal(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DevValnRadica ON Trn_DevVal(TipDoc,nRadica,IdCiaDoc)

GO
ALTER TABLE Trn_Disciplinario ADD 
 CONSTRAINT FK_Trn_Disciplinario_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Disciplinario_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Disciplinario_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Disciplinario_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Disciplinario_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Disciplinario_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Disciplinario_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DisciplinarioFecha ON Trn_Disciplinario(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DisciplinarioIdVehiculo ON Trn_Disciplinario(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_DisciplinarioIdConductor ON Trn_Disciplinario(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_DisciplinarioFecSuceso ON Trn_Disciplinario(FecSuceso)

GO
ALTER TABLE Trn_DisInfraccion ADD 
 CONSTRAINT FK_Trn_DisInfraccion_Trn_Disciplinario FOREIGN KEY (TipDoc,Numero,IdCia) REFERENCES [dbo].[Trn_Disciplinario] (TipDoc,Numero,IdCia)
GO
ALTER TABLE Trn_DocMemo ADD 
 CONSTRAINT FK_Trn_DocMemo_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DocMemo_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
ALTER TABLE Trn_DocSoporte ADD 
 CONSTRAINT FK_Trn_DocSoporte_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_DocSoporte_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DocSoporte_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_DocSoporte_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_DocSoporte_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_DocSoporte_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DocSoporteFecha ON Trn_DocSoporte(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_DocSoporteIdTercero ON Trn_DocSoporte(IdTercero)

GO
ALTER TABLE Trn_DocSoporteDet ADD 
 CONSTRAINT FK_Trn_DocSoporteDet_Trn_DocSoporte FOREIGN KEY (TipDoc,NumDoc,IdCia) REFERENCES [dbo].[Trn_DocSoporte] (TipDoc,NumDoc,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_DocSoporteDetComprobante ON Trn_DocSoporteDet(TipCom,Comprobante,IdCiaCom,ItemCom)

GO
ALTER TABLE Trn_EdsCalibra ADD 
 CONSTRAINT FK_Trn_EdsCalibra_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsCalibra_adm_Usuarios1 FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsCalibra_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_EdsCalibra_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsCalibra_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsCalibra_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_EdsCalibra_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_EdsCalibra_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_EdsCalibra_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCalibraFecha ON Trn_EdsCalibra(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCalibraIdConcepto ON Trn_EdsCalibra(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCalibraIdCajero ON Trn_EdsCalibra(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCalibraComprobante ON Trn_EdsCalibra(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_EdsCortes ADD 
 CONSTRAINT FK_Trn_EdsCortes_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsCortes_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsCortes_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_EdsCortes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsCortes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsCortes_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_EdsCortes_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_EdsCortes_Jornadas FOREIGN KEY (IdJornada) REFERENCES [dbo].[Jornadas] (IdJornada),
 CONSTRAINT FK_Trn_EdsCortes_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_EdsCortes_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesFecha ON Trn_EdsCortes(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesNitTercero ON Trn_EdsCortes(NitTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesIdCajero ON Trn_EdsCortes(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesIdVend ON Trn_EdsCortes(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesFecCorte ON Trn_EdsCortes(FecCorte)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesNumCorte ON Trn_EdsCortes(NumCorte)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsCortesComprobante ON Trn_EdsCortes(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_EdsForItems ADD 
 CONSTRAINT FK_Trn_EdsForItems_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_EdsForItems_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_EdsForItems_Trn_EdsFormas FOREIGN KEY (TipoRango,IdRango,NumSerie,NumForma) REFERENCES [dbo].[Trn_EdsFormas] (TipoRango,IdRango,NumSerie,NumForma)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EdsForItemsIdProducto ON Trn_EdsForItems(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsForItemsIdBodega ON Trn_EdsForItems(IdBodega)

GO
ALTER TABLE Trn_EdsFormas ADD 
 CONSTRAINT FK_Trn_EdsFormas_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsFormas_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_EdsFormas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsFormas_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_EdsFormas_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_EdsFormas_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_EdsFormas_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_EdsFormas_Trn_EdsRangos FOREIGN KEY (TipoRango,IdRango) REFERENCES [dbo].[Trn_EdsRangos] (TipoRango,IdRango)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasPlanilla ON Trn_EdsFormas(Planilla,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasFecha ON Trn_EdsFormas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasIdCliente ON Trn_EdsFormas(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasIdCuenta ON Trn_EdsFormas(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasIdVend ON Trn_EdsFormas(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasCdProducto ON Trn_EdsFormas(CdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsFormasDocumento ON Trn_EdsFormas(TipDcm,Documento,IdCiaDcm)

GO
ALTER TABLE Trn_EdsRangos ADD 
 CONSTRAINT FK_Trn_EdsRangos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsRangos_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_EdsRangos_Companias FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsRangos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_EdsRangos_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_EdsRangos_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_EdsRangos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EdsRangosFecha ON Trn_EdsRangos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsRangosIdCliente ON Trn_EdsRangos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsRangosIdCuenta ON Trn_EdsRangos(IdCuenta)
 CREATE NONCLUSTERED INDEX IX_Trn_EdsRangosNumTarjeta ON Trn_EdsRangos(NumTarjeta)

GO
ALTER TABLE Trn_EdsUnion ADD 
 CONSTRAINT FK_Trn_EdsUnion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_EdsUnion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EdsUnion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
ALTER TABLE Trn_EdsUnionDisp ADD 
 CONSTRAINT FK_Trn_EdsUnionDisp_Trn_EdsUnion FOREIGN KEY (TipDoc,NumNota,IdCia) REFERENCES [dbo].[Trn_EdsUnion] (TipDoc,NumNota,IdCia)
GO
ALTER TABLE Trn_EdsUnionItems ADD 
 CONSTRAINT FK_Trn_EdsUnionItems_Trn_EdsUnion FOREIGN KEY (TipDoc,NumNota,IdCia) REFERENCES [dbo].[Trn_EdsUnion] (TipDoc,NumNota,IdCia)
GO
ALTER TABLE Trn_EgrAntAbonos ADD 
 CONSTRAINT FK_Trn_EgrAntAbonos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EgrAntAbonos_Companias1 FOREIGN KEY (IdCiaFac) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EgrAntAbonos_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_EgrAntAbonos_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom),
 CONSTRAINT FK_Trn_EgrAntAbonos_Trn_EgrAnticipo FOREIGN KEY (TipCan,nAnticipo,IdCiaAnt,ItemAnt) REFERENCES [dbo].[Trn_EgrAnticipo] (TipCom,Comprobante,IdCia,Item)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EgrAntAbonosnAnticipo ON Trn_EgrAntAbonos(TipCan,nAnticipo,IdCiaAnt,ItemAnt)

GO
ALTER TABLE Trn_EgrAnticipo ADD 
 CONSTRAINT FK_Trn_EgrAnticipo_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EgrAnticipo_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_EgrAnticipo_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_EgrAnticipo_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
 CREATE CLUSTERED INDEX IX_Trn_EgrAnticipoIdCuenta ON Trn_EgrAnticipo(IdCuenta,IdTercero,Fecha)

GO
ALTER TABLE Trn_EgrFactura ADD 
 CONSTRAINT FK_Trn_EgrFactura_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EgrFactura_Companias1 FOREIGN KEY (IdCiaFac) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_EgrFactura_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_EgrFactura_Sys_TiposDoc FOREIGN KEY (TipFac) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_EgrFactura_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_EgrFactura_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom),
 CONSTRAINT FK_Trn_EgrFactura_Trn_ComFactura FOREIGN KEY (TipFac,Factura,IdCiaFac,ItemFac,IdProveedor) REFERENCES [dbo].[Trn_ComFactura] (TipFac,Factura,IdCia,Item,IdProveedor)
GO
 CREATE CLUSTERED INDEX IX_Trn_EgrFacturaFecha ON Trn_EgrFactura(Fecha,IdCuenta,IdProveedor,Factura)
 CREATE NONCLUSTERED INDEX IX_Trn_EgrFacturaFactura ON Trn_EgrFactura(TipFac,Factura,IdCiaFac,ItemFac,IdProveedor)

GO
ALTER TABLE Trn_EntArticulos ADD 
 CONSTRAINT FK_Trn_EntArticulos_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_EntArticulos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_EntArticulos_Trn_Entradas FOREIGN KEY (TipDoc,Entrada,IdCia) REFERENCES [dbo].[Trn_Entradas] (TipDoc,Entrada,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_EntArticulosIdProducto ON Trn_EntArticulos(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_EntArticulosNumOrden ON Trn_EntArticulos(TipOrd,NumOrden,IdCiaOrd)
 CREATE NONCLUSTERED INDEX IX_Trn_EntArticulosNumSalida ON Trn_EntArticulos(TipSal,NumSalida,IdCiaSal)

GO
ALTER TABLE Trn_Entradas ADD 
 CONSTRAINT FK_Trn_Entradas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Entradas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Entradas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Entradas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Entradas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Entradas_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_Entradas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Entradas_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_EntradasFecha ON Trn_Entradas(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_EntradasIdConcepto ON Trn_Entradas(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_EntradasIdProv ON Trn_Entradas(IdProv)
 CREATE NONCLUSTERED INDEX IX_Trn_EntradasFechaFac ON Trn_Entradas(FechaFac)
 CREATE NONCLUSTERED INDEX IX_Trn_EntradasOCompra ON Trn_Entradas(TipOdc,OCompra,IdCiaOdc)
 CREATE NONCLUSTERED INDEX IX_Trn_EntradasDocEquiv ON Trn_Entradas(DocEquiv)
 CREATE NONCLUSTERED INDEX IX_Trn_EntradasComprobante ON Trn_Entradas(TipCom,Comprobante,IdCiaCom)

GO
 CREATE NONCLUSTERED INDEX IX_Trn_FaceNumFace ON Trn_Face(Prefijo,NumFace)

GO
ALTER TABLE Trn_FactCausacion ADD 
 CONSTRAINT FK_Trn_FactCausacion_Fijos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Fijos] (IdCargo)
GO
ALTER TABLE Trn_Factcon ADD 
 CONSTRAINT FK_Trn_Factcon_adm_Usuarios FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Factcon_adm_Usuarios1 FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Factcon_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Factcon_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Factcon_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Factcon_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Factcon_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Factcon_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Factcon_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Factcon_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_FactconFecha ON Trn_Factcon(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconIdConcepto ON Trn_Factcon(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconnClieCon ON Trn_Factcon(nClieCon)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconNitCliente ON Trn_Factcon(NitCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconIdVend ON Trn_Factcon(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconIdCajero ON Trn_Factcon(IdCajero)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconIdLocal ON Trn_Factcon(IdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconPedido ON Trn_Factcon(Pedido,TipPed,IdCiaPed)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconRemision ON Trn_Factcon(TipRem,Remision,IdCiaRem)
 CREATE NONCLUSTERED INDEX IX_Trn_FactconComprobante ON Trn_Factcon(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_Facturas ADD 
 CONSTRAINT FK_Trn_Facturas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Facturas_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Facturas_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Facturas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Facturas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Facturas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Facturas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Facturas_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_Facturas_Localidades FOREIGN KEY (IdLocEnv) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Facturas_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_Facturas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Facturas_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Facturas_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_FacturasFecha ON Trn_Facturas(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasIdConcepto ON Trn_Facturas(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasIdCliente ON Trn_Facturas(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasIdAgencia ON Trn_Facturas(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasIdVend ON Trn_Facturas(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasIdLocEnv ON Trn_Facturas(IdLocEnv)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasIdPlazo ON Trn_Facturas(IdPlazo)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasPedido ON Trn_Facturas(TipPed,Pedido,IdCiaPed)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasRemision ON Trn_Facturas(TipRem,Remision,IdCiaRem)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasCotizacion ON Trn_Facturas(TipCot,Cotizacion,IdCiaCot)
 CREATE NONCLUSTERED INDEX IX_Trn_FacturasComprobante ON Trn_Facturas(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_FcAbonos ADD 
 CONSTRAINT FK_Trn_FcAbonos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FcAbonos_Trn_FcSemanas FOREIGN KEY (IdVehiculo,nSemana) REFERENCES [dbo].[Trn_FcSemanas] (IdVehiculo,nSemana)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FcAbonosFecha ON Trn_FcAbonos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FcAbonosnSemana ON Trn_FcAbonos(IdVehiculo,nSemana)

GO
ALTER TABLE Trn_FcCausacion ADD 
 CONSTRAINT FK_Trn_FcCausacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FcCausacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FcCausacion_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FcCausacion_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FcCausacion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FcCausacion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FcCausacionFecha ON Trn_FcCausacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FcCausacionFecCausac ON Trn_FcCausacion(FecCausac)

GO
ALTER TABLE Trn_FcNotas ADD 
 CONSTRAINT FK_Trn_FcNotas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FcNotas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FcNotas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FcNotas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FcNotas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FcNotas_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FcNotas_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FcNotas_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FcNotasFecha ON Trn_FcNotas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FcNotasIdVehiculo ON Trn_FcNotas(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_FcNotasIdPropietario ON Trn_FcNotas(IdPropietario)

GO
ALTER TABLE Trn_FcSemanas ADD 
 CONSTRAINT FK_Trn_FcSemanas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FcSemanas_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FcSemanasNumCargue ON Trn_FcSemanas(NumCargue,CiaCargue)
 CREATE NONCLUSTERED INDEX IX_Trn_FcSemanasFecha ON Trn_FcSemanas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FcSemanasRecibo ON Trn_FcSemanas(TipRec,Recibo,IdCiaRec)

GO
ALTER TABLE Trn_FinAbonos ADD 
 CONSTRAINT FK_Trn_FinAbonos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinAbonos_Sys_TiposDoc FOREIGN KEY (TipRec) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinAbonos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinAbonos_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinAbonos_Trn_FinCuotas FOREIGN KEY (TipDoc,IdPrestamo,IdCiaPre,ItemPre) REFERENCES [dbo].[Trn_FinCuotas] (TipDoc,IdPrestamo,IdCia,Item)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinAbonosIdPrestamo ON Trn_FinAbonos(TipDoc,IdPrestamo,IdCiaPre,ItemPre)
 CREATE NONCLUSTERED INDEX IX_Trn_FinAbonosIdCliente ON Trn_FinAbonos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_FinAbonosFecPago ON Trn_FinAbonos(FecPago)

GO
ALTER TABLE Trn_FinAfavor ADD 
 CONSTRAINT FK_Trn_FinAfavor_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinAfavor_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinAfavor_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinAfavor_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinAfavorIdCliente ON Trn_FinAfavor(IdCliente,IdAgencia)

GO
ALTER TABLE Trn_FinAmtza ADD 
 CONSTRAINT FK_Trn_FinAmtza_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCia) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinAmtzaFecCausac ON Trn_FinAmtza(FecCausac)
 CREATE NONCLUSTERED INDEX IX_Trn_FinAmtzaFecVence ON Trn_FinAmtza(FecVence)

GO
ALTER TABLE Trn_FinAportes ADD 
 CONSTRAINT FK_Trn_FinAportes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinAportes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinAportes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinAportes_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinAportes_Sys_TiposDoc FOREIGN KEY (TipLiq) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinAportesFecLiquida ON Trn_FinAportes(FecLiquida)
 CREATE NONCLUSTERED INDEX IX_Trn_FinAportesFecha ON Trn_FinAportes(Fecha)

GO
ALTER TABLE Trn_FinAportesDet ADD 
 CONSTRAINT FK_Trn_FinAportesDet_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinAportesDet_Trn_FinAportes FOREIGN KEY (TipLiq,NumLiquida,IdCia) REFERENCES [dbo].[Trn_FinAportes] (TipLiq,NumLiquida,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinAportesDetIdCliente ON Trn_FinAportesDet(IdCliente,IdAgencia)

GO
ALTER TABLE Trn_FinCanAportes ADD 
 CONSTRAINT FK_Trn_FinCanAportes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinCanAportes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinCanAportes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinCanAportes_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinCanAportes_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinCanAportesFecha ON Trn_FinCanAportes(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinCanAportesIdCliente ON Trn_FinCanAportes(IdCliente,IdAgencia)

GO
ALTER TABLE Trn_FinCauMora ADD 
 CONSTRAINT FK_Trn_FinCauMora_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinCauMora_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinCauMora_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinCauMora_Trn_FinCausacion FOREIGN KEY (TipoProc,NumProc,IdCia) REFERENCES [dbo].[Trn_FinCausacion] (TipoProc,NumProc,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinCauMoraIdPrestamo ON Trn_FinCauMora(TipDoc,IdPrestamo,IdCiaPre,ItemPre)
 CREATE NONCLUSTERED INDEX IX_Trn_FinCauMoraIdCliente ON Trn_FinCauMora(IdCliente)

GO
ALTER TABLE Trn_FinCausacion ADD 
 CONSTRAINT FK_Trn_FinCausacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinCausacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinCausacionFecha ON Trn_FinCausacion(Fecha)

GO
ALTER TABLE Trn_FinCiAportes ADD 
 CONSTRAINT FK_Trn_FinCiAportes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinCiAportes_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_FinCiAportesIdCliente ON Trn_FinCiAportes(IdCliente,IdAgencia,Item)
 CREATE NONCLUSTERED INDEX IX_Trn_FinCiAportesFecInicio ON Trn_FinCiAportes(FecInicio,FecFinal)

GO
ALTER TABLE Trn_FinConvenios ADD 
 CONSTRAINT FK_Trn_FinConvenios_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinConvenios_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinConvenios_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinConvenios_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinConvenios_Sys_TiposDoc FOREIGN KEY (TipLiq) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinConvenios_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinConveniosIdProveedor ON Trn_FinConvenios(IdProveedor)
 CREATE NONCLUSTERED INDEX IX_Trn_FinConveniosFecha ON Trn_FinConvenios(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinConveniosNumFactura ON Trn_FinConvenios(NumFactura)

GO
ALTER TABLE Trn_FinCuotas ADD 
 CONSTRAINT FK_Trn_FinCuotas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinCuotas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinCuotas_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinCuotasFecha ON Trn_FinCuotas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinCuotasIdCliente ON Trn_FinCuotas(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_FinCuotasNumPreMora ON Trn_FinCuotas(NumPreMora,IdCiaCau)
 CREATE NONCLUSTERED INDEX IX_Trn_FinCuotasNumCausacion ON Trn_FinCuotas(TipoCausac,NumCausacion,IdCiaCau)

GO
ALTER TABLE Trn_FinDevFac ADD 
 CONSTRAINT FK_Trn_FinDevFac_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinDevFac_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinDevFac_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinDevFac_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinDevFac_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinDevFac_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_FinDevFac_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinDevFac_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinDevFac_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinDevFac_Trn_FinFactint FOREIGN KEY (TipDoc,Factura,IdCiaDoc) REFERENCES [dbo].[Trn_FinFactint] (TipDoc,Factura,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevFacFecha ON Trn_FinDevFac(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevFacFactura ON Trn_FinDevFac(TipDoc,Factura,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevFacIdCliente ON Trn_FinDevFac(IdCliente)

GO
ALTER TABLE Trn_FinDevPre ADD 
 CONSTRAINT FK_Trn_FinDevPre_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinDevPre_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinDevPre_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinDevPre_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinDevPre_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinDevPre_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinDevPre_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinDevPre_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinDevPre_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCiaDoc) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevPreIdPrestamo ON Trn_FinDevPre(TipDoc,IdPrestamo,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevPreFecha ON Trn_FinDevPre(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevPreIdCliente ON Trn_FinDevPre(IdCliente)

GO
ALTER TABLE Trn_FinDevRec ADD 
 CONSTRAINT FK_Trn_FinDevRec_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinDevRec_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinDevRec_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinDevRec_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinDevRec_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinDevRec_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinDevRec_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinDevRec_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinDevRec_Trn_FinRecibos FOREIGN KEY (TipDoc,Recibo,IdCiaDoc) REFERENCES [dbo].[Trn_FinRecibos] (TipDoc,Recibo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevRecFecha ON Trn_FinDevRec(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevRecRecibo ON Trn_FinDevRec(TipDoc,Recibo,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_FinDevRecIdCliente ON Trn_FinDevRec(IdCliente)

GO
ALTER TABLE Trn_FinFactDet ADD 
 CONSTRAINT FK_Trn_FinFactDet_FinConcFactura FOREIGN KEY (IdConcepto) REFERENCES [dbo].[FinConcFactura] (IdConcepto),
 CONSTRAINT FK_Trn_FinFactDet_Trn_FinFactint FOREIGN KEY (TipDoc,Factura,IdCia) REFERENCES [dbo].[Trn_FinFactint] (TipDoc,Factura,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinFactDetIdConcepto ON Trn_FinFactDet(IdConcepto)

GO
ALTER TABLE Trn_FinFactint ADD 
 CONSTRAINT FK_Trn_FinFactint_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinFactint_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_FinFactint_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinFactint_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinFactint_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinFactint_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinFactint_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_FinFactint_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_FinFactint_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinFactint_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinFactint_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinFactintFecha ON Trn_FinFactint(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinFactintIdCliente ON Trn_FinFactint(IdCliente)

GO
ALTER TABLE Trn_FinFacturas ADD 
 CONSTRAINT FK_Trn_FinFacturas_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCia) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinFacturasNumFactura ON Trn_FinFacturas(NumFactura)
 CREATE NONCLUSTERED INDEX IX_Trn_FinFacturasFecha ON Trn_FinFacturas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinFacturasFechaLiq ON Trn_FinFacturas(FechaLiq)

GO
ALTER TABLE Trn_FinNotas ADD 
 CONSTRAINT FK_Trn_FinNotas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinNotas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinNotas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinNotas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinNotas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinNotas_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_FinNotas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinNotas_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinNotas_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinNotasFecha ON Trn_FinNotas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinNotasIdCliente ON Trn_FinNotas(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_FinNotasComprobante ON Trn_FinNotas(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_FinObserv ADD 
 CONSTRAINT FK_Trn_FinObserv_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCia) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
ALTER TABLE Trn_FinPagos ADD 
 CONSTRAINT FK_Trn_FinPagos_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCia) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinPagosNumero ON Trn_FinPagos(Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_FinPagosFecha ON Trn_FinPagos(Fecha)

GO
ALTER TABLE Trn_FinPrestamo ADD 
 CONSTRAINT FK_Trn_FinPrestamo_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinPrestamo_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinPrestamo_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinPrestamo_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinPrestamo_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinPrestamo_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinPrestamo_TasasInteres FOREIGN KEY (IdTasa) REFERENCES [dbo].[TasasInteres] (IdTasa),
 CONSTRAINT FK_Trn_FinPrestamo_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinPrestamo_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinPrestamoFecha ON Trn_FinPrestamo(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinPrestamoFecPrestamo ON Trn_FinPrestamo(FecPrestamo)
 CREATE NONCLUSTERED INDEX IX_Trn_FinPrestamoIdCliente ON Trn_FinPrestamo(IdCliente)

GO
ALTER TABLE Trn_FinPrestEgreso ADD 
 CONSTRAINT FK_Trn_FinPrestEgreso_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinPrestEgreso_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
ALTER TABLE Trn_FinPrestGarant ADD 
 CONSTRAINT FK_Trn_FinPrestGarant_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinPrestGarant_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCia) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
ALTER TABLE Trn_FinPrestSeguro ADD 
 CONSTRAINT FK_Trn_FinPrestSeguro_Trn_FinPrestamo FOREIGN KEY (TipDoc,IdPrestamo,IdCia) REFERENCES [dbo].[Trn_FinPrestamo] (TipDoc,IdPrestamo,IdCia)
GO
ALTER TABLE Trn_FinRecibos ADD 
 CONSTRAINT FK_Trn_FinRecibos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_FinRecibos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinRecibos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_FinRecibos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_FinRecibos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_FinRecibos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_FinRecibos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_FinRecibos_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_FinRecibosFecha ON Trn_FinRecibos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_FinRecibosIdCliente ON Trn_FinRecibos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_FinRecibosIdVend ON Trn_FinRecibos(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_FinRecibosFecPago ON Trn_FinRecibos(FecPago)

GO
ALTER TABLE Trn_Guia ADD 
 CONSTRAINT FK_Trn_Guia_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Guia_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Guia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Guia_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Guia_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Guia_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Guia_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Guia_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Guia_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Guia_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaFecha ON Trn_Guia(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaFechaDesp ON Trn_Guia(FechaDesp)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaIdCliente ON Trn_Guia(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaIdAgencia ON Trn_Guia(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaIdLocal ON Trn_Guia(IdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaIdVehiculo ON Trn_Guia(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaIdConductor ON Trn_Guia(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaOCargue ON Trn_Guia(TipOcc,OCargue,IdCiaOcc)
 CREATE NONCLUSTERED INDEX IX_Trn_GuiaFactura ON Trn_Guia(TipFac,Factura,IdCiaFac)

GO
ALTER TABLE Trn_InvDetalle ADD 
 CONSTRAINT FK_Trn_InvDetalle_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_InvDetalle_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_InvDetalle_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_InvDetalle_Trn_InvFisico FOREIGN KEY (TipDoc,nInventario,IdCia) REFERENCES [dbo].[Trn_InvFisico] (TipDoc,nInventario,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_InvDetalleIdProducto ON Trn_InvDetalle(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_InvDetalleIdBodega ON Trn_InvDetalle(IdBodega)
 CREATE NONCLUSTERED INDEX IX_Trn_InvDetalleIdUsuario ON Trn_InvDetalle(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Trn_InvDetalleIdEstacion ON Trn_InvDetalle(IdEstacion)

GO
ALTER TABLE Trn_InvFisico ADD 
 CONSTRAINT FK_Trn_InvFisico_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_InvFisico_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_InvFisico_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_InvFisico_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_InvFisico_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_InvFisicoFecha ON Trn_InvFisico(Fecha)

GO
ALTER TABLE Trn_JurCasos ADD 
 CONSTRAINT FK_Trn_JurCasos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_JurCasos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_JurCasos_JurAutoridades FOREIGN KEY (IdAutoridad) REFERENCES [dbo].[JurAutoridades] (IdAutoridad),
 CONSTRAINT FK_Trn_JurCasos_JurCalifica FOREIGN KEY (IdCalifica) REFERENCES [dbo].[JurCalifica] (IdCalifica),
 CONSTRAINT FK_Trn_JurCasos_JurClaseAcc FOREIGN KEY (IdClase) REFERENCES [dbo].[JurClaseAcc] (IdClase),
 CONSTRAINT FK_Trn_JurCasos_JurEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[JurEstados] (IdEstado),
 CONSTRAINT FK_Trn_JurCasos_JurTipos FOREIGN KEY (IdTipoPro) REFERENCES [dbo].[JurTipos] (IdTipoPro),
 CONSTRAINT FK_Trn_JurCasos_Rutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[Rutas] (IdRuta),
 CONSTRAINT FK_Trn_JurCasos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_JurCasos_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_JurCasos_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_JurCasos_Terceros2 FOREIGN KEY (IdAbogado) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_JurCasosFecha ON Trn_JurCasos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_JurCasosIdVehiculo ON Trn_JurCasos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_JurCasosIdPropietario ON Trn_JurCasos(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_JurCasosCartulina ON Trn_JurCasos(TipCar,Cartulina,IdCiaCar)

GO
ALTER TABLE Trn_JurCasosHis ADD 
 CONSTRAINT FK_Trn_JurCasosHis_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_JurCasosHis_Trn_JurCasos FOREIGN KEY (TipDoc,CasoID,IdCia) REFERENCES [dbo].[Trn_JurCasos] (TipDoc,CasoID,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_JurCasosHisFechaUp ON Trn_JurCasosHis(FechaUp)

GO
ALTER TABLE Trn_JurCasosQtn ADD 
 CONSTRAINT FK_Trn_JurCasosQtn_JurPreguntas FOREIGN KEY (IdPregunta) REFERENCES [dbo].[JurPreguntas] (IdPregunta),
 CONSTRAINT FK_Trn_JurCasosQtn_Trn_JurCasos FOREIGN KEY (TipDoc,CasoID,IdCia) REFERENCES [dbo].[Trn_JurCasos] (TipDoc,CasoID,IdCia)
GO
ALTER TABLE Trn_JurInvesHis ADD 
 CONSTRAINT FK_Trn_JurInvesHis_JurEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[JurEstados] (IdEstado),
 CONSTRAINT FK_Trn_JurInvesHis_Trn_JurInvestiga FOREIGN KEY (TipDoc,CasoID,IdCia) REFERENCES [dbo].[Trn_JurInvestiga] (TipDoc,CasoID,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_JurInvesHisFechaUp ON Trn_JurInvesHis(FechaUp)

GO
ALTER TABLE Trn_JurInvestiga ADD 
 CONSTRAINT FK_Trn_JurInvestiga_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_JurInvestiga_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_JurInvestiga_JurAutoridades FOREIGN KEY (IdAutoridad) REFERENCES [dbo].[JurAutoridades] (IdAutoridad),
 CONSTRAINT FK_Trn_JurInvestiga_JurEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[JurEstados] (IdEstado),
 CONSTRAINT FK_Trn_JurInvestiga_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_JurInvestiga_Terceros FOREIGN KEY (IdAbogado) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_JurInvestiga_Terceros1 FOREIGN KEY (IdEmpresa) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_JurInvestigaFecha ON Trn_JurInvestiga(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_JurInvestigaIdAbogado ON Trn_JurInvestiga(IdAbogado)
 CREATE NONCLUSTERED INDEX IX_Trn_JurInvestigaIdEmpresa ON Trn_JurInvestiga(IdEmpresa)

GO
ALTER TABLE Trn_JurInvVehic ADD 
 CONSTRAINT FK_Trn_JurInvVehic_Trn_JurInvestiga FOREIGN KEY (TipDoc,CasoID,IdCia) REFERENCES [dbo].[Trn_JurInvestiga] (TipDoc,CasoID,IdCia)
GO
ALTER TABLE Trn_JurReclamac ADD 
 CONSTRAINT FK_Trn_JurReclamac_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_JurReclamac_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_JurReclamac_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_JurReclamac_JurTiposRec FOREIGN KEY (IdTipoRec) REFERENCES [dbo].[JurTiposRec] (IdTipoRec),
 CONSTRAINT FK_Trn_JurReclamac_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_JurReclamac_Terceros FOREIGN KEY (IdReclamnte) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_JurReclamacFecha ON Trn_JurReclamac(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_JurReclamacSiniestro ON Trn_JurReclamac(TipSin,Siniestro,IdCiaSin)

GO
ALTER TABLE Trn_JurRecOfrecmto ADD 
 CONSTRAINT FK_Trn_JurRecOfrecmto_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_JurRecOfrecmto_Trn_JurReclamac FOREIGN KEY (TipDoc,Reclamac,IdCia) REFERENCES [dbo].[Trn_JurReclamac] (TipDoc,Reclamac,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_JurRecOfrecmtoFechaOfrec ON Trn_JurRecOfrecmto(FechaOfrec)

GO
ALTER TABLE Trn_Kardex ADD 
 CONSTRAINT FK_Trn_Kardex_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_Kardex_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Kardex_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Kardex_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_Kardex_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Kardex_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Kardex_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Kardex_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE CLUSTERED INDEX IX_Trn_KardexFechaIdProducto ON Trn_Kardex(Fecha,IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexTimeSys ON Trn_Kardex(TimeSys)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexIdBodega ON Trn_Kardex(IdBodega)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexIdTercero ON Trn_Kardex(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexIdVend ON Trn_Kardex(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexNumOrden ON Trn_Kardex(TipOrd,NumOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexNumDocDev ON Trn_Kardex(TipDocDev,NumDocDev)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexCotizacion ON Trn_Kardex(Cotizacion,IdCiaCot)
 CREATE NONCLUSTERED INDEX IX_Trn_KardexRemision ON Trn_Kardex(Remision,IdCiaRem)

GO
ALTER TABLE Trn_KarUbic ADD 
 CONSTRAINT FK_Trn_KarUbic_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_KarUbic_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_KarUbic_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_KarUbic_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_KarUbicIdProducto ON Trn_KarUbic(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_KarUbicIdBodega ON Trn_KarUbic(IdBodega)
 CREATE NONCLUSTERED INDEX IX_Trn_KarUbicIdUbic ON Trn_KarUbic(IdUbic)
 CREATE NONCLUSTERED INDEX IX_Trn_KarUbicLinea ON Trn_KarUbic(Linea)

GO
ALTER TABLE Trn_Lotes ADD 
 CONSTRAINT FK_Trn_Lotes_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_Lotes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Lotes_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_LotesFecha ON Trn_Lotes(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_LotesFecVence ON Trn_Lotes(FecVence)
 CREATE NONCLUSTERED INDEX IX_Trn_LotesEntrada ON Trn_Lotes(Entrada)

GO
ALTER TABLE Trn_LotMov ADD 
 CONSTRAINT FK_Trn_LotMov_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_LotMov_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_LotMov_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_LotMov_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_LotMovNumLote ON Trn_LotMov(NumLote)
 CREATE NONCLUSTERED INDEX IX_Trn_LotMovIdProducto ON Trn_LotMov(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_LotMovIdBodega ON Trn_LotMov(IdBodega)
 CREATE NONCLUSTERED INDEX IX_Trn_LotMovFecha ON Trn_LotMov(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_LotMovLinea ON Trn_LotMov(Linea)
 CREATE NONCLUSTERED INDEX IX_Trn_LotMovFecVence ON Trn_LotMov(FecVence)

GO
ALTER TABLE Trn_MayAgencias ADD 
 CONSTRAINT FK_Trn_MayAgencias_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
ALTER TABLE Trn_MayAnotaciones ADD 
 CONSTRAINT FK_Trn_MayAnotaciones_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
ALTER TABLE Trn_MayBonif ADD 
 CONSTRAINT FK_Trn_MayBonif_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
ALTER TABLE Trn_MayCesion ADD 
 CONSTRAINT FK_Trn_MayCesion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MayCesion_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MayCesion_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayCesionFecha ON Trn_MayCesion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MayCesionNContrato ON Trn_MayCesion(NContrato,IdCia)

GO
ALTER TABLE Trn_MayContDoc ADD 
 CONSTRAINT FK_Trn_MayContDoc_MayTiposDoc FOREIGN KEY (IdDoc) REFERENCES [dbo].[MayTiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_MayContDoc_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayContDocIdDoc ON Trn_MayContDoc(IdDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_MayContDocFechaRad ON Trn_MayContDoc(FechaRad)

GO
ALTER TABLE Trn_MayContratos ADD 
 CONSTRAINT FK_Trn_MayContratos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MayContratos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MayContratos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MayContratos_MayEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[MayEstados] (IdEstado),
 CONSTRAINT FK_Trn_MayContratos_MayTipos FOREIGN KEY (IdTipo) REFERENCES [dbo].[MayTipos] (IdTipo),
 CONSTRAINT FK_Trn_MayContratos_MayTiposBonif FOREIGN KEY (IdBonif) REFERENCES [dbo].[MayTiposBonif] (IdBonif),
 CONSTRAINT FK_Trn_MayContratos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MayContratos_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MayContratos_TiposBan FOREIGN KEY (IdBandera) REFERENCES [dbo].[TiposBan] (IdBandera)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayContratosIdCliente ON Trn_MayContratos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_MayContratosIdAgencia ON Trn_MayContratos(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_MayContratosFecha ON Trn_MayContratos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MayContratosNumInterno ON Trn_MayContratos(IdTipo,NumInterno)

GO
ALTER TABLE Trn_MayFacturas ADD 
 CONSTRAINT FK_Trn_MayFacturas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MayFacturas_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_MayFacturas_Sys_TiposDoc FOREIGN KEY (TipFac) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_MayFacturas_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_MayFacturasFecha ON Trn_MayFacturas(Fecha,IdCliente,IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_MayFacturasNContrato ON Trn_MayFacturas(NContrato,CdCiaCon)

GO
ALTER TABLE Trn_MayInventario ADD 
 CONSTRAINT FK_Trn_MayInventario_MayItemsInv FOREIGN KEY (IdArticulo) REFERENCES [dbo].[MayItemsInv] (IdArticulo),
 CONSTRAINT FK_Trn_MayInventario_MayTipos FOREIGN KEY (IdTipo) REFERENCES [dbo].[MayTipos] (IdTipo),
 CONSTRAINT FK_Trn_MayInventario_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayInventarioIdArticulo ON Trn_MayInventario(IdArticulo)
 CREATE NONCLUSTERED INDEX IX_Trn_MayInventarioDocumento ON Trn_MayInventario(TipDoc,Documento,IdCiaDoc)

GO
ALTER TABLE Trn_MayInvmov ADD 
 CONSTRAINT FK_Trn_MayInvmov_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MayInvmov_MayItemsInv FOREIGN KEY (IdArticulo) REFERENCES [dbo].[MayItemsInv] (IdArticulo)
GO
ALTER TABLE Trn_MayLiqDetalle ADD 
 CONSTRAINT FK_Trn_MayLiqDetalle_SubGrupos FOREIGN KEY (IdSubgrupo) REFERENCES [dbo].[SubGrupos] (IdSubgrupo),
 CONSTRAINT FK_Trn_MayLiqDetalle_Trn_MayLiquida FOREIGN KEY (NLiquida,IdCia) REFERENCES [dbo].[Trn_MayLiquida] (NLiquida,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayLiqDetalleIdSubgrupo ON Trn_MayLiqDetalle(IdSubgrupo)

GO
ALTER TABLE Trn_MayLiqTotales ADD 
 CONSTRAINT FK_Trn_MayLiqTotales_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_MayLiqTotales_TercCliente FOREIGN KEY (IdCliente) REFERENCES [dbo].[TercCliente] (IdClie),
 CONSTRAINT FK_Trn_MayLiqTotales_Trn_MayLiquida FOREIGN KEY (NLiquida,IdCia) REFERENCES [dbo].[Trn_MayLiquida] (NLiquida,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayLiqTotalesNContrato ON Trn_MayLiqTotales(NContrato,IdCiaCon)
 CREATE NONCLUSTERED INDEX IX_Trn_MayLiqTotalesIdCliente ON Trn_MayLiqTotales(IdCliente)

GO
ALTER TABLE Trn_MayLiquida ADD 
 CONSTRAINT FK_Trn_MayLiquida_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MayLiquida_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MayLiquidaFecha ON Trn_MayLiquida(Fecha)

GO
ALTER TABLE Trn_MayPspto ADD 
 CONSTRAINT FK_Trn_MayPspto_Trn_MayContratos FOREIGN KEY (NContrato,IdCia) REFERENCES [dbo].[Trn_MayContratos] (NContrato,IdCia)
GO
ALTER TABLE Trn_MttoDiagn ADD 
 CONSTRAINT FK_Trn_MttoDiagn_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MttoDiagn_Terceros FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MttoDiagn_Trn_MttoOrden FOREIGN KEY (TipOdt,NumOrden,IdCia) REFERENCES [dbo].[Trn_MttoOrden] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_MttoDiagnDet ADD 
 CONSTRAINT FK_Trn_MttoDiagnDet_MttoInspecciones FOREIGN KEY (IdInspec) REFERENCES [dbo].[MttoInspecciones] (IdInspec),
 CONSTRAINT FK_Trn_MttoDiagnDet_Trn_MttoDiagn FOREIGN KEY (TipOdt,NumOrden,IdCia,NumDiagn) REFERENCES [dbo].[Trn_MttoDiagn] (TipOdt,NumOrden,IdCia,NumDiagn)
GO
ALTER TABLE Trn_MttoOrden ADD 
 CONSTRAINT FK_Trn_MttoOrden_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MttoOrden_CentrosServ FOREIGN KEY (IdCenSer) REFERENCES [dbo].[CentrosServ] (IdCenSer),
 CONSTRAINT FK_Trn_MttoOrden_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MttoOrden_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MttoOrden_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_MttoOrden_MttoTiposOdt FOREIGN KEY (IdTipoOdt) REFERENCES [dbo].[MttoTiposOdt] (IdTipoOdt),
 CONSTRAINT FK_Trn_MttoOrden_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_MttoOrden_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MttoOrden_Terceros1 FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MttoOrden_Terceros2 FOREIGN KEY (IdSupervisor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenFecha ON Trn_MttoOrden(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenFechaOrden ON Trn_MttoOrden(FechaOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenIdVehiculo ON Trn_MttoOrden(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenIdConductor ON Trn_MttoOrden(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenIdOperario ON Trn_MttoOrden(IdOperario)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenIdCenSer ON Trn_MttoOrden(IdCenSer)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdennRemolque ON Trn_MttoOrden(nRemolque)

GO
ALTER TABLE Trn_MttoOrdenDet ADD 
 CONSTRAINT FK_Trn_MttoOrdenDet_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MttoOrdenDet_MttoConceptos FOREIGN KEY (IdConc) REFERENCES [dbo].[MttoConceptos] (IdConc),
 CONSTRAINT FK_Trn_MttoOrdenDet_MttoEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[MttoEstados] (IdEstado),
 CONSTRAINT FK_Trn_MttoOrdenDet_Terceros FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MttoOrdenDet_Trn_MttoOrden FOREIGN KEY (TipOdt,NumOrden,IdCia) REFERENCES [dbo].[Trn_MttoOrden] (TipDoc,NumOrden,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenDetFechaServ ON Trn_MttoOrdenDet(FechaServ)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenDetIdConc ON Trn_MttoOrdenDet(IdConc)

GO
ALTER TABLE Trn_MttoOrdenReq ADD 
 CONSTRAINT FK_Trn_MttoOrdenReq_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MttoOrdenReq_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_MttoOrdenReq_Terceros FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MttoOrdenReq_Trn_MttoOrden FOREIGN KEY (TipOdt,NumOrden,IdCiaOdt) REFERENCES [dbo].[Trn_MttoOrden] (TipDoc,NumOrden,IdCia),
 CONSTRAINT FK_Trn_MttoOrdenReq_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenReqIdProducto ON Trn_MttoOrdenReq(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenReqNumSalida ON Trn_MttoOrdenReq(TipSal,NumSalida,IdCiaSal)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoOrdenReqNumOrden ON Trn_MttoOrdenReq(TipOdt,NumOrden,IdCiaOdt)

GO
ALTER TABLE Trn_MttoTrabajos ADD 
 CONSTRAINT FK_Trn_MttoTrabajos_MttoConceptos FOREIGN KEY (IdConc) REFERENCES [dbo].[MttoConceptos] (IdConc)
GO
 CREATE CLUSTERED INDEX IX_Trn_MttoTrabajosFecha ON Trn_MttoTrabajos(IdVehiculo,nRemolque,IdConc,Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MttoTrabajosNumOrden ON Trn_MttoTrabajos(TipDoc,NumOrden,IdCia)

GO
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)
GO
ALTER TABLE Trn_MudContFact ADD 
 CONSTRAINT FK_Trn_MudContFact_Trn_MudContratos FOREIGN KEY (TipDoc,NumContrato,IdCia) REFERENCES [dbo].[Trn_MudContratos] (TipDoc,NumContrato,IdCia)
GO
ALTER TABLE Trn_MudContNov ADD 
 CONSTRAINT FK_Trn_MudContNov_Trn_MudContratos FOREIGN KEY (TipDoc,NumContrato,IdCia) REFERENCES [dbo].[Trn_MudContratos] (TipDoc,NumContrato,IdCia)
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)
GO
 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)

GO
ALTER TABLE Trn_MudInventario ADD 
 CONSTRAINT FK_Trn_MudInventario_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MudInventario_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_MudInventario_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MudInventario_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MudInventario_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_MudInventario_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_MudInventario_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_MudInventario_MudServicios FOREIGN KEY (IdTipoServ) REFERENCES [dbo].[MudServicios] (IdTipoServ),
 CONSTRAINT FK_Trn_MudInventario_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_MudInventario_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MudInventario_TercVendedor FOREIGN KEY (IdVend) REFERENCES [dbo].[TercVendedor] (IdVend)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MudInventarioFecha ON Trn_MudInventario(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MudInventarioFecDespacho ON Trn_MudInventario(FecDespacho)
 CREATE NONCLUSTERED INDEX IX_Trn_MudInventarioIdCliente ON Trn_MudInventario(IdCliente,IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_MudInventarioIdOrigen ON Trn_MudInventario(IdOrigen,IdDestino)

GO
ALTER TABLE Trn_MudInventDet ADD 
 CONSTRAINT FK_Trn_MudInventDet_MudEstados FOREIGN KEY (IdEstado) REFERENCES [dbo].[MudEstados] (IdEstado),
 CONSTRAINT FK_Trn_MudInventDet_Trn_MudInventario FOREIGN KEY (TipDoc,NumInvent,IdCia) REFERENCES [dbo].[Trn_MudInventario] (TipDoc,NumInvent,IdCia)
GO
ALTER TABLE Trn_MudOrdenConc ADD 
 CONSTRAINT FK_Trn_MudOrdenConc_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_MudOrdenConc_Trn_MudOrdenServ FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_MudOrdenServ] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_MudOrdenNov ADD 
 CONSTRAINT FK_Trn_MudOrdenNov_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MudOrdenNov_Trn_MudOrdenServ FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_MudOrdenServ] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_MudOrdenOper ADD 
 CONSTRAINT FK_Trn_MudOrdenOper_TiposOperarios FOREIGN KEY (IdTipoOper) REFERENCES [dbo].[TiposOperarios] (IdOper),
 CONSTRAINT FK_Trn_MudOrdenOper_Trn_MudOrdenServ FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_MudOrdenServ] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_MudOrdenServ ADD 
 CONSTRAINT FK_Trn_MudOrdenServ_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_MudOrdenServ_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MudOrdenServ_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_MudOrdenServ_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_MudOrdenServ_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_MudOrdenServ_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_MudOrdenServ_MudServicios FOREIGN KEY (IdTipoServ) REFERENCES [dbo].[MudServicios] (IdTipoServ),
 CONSTRAINT FK_Trn_MudOrdenServ_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_MudOrdenServ_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MudOrdenServ_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_MudOrdenServFecha ON Trn_MudOrdenServ(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_MudOrdenServIdCliente ON Trn_MudOrdenServ(IdCliente)

GO
ALTER TABLE Trn_MudOrdenVeh ADD 
 CONSTRAINT FK_Trn_MudOrdenVeh_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_MudOrdenVeh_Trn_MudOrdenServ FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_MudOrdenServ] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_NiifComp ADD 
 CONSTRAINT FK_Trn_NiifComp_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NiifComp_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NiifComp_Companias1 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NiifComp_Companias2 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NiifComp_CtasCorrientes FOREIGN KEY (IdCta) REFERENCES [dbo].[CtasCorrientes] (IdCta),
 CONSTRAINT FK_Trn_NiifComp_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_NiifComp_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_NiifComp_TiposCom FOREIGN KEY (TipCom) REFERENCES [dbo].[TiposCom] (IdCom)
GO
 CREATE CLUSTERED INDEX IX_Trn_NiifCompFecha ON Trn_NiifComp(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifCompIdTercero ON Trn_NiifComp(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifCompDocumento ON Trn_NiifComp(TipDoc,Documento,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifCompIdCta ON Trn_NiifComp(IdCta)

GO
ALTER TABLE Trn_NiifDetalle ADD 
 CONSTRAINT FK_Trn_NiifDetalle_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NiifDetalle_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_NiifDetalle_Companias FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NiifDetalle_PucNiif FOREIGN KEY (IdCuenta) REFERENCES [dbo].[PucNiif] (IdCuenta),
 CONSTRAINT FK_Trn_NiifDetalle_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_NiifDetalle_Trn_NiifComp FOREIGN KEY (TipCom,Comprobante,IdCia) REFERENCES [dbo].[Trn_NiifComp] (TipCom,Comprobante,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_NiifDetalleFecha ON Trn_NiifDetalle(Fecha,IdCuenta,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifDetalleIdCCosto ON Trn_NiifDetalle(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifDetalleIdSubCos ON Trn_NiifDetalle(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifDetalleIdTercero ON Trn_NiifDetalle(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifDetalleCodAgncia ON Trn_NiifDetalle(CodAgncia)
 CREATE NONCLUSTERED INDEX IX_Trn_NiifDetalleIdVehiculo ON Trn_NiifDetalle(IdVehiculo)

GO
 CREATE UNIQUE CLUSTERED INDEX IX_Trn_NiifPoliticasIdPolitica ON Trn_NiifPoliticas(IdPolitica)

GO
ALTER TABLE Trn_NomAbonos ADD 
 CONSTRAINT FK_Trn_NomAbonos_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomAbonos_Trn_NomPrest FOREIGN KEY (NPrestamo) REFERENCES [dbo].[Trn_NomPrest] (NPrestamo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAbonosIdEmpleado ON Trn_NomAbonos(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAbonosFechaAbo ON Trn_NomAbonos(FechaAbo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAbonosDscto ON Trn_NomAbonos(Dscto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAbonosNPrestamo ON Trn_NomAbonos(NPrestamo)

GO
ALTER TABLE Trn_NomAjustes ADD 
 CONSTRAINT FK_Trn_NomAjustes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomAjustes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NomAjustes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NomAjustes_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomAjustes_TiposNom FOREIGN KEY (IdNom) REFERENCES [dbo].[TiposNom] (IdNom)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAjustesIdEmpleado ON Trn_NomAjustes(IdEmpleado,NContrato,IdPeriodo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAjustesFechaInicial ON Trn_NomAjustes(FechaInicial,FechaFinal)

GO
ALTER TABLE Trn_NomAjustesDet ADD 
 CONSTRAINT FK_Trn_NomAjustesDet_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NomAjustesDet_Trn_NomAjustes FOREIGN KEY (TipNota,NumNota,IdCia) REFERENCES [dbo].[Trn_NomAjustes] (TipNota,NumNota,IdCia)
GO
ALTER TABLE Trn_NomAlqDet ADD 
 CONSTRAINT FK_Trn_NomAlqDet_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomAlqDet_Fondos FOREIGN KEY (IdFonPen) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Trn_NomAlqDet_Fondos1 FOREIGN KEY (IdFonSal) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Trn_NomAlqDet_Fondos2 FOREIGN KEY (IdFonRie) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Trn_NomAlqDet_Fondos3 FOREIGN KEY (IdCajCom) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Trn_NomAlqDet_Trn_NomAutoliq FOREIGN KEY (TipoLiq,Numero) REFERENCES [dbo].[Trn_NomAutoliq] (TipoLiq,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetNumero ON Trn_NomAlqDet(TipoLiq,Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetIdEmpleado ON Trn_NomAlqDet(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetNContrato ON Trn_NomAlqDet(NContrato)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetIdFonPen ON Trn_NomAlqDet(IdFonPen)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetIdFonSal ON Trn_NomAlqDet(IdFonSal)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetIdFonRie ON Trn_NomAlqDet(IdFonRie)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqDetIdCajCom ON Trn_NomAlqDet(IdCajCom)

GO
ALTER TABLE Trn_NomAlqNov ADD 
 CONSTRAINT FK_Trn_NomAlqNov_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomAlqNov_Trn_NomAutoliq FOREIGN KEY (TipoLiq,Numero) REFERENCES [dbo].[Trn_NomAutoliq] (TipoLiq,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqNovNumero ON Trn_NomAlqNov(TipoLiq,Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqNovIdEmpleado ON Trn_NomAlqNov(IdEmpleado)

GO
ALTER TABLE Trn_NomAlqNvd ADD 
 CONSTRAINT FK_Trn_NomAlqNvd_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomAlqNvd_Trn_NomAutoliq FOREIGN KEY (TipoLiq,Numero) REFERENCES [dbo].[Trn_NomAutoliq] (TipoLiq,Numero)
GO
ALTER TABLE Trn_NomAlqTot ADD 
 CONSTRAINT FK_Trn_NomAlqTot_Fondos FOREIGN KEY (IdFondo) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Trn_NomAlqTot_Trn_NomAutoliq FOREIGN KEY (TipoLiq,Numero) REFERENCES [dbo].[Trn_NomAutoliq] (TipoLiq,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqTotNumero ON Trn_NomAlqTot(TipoLiq,Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqTotIdFondo ON Trn_NomAlqTot(IdFondo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqTotTipAdm ON Trn_NomAlqTot(TipAdm)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAlqTotTipoReg ON Trn_NomAlqTot(TipoReg)

GO
ALTER TABLE Trn_NomAstncia ADD 
 CONSTRAINT FK_Trn_NomAstncia_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomAstncia_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAstnciaIdEmpleado ON Trn_NomAstncia(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAstnciaIdUsuario ON Trn_NomAstncia(IdUsuario)

GO
ALTER TABLE Trn_NomAutoliq ADD 
 CONSTRAINT FK_Trn_NomAutoliq_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomAutoliq_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_NomAutoliq_NomAportante FOREIGN KEY (IdAportnte) REFERENCES [dbo].[NomAportante] (IdAportnte)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomAutoliqFecha ON Trn_NomAutoliq(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAutoliqPerAutoliq ON Trn_NomAutoliq(PerAutoliq)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAutoliqIdAportnte ON Trn_NomAutoliq(IdAportnte)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAutoliqFechaPago ON Trn_NomAutoliq(FechaPago)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAutoliqIdEstado ON Trn_NomAutoliq(IdEstado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomAutoliqIdUsuario ON Trn_NomAutoliq(IdUsuario)

GO
ALTER TABLE Trn_NomCAdmon ADD 
 CONSTRAINT FK_Trn_NomCAdmon_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomCAdmon_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomCAdmon_Fondos FOREIGN KEY (IdFondo) REFERENCES [dbo].[Fondos] (IdFondo),
 CONSTRAINT FK_Trn_NomCAdmon_Fondos1 FOREIGN KEY (IdFonNew) REFERENCES [dbo].[Fondos] (IdFondo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonIdEmpleado ON Trn_NomCAdmon(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonFecha ON Trn_NomCAdmon(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonClaseAdmon ON Trn_NomCAdmon(ClaseAdmon)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonNNovedad ON Trn_NomCAdmon(NNovedad)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonIdFondo ON Trn_NomCAdmon(IdFondo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonIdFonNew ON Trn_NomCAdmon(IdFonNew)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCAdmonIdUsuario ON Trn_NomCAdmon(IdUsuario)

GO
ALTER TABLE Trn_NomCertf ADD 
 CONSTRAINT FK_Trn_NomCertf_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomCertf_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomCertfIdEmpleado ON Trn_NomCertf(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCertfNumCertf ON Trn_NomCertf(NumCertf)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCertfnAnno ON Trn_NomCertf(nAnno)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCertfnMes ON Trn_NomCertf(nMes)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCertfIdUsuario ON Trn_NomCertf(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Trn_NomCertfClaseCert ON Trn_NomCertf(ClaseCert)

GO
ALTER TABLE Trn_NomConAuto ADD 
 CONSTRAINT FK_Trn_NomConAuto_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomConAuto_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomConAutoIdConcepto ON Trn_NomConAuto(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomConAutoFecInicio ON Trn_NomConAuto(FecInicio)
 CREATE NONCLUSTERED INDEX IX_Trn_NomConAutoIdUsuario ON Trn_NomConAuto(IdUsuario)

GO
ALTER TABLE Trn_NomDetalle ADD 
 CONSTRAINT FK_Trn_NomDetalle_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomDetalle_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NomDetalle_Trn_Nomina FOREIGN KEY (IdPeriodo,KeyRegistro) REFERENCES [dbo].[Trn_Nomina] (IdPeriodo,KeyRegistro)
GO
 CREATE CLUSTERED INDEX IX_Trn_NomDetalleItem ON Trn_NomDetalle(IdPeriodo,IdEmpleado,IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomDetalleIdPeriodoKey ON Trn_NomDetalle(KeyRegistro)
 CREATE NONCLUSTERED INDEX IX_Trn_NomDetalleClaseLiq ON Trn_NomDetalle(ClaseLiq)
 CREATE NONCLUSTERED INDEX IX_Trn_NomDetalleNPrestamo ON Trn_NomDetalle(NPrestamo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomDetalleNCuota ON Trn_NomDetalle(NCuota)

GO
ALTER TABLE Trn_NomDiario ADD 
 CONSTRAINT FK_Trn_NomDiario_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomDiario_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE CLUSTERED INDEX IX_Trn_NomDiarioIdEmpleado ON Trn_NomDiario(IdEmpleado,Fecha)

GO
ALTER TABLE Trn_NomDotacion ADD 
 CONSTRAINT FK_Trn_NomDotacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomDotacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomDotacionFecha ON Trn_NomDotacion(Fecha)

GO
ALTER TABLE Trn_NomDotacionDet ADD 
 CONSTRAINT FK_Trn_NomDotacionDet_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomDotacionDet_NomPrendas FOREIGN KEY (IdPrend) REFERENCES [dbo].[NomPrendas] (IdPrend),
 CONSTRAINT FK_Trn_NomDotacionDet_Trn_NomDotacion FOREIGN KEY (IdCia,Numero) REFERENCES [dbo].[Trn_NomDotacion] (IdCia,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomDotacionDetIdEmpleado ON Trn_NomDotacionDet(IdEmpleado)

GO
ALTER TABLE Trn_NomFijos ADD 
 CONSTRAINT FK_Trn_NomFijos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomFijos_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomFijosIdEmpleado ON Trn_NomFijos(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomFijosnAnno ON Trn_NomFijos(nAnno)
 CREATE NONCLUSTERED INDEX IX_Trn_NomFijosnMes ON Trn_NomFijos(nMes)
 CREATE NONCLUSTERED INDEX IX_Trn_NomFijosIdUsuario ON Trn_NomFijos(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Trn_NomFijosOrignPorc ON Trn_NomFijos(OrignPorc)

GO
ALTER TABLE Trn_Nomina ADD 
 CONSTRAINT FK_Trn_Nomina_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Nomina_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Nomina_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_Nomina_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_Nomina_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Nomina_Instalaciones FOREIGN KEY (IdInstala) REFERENCES [dbo].[Instalaciones] (IdInstala),
 CONSTRAINT FK_Trn_Nomina_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_Nomina_TiposNom FOREIGN KEY (IdNom) REFERENCES [dbo].[TiposNom] (IdNom)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdPeriodo ON Trn_Nomina(IdPeriodo)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdEmpleado ON Trn_Nomina(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaFecInicial ON Trn_Nomina(FecInicial)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaFecFinal ON Trn_Nomina(FecFinal)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaNContrato ON Trn_Nomina(NContrato)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdDep ON Trn_Nomina(IdDep)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdInstala ON Trn_Nomina(IdInstala)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdCCosto ON Trn_Nomina(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdSubCos ON Trn_Nomina(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdNom ON Trn_Nomina(IdNom)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdEstado ON Trn_Nomina(IdEstado)
 CREATE NONCLUSTERED INDEX IX_Trn_NominaIdUsuario ON Trn_Nomina(IdUsuario)

GO
ALTER TABLE Trn_NomLiqDet ADD 
 CONSTRAINT FK_Trn_NomLiqDet_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_NomLiqDet_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_NomLiqDet_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomLiqDet_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NomLiqDet_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_NomLiqDet_TiposNom FOREIGN KEY (IdNom) REFERENCES [dbo].[TiposNom] (IdNom),
 CONSTRAINT FK_Trn_NomLiqDet_Trn_NomLiquida FOREIGN KEY (TipoLiq,Numero) REFERENCES [dbo].[Trn_NomLiquida] (TipoLiq,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetIdConcepto ON Trn_NomLiqDet(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetFecInicial ON Trn_NomLiqDet(FecInicial)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetFecFinal ON Trn_NomLiqDet(FecFinal)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetIdEmpleado ON Trn_NomLiqDet(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetNPrestamo ON Trn_NomLiqDet(NPrestamo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetIdDep ON Trn_NomLiqDet(IdDep)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetIdSubCos ON Trn_NomLiqDet(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetIdCCosto ON Trn_NomLiqDet(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiqDetIdNom ON Trn_NomLiqDet(IdNom)

GO
ALTER TABLE Trn_NomLiquida ADD 
 CONSTRAINT FK_Trn_NomLiquida_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomLiquida_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiquidaFecha ON Trn_NomLiquida(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiquidaIdEstado ON Trn_NomLiquida(IdEstado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLiquidaIdUsuario ON Trn_NomLiquida(IdUsuario)

GO
ALTER TABLE Trn_NomLogVeh ADD 
 CONSTRAINT FK_Trn_NomLogVeh_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomLogVeh_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomLogVehIdEmpleado ON Trn_NomLogVeh(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLogVehpVehNew ON Trn_NomLogVeh(pVehNew)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLogVehNitPropNew ON Trn_NomLogVeh(NitPropNew)
 CREATE NONCLUSTERED INDEX IX_Trn_NomLogVehIdUsuario ON Trn_NomLogVeh(IdUsuario)

GO
ALTER TABLE Trn_NomNov ADD 
 CONSTRAINT FK_Trn_NomNov_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomNov_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomNov_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovIdPeriodo ON Trn_NomNov(IdPeriodo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovIdEmpleado ON Trn_NomNov(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovIdConcepto ON Trn_NomNov(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovIdUsuario ON Trn_NomNov(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovItem ON Trn_NomNov(Item)

GO
ALTER TABLE Trn_NomNovedad ADD 
 CONSTRAINT FK_Trn_NomNovedad_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomNovedad_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomNovedad_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NomNovedad_TiposNov FOREIGN KEY (IdNov) REFERENCES [dbo].[TiposNov] (IdNov)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovedadIdEmpleado ON Trn_NomNovedad(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovedadIdConcepto ON Trn_NomNovedad(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovedadFecInicio ON Trn_NomNovedad(FecInicio)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovedadIdNov ON Trn_NomNovedad(IdNov)
 CREATE NONCLUSTERED INDEX IX_Trn_NomNovedadIdUsuario ON Trn_NomNovedad(IdUsuario)

GO
ALTER TABLE Trn_NomPrest ADD 
 CONSTRAINT FK_Trn_NomPrest_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomPrest_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomPrest_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomPrestIdEmpleado ON Trn_NomPrest(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomPrestIdConcepto ON Trn_NomPrest(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomPrestFecha ON Trn_NomPrest(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomPrestIdUsuario ON Trn_NomPrest(IdUsuario)
 CREATE NONCLUSTERED INDEX IX_Trn_NomPrestFrecDcto ON Trn_NomPrest(FrecDcto)

GO
ALTER TABLE Trn_NomPrmSalud ADD 
 CONSTRAINT FK_Trn_NomPrmSalud_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
ALTER TABLE Trn_NomProrrogas ADD 
 CONSTRAINT FK_Trn_NomProrrogas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomProrrogas_Areas FOREIGN KEY (IdArea) REFERENCES [dbo].[Areas] (IdArea),
 CONSTRAINT FK_Trn_NomProrrogas_Cargos FOREIGN KEY (IdCargo) REFERENCES [dbo].[Cargos] (IdCargo),
 CONSTRAINT FK_Trn_NomProrrogas_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_NomProrrogas_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_NomProrrogas_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomProrrogas_TiposCon FOREIGN KEY (IdTipCon) REFERENCES [dbo].[TiposCon] (IdTipCon)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomProrrogasNContrato ON Trn_NomProrrogas(NContrato)
 CREATE NONCLUSTERED INDEX IX_Trn_NomProrrogasIdEmpleado ON Trn_NomProrrogas(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomProrrogasFecha ON Trn_NomProrrogas(Fecha)

GO
ALTER TABLE Trn_NomRet ADD 
 CONSTRAINT FK_Trn_NomRet_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomRet_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_NomRet_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_NomRet_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomRet_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_NomRet_NomCausalesRet FOREIGN KEY (IdCausa) REFERENCES [dbo].[NomCausalesRet] (IdCausa),
 CONSTRAINT FK_Trn_NomRet_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_NomRet_TiposNom FOREIGN KEY (IdNom) REFERENCES [dbo].[TiposNom] (IdNom)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdEmpleado ON Trn_NomRet(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetFecha ON Trn_NomRet(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdCausa ON Trn_NomRet(IdCausa)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetKeyReg ON Trn_NomRet(KeyReg,IdPeriodo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdDep ON Trn_NomRet(IdDep)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdCCosto ON Trn_NomRet(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdSubCos ON Trn_NomRet(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdNom ON Trn_NomRet(IdNom)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdEstado ON Trn_NomRet(IdEstado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetIdUsuario ON Trn_NomRet(IdUsuario)

GO
ALTER TABLE Trn_NomRetDet ADD 
 CONSTRAINT FK_Trn_NomRetDet_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomRetDet_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NomRetDet_Trn_NomRet FOREIGN KEY (IdEmpleado,Numero) REFERENCES [dbo].[Trn_NomRet] (IdEmpleado,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetDetIdEmpleado ON Trn_NomRetDet(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetDetIdConcepto ON Trn_NomRetDet(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetDetFecDesde ON Trn_NomRetDet(FecDesde)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetDetFecHasta ON Trn_NomRetDet(FecHasta)
 CREATE NONCLUSTERED INDEX IX_Trn_NomRetDetNumero ON Trn_NomRetDet(IdEmpleado,Numero)

GO
ALTER TABLE Trn_NomSueldos ADD 
 CONSTRAINT FK_Trn_NomSueldos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomSueldos_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomSueldosIdEmpleado ON Trn_NomSueldos(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomSueldosNContrato ON Trn_NomSueldos(NContrato)
 CREATE NONCLUSTERED INDEX IX_Trn_NomSueldosFecha ON Trn_NomSueldos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomSueldosIdUsuario ON Trn_NomSueldos(IdUsuario)

GO
ALTER TABLE Trn_NomVac ADD 
 CONSTRAINT FK_Trn_NomVac_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NomVac_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomVac_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacIdEmpleado ON Trn_NomVac(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacFecha ON Trn_NomVac(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacNContrato ON Trn_NomVac(NContrato)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacFecInicial ON Trn_NomVac(FecInicial)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacNNovedad ON Trn_NomVac(NNovedad)

GO
ALTER TABLE Trn_NomVacDet ADD 
 CONSTRAINT FK_Trn_NomVacDet_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado),
 CONSTRAINT FK_Trn_NomVacDet_NomConceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[NomConceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NomVacDet_Trn_NomVac FOREIGN KEY (IdEmpleado,Numero) REFERENCES [dbo].[Trn_NomVac] (IdEmpleado,Numero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacDetIdEmpleado ON Trn_NomVacDet(IdEmpleado)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacDetNumero ON Trn_NomVacDet(Numero)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacDetIdConcepto ON Trn_NomVacDet(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacDetNPrestamo ON Trn_NomVacDet(NPrestamo)
 CREATE NONCLUSTERED INDEX IX_Trn_NomVacDetIdPeriodo ON Trn_NomVacDet(IdPeriodo)

GO
ALTER TABLE Trn_NomVehiculo ADD 
 CONSTRAINT FK_Trn_NomVehiculo_Empleados FOREIGN KEY (IdEmpleado) REFERENCES [dbo].[Empleados] (IdEmpleado)
GO
ALTER TABLE Trn_NotaProd ADD 
 CONSTRAINT FK_Trn_NotaProd_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NotaProd_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_NotaProd_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NotaProd_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NotaProd_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NotaProd_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_NotaProd_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_NotaProd_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_NotaProd_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NotaProdFecha ON Trn_NotaProd(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NotaProdIdCia ON Trn_NotaProd(IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_NotaProdIdConcepto ON Trn_NotaProd(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NotaProdIdTercero ON Trn_NotaProd(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_NotaProdNumOrden ON Trn_NotaProd(NumOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_NotaProdComprobante ON Trn_NotaProd(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_Notas ADD 
 CONSTRAINT FK_Trn_Notas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Notas_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Notas_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Notas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Notas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Notas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Notas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Notas_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Notas_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_Notas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Notas_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Notas_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_NotasFecha ON Trn_Notas(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasIdConcepto ON Trn_Notas(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasIdCliente ON Trn_Notas(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasIdVend ON Trn_Notas(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasIdLocal ON Trn_Notas(IdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasDocumento ON Trn_Notas(TipDcm,Documento,IdCiaDcm)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasComprobante ON Trn_Notas(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_NotasBuses ADD 
 CONSTRAINT FK_Trn_NotasBuses_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_NotasBuses_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Trn_NotasBuses_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Trn_NotasBuses_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_NotasBuses_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_NotasBuses_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_NotasBuses_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_NotasBuses_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_NotasBuses_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_NotasBuses_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_NotasBusesFecha ON Trn_NotasBuses(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasBusesIdCliente ON Trn_NotasBuses(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasBusesIdVehiculo ON Trn_NotasBuses(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_NotasBusesComprobante ON Trn_NotasBuses(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_OComb ADD 
 CONSTRAINT FK_Trn_OComb_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OComb_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_OComb_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OComb_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OComb_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OComb_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OComb_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_OComb_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_OComb_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_OComb_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OComb_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OComb_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OComb_Terceros2 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OComb_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OCombFecha ON Trn_OComb(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombIdCliente ON Trn_OComb(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombIdAgencia ON Trn_OComb(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombIdVend ON Trn_OComb(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombIdLocal ON Trn_OComb(IdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombIdVehiculo ON Trn_OComb(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombIdConductor ON Trn_OComb(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombGuia ON Trn_OComb(TipGui,Guia,IdCiaGui)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombFactura ON Trn_OComb(TipFac,Factura,IdCiaFac)
 CREATE NONCLUSTERED INDEX IX_Trn_OCombPedido ON Trn_OComb(TipPed,Pedido,IdCiaPed)

GO
ALTER TABLE Trn_OCompra ADD 
 CONSTRAINT FK_Trn_OCompra_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OCompra_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_OCompra_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OCompra_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OCompra_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OCompra_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OCompra_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_OCompra_Localidades FOREIGN KEY (IdLocEtga) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_OCompra_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_OCompra_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OCompra_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OCompra_Terceros1 FOREIGN KEY (IdEmpresa) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_OCompraFecha ON Trn_OCompra(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraFechaVence ON Trn_OCompra(FechaVence)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraIdConcepto ON Trn_OCompra(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraIdProv ON Trn_OCompra(IdProv)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraIdEmpresa ON Trn_OCompra(IdEmpresa)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraIdLocEtga ON Trn_OCompra(IdLocEtga)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraIdForma ON Trn_OCompra(IdForma)
 CREATE NONCLUSTERED INDEX IX_Trn_OCompraEntrada ON Trn_OCompra(TipEnt,Entrada,IdCiaEnt)

GO
ALTER TABLE Trn_OilAcumCostos ADD 
 CONSTRAINT FK_Trn_OilAcumCostos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilAcumCostos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE CLUSTERED INDEX IX_Trn_OilAcumCostosIdProducto ON Trn_OilAcumCostos(IdCia,IdProducto,Periodo)

GO
ALTER TABLE Trn_OilAjustes ADD 
 CONSTRAINT FK_Trn_OilAjustes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilAjustes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilAjustes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilAjustes_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilAjustes_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilAjustes_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilAjustes_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilAjustesFecha ON Trn_OilAjustes(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilAjustesNumOrden ON Trn_OilAjustes(TipOrden,NumOrden,IdCiaOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_OilAjustesFecProceso ON Trn_OilAjustes(FecProceso)

GO
ALTER TABLE Trn_OilAjustesProd ADD 
 CONSTRAINT FK_Trn_OilAjustesProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilAjustesProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilAjustesProd_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque),
 CONSTRAINT FK_Trn_OilAjustesProd_Trn_OilAjustes FOREIGN KEY (TipDoc,NumProceso,IdCia) REFERENCES [dbo].[Trn_OilAjustes] (TipDoc,NumProceso,IdCia)
GO
ALTER TABLE Trn_OilCierres ADD 
 CONSTRAINT FK_Trn_OilCierres_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilCierres_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_OilCierresPeriodo ON Trn_OilCierres(nAnno,Periodo,IdCia)

GO
ALTER TABLE Trn_OilCompra ADD 
 CONSTRAINT FK_Trn_OilCompra_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilCompra_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilCompra_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilCompra_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilCompra_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilCompra_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilCompra_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilCompraFecha ON Trn_OilCompra(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilCompraIdProveedor ON Trn_OilCompra(IdProveedor)
 CREATE NONCLUSTERED INDEX IX_Trn_OilCompraNumFactura ON Trn_OilCompra(NumFactura)
 CREATE NONCLUSTERED INDEX IX_Trn_OilCompraFechaFac ON Trn_OilCompra(FechaFac)

GO
ALTER TABLE Trn_OilCompraDesp ADD 
 CONSTRAINT FK_Trn_OilCompraDesp_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilCompraDesp_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilCompraDesp_Trn_OilCompra FOREIGN KEY (TipDoc,NumCompra,IdCia) REFERENCES [dbo].[Trn_OilCompra] (TipDoc,NumCompra,IdCia)
GO
ALTER TABLE Trn_OilCompraProd ADD 
 CONSTRAINT FK_Trn_OilCompraProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilCompraProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilCompraProd_Trn_OilCompra FOREIGN KEY (TipDoc,NumCompra,IdCia) REFERENCES [dbo].[Trn_OilCompra] (TipDoc,NumCompra,IdCia)
GO
ALTER TABLE Trn_OilCostos ADD 
 CONSTRAINT FK_Trn_OilCostos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilCostos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilCostos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilCostos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilCostos_Sys_TiposDoc FOREIGN KEY (TipProc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostosFecha ON Trn_OilCostos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostosFechaInicio ON Trn_OilCostos(FechaInicio)
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostosNitProveedor ON Trn_OilCostos(NitProveedor)

GO
ALTER TABLE Trn_OilCostosProd ADD 
 CONSTRAINT FK_Trn_OilCostosProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilCostosProd_Trn_OilCostos FOREIGN KEY (TipProc,NumProceso,IdCia) REFERENCES [dbo].[Trn_OilCostos] (TipProc,NumProceso,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostosProdNumCompra ON Trn_OilCostosProd(TipCom,NumCompra,IdCiaCom)

GO
ALTER TABLE Trn_OilCostoVen ADD 
 CONSTRAINT FK_Trn_OilCostoVen_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilCostoVen_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilCostoVen_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilCostoVen_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilCostoVen_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilCostoVen_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostoVenFecha ON Trn_OilCostoVen(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostoVenFechaInicio ON Trn_OilCostoVen(FechaInicio,FechaFinal)

GO
ALTER TABLE Trn_OilCostoVenProd ADD 
 CONSTRAINT FK_Trn_OilCostoVenProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilCostoVenProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilCostoVenProd_Trn_OilCostoVen FOREIGN KEY (TipDoc,NumNota,IdCia) REFERENCES [dbo].[Trn_OilCostoVen] (TipDoc,NumNota,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilCostoVenProdIdProducto ON Trn_OilCostoVenProd(IdProducto)

GO
ALTER TABLE Trn_OilDespClie ADD 
 CONSTRAINT FK_Trn_OilDespClie_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilDespClie_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDespClie_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDespClie_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilDespClie_Localidades FOREIGN KEY (IdLocOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_OilDespClie_Localidades1 FOREIGN KEY (IdLocDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_OilDespClie_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilDespClie_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OilDespClie_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilDespClieFecha ON Trn_OilDespClie(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilDespClieFecDespacho ON Trn_OilDespClie(FecDespacho)
 CREATE NONCLUSTERED INDEX IX_Trn_OilDespClieIdCliente ON Trn_OilDespClie(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_OilDespClieIdConductor ON Trn_OilDespClie(IdConductor)

GO
ALTER TABLE Trn_OilDespClieProd ADD 
 CONSTRAINT FK_Trn_OilDespClieProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilDespClieProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilDespClieProd_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque),
 CONSTRAINT FK_Trn_OilDespClieProd_Trn_OilDespClie FOREIGN KEY (TipDoc,NumGuia,IdCia) REFERENCES [dbo].[Trn_OilDespClie] (TipDoc,NumGuia,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilDespClieProdIdProducto ON Trn_OilDespClieProd(IdProducto)

GO
ALTER TABLE Trn_OilDevCompra ADD 
 CONSTRAINT FK_Trn_OilDevCompra_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilDevCompra_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDevCompra_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDevCompra_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilDevCompra_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilDevCompra_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OilDevCompra_Trn_OilCompra FOREIGN KEY (TipDoc,NumCompra,IdCiaDoc) REFERENCES [dbo].[Trn_OilCompra] (TipDoc,NumCompra,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilDevCompraFecha ON Trn_OilDevCompra(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilDevCompraNumCompra ON Trn_OilDevCompra(TipDoc,NumCompra,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_OilDevCompraIdProveedor ON Trn_OilDevCompra(IdProveedor)

GO
ALTER TABLE Trn_OilDevComProd ADD 
 CONSTRAINT FK_Trn_OilDevComProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilDevComProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilDevComProd_Trn_OilDevCompra FOREIGN KEY (TipDev,Devolucion,IdCia) REFERENCES [dbo].[Trn_OilDevCompra] (TipDev,Devolucion,IdCia)
GO
ALTER TABLE Trn_OilDevCostos ADD 
 CONSTRAINT FK_Trn_OilDevCostos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilDevCostos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDevCostos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDevCostos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilDevCostos_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilDevCostos_Trn_OilCostos FOREIGN KEY (TipDoc,NumProceso,IdCiaDoc) REFERENCES [dbo].[Trn_OilCostos] (TipProc,NumProceso,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilDevCostosFecha ON Trn_OilDevCostos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilDevCostosNumProceso ON Trn_OilDevCostos(TipDoc,NumProceso,IdCiaDoc)

GO
ALTER TABLE Trn_OilDevCostosProd ADD 
 CONSTRAINT FK_Trn_OilDevCostosProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilDevCostosProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilDevCostosProd_Trn_OilDevCostos FOREIGN KEY (TipDev,Devolucion,IdCia) REFERENCES [dbo].[Trn_OilDevCostos] (TipDev,Devolucion,IdCia)
GO
ALTER TABLE Trn_OilDevFacProd ADD 
 CONSTRAINT FK_Trn_OilDevFacProd_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilDevFacProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilDevFacProd_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilDevFacProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed)
GO
ALTER TABLE Trn_OilEntrada ADD 
 CONSTRAINT FK_Trn_OilEntrada_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilEntrada_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilEntrada_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilEntrada_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilEntrada_Sys_TiposDoc FOREIGN KEY (TipEnt) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilEntrada_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OilEntrada_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilEntradaFecha ON Trn_OilEntrada(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilEntradaNumGuia ON Trn_OilEntrada(NumGuia,IdCiaGuia)
 CREATE NONCLUSTERED INDEX IX_Trn_OilEntradaFecDespacho ON Trn_OilEntrada(FecDespacho)
 CREATE NONCLUSTERED INDEX IX_Trn_OilEntradaIdProveedor ON Trn_OilEntrada(IdProveedor)
 CREATE NONCLUSTERED INDEX IX_Trn_OilEntradaIdVehiculo ON Trn_OilEntrada(IdVehiculo)

GO
ALTER TABLE Trn_OilEntradaProd ADD 
 CONSTRAINT FK_Trn_OilEntradaProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilEntradaProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilEntradaProd_Trn_OilEntrada FOREIGN KEY (TipEnt,NumEntrada,IdCia) REFERENCES [dbo].[Trn_OilEntrada] (TipEnt,NumEntrada,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilEntradaProdIdProducto ON Trn_OilEntradaProd(IdProducto)

GO
ALTER TABLE Trn_OilFacturaProd ADD 
 CONSTRAINT FK_Trn_OilFacturaProd_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilFacturaProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilFacturaProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilFacturaProdIdProducto ON Trn_OilFacturaProd(IdProducto)

GO
ALTER TABLE Trn_OilGuia ADD 
 CONSTRAINT FK_Trn_OilGuia_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilGuia_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilGuia_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilGuia_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilGuia_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilGuia_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilGuia_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OilGuia_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilGuiaFecDespacho ON Trn_OilGuia(FecDespacho)
 CREATE NONCLUSTERED INDEX IX_Trn_OilGuiaFecha ON Trn_OilGuia(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilGuiaIdProveedor ON Trn_OilGuia(IdProveedor)
 CREATE NONCLUSTERED INDEX IX_Trn_OilGuiaIdVehiculo ON Trn_OilGuia(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_OilGuiaIdConductor ON Trn_OilGuia(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_OilGuiaIdProducto ON Trn_OilGuia(IdProducto)

GO
ALTER TABLE Trn_OilInvent ADD 
 CONSTRAINT FK_Trn_OilInvent_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilInvent_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilInvent_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilInvent_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilInvent_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilInvent_Sys_TiposDoc FOREIGN KEY (TipEnt) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilInvent_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilInventFecha ON Trn_OilInvent(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilInventIdProveedor ON Trn_OilInvent(IdProveedor)

GO
ALTER TABLE Trn_OilInventDev ADD 
 CONSTRAINT FK_Trn_OilInventDev_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilInventDev_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilInventDev_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilInventDev_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilInventDev_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilInventDev_Terceros FOREIGN KEY (IdProveedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_OilInventDev_Trn_OilInvent FOREIGN KEY (TipEnt,NumEntrada,IdCiaDoc) REFERENCES [dbo].[Trn_OilInvent] (TipEnt,NumEntrada,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilInventDevFecha ON Trn_OilInventDev(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilInventDevNumEntrada ON Trn_OilInventDev(TipEnt,NumEntrada,IdCiaDoc)

GO
ALTER TABLE Trn_OilInventDevp ADD 
 CONSTRAINT FK_Trn_OilInventDevp_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilInventDevp_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilInventDevp_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque),
 CONSTRAINT FK_Trn_OilInventDevp_Trn_OilInventDev FOREIGN KEY (TipDev,Devolucion,IdCia) REFERENCES [dbo].[Trn_OilInventDev] (TipDev,Devolucion,IdCia)
GO
ALTER TABLE Trn_OilInventProd ADD 
 CONSTRAINT FK_Trn_OilInventProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilInventProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilInventProd_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque),
 CONSTRAINT FK_Trn_OilInventProd_Trn_OilInvent FOREIGN KEY (TipEnt,NumEntrada,IdCia) REFERENCES [dbo].[Trn_OilInvent] (TipEnt,NumEntrada,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilInventProdIdProducto ON Trn_OilInventProd(IdProducto)

GO
ALTER TABLE Trn_OilMediciones ADD 
 CONSTRAINT FK_Trn_OilMediciones_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilMediciones_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilMediciones_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilMediciones_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilMediciones_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilMediciones_Turnos FOREIGN KEY (IdTurno) REFERENCES [dbo].[Turnos] (IdTurno)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilMedicionesFecha ON Trn_OilMediciones(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilMedicionesFecProceso ON Trn_OilMediciones(FecProceso)

GO
ALTER TABLE Trn_OilMedicionesTq ADD 
 CONSTRAINT FK_Trn_OilMedicionesTq_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilMedicionesTq_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilMedicionesTq_Trn_OilMediciones FOREIGN KEY (TipDoc,NumInvent,IdCia) REFERENCES [dbo].[Trn_OilMediciones] (TipDoc,NumInvent,IdCia)
GO
ALTER TABLE Trn_OilNotas ADD 
 CONSTRAINT FK_Trn_OilNotas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilNotas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilNotas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilNotas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilNotas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilNotas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilNotas_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilNotasFecha ON Trn_OilNotas(Fecha)

GO
ALTER TABLE Trn_OilNotasProd ADD 
 CONSTRAINT FK_Trn_OilNotasProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilNotasProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilNotasProd_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque),
 CONSTRAINT FK_Trn_OilNotasProd_Trn_OilNotas FOREIGN KEY (TipDoc,NumNota,IdCia) REFERENCES [dbo].[Trn_OilNotas] (TipDoc,NumNota,IdCia)
GO
ALTER TABLE Trn_OilSaldos ADD 
 CONSTRAINT FK_Trn_OilSaldos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilSaldos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilSaldos_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilSaldos_Tanques FOREIGN KEY (IdTanque) REFERENCES [dbo].[Tanques] (IdTanque)
GO
ALTER TABLE Trn_OilTraslado ADD 
 CONSTRAINT FK_Trn_OilTraslado_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_OilTraslado_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilTraslado_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_OilTraslado_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_OilTraslado_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_OilTraslado_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_OilTraslado_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilTrasladoFecha ON Trn_OilTraslado(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_OilTrasladoFechaInicio ON Trn_OilTraslado(FechaInicio,FechaFinal)
 CREATE NONCLUSTERED INDEX IX_Trn_OilTrasladoIdTercero ON Trn_OilTraslado(IdTercero)

GO
ALTER TABLE Trn_OilTrasladoProd ADD 
 CONSTRAINT FK_Trn_OilTrasladoProd_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilTrasladoProd_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilTrasladoProd_Trn_OilTraslado FOREIGN KEY (TipDoc,NumNota,IdCia) REFERENCES [dbo].[Trn_OilTraslado] (TipDoc,NumNota,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_OilTrasladoProdIdProducto ON Trn_OilTrasladoProd(IdProducto)

GO
ALTER TABLE Trn_OilTrasladoRubros ADD 
 CONSTRAINT FK_Trn_OilTrasladoRubros_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_OilTrasladoRubros_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_Trn_OilTrasladoRubros_Trn_OilTraslado FOREIGN KEY (TipDoc,NumNota,IdCia) REFERENCES [dbo].[Trn_OilTraslado] (TipDoc,NumNota,IdCia)
GO
ALTER TABLE Trn_Opedido ADD 
 CONSTRAINT FK_Trn_Opedido_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Opedido_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Opedido_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Opedido_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Opedido_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Opedido_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Opedido_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_Opedido_Localidades FOREIGN KEY (IdLocEnv) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Opedido_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_Opedido_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Opedido_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Opedido_Terceros1 FOREIGN KEY (IdClieFact) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Opedido_Terceros2 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_OpedidoFecha ON Trn_Opedido(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoNumAprob ON Trn_Opedido(NumAprob,IdCiaApr)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoFechaVence ON Trn_Opedido(FechaVence)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoIdCliente ON Trn_Opedido(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoIdAgencia ON Trn_Opedido(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoIdVend ON Trn_Opedido(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoFactura ON Trn_Opedido(TipFac,Factura,IdCiaFac)
 CREATE NONCLUSTERED INDEX IX_Trn_OpedidoRemision ON Trn_Opedido(TipRem,Remision,IdCiaRem)

GO
ALTER TABLE Trn_Pagos ADD 
 CONSTRAINT FK_Trn_Pagos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Pagos_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Trn_Pagos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Pagos_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_Pagos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PagosFecha ON Trn_Pagos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_PagosIdForma ON Trn_Pagos(IdForma)
 CREATE NONCLUSTERED INDEX IX_Trn_PagosIdBanco ON Trn_Pagos(IdBanco)
 CREATE NONCLUSTERED INDEX IX_Trn_PagosNitCliente ON Trn_Pagos(NitCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_PagosCdLocal ON Trn_Pagos(CdLocal)
 CREATE NONCLUSTERED INDEX IX_Trn_PagosDocRef ON Trn_Pagos(TipRef,DocRef,IdCiaRef)

GO
ALTER TABLE Trn_PreCausacion ADD 
 CONSTRAINT FK_Trn_PreCausacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_PreCausacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_PreCausacion_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PreCausacionFecha ON Trn_PreCausacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_PreCausacionIdPropietario ON Trn_PreCausacion(IdPropietario)

GO
ALTER TABLE Trn_PreCuotas ADD 
 CONSTRAINT FK_Trn_PreCuotas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_PreCuotas_Trn_Prestamos FOREIGN KEY (TipDoc,PrestamoID,IdCia) REFERENCES [dbo].[Trn_Prestamos] (TipDoc,PrestamoID,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PreCuotasCausacionID ON Trn_PreCuotas(CausacionID,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_PreCuotasFecCausa ON Trn_PreCuotas(FecCausa)

GO
ALTER TABLE Trn_PresDetalle ADD 
 CONSTRAINT FK_Trn_PresDetalle_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_PresDetalle_Trn_Presupuesto FOREIGN KEY (Numero,IdCia) REFERENCES [dbo].[Trn_Presupuesto] (Numero,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PresDetalleIdCuenta ON Trn_PresDetalle(IdCuenta)

GO
ALTER TABLE Trn_Prestamos ADD 
 CONSTRAINT FK_Trn_Prestamos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Prestamos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Prestamos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Prestamos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Prestamos_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Prestamos_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Prestamos_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PrestamosFecha ON Trn_Prestamos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_PrestamosIdVehiculo ON Trn_Prestamos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_PrestamosIdPropietario ON Trn_Prestamos(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_PrestamosComprobante ON Trn_Prestamos(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_Presupuesto ADD 
 CONSTRAINT FK_Trn_Presupuesto_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Presupuesto_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Presupuesto_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PresupuestonAnno ON Trn_Presupuesto(nAnno,nMes)

GO
ALTER TABLE Trn_ProdConsDet ADD 
 CONSTRAINT FK_Trn_ProdConsDet_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsDet_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdConsDet_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdConsIns ADD 
 CONSTRAINT FK_Trn_ProdConsIns_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsIns_ProdMcias FOREIGN KEY (IdInsumo) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdConsIns_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc),
 CONSTRAINT FK_Trn_ProdConsIns_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdConsInsu ADD 
 CONSTRAINT FK_Trn_ProdConsInsu_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsInsu_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdConsInsu_ProdMcias1 FOREIGN KEY (IdInsumo) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdConsInsu_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc),
 CONSTRAINT FK_Trn_ProdConsInsu_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdConsolida ADD 
 CONSTRAINT FK_Trn_ProdConsolida_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_ProdConsolida_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsolida_Bodegas1 FOREIGN KEY (IdBodIns) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsolida_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdConsolida_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_ProdConsolida_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdConsolidaFecha ON Trn_ProdConsolida(Fecha)

GO
ALTER TABLE Trn_ProdConsPed ADD 
 CONSTRAINT FK_Trn_ProdConsPed_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdConsProc ADD 
 CONSTRAINT FK_Trn_ProdConsProc_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsProc_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdConsProc_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc),
 CONSTRAINT FK_Trn_ProdConsProc_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdConsTallas ADD 
 CONSTRAINT FK_Trn_ProdConsTallas_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdConsTdo ADD 
 CONSTRAINT FK_Trn_ProdConsTdo_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_ProdConsTdo_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdConsTdo_Trn_ProdConsolida FOREIGN KEY (TipDoc,NumCons,IdCia) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia)
GO
ALTER TABLE Trn_ProdEntrega ADD 
 CONSTRAINT FK_Trn_ProdEntrega_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_ProdEntrega_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdEntrega_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdEntrega_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_ProdEntrega_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_ProdEntrega_Trn_ProdOrden FOREIGN KEY (TipOrden,NumOrden,IdCiaOrden) REFERENCES [dbo].[Trn_ProdOrden] (TipDoc,NumOrden,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdEntregaNumOrden ON Trn_ProdEntrega(TipOrden,NumOrden,IdCiaOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdEntregaFecha ON Trn_ProdEntrega(Fecha)

GO
ALTER TABLE Trn_ProdEntregaDei ADD 
 CONSTRAINT FK_Trn_ProdEntregaDei_Trn_ProdEntregaDev FOREIGN KEY (TipDev,Devolucion,IdCia) REFERENCES [dbo].[Trn_ProdEntregaDev] (TipDev,Devolucion,IdCia)
GO
ALTER TABLE Trn_ProdEntregaDet ADD 
 CONSTRAINT FK_Trn_ProdEntregaDet_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdEntregaDet_Trn_ProdEntrega FOREIGN KEY (TipDoc,NumEntrega,IdCia) REFERENCES [dbo].[Trn_ProdEntrega] (TipDoc,NumEntrega,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdEntregaDetNumOrden ON Trn_ProdEntregaDet(TipOrden,NumOrden,IdCiaOrden,ItemOrden)

GO
ALTER TABLE Trn_ProdEntregaDev ADD 
 CONSTRAINT FK_Trn_ProdEntregaDev_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_ProdEntregaDev_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdEntregaDev_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdEntregaDev_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_ProdEntregaDev_Trn_ProdEntrega FOREIGN KEY (TipDocEnt,NumEntrega,IdCiaEnt) REFERENCES [dbo].[Trn_ProdEntrega] (TipDoc,NumEntrega,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdEntregaDevFecha ON Trn_ProdEntregaDev(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdEntregaDevNumEntrega ON Trn_ProdEntregaDev(TipDocEnt,NumEntrega,IdCiaEnt)

GO
ALTER TABLE Trn_ProdEntregaDtl ADD 
 CONSTRAINT FK_Trn_ProdEntregaDtl_Trn_ProdEntregaDev FOREIGN KEY (TipDev,Devolucion,IdCia) REFERENCES [dbo].[Trn_ProdEntregaDev] (TipDev,Devolucion,IdCia)
GO
ALTER TABLE Trn_ProdEntregaInsu ADD 
 CONSTRAINT FK_Trn_ProdEntregaInsu_ProdMcias FOREIGN KEY (IdInsumo) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
ALTER TABLE Trn_ProdEntregaTallas ADD 
 CONSTRAINT FK_Trn_ProdEntregaTallas_Trn_ProdEntrega FOREIGN KEY (TipDoc,NumEntrega,IdCia) REFERENCES [dbo].[Trn_ProdEntrega] (TipDoc,NumEntrega,IdCia)
GO
ALTER TABLE Trn_ProdOrden ADD 
 CONSTRAINT FK_Trn_ProdOrden_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_ProdOrden_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdOrden_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdOrden_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_ProdOrden_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_ProdOrden_Talleres FOREIGN KEY (IdTaller) REFERENCES [dbo].[Talleres] (IdTaller),
 CONSTRAINT FK_Trn_ProdOrden_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdOrdenFecha ON Trn_ProdOrden(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdOrdenNumCons ON Trn_ProdOrden(TipCons,NumCons,IdCiaCons)

GO
ALTER TABLE Trn_ProdOrdenDet ADD 
 CONSTRAINT FK_Trn_ProdOrdenDet_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdOrdenDet_Trn_ProdConsolida FOREIGN KEY (TipCons,NumCons,IdCiaCons) REFERENCES [dbo].[Trn_ProdConsolida] (TipDoc,NumCons,IdCia),
 CONSTRAINT FK_Trn_ProdOrdenDet_Trn_ProdOrden FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_ProdOrden] (TipDoc,NumOrden,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdOrdenDetNumCons ON Trn_ProdOrdenDet(TipCons,NumCons,IdCiaCons,ItemCons)

GO
ALTER TABLE Trn_ProdOrdenSal ADD 
 CONSTRAINT FK_Trn_ProdOrdenSal_Trn_ProdOrden FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_ProdOrden] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_ProdOrdenTallas ADD 
 CONSTRAINT FK_Trn_ProdOrdenTallas_Trn_ProdOrden FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_ProdOrden] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_ProdPedidoInsu ADD 
 CONSTRAINT FK_Trn_ProdPedidoInsu_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_ProdPedidoInsu_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdPedidoInsu_ProdMcias1 FOREIGN KEY (IdInsumo) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_ProdPedidoInsu_TiposProceso FOREIGN KEY (IdTipProc) REFERENCES [dbo].[TiposProceso] (IdTipProc)
GO
ALTER TABLE Trn_ProdTarf ADD 
 CONSTRAINT FK_Trn_ProdTarf_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ProdTarfFecInicial ON Trn_ProdTarf(FecInicial)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdTarfFecFinal ON Trn_ProdTarf(FecFinal)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdTarfCdProducto ON Trn_ProdTarf(CdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdTarfCdClie ON Trn_ProdTarf(CdClie)
 CREATE NONCLUSTERED INDEX IX_Trn_ProdTarfCdVend ON Trn_ProdTarf(CdVend)

GO
ALTER TABLE Trn_Puntos ADD 
 CONSTRAINT FK_Trn_Puntos_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Puntos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Puntos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_PuntosFecha ON Trn_Puntos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_PuntosIdCliente ON Trn_Puntos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_PuntosIdAgencia ON Trn_Puntos(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_PuntosIdProgrma ON Trn_Puntos(IdProgrma)
 CREATE NONCLUSTERED INDEX IX_Trn_PuntosNumTarjeta ON Trn_Puntos(NumTarjeta)

GO
ALTER TABLE Trn_RadicaVales ADD 
 CONSTRAINT FK_Trn_RadicaVales_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_RadicaVales_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RadicaVales_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_RadicaVales_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_RadicaVales_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_RadicaVales_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RadicaValesFecha ON Trn_RadicaVales(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RadicaValesIdTercero ON Trn_RadicaVales(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_RadicaValesComprobante ON Trn_RadicaVales(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_RecAfavor ADD 
 CONSTRAINT FK_Trn_RecAfavor_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_RecAfavor_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RecAfavor_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_RecAfavor_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecAfavor_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RecAfavorFecha ON Trn_RecAfavor(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RecAfavorIdCliente ON Trn_RecAfavor(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RecAfavorIdVend ON Trn_RecAfavor(IdVend)

GO
ALTER TABLE Trn_RecBuses ADD 
 CONSTRAINT FK_Trn_RecBuses_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_RecBuses_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Trn_RecBuses_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Trn_RecBuses_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_RecBuses_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RecBuses_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_RecBuses_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_RecBuses_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_RecBuses_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecBuses_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecBuses_Terceros2 FOREIGN KEY (IdVendedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecBuses_Terceros3 FOREIGN KEY (IdRelevador) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecBuses_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RecBusesFecha ON Trn_RecBuses(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RecBusesIdCliente ON Trn_RecBuses(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RecBusesCartulina ON Trn_RecBuses(TipCar,Cartulina,IdCiaCar)
 CREATE NONCLUSTERED INDEX IX_Trn_RecBusesIdVehiculo ON Trn_RecBuses(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_RecBusesIdConductor ON Trn_RecBuses(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_RecBusesComprobante ON Trn_RecBuses(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_RecCheques ADD 
 CONSTRAINT FK_Trn_RecCheques_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_RecCheques_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_RecCheques_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RecCheques_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RecCheques_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_RecCheques_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_RecCheques_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RecChequesFecha ON Trn_RecCheques(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RecChequesIdCliente ON Trn_RecCheques(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RecChequesComprobante ON Trn_RecCheques(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_RecFactura ADD 
 CONSTRAINT FK_Trn_RecFactura_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_RecFactura_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Trn_RecFactura_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RecFactura_Companias1 FOREIGN KEY (IdCiaDoc) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_RecFactura_Sys_TiposDoc FOREIGN KEY (TipRec) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_RecFactura_Sys_TiposDoc1 FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_RecFactura_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecFactura_Terceros1 FOREIGN KEY (IdVendedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_RecFactura_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RecFacturaDocumento ON Trn_RecFactura(TipDoc,Documento,IdCiaDoc,ItemDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_RecFacturaFecha ON Trn_RecFactura(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RecFacturaIdCliente ON Trn_RecFactura(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RecFacturaIdVehiculo ON Trn_RecFactura(IdVehiculo)

GO
ALTER TABLE Trn_Recibos ADD 
 CONSTRAINT FK_Trn_Recibos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Recibos_adm_Usuarios1 FOREIGN KEY (IdCajero) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Recibos_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Recibos_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Recibos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Recibos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Recibos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Recibos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Recibos_Localidades FOREIGN KEY (IdLocal) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Recibos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Recibos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Recibos_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_RecibosFecha ON Trn_Recibos(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosIdConcepto ON Trn_Recibos(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosIdCliente ON Trn_Recibos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosFecPago ON Trn_Recibos(FecPago)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosIdVend ON Trn_Recibos(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosDocumento ON Trn_Recibos(TipDcm,Documento,IdCiaDcm)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosComprobante ON Trn_Recibos(TipCom,Comprobante,IdCiaCom)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosIdCCosto ON Trn_Recibos(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_RecibosIdCajero ON Trn_Recibos(IdCajero)

GO
ALTER TABLE Trn_RecTanqueos ADD 
 CONSTRAINT FK_Trn_RecTanqueos_EdsServicio FOREIGN KEY (IdEstacion) REFERENCES [dbo].[EdsServicio] (IdEstacion),
 CONSTRAINT FK_Trn_RecTanqueos_TiposFuel FOREIGN KEY (IdTipoCom) REFERENCES [dbo].[TiposFuel] (IdCom),
 CONSTRAINT FK_Trn_RecTanqueos_Trn_RecBuses FOREIGN KEY (TipDoc,Recibo,IdCia) REFERENCES [dbo].[Trn_RecBuses] (TipDoc,Recibo,IdCia)
GO
ALTER TABLE Trn_Remision ADD 
 CONSTRAINT FK_Trn_Remision_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Remision_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Remision_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Remision_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Remision_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Remision_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Remision_Formaspago FOREIGN KEY (IdForma) REFERENCES [dbo].[Formaspago] (IdForma),
 CONSTRAINT FK_Trn_Remision_Localidades FOREIGN KEY (IdLocEnv) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_Remision_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_Remision_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Remision_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Remision_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionFecha ON Trn_Remision(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionFechaVence ON Trn_Remision(FechaVence)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionIdConcepto ON Trn_Remision(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionIdCliente ON Trn_Remision(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionIdAgencia ON Trn_Remision(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionIdVend ON Trn_Remision(IdVend)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionIdLocEnv ON Trn_Remision(IdLocEnv)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionNitEmpTrans ON Trn_Remision(NitEmpTrans)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionFactura ON Trn_Remision(TipFac,Factura,IdCiaFac)
 CREATE NONCLUSTERED INDEX IX_Trn_RemisionPedido ON Trn_Remision(TipPed,Pedido,IdCiaPed)

GO
ALTER TABLE Trn_ReqDetalle ADD 
 CONSTRAINT FK_Trn_ReqDetalle_SubGrupos FOREIGN KEY (IdSubgrupo) REFERENCES [dbo].[SubGrupos] (IdSubgrupo),
 CONSTRAINT FK_Trn_ReqDetalle_Trn_Requisicion FOREIGN KEY (TipDoc,Requisicion,IdCia) REFERENCES [dbo].[Trn_Requisicion] (TipDoc,Requisicion,IdCia),
 CONSTRAINT FK_Trn_ReqDetalle_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ReqDetalleCdProducto ON Trn_ReqDetalle(CdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_ReqDetalleIdSubgrupo ON Trn_ReqDetalle(IdSubgrupo)
 CREATE NONCLUSTERED INDEX IX_Trn_ReqDetalleNumOrden ON Trn_ReqDetalle(TipOrd,NumOrden,IdCiaOrd)
 CREATE NONCLUSTERED INDEX IX_Trn_ReqDetalleNSalida ON Trn_ReqDetalle(TipSal,NSalida,IdCiaSal)

GO
ALTER TABLE Trn_Requisicion ADD 
 CONSTRAINT FK_Trn_Requisicion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Requisicion_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Requisicion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Requisicion_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Requisicion_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Requisicion_Dependencias FOREIGN KEY (IdDep) REFERENCES [dbo].[Dependencias] (IdDep),
 CONSTRAINT FK_Trn_Requisicion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Requisicion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Requisicion_Terceros FOREIGN KEY (IdRespons) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_RequisicionFecha ON Trn_Requisicion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_RequisicionIdConcepto ON Trn_Requisicion(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_RequisicionIdRespons ON Trn_Requisicion(IdRespons)
 CREATE NONCLUSTERED INDEX IX_Trn_RequisicionNitCliente ON Trn_Requisicion(NitCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_RequisicionNumSalida ON Trn_Requisicion(TipSal,NumSalida,IdCiaSal)

GO
ALTER TABLE Trn_SaiArticulos ADD 
 CONSTRAINT FK_Trn_SaiArticulos_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_SaiArticulos_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_SaiArticulos_Trn_Salidas FOREIGN KEY (TipDoc,Salida,IdCia) REFERENCES [dbo].[Trn_Salidas] (TipDoc,Salida,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_SaiArticulosEntrada ON Trn_SaiArticulos(TipEnt,Entrada,IdCiaEnt)
 CREATE NONCLUSTERED INDEX IX_Trn_SaiArticulosIdProducto ON Trn_SaiArticulos(IdProducto)

GO
ALTER TABLE Trn_Salidas ADD 
 CONSTRAINT FK_Trn_Salidas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Salidas_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Salidas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Salidas_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Salidas_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Salidas_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Salidas_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_Salidas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Salidas_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_SalidasFecha ON Trn_Salidas(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasIdTercero ON Trn_Salidas(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasIdConcepto ON Trn_Salidas(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasNumOrden ON Trn_Salidas(TipOrd,NumOrden,IdCiaOrd)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasIdCCosto ON Trn_Salidas(IdCCosto)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasIdSubCos ON Trn_Salidas(IdSubCos)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasComprobante ON Trn_Salidas(TipCom,Comprobante,IdCiaCom)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasNContrato ON Trn_Salidas(NContrato)
 CREATE NONCLUSTERED INDEX IX_Trn_SalidasNitCliente ON Trn_Salidas(NitCliente)

GO
ALTER TABLE Trn_Seriales ADD 
 CONSTRAINT FK_Trn_Seriales_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Seriales_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_Seriales_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Seriales_EstadoSer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoSer] (IdEstado),
 CONSTRAINT FK_Trn_Seriales_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_SerialesIdBodega ON Trn_Seriales(IdBodega)
 CREATE NONCLUSTERED INDEX IX_Trn_SerialesFecEntrada ON Trn_Seriales(FecEntrada)
 CREATE NONCLUSTERED INDEX IX_Trn_SerialesFecSalida ON Trn_Seriales(FecSalida)
 CREATE NONCLUSTERED INDEX IX_Trn_SerialesIdEstado ON Trn_Seriales(IdEstado)
 CREATE NONCLUSTERED INDEX IX_Trn_SerialesIdUsuario ON Trn_Seriales(IdUsuario)

GO
ALTER TABLE Trn_SerMov ADD 
 CONSTRAINT FK_Trn_SerMov_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_SerMov_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_SerMov_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_SerMov_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE CLUSTERED INDEX IX_Trn_SerMovFecha ON Trn_SerMov(Fecha,IdProducto,NumSerial)
 CREATE NONCLUSTERED INDEX IX_Trn_SerMovIdProducto ON Trn_SerMov(IdProducto)
 CREATE NONCLUSTERED INDEX IX_Trn_SerMovNumSerial ON Trn_SerMov(NumSerial)
 CREATE NONCLUSTERED INDEX IX_Trn_SerMovIdBodega ON Trn_SerMov(IdBodega)

GO
ALTER TABLE Trn_SobDetalle ADD 
 CONSTRAINT FK_Trn_SobDetalle_Trn_Sobretasas FOREIGN KEY (IdDec,NumDeclara) REFERENCES [dbo].[Trn_Sobretasas] (IdDec,NumDeclara)
GO
ALTER TABLE Trn_Sobretasas ADD 
 CONSTRAINT FK_Trn_Sobretasas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Sobretasas_Bancos FOREIGN KEY (IdBanco) REFERENCES [dbo].[Bancos] (IdBanco),
 CONSTRAINT FK_Trn_Sobretasas_ClaseCta FOREIGN KEY (IdClase) REFERENCES [dbo].[ClaseCta] (IdClase),
 CONSTRAINT FK_Trn_Sobretasas_SobEntidades FOREIGN KEY (IdEnterr) REFERENCES [dbo].[SobEntidades] (IdEnterr),
 CONSTRAINT FK_Trn_Sobretasas_SobTiposDec FOREIGN KEY (IdDec) REFERENCES [dbo].[SobTiposDec] (IdDec)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_SobretasasnAnno ON Trn_Sobretasas(nAnno,nMes)
 CREATE NONCLUSTERED INDEX IX_Trn_SobretasasFecha ON Trn_Sobretasas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_SobretasasIdEnterr ON Trn_Sobretasas(IdEnterr,TipoEntidad,nAnno,nMes)
 CREATE NONCLUSTERED INDEX IX_Trn_SobretasasNitDeclara ON Trn_Sobretasas(NitDeclara)

GO
ALTER TABLE Trn_Tallajes ADD 
 CONSTRAINT FK_Trn_Tallajes_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_Tallajes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Tallajes_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto)
GO
 CREATE CLUSTERED INDEX IX_Trn_TallajesNumTalla ON Trn_Tallajes(IdProducto,IdCia,IdBodega,NumTalla)

GO
ALTER TABLE Trn_TallasMov ADD 
 CONSTRAINT FK_Trn_TallasMov_Bodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[Bodegas] (IdBodega),
 CONSTRAINT FK_Trn_TallasMov_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TallasMov_ProdMcias FOREIGN KEY (IdProducto) REFERENCES [dbo].[ProdMcias] (IdProducto),
 CONSTRAINT FK_Trn_TallasMov_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TallasMovNumTalla ON Trn_TallasMov(IdProducto,IdBodega,NumTalla)
 CREATE NONCLUSTERED INDEX IX_Trn_TallasMovFecha ON Trn_TallasMov(Fecha)

GO
ALTER TABLE Trn_tasas ADD 
 CONSTRAINT FK_Trn_tasas_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_tasas_adm_monedas1 FOREIGN KEY (IdMnedaD) REFERENCES [dbo].[adm_monedas] (IdMneda)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_tasasIdMneda ON Trn_tasas(IdMneda)
 CREATE NONCLUSTERED INDEX IX_Trn_tasasIdMnedaD ON Trn_tasas(IdMnedaD)
 CREATE NONCLUSTERED INDEX IX_Trn_tasasFecha ON Trn_tasas(Fecha)

GO
ALTER TABLE Trn_TasasDia ADD 
 CONSTRAINT FK_Trn_TasasDia_TiposTasas FOREIGN KEY (IdTasa) REFERENCES [dbo].[TiposTasas] (IdTasa)
GO
 CREATE CLUSTERED INDEX IX_Trn_TasasDiaFecha ON Trn_TasasDia(IdTasa,Fecha)

GO
ALTER TABLE Trn_TraAntAbonos ADD 
 CONSTRAINT FK_Trn_TraAntAbonos_Trn_TraAnticipos FOREIGN KEY (TipAnt,Anticipo,IdCiaAnt) REFERENCES [dbo].[Trn_TraAnticipos] (TipDoc,Anticipo,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraAntAbonosFecha ON Trn_TraAntAbonos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraAntAbonosAnticipo ON Trn_TraAntAbonos(TipAnt,Anticipo,IdCiaAnt)

GO
ALTER TABLE Trn_TraAnticipos ADD 
 CONSTRAINT FK_Trn_TraAnticipos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraAnticipos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraAnticipos_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraAnticipos_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraAnticipos_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraAnticipos_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_TraAnticipos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraAnticipos_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraAnticipos_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraAnticipos_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraAnticiposFecha ON Trn_TraAnticipos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraAnticiposManifiesto ON Trn_TraAnticipos(TipMuc,Manifiesto,IdCiaMuc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraAnticiposIdVehiculo ON Trn_TraAnticipos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraAnticiposIdPoseedor ON Trn_TraAnticipos(IdPoseedor)

GO
ALTER TABLE Trn_TraCauDetalle ADD 
 CONSTRAINT FK_Trn_TraCauDetalle_TraConcCausac FOREIGN KEY (IdConcepto) REFERENCES [dbo].[TraConcCausac] (IdConcepto),
 CONSTRAINT FK_Trn_TraCauDetalle_Trn_TraCausacion FOREIGN KEY (TipDoc,Causacion,IdCia) REFERENCES [dbo].[Trn_TraCausacion] (TipDoc,Causacion,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraCauDetalleIdConcepto ON Trn_TraCauDetalle(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCauDetalleCdCuenta ON Trn_TraCauDetalle(CdCuenta)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCauDetalleNitTercero ON Trn_TraCauDetalle(NitTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCauDetalleFecVence ON Trn_TraCauDetalle(FecVence)

GO
ALTER TABLE Trn_TraCausacion ADD 
 CONSTRAINT FK_Trn_TraCausacion_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraCausacion_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraCausacion_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraCausacion_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraCausacion_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraCausacion_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraCausacion_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraCausacionFecha ON Trn_TraCausacion(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCausacionIdProv ON Trn_TraCausacion(IdProv,Factura)

GO
ALTER TABLE Trn_TraConceptos ADD 
 CONSTRAINT FK_Trn_TraConceptos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraConceptos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraConceptosIdConcepto ON Trn_TraConceptos(IdConcepto)

GO
ALTER TABLE Trn_TraCumplido ADD 
 CONSTRAINT FK_Trn_TraCumplido_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraCumplido_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraCumplido_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraCumplido_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraCumplido_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraCumplido_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumplidoFecha ON Trn_TraCumplido(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumplidoManifiesto ON Trn_TraCumplido(TipMuc,Manifiesto,IdCiaMuc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumplidoIdVehiculo ON Trn_TraCumplido(IdVehiculo)

GO
ALTER TABLE Trn_TraCumRadDoc ADD 
 CONSTRAINT FK_Trn_TraCumRadDoc_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraCumRadDoc_Trn_TraCumRadica FOREIGN KEY (NumRadica,IdCia) REFERENCES [dbo].[Trn_TraCumRadica] (NumRadica,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumRadDocNitCliente ON Trn_TraCumRadDoc(NitCliente,ItemDoc)

GO
ALTER TABLE Trn_TraCumRadica ADD 
 CONSTRAINT FK_Trn_TraCumRadica_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraCumRadica_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumRadicaFecha ON Trn_TraCumRadica(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumRadicaManifiesto ON Trn_TraCumRadica(TipMuc,Manifiesto,IdCiaMuc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumRadicaNumeroCum ON Trn_TraCumRadica(NumeroCum,IdCiaCum)

GO
ALTER TABLE Trn_TraCumRemesas ADD 
 CONSTRAINT FK_Trn_TraCumRemesas_Trn_TraCumplido FOREIGN KEY (TipDoc,Cumplido,IdCia) REFERENCES [dbo].[Trn_TraCumplido] (TipDoc,Cumplido,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraCumRemesasRemesa ON Trn_TraCumRemesas(TipRem,Remesa,IdCiaRem,ItemRem)

GO
ALTER TABLE Trn_TraDecAduana ADD 
 CONSTRAINT FK_Trn_TraDecAduana_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraDecAduana_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDecAduana_Aduanas FOREIGN KEY (IdAduOrigen) REFERENCES [dbo].[Aduanas] (IdAduana),
 CONSTRAINT FK_Trn_TraDecAduana_Aduanas1 FOREIGN KEY (IdAduDestino) REFERENCES [dbo].[Aduanas] (IdAduana),
 CONSTRAINT FK_Trn_TraDecAduana_Aduanas2 FOREIGN KEY (IdAduCarga) REFERENCES [dbo].[Aduanas] (IdAduana),
 CONSTRAINT FK_Trn_TraDecAduana_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDecAduana_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDecAduana_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDecAduana_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraDecAduana_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraDecAduana_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecAduanaFecha ON Trn_TraDecAduana(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecAduanaFecEmision ON Trn_TraDecAduana(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecAduanaIdDestino ON Trn_TraDecAduana(IdOrigen,IdDestino)

GO
ALTER TABLE Trn_TraDecMcia ADD 
 CONSTRAINT FK_Trn_TraDecMcia_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraDecMcia_Trn_TraDecAduana FOREIGN KEY (TipDoc,NumDeclara,IdCia) REFERENCES [dbo].[Trn_TraDecAduana] (TipDoc,NumDeclara,IdCia),
 CONSTRAINT FK_Trn_TraDecMcia_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDecMciaNumOrden ON Trn_TraDecMcia(TipOrd,NumOrden,IdCiaOrd)

GO
ALTER TABLE Trn_TraDespachos ADD 
 CONSTRAINT FK_Trn_TraDespachos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDespachos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDespachos_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraDespachos_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraDespachos_Rutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[Rutas] (IdRuta),
 CONSTRAINT FK_Trn_TraDespachos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDespachos_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDespachos_Terceros1 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDespachosFecha ON Trn_TraDespachos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDespachosIdVehiculo ON Trn_TraDespachos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDespachosIdRuta ON Trn_TraDespachos(IdRuta)

GO
ALTER TABLE Trn_TraDespProgram ADD 
 CONSTRAINT FK_Trn_TraDespProgram_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDespProgram_Trn_TraDespachos FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraDespachos] (TipDoc,Manifiesto,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDespProgramCdRuta ON Trn_TraDespProgram(CdRuta,IdPunto)

GO
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)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevAosFecha ON Trn_TraDevAos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevAosAnticipo ON Trn_TraDevAos(TipDoc,Anticipo,IdCiaDoc)

GO
ALTER TABLE Trn_TraDevCau ADD 
 CONSTRAINT FK_Trn_TraDevCau_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevCau_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevCau_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevCau_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevCau_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevCau_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevCau_Terceros FOREIGN KEY (IdProv) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevCau_Trn_TraCausacion FOREIGN KEY (TipDoc,Causacion,IdCiaDoc) REFERENCES [dbo].[Trn_TraCausacion] (TipDoc,Causacion,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCauFecha ON Trn_TraDevCau(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCauCausacion ON Trn_TraDevCau(TipDoc,Causacion,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCauIdProv ON Trn_TraDevCau(IdProv)

GO
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)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCosFecha ON Trn_TraDevCos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevCosCumplido ON Trn_TraDevCos(TipDoc,Cumplido,IdCiaDoc)

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)
GO
ALTER TABLE Trn_TraDevLeg ADD 
 CONSTRAINT FK_Trn_TraDevLeg_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevLeg_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevLeg_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevLeg_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevLeg_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevLeg_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevLeg_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevLeg_Terceros1 FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevLeg_Terceros2 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevLeg_Trn_TraLiqViajes FOREIGN KEY (TipDoc,Liquidacion,IdCiaDoc) REFERENCES [dbo].[Trn_TraLiqViajes] (TipDoc,Liquidacion,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLegFecha ON Trn_TraDevLeg(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLegLiquidacion ON Trn_TraDevLeg(TipDoc,Liquidacion,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLegIdVehiculo ON Trn_TraDevLeg(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLegIdPoseedor ON Trn_TraDevLeg(IdPoseedor)

GO
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)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLgoFecha ON Trn_TraDevLgo(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLgoLiquidacion ON Trn_TraDevLgo(TipDoc,Liquidacion,IdCiaDoc)

GO
ALTER TABLE Trn_TraDevLiq ADD 
 CONSTRAINT FK_Trn_TraDevLiq_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevLiq_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevLiq_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevLiq_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevLiq_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevLiq_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevLiq_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevLiq_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevLiq_Trn_TraLiquida FOREIGN KEY (TipDoc,Liquidacion,IdCiaDoc) REFERENCES [dbo].[Trn_TraLiquida] (TipDoc,Liquidacion,IdCia),
 CONSTRAINT FK_Trn_TraDevLiq_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLiqFecha ON Trn_TraDevLiq(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLiqLiquidacion ON Trn_TraDevLiq(TipDoc,Liquidacion,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLiqIdPoseedor ON Trn_TraDevLiq(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevLiqIdVehiculo ON Trn_TraDevLiq(IdVehiculo)

GO
ALTER TABLE Trn_TraDevOdp ADD 
 CONSTRAINT FK_Trn_TraDevOdp_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraDevOdp_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevOdp_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraDevOdp_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraDevOdp_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraDevOdp_Sys_TiposDoc FOREIGN KEY (TipDev) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraDevOdp_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevOdp_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraDevOdp_Trn_TraOrdenPago FOREIGN KEY (TipDoc,OrdPago,IdCiaDoc) REFERENCES [dbo].[Trn_TraOrdenPago] (TipDoc,OrdPago,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevOdpFecha ON Trn_TraDevOdp(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevOdpOrdPago ON Trn_TraDevOdp(TipDoc,OrdPago,IdCiaDoc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevOdpIdPoseedor ON Trn_TraDevOdp(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraDevOdpIdVehiculo ON Trn_TraDevOdp(IdVehiculo)

GO
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)
GO
 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)

GO
ALTER TABLE Trn_TraFacRemesas ADD 
 CONSTRAINT FK_Trn_TraFacRemesas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraFacRemesas_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraFacRemesas_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraFacRemesas_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraFacRemesasRemesa ON Trn_TraFacRemesas(TipRem,Remesa,IdCiaRem,ItemRem)
 CREATE NONCLUSTERED INDEX IX_Trn_TraFacRemesasIdOrigen ON Trn_TraFacRemesas(IdOrigen,IdDestino)
 CREATE NONCLUSTERED INDEX IX_Trn_TraFacRemesasCdMercancia ON Trn_TraFacRemesas(CdMercancia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraFacRemesasFechaFact ON Trn_TraFacRemesas(FechaFact)
 CREATE NONCLUSTERED INDEX IX_Trn_TraFacRemesasFecRemesa ON Trn_TraFacRemesas(FecRemesa)

GO
ALTER TABLE Trn_TraInfViajes ADD 
 CONSTRAINT FK_Trn_TraInfViajes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraInfViajes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraInfViajes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraInfViajes_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraInfViajes_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraInfViajes_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraInfViajes_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraInfViajes_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraInfViajes_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraInfViajes_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraInfViajesFecha ON Trn_TraInfViajes(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraInfViajesIdVehiculo ON Trn_TraInfViajes(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraInfViajesIdPoseedor ON Trn_TraInfViajes(IdPoseedor)

GO
ALTER TABLE Trn_TraInfViajesOrd ADD 
 CONSTRAINT FK_Trn_TraInfViajesOrd_Sys_TiposDoc FOREIGN KEY (TipOrden) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraInfViajesOrd_Trn_TraInfViajes FOREIGN KEY (TipDoc,NumViaje,IdCia) REFERENCES [dbo].[Trn_TraInfViajes] (TipDoc,NumViaje,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraInfViajesOrdNumOrden ON Trn_TraInfViajesOrd(TipOrden,NumOrden,IdCiaOrd)

GO
ALTER TABLE Trn_TraLiqDetalle ADD 
 CONSTRAINT FK_Trn_TraLiqDetalle_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_TraLiqDetalle_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_TraLiqDetalle_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE Trn_TraLiqManif ADD 
 CONSTRAINT FK_Trn_TraLiqManif_Trn_TraLiqViajes FOREIGN KEY (TipDoc,Liquidacion,IdCia) REFERENCES [dbo].[Trn_TraLiqViajes] (TipDoc,Liquidacion,IdCia)
GO
ALTER TABLE Trn_TraLiquida ADD 
 CONSTRAINT FK_Trn_TraLiquida_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraLiquida_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraLiquida_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraLiquida_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraLiquida_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraLiquida_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraLiquida_Terceros FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraLiquida_Terceros1 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraLiquida_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiquidaFecha ON Trn_TraLiquida(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiquidaIdVehiculo ON Trn_TraLiquida(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiquidaIdPoseedor ON Trn_TraLiquida(IdPoseedor)

GO
ALTER TABLE Trn_TraLiquidaDed ADD 
 CONSTRAINT FK_Trn_TraLiquidaDed_Trn_TraLiquida FOREIGN KEY (TipDoc,Liquidacion,IdCia) REFERENCES [dbo].[Trn_TraLiquida] (TipDoc,Liquidacion,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiquidaDedCausacion ON Trn_TraLiquidaDed(TipCau,Causacion,IdCiaCau)

GO
ALTER TABLE Trn_TraLiquidaOdp ADD 
 CONSTRAINT FK_Trn_TraLiquidaOdp_Trn_TraLiquida FOREIGN KEY (TipDoc,Liquidacion,IdCia) REFERENCES [dbo].[Trn_TraLiquida] (TipDoc,Liquidacion,IdCia)
GO
ALTER TABLE Trn_TraLiquidaOtr ADD 
 CONSTRAINT FK_Trn_TraLiquidaOtr_Trn_TraLiquida FOREIGN KEY (TipDoc,Liquidacion,IdCia) REFERENCES [dbo].[Trn_TraLiquida] (TipDoc,Liquidacion,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiquidaOtr ON Trn_TraLiquidaOtr(TipCau,Causacion,IdCiaCau)

GO
ALTER TABLE Trn_TraLiqViajes ADD 
 CONSTRAINT FK_Trn_TraLiqViajes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraLiqViajes_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraLiqViajes_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraLiqViajes_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraLiqViajes_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraLiqViajes_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraLiqViajes_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraLiqViajes_Terceros1 FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraLiqViajes_Terceros2 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiqViajesFecha ON Trn_TraLiqViajes(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiqViajesManifiesto ON Trn_TraLiqViajes(TipMuc,Manifiesto,IdCiaMuc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiqViajesIdVehiculo ON Trn_TraLiqViajes(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraLiqViajesIdPoseedor ON Trn_TraLiqViajes(IdPoseedor)

GO
ALTER TABLE Trn_TraManifAnexo ADD 
 CONSTRAINT FK_Trn_TraManifAnexo_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraManifAnexo_Trn_TraManifiesto FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifiesto] (TipDoc,Manifiesto,IdCia)
GO
ALTER TABLE Trn_TraManifiesto ADD 
 CONSTRAINT FK_Trn_TraManifiesto_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraManifiesto_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraManifiesto_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraManifiesto_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraManifiesto_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifiesto_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifiesto_Localidades2 FOREIGN KEY (IdLocFletes) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifiesto_Rutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[Rutas] (IdRuta),
 CONSTRAINT FK_Trn_TraManifiesto_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraManifiesto_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraManifiesto_Terceros1 FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraManifiesto_Terceros2 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraManifiesto_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE CLUSTERED INDEX IX_Trn_TraManifiestoFecha ON Trn_TraManifiesto(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifiestoIdVehiculo ON Trn_TraManifiesto(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifiestoIdPoseedor ON Trn_TraManifiesto(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifiestoIdConductor ON Trn_TraManifiesto(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifiestoFecDespacho ON Trn_TraManifiesto(FecDespacho)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifiestoIdOrigen ON Trn_TraManifiesto(IdOrigen,IdDestino)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifiestoIdRuta ON Trn_TraManifiesto(IdRuta)

GO
ALTER TABLE Trn_TraManifInt ADD 
 CONSTRAINT FK_Trn_TraManifInt_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraManifInt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraManifInt_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraManifInt_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraManifInt_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraManifInt_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifInt_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraManifInt_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraManifInt_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraManifInt_Terceros1 FOREIGN KEY (IdCondRelev) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntFecha ON Trn_TraManifInt(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntFecEmision ON Trn_TraManifInt(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntIdOrigen ON Trn_TraManifInt(IdOrigen,IdDestino)
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntIdVehiculo ON Trn_TraManifInt(IdVehiculo)

GO
ALTER TABLE Trn_TraManifIntCon ADD 
 CONSTRAINT FK_Trn_TraManifIntCon_TiposCnd FOREIGN KEY (IdTipoCon) REFERENCES [dbo].[TiposCnd] (IdTipoCon),
 CONSTRAINT FK_Trn_TraManifIntCon_TiposPcnto FOREIGN KEY (IdTipoPre) REFERENCES [dbo].[TiposPcnto] (IdTipoPre),
 CONSTRAINT FK_Trn_TraManifIntCon_Trn_TraManifInt FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifInt] (TipDoc,Manifiesto,IdCia)
GO
ALTER TABLE Trn_TraManifIntMcia ADD 
 CONSTRAINT FK_Trn_TraManifIntMcia_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraManifIntMcia_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Trn_TraManifIntMcia_Trn_TraManifInt FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifInt] (TipDoc,Manifiesto,IdCia),
 CONSTRAINT FK_Trn_TraManifIntMcia_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifIntMciaNumOrden ON Trn_TraManifIntMcia(TipOrd,NumOrden,IdCiaOrd)

GO
ALTER TABLE Trn_TraManifMod ADD 
 CONSTRAINT FK_Trn_TraManifMod_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraManifMod_Trn_TraManifiesto FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifiesto] (TipDoc,Manifiesto,IdCia)
GO
ALTER TABLE Trn_TraManifRem ADD 
 CONSTRAINT FK_Trn_TraManifRem_Trn_TraManifiesto FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraManifiesto] (TipDoc,Manifiesto,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraManifRemRemesa ON Trn_TraManifRem(TipRem,Remesa,IdCiaRem)

GO
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)
GO
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)
GO
 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)

GO
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)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenCumFecha ON Trn_TraOrdenCum(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenCumNumOrden ON Trn_TraOrdenCum(TipOds,NumOrden,IdCiaOds)

GO
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)
GO
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)
GO
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)
GO
 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)

GO
ALTER TABLE Trn_TraOrdenManif ADD 
 CONSTRAINT FK_Trn_TraOrdenManif_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenManif_Terceros1 FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenManif_Terceros2 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraOrdenManif_Trn_TraManifiesto FOREIGN KEY (TipMuc,Manifiesto,IdCiaMuc) REFERENCES [dbo].[Trn_TraManifiesto] (TipDoc,Manifiesto,IdCia),
 CONSTRAINT FK_Trn_TraOrdenManif_Trn_TraOrdenPago FOREIGN KEY (TipDoc,OrdPago,IdCia) REFERENCES [dbo].[Trn_TraOrdenPago] (TipDoc,OrdPago,IdCia),
 CONSTRAINT FK_Trn_TraOrdenManif_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenManifManifiesto ON Trn_TraOrdenManif(TipMuc,Manifiesto,IdCiaMuc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenManifIdVehiculo ON Trn_TraOrdenManif(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenManifIdPoseedor ON Trn_TraOrdenManif(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenManifIdConductor ON Trn_TraOrdenManif(IdConductor)

GO
ALTER TABLE Trn_TraOrdenOper ADD 
 CONSTRAINT FK_Trn_TraOrdenOper_Terceros FOREIGN KEY (IdOperario) REFERENCES [dbo].[Terceros] (IdTercero)
GO
ALTER TABLE Trn_TraOrdenPago ADD 
 CONSTRAINT FK_Trn_TraOrdenPago_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraOrdenPago_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenPago_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraOrdenPago_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_TraOrdenPago_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraOrdenPago_Plazos FOREIGN KEY (IdPlazo) REFERENCES [dbo].[Plazos] (IdPlazo),
 CONSTRAINT FK_Trn_TraOrdenPago_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE CLUSTERED INDEX IX_Trn_TraOrdenPagoFecha ON Trn_TraOrdenPago(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenPagoComprobante ON Trn_TraOrdenPago(TipCom,Comprobante,IdCiaCom)

GO
ALTER TABLE Trn_TraOrdenRemesas ADD 
 CONSTRAINT FK_Trn_TraOrdenRemesas_Trn_TraOrdenPago FOREIGN KEY (TipDoc,OrdPago,IdCia) REFERENCES [dbo].[Trn_TraOrdenPago] (TipDoc,OrdPago,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenRemesasManifiesto ON Trn_TraOrdenRemesas(TipMuc,Manifiesto,IdCiaMuc)
 CREATE NONCLUSTERED INDEX IX_Trn_TraOrdenRemesasRemesa ON Trn_TraOrdenRemesas(TipRem,Remesa,IdCiaRem,ItemRem)

GO
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)
GO
 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)

GO
ALTER TABLE Trn_TraPedAnexo ADD 
 CONSTRAINT FK_Trn_TraPedAnexo_Trn_TraPedido FOREIGN KEY (TipDoc,Pedido,IdCia) REFERENCES [dbo].[Trn_TraPedido] (TipDoc,Pedido,IdCia)
GO
ALTER TABLE Trn_TraPedido ADD 
 CONSTRAINT FK_Trn_TraPedido_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraPedido_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraPedido_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraPedido_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraPedido_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraPedido_Localidades FOREIGN KEY (IdLocOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPedido_Localidades1 FOREIGN KEY (IdLocDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPedido_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraPedido_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraPedido_Terceros1 FOREIGN KEY (IdClieFact) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraPedido_Terceros2 FOREIGN KEY (IdRemitente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraPedido_Terceros3 FOREIGN KEY (IdDestinatario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraPedido_Terceros4 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedidoFecha ON Trn_TraPedido(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedidoIdCliente ON Trn_TraPedido(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedidoIdRemitente ON Trn_TraPedido(IdRemitente)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedidoFactura ON Trn_TraPedido(TipFac,Factura,IdCiaFac)

GO
ALTER TABLE Trn_TraPedMcias ADD 
 CONSTRAINT FK_Trn_TraPedMcias_Empaques FOREIGN KEY (IdEmp) REFERENCES [dbo].[Empaques] (IdEmp),
 CONSTRAINT FK_Trn_TraPedMcias_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPedMcias_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPedMcias_Mercancias FOREIGN KEY (IdMercancia) REFERENCES [dbo].[Mercancias] (IdMercancia),
 CONSTRAINT FK_Trn_TraPedMcias_TiposMcia FOREIGN KEY (IdTmcia) REFERENCES [dbo].[TiposMcia] (IdTmcia),
 CONSTRAINT FK_Trn_TraPedMcias_TiposMnjo FOREIGN KEY (IdMnjo) REFERENCES [dbo].[TiposMnjo] (IdMnjo),
 CONSTRAINT FK_Trn_TraPedMcias_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Trn_TraPedMcias_Trn_TraPedido FOREIGN KEY (TipDoc,Pedido,IdCia) REFERENCES [dbo].[Trn_TraPedido] (TipDoc,Pedido,IdCia),
 CONSTRAINT FK_Trn_TraPedMcias_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedMciasIdMercancia ON Trn_TraPedMcias(IdMercancia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedMciasIdOrigen ON Trn_TraPedMcias(IdOrigen)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPedMciasIdDestino ON Trn_TraPedMcias(IdDestino)

GO
ALTER TABLE Trn_TraPorteInt ADD 
 CONSTRAINT FK_Trn_TraPorteInt_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraPorteInt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraPorteInt_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraPorteInt_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraPorteInt_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraPorteInt_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPorteInt_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPorteInt_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraPorteIntFecha ON Trn_TraPorteInt(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPorteIntFecEmision ON Trn_TraPorteInt(FecEmision)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPorteIntIdOrigen ON Trn_TraPorteInt(IdOrigen,IdDestino)

GO
ALTER TABLE Trn_TraPorteIntGas ADD 
 CONSTRAINT FK_Trn_TraPorteIntGas_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_TraPorteIntGas_Trn_TraPorteInt FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraPorteInt] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_TraPorteIntMcia ADD 
 CONSTRAINT FK_Trn_TraPorteIntMcia_adm_monedas FOREIGN KEY (IdMoneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraPorteIntMcia_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Trn_TraPorteIntMcia_Trn_TraPorteInt FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraPorteInt] (TipDoc,NumOrden,IdCia),
 CONSTRAINT FK_Trn_TraPorteIntMcia_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
ALTER TABLE Trn_TraPresAnt ADD 
 CONSTRAINT FK_Trn_TraPresAnt_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraPresAnt_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraPresAnt_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraPresAntFecha ON Trn_TraPresAnt(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraPresAntIdOrigen ON Trn_TraPresAnt(IdOrigen,IdDestino)

GO
ALTER TABLE Trn_TraPresItems ADD 
 CONSTRAINT FK_Trn_TraPresItems_ConcDiversos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[ConcDiversos] (IdConcepto),
 CONSTRAINT FK_Trn_TraPresItems_Trn_TraPresAnt FOREIGN KEY (NumPsto) REFERENCES [dbo].[Trn_TraPresAnt] (NumPsto)
GO
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)
GO
 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)

GO
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)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraReexpedidoRemRemesa ON Trn_TraReexpedidoRem(TipRem,Remesa,IdCiaRem)

GO
ALTER TABLE Trn_TraRemAnexo ADD 
 CONSTRAINT FK_Trn_TraRemAnexo_Terceros FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraRemAnexo_Trn_TraRemesa FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraRemesa] (TipDoc,NumOrden,IdCia)
GO
 CREATE CLUSTERED INDEX IX_Trn_TraRemCancelaRemesa ON Trn_TraRemCancela(TipRem,Remesa,IdCiaRem,Item)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemCancelaFecha ON Trn_TraRemCancela(Fecha)

GO
ALTER TABLE Trn_TraRemCntdor ADD 
 CONSTRAINT FK_Trn_TraRemCntdor_TiposCnd FOREIGN KEY (IdTipoCon) REFERENCES [dbo].[TiposCnd] (IdTipoCon),
 CONSTRAINT FK_Trn_TraRemCntdor_TiposPcnto FOREIGN KEY (IdTipoPre) REFERENCES [dbo].[TiposPcnto] (IdTipoPre),
 CONSTRAINT FK_Trn_TraRemCntdor_Trn_TraRemesa FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraRemesa] (TipDoc,NumOrden,IdCia)
GO
ALTER TABLE Trn_TraRemesa ADD 
 CONSTRAINT FK_Trn_TraRemesa_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_Trn_TraRemesa_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraRemesa_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraRemesa_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraRemesa_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_TraRemesa_Localidades FOREIGN KEY (IdLocOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraRemesa_Localidades1 FOREIGN KEY (IdLocDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraRemesa_Localidades2 FOREIGN KEY (IdLocFletes) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraRemesa_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraRemesa_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraRemesa_Terceros1 FOREIGN KEY (IdClieFact) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraRemesa_Terceros2 FOREIGN KEY (IdRemitente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraRemesa_Terceros3 FOREIGN KEY (IdDestinatario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraRemesa_Terceros4 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_TraRemesaFecha ON Trn_TraRemesa(Fecha,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaIdCliente ON Trn_TraRemesa(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaIdVehiculo ON Trn_TraRemesa(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaFecDespacho ON Trn_TraRemesa(FecDespacho)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaNumGuia ON Trn_TraRemesa(SerieGuia,NumGuia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaIdAgencia ON Trn_TraRemesa(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaIdLocOrigen ON Trn_TraRemesa(IdLocOrigen,IdLocDestino)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemesaIdConductor ON Trn_TraRemesa(IdConductor)

GO
ALTER TABLE Trn_TraRemMcias ADD 
 CONSTRAINT FK_Trn_TraRemMcias_Empaques FOREIGN KEY (IdEmp) REFERENCES [dbo].[Empaques] (IdEmp),
 CONSTRAINT FK_Trn_TraRemMcias_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraRemMcias_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_Trn_TraRemMcias_Mercancias FOREIGN KEY (IdMercancia) REFERENCES [dbo].[Mercancias] (IdMercancia),
 CONSTRAINT FK_Trn_TraRemMcias_Terceros FOREIGN KEY (NitRemite) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraRemMcias_TiposMcia FOREIGN KEY (IdTmcia) REFERENCES [dbo].[TiposMcia] (IdTmcia),
 CONSTRAINT FK_Trn_TraRemMcias_TiposMnjo FOREIGN KEY (IdMnjo) REFERENCES [dbo].[TiposMnjo] (IdMnjo),
 CONSTRAINT FK_Trn_TraRemMcias_TiposNat FOREIGN KEY (IdNat) REFERENCES [dbo].[TiposNat] (IdNat),
 CONSTRAINT FK_Trn_TraRemMcias_Trn_TraRemesa FOREIGN KEY (TipDoc,NumOrden,IdCia) REFERENCES [dbo].[Trn_TraRemesa] (TipDoc,NumOrden,IdCia),
 CONSTRAINT FK_Trn_TraRemMcias_UndMed FOREIGN KEY (IdUnd) REFERENCES [dbo].[UndMed] (IdUnd)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemMciasIdMercancia ON Trn_TraRemMcias(IdMercancia)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemMciasIdOrigen ON Trn_TraRemMcias(IdOrigen)
 CREATE NONCLUSTERED INDEX IX_Trn_TraRemMciasIdDestino ON Trn_TraRemMcias(IdDestino)

GO
ALTER TABLE Trn_TraReportes ADD 
 CONSTRAINT FK_Trn_TraReportes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraReportes_Trn_TraDespachos FOREIGN KEY (TipDoc,Manifiesto,IdCia) REFERENCES [dbo].[Trn_TraDespachos] (TipDoc,Manifiesto,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraReportesCdRuta ON Trn_TraReportes(CdRuta,IdPunto)

GO
ALTER TABLE Trn_Traslados ADD 
 CONSTRAINT FK_Trn_Traslados_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_Traslados_CentroCosto FOREIGN KEY (IdCCosto) REFERENCES [dbo].[CentroCosto] (IdCCosto),
 CONSTRAINT FK_Trn_Traslados_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Traslados_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Traslados_Conceptos FOREIGN KEY (IdConcepto) REFERENCES [dbo].[Conceptos] (IdConcepto),
 CONSTRAINT FK_Trn_Traslados_EstadoDoc FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoDoc] (IdEstado),
 CONSTRAINT FK_Trn_Traslados_SubCentros FOREIGN KEY (IdSubCos) REFERENCES [dbo].[SubCentros] (IdSubCos),
 CONSTRAINT FK_Trn_Traslados_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Traslados_Terceros FOREIGN KEY (IdTercero) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TrasladosFecha ON Trn_Traslados(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TrasladosIdTercero ON Trn_Traslados(IdTercero)
 CREATE NONCLUSTERED INDEX IX_Trn_TrasladosIdConcepto ON Trn_Traslados(IdConcepto)
 CREATE NONCLUSTERED INDEX IX_Trn_TrasladosNumOrden ON Trn_Traslados(NumOrden)
 CREATE NONCLUSTERED INDEX IX_Trn_TrasladosComprobante ON Trn_Traslados(TipCom,Comprobante,IdCiaCom)
 CREATE NONCLUSTERED INDEX IX_Trn_TrasladosIdCCosto ON Trn_Traslados(IdCCosto)

GO
ALTER TABLE Trn_TraTalonarios ADD 
 CONSTRAINT FK_Trn_TraTalonarios_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraTalonariosFecha ON Trn_TraTalonarios(Fecha)

GO
ALTER TABLE Trn_TraTrasladoRem ADD 
 CONSTRAINT FK_Trn_TraTrasladoRem_Trn_TraTraslados FOREIGN KEY (TipDoc,Traslado,IdCia) REFERENCES [dbo].[Trn_TraTraslados] (TipDoc,Traslado,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraTrasladoRemRemesa ON Trn_TraTrasladoRem(TipRem,Remesa,IdCiaRem)

GO
ALTER TABLE Trn_TraTraslados ADD 
 CONSTRAINT FK_Trn_TraTraslados_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraTraslados_AlmBodegas FOREIGN KEY (IdBodega) REFERENCES [dbo].[AlmBodegas] (IdBodega),
 CONSTRAINT FK_Trn_TraTraslados_AlmBodegas1 FOREIGN KEY (IdBodDtno) REFERENCES [dbo].[AlmBodegas] (IdBodega),
 CONSTRAINT FK_Trn_TraTraslados_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraTraslados_Companias1 FOREIGN KEY (IdCiaCrea) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraTraslados_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_TraTraslados_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_TraTrasladosFecha ON Trn_TraTraslados(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_TraTrasladosIdConductor ON Trn_TraTraslados(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_TraTrasladosIdVehiculo ON Trn_TraTraslados(IdVehiculo)

GO
ALTER TABLE Trn_TraTurn ADD 
 CONSTRAINT FK_Trn_TraTurn_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_TraTurn_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_TraTurn_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_TraTurn_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE CLUSTERED INDEX IX_Trn_TraTurnIdVehiculo ON Trn_TraTurn(IdCia,IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_TraTurnFecha ON Trn_TraTurn(Fecha)

GO
ALTER TABLE Trn_Vales ADD 
 CONSTRAINT FK_Trn_Vales_Puc FOREIGN KEY (IdCuenta) REFERENCES [dbo].[Puc] (IdCuenta),
 CONSTRAINT FK_Trn_Vales_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Vales_Trn_RadicaVales FOREIGN KEY (TipDoc,nRadica,IdCia) REFERENCES [dbo].[Trn_RadicaVales] (TipDoc,nRadica,IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_ValesNumForma ON Trn_Vales(TipoRango,IdRango,NumSerie,NumForma)
 CREATE NONCLUSTERED INDEX IX_Trn_ValesIdCliente ON Trn_Vales(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_ValesNumFactura ON Trn_Vales(TipFac,NumFactura,IdCiaFac)

GO
ALTER TABLE Trn_ValesRutas ADD 
 CONSTRAINT FK_Trn_ValesRutas_TaxRutas FOREIGN KEY (IdRuta) REFERENCES [dbo].[TaxRutas] (IdRuta),
 CONSTRAINT FK_Trn_ValesRutas_Trn_Vales FOREIGN KEY (TipDoc,nRadica,IdCia,Item) REFERENCES [dbo].[Trn_Vales] (TipDoc,nRadica,IdCia,Item)
GO
ALTER TABLE Trn_VehConductor ADD 
 CONSTRAINT FK_Trn_VehConductor_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_VehConductor_TercCndtores FOREIGN KEY (IdConductor) REFERENCES [dbo].[TercCndtores] (IdConductor),
 CONSTRAINT FK_Trn_VehConductor_TercCndtores1 FOREIGN KEY (IdCondNuevo) REFERENCES [dbo].[TercCndtores] (IdConductor),
 CONSTRAINT FK_Trn_VehConductor_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VehConductor_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_VehConductorIdVehiculo ON Trn_VehConductor(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehConductorFecha ON Trn_VehConductor(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_VehConductorIdPropietario ON Trn_VehConductor(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_VehConductorIdConductor ON Trn_VehConductor(IdConductor)
 CREATE NONCLUSTERED INDEX IX_Trn_VehConductorIdCondNuevo ON Trn_VehConductor(IdCondNuevo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehConductorIdUsuario ON Trn_VehConductor(IdUsuario)

GO
ALTER TABLE Trn_VehLecturas ADD 
 CONSTRAINT FK_Trn_VehLecturas_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_VehLecturas_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_VehLecturasFecha ON Trn_VehLecturas(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_VehLecturaspVehiculo ON Trn_VehLecturas(pVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehLecturasTimeSys ON Trn_VehLecturas(TimeSys)

GO
ALTER TABLE Trn_VehNumOrden ADD 
 CONSTRAINT FK_Trn_VehNumOrden_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_VehNumOrden_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_VehNumOrdenFecha ON Trn_VehNumOrden(Fecha)

GO
ALTER TABLE Trn_VehTraspasos ADD 
 CONSTRAINT FK_Trn_VehTraspasos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Trn_VehTraspasos_GruposPro FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposPro] (IdGrupo),
 CONSTRAINT FK_Trn_VehTraspasos_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VehTraspasos_Terceros1 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VehTraspasos_Terceros2 FOREIGN KEY (IdPropNuevo) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VehTraspasos_Terceros3 FOREIGN KEY (IdPoseeNuevo) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VehTraspasos_TiposPpt FOREIGN KEY (IdPpd) REFERENCES [dbo].[TiposPpt] (IdPpd),
 CONSTRAINT FK_Trn_VehTraspasos_TiposPpt1 FOREIGN KEY (IdNewPpd) REFERENCES [dbo].[TiposPpt] (IdPpd),
 CONSTRAINT FK_Trn_VehTraspasos_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdVehiculo ON Trn_VehTraspasos(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosFecha ON Trn_VehTraspasos(Fecha)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdPpd ON Trn_VehTraspasos(IdPpd)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdPropietario ON Trn_VehTraspasos(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdPoseedor ON Trn_VehTraspasos(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdPropNuevo ON Trn_VehTraspasos(IdPropNuevo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdPoseeNuevo ON Trn_VehTraspasos(IdPoseeNuevo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdNewPpd ON Trn_VehTraspasos(IdNewPpd)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdGrupo ON Trn_VehTraspasos(IdGrupo)
 CREATE NONCLUSTERED INDEX IX_Trn_VehTraspasosIdUsuario ON Trn_VehTraspasos(IdUsuario)

GO
ALTER TABLE Trn_VencAbonos ADD 
 CONSTRAINT FK_Trn_VencAbonos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_VencAbonos_Companias1 FOREIGN KEY (IdCiaFac) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_VencAbonos_Sys_TiposDoc FOREIGN KEY (TipRec) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_VencAbonos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VencAbonos_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_VencAbonos_Trn_Vencimientos FOREIGN KEY (TipDoc,Factura,IdCiaFac,ItemFac) REFERENCES [dbo].[Trn_Vencimientos] (TipDoc,Factura,IdCia,Item)
GO
 CREATE CLUSTERED INDEX IX_Trn_VencAbonosFecha ON Trn_VencAbonos(Fecha,IdCliente,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_VencAbonosFactura ON Trn_VencAbonos(TipDoc,Factura,IdCiaFac,ItemFac)
 CREATE NONCLUSTERED INDEX IX_Trn_VencAbonosIdCliente ON Trn_VencAbonos(IdCliente)
 CREATE NONCLUSTERED INDEX IX_Trn_VencAbonosIdAgencia ON Trn_VencAbonos(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_VencAbonosIdVend ON Trn_VencAbonos(IdVend)

GO
ALTER TABLE Trn_Vencimientos ADD 
 CONSTRAINT FK_Trn_Vencimientos_Agencias FOREIGN KEY (IdAgencia) REFERENCES [dbo].[Agencias] (IdAgencia),
 CONSTRAINT FK_Trn_Vencimientos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Trn_Vencimientos_Sys_TiposDoc FOREIGN KEY (TipDoc) REFERENCES [dbo].[Sys_TiposDoc] (IdDoc),
 CONSTRAINT FK_Trn_Vencimientos_Terceros FOREIGN KEY (IdCliente) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Trn_Vencimientos_Terceros1 FOREIGN KEY (IdVend) REFERENCES [dbo].[Terceros] (IdTercero)
GO
 CREATE CLUSTERED INDEX IX_Trn_VencimientosFechaIdCliente ON Trn_Vencimientos(Fecha,IdCliente,IdCia)
 CREATE NONCLUSTERED INDEX IX_Trn_VencimientosIdAgencia ON Trn_Vencimientos(IdAgencia)
 CREATE NONCLUSTERED INDEX IX_Trn_VencimientosFechaVence ON Trn_Vencimientos(FechaVence)
 CREATE NONCLUSTERED INDEX IX_Trn_VencimientosIdVend ON Trn_Vencimientos(IdVend)

GO
ALTER TABLE UndMed ADD 
 CONSTRAINT FK_UndMed_Empaques FOREIGN KEY (IdEmp) REFERENCES [dbo].[Empaques] (IdEmp),
 CONSTRAINT FK_UndMed_Sys_Um FOREIGN KEY (UndMed) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_UndMed_Sys_Um1 FOREIGN KEY (UndCapc) REFERENCES [dbo].[Sys_Um] (UndMed),
 CONSTRAINT FK_UndMed_TiposMat FOREIGN KEY (IdMat) REFERENCES [dbo].[TiposMat] (IdMat)
GO
 CREATE NONCLUSTERED INDEX IX_UndMedIdMat ON UndMed(IdMat)
 CREATE NONCLUSTERED INDEX IX_UndMedIdEmp ON UndMed(IdEmp)
 CREATE NONCLUSTERED INDEX IX_UndMedFormRecp ON UndMed(FormRecp)
 CREATE NONCLUSTERED INDEX IX_UndMedClaseEmp ON UndMed(ClaseEmp)
 CREATE NONCLUSTERED INDEX IX_UndMedUndMed ON UndMed(UndMed)
 CREATE NONCLUSTERED INDEX IX_UndMedUndCapc ON UndMed(UndCapc)

GO
ALTER TABLE Veh_Contrato ADD 
 CONSTRAINT FK_Veh_Contrato_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Veh_Contrato_TiposAdm FOREIGN KEY (IdAdmon) REFERENCES [dbo].[TiposAdm] (IdAdmon),
 CONSTRAINT FK_Veh_Contrato_TiposCon FOREIGN KEY (IdTipCon) REFERENCES [dbo].[TiposCon] (IdTipCon),
 CONSTRAINT FK_Veh_Contrato_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_Veh_ContratoIdVehiculo ON Veh_Contrato(IdVehiculo)

GO
ALTER TABLE Veh_Cupos ADD 
 CONSTRAINT FK_Veh_Cupos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Veh_Cupos_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Veh_Cupos_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
ALTER TABLE Veh_Saldos ADD 
 CONSTRAINT FK_Veh_Saldos_BusClaseCue FOREIGN KEY (IdClase) REFERENCES [dbo].[BusClaseCue] (IdClase),
 CONSTRAINT FK_Veh_Saldos_Companias FOREIGN KEY (IdCia) REFERENCES [dbo].[Companias] (IdCia),
 CONSTRAINT FK_Veh_Saldos_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
ALTER TABLE VehClientes ADD 
 CONSTRAINT FK_VehClientes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_VehClientes_EstadoVeh FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoVeh] (IdEstado),
 CONSTRAINT FK_VehClientes_Marcas FOREIGN KEY (IdMarca) REFERENCES [dbo].[Marcas] (IdMarca),
 CONSTRAINT FK_VehClientes_TiposFil FOREIGN KEY (IdFiltro) REFERENCES [dbo].[TiposFil] (IdFiltro),
 CONSTRAINT FK_VehClientes_TiposFuel FOREIGN KEY (IdCom) REFERENCES [dbo].[TiposFuel] (IdCom),
 CONSTRAINT FK_VehClientes_TiposLla FOREIGN KEY (IdTlla) REFERENCES [dbo].[TiposLla] (IdTlla),
 CONSTRAINT FK_VehClientes_TiposLub FOREIGN KEY (IdLub) REFERENCES [dbo].[TiposLub] (IdLub),
 CONSTRAINT FK_VehClientes_TiposMot FOREIGN KEY (IdTipoMot) REFERENCES [dbo].[TiposMot] (IdTipoMot),
 CONSTRAINT FK_VehClientes_TiposVeh FOREIGN KEY (IdTipoVeh) REFERENCES [dbo].[TiposVeh] (IdTipoVeh)
GO
ALTER TABLE VehConductores ADD 
 CONSTRAINT FK_VehConductores_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
ALTER TABLE Vehiculos ADD 
 CONSTRAINT FK_Vehiculos_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_Vehiculos_EstadoVeh FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoVeh] (IdEstado),
 CONSTRAINT FK_Vehiculos_GruposPro FOREIGN KEY (IdGrupo) REFERENCES [dbo].[GruposPro] (IdGrupo),
 CONSTRAINT FK_Vehiculos_Marcas FOREIGN KEY (IdMarca) REFERENCES [dbo].[Marcas] (IdMarca),
 CONSTRAINT FK_Vehiculos_Marcas1 FOREIGN KEY (IdMarlla) REFERENCES [dbo].[Marcas] (IdMarca),
 CONSTRAINT FK_Vehiculos_MarcasLin FOREIGN KEY (IdLinea) REFERENCES [dbo].[MarcasLin] (IdLinea),
 CONSTRAINT FK_Vehiculos_PeajesCat FOREIGN KEY (IdCat) REFERENCES [dbo].[PeajesCat] (IdCat),
 CONSTRAINT FK_Vehiculos_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Vehiculos_Terceros1 FOREIGN KEY (IdPoseedor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Vehiculos_Terceros2 FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_Vehiculos_TiposAdm FOREIGN KEY (IdAdmon) REFERENCES [dbo].[TiposAdm] (IdAdmon),
 CONSTRAINT FK_Vehiculos_TiposCar FOREIGN KEY (IdCrceria) REFERENCES [dbo].[TiposCar] (IdCrceria),
 CONSTRAINT FK_Vehiculos_TiposCol FOREIGN KEY (IdColor) REFERENCES [dbo].[TiposCol] (IdColor),
 CONSTRAINT FK_Vehiculos_TiposFuel FOREIGN KEY (IdCom) REFERENCES [dbo].[TiposFuel] (IdCom),
 CONSTRAINT FK_Vehiculos_TiposLla FOREIGN KEY (IdTlla) REFERENCES [dbo].[TiposLla] (IdTlla),
 CONSTRAINT FK_Vehiculos_TiposLub FOREIGN KEY (IdLub) REFERENCES [dbo].[TiposLub] (IdLub),
 CONSTRAINT FK_Vehiculos_TiposMot FOREIGN KEY (IdTipoMot) REFERENCES [dbo].[TiposMot] (IdTipoMot),
 CONSTRAINT FK_Vehiculos_TiposNivs FOREIGN KEY (IdNiv) REFERENCES [dbo].[TiposNivs] (IdNiv),
 CONSTRAINT FK_Vehiculos_TiposPpt FOREIGN KEY (IdPpd) REFERENCES [dbo].[TiposPpt] (IdPpd),
 CONSTRAINT FK_Vehiculos_TiposVeh FOREIGN KEY (IdTipoVeh) REFERENCES [dbo].[TiposVeh] (IdTipoVeh)
GO
 CREATE NONCLUSTERED INDEX IX_VehiculosNumVeh ON Vehiculos(NumVeh)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdTipoVeh ON Vehiculos(IdTipoVeh)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdMarca ON Vehiculos(IdMarca)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdCrceria ON Vehiculos(IdCrceria)
 CREATE NONCLUSTERED INDEX IX_VehiculosModelo ON Vehiculos(Modelo)
 CREATE NONCLUSTERED INDEX IX_VehiculosNumMotor ON Vehiculos(NumMotor)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdPropietario ON Vehiculos(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdPoseedor ON Vehiculos(IdPoseedor)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdConductor ON Vehiculos(IdConductor)
 CREATE NONCLUSTERED INDEX IX_VehiculosFecIngreso ON Vehiculos(FecIngreso)
 CREATE NONCLUSTERED INDEX IX_VehiculosIdEstado ON Vehiculos(IdEstado)

GO
ALTER TABLE VehPartes ADD 
 CONSTRAINT FK_VehPartes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_VehPartes_EstadoSer FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoSer] (IdEstado),
 CONSTRAINT FK_VehPartes_MttoSistemas FOREIGN KEY (IdSistema) REFERENCES [dbo].[MttoSistemas] (IdSistema)
GO
ALTER TABLE VehPolizas ADD 
 CONSTRAINT FK_VehPolizas_ClasePol FOREIGN KEY (IdClase) REFERENCES [dbo].[ClasePol] (IdClase),
 CONSTRAINT FK_VehPolizas_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
 CREATE NONCLUSTERED INDEX IX_VehPolizasIdVehiculo ON VehPolizas(IdVehiculo)
 CREATE NONCLUSTERED INDEX IX_VehPolizasIdClase ON VehPolizas(IdClase)
 CREATE NONCLUSTERED INDEX IX_VehPolizasNumero ON VehPolizas(Numero)

GO
ALTER TABLE VehPropietarios ADD 
 CONSTRAINT FK_VehPropietarios_Terceros FOREIGN KEY (NitPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_VehPropietarios_Vehiculos FOREIGN KEY (IdVehiculo) REFERENCES [dbo].[Vehiculos] (IdVehiculo)
GO
ALTER TABLE VehRemolq ADD 
 CONSTRAINT FK_VehRemolq_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_VehRemolq_EstadoVeh FOREIGN KEY (IdEstado) REFERENCES [dbo].[EstadoVeh] (IdEstado),
 CONSTRAINT FK_VehRemolq_Marcas FOREIGN KEY (IdMarca) REFERENCES [dbo].[Marcas] (IdMarca),
 CONSTRAINT FK_VehRemolq_Terceros FOREIGN KEY (IdPropietario) REFERENCES [dbo].[Terceros] (IdTercero),
 CONSTRAINT FK_VehRemolq_TiposCar FOREIGN KEY (IdCrceria) REFERENCES [dbo].[TiposCar] (IdCrceria),
 CONSTRAINT FK_VehRemolq_TiposCol FOREIGN KEY (IdColor) REFERENCES [dbo].[TiposCol] (IdColor)
GO
 CREATE NONCLUSTERED INDEX IX_VehRemolqIdMarca ON VehRemolq(IdMarca)
 CREATE NONCLUSTERED INDEX IX_VehRemolqIdColor ON VehRemolq(IdColor)
 CREATE NONCLUSTERED INDEX IX_VehRemolqIdCrceria ON VehRemolq(IdCrceria)
 CREATE NONCLUSTERED INDEX IX_VehRemolqModelo ON VehRemolq(Modelo)
 CREATE NONCLUSTERED INDEX IX_VehRemolqIdPropietario ON VehRemolq(IdPropietario)
 CREATE NONCLUSTERED INDEX IX_VehRemolqIdEstado ON VehRemolq(IdEstado)
 CREATE NONCLUSTERED INDEX IX_VehRemolqIdUsuario ON VehRemolq(IdUsuario)

GO
ALTER TABLE VehRemPolizas ADD 
 CONSTRAINT FK_VehRemPolizas_ClasePol FOREIGN KEY (IdClase) REFERENCES [dbo].[ClasePol] (IdClase)
GO
