private static void ExecutaAlterarPeriodosComHierarquiaInferior(FechamentoDto fechamentoDto, PeriodoFechamento fechamento, bool ehSme) { if ((ehSme && !fechamento.DreId.HasValue) || (fechamento.DreId.HasValue && !fechamento.UeId.HasValue) && fechamentoDto.ConfirmouAlteracaoHierarquica) { Cliente.Executar <IServicoPeriodoFechamento>(c => c.AlterarPeriodosComHierarquiaInferior(fechamento)); } }
public IHttpActionResult ObterDadosFechamento(int idLoja) { using (var sessao = new GDATransaction()) { var dataCaixaAberto = CaixaDiarioDAO.Instance.GetDataCaixaAberto(sessao, (uint)idLoja); var fechamento = new FechamentoDto(); fechamento.DiaAtual = new DiaAtualDto() { CaixaFechado = CaixaDiarioDAO.Instance.CaixaFechado(sessao, (uint)idLoja), Saldo = CaixaDiarioDAO.Instance.GetSaldoByLoja(sessao, (uint)idLoja), SaldoDinheiro = CaixaDiarioDAO.Instance.GetSaldoByFormaPagto(sessao, Data.Model.Pagto.FormaPagto.Dinheiro, 0, (uint)idLoja, 0, DateTime.Now, 1), ExistemMovimentacoes = CaixaDiarioDAO.Instance.ExisteMovimentacao(sessao, (uint)idLoja, DateTime.Now), }; fechamento.DiaAnterior = new DiaAnteriorDto() { CaixaFechado = CaixaDiarioDAO.Instance.CaixaFechadoDiaAnterior(sessao, (uint)idLoja), Saldo = CaixaDiarioDAO.Instance.GetSaldoDiaAnterior(sessao, (uint)idLoja), SaldoDinheiro = CaixaDiarioDAO.Instance.GetSaldoByFormaPagto(sessao, Data.Model.Pagto.FormaPagto.Dinheiro, 0, (uint)idLoja, 0, dataCaixaAberto, 1), DataCaixaAberto = dataCaixaAberto, }; if (fechamento.DiaAtual.Saldo == 0 && !fechamento.DiaAtual.ExistemMovimentacoes) { fechamento.DiaAtual.Saldo = fechamento.DiaAnterior.Saldo; fechamento.DiaAtual.SaldoDinheiro += fechamento.DiaAnterior.Saldo; } return(this.Item(fechamento)); } }
private PeriodoFechamento MapearParaDominio(FechamentoDto fechamentoDto) { var(dre, ue) = ObterDreEUe(fechamentoDto.DreId, fechamentoDto.UeId); var fechamento = repositorioFechamento.ObterPorTipoCalendarioDreEUE(fechamentoDto.TipoCalendarioId.Value, dre?.Id, ue?.Id); if (fechamento == null) { fechamento = new PeriodoFechamento(dre, ue); } var tipoCalendario = repositorioTipoCalendario.ObterPorId(fechamentoDto.TipoCalendarioId.Value); if (tipoCalendario == null) { throw new NegocioException("Tipo calendário não encontrado."); } if (fechamentoDto.FechamentosBimestres != null && fechamentoDto.FechamentosBimestres.Any()) { foreach (var bimestre in fechamentoDto.FechamentosBimestres) { var periodoEscolar = repositorioPeriodoEscolar.ObterPorId(bimestre.PeriodoEscolarId); PeriodoFechamentoBimestre fechamentoBimestreExistente = fechamento.ObterFechamentoBimestre(bimestre.PeriodoEscolarId); if (fechamentoBimestreExistente != null) { fechamentoBimestreExistente.AtualizarDatas(bimestre.InicioDoFechamento, bimestre.FinalDoFechamento); } else { fechamento.AdicionarFechamentoBimestre(new PeriodoFechamentoBimestre(fechamento.Id, periodoEscolar, bimestre.InicioDoFechamento, bimestre.FinalDoFechamento)); } } } return(fechamento); }
public IHttpActionResult Fechar(int idLoja, [FromBody] FechamentoDto fechamento) { using (var sessao = new GDATransaction()) { var validacao = this.ValidarExistenciaIdLoja(sessao, idLoja); if (validacao != null) { return(validacao); } if (fechamento.ValorATransferirCaixaGeral == null) { return(this.ErroValidacao("Informe o valor a ser transferido para o caixa geral")); } var diaAnteriorAberto = !CaixaDiarioDAO.Instance.CaixaFechadoDiaAnterior(sessao, (uint)idLoja); if (!diaAnteriorAberto && fechamento.SaldoTela != CaixaDiarioDAO.Instance.GetSaldoByLoja((uint)idLoja)) { return(this.ErroValidacao("Foram feitas movimentações no caixa diário que não estão sendo exibidas na tela." + "\n\nEntre na tela novamente para recuperar o saldo correto do dia.")); } try { sessao.BeginTransaction(); var dataFechamento = diaAnteriorAberto ? CaixaDiarioDAO.Instance.GetDataCaixaAberto(sessao, (uint)idLoja) : DateTime.Now; CaixaDiarioDAO.Instance.FechaCaixa( sessao, (uint)idLoja, fechamento.ValorATransferirCaixaGeral.GetValueOrDefault(), dataFechamento, diaAnteriorAberto); sessao.Commit(); return(this.Aceito("Caixa fechado.")); } catch (Exception ex) { sessao.Rollback(); return(this.ErroValidacao("Falha ao fechar caixa.", ex)); } } }
private void ValidarRegistrosForaDoPeriodo(FechamentoDto fechamentoDto, PeriodoFechamento fechamento, bool ehSme, bool ehDre) { if ((ehDre || ehSme) && string.IsNullOrWhiteSpace(fechamentoDto.UeId) && fechamento.Id > 0 && !fechamentoDto.ConfirmouAlteracaoHierarquica) { foreach (var fechamentoBimestre in fechamento.FechamentosBimestre) { var existeRegistroForaDoPeriodo = repositorioPeriodoFechamento.ValidaRegistrosForaDoPeriodo(fechamentoBimestre.InicioDoFechamento, fechamentoBimestre.FinalDoFechamento, fechamento.Id, fechamentoBimestre.PeriodoEscolarId, fechamento.DreId); if (existeRegistroForaDoPeriodo) { var textoSme = ehDre ? "" : "DRE's/"; throw new NegocioException($"A alteração que você está fazendo afetará datas de fechamento definidas pelas {textoSme}UE's. Deseja Continuar?", 602); } } } }
public async Task Salvar(FechamentoDto fechamentoDto) { var usuarioLogado = await servicoUsuario.ObterUsuarioLogado(); var fechamento = MapearParaDominio(fechamentoDto); var(ehSme, ehDre) = (usuarioLogado.EhPerfilSME(), usuarioLogado.EhPerfilDRE()); ValidarCamposObrigatorios(ehSme, ehDre, fechamento); ValidarHierarquiaPeriodos(ehSme, ehDre, fechamento); ValidarRegistrosForaDoPeriodo(fechamentoDto, fechamento, ehSme, ehDre); unitOfWork.IniciarTransacao(); var id = repositorioPeriodoFechamento.Salvar(fechamento); repositorioPeriodoFechamento.SalvarBimestres(fechamento.FechamentosBimestre, id); unitOfWork.PersistirTransacao(); ExecutaAlterarPeriodosComHierarquiaInferior(fechamentoDto, fechamento, ehSme); CriarEventoFechamento(fechamento); }
public async Task Salvar(FechamentoDto fechamentoDto) { await servicoPeriodoFechamento.Salvar(fechamentoDto); }
public async Task <IActionResult> Post([FromBody] FechamentoDto fechamentoDto, [FromServices] IComandosPeriodoFechamento comandosFechamento) { await comandosFechamento.Salvar(fechamentoDto); return(Ok()); }