IF EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[FK__RDX_LUGVE__CLAVE__4A59F0B5]') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
  ALTER TABLE [RDX_LUGVEN]
  DROP CONSTRAINT [FK__RDX_LUGVE__CLAVE__4A59F0B5]
GO

--
-- Dropping foreign key FK__RDX_ARTVEN__56BFC79A : 
--

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[FK__RDX_ARTVEN__56BFC79A]') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
  ALTER TABLE [dbo].[RDX_ARTVEN]
  DROP CONSTRAINT [FK__RDX_ARTVEN__56BFC79A]
GO

ALTER TABLE [RDX_CABINV]
ADD [CARGADO]char(1) NULL
GO

ALTER TABLE [RDX_CABVEN]
ADD [CARGADO]char(1) NULL
GO


/*--------------- SQL ---------------*/

IF EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[RDX_INVENTARIOEDI]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  DROP TABLE [RDX_INVENTARIOEDI]
GO

CREATE TABLE [RDX_INVENTARIOEDI] (
  [NUMDOC] varchar(25) NOT NULL,
  [NUMLIN] numeric(6, 0) NOT NULL,
  [NUMCANT] numeric(6, 0) NOT NULL,
  [TIPOCANT] varchar(3) NULL,
  [FECHA] datetime NULL,
  [CENTRO] varchar(17) NULL,
  [FILIAL] varchar(25) NULL,
  [CODVEN] varchar(10) NULL,
  [VENDEDOR] varchar(66) NULL,
  [CODIGO_BARRA] varchar(17) NULL,
  [CODIGO] varchar(12) NULL,
  [PRODUCTO] varchar(40) NULL,
  [COLOR] varchar(10) NULL,
  [TALLA] varchar(8) NULL,
  [CANTIDAD] numeric(15, 0) NULL,
  [CENTRO2] varchar(17) NULL,
  [FILIAL2] varchar(25) NULL,
  [ULTIMO_INVENTARIO] char(1) NULL,
  [IGNORAR] char(1) NULL
)
ON [PRIMARY]
GO

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

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx] ON [RDX_INVENTARIOEDI]
  ([TIPOCANT])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx2] ON [RDX_INVENTARIOEDI]
  ([FECHA])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx3] ON [RDX_INVENTARIOEDI]
  ([CENTRO])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx4] ON [RDX_INVENTARIOEDI]
  ([CODVEN])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx5] ON [RDX_INVENTARIOEDI]
  ([CODIGO_BARRA])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx6] ON [RDX_INVENTARIOEDI]
  ([CODIGO])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx7] ON [RDX_INVENTARIOEDI]
  ([CENTRO2])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx8] ON [RDX_INVENTARIOEDI]
  ([ULTIMO_INVENTARIO])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_INVENTARIOEDI_idx9] ON [RDX_INVENTARIOEDI]
  ([CENTRO], [CODIGO], [COLOR], [TALLA])
ON [PRIMARY]
GO

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

/*--------------- SQL ---------------*/

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[RDX_VENTASEDI]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  DROP TABLE [RDX_VENTASEDI]
GO

