USE [TryNFeOnline]
GO

ALTER TABLE [dbo].[Fatura] ADD 
[idGNREDados] [int] NULL
GO
CREATE TABLE [dbo].[GNREStatus]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idGNREDados] [int] NOT NULL,
	[servico] [int] NOT NULL,
	[descricao] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
	[dataHora] [datetime] NULL,
	CONSTRAINT [PK_GNREStatus] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GNREItemValor]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idGNREItem] [int] NOT NULL,
	[tipo] [int] NULL,
	[valor] [decimal] (18,4) NOT NULL,
	CONSTRAINT [PK_GNREItemValor] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GNREItemCampoAdicional]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idGNREItem] [int] NOT NULL,
	[idnObrigatorio] [bit] NOT NULL,
	[codigo] [int] NULL,
	[valor] [varchar] (200) COLLATE Latin1_General_CI_AS NULL,
	[tipoCampo] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[titulo] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	CONSTRAINT [PK_GNREItemCampoAdicional] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ParametrizacaoAliquotas]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[identificador] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[ufDestino] [varchar] (4) COLLATE Latin1_General_CI_AS NULL,
	[aliquota] [decimal] (18,4) NULL,
	[ncm] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	CONSTRAINT [PK_ParametrizacaoAliquotas] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GNREItem]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idGNREDados] [int] NOT NULL,
	[receita] [varchar] (10) COLLATE Latin1_General_CI_AS NULL,
	[receitaDescricao] [varchar] (200) COLLATE Latin1_General_CI_AS NULL,
	[detalhamentoCodigo] [varchar] (10) COLLATE Latin1_General_CI_AS NULL,
	[detalhamentoDescricao] [varchar] (500) COLLATE Latin1_General_CI_AS NULL,
	[documentoOrigemTipo] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[documentoOrigemDescricao] [varchar] (100) COLLATE Latin1_General_CI_AS NULL,
	[documentoOrigemNumero] [varchar] (100) COLLATE Latin1_General_CI_AS NULL,
	[produtoCodigo] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[produtoDescricao] [varchar] (200) COLLATE Latin1_General_CI_AS NULL,
	[refPeriodo] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[refMes] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[refAno] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[refParcela] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[dataVencimento] [date] NULL,
	[convenio] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[idDestinatario] [int] NULL,
	[destinatarioCpfCnpj] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	[destinatarioIE] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	[destinatarioRazaoSocial] [varchar] (60) COLLATE Latin1_General_CI_AS NULL,
	[idDestinatarioCidade] [int] NULL,
	[numeroControle] [varchar] (30) COLLATE Latin1_General_CI_AS NULL,
	[numeroControleFecp] [varchar] (30) COLLATE Latin1_General_CI_AS NULL,
	[valorExigido] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[idNotaFiscal] [int] NULL,
	CONSTRAINT [PK_GNREItem] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[GNREDados]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idFilial] [int] NOT NULL,
	[UFFavorecida] [varchar] (5) COLLATE Latin1_General_CI_AS NOT NULL,
	[tipoGNRE] [int] NOT NULL,
	[inscricaoEstadualUF] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	[valorGNRE] [decimal] (18,4) NULL,
	[dataPagamento] [date] NULL,
	[ambiente] [int] NOT NULL,
	[dataGeracao] [datetime] NOT NULL,
	[codigoStatus] [int] NULL,
	[descricaoStatus] [varchar] (300) COLLATE Latin1_General_CI_AS NULL,
	[numeroRecibo] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	[dataHoraRecibo] [datetime] NULL,
	[tempoEstimadoProc] [int] NULL,
	[situacaoGuia] [int] NULL,
	[representacaoNumerica] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[nossoNumero] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[linhaDigitavel] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[codigoBarras] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[pdfGuia] [varbinary] (max) NULL,
	[arquivoPagamento] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
	[idnPago] [bit] NOT NULL,
	[idnExigeContribuinteEmitente] [bit] NOT NULL,
	CONSTRAINT [PK_GNREDados] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[EmitenteIEUF]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idEmitente] [int] NULL,
	[uf] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[inscricaoEstadual] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[dataInclusao] [datetime] NOT NULL,
	[idnInativo] [bit] NOT NULL,
	[convenio] [varchar] (30) COLLATE Latin1_General_CI_AS NULL,
	CONSTRAINT [PK_EmitenteIEEstados] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[GNREItem] ADD CONSTRAINT [FK_GNREItem_cidade] FOREIGN KEY
	(
		[idDestinatarioCidade]
	)
	REFERENCES [dbo].[cidade]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[GNREItem] ADD CONSTRAINT [FK_GNREItem_GNREDados] FOREIGN KEY
	(
		[idGNREDados]
	)
	REFERENCES [dbo].[GNREDados]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[GNREItem] ADD CONSTRAINT [FK_GNREItem_parceiro] FOREIGN KEY
	(
		[idDestinatario]
	)
	REFERENCES [dbo].[parceiro]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[EmitenteIEUF] ADD CONSTRAINT [FK_EmitenteIEEstados_emitente] FOREIGN KEY
	(
		[idEmitente]
	)
	REFERENCES [dbo].[emitente]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[GNREItemCampoAdicional] ADD CONSTRAINT [FK_GNREItemCampoAdicional_GNREItem] FOREIGN KEY
	(
		[idGNREItem]
	)
	REFERENCES [dbo].[GNREItem]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[GNREItemValor] ADD CONSTRAINT [FK_GNREItemValor_GNREItem] FOREIGN KEY
	(
		[idGNREItem]
	)
	REFERENCES [dbo].[GNREItem]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[GNREStatus] ADD CONSTRAINT [FK_GNREStatus_GNREDados] FOREIGN KEY
	(
		[idGNREDados]
	)
	REFERENCES [dbo].[GNREDados]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[GNREDados] ADD CONSTRAINT [FK_GNREDados_emitente] FOREIGN KEY
	(
		[idFilial]
	)
	REFERENCES [dbo].[emitente]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[Fatura] ADD CONSTRAINT [FK_Fatura_GNREDados] FOREIGN KEY
	(
		[idGNREDados]
	)
	REFERENCES [dbo].[GNREDados]
	(
		[id]
	)
