/****** Object:  View [dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_IMPORTADO_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_IMPORTADO_ANALITICO]')) 
  DROP VIEW [dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_IMPORTADO_ANALITICO] 

GO 

--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_DANFE_IMPORTADO_ANALITICO 
CREATE VIEW V_PAINEL_NFE_EST_NF_ENT_DANFE_IMPORTADO_ANALITICO  
AS
SELECT EST_NF_ENT_DANFE_PROVISORIO.CD_CTR AS codigoControle,
       EST_NF_ENT_DANFE_PROVISORIO.CD_FILIAL filialOrigemId,
       EST_NF_ENT_DANFE_PROVISORIO.CD_FORN AS fornecedorId,
       PG_FORN.NM_FANT AS fornecedorNome,
       EST_NF_ENT_DANFE_PROVISORIO.NR_NF AS numeroNfe,
       EST_NF_ENT_DANFE_PROVISORIO.DT_EMIS_NF AS data,
       EST_NF_ENT_DANFE_PROVISORIO.VLR_NF AS valor,
	   DS_TP as ClassificacaoFornecedor
FROM EST_NF_ENT_DANFE_PROVISORIO
INNER JOIN EST_NF_ENT_DANFE_PROVISORIO_PENDENTE ON EST_NF_ENT_DANFE_PROVISORIO.CD_CTR = EST_NF_ENT_DANFE_PROVISORIO_PENDENTE.CD_CTR
INNER JOIN PG_FORN ON EST_NF_ENT_DANFE_PROVISORIO.CD_EMP = PG_FORN.CD_EMP
AND EST_NF_ENT_DANFE_PROVISORIO.CD_FORN = PG_FORN.CD_FORN
INNER JOIN PRC_FILIAL ON EST_NF_ENT_DANFE_PROVISORIO.CD_EMP = PRC_FILIAL.CD_EMP
AND EST_NF_ENT_DANFE_PROVISORIO.CD_FILIAL = PRC_FILIAL.CD_FILIAL
INNER JOIN EST_NF_ENT_NFE_FORN_VALID ON EST_NF_ENT_DANFE_PROVISORIO.CD_EMP = EST_NF_ENT_NFE_FORN_VALID.CD_EMP
AND EST_NF_ENT_DANFE_PROVISORIO.CD_FILIAL = EST_NF_ENT_NFE_FORN_VALID.CD_FILIAL
AND EST_NF_ENT_DANFE_PROVISORIO.NR_NF = EST_NF_ENT_NFE_FORN_VALID.NR_NF
AND EST_NF_ENT_DANFE_PROVISORIO.CD_FORN = EST_NF_ENT_NFE_FORN_VALID.CD_FORN
INNER JOIN PG_TP_FORN ON
PG_FORN.CD_TP_FORN = PG_TP_FORN.CD_TP_FORN
WHERE VALIDACAO IN (1, 4)