Ejemplo n.º 1
0
        private void CriarEventoFechamentoReabertura(FechamentoReabertura fechamentoReabertura)
        {
            var tipoEvento = repositorioEventoTipo.ObterTipoEventoPorTipo(TipoEvento.FechamentoBimestre);

            if (tipoEvento == null)
            {
                throw new NegocioException($"Não foi possível localizar o tipo de evento {TipoEvento.FechamentoBimestre.GetAttribute<DisplayAttribute>().Name}.");
            }

            var evento = new Evento()
            {
                DataFim          = fechamentoReabertura.Fim,
                DataInicio       = fechamentoReabertura.Inicio,
                Descricao        = fechamentoReabertura.Descricao,
                Nome             = $"Reabertura de fechamento de bimestre - {fechamentoReabertura.TipoCalendario.Nome} - {fechamentoReabertura.TipoCalendario.AnoLetivo}.",
                TipoCalendarioId = fechamentoReabertura.TipoCalendario.Id,
                DreId            = fechamentoReabertura.Dre.CodigoDre,
                UeId             = fechamentoReabertura.Ue.CodigoUe,
                Status           = EntidadeStatus.Aprovado,
                TipoEventoId     = tipoEvento.Id,
                Migrado          = false,
                Letivo           = EventoLetivo.Sim,
            };

            repositorioEvento.Salvar(evento);
        }
Ejemplo n.º 2
0
        public async Task <string> AlterarAsync(FechamentoReabertura fechamentoReabertura, DateTime dataInicialAnterior, DateTime dataFimAnterior, bool confirmacacaoAlteracaoHierarquica)
        {
            var fechamentoReaberturas = await repositorioFechamentoReabertura.Listar(fechamentoReabertura.TipoCalendarioId, null, null, null);

            var fechamentoReaberturasParaVerificar = fechamentoReaberturas.Where(a => a.Id != fechamentoReabertura.Id);
            var fechamentoReaberturasParaAtualizar = fechamentoReaberturasParaVerificar.Where(a => fechamentoReabertura.Inicio > a.Inicio || a.Fim > fechamentoReabertura.Fim);

            var usuarioAtual = await servicoUsuario.ObterUsuarioLogado();

            fechamentoReabertura.PodeSalvar(fechamentoReaberturasParaVerificar, usuarioAtual);

            fechamentoReabertura.VerificaStatus();

            unitOfWork.IniciarTransacao();

            var fechamentoReaberturaId = await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

            var mensagemRetorno = "Reabertura de Fechamento alterado com sucesso.";

            if (fechamentoReabertura.Status == EntidadeStatus.AguardandoAprovacao)
            {
                fechamentoReabertura.WorkflowAprovacaoId = PersistirWorkflowFechamentoReabertura(fechamentoReabertura);
                await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

                mensagemRetorno = "Reabertura de Fechamento alterado e será válido após aprovação.";
            }

            await VerificaEAtualizaFechamentosReaberturasParaAlterar(fechamentoReabertura, fechamentoReaberturasParaAtualizar, confirmacacaoAlteracaoHierarquica);

            unitOfWork.PersistirTransacao();

            return(mensagemRetorno);
        }
