Ejemplo n.º 1
0
        private LancamentoFinanceiro indexarDados(LancamentoFinanceiro lancto)
        {
            if (lancto.CentroCusto != null)
            {
                lookUpCentroCusto1.FindSetCentroCusto(lancto.CentroCusto.CodigoCentroCusto);
            }

            if (lancto.CliFor != null)
            {
                lookUpCliFor1.FindSetCliFor(lancto.CliFor.IdCliFor.ToString());
            }

            lookUpFilial1.FindSetFilial(lancto.Filial.CodigoFilial);

            rdTipoLanc.SelectedIndex = (int)lancto.TipoLancamento;

            this.dtEditEmissao.DateTime    = lancto.DataLancamento;
            this.dtEditVencimento.DateTime = lancto.DataVencimento;
            this.txtValorLancamento.Text   = lancto.ValorLancamento.ToString("N2");
            this.txtValorJuros.Text        = lancto.ValorJuros.ToString("N2");
            this.richObs.Text = lancto.Observacao;

            //indexado a partir 0
            this.cbStatusLancamento.SelectedIndex = (int)lancto.StatusLancamento;

            this._anexos = lancto.Anexos.ToList();
            this.gridControl1.DataSource = this._anexos;
            this.gridView1.RefreshData();

            statusView(lancto);

            //deixe colocar se ainda nao foi pago ou se nao tem anexos
            if (lancto.Anexos.Count == 0 ||
                lancto.StatusLancamento == TypeStatusLancamentoFinanceiro.Aberto ||
                lancto.StatusLancamento == TypeStatusLancamentoFinanceiro.Vencido)
            {
                this.barBtnDigitalizar.Enabled = true;
                this.barBtnAnexar.Enabled      = true;
                this.btnSalvarAnexos.Visible   = true;
                this.btnRemoveAnexo.Visible    = true;

                this.gridView1.OptionsBehavior.Editable = true;
                this.btnCancelar.Visible = false;
            }

            //se a venda eh nula entao eh um lançamento avulso
            if (lancto.IdVenda == null && lancto.StatusLancamento != TypeStatusLancamentoFinanceiro.Pago)
            {
                //flexibilidade
                dtEditEmissao.ReadOnly    = false;
                dtEditVencimento.ReadOnly = false;
            }

            if (_currentUser.IsAdmin)
            {
                btnSalvarAnexos.Visible = true;
                btnRemoveAnexo.Visible  = true;
            }
            return(lancto);
        }
