/****** Object:  StoredProcedure [dbo].[P_GERA_DUP_PAGAR_GRP_ECONOMICO_EXECUTE_ALL]    Script Date: 02/06/2014 15:52:48 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_GERA_DUP_PAGAR_GRP_ECONOMICO_EXECUTE_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_GERA_DUP_PAGAR_GRP_ECONOMICO_EXECUTE_ALL]
GO
GO

/****** Object:  StoredProcedure [dbo].[P_PG_CRED_GERAR_DUPLICATA_GRP_ECONOMICO_EXECUTE_ALL]    Script Date: 02/06/2014 15:52:48 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_PG_CRED_GERAR_DUPLICATA_GRP_ECONOMICO_EXECUTE_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_PG_CRED_GERAR_DUPLICATA_GRP_ECONOMICO_EXECUTE_ALL]
GO
GO
GO
--EXEC P_PG_CRED_GERAR_DUPLICATA_GRP_ECONOMICO_EXECUTE_ALL 2014
CREATE PROCEDURE [dbo].[P_PG_CRED_GERAR_DUPLICATA_GRP_ECONOMICO_EXECUTE_ALL] @ANO INT=0 AS 

IF @ANO=0
begin
	SET @ANO=YEAR(GETDATE())
end

DECLARE @CD_FILIAL  AS INT
DECLARE ljsCpEco CURSOR 
	FAST_FORWARD FOR 
	SELECT 
		CD_FILIAL 
	FROM 
		PRC_FILIAL
	ORDER BY
		CD_FILIAL 
		
OPEN ljsCpEco
FETCH NEXT FROM ljsCpEco INTO @CD_FILIAL

WHILE @@FETCH_STATUS=0
  begin
	PRINT	'  Gerando financeiro da filial ' + convert(varchar(5), @CD_FILIAL ) + 
			' (' + CONVERT(VARCHAR(8), GETDATE(), 114) + ')...'
		EXECUTE P_PG_CRED_GERAR_DUPLICATA_GRP_ECONOMICO @CD_FILIAL,@ANO;
	FETCH NEXT FROM ljsCpEco INTO @CD_FILIAL
  end
PRINT 'Concluído.'
CLOSE ljsCpEco
DEALLOCATE ljsCpEco