ALTER TABLE [Alphaind].[dbo].[TiposdeGrade] ADD id int NULL;
--preencha os id da tabela de grade

ALTER DATABASE [Alphaind] SET COMPATIBILITY_LEVEL = 130


---------outro
USE [AlphaInd]
GO

/****** Object:  View [dbo].[viewEstoqueAlmox]    Script Date: 01/07/2023 19:16:53 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE OR ALTER view [dbo].[viewEstoqueAlmox]
as
  select a.Codigo, ai.Cor, a.Und,
  (ai.Entradas-ai.Saida) as Estoque
  from Almox a inner join Almox_Itens ai
  on a.Codigo=ai.Almox
GO

---------outro
USE [AlphaInd]
GO

/****** Object:  View [dbo].[viewEstoqueLojas]    Script Date: 01/07/2023 19:29:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE OR ALTER view [dbo].[viewEstoqueLojas]
as
  select plg.Loja, l.Fantasia as NomeLoja, 
  plg.Produto, plg.CodigodaCor,
  (plg.Ent01-plg.Sai01) as Tam01,
  (plg.Ent02-plg.Sai02) as Tam02,
  (plg.Ent03-plg.Sai03) as Tam03,
  (plg.Ent04-plg.Sai04) as Tam04,
  (plg.Ent05-plg.Sai05) as Tam05,
  (plg.Ent06-plg.Sai06) as Tam06,
  (plg.Ent07-plg.Sai07) as Tam07,
  (plg.Ent08-plg.Sai08) as Tam08,
  (plg.Ent09-plg.Sai09) as Tam09,
  (plg.Ent10-plg.Sai10) as Tam10
  from Produtos_LojasGrade plg inner join Lojas l
  on plg.Loja=l.Codigo
GO



---------outro
/****** Object:  View [dbo].[viewEstoqueLojas]    Script Date: 01/07/2023 19:29:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE OR ALTER view [dbo].[ViewAtacadoProdutosSku]
as
select 1 Loja, '' as NomeLoja, 
  plg.Produto, plg.cor CodigodaCor,
  (plg.Ent01-plg.Sai01) as Tam01,
  (plg.Ent02-plg.Sai02) as Tam02,
  (plg.Ent03-plg.Sai03) as Tam03,
  (plg.Ent04-plg.Sai04) as Tam04,
  (plg.Ent05-plg.Sai05) as Tam05,
  (plg.Ent06-plg.Sai06) as Tam06,
  (plg.Ent07-plg.Sai07) as Tam07,
  (plg.Ent08-plg.Sai08) as Tam08,
  (plg.Ent09-plg.Sai09) as Tam09,
  (plg.Ent10-plg.Sai10) as Tam10
  from Produtos_Item plg
  where (plg.Ent01-plg.Sai01) +
  (plg.Ent02-plg.Sai02)+
  (plg.Ent03-plg.Sai03)+
  (plg.Ent04-plg.Sai04)+
  (plg.Ent05-plg.Sai05)+
  (plg.Ent06-plg.Sai06)+
  (plg.Ent07-plg.Sai07)+
  (plg.Ent08-plg.Sai08)+
  (plg.Ent09-plg.Sai09)+
  (plg.Ent10-plg.Sai10) > 0
GO
