--------------- SQL ---------------
CREATE TABLE [RDX_CABINV] (
  [NUMDOC] varchar(25) NOT NULL,
  [TIPODOC] varchar(3) NULL,
  [TIPOLIQ] varchar(3) NULL,
  [FECHA] datetime NULL,
  [FECHALIQ] datetime NULL,
  [EMISOR] varchar(17) NULL,
  [RECEPTOR] varchar(17) NULL,
  [DPTO] varchar(3) NULL,
  [CENTRO] varchar(17) NULL,
  [FECHA_CARGA] datetime NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_CABINV]
TO [public]
GO

ALTER TABLE [RDX_CABINV]
ADD PRIMARY KEY CLUSTERED ([NUMDOC])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_CABINV_idx] ON [RDX_CABINV]
  ([FECHALIQ])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_CABINV_idx2] ON [RDX_CABINV]
  ([CENTRO])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_LININV] (
  [NUMDOC] varchar(25) NOT NULL,
  [NUMLIN] numeric(6, 0) NOT NULL,
  [CODART] varchar(17) NULL,
  [FAMILIA] varchar(17) NULL,
  [BARRA] varchar(17) NULL,
  [TALLA] varchar(17) NULL,
  [MARCA] varchar(25) NULL,
  [TAMANO] varchar(25) NULL,
  [SERIE] varchar(25) NULL,
  [COLOR] varchar(25) NULL,
  [MODELO] varchar(25) NULL,
  [DIBUJO] varchar(25) NULL,
  [DESCRIP] varchar(70) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_LININV]
TO [public]
GO

ALTER TABLE [RDX_LININV]
ADD PRIMARY KEY CLUSTERED ([NUMDOC], [NUMLIN])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_LININV_idx] ON [RDX_LININV]
  ([CODART])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_CANTINV] (
  [NUMDOC] varchar(25) NOT NULL,
  [NUMLIN] numeric(6, 0) NOT NULL,
  [NUMCANT] numeric(6, 0) NOT NULL,
  [TIPOCANT] varchar(3) NULL,
  [CANTIDAD] numeric(15, 0) NULL,
  [CENTRO] varchar(17) NULL,
  [TMOV] varchar(3) NULL,
  [FACT] varchar(12) NULL,
  [DEPTO] varchar(3) NULL,
  [IDVEN] varchar(10) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_CANTINV]
TO [public]
GO

ALTER TABLE [RDX_CANTINV]
ADD PRIMARY KEY CLUSTERED ([NUMDOC], [NUMLIN], [NUMCANT])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_CANTINV_idx] ON [RDX_CANTINV]
  ([TIPOCANT])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_CANTINV_idx2] ON [RDX_CANTINV]
  ([IDVEN])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_CABVEN] (
  [CLAVE1] numeric(10, 0) NOT NULL,
  [NUMINF] varchar(35) NULL,
  [FUNCION] varchar(10) NULL,
  [FECINI] datetime NULL,
  [FECFIN] datetime NULL,
  [FECINF] datetime NULL,
  [PERVENINI] datetime NULL,
  [PERVENFIN] datetime NULL,
  [EANOFI] varchar(17) NULL,
  [EANEMI] varchar(17) NULL,
  [EANREC] varchar(17) NULL,
  [EANVEN] varchar(17) NULL,
  [EANALM] varchar(17) NULL,
  [EANREP] varchar(17) NULL,
  [EANPRO] varchar(17) NULL,
  [EANADMSA] varchar(17) NULL,
  [EANREPSR] varchar(17) NULL,
  [ADMVENSA] varchar(35) NULL,
  [REPDEPSR] varchar(35) NULL,
  [EMAILSA] varchar(35) NULL,
  [NUMFAXSA] varchar(35) NULL,
  [NUMTELSA] varchar(35) NULL,
  [NUMTLXSA] varchar(35) NULL,
  [X400SA] varchar(35) NULL,
  [EMAILSR] varchar(35) NULL,
  [NUMFAXSR] varchar(35) NULL,
  [NUMTELSR] varchar(35) NULL,
  [NUMTLXSR] varchar(35) NULL,
  [X400SR] varchar(35) NULL,
  [NUMPRE] varchar(35) NULL,
  [NUMINFSC] varchar(35) NULL,
  [NUMCON] varchar(35) NULL,
  [FECPRE] datetime NULL,
  [FECINFSC] datetime NULL,
  [FECCON] datetime NULL,
  [DIVPED] varchar(3) NULL,
  [DIVPRE] varchar(3) NULL,
  [DIVPAG] varchar(3) NULL,
  [DIVPEDF] varchar(3) NULL,
  [DIVPREF] varchar(3) NULL,
  [DIVPAGF] varchar(3) NULL,
  [TASCAM] numeric(15, 3) NULL,
  [FECTAS] datetime NULL,
  [FECHA_CARGA] datetime NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_CABVEN]
