/****** Object:  View [dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_NAO_ENCONTRADO_ANALITICO]    Script Date: 03/10/2018 11:00:00 ******/ 
IF EXISTS (SELECT * 
           FROM   SYS.VIEWS 
           WHERE  OBJECT_ID = 
      Object_id(N'[dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_NAO_ENCONTRADO_ANALITICO]')) 
  DROP VIEW [dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_NAO_ENCONTRADO_ANALITICO] 

GO 

--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_DANFE_NAO_ENCONTRADO_ANALITICO 
CREATE VIEW V_PAINEL_NFE_EST_NF_ENT_DANFE_NAO_ENCONTRADO_ANALITICO  
AS
SELECT EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.CD_FILIAL AS filialOrigemId,
       EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.CD_FORN AS fornecedorId,
       RZ_FORN AS fornecedorNome,
       EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.NR_NF AS numeroNfe,
       EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.NR_AUTORIZADOR AS autorizador,
       EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.DT_CAD AS data,
       EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.STS_IMP AS statusDevolucao,
       EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.MSG_SEFAZ AS msgSefaz,
	   DS_TP as ClassificacaoFornecedor
FROM EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO
INNER JOIN PG_FORN ON EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.CD_EMP = PG_FORN.CD_EMP
AND EST_NF_ENT_DANFE_PROVISORIO_NAO_ENCONTRADO.CD_FORN = PG_FORN.CD_FORN
INNER JOIN PG_TP_FORN ON
PG_FORN.CD_TP_FORN = PG_TP_FORN.CD_TP_FORN