Ejemplo n.º 3
0
        private void NotificarAdminSgpUeFechamentoReaberturaReprovado(FechamentoReabertura fechamentoReabertura, long codigoDaNotificacao, string motivo, long nivelId)
        {
            var adminsSgpUe = servicoEOL.ObterAdministradoresSGP(fechamentoReabertura.Ue.CodigoUe).Result;

            if (adminsSgpUe != null && adminsSgpUe.Any())
            {
                foreach (var adminSgpUe in adminsSgpUe)
                {
                    var usuario     = servicoUsuario.ObterUsuarioPorCodigoRfLoginOuAdiciona(adminSgpUe);
                    var notificacao = new Notificacao()
                    {
                        UeId      = fechamentoReabertura.Ue.CodigoUe,
                        UsuarioId = usuario.Id,
                        Ano       = fechamentoReabertura.CriadoEm.Year,
                        Categoria = NotificacaoCategoria.Aviso,
                        DreId     = fechamentoReabertura.Dre.CodigoDre,
                        Titulo    = "Cadastro de período de reabertura de fechamento - ano anterior",
                        Tipo      = NotificacaoTipo.Calendario,
                        Codigo    = codigoDaNotificacao,
                        Mensagem  = $@"O período de reabertura do fechamento de bimestre abaixo da {fechamentoReabertura.Ue.Nome} ({fechamentoReabertura.Dre.Abreviacao}) foi reprovado pela supervisão escolar. Motivo: {motivo} <br/>
                                  Descrição: { fechamentoReabertura.Descricao} < br />
                                  Início: { fechamentoReabertura.Inicio.ToString("dd/MM/yyyy")} < br />
                                  Fim: { fechamentoReabertura.Fim.ToString("dd/MM/yyyy")} < br />
                                  Bimestres: { fechamentoReabertura.ObterBimestresNumeral()}"
                    };
                    repositorioNotificacao.Salvar(notificacao);
                    repositorioWorkflowAprovacaoNivelNotificacao.Salvar(new WorkflowAprovacaoNivelNotificacao()
                    {
                        NotificacaoId = notificacao.Id, WorkflowAprovacaoNivelId = nivelId
                    });
                }
            }
        }
        private void NotificarDiretorUeFechamentoReaberturaReprovado(FechamentoReabertura fechamentoReabertura, long codigoDaNotificacao, string motivo, long nivelId)
        {
            var diretoresDaEscola = servicoEOL.ObterFuncionariosPorCargoUe(fechamentoReabertura.Ue.CodigoUe, (long)Cargo.Diretor);

            if (diretoresDaEscola == null && !diretoresDaEscola.Any())
            {
                throw new NegocioException("Não foi possível localizar o diretor da Ue desta reabertura de fechamento.");
            }

            foreach (var diretorDaEscola in diretoresDaEscola)
            {
                var usuario     = servicoUsuario.ObterUsuarioPorCodigoRfLoginOuAdiciona(diretorDaEscola.CodigoRf);
                var notificacao = new Notificacao()
                {
                    UeId      = fechamentoReabertura.Ue.CodigoUe,
                    UsuarioId = usuario.Id,
                    Ano       = fechamentoReabertura.CriadoEm.Year,
                    Categoria = NotificacaoCategoria.Aviso,
                    DreId     = fechamentoReabertura.Dre.CodigoDre,
                    Titulo    = "Cadastro de período de reabertura de fechamento - ano anterior",
                    Tipo      = NotificacaoTipo.Calendario,
                    Codigo    = codigoDaNotificacao,
                    Mensagem  = $@"O período de reabertura do fechamento de bimestre abaixo da {fechamentoReabertura.Ue.Nome} ({fechamentoReabertura.Dre.Nome}) foi reprovado pela supervisão escolar. Motivo: {motivo} <br />
                                  Descrição: { fechamentoReabertura.Descricao} < br />
                                  Início: { fechamentoReabertura.Inicio.ToString("dd/MM/yyyy")} < br />
                                  Fim: { fechamentoReabertura.Fim.ToString("dd/MM/yyyy")} < br />
                                  Bimestres: { fechamentoReabertura.ObterBimestresNumeral()}"
                };
                repositorioNotificacao.Salvar(notificacao);
                repositorioWorkflowAprovacaoNivelNotificacao.Salvar(new WorkflowAprovacaoNivelNotificacao()
                {
                    NotificacaoId = notificacao.Id, WorkflowAprovacaoNivelId = nivelId
                });
            }
        }
        public async Task <string> ExcluirAsync(FechamentoReabertura fechamentoReabertura)
        {
            unitOfWork.IniciarTransacao();

            try
            {
                if (fechamentoReabertura.EhParaSme())
                {
                    var fechamentosSME = await repositorioFechamentoReabertura.Listar(fechamentoReabertura.TipoCalendario.Id, null, null, null);

                    if (fechamentosSME.Any(f => f.EhParaDre() || f.EhParaUe()))
                    {
                        return($"Não foi possível excluir o fechamento de reabertura de código {fechamentoReabertura.Id}, existem fechamentos para DRE/UE relacionados a essa SME");
                    }
                }
                else if (fechamentoReabertura.EhParaDre())
                {
                    var fechamentosDre = await repositorioFechamentoReabertura.Listar(fechamentoReabertura.TipoCalendario.Id, fechamentoReabertura.DreId, null, null);

                    if (fechamentosDre.Any(f => f.EhParaUe()))
                    {
                        return($"Não foi possível excluir o fechamento de reabertura de código {fechamentoReabertura.Id}, existem fechamentos para UE relacionados a essa DRE");
                    }
                }

                fechamentoReabertura.Excluir();
                await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

                if (fechamentoReabertura.EhParaUe())
                {
                    await ExcluirVinculosAysnc(fechamentoReabertura);
                }
                else
                {
                    var fechamentoReaberturas = await repositorioFechamentoReabertura.Listar(fechamentoReabertura.TipoCalendarioId, null, null, null);

                    var fechamentoReaberturasParaExcluir = fechamentoReaberturas.Where(a => a.Id != fechamentoReabertura.Id && fechamentoReabertura.Inicio >= a.Inicio || a.Fim >= fechamentoReabertura.Fim);

                    if (fechamentoReaberturasParaExcluir != null && fechamentoReaberturasParaExcluir.Any())
                    {
                        foreach (var fechamentoReaberturaParaExcluir in fechamentoReaberturasParaExcluir)
                        {
                            await ExcluirVinculosAysnc(fechamentoReaberturaParaExcluir);
                        }
                    }
                }
            }
            catch (NegocioException nEx)
            {
                return(nEx.Message);
            }
            catch (Exception)
            {
                return($"Não foi possível excluir o fechamento de reabertura de código {fechamentoReabertura.Id}");
            }

            unitOfWork.PersistirTransacao();

            return("Exclusão efetuada com sucesso.");
        }
        public async Task <string> SalvarAsync(FechamentoReabertura fechamentoReabertura)
        {
            var fechamentoReaberturas = await repositorioFechamentoReabertura.Listar(fechamentoReabertura.TipoCalendarioId, null, null, null);

            var usuarioAtual = await servicoUsuario.ObterUsuarioLogado();

            fechamentoReabertura.PodeSalvar(fechamentoReaberturas, usuarioAtual);

            fechamentoReabertura.VerificaStatus();

            unitOfWork.IniciarTransacao();

            var fechamentoReaberturaId = await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

            var mensagemRetorno = "Reabertura de Fechamento cadastrada com sucesso";

            foreach (var fechamentoReaberturaBimestre in fechamentoReabertura.Bimestres)
            {
                fechamentoReaberturaBimestre.FechamentoAberturaId = fechamentoReaberturaId;

                if (fechamentoReaberturaBimestre.Id > 0)
                {
                    fechamentoReaberturaBimestre.AlteradoEm  = DateTime.Now;
                    fechamentoReaberturaBimestre.AlteradoPor = usuarioAtual.Nome;
                    fechamentoReaberturaBimestre.AlteradoRF  = usuarioAtual.CodigoRf;
                }
                else
                {
                    fechamentoReaberturaBimestre.CriadoPor = usuarioAtual.Nome;
                    fechamentoReaberturaBimestre.CriadoRF  = usuarioAtual.CodigoRf;
                }

                await repositorioFechamentoReabertura.SalvarBimestreAsync(fechamentoReaberturaBimestre);
            }

            if (fechamentoReabertura.Status == EntidadeStatus.AguardandoAprovacao)
            {
                fechamentoReabertura.WorkflowAprovacaoId = await PersistirWorkflowFechamentoReabertura(fechamentoReabertura);

                await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

                mensagemRetorno = "Reabertura de Fechamento cadastrado e será válido após aprovação.";
            }
            else if (fechamentoReabertura.DeveCriarEventos())
            {
                await GeraEventos(fechamentoReabertura);
            }

            unitOfWork.PersistirTransacao();

            return(mensagemRetorno);
        }