GO
SET IDENTITY_INSERT [dbo].[Telas] ON
GO
INSERT [dbo].[Telas] ([id], [descricao], [controle], [idnPermiteAbrirVarias]) VALUES (396, N'Consultar GNRE', N'Cadastros.ucConsGNRE, Cadastros, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', 0)
GO
INSERT [dbo].[Telas] ([id], [descricao], [controle], [idnPermiteAbrirVarias]) VALUES (397, N'Consultar IE outra UF', N'Cadastros.ucConsEmitenteInscricaoUF, Cadastros, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', 0)
GO
INSERT [dbo].[Telas] ([id], [descricao], [controle], [idnPermiteAbrirVarias]) VALUES (398, N'Cadastrar IE outra UF', N'Cadastros.ucCadEmitenteInscricaoUF, Cadastros, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', 0)
GO
SET IDENTITY_INSERT [dbo].[Telas] OFF
GO
SET IDENTITY_INSERT [dbo].[MenuItens] ON 
GO
INSERT [dbo].[MenuItens] ([id], [idMenu], [descricao], [idTela], [idMenuItemPai], [ordem], [idnVisivel], [md5], [imagem]) VALUES (514, 1, N'-', null, 200, 15, 1, NULL, NULL)
GO
INSERT [dbo].[MenuItens] ([id], [idMenu], [descricao], [idTela], [idMenuItemPai], [ordem], [idnVisivel], [md5], [imagem]) VALUES (515, 1, N'Consultar GNRE', 396, 200, 16, 1, NULL, NULL)
GO
INSERT [dbo].[MenuItens] ([id], [idMenu], [descricao], [idTela], [idMenuItemPai], [ordem], [idnVisivel], [md5], [imagem]) VALUES (516, 2, N'-', null, 468, 8, 1, NULL, NULL)
GO
INSERT [dbo].[MenuItens] ([id], [idMenu], [descricao], [idTela], [idMenuItemPai], [ordem], [idnVisivel], [md5], [imagem]) VALUES (517, 2, N'Consultar GNRE', 396, 468, 9, 1, NULL, NULL)
GO
SET IDENTITY_INSERT [dbo].[MenuItens] OFF
GO
SET IDENTITY_INSERT [MenuLateralItens] ON
GO
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (441, 1, '-', null, 5, null, 4)
GO
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (442, 1, 'Consultar IE outras UFs', 397, 5, 'search-2_32.png', 5)
GO
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (443, 1, 'Cadastrar IE outra UF', 398, 5, 'brasil_32.png', 6)
GO
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (444, 2, '-', null, 5, null, 4)
GO
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (445, 2, 'Consultar IE outras UFs', 397, 5, 'search-2_32.png', 5)
GO
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (446, 2, 'Cadastrar IE outra UF', 398, 5, 'brasil_32.png', 6)
GO
SET IDENTITY_INSERT [MenuLateralItens] OFF
GO
INSERT INTO VERSAO(VERSAO, VERSAOATUALIZACAO, DATAATUALIZACAO, REVISAO) VALUES(508, 766, GETDATE(),1);