/****** Object:  StoredProcedure [dbo].[P_EST_NF_ENT_CORRIGE_CFOP_ALL]    Script Date: 02/11/2014 18:34:05 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_EST_NF_ENT_CORRIGE_CFOP_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_EST_NF_ENT_CORRIGE_CFOP_ALL]
GO
GO 
--P_EST_NF_ENT_CORRIGE_CFOP_ALL 1,'2017-09-01','2017-10-01'
CREATE PROCEDURE [dbo].[P_EST_NF_ENT_CORRIGE_CFOP_ALL] (@CD_EMP INT=1, 
														@DT_INI DATETIME, 
														@DT_FIM DATETIME)
WITH ENCRYPTION
AS
begin
SET NOCOUNT ON
DECLARE @CD_FILIAL INT
DECLARE CorrecaoCFOPNotaEntrada CURSOR FAST_FORWARD FOR 
	SELECT  
		CD_FILIAL
	FROM
		PRC_FILIAL
			
OPEN CorrecaoCFOPNotaEntrada
FETCH NEXT FROM CorrecaoCFOPNotaEntrada INTO @CD_FILIAL
	WHILE @@FETCH_STATUS=0
	  begin

	    PRINT 'Filial.: ' + CONVERT(VARCHAR, @CD_FILIAL) + ' ' + CONVERT(VARCHAR, GETDATE (),108)
		
		EXEC P_EST_NF_ENT_CORRIGE_CFOP @CD_EMP, @CD_FILIAL, @DT_INI, @DT_FIM,1

		FETCH NEXT FROM CorrecaoCFOPNotaEntrada INTO @CD_FILIAL
	end
PRINT 'Concluido.'
CLOSE CorrecaoCFOPNotaEntrada;
DEALLOCATE CorrecaoCFOPNotaEntrada;
end
