Exemplo n.º 1
0
        public bool ExcluirLancamento(Lancamento lancamento)
        {
            bool ret = true;

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

            if (lancamento.LancamentoId == Guid.Empty)
            {
                return(false);
            }

            try
            {
                using (IDataContextAsync context = new PCFTIDataContext())
                    using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                    {
                        IRepositoryAsync <Lancamento> lancamentoRepository = new Repository <Lancamento>(context, unitOfWork);
                        ILancamentoService            lancamentoService    = new LancamentoService(lancamentoRepository);
                        lancamento.ObjectState = INFRAESTRUTURA.TRANSVERSAL.Core.States.ObjectState.Deleted;
                        lancamentoService.Delete(lancamento.LancamentoId);
                        unitOfWork.SaveChanges();
                        (new Execute()).Sistema.Versao.NovaVersaoParaExclusao(lancamento);
                    }
            }
            catch
            {
                ret = false;
            }
            return(ret);
        }
        public ActionResult Edit(int id, Lancamento lancamento)
        {
            if (lancamento.isContaPagarReceber == true || lancamento.isTransferencia == true)
            {
                return(BadRequest());
            }

            try
            {
                if (ModelState.IsValid)
                {
                    LancamentoService service = new LancamentoService();
                    service.ValidarCampos(lancamento);

                    _lancamento.Atualizar(lancamento);
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(lancamento));
            }
            catch (Exception ex)
            {
                Mensagem = ex.Message.ToString();
                ModelState.AddModelError(String.Empty, Mensagem);
                return(View(lancamento));
            }
        }
        public ActionResult Create(Lancamento lancamento)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    lancamento.EmpresaID = Convert.ToInt32(User.FindFirst(ClaimTypes.GroupSid).Value);

                    LancamentoService service = new LancamentoService();
                    service.PreencherCampos(lancamento);

                    _lancamento.Inserir(lancamento);

                    return(RedirectToAction(nameof(Index)));
                }

                CarregarFornecedores();
                CarregarClientes();
                CarregarCategorias();
                CarregarSubCategorias(0);
                CarregarCentroDeCusto();
                CarregarContaContabil();
                return(View(lancamento));
            }
            catch (Exception ex)
            {
                Mensagem = ex.Message.ToString();
                ModelState.AddModelError(String.Empty, Mensagem);
                return(View(lancamento));
            }
        }
Exemplo n.º 4
0
        public Lancamento CriarNovoLancamento(Lancamento lancamento, bool Atualizar = false)
        {
            if (lancamento == null)
            {
                lancamento = new Lancamento();
                lancamento.LancamentoId = Guid.Empty;
            }

            using (IDataContextAsync context = new PCFTIDataContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Lancamento> lancamentoRepository = new Repository <Lancamento>(context, unitOfWork);
                    ILancamentoService            lancamentoService    = new LancamentoService(lancamentoRepository);
                    if (!ExisteLancamento(lancamento.LancamentoId))
                    {
                        lancamento = lancamentoService.NovoLancamento(lancamento);
                        unitOfWork.SaveChanges();
                    }
                    else if (Atualizar)
                    {
                        lancamento = AtualizarLancamento(lancamento);
                        unitOfWork.SaveChanges();
                    }

                    unitOfWork.Dispose();
                    (new Execute()).Sistema.Versao.NovaVersaoParaCriacao(lancamento);
                }

            return(lancamento);
        }
Exemplo n.º 5
0
 public LancamentoController(CategoriaService categoriaService, CartaoService cartaoService,
                             LancamentoService lancamentoService, UsuarioAutenticado usuarioAutenticado)
 {
     _categoriaService   = categoriaService;
     _cartaoService      = cartaoService;
     _lancamentoService  = lancamentoService;
     _usuarioAutenticado = usuarioAutenticado;
 }
