
/*------ ATD 425549 ------*/
IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS T WHERE T.NAME = 'ITEM_PEDIDO_ECOMMERCE' AND T.XTYPE = 'U')
begin
	CREATE TABLE dbo.ITEM_PEDIDO_ECOMMERCE(
		ID INT IDENTITY NOT NULL,
		NUMPED INT NOT NULL,
		NUMPEDECOMMERCE VARCHAR(100) NOT NULL,
		CODIGOFRANQUIA VARCHAR(3) NOT NULL,
		CODIGOVARIACAO INT NOT NULL,
		CODIGOPRODUTO INT NOT NULL,
		CODPRO CHAR(5) NOT NULL,
		QUANTIDADE DECIMAL(15,3) NOT NULL,
		PRECOUNITARIO DECIMAL(15,5) NOT NULL)

	ALTER TABLE ITEM_PEDIDO_ECOMMERCE ADD CONSTRAINT PK_ITEM_PEDIDO_ECOMMERCE PRIMARY KEY (ID)

	CREATE INDEX ITEM_PEDIDO_ECOMMERCE_IDX1 ON ITEM_PEDIDO_ECOMMERCE(NUMPED)
	CREATE INDEX ITEM_PEDIDO_ECOMMERCE_IDX2 ON ITEM_PEDIDO_ECOMMERCE(NUMPEDECOMMERCE)
end
go

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'ITEMCLICOMPLEMENTO' AND COLUMN_NAME = 'IdPedidoOrigem')
begin
ALTER TABLE ITEMCLICOMPLEMENTO ADD IdPedidoOrigem VARCHAR(100)
end

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'ITEMCLICOMPLEMENTO' AND COLUMN_NAME = 'CODIGOFRANQUIAECOMMERCE')
begin
ALTER TABLE ITEMCLICOMPLEMENTO ADD CODIGOFRANQUIAECOMMERCE VARCHAR(3)
end

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'PEDIDO_ECOMMERCE' AND COLUMN_NAME = 'GRUPO')
begin
ALTER TABLE PEDIDO_ECOMMERCE ADD GRUPO VARCHAR(50)
end

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'NOTA_FISCAL_ECOMMERCE' AND COLUMN_NAME = 'NUMPEDECOMMERCE')
begin
ALTER TABLE NOTA_FISCAL_ECOMMERCE ADD NUMPEDECOMMERCE VARCHAR(100)
end

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'NOTA_FISCAL_ECOMMERCE' AND COLUMN_NAME = 'CODIGOFRANQUIA')
begin
ALTER TABLE NOTA_FISCAL_ECOMMERCE ADD CODIGOFRANQUIA VARCHAR(3)
end