/****** Object:  View [dbo].[V_BI_MOVIMENTO_ESTOQUE]    Script Date: 04/11/2013 10:05:53 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_BI_MOVIMENTO_ESTOQUE]'))
DROP VIEW [dbo].[V_BI_MOVIMENTO_ESTOQUE]
GO
--SELECT * FROM V_BI_MOVIMENTO_ESTOQUE
CREATE VIEW V_BI_MOVIMENTO_ESTOQUE 
AS
SELECT
	p.CD_FILIAL as Filial,
	f.NM_FILIAL_LISTA AS NmFilial,
	p.CD_PROD as CodProduto,
	a.DS_PROD AS DsProduto,
	p.QT_EST AS QtEstoque,
	(p.QT_EST*p.VLR_CUSTO_MD) as VlrCustoMedio,
	(p.QT_EST*P.VLR_CUSTO) as VlrCusto,
	(p.QT_EST*P.VLR_CUSTO_GER) as VlrCustoGer,
	p.MEDIAF AS MediaF,
	s.DS_SIGLA AS CurvaABC,
	QTDE_FINANCIADO AS QtFinanciado,
	QTDE_LIMITADOR AS QtLimitador,
	QTDE_FACEAMENTO AS QtFaceamento,
	DS_ARV_MERC_CATEG as Categoria,
	DS_ARV_MERC_DEPTO as Departamento,
	DS_ARV_MERC_AREA_ATEND as AreaAtendimento,
	DS_ARV_MERC_FAMILIA  as Familia,
	DS_ARV_MERC_MIX as Mix,
	DS_ARV_MERC_MTZ_BCG as MatrizBCG,
	DS_ARV_MERC_PAPEL as Papel,
	DS_ARV_MERC_EQUI as Equivalencia,
	DS_ARV_MERC_CONSUMO as Consumo,
	DS_ARV_MERC_CLASSIFICACAO as Classificacao,
	DS_APRES as Apresentacao,
	DS_MC as Marca,
	a.DS_GRP_EXPO as GrupoExposicao,
	A.TIPO_COMPRA  as TipoCompra,
	a.DS_ARV_MERC_LINHA as Linha,
	a.NM_FABRIC as Fabricante,
	a.DS_GENERO as Genero,
	a.DS_ARV_MERC_SEG as Segmento
FROM
	EST_PROD_CPL p INNER JOIN V_EST_PROD_ARV_MERCADOLOGICA a ON
	p.CD_EMP = a.CD_EMP AND
	p.CD_PROD = a.CD_PROD
	INNER JOIN EST_PROD_CURVA_SIGLA	 S ON
	p.CD_EMP = S.CD_EMP AND
	p.CD_SIGLA = S.CD_SIGLA
	INNER JOIN PRC_FILIAL f  ON
	p.CD_EMP = f.CD_EMP AND
	p.CD_FILIAL = f.CD_FILIAL 
where
	a.FLAG_LINHA_NAO_FAZ_BALANCO=0