diff options
Diffstat (limited to 'Decompiler/Gestor.Application.Servicos.Financeiro/FinanceiroServico.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.Servicos.Financeiro/FinanceiroServico.cs | 789 |
1 files changed, 789 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Servicos.Financeiro/FinanceiroServico.cs b/Decompiler/Gestor.Application.Servicos.Financeiro/FinanceiroServico.cs new file mode 100644 index 0000000..e57fb32 --- /dev/null +++ b/Decompiler/Gestor.Application.Servicos.Financeiro/FinanceiroServico.cs @@ -0,0 +1,789 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Generic; +using Gestor.Infrastructure.UnitOfWork.Generic; +using Gestor.Infrastructure.UnitOfWork.Logic; +using Gestor.Model.API; +using Gestor.Model.Common; +using Gestor.Model.Domain.Common; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Financeiro.Relatorios; +using Gestor.Model.Domain.Generic; + +namespace Gestor.Application.Servicos.Financeiro; + +public class FinanceiroServico : BaseServico +{ + public async Task<bool> TemLancamentosPorFornecedor(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.HasByFornecedor(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)154, tries, id); + } + } + return false; + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPorFornecedor(long id, StatusLancamento status) + { + //IL_001e: Unknown result type (might be due to invalid IL or missing references) + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + int tries = 3; + return await Task.Run(delegate + { + //IL_0074: Unknown result type (might be due to invalid IL or missing references) + //IL_0019: Unknown result type (might be due to invalid IL or missing references) + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindByFornecedor(id, status) + orderby x.Vencimento descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)157, tries, new { id, status }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPorFornecedor(long id, DateTime date, Sinal sinal) + { + //IL_0026: Unknown result type (might be due to invalid IL or missing references) + //IL_0027: Unknown result type (might be due to invalid IL or missing references) + int tries = 3; + return await Task.Run(delegate + { + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindByFornecedor(id, date, sinal) + orderby x.Vencimento descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)157, tries, new { id, date }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPorControle(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.FindByControle(id, (StatusLancamento)2); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)158, tries, new { id }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentos(DateTime inicio, DateTime fim, StatusLancamento status) + { + //IL_0026: Unknown result type (might be due to invalid IL or missing references) + //IL_0027: Unknown result type (might be due to invalid IL or missing references) + int tries = 3; + return await Task.Run(delegate + { + //IL_0080: Unknown result type (might be due to invalid IL or missing references) + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.Find(inicio, fim, status) + orderby x.Vencimento descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)160, tries, new { inicio, fim, status }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPorLancamento(DateTime inicio, DateTime fim, StatusLancamento status) + { + //IL_0026: Unknown result type (might be due to invalid IL or missing references) + //IL_0027: Unknown result type (might be due to invalid IL or missing references) + int tries = 3; + return await Task.Run(delegate + { + //IL_0080: Unknown result type (might be due to invalid IL or missing references) + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindByLancamento(inicio, fim, status) + orderby x.DataLancamento descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)329, tries, new { inicio, fim, status }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentos(DateTime inicio, DateTime fim, long conta) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindLancamentosByConta(inicio, fim, conta) + orderby x.Vencimento descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)165, tries, new { inicio, fim, conta }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPersonalizados(DateTime inicio, DateTime fim, StatusLancamento status, FiltroLancamentoData filtrodata) + { + //IL_0026: Unknown result type (might be due to invalid IL or missing references) + //IL_0027: Unknown result type (might be due to invalid IL or missing references) + //IL_002e: Unknown result type (might be due to invalid IL or missing references) + //IL_0030: Unknown result type (might be due to invalid IL or missing references) + int tries = 3; + return await Task.Run(delegate + { + //IL_0086: Unknown result type (might be due to invalid IL or missing references) + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + //IL_0025: Unknown result type (might be due to invalid IL or missing references) + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindPersonalizado(inicio, fim, status, filtrodata) + orderby x.Vencimento descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)160, tries, new { inicio, fim, status }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPorBaixa(DateTime inicio, DateTime fim) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindByBaixa(inicio, fim) + orderby x.Baixa descending + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)161, tries, new { inicio, fim }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<List<Lancamento>> BuscarLancamentosPorPagamento(DateTime inicio, DateTime fim) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.LancamentoRepository.FindByPagamento(inicio, fim) + orderby x.Pagamento + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)162, tries, new { inicio, fim }); + } + } + return new List<Lancamento>(); + }); + } + + public async Task<Lancamento> Save(Lancamento lancamento) + { + int tries = 3; + base.Sucesso = true; + DateTime now = Funcoes.GetNetworkTime(); + Lancamento lancamentoOriginal = lancamento; + return await Task.Run((Func<Lancamento>)delegate + { + while (tries > 0) + { + List<RegistroLog> list = new List<RegistroLog>(); + lancamento = lancamentoOriginal; + try + { + UnitOfWork commited = Instancia.Commited; + try + { + int num; + if (((DomainBase)lancamento).Id != 0L) + { + num = 1; + if (num != 0) + { + goto IL_0047; + } + } + else + { + num = 0; + } + lancamento.DataLancamento = now; + goto IL_0047; + IL_0047: + if (num == 1) + { + list.Add(CreateLog(((DomainBase)lancamento).Id, lancamento, (TipoTela)25)); + } + ControleFinanceiro controle = lancamento.Controle; + controle = ((((DomainBase)controle).Id == 0L) ? commited.ControleFinanceiroRepository.SaveOrUpdate(controle) : commited.ControleFinanceiroRepository.Merge(controle)); + lancamento.Controle = controle; + lancamento = ((((DomainBase)lancamento).Id == 0L) ? commited.LancamentoRepository.SaveOrUpdate(lancamento) : commited.LancamentoRepository.Merge(lancamento)); + if (num == 0) + { + list.Add(CreateLog(((DomainBase)lancamento).Id, ((DomainBase)lancamento).GetValorOriginal(), (TipoTela)25, (TipoAcao)0)); + } + SaveLog(list, commited); + ((GenericUnitOfWork)commited).Commit(); + return lancamento; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)279, tries, lancamento); + } + } + return lancamentoOriginal; + }); + } + + public async Task<List<Lancamento>> AddRange(List<Lancamento> lancamentos) + { + int tries = 3; + base.Sucesso = true; + DateTime now = Funcoes.GetNetworkTime(); + List<Lancamento> lancamentosOriginal = lancamentos; + return await Task.Run(delegate + { + while (tries > 0) + { + List<RegistroLog> logs = new List<RegistroLog>(); + lancamentos = lancamentosOriginal; + try + { + UnitOfWork commited = Instancia.Commited; + try + { + ControleFinanceiro controle = lancamentos.First().Controle; + controle = ((((DomainBase)controle).Id == 0L) ? commited.ControleFinanceiroRepository.SaveOrUpdate(controle) : commited.ControleFinanceiroRepository.Merge(controle)); + lancamentos.ForEach(delegate(Lancamento x) + { + x.Controle = controle; + x.DataLancamento = now; + }); + lancamentos = commited.LancamentoRepository.AddRange(lancamentos); + lancamentos.ForEach(delegate(Lancamento x) + { + logs.Add(CreateLog(((DomainBase)x).Id, ((DomainBase)x).GetValorOriginal(), (TipoTela)25, (TipoAcao)0)); + }); + SaveLog(logs, commited); + ((GenericUnitOfWork)commited).Commit(); + return lancamentos; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)279, tries, lancamentos); + } + } + return lancamentosOriginal; + }); + } + + public async Task<List<Lancamento>> Atualizar(List<Lancamento> lancamentos) + { + int tries = 3; + base.Sucesso = true; + Funcoes.GetNetworkTime(); + List<Lancamento> lancamentosOriginal = lancamentos; + return await Task.Run(delegate + { + while (tries > 0) + { + List<RegistroLog> logs = new List<RegistroLog>(); + lancamentos = lancamentosOriginal; + try + { + UnitOfWork unitOfWork = Instancia.Commited; + try + { + lancamentos.ForEach(delegate(Lancamento lancamento) + { + logs.Add(CreateLog(((DomainBase)lancamento).Id, lancamento, (TipoTela)25)); + lancamento.Controle = unitOfWork.ControleFinanceiroRepository.Merge(lancamento.Controle); + lancamento = unitOfWork.LancamentoRepository.Merge(lancamento); + }); + SaveLog(logs, unitOfWork); + ((GenericUnitOfWork)unitOfWork).Commit(); + return lancamentos; + } + finally + { + if (unitOfWork != null) + { + ((IDisposable)unitOfWork).Dispose(); + } + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)280, tries, lancamentos); + } + } + return lancamentosOriginal; + }); + } + + public async Task<List<Lancamento>> IncluirRange(List<Lancamento> lancamentos) + { + int tries = 3; + base.Sucesso = true; + Funcoes.GetNetworkTime(); + List<Lancamento> lancamentosOriginal = lancamentos; + return await Task.Run(delegate + { + while (tries > 0) + { + List<RegistroLog> logs = new List<RegistroLog>(); + lancamentos = lancamentosOriginal; + try + { + UnitOfWork unitOfWork = Instancia.Commited; + try + { + lancamentos.ForEach(delegate(Lancamento lancamento) + { + lancamento.Controle = unitOfWork.ControleFinanceiroRepository.Merge(lancamento.Controle); + lancamento = unitOfWork.LancamentoRepository.SaveOrUpdate(lancamento); + logs.Add(CreateLog(((DomainBase)lancamento).Id, ((DomainBase)lancamento).GetValorOriginal(), (TipoTela)25, (TipoAcao)0)); + }); + SaveLog(logs, unitOfWork); + ((GenericUnitOfWork)unitOfWork).Commit(); + return lancamentos; + } + finally + { + if (unitOfWork != null) + { + ((IDisposable)unitOfWork).Dispose(); + } + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)281, tries, lancamentos); + } + } + return lancamentosOriginal; + }); + } + + public async Task<Lancamento> BuscarLancamento(long id, int parcela) + { + int tries = 3; + return await Task.Run((Func<Lancamento>)delegate + { + //IL_0068: Unknown result type (might be due to invalid IL or missing references) + //IL_006e: Expected O, but got Unknown + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.FindByControle(id, parcela); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)163, tries, new { id, parcela }); + } + } + return new Lancamento(); + }); + } + + public async Task<Lancamento> BuscarLancamento(long id) + { + int tries = 3; + return await Task.Run((Func<Lancamento>)delegate + { + //IL_005c: Unknown result type (might be due to invalid IL or missing references) + //IL_0062: Expected O, but got Unknown + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.FindById(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)164, tries, id); + } + } + return new Lancamento(); + }); + } + + public async Task<bool> Excluir(List<Lancamento> lancamentos) + { + int tries = 3; + Funcoes.GetNetworkTime(); + return await Task.Run(delegate + { + while (tries > 0) + { + List<RegistroLog> logs = new List<RegistroLog>(); + try + { + UnitOfWork unitOfWork = Instancia.Commited; + try + { + lancamentos.ForEach(delegate(Lancamento x) + { + bool num = unitOfWork.LancamentoRepository.FindByControle(((DomainBase)x.Controle).Id, (StatusLancamento)2).Count == 1; + logs.Add(CreateLog(((DomainBase)x).Id, ((DomainBase)x).GetValorOriginal(), (TipoTela)25, (TipoAcao)2)); + if (num) + { + unitOfWork.ControleFinanceiroRepository.Delete(((DomainBase)x.Controle).Id); + } + else + { + x.Controle.Parcelas = x.Controle.Parcelas - 1; + unitOfWork.ControleFinanceiroRepository.Merge(x.Controle); + unitOfWork.LancamentoRepository.Delete(((DomainBase)x).Id); + } + }); + SaveLog(logs, unitOfWork); + ((GenericUnitOfWork)unitOfWork).Commit(); + } + finally + { + if (unitOfWork != null) + { + ((IDisposable)unitOfWork).Dispose(); + } + } + return true; + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)282, tries, lancamentos); + } + } + return false; + }); + } + + public async Task<bool> Excluir(Lancamento lancamento) + { + int tries = 3; + Funcoes.GetNetworkTime(); + return await Task.Run(delegate + { + while (tries > 0) + { + List<RegistroLog> list = new List<RegistroLog>(); + try + { + UnitOfWork commited = Instancia.Commited; + try + { + bool num = commited.LancamentoRepository.FindByControle(((DomainBase)lancamento.Controle).Id, (StatusLancamento)2).Count == 1; + list.Add(CreateLog(((DomainBase)lancamento).Id, ((DomainBase)lancamento).GetValorOriginal(), (TipoTela)25, (TipoAcao)2)); + if (num) + { + commited.ControleFinanceiroRepository.Delete(((DomainBase)lancamento.Controle).Id); + } + else + { + lancamento.Controle.Parcelas = lancamento.Controle.Parcelas - 1; + commited.ControleFinanceiroRepository.Merge(lancamento.Controle); + commited.LancamentoRepository.Delete(((DomainBase)lancamento).Id); + } + SaveLog(list, commited); + ((GenericUnitOfWork)commited).Commit(); + return true; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)282, tries, lancamento); + } + } + return false; + }); + } + + public async Task<List<ExtratoConta>> BuscarLancamentosPorConta(DateTime inicio, DateTime fim, long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.FindByConta(inicio, fim, id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)165, tries, new { inicio, fim, id }); + } + } + return new List<ExtratoConta>(); + }); + } + + public async Task<bool> Transferir(Lancamento lancamentoOrigem, Lancamento lancamentoDestino) + { + int tries = 3; + Lancamento lancamentoOrigemOriginal = lancamentoOrigem; + Lancamento lancamentoDestinoOriginal = lancamentoDestino; + Funcoes.GetNetworkTime(); + return await Task.Run(delegate + { + while (tries > 0) + { + List<RegistroLog> list = new List<RegistroLog>(); + lancamentoOrigem = lancamentoOrigemOriginal; + lancamentoDestino = lancamentoDestinoOriginal; + try + { + UnitOfWork commited = Instancia.Commited; + try + { + ControleFinanceiro controle = lancamentoOrigem.Controle; + controle = commited.ControleFinanceiroRepository.SaveOrUpdate(controle); + lancamentoOrigem.Controle = controle; + lancamentoDestino.Controle = controle; + lancamentoOrigem = commited.LancamentoRepository.SaveOrUpdate(lancamentoOrigem); + lancamentoDestino = commited.LancamentoRepository.SaveOrUpdate(lancamentoDestino); + list.Add(CreateLog(((DomainBase)lancamentoOrigem).Id, ((DomainBase)lancamentoOrigem).GetValorOriginal(), (TipoTela)25, (TipoAcao)0)); + list.Add(CreateLog(((DomainBase)lancamentoDestino).Id, ((DomainBase)lancamentoDestino).GetValorOriginal(), (TipoTela)25, (TipoAcao)0)); + SaveLog(list, commited); + ((GenericUnitOfWork)commited).Commit(); + return true; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)283, tries, new { lancamentoOrigem, lancamentoDestino }); + } + } + return false; + }); + } + + public async Task<List<Lancamento>> BuscarFechamento(FiltroFinanceiro filtro) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.Fechamento(filtro); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)294, tries, filtro); + } + } + return new List<Lancamento>(); + }); + } +} |