Example #1
0
        public bool AlterarLancamento(LancamentoEntity entity)
        {
            bool returnIncluirLancamento = false;

            try
            {
                Lancamento obj = new Lancamento()
                {
                    dtCadastroLancamento   = entity.dtCadastroLancamento,
                    dtEfetivacaoLancamento = entity.dtEfetivacaoLancamento,
                    idLancamento           = entity.idLancamento,
                    idTipoLanmento         = entity.idTipoLanmento,
                    Observacao             = entity.Observacao,
                    Situacao = entity.Situacao,
                    Valor    = entity.Valor
                };


                returnIncluirLancamento = new LancamentoRepository().AtualizarLancamento(obj);
            }
            catch (Exception ex)
            {
                returnIncluirLancamento = false;

                throw ex;
            }

            return(returnIncluirLancamento);
        }
        public bool RealizaTransferencia(TransferEntity transfer)
        {
            const string proc = "sp_Lancamento_Transfer";

            var transferContas = VerificaContas(transfer);

            if (transferContas != null)
            {
                LancamentoEntity lancto = new LancamentoEntity()
                {
                    ContaCorrenteOriId = transferContas.ContaCorrenteOriId,
                    ContaCorrenteDesId = transferContas.ContaCorrenteDesId,
                    Valor = transfer.Valor
                };

                var paramContaOrigem           = DataHelperParameters.CreateParameter("@FromContaCorrenteId", lancto.ContaCorrenteOriId);
                var paramContaDestino          = DataHelperParameters.CreateParameter("@ToContaCorrenteId", lancto.ContaCorrenteDesId);
                var paramContaOrigemSaldoAtual = DataHelperParameters.CreateParameter("@Valor", lancto.Valor);

                return(_unitOfWork.Get <bool>(proc, paramContaOrigem, paramContaDestino));
            }
            else
            {
                return(false);
            }
        }
