/****** Object:  View [dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_PROVISORIO_CHECKIN_ENTRADA_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_PROVISORIO_CHECKIN_ENTRADA_ANALITICO]')) 
  DROP VIEW [dbo].[V_PAINEL_NFE_EST_NF_ENT_DANFE_PROVISORIO_CHECKIN_ENTRADA_ANALITICO] 

GO 

--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_DANFE_PROVISORIO_CHECKIN_ENTRADA_ANALITICO 
CREATE VIEW V_PAINEL_NFE_EST_NF_ENT_DANFE_PROVISORIO_CHECKIN_ENTRADA_ANALITICO  
AS
SELECT EST_NF_ENT_DANFE_PROVISORIO.CD_FILIAL AS filialOrigemId,
       EST_NF_ENT_DANFE_PROVISORIO.DT_EMIS_NF AS data,
       EST_NF_ENT_DANFE_PROVISORIO.CD_CTR AS codigoControle,
       EST_NF_ENT_DANFE_PROVISORIO.NR_NF AS numeroNfe,
       EST_NF_ENT_DANFE_PROVISORIO.CD_FORN AS fornecedorId,
       PG_FORN.NM_FANT AS fornecedorNome,
       EST_NF_ENT_DANFE_PROVISORIO.VLR_NF AS valor
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 EST_NF_ENT_DANFE_PROVISORIO_CHECKIN_ENTRADA ON EST_NF_ENT_DANFE_PROVISORIO.CD_CTR = EST_NF_ENT_DANFE_PROVISORIO_CHECKIN_ENTRADA.CD_CTR
LEFT OUTER JOIN EST_NF_ENT_DANFE_PROVISORIO_ERROS_VALIDACAO ON EST_NF_ENT_DANFE_PROVISORIO.CD_CTR = EST_NF_ENT_DANFE_PROVISORIO_ERROS_VALIDACAO.CD_CTR
WHERE EST_NF_ENT_DANFE_PROVISORIO.CD_EMP=1
  AND EST_NF_ENT_DANFE_PROVISORIO_ERROS_VALIDACAO.CD_CTR IS NULL