USE [TryNFeOnline]
GO

ALTER TABLE [dbo].[AutorizacaoSupervisor] ADD 
[idnCondicaoPagamentoIncompativelValor] [bit] NULL,
[dscCondicaoPagamentoPermitida] [varchar] (1000) COLLATE Latin1_General_CI_AS NULL,
[idnFormaPagamentoIncompativelValor] [bit] NULL,
[dscFormaPagamentoPermitida] [varchar] (1000) COLLATE Latin1_General_CI_AS NULL
GO
ALTER TABLE [dbo].[configuracoes] ADD 
[mensagemEmailPrestacaoServicoDesacordo] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
[idnBloquearProdutosSemEstoquePedido] [bit] NULL
GO
CREATE TABLE [dbo].[AutorizacaoSupervisorParametros]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[valorInicial] [decimal] (18,4) NULL,
	[valorFinal] [decimal] (18,4) NULL,
	[idCondicaoPagamento] [int] NULL,
	[idFormaPagamento] [int] NULL,
	CONSTRAINT [PK_AutorizacaoSupervisorParametros] PRIMARY KEY CLUSTERED
	(
		[id] ASC
	) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ctePrestacaoDesacordo]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idFilial] [int] NOT NULL,
	[chaveCTe] [varchar] (50) COLLATE Latin1_General_CI_AS NULL,
	[numero] [int] NULL,
	[cnpjEmissor] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	[xObs] [varchar] (300) COLLATE Latin1_General_CI_AS NULL,
	[tpAmb] [int] NULL,
	[cStat] [varchar] (5) COLLATE Latin1_General_CI_AS NULL,
	[xMotivo] [varchar] (500) COLLATE Latin1_General_CI_AS NULL,
	[dataRegEvento] [datetime] NULL,
	[nProt] [varchar] (20) COLLATE Latin1_General_CI_AS NULL,
	[xmlEnvio] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
	[xmlRetorno] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
	[xmlDistribuicao] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
	[idnEmailEnviado] [bit] NOT NULL,
	[enderecoEmail] [varchar] (200) COLLATE Latin1_General_CI_AS NULL,
	[statusEmail] [varchar] (max) COLLATE Latin1_General_CI_AS NULL,
	[dataInclusao] [datetime] NULL,
	CONSTRAINT [PK_ctePrestacaoDesacordo] 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].[DashboardRestricoes]