Ejemplo n.º 7
0
        private FechamentoReabertura TransformarDtoEmEntidadeParaPersistencia(FechamentoReaberturaPersistenciaDto fechamentoReaberturaPersistenciaDto)
        {
            Dre dre = null;
            Ue  ue  = null;

            if (!string.IsNullOrEmpty(fechamentoReaberturaPersistenciaDto.DreCodigo))
            {
                dre = repositorioDre.ObterPorCodigo(fechamentoReaberturaPersistenciaDto.DreCodigo);
                if (dre == null)
                {
                    throw new NegocioException("Não foi possível localizar a Dre.");
                }
            }

            if (!string.IsNullOrEmpty(fechamentoReaberturaPersistenciaDto.UeCodigo))
            {
                ue = repositorioUe.ObterPorCodigo(fechamentoReaberturaPersistenciaDto.UeCodigo);
                if (ue == null)
                {
                    throw new NegocioException("Não foi possível localizar a UE.");
                }
            }

            var tipoCalendario = repositorioTipoCalendario.ObterPorId(fechamentoReaberturaPersistenciaDto.TipoCalendarioId);

            if (tipoCalendario == null)
            {
                throw new NegocioException("Não foi possível localizar o Tipo de Calendário.");
            }

            var fechamentoReabertura = new FechamentoReabertura()
            {
                Descricao = fechamentoReaberturaPersistenciaDto.Descricao,
                Fim       = fechamentoReaberturaPersistenciaDto.Fim,
                Inicio    = fechamentoReaberturaPersistenciaDto.Inicio
            };

            fechamentoReabertura.AtualizarDre(dre);
            fechamentoReabertura.AtualizarUe(ue);
            fechamentoReabertura.AtualizarTipoCalendario(tipoCalendario);

            fechamentoReaberturaPersistenciaDto.Bimestres.ToList().ForEach(bimestre =>
            {
                fechamentoReabertura.Adicionar(new FechamentoReaberturaBimestre()
                {
                    Bimestre = bimestre
                });
            });

            return(fechamentoReabertura);
        }