Ejemplo n.º 2
0
        public async Task <ConsolidadoFluxo> AdicionarLancamento(LancamentoFinanceiro lancamento)
        {
            var dataLancamento = DateTime.ParseExact(lancamento.Data, "dd-MM-yyyy", null, System.Globalization.DateTimeStyles.None);

            var consolidadoFluxo = await BuscaDadoConsolidado(dataLancamento);

            if (consolidadoFluxo == null)
            {
                consolidadoFluxo = new ConsolidadoFluxo()
                {
                    Data = dataLancamento, Encargos = new List <DataValor>(), Entradas = new List <DataValor>(), Saidas = new List <DataValor>()
                }
            }
            ;

            if (lancamento.Lancamento == TipoLancamento.Pagamento)
            {
                consolidadoFluxo.Saidas.Add(new DataValor(lancamento.Data, lancamento.Valor));
            }

            if (lancamento.Lancamento == TipoLancamento.Recebimento)
            {
                consolidadoFluxo.Entradas.Add(new DataValor(lancamento.Data, lancamento.Valor));
            }

            consolidadoFluxo.Encargos.Add(new DataValor(lancamento.Data, lancamento.Encargos));

            consolidadoFluxo.Total = consolidadoFluxo.Entradas.Sum(x => x.Valor) + ((consolidadoFluxo.Saidas.Sum(x => x.Valor) + consolidadoFluxo.Encargos.Sum(x => x.Valor)) * -1);

            return(await _repositorioConsolidadoFluxo.Salvar_Async(consolidadoFluxo));
        }
    }
        public async Task <IActionResult> PutLancamentoFinanceiro(LancamentoFinanceiro lancamento)
        {
            try
            {
                var oldLancamento = await _ctx.LancamentosFinanceiros.FirstOrDefaultAsync(x => x.Id == lancamento.Id);

                if (oldLancamento == null)
                {
                    return(NotFound());
                }

                if (oldLancamento.Status.Value)
                {
                    throw new Exception("O lançamento já foi conciliado");
                }

                _ctx.Entry(oldLancamento).State = EntityState.Detached;

                ValidadeData(lancamento);

                _ctx.Update(lancamento);

                await _ctx.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 4
0
        public void ToFinancialEntryEntity()
        {
            var dto = new LancamentoFinanceiro
            {
                descricao           = "Test description",
                banco_destino       = BankEnum.NuBank,
                conta_destino       = "0001",
                tipo_de_conta       = AccountTypeEnum.Checking,
                cpf_cnpj_destino    = "47.972.568/0001-38",
                tipo_da_lancamento  = FinancialEntryTypeEnum.Payment,
                valor_do_lancamento = "R$ 1.000,05",
                data_de_lancamento  = "05-01-2019"
            };

            var entity = (FinancialEntryEntity)dto;

            Assert.Equal("Test description", entity.Description);
            Assert.Equal(BankEnum.NuBank, entity.DestinationBank);
            Assert.Equal("0001", entity.DestinationAccount);
            Assert.Equal(AccountTypeEnum.Checking, entity.AccountType);
            Assert.Equal("47.972.568/0001-38", entity.DestinationCpfCnpj);
            Assert.Equal(FinancialEntryTypeEnum.Payment, entity.EntryType);
            Assert.Equal(1000.05m, entity.Value);
            Assert.Equal("05-01-2019", entity.EntryDate.ToString("dd-MM-yyyy"));
        }
Ejemplo n.º 5
0
        public void EnviaParaFila(LancamentoFinanceiro lancamento, ConnectionFactory connectionFactory)
        {
            var queue = $"queue-{lancamento.Lancamento.GetDescription().ToLower()}";

            using (var conn = connectionFactory.CreateConnection())
                using (var channel = conn.CreateModel())
                {
                    channel.QueueDeclare(queue: queue,
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    var message = JsonConvert.SerializeObject(new
                    {
                        lancamento.Descricao,
                        lancamento.Conta,
                        lancamento.Banco,
                        lancamento.CpfCnpj,
                        Valor    = lancamento.Valor.ToString(),
                        Encargos = lancamento.Encargos.ToString(),
                        lancamento.Lancamento,
                        lancamento.TipoConta,
                        lancamento.Data
                    });
                    var body = Encoding.UTF8.GetBytes(message);

                    channel.BasicPublish(exchange: "",
                                         routingKey: queue,
                                         basicProperties: null,
                                         body: body);
                }
        }
Ejemplo n.º 6
0
        private void btnSalvarAnexos_Click(object sender, EventArgs e)
        {
            if (gridView1.IsEmptyWarning())
            {
                LancamentoFinanceiro novo = indexarDados();
                if (novo != null)
                {
                    if (new LancamentoDaoManager().SalvarAnexos(novo))
                    {
                        if (_lancAnt == null)
                        {
                            XMessageIts.Mensagem("Anexos salvos com sucesso!");
                        }
                        else
                        {
                            XMessageIts.Mensagem("Anexos atualizados com sucesso!");
                        }

                        if (_lancAnt != null && _lancAnt.StatusLancamento == TypeStatusLancamentoFinanceiro.Pago)
                        {
                            this.Dispose();
                        }
                    }
                }
            }
        }
        public XFrmAssitenteLancamentoFinanceiro(LancamentoFinanceiro lancamentoFinanceiro,
                                                 FormTypeAction action = FormTypeAction.Salvar)
            : this()
        {
            //evitar o erro
            //the entity wrapper stored in the proxy does not reference the same proxy
            //pq ele nao faz parte das opçoes do combo
            lancamentoFinanceiro.StatusLancamento = TypeStatusLancamentoFinanceiro.Aberto;
            //lançamento base
            //nao posso mexer no lançamento do grid
            this._lancamentoAtual = lancamentoFinanceiro.Clone();


            this._lancamentoAtual.IdLancamento = lancamentoFinanceiro.IdLancamento;
            this._lancamentoList         = new List <LancamentoFinanceiro>();
            this.txtTotalLancamento.Text = _lancamentoAtual.TotalLancamento.ToString("N2");
            this._action = action;

            if (action != FormTypeAction.Salvar)
            {
                lblDesId.Visible           = true;
                lblDescVencimento.Visible  = true; lblDescValor.Visible = true;
                lblId.Visible              = true;
                lblDataVencimento.Visible  = true;
                lblTotalLancamento.Visible = true;
            }


            lblId.Text              = lancamentoFinanceiro.IdLancamento.ToString();
            lblDataVencimento.Text  = _lancamentoAtual.DataVencimento.ToShortDateString();
            lblTotalLancamento.Text = _lancamentoAtual.TotalLancamento.ToString("N2");
            //cria uma lancamento utilizando o lançamento base
            this.gerarParcelamento(1, 30);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Put(int lancamentoId, LancamentoFinanceiro model)
        {
            try
            {
                var lancamento = await _repo.GetLancamentoFinanceiroById(lancamentoId);

                if (lancamento == null)
                {
                    return(NotFound());
                }

                if (lancamento.Status == "Conciliado")
                {
                    return(BadRequest(new { id = lancamento.Id, erro = $"O lançamento #{lancamento.Id} já está conciliado e não pode ser deletado!" }));
                }

                _repo.Update(model);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/lancamentofinanceiro/{model.Id}", model));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no banco de dados!"));
            }

            return(BadRequest());
        }
        public void TestesDeMetodos()
        {
            GerarMoqVazio();

            var dadosConsolidados = fluxoDeCaixaService.BuscaDadosConsolidados().Result;
            var dadoConsolidado1  = fluxoDeCaixaService.BuscaDadoConsolidado(DateTime.Now).Result;

            Assert.True(dadosConsolidados.Count() == 31);
            Assert.True(dadoConsolidado1.Data == DateTime.MinValue);
            Assert.ThrowsAny <AggregateException>(() => fluxoDeCaixaService.AdicionarLancamento(null).Result);

            GerarMoqNegativo();

            var lancamento1 = new LancamentoFinanceiro(1, "teste", "1", "237", 1, "421.058-748-60", "R$ 1.000,00", "R$ 12,00", DateTime.Now.ToString("dd-MM-yyyy"));
            var lancamento2 = new LancamentoFinanceiro(2, "teste", "1", "237", 1, "421.058-748-60", "R$ 1.000,00", "R$ 12,00", DateTime.Now.ToString("dd-MM-yyyy"));

            dadoConsolidado1 = fluxoDeCaixaService.AdicionarLancamento(lancamento1).Result;
            var dadoConsolidado2 = fluxoDeCaixaService.AdicionarLancamento(lancamento2).Result;

            Assert.ThrowsAny <System.Exception>(() => fluxoDeCaixaService.EfetuaLancamento(lancamento1).Result);
            Assert.True(dadoConsolidado1 != null);
            Assert.True(dadoConsolidado2 != null);

            GerarMoqPositivo();

            Assert.True(fluxoDeCaixaService.EfetuaLancamento(lancamento1).Result != null);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Editar(int id)
        {
            var lancamento = new LancamentoFinanceiro();

            using (var client = new HttpClient())
            {
                using (var resposta = await client.GetAsync(String.Format("{0}{1}", _options.Value.URILancamentoFinanceiro, id)))
                {
                    if (resposta.IsSuccessStatusCode)
                    {
                        var json = await resposta.Content.ReadAsStringAsync();

                        lancamento = JsonConvert.DeserializeObject <LancamentoFinanceiro>(json);
                        CarregaListas();
                    }
                    else
                    {
                        TempData["Erro"] = "Erro na busca do lançamento para edição";
                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }

            return(View(lancamento));
        }
Ejemplo n.º 11
0
        private void updateItens(BalcaoContext ctx, LancamentoFinanceiro lancamento, LancamentoFinanceiro novo)
        {
            //atualizando os itens atuais
            for (int i = 0; i < lancamento.Anexos.Count; i++)
            {
                var item = lancamento.Anexos.ToList()[i];
                //verifica se o item atual ja esta na nova lista
                var itemAtualizado = novo.Anexos.ToList().Find(x => x.IdAnexo == item.IdAnexo);

                //se ele existe ou vou atualiza-lo
                if (itemAtualizado != null)
                {
                    var a = ctx.AnexoLancamentoDao.Find(itemAtualizado.IdAnexo);

                    //atualiza o item
                    item.Update(itemAtualizado);
                    ctx.AnexoLancamentoDao.Update(a);
                }

                //ele nao existe
                else
                {
                    var a = ctx.AnexoLancamentoDao.Find(item.IdAnexo);
                    // então ele nao faz parte da lista de arquivos
                    //marque o item para ser removido
                    ctx.AnexoLancamentoDao.Delete(a);
                }
            }
            lancamento.QuantidadeAnexos = lancamento.Anexos.Count;
        }
Ejemplo n.º 12
0
 public XFrmAddLancamentoFinanceiro(LancamentoFinanceiro l, Usuario user) : this()
 {
     this._currentUser = user;
     this._lancAnt     = this.indexarDados(l);
     FormsUtil.AddShortcutEscapeOnDispose(this);
     this.btnAssistente.Visible = false;
 }
        private void ValidadeData(LancamentoFinanceiro lancamento)
        {
            var retStr = "";
            var isOk   = true;

            if (!lancamento.DataHoraLancamento.HasValue)
            {
                isOk    = false;
                retStr += "\n-Necessário preencher a data do lançamento";
            }
            if (!lancamento.Valor.HasValue)
            {
                isOk    = false;
                retStr += "\n-Necessário preencher o valor do lançamento";
            }
            if (!lancamento.Tipo.HasValue)
            {
                isOk    = false;
                retStr += "\n-Necessário preencher o tipo do lançamento";
            }

            if (!isOk)
            {
                throw new Exception(retStr);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Recupera o lancamento usando modo EAGER
        /// </summary>
        /// <param name="lan"></param>
        /// <returns></returns>
        public static LancamentoFinanceiro FindCpl(LancamentoFinanceiro lan)
        {
            try
            {
                using (var ctx = new BalcaoContext())
                {
                    ctx.LazyLoading(false);

                    //carregando cliente/anexos do lancamento
                    //carregando o lancamento sempre que visualizar
                    //sai mesmo custoso que carregando todos os anexos diretamente no grid
                    //considerando que havera milhoes de lancamentos
                    //evita uma sobrecarga porem eh mais trabalhoso
                    //mas compensa significativamente em performance
                    LancamentoFinanceiro current = ctx.LancamentosFinanceiros
                                                   .Where(l => l.IdLancamento == lan.IdLancamento)
                                                   .Include(l => l.CliFor)
                                                   .Include(l => l.FormaPagamento)
                                                   .Include(l => l.CentroCusto)
                                                   .Include(l => l.Baixas)
                                                   .Include(l => l.Extratos)
                                                   .Include(l => l.Anexos)
                                                   .Include(l => l.Filial).First();

                    return(current);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public void InserirLancamento(LancamentoFinanceiro lancamentoFinanceiro)
        {
            if (!_lancamentoRepositorio.ExisteTipoLancamento(lancamentoFinanceiro.TipoLancamento.ID))
            {
                throw new Exception(Mensagens.MENSAGEM_NAO_EXISTE_TIPO_LANCAMENTO_CADASTRADRO);
            }

            _lancamentoRepositorio.Inserir(lancamentoFinanceiro);
        }
        public void InserirLancamento(LancamentoFinanceiro lancamentoFinanceiro)
        {
            if (!_lancamentoRepositorio.ExisteTipoLancamento(lancamentoFinanceiro.TipoLancamento.ID))
            {
                throw new Exception("Tipo de lançamento não cadastrado!");
            }

            _lancamentoRepositorio.Inserir(lancamentoFinanceiro);
        }
Ejemplo n.º 17
0
        public void Inserir(LancamentoFinanceiro lancamentoFinanceiro)
        {
            var tipoLancamento = _fluxoCaixaContext.TiposLancamento.FirstOrDefault(_ => _.Id == lancamentoFinanceiro.TipoLancamento.Id);

            lancamentoFinanceiro.TipoLancamento = tipoLancamento;

            _fluxoCaixaContext.LancamentosFinanceiro.Add(lancamentoFinanceiro);

            _fluxoCaixaContext.SaveChanges();
        }
        public LancamentoFinanceiro Atualiza(LancamentoFinanceiro atualizar, LancamentoFinanceiro novosDados)
        {
            atualizar.DataLancamento   = novosDados.DataLancamento == null ? atualizar.DataLancamento : novosDados.DataLancamento;
            atualizar.Valor            = novosDados.Valor == null ? atualizar.Valor : novosDados.Valor;
            atualizar.TipoLancamento   = string.IsNullOrEmpty(novosDados.TipoLancamento) ? atualizar.TipoLancamento : novosDados.TipoLancamento;
            atualizar.StatusLancamento = string.IsNullOrEmpty(novosDados.StatusLancamento) ? atualizar.StatusLancamento : novosDados.StatusLancamento;
            atualizar.IdBalanco        = novosDados.IdBalanco == null ? atualizar.IdBalanco : novosDados.IdBalanco;

            return(atualizar);
        }
Ejemplo n.º 19
0
        public void Atualizar(LancamentoFinanceiro lancamentoFinanceiro)
        {
            var lancamento = _fluxoCaixaContext.LancamentosFinanceiro.FirstOrDefault(_ => _.Id == lancamentoFinanceiro.Id);

            var tipoLancamento = _fluxoCaixaContext.TiposLancamento.FirstOrDefault(_ => _.Id == lancamentoFinanceiro.TipoLancamento.Id);

            lancamento.TipoLancamento = tipoLancamento;
            lancamento.Valor          = lancamentoFinanceiro.Valor;

            _fluxoCaixaContext.SaveChanges();
        }
Ejemplo n.º 20
0
        public async Task <int> Deletar(LancamentoFinanceiro model)
        {
            var modelDeletar = await Consultar(model);

            if (modelDeletar == null || modelDeletar.Status == (int)StatusLancamento.Conciliado)
            {
                throw new ArgumentException("Objeto vazio ou já conciliado");
            }

            return(await _repositorioLancamento.Deletar(model));
        }
Ejemplo n.º 21
0
        public bool SalvarAnexos(LancamentoFinanceiro novo)
        {
            using (var ctx = new BalcaoContext())
            {
                var current = ctx.LancamentoFinanceiroDao.Find(novo.IdLancamento);

                new AnexoDaoManager().UpdateAnexos(ctx, current, novo);

                return(ctx.LancamentoFinanceiroDao.Update(current));
            }
        }
Ejemplo n.º 22
0
        public async Task <int> Cadastrar(LancamentoFinanceiro model)
        {
            if (model == null)
            {
                throw new ArgumentException("Objeto vazio");
            }

            model.DataHoraLancamento = DateTime.Now;

            return(await _repositorioLancamento.Cadastrar(model));
        }
Ejemplo n.º 23
0
        public bool IsSatisfiedBy(LancamentoFinanceiro lancamentoFinanceiro)
        {
            var _lancamentoFinanceiro = _lancamentoFinanceiroRepository.ObterPorId(lancamentoFinanceiro.Id).Result;

            if (_lancamentoFinanceiro.Status == Enums.LancamentoFinanceiro.EStatus.CONCILIADO)
            {
                return(false);
            }

            return(true);
        }
 public bool PodeAtualizarOuApagar(LancamentoFinanceiro lancamento)
 {
     if (lancamento.IdBalanco == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 25
0
        public bool SaveLancamento(LancamentoFinanceiro lancamento)
        {
            using (var ctx = new BalcaoContext())
            {
                //zerando referencias
                lancamento.CentroCusto = null;
                lancamento.CliFor      = null;
                lancamento.Filial      = null;

                return(ctx.LancamentoFinanceiroDao.Save(lancamento));
            }
        }
Ejemplo n.º 26
0
        public void API_Controller_Lancamentos_BuscarLancamentoFinanceiroPorID_Nao_Encontrado()
        {
            //prepare
            LancamentoFinanceiro lancamento = null;

            _lancamentosServicesMock.Setup(_ => _.BuscarLancamentoFinanceiroPorId(It.IsAny <int>())).Returns(lancamento);

            //action
            var retorno = _lancamentosController.BuscarLancamentoFinanceiroPorId(1);

            //assert
            Assert.IsTrue(((StatusCodeResult)retorno).StatusCode == (int)HttpStatusCode.NotFound);
        }
Ejemplo n.º 27
0
        public async Task <AcceptedResult> Post([FromBody] LancamentoFinanceiro lancamento)
        {
            try
            {
                await _financialEntryBusiness.AddToQueue((FinancialEntryEntity)lancamento);

                return(Accepted());
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 28
0
        private void statusView(LancamentoFinanceiro l)
        {
            if (l.StatusLancamento == TypeStatusLancamentoFinanceiro.Pago)
            {
                this.dtEditPagamento.Visible = true;
                this.lblDataPagto.Visible    = true;

                //pago entao tem uma forma de pagamento
                this.cbFormaPagto.AddItem(l.FormaPagamento);
                this.cbFormaPagto.Visible     = true;
                this.lblFrmPagamento.Visible  = true;
                this.dtEditPagamento.DateTime = l.DataPagamento.Value;
            }

            if (l.StatusLancamento == TypeStatusLancamentoFinanceiro.Cancelado)
            {
                richObs.ForeColor = System.Drawing.Color.Red;

                this.richObs.AppendText(this.richObs.Text + "\n\r\n\r");

                if (!string.IsNullOrEmpty(l.MotivoCancelamento))
                {
                    this.richObs.AppendText(l.MotivoCancelamento);
                }

                this.lblCancelamento.Visible     = true;
                this.dtEditCancelamento.DateTime = l.DataCancelamento.Value;
                this.dtEditCancelamento.Visible  = true;
            }


            if (l.StatusLancamento == TypeStatusLancamentoFinanceiro.Cancelado ||
                l.StatusLancamento == TypeStatusLancamentoFinanceiro.Pago ||
                l.IdVenda != null)
            {
                ReadyOnlyMode();
                gridView1.OptionsBehavior.Editable = false;
            }

            else
            {
                this.btnSalvar.Enabled = true;
                this.btnSalvar.Visible = true;
            }

            if (l.StatusLancamento == TypeStatusLancamentoFinanceiro.Aberto ||
                l.StatusLancamento == TypeStatusLancamentoFinanceiro.Vencido)
            {
                this.richObs.ReadOnly = false;
            }
        }
Ejemplo n.º 29
0
        public async Task <int> Editar(LancamentoFinanceiro model)
        {
            var modelAtualizar = await Consultar(model);

            if (modelAtualizar == null || modelAtualizar.Status == (int)StatusLancamento.Conciliado)
            {
                throw new ArgumentException("Objeto vazio ou já conciliado");
            }

            modelAtualizar.Valor  = model.Valor;
            modelAtualizar.Tipo   = model.Tipo;
            modelAtualizar.Status = model.Status;

            return(await _repositorioLancamento.Editar(modelAtualizar));
        }
Ejemplo n.º 30
0
        public void InserirLancamento(LancamentoFinanceiro lancamentoFinanceiro)
        {
            if (lancamentoFinanceiro.EntidadeValida())
            {
                throw new Exception(Mensagens.MENSAGEM_CAMPOS_OBRIGATORIOS_LANCAMENTO);
            }

            if (!_lancamentoRepositorio.ExisteTipoLancamento(lancamentoFinanceiro.TipoLancamento.Id))
            {
                throw new Exception(Mensagens.MENSAGEM_NAO_EXISTE_TIPO_LANCAMENTO_CADASTRADRO);
            }

            lancamentoFinanceiro.SetarValoresPadraoInserir();

            _lancamentoRepositorio.Inserir(lancamentoFinanceiro);
        }