TO [public]
GO

ALTER TABLE [RDX_CABVEN]
ADD PRIMARY KEY CLUSTERED ([CLAVE1])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_LUGVEN] (
  [CLAVE1] numeric(10, 0) NOT NULL,
  [CLAVE2] numeric(5, 0) NOT NULL,
  [EANLUG] varchar(17) NULL,
  [LUGVEN] varchar(70) NULL,
  [FECINI] datetime NULL,
  [FECFIN] datetime NULL,
  [PERVENINI] datetime NULL,
  [PERVENFIN] datetime NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_LUGVEN]
TO [public]
GO

ALTER TABLE [RDX_LUGVEN]
ADD PRIMARY KEY CLUSTERED ([CLAVE1], [CLAVE2])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_LUGVEN_PERVENINI_IDX] ON [RDX_LUGVEN]
  ([PERVENINI])
ON [PRIMARY]
GO

ALTER TABLE [RDX_LUGVEN]
ADD CONSTRAINT [FK__RDX_LUGVE__CLAVE__4A59F0B5] FOREIGN KEY ([CLAVE1]) 
  REFERENCES [RDX_CABVEN] ([CLAVE1]) 
  ON UPDATE CASCADE
  ON DELETE CASCADE
GO

ALTER TABLE [RDX_LUGVEN]
NOCHECK CONSTRAINT [FK__RDX_LUGVE__CLAVE__4A59F0B5]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_ARTVEN] (
  [CLAVE1] numeric(10, 0) NOT NULL,
  [CLAVE2] numeric(5, 0) NOT NULL,
  [CLAVE3] numeric(5, 0) NOT NULL,
  [EANART] varchar(17) NULL,
  [CODCOM] varchar(35) NULL,
  [NUMVAR] varchar(35) NULL,
  [CODPRO] varchar(35) NULL,
  [DESARTCO] varchar(35) NULL,
  [DESART] varchar(70) NULL,
  [NUMCON] varchar(35) NULL,
  [NUMLIS] varchar(35) NULL,
  [CONESP1] varchar(3) NULL,
  [CONESP2] varchar(3) NULL,
  [CONESP3] varchar(3) NULL,
  [VALVEN] numeric(15, 3) NULL,
  [PRENETCT] numeric(15, 3) NULL,
  [PREBRUCT] numeric(15, 3) NULL,
  [PREINFET] numeric(15, 3) NULL,
  [PREINFFT] numeric(15, 3) NULL,
  [PRECALCT] numeric(15, 3) NULL,
  [PRENETCA] numeric(15, 3) NULL,
  [PREBRUCA] numeric(15, 3) NULL,
  [PREINFEA] numeric(15, 3) NULL,
  [PREINFFA] numeric(15, 3) NULL,
  [PRECALCA] numeric(15, 3) NULL,
  [BAPRUN1] numeric(9, 0) NULL,
  [UNIMED1] varchar(3) NULL,
  [BAPRUN2] numeric(9, 0) NULL,
  [UNIMED2] varchar(3) NULL,
  [BAPRUN3] numeric(9, 0) NULL,
  [UNIMED3] varchar(3) NULL,
  [BAPRUN4] numeric(9, 0) NULL,
  [UNIMED4] varchar(3) NULL,
  [BAPRUN5] numeric(9, 0) NULL,
  [UNIMED5] varchar(3) NULL,
  [CANVEN] numeric(15, 3) NULL,
  [EXIPRO] numeric(15, 3) NULL,
  [DESEXI] numeric(15, 3) NULL,
  [ESPMEDCV] varchar(3) NULL,
  [ESPMEDEP] varchar(3) NULL,
  [ESPMEDDE] varchar(3) NULL,
  [CANDEV] numeric(15, 3) NULL,
  [EANVEN] varchar(17) NULL,
  [NOMVEN] varchar(70) NULL,
  [NUMTALON] varchar(35) NULL,
  [CANVENNET] numeric(15, 3) NULL,
  [UMEDVENNET] varchar(3) NULL,
  [CANESP] numeric(15, 3) NULL,
  [UMEDESP] varchar(3) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_ARTVEN]