Ejemplo n.º 8
0
        private void TrataReprovacaoFechamentoReabertura(WorkflowAprovacao workflow, long codigoDaNotificacao, string motivo, long nivelId)
        {
            FechamentoReabertura fechamentoReabertura = repositorioFechamentoReabertura.ObterCompleto(0, workflow.Id);

            if (fechamentoReabertura == null)
            {
                throw new NegocioException("Não foi possível localizar a reabertura do fechamento do fluxo de aprovação.");
            }

            fechamentoReabertura.ReprovarWorkFlow();

            repositorioFechamentoReabertura.Salvar(fechamentoReabertura);

            NotificarAdminSgpUeFechamentoReaberturaReprovado(fechamentoReabertura, codigoDaNotificacao, motivo, nivelId);
            NotificarDiretorUeFechamentoReaberturaReprovado(fechamentoReabertura, codigoDaNotificacao, motivo, nivelId);
        }
        private void AprovarUltimoNivelDeEventoFechamentoReabertura(long codigoDaNotificacao, long workflowId, long nivelId)
        {
            FechamentoReabertura fechamentoReabertura = repositorioFechamentoReabertura.ObterCompleto(0, workflowId);

            if (fechamentoReabertura == null)
            {
                throw new NegocioException("Não foi possível localizar a reabertura do fechamento do fluxo de aprovação.");
            }

            fechamentoReabertura.AprovarWorkFlow();
            //TODO: CRIAR EVENTOS;

            repositorioFechamentoReabertura.Salvar(fechamentoReabertura);

            NotificarAdminSgpUeFechamentoReaberturaAprovado(fechamentoReabertura, codigoDaNotificacao, nivelId);
            NotificarDiretorUeFechamentoReaberturaAprovado(fechamentoReabertura, codigoDaNotificacao, nivelId);
        }
Ejemplo n.º 10
0
 private FechamentoReaberturaRetornoDto TransformaEntidadeEmDto(FechamentoReabertura fechamentoReabertura)
 {
     return(new FechamentoReaberturaRetornoDto()
     {
         Bimestres = fechamentoReabertura.ObterBimestresSelecionados(),
         DataInicio = fechamentoReabertura.Inicio,
         DataFim = fechamentoReabertura.Fim,
         Descricao = fechamentoReabertura.Descricao,
         Id = fechamentoReabertura.Id,
         BimestresQuantidadeTotal = fechamentoReabertura.TipoCalendario.QuantidadeDeBimestres(),
         DreCodigo = fechamentoReabertura.Dre?.CodigoDre,
         UeCodigo = fechamentoReabertura.Ue?.CodigoUe,
         TipoCalendarioId = fechamentoReabertura.TipoCalendarioId,
         CriadoEm = fechamentoReabertura.CriadoEm,
         AlteradoEm = fechamentoReabertura.AlteradoEm ?? DateTime.MinValue,
         CriadoPor = fechamentoReabertura.CriadoPor,
         AlteradoPor = fechamentoReabertura.AlteradoPor,
         AlteradoRF = fechamentoReabertura.AlteradoRF,
         CriadoRF = fechamentoReabertura.CriadoRF
     });
 }
Ejemplo n.º 11
0
 private static FechamentoReaberturaListagemDto TransformaEntidadeEmDtoListagem(FechamentoReabertura item)
 {
     return(new FechamentoReaberturaListagemDto()
     {
         Bimestres = item.ObterBimestresSelecionados(),
         DataInicio = item.Inicio,
         DataFim = item.Fim,
         Descricao = item.Descricao,
         Id = item.Id,
         BimestresQuantidadeTotal = item.TipoCalendario.QuantidadeDeBimestres()
     });
 }
Ejemplo n.º 12
0
 private async Task AtualizaFechamentosComDatasDistintas(FechamentoReabertura fechamentoReabertura, List <(FechamentoReabertura, bool, bool)> fechamentosReaberturasParaAtualizar)