(
	[id] [int] IDENTITY (1,1) NOT NULL,
	[idDashboard] [int] NOT NULL,
	[idOperador] [int] NOT NULL,
	CONSTRAINT [PK_DashboardRestricoes] 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 PROCEDURE [dbo].[TRYNFE_OBTERNOTAS]
  (
	-- Add the parameters for the stored procedure here
	@SERVICO_IN int
   )	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	declare @Resultado TABLE
	(
		NOTA_ID int,
		SERVICO int,
		NUM_RECIBO varchar(30),
		TP_AMB int,
		CODFILIAL int,
		CUF int,
		TP_EMIS int,
		idnEmiteNF bit,
		idnEmiteCte bit,
		idnEmiteMdfe bit,
		idnEmiteNFSe bit,
		idnEmiteNFCe bit,
		idnEmiteMDe bit,
		idnEmiteCTeOS bit,
		PADRAO_NFSe varchar(50),
		idnNovaVersao bit,
		versaoNFe int
	)
	
	if ((@SERVICO_IN = 0) or (@SERVICO_IN = 1)) 
	begin
				/*NOTA_ID int,
		SERVICO int,
		NUM_RECIBO varchar(30),
		TP_AMB int,
		CODFILIAL int,
		CUF int,
		TP_EMIS int*/
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 1 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, nf.NFSePadrao as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id   
		where (nf.nfeAcao = 1)--Enviar Nota
		and   ((nf.idnEmiteNF = 1) or (nf.idnEmiteCte = 1) or (nf.idnEmiteCTeOS = 1) or (nf.idnEmiteMDFe = 1) or (nf.idnEmiteNFSe = 1) or (nf.idnEmiteNFCe = 1))

		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 21 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id   
		where (nf.nfeAcao = 21) --EPEC
		and   ((nf.idnEmiteNF = 1) or (nf.idnEmiteCte = 1) or (nf.idnEmiteMDFe = 1) or (nf.idnEmiteNFCe = 1))
				
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 2 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, nf.NFSePadrao as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id 
		where (nf.nfeAcao = 2) --Cancelar Nota
		and   ((nf.nfeCstat = 100) or (nf.nfeCstat = 150))
		and   ((nf.idnEmiteNF = 1) or (nf.idnEmiteCte = 1) or (nf.idnEmiteCTeOS = 1) or (nf.idnEmiteMDFe = 1) or (nf.idnEmiteNFSe = 1) or (nf.idnEmiteNFCe = 1))
		
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 6 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, nf.NFSePadrao as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id 		
		where (nf.nfeAcao = 6) --Verifica situacao da nfe
		and   ((nf.idnEmiteNF = 1) or (nf.idnEmiteCte = 1) or (nf.idnEmiteCTeOS = 1) or (nf.idnEmiteMDFe = 1) or (nf.idnEmiteNFSe = 1) or (nf.idnEmiteNFCe = 1))
		
		INSERT INTO @Resultado
		select ni.id as NOTA_ID, 3 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ni.idemitente as CODFILIAL, null as CUF, null as TP_EMIS, ni.idnEmiteNF, ni.idnEmiteCte, 0, 0, ni.idnEmiteNFCe, 0, ni.idnEmiteCTeOS, null as PADRAO_NFSe, 1, 4
		from inutilizacao ni
		where (ni.cstat is null) -- Se algum status ja foi definido, indica que o servico ja obteve uma resposta...
						
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 8 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, 0, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id   
		where (nf.nfeAcao = 100)    --Notas Recebidas
		and   (nf.idnEmiteNF = 0)
		
		INSERT INTO @Resultado
		select cc.id as NOTA_ID, 9 as SERVICO, null as NUM_RECIBO, nf.nfeTpAmb as TP_AMB, ne.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from nfCCe cc --Carta Correcao
		inner join notafiscal nf on nf.id = cc.idNotaFiscal
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id
		where (cc.cStat is null)
		
		INSERT INTO @Resultado
		select ev.id as NOTA_ID, 9 as SERVICO, null as NUM_RECIBO, nf.nfeTpAmb as TP_AMB, ne.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from NFEvento ev --Carta correcao
		inner join notafiscal nf on nf.id = ev.idNotaFiscal
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id
		where (ev.Acao = 1)

		INSERT INTO @Resultado
		select pd.id as NOTA_ID, 10 as SERVICO, null, pd.tpAmb, pd.idFilial, null, null, 0, 1, 0, 0, 0, 0, 0, null, 0, 4
		from ctePrestacaoDesacordo pd --Prestacao de Servico em Desacordo CTe
		where (pd.cStat is null)
		
		INSERT INTO @Resultado
		select condutor.id as NOTA_ID, 11 as SERVICO, null as NUM_RECIBO, nf.nfeTpAmb as TP_AMB, ne.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from mdfeInclusaoCondutor condutor
		inner join notafiscal nf on nf.id = condutor.idNotaFiscal
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id
		where (condutor.cStat is null) --Evento de Inclusao de Condutor MDFe
		
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 12 as SERVICO, null as NUM_RECIBO, nf.nfeTpAmb as TP_AMB, ne.idEmitente as CODFILIAL, 
		null as CUF, null as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id 		
		where (nf.nfeAcao = 12) --Evento Encerramento MDFe
		and (nf.idnEmiteMDFe = 1)

		INSERT INTO @Resultado
		select pagto.id as NOTA_ID, 13 as SERVICO, null as NUM_RECIBO, nf.nfeTpAmb as TP_AMB, ne.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from mdfeMrPagamentoFrete pagto
		inner join mdfeModalRodoviario m on m.id = pagto.idModalRodoviario
		inner join notafiscal nf on nf.id = m.idNotaFiscal
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id
		where (pagto.cStat is null) --Evento de Pagamento da Operacao de Transporte do MDFe
		and (pagto.idnEvento = 1)
		
		INSERT INTO @Resultado
		select mde.id as NOTA_ID, 15 as SERVICO, null as NUM_RECIBO, mde.tpAmb as TP_AMB, mde.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, 0, 0, 0, 0, 0, 1, 0, null as PADRAO_NFSe, 0, 4
		from MDeConsultaNFe mde
		where (mde.acao = 1) --Consultar Notas Manifestacao
		and ((mde.dataHoraConsultar <= GETDATE()) or (mde.dataHoraConsultar is null))
		
		INSERT INTO @Resultado
		select ev.id as NOTA_ID, 16 as SERVICO, null as NUM_RECIBO, mde.tpAmb as TP_AMB, cons.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, 0, 0, 0, 0, 0, 1, 0, null as PADRAO_NFSe, 0, 4
		from MDeEvento ev
		inner join MDeNotas mde on mde.id = ev.idMDeNota
		inner join MDeConsultaNFe cons on cons.id = mde.idMDeConsulta
		where (ev.Acao = 1) --Eventos Manifestacao Destinatario
		
		INSERT INTO @Resultado
		select mde.id as NOTA_ID, 17 as SERVICO, null as NUM_RECIBO, mde.tpAmb as TP_AMB, mde.idEmitente as CODFILIAL,
		null as CUF, null as TP_EMIS, 0, 0, 0, 0, 0, 1, 0, null as PADRAO_NFSe, 0, 4
		from MDeDownloadNFe mde
		where (mde.Acao = 1) --Download XML
		
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 18 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, nf.NFSePadrao as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id   
		where (nf.nfeAcao = 18) --Consultar Situacao Lote NFSe
		and   (nf.idnEmiteNFSe = 1)
		
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 19 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, nf.NFSePadrao as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id   
		where (nf.nfeAcao = 19) --Consultar NFSe por RPS
		and   (nf.idnEmiteNFSe = 1)
		
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 20 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, nf.NFSePadrao as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id   
		where (nf.nfeAcao = 20) --Consultar URL NFSe
		and   (nf.idnEmiteNFSe = 1)
		
		INSERT INTO @Resultado
		select en.id as NOTA_ID, 22 as SERVICO, null as NUM_RECIBO, en.tpAmb as TP_AMB,
		en.idEmitente as CODFILIAL, null as CUF, null as TP_EMIS, 0, 0, 1, 0, 0, 0, 0, null as PADRAO_NFSe, 0, 4
		from mdfeEncerrar en
		where (en.acao = 1) --Encerrar MDFe nao lancada sistema
		
		INSERT INTO @Resultado
		select nf.id as NOTA_ID, 23 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
		ne.idEmitente as CODFILIAL, null as CUF, nf.tpEmis as TP_EMIS, nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
		from notafiscal nf
		inner join nfEmitente ne on ne.idNotaFiscal = nf.id
		where (nf.nfeAcao = 23) --Duplicar nota
		and   ((nf.idnEmiteNF = 1) or (nf.idnEmiteCte = 1) or (nf.idnEmiteMDFe = 1) or (nf.idnEmiteNFCe = 1))
		
		
		SELECT * from @Resultado		
		
	end
	
	if ((@SERVICO_IN = 0) or (@SERVICO_IN = 2))
	begin	    
			/*NOTA_ID int,
		SERVICO int,
		NUM_RECIBO varchar(30),
		TP_AMB int,
		CODFILIAL int,
		CUF int,
		TP_EMIS int*/
		INSERT INTO @Resultado
	    select nf.id, 5 as SERVICO, nf.nfeNrec as NUM_RECIBO, nf.nfeTpAmb as TP_AMB, ne.idEmitente as CODFILIAL,
	    es.codnacional as CUF, nf.tpEmis as TP_EMIS,  nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
	    from notafiscal nf
	    inner join nfEmitente ne on ne.idNotaFiscal = nf.id
	    inner join cidade ci on ci.id = ne.idCidade
		inner join estado es on es.UF = ci.uf and es.idPais = ci.idPais	    	    
	    where (nf.nfeAcao = 5) --Acao 5 ? pra verificar o status da nota..
	    and   (nf.nfeNrec is not null)
	    and   (nf.nfeCstat in (103,104,105))
	    and   (DATEDIFF(SECOND, coalesce(nf.dataAtualizacaoStatusNota, convert(date, GETDATE())), GETDATE()) > 15)
	    
	    select * from @Resultado
	end	

	if ((@SERVICO_IN = 0) or (@SERVICO_IN = 4))
	begin		
	  INSERT INTO @Resultado
	  select nf.id as NOTA_ID, 4 as SERVICO, null as NUM_RECIBO, null as TP_AMB,
	  ne.idEmitente as CODFILIAL, null as CUF, null as TP_EMIS,  nf.idnEmiteNF, nf.idnEmiteCte, nf.idnEmiteMDFe, nf.idnEmiteNFSe, nf.idnEmiteNFCe, 0, nf.idnEmiteCTeOS, null as PADRAO_NFSe, nf.idnNovaVersaoCTe, nf.versaoNFeNFCe
	  from notafiscal nf
	  inner join nfEmitente ne on ne.idNotaFiscal = nf.id
      where (nf.nfeAcao = 4)
    end	
END
GO
ALTER TABLE [dbo].[AutorizacaoSupervisorParametros] ADD CONSTRAINT [FK_AutorizacaoSupervisorParametros_CondicaoPagamento] FOREIGN KEY
	(
		[idCondicaoPagamento]
	)
	REFERENCES [dbo].[CondicaoPagamento]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[AutorizacaoSupervisorParametros] ADD CONSTRAINT [FK_AutorizacaoSupervisorParametros_FormaPagamento] FOREIGN KEY
	(
		[idFormaPagamento]
	)
	REFERENCES [dbo].[FormaPagamento]
	(
		[id]
	)
GO

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

ALTER TABLE [dbo].[DashboardRestricoes] ADD CONSTRAINT [FK_DashboardRestricoes_Dashboard] FOREIGN KEY
	(
		[idDashboard]
	)
	REFERENCES [dbo].[Dashboard]
	(
		[id]
	)
GO

ALTER TABLE [dbo].[DashboardRestricoes] ADD CONSTRAINT [FK_DashboardRestricoes_Operador] FOREIGN KEY
	(
		[idOperador]
	)
	REFERENCES [dbo].[Operador]
	(
		[id]
	)
GO
SET IDENTITY_INSERT [dbo].[Telas] ON 
GO
INSERT [dbo].[Telas] ([id], [descricao], [controle], [idnPermiteAbrirVarias]) VALUES (305, N'Consultar Parâmetros da Autorização Supervisionada', N'Cadastros.ucConsParametrosAutorizacaoSupervisor, Cadastros, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', 0)
GO
INSERT [dbo].[Telas] ([id], [descricao], [controle], [idnPermiteAbrirVarias]) VALUES (306, N'Cadastrar Parâmetros da Autorização Supervisionada', N'Cadastros.ucCadParametrosAutorizacaoSupervisor, Cadastros, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', 0)
GO
INSERT [dbo].[Telas] ([id], [descricao], [controle], [imagem], [teclaAtalho1], [teclaAtalho2], [idnPermiteAbrirVarias], [qtdVezesAberta], [dataUltimaAbertura], [idnRestricaoAcesso]) VALUES (307, N'Evento de Prestação de Serviço em desacordo', N'Cadastros.ucConsPrestacaoServicoDesacordo, Cadastros, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', NULL, NULL, NULL, NULL, 3, CAST(N'2020-12-01T16:46:02.917' AS DateTime), NULL)
GO
SET IDENTITY_INSERT [dbo].[Telas] OFF
GO
SET IDENTITY_INSERT [dbo].[MenuLateralGrupos] ON 
GO 
INSERT INTO [dbo].[MenuLateralGrupos] ([id], [descricaoGrupo],[ordem],[telaOrigem]) VALUES (62,'Autorização Supervisionada', 19, 'Financeiro')
GO
SET IDENTITY_INSERT [dbo].[MenuLateralGrupos] OFF 
GO
SET IDENTITY_INSERT [dbo].[MenuLateralItens] ON
GO 
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (288,1, 'Consultar Parâmetros Autorização', 305, 62, 'search-2_32.png', 0)
GO 
INSERT INTO [dbo].[MenuLateralItens] ([id],[idMenu],[descricao],[idTela],[idMenuLateralGrupo],[imagem],[ordem]) VALUES (289,1, 'Cadastrar Parâmetros Autorização', 306, 62, 'shield.png', 1)
GO
SET IDENTITY_INSERT [dbo].[MenuLateralItens] OFF
GO
SET IDENTITY_INSERT [dbo].[MenuItens] ON 
INSERT [dbo].[MenuItens] ([id], [idMenu], [descricao], [idTela], [idMenuItemPai], [ordem], [idnVisivel], [md5], [imagem]) VALUES (416, 1, N'Evento de Prestação em desacordo', 307, 22, 13, 1, NULL, N'')
GO
INSERT [dbo].[MenuItens] ([id], [idMenu], [descricao], [idTela], [idMenuItemPai], [ordem], [idnVisivel], [md5], [imagem]) VALUES (417, 2, N'Evento de Prestação em desacordo', 307, 164, 9, 1, NULL, N'')
GO
SET IDENTITY_INSERT [dbo].[MenuItens] OFF
GO
UPDATE MenuLateralItens SET descricao = 'Alteração de Preços e Custos' WHERE id = 10
GO
UPDATE estado SET consultaNFCeProducao = 'http://www.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp', consultaNFCeHomologacao = 'http://www.homologacao.sefaz.ma.gov.br/portal/consultarNFCe.jsp' where UF = 'MA'

GO
UPDATE configuracoes SET mensagemEmailPrestacaoServicoDesacordo = 'Olá,<br/><br/>Você está recebendo um aviso sobre o registro do evento de "Prestação de Serviço em Desacordo", referente ao Documento Fiscal nº %numero%, emitido pelo CNPJ: %cnpjEmissor%.<br/><b>Tomador do Serviço: %razaoSocialTomador%.<br/>CPF/CNPJ: %cpfCnpjTomador%.</b><br/><br/>Segue em anexo o arquivo XML e o PDF, contendo os dados do evento.<br/><br/><i>Este e-mail foi enviado automaticamente, caso tenha alguma dúvida, entre em contato.</i>'
GO
UPDATE configuracoes SET versaoMinimaAppComandas = 14
GO
declare @diasSemManutencao int = 0;
SET @diasSemManutencao = (select DATEDIFF(DAY,coalesce(m.dataUltimaExecucao, DATEADD(week,-2, getdate())), GETDATE()) from ManutencoesBanco m where descricao = 'INDICES');
if (@diasSemManutencao >= 7)
begin
	EXEC sp_msforeachtable 'SET QUOTED_IDENTIFIER ON ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR = 90)';
	EXEC sp_msforeachtable 'SET QUOTED_IDENTIFIER ON ALTER INDEX ALL ON ? REORGANIZE';
	UPDATE ManutencoesBanco set dataUltimaExecucao = GETDATE() where descricao = 'INDICES';
end;
GO
INSERT INTO VERSAO(VERSAO, VERSAOATUALIZACAO, DATAATUALIZACAO) VALUES(430, 688, GETDATE());