TO [public]
GO

ALTER TABLE [RDX_ARTVEN]
ADD PRIMARY KEY CLUSTERED ([CLAVE1], [CLAVE2], [CLAVE3])
ON [PRIMARY]
GO

ALTER TABLE [RDX_ARTVEN]
ADD CONSTRAINT [FK__RDX_ARTVEN__56BFC79A] FOREIGN KEY ([CLAVE1], [CLAVE2]) 
  REFERENCES [RDX_LUGVEN] ([CLAVE1], [CLAVE2]) 
  ON UPDATE CASCADE
  ON DELETE CASCADE
GO

ALTER TABLE [RDX_ARTVEN]
NOCHECK CONSTRAINT [FK__RDX_ARTVEN__56BFC79A]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_INFORMES] (
  [ID] smallint IDENTITY(1, 1) NOT NULL,
  [CATEGORIA] varchar(15) NULL,
  [ICONO] smallint NULL,
  [NOMBRE] varchar(50) NULL,
  [DESCRIPCION] varchar(255) NULL,
  [ORDEN] smallint NULL,
  [VISTA] text NULL,
  [MODIFICABLE] char(1) CONSTRAINT [DF__RDX_INFOR__MODIF__5C78A0F0] DEFAULT 'S' NOT NULL
)
ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_INFORMES]
TO [public]
GO

ALTER TABLE [RDX_INFORMES]
ADD CONSTRAINT [RDX_INFORMES_pk] 
PRIMARY KEY CLUSTERED ([ID])
ON [PRIMARY]
GO

--------------- SQL ---------------

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_ARTVEN]
TO [public]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_CABINV]
TO [public]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_CABVEN]
TO [public]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_CANTINV]
TO [public]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_LININV]
TO [public]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_LUGVEN]
TO [public]
GO


--------------- SQL ---------------
CREATE TABLE [RDX_LOG_CARGA] (
  [ID] int IDENTITY(1, 1) NOT NULL,
  [REPORT] varchar(10) NOT NULL,
  [FECHA] datetime NOT NULL,
  [OK] bit NOT NULL,
  [ERROR_MSG] varchar(255) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_LOG_CARGA]
TO [public]
GO

ALTER TABLE [RDX_LOG_CARGA]
ADD UNIQUE NONCLUSTERED ([ID])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_REFERENCIA_GENERICA] (
  [NUMINF] varchar(35) NOT NULL,
  [CLAVE1] numeric(10, 0) NOT NULL,
  [CLAVE2] numeric(5, 0) NOT NULL,
  [CLAVE3] numeric(5, 0) NOT NULL,
  [FECHACAMBIO] datetime NOT NULL,
  [ESTADO] char(1) NOT NULL,
  [CODIGO_BARRA] varchar(25) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_REFERENCIA_GENERICA]
TO [public]
GO

ALTER TABLE [RDX_REFERENCIA_GENERICA]
ADD CONSTRAINT [PK__RDX_REFERENCIA_G__68DE77D5] 
PRIMARY KEY CLUSTERED ([NUMINF], [CLAVE1], [CLAVE2], [CLAVE3])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_AJUSTES_ALBARAN] (
  [ALBARAN] char(7) NOT NULL,
  [ESTADO] varchar(15) NULL,
  [OBSERVACIONES] varchar(255) NULL,
  [CONTABILIZAR] char(1) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_AJUSTES_ALBARAN]
TO [public]
GO