Exemplo n.º 6
0
        public IActionResult Post([FromBody] LancamentoViewModel lancamentoViewModel)
        {
            var service = new LancamentoService(_lancamentoRepository,
                                                _usuarioRepository,
                                                _folhaPontoRepository);

            var retorno = service.InserirLancamento(lancamentoViewModel);

            return(Ok());
        }
 public RelatorioController(PoupancaService poupancaService, UsuarioService usuarioService, LancamentoService lancamentoService, RecebimentoService recebimentoService,
                            UsuarioAutenticado usuarioAutenticado, CategoriaService categoriaService, CartaoService cartaoService)
 {
     _usuarioService     = usuarioService;
     _lancamentoService  = lancamentoService;
     _recebimentoService = recebimentoService;
     _poupancaService    = poupancaService;
     _usuarioAutenticado = usuarioAutenticado;
     _categoriaService   = categoriaService;
     _cartaoService      = cartaoService;
 }
 public UsuarioController(CategoriaService categoriaService, CartaoService cartaoService, MetaService metaService, PoupancaService poupancaService,
                          UsuarioService usuarioService, LancamentoService lancamentoService, RecebimentoService recebimentoService,
                          UserManager <UsuarioLogado> userManager, SignInManager <UsuarioLogado> signInManager, UsuarioAutenticado usuarioAutenticado)
 {
     _usuarioService     = usuarioService;
     _lancamentoService  = lancamentoService;
     _recebimentoService = recebimentoService;
     _categoriaService   = categoriaService;
     _cartaoService      = cartaoService;
     _metaService        = metaService;
     _poupancaService    = poupancaService;
     _userManager        = userManager;
     _signInManager      = signInManager;
     _usuarioAutenticado = usuarioAutenticado;
 }
        public async void Lancamento_Service_AddAsync_Deve_Retornar_Success()
        {
            var contaOrigem = new ContaCorrente(Guid.NewGuid(), 123);

            var lancamentoRepositoryMock = new Mock <ILancamentoRepository>();
            var accRepositoryMock        = new Mock <IContaCorrenteRepository>();

            accRepositoryMock.Setup(x => x.GetAsync(123))
            .ReturnsAsync(new ContaCorrente(contaOrigem.Id, contaOrigem.Numero));

            var _service = new LancamentoService(lancamentoRepositoryMock.Object,
                                                 accRepositoryMock.Object);

            await _service.AddAsync(Guid.NewGuid(), DateTime.UtcNow, 123, 123, 9998);

            lancamentoRepositoryMock.Verify(x => x.AddAsync(It.IsAny <Lancamento>()), Times.Once);
        }
Exemplo n.º 10
0
        public Lancamento AtualizarLancamento(Lancamento lancamento)
        {
            if (lancamento == null)
            {
                return(lancamento);
            }

            using (IDataContextAsync context = new PCFTIDataContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Lancamento> lancamentoRepository = new Repository <Lancamento>(context, unitOfWork);
                    ILancamentoService            lancamentoService    = new LancamentoService(lancamentoRepository);
                    lancamento.ObjectState = INFRAESTRUTURA.TRANSVERSAL.Core.States.ObjectState.Modified;
                    lancamentoService.Update(lancamento);
                    unitOfWork.SaveChanges();
                    unitOfWork.Dispose();
                    (new Execute()).Sistema.Versao.NovaVersaoParaEdicao(lancamento);
                }

            return(lancamento);
        }
Exemplo n.º 11
0
        public Lancamento CarregarLancamento(Guid LancamentoId)
        {
            Lancamento ret = null;

            try
            {
                using (IDataContextAsync context = new PCFTIDataContext())
                    using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                    {
                        IRepositoryAsync <Lancamento> lancamentoRepository = new Repository <Lancamento>(context, unitOfWork);
                        ILancamentoService            lancamentoService    = new LancamentoService(lancamentoRepository);

                        ret = lancamentoService.Find(LancamentoId);
                        unitOfWork.Dispose();
                    }
            }
            catch
            {
                ret = null;
            }
            return(ret);
        }
Exemplo n.º 12
0
        public bool ExisteLancamento(Guid LancamentoId)
        {
            bool ret = false;

            try
            {
                using (IDataContextAsync context = new PCFTIDataContext())
                    using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                    {
                        IRepositoryAsync <Lancamento> lancamentoRepository = new Repository <Lancamento>(context, unitOfWork);
                        ILancamentoService            lancamentoService    = new LancamentoService(lancamentoRepository);

                        ret = (!(lancamentoService.Find(LancamentoId) == null));
                        unitOfWork.Dispose();
                    }
            }
            catch
            {
                ret = false;
            }
            return(ret);
        }
Exemplo n.º 13
0
        public LancamentoServiceTest()
        {
            var contaCorrenteRepository = new Mock <IContaCorrenteRepository>();

            contaCorrenteRepository.Setup(x => x.SelectByNumber("111")).Returns((string i) =>
            {
                return(new ContaCorrente()
                {
                    Id = 1,
                    Numero = "111"
                });
            });

            contaCorrenteRepository.Setup(x => x.SelectByNumber("222")).Returns((string i) =>
            {
                return(new ContaCorrente()
                {
                    Id = 1,
                    Numero = "222"
                });
            });

            var lancamentoRepository = new Mock <ILancamentoRepository>();

            lancamentoRepository.Setup(x => x.Select(1)).Returns((int i) =>
            {
                return(new Lancamento()
                {
                    Id = 1,
                    IDContaOrigem = 1,
                    IDContaDestino = 2,
                    Valor = 200,
                });
            });

            _LancamentoService = new LancamentoService(contaCorrenteRepository.Object, lancamentoRepository.Object);
        }
