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

GO

--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_SEM_GERAR_FINANCEIRO_QTDE	WITH (NOLOCK)
CREATE VIEW [dbo].[V_PAINEL_NFE_EST_NF_ENT_SEM_GERAR_FINANCEIRO_QTDE] AS
SELECT EST_NF_ENT.CD_EMP, COUNT(EST_NF_ENT.CD_NF) AS QTDE_SEM_GERAR_FINANCEIRO
FROM EST_NF_ENT WITH (NOLOCK)
INNER JOIN GLB_MOV_OP ON EST_NF_ENT.CD_NT_MOV = GLB_MOV_OP.CD_MOV_OP
WHERE GLB_MOV_OP.GERA_DP_PG = 1
  AND IGNORAR_GERACAO_FINAN = 0
  AND EST_NF_ENT.FLAG_NOTA_INTEGRACAO <>1
  	AND NOT EXISTS (SELECT 
						PG_CRED_EST_NF_ENT.CD_NF 
					FROM      
						PG_CRED_EST_NF_ENT     INNER JOIN PG_CRED ON      
						PG_CRED_EST_NF_ENT.CD_EMP = PG_CRED.CD_EMP AND     
						PG_CRED_EST_NF_ENT.CD_FILIAL = PG_CRED.CD_FILIAL  AND     
						PG_CRED_EST_NF_ENT.NR_DP = PG_CRED.NR_DP AND     
						PG_CRED_EST_NF_ENT.ANO = PG_CRED.ANO 
					WHERE     
						PG_CRED_EST_NF_ENT.CD_EMP = EST_NF_ENT.CD_EMP AND     
						PG_CRED_EST_NF_ENT.CD_FILIAL = EST_NF_ENT.CD_FILIAL  AND     
						PG_CRED_EST_NF_ENT.CD_NF = EST_NF_ENT.CD_NF     
						AND PG_CRED.STS_DP <> 3) 
GROUP BY
EST_NF_ENT.CD_EMP