CREATE TABLE [RDX_VENTASEDI] (
  [NUMINF] varchar(35) NOT NULL,
  [CLAVE1] numeric(10, 0) NOT NULL,
  [CLAVE2] numeric(5, 0) NOT NULL,
  [CLAVE3] numeric(5, 0) NOT NULL,
  [PERVENINI] datetime NULL,
  [NUMTALON] varchar(35) NULL,
  [EANLUG] varchar(17) NULL,
  [FILIAL] varchar(25) NULL,
  [EANVEN] varchar(17) NULL,
  [CODVEN] varchar(4) NULL,
  [VENDEDOR] varchar(66) NULL,
  [EANART] varchar(17) NULL,
  [CODCOM] varchar(35) NULL,
  [PRODUTO] varchar(12) NULL,
  [DESC_PRODUTO] varchar(40) NULL,
  [COR_PRODUTO] varchar(10) NULL,
  [GRADE] varchar(8) NULL,
  [TIPO_PRODUTO] varchar(25) NULL,
  [GRUPO_PRODUTO] varchar(25) NULL,
  [DESC_COLECAO] varchar(40) NULL,
  [VALVEN] numeric(15, 3) NULL,
  [CANVEN] numeric(15, 3) NULL,
  [CANDEV] numeric(15, 3) NULL,
  [CANVENNET] numeric(15, 3) NULL,
  [CANESP] numeric(15, 3) NULL,
  [IGNORAR] char(1) NULL
)
ON [PRIMARY]
GO

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

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx] ON [RDX_VENTASEDI]
  ([PERVENINI])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx2] ON [RDX_VENTASEDI]
  ([NUMTALON])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx3] ON [RDX_VENTASEDI]
  ([EANVEN])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx4] ON [RDX_VENTASEDI]
  ([CODVEN])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx5] ON [RDX_VENTASEDI]
  ([EANART])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx6] ON [RDX_VENTASEDI]
  ([CODCOM])
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_VENTASEDI_idx7] ON [RDX_VENTASEDI]
  ([PRODUTO])
ON [PRIMARY]
GO

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



/*--------------- SQL ---------------*/

CREATE PROCEDURE RDX_P_CARGAR_INVENTARIOEDI
AS
BEGIN
	INSERT INTO RDX_INVENTARIOEDI (
	       NUMDOC, NUMLIN, NUMCANT, TIPOCANT, FECHA, CENTRO, FILIAL, CODVEN,
           VENDEDOR, CODIGO_BARRA, CODIGO, PRODUCTO, COLOR, TALLA, CANTIDAD,
           CENTRO2, FILIAL2, IGNORAR	)
	SELECT
	      RDX_CANTINV.NUMDOC,
	      RDX_CANTINV.NUMLIN,
	      RDX_CANTINV.NUMCANT,
	      RDX_CANTINV.TIPOCANT,
	      RDX_CABINV.FECHALIQ AS FECHA,
	      RDX_CABINV.CENTRO,
	      FILIAL = ISNULL(FILIAIS.FILIAL, RDX_CABINV.CENTRO),
	      RDX_CANTINV.IDVEN AS CODVEN,
	      VENDEDOR = ISNULL(LTRIM(RTRIM(LOJA_VENDEDORES.NOME_VENDEDOR)) + ' ' + LTRIM(RTRIM(LOJA_VENDEDORES.VENDEDOR_APELIDO)), RDX_CANTINV.IDVEN),
	      RDX_LININV.CODART AS CODIGO_BARRA,
	      CODIGO = ISNULL(PRODUTOS.PRODUTO, '107CH.EN.01'),
	      PRODUCTO = ISNULL(PRODUTOS.DESC_PRODUTO, '*** ERROR REFERENCIA  **** LLAMAR AL CI'),
	      COLOR = ISNULL(PRODUTOS_BARRA.COR_PRODUTO, 300),
	      TALLA = PRODUTOS_BARRA.GRADE,
	      RDX_CANTINV.CANTIDAD,
	      CENTRO2 = RDX_CANTINV.CENTRO,
	      FILIAL2 = ISNULL(FILIAIS2.FILIAL, RDX_CANTINV.CENTRO),
		  RDX_CABINV.IGNORAR
	FROM RDX_CANTINV
	INNER JOIN RDX_LININV ON
	      ((RDX_LININV.NUMDOC = RDX_CANTINV.NUMDOC) AND
	       (RDX_LININV.NUMLIN = RDX_CANTINV.NUMLIN))
	INNER JOIN RDX_CABINV ON
	      (RDX_CABINV.NUMDOC = RDX_LININV.NUMDOC)
	LEFT OUTER JOIN RDX_FILIALES ON (RDX_FILIALES.CODBARRA = RDX_CABINV.CENTRO)
	LEFT OUTER JOIN FILIAIS ON (FILIAIS.COD_FILIAL = RDX_FILIALES.CODFILIAL)
	LEFT OUTER JOIN RDX_FILIALES RDX_FILIALES2 ON (RDX_FILIALES2.CODBARRA = RDX_CANTINV.CENTRO)
	LEFT OUTER JOIN FILIAIS FILIAIS2 ON (FILIAIS2.COD_FILIAL = RDX_FILIALES2.CODFILIAL)
	LEFT OUTER JOIN LOJA_VENDEDORES ON (LOJA_VENDEDORES.RG = RDX_CANTINV.IDVEN)
	LEFT OUTER JOIN PRODUTOS_BARRA ON ((PRODUTOS_BARRA.CODIGO_BARRA = RDX_LININV.CODART))
	LEFT OUTER JOIN PRODUTOS ON (PRODUTOS.PRODUTO = PRODUTOS_BARRA.PRODUTO)
	WHERE RDX_CABINV.FECHALIQ >= CONVERT(DATETIME, '20060601', 112)  /* PARA NO COGER AŅOS ANTERIORES */
	AND RDX_CABINV.CARGADO IS NULL
	
	UPDATE RDX_CABINV SET
	       CARGADO = 1
    WHERE CARGADO IS NULL