ALTER TABLE [RDX_AJUSTES_ALBARAN]
ADD CONSTRAINT [PK__RDX_AJUSTES_ALBA__1B69F7A2] 
PRIMARY KEY CLUSTERED ([ALBARAN])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_AJUSTES_HOJA_DEVOLUCIONES] (
  [NUMHOJA] char(8) NOT NULL,
  [ESTADO] varchar(20) NULL,
  [OBSERVACIONES] varchar(255) NULL,
  [CONTABILIZAR] char(1) CONSTRAINT [DF__RDX_AJUST__CONTA__7BF14C49] DEFAULT 'S' NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_AJUSTES_HOJA_DEVOLUCIONES]
TO [public]
GO

ALTER TABLE [RDX_AJUSTES_HOJA_DEVOLUCIONES]
ADD CONSTRAINT [PK__RDX_AJUSTES_HOJA__483C9E19] 
PRIMARY KEY CLUSTERED ([NUMHOJA])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_DEVOLUCION_AJUSTES] (
  [FECHA] datetime NOT NULL,
  [CENTRO] varchar(17) NOT NULL,
  [CODIGO] varchar(12) NOT NULL,
  [COLOR] varchar(10) NOT NULL,
  [APROBADO] char(1) NULL,
  [FECHACAMBIO] datetime NULL,
  [CANT38] numeric(15, 0) NULL,
  [CANT40] numeric(15, 0) NULL,
  [CANT42] numeric(15, 0) NULL,
  [CANT44] numeric(15, 0) NULL,
  [CANT46] numeric(15, 0) NULL,
  [CANT48] numeric(15, 0) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_DEVOLUCION_AJUSTES]
TO [public]
GO

ALTER TABLE [RDX_DEVOLUCION_AJUSTES]
ADD CONSTRAINT [PK_RDX_DEVOLUCION_AJUSTES_2F70F04A] 
PRIMARY KEY CLUSTERED ([FECHA], [CENTRO], [CODIGO], [COLOR])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_RECEPCION_AJUSTES] (
  [FECHA] datetime NOT NULL,
  [CENTRO] varchar(17) NOT NULL,
  [CODIGO] varchar(12) NOT NULL,
  [COLOR] varchar(10) NOT NULL,
  [APROBADO] char(1) NULL,
  [FECHACAMBIO] datetime NULL,
  [CANT38] numeric(15, 0) NULL,
  [CANT40] numeric(15, 0) NULL,
  [CANT42] numeric(15, 0) NULL,
  [CANT44] numeric(15, 0) NULL,
  [CANT46] numeric(15, 0) NULL,
  [CANT48] numeric(15, 0) NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_RECEPCION_AJUSTES]
TO [public]
GO

ALTER TABLE [RDX_RECEPCION_AJUSTES]
ADD CONSTRAINT [PK_RDX_RECEPCION_AJUSTES_2F70F04F] 
PRIMARY KEY CLUSTERED ([FECHA], [CENTRO], [CODIGO], [COLOR])
ON [PRIMARY]
GO

--------------- SQL ---------------
CREATE TABLE [RDX_TRASPASOS_AJUSTES] (
  [FECHA] datetime NOT NULL,
  [CENTRO] varchar(17) NOT NULL,
  [CENTRO2] varchar(17) NOT NULL,
  [CODIGO] varchar(12) NOT NULL,
  [COLOR] varchar(10) NOT NULL,
  [APROBADO] char(1) NULL,
  [ESTADO] varchar(20) NULL,
  [OBSERVACIONES] varchar(255) NULL,
  [CONTABILIZAR] char(1) NULL,
  [FECHACAMBIO] datetime NULL,
  [CANT38] numeric(15, 0) NULL,
  [CANT40] numeric(15, 0) NULL,
  [CANT42] numeric(15, 0) NULL,
  [CANT44] numeric(15, 0) NULL,
  [CANT46] numeric(15, 0) NULL,
  [CANT48] numeric(15, 0) NULL,
  [TIPOCANT] varchar(3) NOT NULL
)
ON [PRIMARY]
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_TRASPASOS_AJUSTES]
TO [public]
GO

ALTER TABLE [RDX_TRASPASOS_AJUSTES]
ADD CONSTRAINT [PK_RDX_TRASPASOS_AJUSTES_2F70F04A] 
PRIMARY KEY CLUSTERED ([FECHA], [CENTRO], [CENTRO2], [CODIGO], [COLOR], [TIPOCANT])
ON [PRIMARY]
GO