Ejemplo n.º 13
0
 private void AtualizarEntidadeComDto(FechamentoReabertura fechamentoReabertura, FechamentoReaberturaAlteracaoDto fechamentoReaberturaPersistenciaDto)
 {
     fechamentoReabertura.Inicio = fechamentoReaberturaPersistenciaDto.Inicio;
     fechamentoReabertura.Fim    = fechamentoReaberturaPersistenciaDto.Fim;
 }
Ejemplo n.º 14
0
        public async Task <string> Salvar(FechamentoReaberturaPersistenciaDto fechamentoReaberturaPersistenciaDto)
        {
            FechamentoReabertura entidade = TransformarDtoEmEntidadeParaPersistencia(fechamentoReaberturaPersistenciaDto);

            return(await servicoFechamentoReabertura.SalvarAsync(entidade));
        }
        public async Task <PodeCadastrarAulaPorDataRetornoDto> Handle(ObterPodeCadastrarAulaPorDataQuery request, CancellationToken cancellationToken)
        {
            var hoje = DateTime.Today;

            // Periodo Escolar
            var periodoEscolar = await repositorioTipoCalendario.ObterPeriodoEscolarPorCalendarioEData(request.TipoCalendarioId, request.DataAula);

            if (periodoEscolar == null)
            {
                return(new PodeCadastrarAulaPorDataRetornoDto(false, "Não é possível cadastrar aula fora do periodo escolar"));
            }

            // Domingo
            if (request.DataAula.FimDeSemana())
            {
                // Evento Letivo
                var temEventoLetivoNoDia = repositorioEvento.EhEventoLetivoPorTipoDeCalendarioDataDreUe(request.TipoCalendarioId, request.DataAula, request.DreCodigo, request.UeCodigo);
                if (!temEventoLetivoNoDia)
                {
                    return(new PodeCadastrarAulaPorDataRetornoDto(false, "Não é possível cadastrar aula no domingo"));
                }
            }

            // Evento não letivo
            var temEventoNaoLetivoNoDia = repositorioEvento.EhEventoNaoLetivoPorTipoDeCalendarioDataDreUe(request.TipoCalendarioId, request.DataAula, request.DreCodigo, request.UeCodigo);

            if (temEventoNaoLetivoNoDia)
            {
                return(new PodeCadastrarAulaPorDataRetornoDto(false, "Apenas é possível consultar este registro pois existe um evento de dia não letivo"));
            }

            if (request.DataAula.Year == hoje.Year)
            {
                if (request.DataAula <= hoje)
                {
                    // Consultar fechamento só se não for data no bimestre corrente
                    var periodoEscolarAtual = await repositorioTipoCalendario.ObterPeriodoEscolarPorCalendarioEData(request.TipoCalendarioId, hoje);

                    if (periodoEscolarAtual == null || periodoEscolar.Id != periodoEscolarAtual.Id)
                    {
                        var periodoFechamento = await repositorioPeriodoFechamento.ObterPeriodoPorUeDataBimestreAsync(request.Turma.UeId, hoje, periodoEscolar.Bimestre);

                        if (periodoFechamento != null)
                        {
                            if (periodoFechamento.ExisteFechamentoEmAberto(hoje))
                            {
                                return(new PodeCadastrarAulaPorDataRetornoDto(true));
                            }
                        }
                        else
                        {
                            FechamentoReabertura periodoFechamentoReabertura = await ObterPeriodoFechamentoReabertura(request.TipoCalendarioId, request.Turma.UeId, hoje);

                            return(periodoFechamentoReabertura != null ?
                                   new PodeCadastrarAulaPorDataRetornoDto(true) :
                                   new PodeCadastrarAulaPorDataRetornoDto(false, "Apenas é possível consultar este registro pois o período deste bimestre não está aberto."));
                        }
                    }
                }
                else
                {
                    return(new PodeCadastrarAulaPorDataRetornoDto(true));
                }
            }
            else
            {
                FechamentoReabertura periodoFechamentoReabertura = await ObterPeriodoFechamentoReabertura(request.TipoCalendarioId, request.Turma.UeId, hoje);

                return(periodoFechamentoReabertura != null ?
                       new PodeCadastrarAulaPorDataRetornoDto(true) :
                       new PodeCadastrarAulaPorDataRetornoDto(false, "Apenas é possível consultar este registro pois o período deste bimestre não está aberto."));
            }

            return(new PodeCadastrarAulaPorDataRetornoDto(true));
        }