END
go 

/*--------------- SQL ---------------*/

CREATE PROCEDURE RDX_P_CARGAR_VENTASEDI
AS
BEGIN
	INSERT INTO RDX_VENTASEDI (
	       NUMINF, CLAVE1, CLAVE2, CLAVE3, PERVENINI, NUMTALON, EANLUG,
           FILIAL, EANVEN, CODVEN, VENDEDOR, EANART, CODCOM, PRODUTO,
           DESC_PRODUTO, COR_PRODUTO, GRADE, TIPO_PRODUTO, GRUPO_PRODUTO,
           DESC_COLECAO, VALVEN, CANVEN, CANDEV, CANVENNET, CANESP )
	SELECT
	  RDX_CABVEN.NUMINF,
	  RDX_ARTVEN.CLAVE1,
	  RDX_ARTVEN.CLAVE2,
	  RDX_ARTVEN.CLAVE3,
	  RDX_LUGVEN.PERVENINI,
	  RDX_ARTVEN.NUMTALON,
	  RDX_LUGVEN.EANLUG,
	  FILIAL = ISNULL(FILIAIS.FILIAL, RDX_LUGVEN.EANLUG),
	  RDX_ARTVEN.EANVEN,
	  LOJA_VENDEDORES.VENDEDOR AS CODVEN,
	  VENDEDOR = ISNULL(LTRIM(RTRIM(LOJA_VENDEDORES.NOME_VENDEDOR)) + ' ' + LTRIM(RTRIM(LOJA_VENDEDORES.VENDEDOR_APELIDO)), RDX_ARTVEN.EANVEN),
	  RDX_ARTVEN.EANART,
	  RDX_ARTVEN.CODCOM,
	  produtos.PRODUTO,
	  ISNULL(produtos.DESC_PRODUTO, '*** ERROR REFERENCIA  **** LLAMAR AL CI') AS DESC_PRODUTO,
	  PRODUTOS_BARRA.COR_PRODUTO,
	  PRODUTOS_BARRA.GRADE,
	  produtos.TIPO_PRODUTO,
	  produtos.GRUPO_PRODUTO,
	  COLECOES.DESC_COLECAO,
	  RDX_ARTVEN.VALVEN,
	  RDX_ARTVEN.CANVEN,
	  RDX_ARTVEN.CANDEV,
	  RDX_ARTVEN.CANVENNET,
	  RDX_ARTVEN.CANESP
	FROM
	  RDX_ARTVEN
	  INNER JOIN RDX_LUGVEN ON (RDX_ARTVEN.CLAVE1 = RDX_LUGVEN.CLAVE1 AND RDX_ARTVEN.CLAVE2 = RDX_LUGVEN.CLAVE2)
	  INNER JOIN RDX_CABVEN ON (RDX_LUGVEN.CLAVE1 = RDX_CABVEN.CLAVE1)
	  left outer join RDX_FILIALES on (RDX_FILIALES.CODBARRA = RDX_LUGVEN.EANLUG)
	  left outer join FILIAIS on (FILIAIS.COD_FILIAL = RDX_FILIALES.CODFILIAL)
	  LEFT OUTER JOIN LOJA_VENDEDORES ON (LOJA_VENDEDORES.RG LIKE '%' + RDX_ARTVEN.EANVEN + '%')
	  LEFT OUTER JOIN PRODUTOS_BARRA ON ((PRODUTOS_BARRA.CODIGO_BARRA = RDX_ARTVEN.EANART) or (PRODUTOS_BARRA.CODIGO_BARRA = RDX_ARTVEN.CODCOM))
	  LEFT OUTER JOIN PRODUTOS on (produtos.PRODUTO = PRODUTOS_BARRA.PRODUTO)
	  LEFT OUTER JOIN COLECOES on (COLECOES.COLECAO = PRODUTOS.COLECAO)
	WHERE RDX_CABVEN.CARGADO IS NULL

	
	UPDATE RDX_CABVEN SET
	       CARGADO = 1
    WHERE CARGADO IS NULL