Exemplo n.º 14
0
 public LancamentoesController(SolNWebAppContext context, LancamentoService lancamentoService, ControleService controleService)
 {
     _context           = context;
     _controleService   = controleService;
     _lancamentoService = lancamentoService;
 }
Exemplo n.º 15
0
        public ActionResult TransferirValores(DateTime txtData, int txtOrigem, int txtDestino, decimal txtValor, string txtDescricao, string txtObservacao)
        {
            try
            {
                var saldoContaOrigem = VerificarSaldoContaOrigem(txtOrigem);

                if (txtValor > saldoContaOrigem)
                {
                    throw new ArgumentException("Saldo insuficiente. Seu saldo na conta origem é de " + saldoContaOrigem.ToString("C"));
                }

                LancamentoService service = new LancamentoService();
                service.ValidarTransferencia(txtData, txtOrigem, txtDestino, txtValor, txtDescricao, txtObservacao);

                #region DEBITANDO A CONTA ORIGEM
                Lancamento lancamentoDebitar = new Lancamento();
                lancamentoDebitar.DataCadastro        = DateTime.Now;
                lancamentoDebitar.DataLancamento      = txtData;
                lancamentoDebitar.ContaContabilID     = txtOrigem;
                lancamentoDebitar.TipoLancamento      = TipoLancamento.Debito;
                lancamentoDebitar.Valor               = txtValor;
                lancamentoDebitar.Descricao           = txtDescricao;
                lancamentoDebitar.CategoriaID         = null;
                lancamentoDebitar.CentroCustoID       = null;
                lancamentoDebitar.ClienteID           = null;
                lancamentoDebitar.DataExclusao        = null;
                lancamentoDebitar.EmpresaID           = Convert.ToInt32(User.FindFirst(ClaimTypes.GroupSid).Value);
                lancamentoDebitar.FlagAtivo           = true;
                lancamentoDebitar.isContaPagarReceber = false;
                lancamentoDebitar.isTransferencia     = true;
                lancamentoDebitar.FornecedorID        = null;
                lancamentoDebitar.Nome            = "Transferência entre contas";
                lancamentoDebitar.NumeroDocumento = new Random().Next(1000000000);
                lancamentoDebitar.Observacoes     = txtObservacao;

                _lancamento.Inserir(lancamentoDebitar);
                #endregion

                #region CREDITANDO A CONTA DESTINO
                Lancamento lancamentoCreditar = new Lancamento();
                lancamentoCreditar.DataCadastro        = DateTime.Now;
                lancamentoCreditar.DataLancamento      = txtData;
                lancamentoCreditar.ContaContabilID     = txtDestino;
                lancamentoCreditar.TipoLancamento      = TipoLancamento.Credito;
                lancamentoCreditar.Valor               = txtValor;
                lancamentoCreditar.Descricao           = txtDescricao;
                lancamentoCreditar.CategoriaID         = null;
                lancamentoCreditar.CentroCustoID       = null;
                lancamentoCreditar.ClienteID           = null;
                lancamentoCreditar.DataExclusao        = null;
                lancamentoCreditar.EmpresaID           = Convert.ToInt32(User.FindFirst(ClaimTypes.GroupSid).Value);
                lancamentoCreditar.FlagAtivo           = true;
                lancamentoCreditar.isContaPagarReceber = false;
                lancamentoCreditar.isTransferencia     = true;
                lancamentoCreditar.FornecedorID        = null;
                lancamentoCreditar.Nome            = "Transferência entre contas";
                lancamentoCreditar.NumeroDocumento = new Random().Next(1000000000);
                lancamentoCreditar.Observacoes     = txtObservacao;

                _lancamento.Inserir(lancamentoCreditar);
                #endregion

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Mensagem = ex.Message.ToString();
                ModelState.AddModelError(String.Empty, Mensagem);
                CarregarContaContabil();
                return(View());
            }
        }
Exemplo n.º 16
0
 public LancamentoTest()
 {
     _service = new LancamentoService(_contaCorrenteRepositoryMock, _lancamentoRepositoryMock);
 }
Exemplo n.º 17
0
 public LancamentoController(LancamentoService lancamentoService)
 {
     _lancamentoService = lancamentoService;
 }