Example #3
0
 public void Update(LancamentoEntity lancamento)
 {
     try
     {
         OpenConnection();
         using (cmd = new SqlCommand("", con))
         {
             cmd.CommandText = "fin.UP_LANCAMENTO_ATUALIZAR";
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value                        = lancamento.Id;
             cmd.Parameters.Add(new SqlParameter("@DESCRICAO", SqlDbType.VarChar)).Value             = lancamento.Descricao;
             cmd.Parameters.Add(new SqlParameter("@CUSTO_FIXO", SqlDbType.Bit)).Value                = lancamento.CustoFixo;
             cmd.Parameters.Add(new SqlParameter("@VALOR", SqlDbType.Money)).Value                   = lancamento.Valor;
             cmd.Parameters.Add(new SqlParameter("@DATA_LANCAMENTO", SqlDbType.SmallDateTime)).Value = lancamento.DataLancamento;
             cmd.Parameters.Add(new SqlParameter("@FECHAMENTO_ID", SqlDbType.Int)).Value             = lancamento.Fechamento.Id;
             cmd.Parameters.Add(new SqlParameter("@CLIENTE_ID", SqlDbType.Int)).Value                = lancamento.Cliente.Id;
             cmd.Parameters.Add(new SqlParameter("@CONTA_BANCARIA_ID", SqlDbType.Int)).Value         = lancamento.ContaBancaria.Id;
             cmd.Parameters.Add(new SqlParameter("@CENTRO_CUSTO_ID", SqlDbType.Int)).Value           = lancamento.CentroCusto.Id;
             cmd.Parameters.Add(new SqlParameter("@CATEGORIA_ID", SqlDbType.Int)).Value              = lancamento.Categoria.Id;
             cmd.Parameters.Add(new SqlParameter("@FORNECEDOR_ID", SqlDbType.Int)).Value             = lancamento.Fornecedor.Id;
             cmd.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         CloseConnection();
     }
 }
        public async Task LancamentoCrud()
        {
            using (var context = _serviceProvide.GetService <MyContext>())
            {
                LancamentoImplementation _repositorioLancamento = new LancamentoImplementation(context);
                ContaImplementation      _repositorioConta      = new ContaImplementation(context);

                ContaEntity _entityConta = new ContaEntity
                {
                    Name        = Faker.Name.FullName(),
                    Description = "Conta Corrente",
                    Balance     = 0,
                    Status      = true
                };

                var _registroContaCriado = await _repositorioConta.InsertAsync(_entityConta);

                Assert.NotNull(_registroContaCriado);
                Assert.Equal(_entityConta.Name, _registroContaCriado.Name);


                LancamentoEntity _entityLancamento = new LancamentoEntity
                {
                    ContaId     = _registroContaCriado.Id,
                    Description = "Crédito em conta",
                    Value       = 100
                };

                var _registroCriado = await _repositorioLancamento.InsertLancamento(_entityLancamento, _entityConta);

                Assert.NotNull(_registroCriado);
                Assert.Equal(_entityLancamento.ContaId, _registroCriado.ContaId);
                Assert.Equal(_entityLancamento.Description, _registroCriado.Description);
                Assert.Equal(_entityLancamento.Value, _registroCriado.Value);

                var _registroSelecionado = await _repositorioLancamento.SelectAsync(_registroCriado.Id);

                Assert.NotNull(_registroSelecionado);
                Assert.Equal(_registroCriado.Description, _registroSelecionado.Description);
                Assert.Equal(_registroCriado.Id, _registroSelecionado.Id);

                var _todosRegistros = await _repositorioLancamento.SelectAsync();

                Assert.NotNull(_todosRegistros);
                Assert.True(_todosRegistros.Count() > 0);
            }
        }
Example #5
0
        public static List <string> ValidationRules(LancamentoEntity lancto)
        {
            List <string> errors = new List <string>();

            if (lancto.ContaCorrenteOriId <= 0)
            {
                errors.Add(ReturnMessage.ContaOrigem_Obrigatorio);
            }
            if (lancto.ContaCorrenteDesId <= 0)
            {
                errors.Add(ReturnMessage.ContaDestino_Obrigatorio);
            }
            if (lancto.Valor <= 0)
            {
                errors.Add(ReturnMessage.Valor_Obrigatorio);
            }

            return(errors);
        }
Example #6
0
        public async Task <bool> PostTransfer(ContaTransferenciaDtoCreate transferencia)
        {
            var contaOrigem = await _repository.SelectAsync(transferencia.ContaIdOrigem);

            if (contaOrigem == null)
            {
                throw new Exception("Conta do remetente não encontrada!");
            }

            var contaDestino = await _repository.SelectAsync(transferencia.ContaIdDestino);

            if (contaDestino == null)
            {
                throw new Exception("Conta de destino não encontrada!");
            }

            contaOrigem.Balance  -= transferencia.ValorTransferencia;
            contaDestino.Balance += transferencia.ValorTransferencia;

            LancamentoEntity lancamentoDebito  = new LancamentoEntity();
            LancamentoEntity lancamentoCredito = new LancamentoEntity();

            lancamentoDebito.Id          = Guid.NewGuid();
            lancamentoDebito.ContaId     = contaOrigem.Id;
            lancamentoDebito.Value       = transferencia.ValorTransferencia;
            lancamentoDebito.Description = $"Transfência entre contas - CC Destino: {contaDestino.Id} R$: {transferencia.ValorTransferencia}";

            lancamentoCredito.Id          = Guid.NewGuid();
            lancamentoCredito.ContaId     = contaDestino.Id;
            lancamentoCredito.Value       = transferencia.ValorTransferencia;
            lancamentoCredito.Description = $"Transfência entre contas - CC Origem: {contaOrigem.Id} R$: {transferencia.ValorTransferencia}";

            var result = await _repository.InsertTransfer(contaOrigem, contaDestino, lancamentoDebito, lancamentoCredito);

            return(result);
        }
Example #7
0
 public void Update(LancamentoEntity lancamento) => new LancamentoRepository().Update(lancamento);
Example #8
0
 public void Insert(LancamentoEntity lancamento) => new LancamentoRepository().Insert(lancamento);
        public async Task <bool> InsertTransfer(ContaEntity contaOrigem, ContaEntity contaDestino, LancamentoEntity lancamentoDebito, LancamentoEntity lancamentoCredito)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    _dataset.Update(contaOrigem);
                    _dataset.Update(contaDestino);

                    _context.Entry(lancamentoDebito).State  = EntityState.Added;
                    _context.Entry(lancamentoCredito).State = EntityState.Added;

                    await _context.SaveChangesAsync();

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Example #10
0
        private bool  ValidarDadosEntrada(ContaCorrenteEntity contaCorrenteDestino, ContaCorrenteEntity contaCorrenteOrigem, LancamentoEntity oLancamento)
        {
            bool bValidador = false;


            if (contaCorrenteDestino != null)
            {
                bValidador = true;
            }
            else
            {
                bValidador = false;
            }

            if (contaCorrenteOrigem != null)
            {
                bValidador = true;
            }
            else
            {
                bValidador = true;
            }
            if (oLancamento != null)
            {
                bValidador = true;
            }

            return(bValidador);
        }
Example #11
0
        public bool ProcessarLancamento(ContaCorrenteEntity contaCorrenteDestino, ContaCorrenteEntity contaCorrenteOrigem, LancamentoEntity oLancamento, string strObj)
        {
            bool bValidar = ValidarDadosEntrada(contaCorrenteDestino, contaCorrenteOrigem, oLancamento);

            if (bValidar == true)
            {
                bValidar = new LancamentoBusiness().IncluirLancamento(oLancamento);

                new LogBusiness().IncluirLog(new LogEntity()
                {
                    dtLog       = DateTime.Now,
                    idOperacao  = 1,
                    JsaonObject = strObj,
                    Log         = "O processamento foi efetuado com sucesso"
                });
            }
            else
            {
                bValidar = false;
            }

            return(bValidar);
        }
Example #12
0
 public LancamentoEntity GetById(int id)
 {
     try
     {
         OpenConnection();
         using (cmd = new SqlCommand("", con))
         {
             cmd.CommandText = "fin.UP_LANCAMENTO_BUSCAR";
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = id;
             dr = cmd.ExecuteReader();
             LancamentoEntity lancamento = null;
             if (dr.HasRows)
             {
                 while (dr.Read())
                 {
                     lancamento = new LancamentoEntity()
                     {
                         Id                      = Convert.ToInt32(dr["ID"]),
                         Ativo                   = Convert.ToBoolean(dr["ATIVO"]),
                         Descricao               = dr["DESCRICAO"].ToString(),
                         DataLancamento          = Convert.ToDateTime(dr["DATA_LANCAMENTO"]),
                         DataLancamentoFormatada = dr["DATA_LANCAMENTO_FORMATADA"].ToString(),
                         Valor                   = Convert.ToDecimal(dr["VALOR"]),
                         CustoFixo               = Convert.ToBoolean(dr["CUSTO_FIXO"]),
                         Categoria               = new CategoriaEntity()
                         {
                             Id   = Convert.ToInt32(dr["CATEGORIA_ID"]),
                             Nome = dr["CATEGORIA_NOME"].ToString()
                         },
                         CentroCusto = new CentroCustoEntity()
                         {
                             Id   = Convert.ToInt32(dr["CENTRO_CUSTO_ID"]),
                             Nome = dr["CENTRO_CUSTO_NOME"].ToString()
                         },
                         Cliente = new ClienteEntity()
                         {
                             Id   = Convert.ToInt32(dr["CLIENTE_ID"]),
                             Nome = dr["CLIENTE_NOME"].ToString()
                         },
                         ContaBancaria = new ContaBancariaEntity()
                         {
                             Id   = Convert.ToInt32(dr["CONTA_BANCARIA_ID"]),
                             Nome = dr["CONTA_BANCARIA_NOME"].ToString()
                         },
                         Fechamento = new Entity.Acompanhamento.FechamentoEntity()
                         {
                             Id = Convert.ToInt32(dr["FECHAMENTO_ID"])
                         },
                         Fornecedor = new FornecedorEntity()
                         {
                             Id   = Convert.ToInt32(dr["FORNECEDOR_ID"]),
                             Nome = dr["FORNECEDOR_NOME"].ToString()
                         }
                     };
                 }
             }
             return(lancamento);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         CloseConnection();
     }
 }