END
go

/*--------------- SQL ---------------*/

CREATE PROCEDURE RDX_P_SET_ULTIMOINVENTARIO
AS
BEGIN
     DECLARE @CENTRO VARCHAR(17),
             @CODIGO VARCHAR(12),
             @COLOR VARCHAR(10),
             @TALLA VARCHAR(8),
             @FECHA DATETIME,
             @UPDATECMD VARCHAR(255)
             
     DECLARE ASD CURSOR FOR
             SELECT RTRIM(CENTRO), RTRIM(CODIGO), RTRIM(COLOR), RTRIM(TALLA), FECHA
             FROM RDX_V_INVENTARIO_MAXFECHAS
     OPEN ASD
     FETCH NEXT FROM ASD INTO @CENTRO, @CODIGO, @COLOR, @TALLA, @FECHA

     IF @@ROWCOUNT >= 0
     BEGIN
	      WHILE @@FETCH_STATUS = 0
	      BEGIN
	           UPDATE RDX_INVENTARIOEDI SET ULTIMO_INVENTARIO=NULL
               WHERE CENTRO = @CENTRO AND CODIGO = @CODIGO AND COLOR = @COLOR AND TALLA = @TALLA

	           UPDATE RDX_INVENTARIOEDI SET ULTIMO_INVENTARIO=1
	           WHERE FECHA = CONVERT(VARCHAR, @FECHA, 112) AND CENTRO = @CENTRO AND CODIGO = @CODIGO AND COLOR = @COLOR AND TALLA = @TALLA AND TIPOCANT = 145
               
               FETCH NEXT FROM ASD INTO @CENTRO, @CODIGO, @COLOR, @TALLA, @FECHA
          END
     END
     CLOSE ASD
     DEALLOCATE ASD
END
go


/* borrar vistas */


IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_ALBARANES]'))
DROP VIEW [dbo].[RDX_V_ALBARANES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_HOJAS_DEVOLUCIONES]'))
DROP VIEW [dbo].[RDX_V_HOJAS_DEVOLUCIONES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_HOJAS_TRASPASOS]'))
DROP VIEW [dbo].[RDX_V_HOJAS_TRASPASOS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI_TRASPASO]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI_TRASPASO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_DEVOLUCIONES]'))
DROP VIEW [dbo].[RDX_V_DEVOLUCIONES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_CONTROL_DEVOLUCIONES]'))
DROP VIEW [dbo].[RDX_V_CONTROL_DEVOLUCIONES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_CONTROL_TRASPASOS]'))
DROP VIEW [dbo].[RDX_V_CONTROL_TRASPASOS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_CONTROL_RECEPCION_DESGLOSADO]'))
DROP VIEW [dbo].[RDX_V_CONTROL_RECEPCION_DESGLOSADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_STOCK_VARELA]'))
DROP VIEW [dbo].[RDX_V_STOCK_VARELA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_STOCK]'))
DROP VIEW [dbo].[RDX_V_STOCK]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_CONTROL_RECEPCION_ALBARANES]'))
DROP VIEW [dbo].[RDX_V_CONTROL_RECEPCION_ALBARANES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIO_STOCK_DESGLOSADO]'))
DROP VIEW [dbo].[RDX_V_INVENTARIO_STOCK_DESGLOSADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_CONTROL_INVENTARIO]'))
DROP VIEW [dbo].[RDX_V_CONTROL_INVENTARIO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASTERMINADAS]'))
DROP VIEW [dbo].[RDX_V_VENTASTERMINADAS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASPROCESO]'))
DROP VIEW [dbo].[RDX_V_VENTASPROCESO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASPROCESOPENDIENTES]'))
DROP VIEW [dbo].[RDX_V_VENTASPROCESOPENDIENTES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASEDI]'))
DROP VIEW [dbo].[RDX_V_VENTASEDI]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_REFERENCIA_GENERICA]'))
DROP VIEW [dbo].[RDX_V_REFERENCIA_GENERICA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI_DEVOLUCION_Y_TARA]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI_DEVOLUCION_Y_TARA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_TRASPASOS]'))
DROP VIEW [dbo].[RDX_V_TRASPASOS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_STOCK_VENTAS]'))
DROP VIEW [dbo].[RDX_V_STOCK_VENTAS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_STOCK_INVENTARIO]'))
DROP VIEW [dbo].[RDX_V_STOCK_INVENTARIO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_ALBARANES_PENDIENTES]'))
DROP VIEW [dbo].[RDX_V_ALBARANES_PENDIENTES]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_ULTIMO_INVENTARIO]'))
DROP VIEW [dbo].[RDX_V_ULTIMO_INVENTARIO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_STOCK_CALCULADO_DESGLOSADO]'))
DROP VIEW [dbo].[RDX_V_STOCK_CALCULADO_DESGLOSADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIO_STOCK]'))
DROP VIEW [dbo].[RDX_V_INVENTARIO_STOCK]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASEDI_ERRONEAS]'))
DROP VIEW [dbo].[RDX_V_VENTASEDI_ERRONEAS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_TRASPASO_ENTRADA]'))
DROP VIEW [dbo].[RDX_V_TRASPASO_ENTRADA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_TRASPASO_SALIDA]'))
DROP VIEW [dbo].[RDX_V_TRASPASO_SALIDA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_RECEPCION_AJUSTES_DESGLOSADO]'))
DROP VIEW [dbo].[RDX_V_RECEPCION_AJUSTES_DESGLOSADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASEDI_RESUELTAS]'))
DROP VIEW [dbo].[RDX_V_VENTASEDI_RESUELTAS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_TRASPASOS_AJUSTES_DESGLOSADO]'))
DROP VIEW [dbo].[RDX_V_TRASPASOS_AJUSTES_DESGLOSADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO]'))
DROP VIEW [dbo].[RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_CONTROL_RECEPCION]'))
DROP VIEW [dbo].[RDX_V_CONTROL_RECEPCION]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIO_MAXFECHAS]'))
DROP VIEW [dbo].[RDX_V_INVENTARIO_MAXFECHAS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_STOCK_CALCULADO]'))
DROP VIEW [dbo].[RDX_V_STOCK_CALCULADO]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI_TRASPASO_ENTRADA]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI_TRASPASO_ENTRADA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI_TRASPASO_SALIDA]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI_TRASPASO_SALIDA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_RECEPCION]'))
DROP VIEW [dbo].[RDX_V_RECEPCION]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_REFERENCIAS_RESUELTAS]'))
DROP VIEW [dbo].[RDX_V_REFERENCIAS_RESUELTAS]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI_RECEPCION]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI_RECEPCION]
go
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_INVENTARIOEDI_PESADA]'))
DROP VIEW [dbo].[RDX_V_INVENTARIOEDI_PESADA]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[RDX_V_VENTASEDI_PESADA]'))
DROP VIEW [dbo].[RDX_V_VENTASEDI_PESADA]
GO


