/****** Object:  View [dbo].[V_EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR]    Script Date: 06/19/2014 11:10:23 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR]'))
	BEGIN
		DROP VIEW [dbo].[V_EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR]
	END
	
GO
--SELECT * FROM V_EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR
CREATE VIEW V_EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR AS 
SELECT 
	CD_EMP, 
	DIA_SEMANA, 
	CD_FILIAL, 
	CD_ARV_MERC_LINHA,
	0 AS CD_FABRIC, 
	NULL AS DT_NAO_RESSUP, 
	0 AS CD_GRP_RES,
	'NAO GERAR RESSUPRIMENTO DIA DA SEMANA FILIAL\LINHA' AS DS_BLOQUEIO
FROM 
	EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR_DIA_SEMANA_PRC_FILIAL_LINHA
WHERE 
	DIA_SEMANA=DATEPART(DW,GETDATE())
UNION ALL
SELECT 
	CD_EMP, 
	DIA_SEMANA, 
	0 AS CD_FILIAL, 
	CD_ARV_MERC_LINHA,
	0 AS CD_FABRIC, 
	NULL AS DT_NAO_RESSUP, 
	0 AS CD_GRP_RES,
	'NAO GERAR RESSUPRIMENTO DIA DA SEMANA LINHA' AS DS_BLOQUEIO
FROM 
	EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR_LINHA_DIA_SEMANA
WHERE 
	DIA_SEMANA=DATEPART(DW,GETDATE())
UNION ALL
SELECT 
	CD_EMP, 
	DIA_SEMANA, 
	0 AS CD_FILIAL, 
	0 AS CD_ARV_MERC_LINHA, 
	CD_FABRIC, 
	NULL AS DT_NAO_RESSUP, 
	0 AS CD_GRP_RES,
	'NAO GERAR RESSUPRIMENTO DIA SEMANA FABRICANTE' AS DS_BLOQUEIO
FROM 
	EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR_FABRIC_DIA_SEMANA
WHERE 
	DIA_SEMANA=DATEPART(DW,GETDATE())
UNION ALL
SELECT 
	CD_EMP, 
	DIA_SEMANA, 
	CD_FILIAL, 
	0 AS CD_ARV_MERC_LINHA, 
	0 AS CD_FABRIC, 
	NULL AS DT_NAO_RESSUP, 
	0 AS CD_GRP_RES,
	'NAO GERAR RESSUPRIMENTO DIA SEMANA POR FILIAL' AS DS_BLOQUEIO
FROM 
	EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR_DIA_SEMANA_PRC_FILIAL
WHERE 
	DIA_SEMANA=DATEPART(DW,GETDATE())
UNION ALL
SELECT 
	CD_EMP, 
	0 AS DIA_SEMANA, 
	CD_FILIAL, 
	0 AS CD_ARV_MERC_LINHA, 
	0 AS CD_FABRIC, 
	DT_NAO_RESSUP, 
	0 AS CD_GRP_RES,
	'NAO GERAR RESSUPRIMENTO DATA POR FILIAL' AS DS_BLOQUEIO
FROM 
	EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR_FILIAL
WHERE
	DT_NAO_RESSUP=CONVERT(CHAR(10),GETDATE(),112)
UNION ALL
SELECT 
	CD_EMP, 
	0 AS DIA_SEMANA, 
	0 AS CD_FILIAL, 
	0 AS CD_ARV_MERC_LINHA, 
	0 AS CD_FABRIC, 
	DT_NAO_RESSUP, 
	CD_GRP_RES ,
	'NAO GERAR RESSUPRIMENTO DATA POR GRUPO DE RESSUPRIMENTO' AS DS_BLOQUEIO
FROM 
	EST_ARV_GRP_RESSUPRIMENTO_NAO_EXECUTAR
WHERE
	DT_NAO_RESSUP=CONVERT(CHAR(10),GETDATE(),112)