From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../ViewModels/Financeiro/BancosContasViewModel.cs | 604 ++ .../Financeiro/CentroDeCustoViewmodel.cs | 255 + .../ViewModels/Financeiro/ContasDialogModel.cs | 48 + .../Financeiro/CopiarClienteViewModel.cs | 28 + .../ViewModels/Financeiro/ExtratoContaViewModel.cs | 552 ++ .../ViewModels/Financeiro/FinanceiroViewModel.cs | 5973 ++++++++++++++++++++ .../ViewModels/Financeiro/FornecedorViewModel.cs | 780 +++ .../ViewModels/Financeiro/InfoExtratoViewModel.cs | 81 + .../Financeiro/MenuFinanceiroViewModel.cs | 30 + .../ViewModels/Financeiro/PlanoViewModel.cs | 147 + .../ViewModels/Financeiro/PlanosViewModel.cs | 330 ++ .../Relatorios/FechamentoFinanceiroViewModel.cs | 2746 +++++++++ .../ViewModels/Financeiro/TranferenciaViewModel.cs | 99 + 13 files changed, 11673 insertions(+) create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/BancosContasViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/ContasDialogModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/CopiarClienteViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/ExtratoContaViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/FinanceiroViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/FornecedorViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/InfoExtratoViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/MenuFinanceiroViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/PlanosViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/Relatorios/FechamentoFinanceiroViewModel.cs create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/TranferenciaViewModel.cs (limited to 'Codemerx/Gestor.Application/ViewModels/Financeiro') diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/BancosContasViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/BancosContasViewModel.cs new file mode 100644 index 0000000..e83a4eb --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/BancosContasViewModel.cs @@ -0,0 +1,604 @@ +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; +using Gestor.Model.Helper; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class BancosContasViewModel : BaseFinanceiroViewModel + { + private readonly BancosContasServico _bancosContasServico; + + public Gestor.Model.Domain.Financeiro.BancosContas CancelBancosContas; + + private long _ultimoId; + + private Gestor.Model.Domain.Financeiro.BancosContas _selectedBancosContas; + + private SolidColorBrush _corDoSaldo = new SolidColorBrush(Colors.Green); + + private ObservableCollection _bancosContasFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + private ObservableCollection _saldos = new ObservableCollection(); + + private bool _habilitarFecharSaldo; + + private Saldo _selectedSaldo = new Saldo(); + + private string _saldoAtual; + + private decimal? _valorAbertura; + + private DateTime? _dataAbertura; + + private bool _incluindo; + + public List BancosContas + { + get; + set; + } + + public ObservableCollection BancosContasFiltrados + { + get + { + return this._bancosContasFiltrados; + } + set + { + this._bancosContasFiltrados = value; + this.IsExpanded = (value != null ? value.Count > 0 : false); + base.OnPropertyChanged("BancosContasFiltrados"); + } + } + + public SolidColorBrush CorDoSaldo + { + get + { + return this._corDoSaldo; + } + set + { + this._corDoSaldo = value; + base.OnPropertyChanged("CorDoSaldo"); + } + } + + public DateTime? DataAbertura + { + get + { + return this._dataAbertura; + } + set + { + this._dataAbertura = value; + base.OnPropertyChanged("DataAbertura"); + } + } + + public bool HabilitarFecharSaldo + { + get + { + return this._habilitarFecharSaldo; + } + set + { + this._habilitarFecharSaldo = value; + base.OnPropertyChanged("HabilitarFecharSaldo"); + } + } + + public bool Incluindo + { + get + { + return this._incluindo; + } + set + { + this._incluindo = value; + base.OnPropertyChanged("Incluindo"); + } + } + + public bool IsExpanded + { + get + { + return this._isExpanded; + } + set + { + this._isExpanded = value; + base.OnPropertyChanged("IsExpanded"); + } + } + + public string SaldoAtual + { + get + { + return this._saldoAtual; + } + set + { + this._saldoAtual = value; + base.OnPropertyChanged("SaldoAtual"); + } + } + + public ObservableCollection Saldos + { + get + { + return this._saldos; + } + set + { + this._saldos = value; + if (value != null && value.Count > 0) + { + this.SelectedSaldo = value.FirstOrDefault((Saldo x) => !x.get_DataFinal().HasValue); + if (this.SelectedSaldo == null) + { + this.UltimoSladoNaoAberto(); + } + } + base.OnPropertyChanged("Saldos"); + } + } + + public Gestor.Model.Domain.Financeiro.BancosContas SelectedBancosContas + { + get + { + return this._selectedBancosContas; + } + set + { + long? nullable; + this._selectedBancosContas = value; + this.CarregarSaldos(value); + if (value != null) + { + nullable = new long?(value.get_Id()); + } + else + { + nullable = null; + } + base.VerificarEnables(nullable); + this.Incluindo = (value == null ? false : value.get_Id() == (long)0); + base.OnPropertyChanged("SelectedBancosContas"); + } + } + + public Saldo SelectedSaldo + { + get + { + return this._selectedSaldo; + } + set + { + bool id; + this._selectedSaldo = value; + if (value == null || value.get_DataFinal().HasValue) + { + id = false; + } + else + { + Usuario usuario = Recursos.Usuario; + if (usuario != null) + { + id = usuario.get_Id() > (long)0; + } + else + { + id = false; + } + } + this.HabilitarFecharSaldo = id; + base.OnPropertyChanged("SelectedSaldo"); + Saldo selectedSaldo = this.SelectedSaldo; + if (selectedSaldo == null) + { + return; + } + selectedSaldo.Initialize(); + } + } + + public decimal? ValorAbertura + { + get + { + return this._valorAbertura; + } + set + { + this._valorAbertura = value; + base.OnPropertyChanged("ValorAbertura"); + } + } + + public BancosContasViewModel() + { + this._bancosContasServico = new BancosContasServico(); + this.Seleciona(); + } + + public async Task CalcularValor() + { + decimal? valorFinal = await this._bancosContasServico.FecharSaldo(this.SelectedSaldo).get_ValorFinal(); + return valorFinal.GetValueOrDefault(); + } + + public async void CancelarAlteracao() + { + base.Loading(true); + if (this.SelectedBancosContas.get_Id() > (long)0) + { + await this.SelecionaBancosDeContas(); + } + BancosContasViewModel bancosContasViewModel = this; + Gestor.Model.Domain.Financeiro.BancosContas bancosConta = this.BancosContasFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.BancosContas x) => x.get_Id() == this._ultimoId); + if (bancosConta == null) + { + bancosConta = this.BancosContasFiltrados.FirstOrDefault(); + } + bancosContasViewModel.SelecionaBancosContas(bancosConta); + base.Alterar(false); + base.Loading(false); + } + + public async void CarregarSaldos(Gestor.Model.Domain.Financeiro.BancosContas banco) + { + if (banco != null && banco.get_Id() != 0) + { + List saldos = await this._bancosContasServico.BuscarSaldos(banco.get_Id()); + this.CorDoSaldo = new SolidColorBrush(Colors.Green); + this.SaldoAtual = string.Empty; + BancosContasViewModel observableCollection = this; + List saldos1 = saldos; + observableCollection.Saldos = new ObservableCollection( + from x in saldos1 + orderby x.get_DataInicio() descending + select x); + if (this.Saldos.FirstOrDefault() != null) + { + Saldo saldo = new Saldo(); + saldo.set_Conta(this.Saldos.First().get_Conta()); + saldo.set_ValorInicio(this.Saldos.First().get_ValorInicio()); + saldo.set_DataInicio(this.Saldos.First().get_DataInicio()); + saldo.set_DataFinal(new DateTime?(Funcoes.GetNetworkTime())); + Saldo saldo1 = saldo; + saldo1 = await this._bancosContasServico.FecharSaldo(saldo1); + decimal? valorFinal = saldo1.get_ValorFinal(); + decimal num = new decimal(); + if ((valorFinal.GetValueOrDefault() < num) & valorFinal.HasValue) + { + this.CorDoSaldo = new SolidColorBrush(Colors.Red); + } + valorFinal = saldo1.get_ValorFinal(); + this.SaldoAtual = string.Format("SALDO: {0:c}", Math.Round(valorFinal.GetValueOrDefault(), 2)); + } + } + } + + public async void Excluir() + { + if (this.SelectedBancosContas != null && this.SelectedBancosContas.get_Id() != 0) + { + if (await (new BaseServico()).BancosContasUtilizado(this.SelectedBancosContas.get_Id())) + { + await base.ShowMessage("NÃO PODE SER EXCLUÍDO POIS ESTÁ SENDO UTILIZADO EM UM LANÇAMENTO.", "OK", "", false); + } + else if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR A CONTA ", this.SelectedBancosContas.get_Descricao(), " PERMANENTEMENTE?"), "SIM", "NÃO", false)) + { + base.Loading(true); + if (await this._bancosContasServico.Delete(this.SelectedBancosContas)) + { + await this.SelecionaBancosDeContas(); + base.Loading(false); + base.ToggleSnackBar("CONTA EXCLUÍDA COM SUCESSO", true); + } + else + { + base.Loading(false); + } + } + } + } + + public async void ExcluirSaldo() + { + if (this.SelectedSaldo != null && this.SelectedSaldo.get_Id() != 0) + { + if (this.Saldos.Count <= 1) + { + await base.ShowMessage("NÃO É POSSÍVEL EXCLUIR O SALDO INICIAL DA CONTA.", "OK", "", false); + } + else if (await base.ShowMessage("DESEJA REALMENTE EXCLUIR O SALDO PERMANENTEMENTE?", "SIM", "NÃO", false)) + { + base.Loading(true); + Saldo saldo = this.Saldos.FirstOrDefault((Saldo x) => { + DateTime? dataFinal = x.get_DataFinal(); + DateTime? dataInicio = this.SelectedSaldo.get_DataInicio(); + if (dataFinal.HasValue != dataInicio.HasValue) + { + return false; + } + if (!dataFinal.HasValue) + { + return true; + } + return dataFinal.GetValueOrDefault() == dataInicio.GetValueOrDefault(); + }); + if (saldo != null) + { + saldo.set_DataFinal(null); + saldo.set_ValorFinal(null); + await this._bancosContasServico.Save(saldo); + if (!this._bancosContasServico.Sucesso) + { + base.Loading(false); + } + else if (await this._bancosContasServico.DeleteSaldo(this.SelectedSaldo)) + { + this.CarregarSaldos(this.SelectedBancosContas); + base.Loading(false); + base.ToggleSnackBar("SALDO EXCLUÍDO COM SUCESSO", true); + base.Loading(false); + } + else + { + base.Loading(false); + } + } + else + { + base.Loading(false); + await base.ShowMessage("NÃO É POSSÍVEL EXCLUIR O SALDO DA CONTA.", "OK", "", false); + } + } + } + } + + public async Task FecharSaldo() + { + this.SelectedSaldo = await this._bancosContasServico.Save(this.SelectedSaldo); + if (this._bancosContasServico.Sucesso) + { + DateTime? dataFinal = this.SelectedSaldo.get_DataFinal(); + if (dataFinal.HasValue) + { + decimal? valorFinal = this.SelectedSaldo.get_ValorFinal(); + if (valorFinal.HasValue) + { + Saldo saldo = new Saldo(); + saldo.set_Conta(this.SelectedSaldo.get_Conta()); + dataFinal = null; + saldo.set_DataFinal(dataFinal); + dataFinal = this.SelectedSaldo.get_DataFinal(); + saldo.set_DataInicio(new DateTime?(dataFinal.Value)); + valorFinal = null; + saldo.set_ValorFinal(valorFinal); + valorFinal = this.SelectedSaldo.get_ValorFinal(); + saldo.set_ValorInicio(valorFinal.Value); + await this._bancosContasServico.Save(saldo); + if (!this._bancosContasServico.Sucesso) + { + return; + } + } + } + this.CarregarSaldos(this.SelectedBancosContas); + base.ToggleSnackBar("SALDO FECHADO COM SUCESSO", true); + } + } + + internal async Task> Filtrar(string value) + { + List bancosContas = await Task.Run>(() => this.FiltrarBancosContas(value)); + return bancosContas; + } + + public List FiltrarBancosContas(string filter) + { + this.BancosContasFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.BancosContas) : new ObservableCollection( + from x in this.BancosContas + where Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(filter)) + orderby x.get_Ativo() descending, x.get_Descricao() + select x)); + return this.BancosContasFiltrados.ToList(); + } + + public void Incluir() + { + this._ultimoId = this.SelectedBancosContas.get_Id(); + this.DataAbertura = null; + this.ValorAbertura = new decimal?(new decimal()); + this.SaldoAtual = ""; + Gestor.Model.Domain.Financeiro.BancosContas bancosConta = new Gestor.Model.Domain.Financeiro.BancosContas(); + bancosConta.set_Ativo(true); + this.SelectedBancosContas = bancosConta; + this.Saldos = new ObservableCollection(); + this.SelectedSaldo = null; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + Gestor.Model.Domain.Financeiro.BancosContas bancosConta; + List> keyValuePairs1 = this.SelectedBancosContas.Validate(); + keyValuePairs1.AddRange(this.Validate()); + if (keyValuePairs1.Count <= 0) + { + bancosConta = await this._bancosContasServico.Save(this.SelectedBancosContas); + if (this._bancosContasServico.Sucesso) + { + if (this.SelectedBancosContas.get_Id() == 0 && this.DataAbertura.HasValue && this.ValorAbertura.HasValue) + { + Saldo saldo = new Saldo(); + saldo.set_Conta(bancosConta); + saldo.set_DataInicio(new DateTime?(this.DataAbertura.Value)); + saldo.set_ValorInicio(this.ValorAbertura.Value); + await this._bancosContasServico.Save(saldo); + if (!this._bancosContasServico.Sucesso) + { + keyValuePairs = null; + bancosConta = null; + return keyValuePairs; + } + } + await this.SelecionaBancosDeContas(); + this.SelecionaBancosContas(bancosConta); + Recursos.BancosContas = this.BancosContas; + base.Alterar(false); + base.ToggleSnackBar("CONTA SALVA COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + bancosConta = null; + return keyValuePairs; + } + + private async void Seleciona() + { + base.Loading(true); + await base.PermissaoTela(26); + await this.SelecionaBancosDeContas(); + base.Loading(false); + } + + public void SelecionaBancosContas(Gestor.Model.Domain.Financeiro.BancosContas bancosContas) + { + base.Loading(true); + this.SelectedBancosContas = this.BancosContasFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.BancosContas x) => x.get_Id() == bancosContas.get_Id()); + base.Loading(false); + } + + private async Task SelecionaBancosDeContas() + { + base.Loading(true); + List bancosContas = await this._bancosContasServico.BuscarBancos(); + BancosContasViewModel list = this; + List bancosContas1 = bancosContas; + IOrderedEnumerable ativo = + from x in bancosContas1 + orderby x.get_Ativo() descending + select x; + list.BancosContas = ativo.ThenBy((Gestor.Model.Domain.Financeiro.BancosContas x) => x.get_Descricao()).ToList(); + this.BancosContasFiltrados = new ObservableCollection(this.BancosContas); + if (this.BancosContasFiltrados.Count <= 0) + { + this.SelectedBancosContas = new Gestor.Model.Domain.Financeiro.BancosContas(); + this.Saldos = new ObservableCollection(); + this.DataAbertura = null; + this.ValorAbertura = new decimal?(new decimal()); + this.SaldoAtual = ""; + base.Alterar(false); + base.EnableMenu = false; + } + else + { + this.SelecionaBancosContas(this.BancosContasFiltrados.First()); + } + Recursos.BancosContas = bancosContas; + base.Loading(false); + } + + private async void UltimoSladoNaoAberto() + { + Saldo saldo = this.Saldos.ToList().Find((Saldo x) => { + DateTime? dataInicio = x.get_DataInicio(); + DateTime? nullable = this.Saldos.Max((Saldo r) => r.get_DataInicio()); + if (dataInicio.HasValue != nullable.HasValue) + { + return false; + } + if (!dataInicio.HasValue) + { + return true; + } + return dataInicio.GetValueOrDefault() == nullable.GetValueOrDefault(); + }); + DateTime? dataFinal = saldo.get_DataFinal(); + bool hasValue = dataFinal.HasValue; + if (hasValue) + { + hasValue = await base.ShowMessage("O ÚLTIMO SALDO NÃO ESTÁ ABERTO. DESEJA ABRÍ-LO AGORA?", "SIM", "NÃO", false); + } + if (hasValue) + { + dataFinal = null; + saldo.set_DataFinal(dataFinal); + saldo.set_ValorFinal(null); + this.SelectedSaldo = await this._bancosContasServico.Save(saldo); + this.SelectedBancosContas = this.SelectedBancosContas; + } + saldo = null; + } + + public List> Validate() + { + List> keyValuePairs = new List>(); + if (this.BancosContas.Where((Gestor.Model.Domain.Financeiro.BancosContas x) => { + if (x.get_Descricao() != this.SelectedBancosContas.get_Descricao()) + { + return false; + } + return x.get_Id() != this.SelectedBancosContas.get_Id(); + }).Any()) + { + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs, "Descricao|DESCRIÇÃO", "NÃO É POSSÍVEL SALVAR MAIS DE UMA CONTA COM A MESMA DESCRIÇÃO.", true); + } + if (this.SelectedBancosContas.get_Id() == 0) + { + if (!this.DataAbertura.HasValue) + { + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs, "DataAbertura|ABERTURA", "É NECESSÁRIO PREENCHER A DATA DE ABERTURA DA CONTA.", true); + } + else if (DateTime.Compare(this.DataAbertura.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.DataAbertura.Value, new DateTime(9999, 12, 31)) > 0) + { + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs, "DataAbertura|ABERTURA", "DATA INVÁLIDA", true); + } + if (!this.ValorAbertura.HasValue) + { + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs, "ValorAbertura|VALOR", "É NECESSÁRIO PREENCHER O VALOR DE ABERTURA DA CONTA.", true); + } + } + return keyValuePairs; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs new file mode 100644 index 0000000..ef57541 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs @@ -0,0 +1,255 @@ +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class CentroDeCustoViewmodel : BaseFinanceiroViewModel + { + private readonly CentroServico _centroServico; + + private ObservableCollection _centrosFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + private Centro _selectedCentro; + + private bool _ativo; + + private long _ultimoId; + + public Centro CancelCentro; + + public bool Ativo + { + get + { + return this._ativo; + } + set + { + this._ativo = bool.Parse(value.ToString()); + base.OnPropertyChanged("Ativo"); + } + } + + public List Centros + { + get; + set; + } + + public ObservableCollection CentrosFiltrados + { + get + { + return this._centrosFiltrados; + } + set + { + this._centrosFiltrados = value; + this.IsExpanded = (value != null ? value.Count > 0 : false); + base.OnPropertyChanged("CentrosFiltrados"); + } + } + + public bool IsExpanded + { + get + { + return this._isExpanded; + } + set + { + this._isExpanded = value; + base.OnPropertyChanged("IsExpanded"); + } + } + + public Centro SelectedCentro + { + get + { + return this._selectedCentro; + } + set + { + this._selectedCentro = value; + if (value.get_Id() > (long)0) + { + this._ultimoId = value.get_Id(); + } + base.VerificarEnables(new long?(value.get_Id())); + base.OnPropertyChanged("SelectedCentro"); + } + } + + public CentroDeCustoViewmodel() + { + this._centroServico = new CentroServico(); + base.EnableMenu = true; + this.Seleciona(); + } + + public async void CancelarAlteracao() + { + base.Loading(true); + base.Alterar(false); + if (this.SelectedCentro.get_Id() > (long)0) + { + await this.SelecionaCentro(); + } + await this.SelecionaCentro(this.CentrosFiltrados.FirstOrDefault((Centro x) => x.get_Id() == this._ultimoId)); + base.Loading(false); + } + + public async Task> Filtrar(string value) + { + List centros = await Task.Run>(() => this.FiltrarCentro(value)); + return centros; + } + + public List FiltrarCentro(string filter) + { + this.CentrosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Centros) : new ObservableCollection( + from x in this.Centros + where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby this.Ativo descending, x.get_Descricao() + select x)); + return this.CentrosFiltrados.ToList(); + } + + public void Incluir() + { + long id; + Centro selectedCentro = this.SelectedCentro; + if (selectedCentro != null) + { + id = selectedCentro.get_Id(); + } + else + { + id = (long)0; + } + this._ultimoId = id; + Centro centro = new Centro(); + centro.set_Ativo(true); + this.SelectedCentro = centro; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + List> keyValuePairs1 = this.SelectedCentro.Validate(); + List> keyValuePairs2 = keyValuePairs1; + keyValuePairs2.AddRange(await this.Validate()); + keyValuePairs2 = null; + if (keyValuePairs1.Count <= 0) + { + this.SelectedCentro = await this._centroServico.Save(this.SelectedCentro); + if (this._centroServico.Sucesso) + { + await this.SelecionaCentro(); + await this.SelecionaCentro(this.CentrosFiltrados.First((Centro x) => x.get_Id() == this.SelectedCentro.get_Id())); + base.Alterar(false); + base.ToggleSnackBar("CENTRO DE CUSTO SALVO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + private async void Seleciona() + { + base.Loading(true); + await base.PermissaoTela(29); + await this.SelecionaCentro(); + await this.SelecionaCentro(this.CentrosFiltrados.FirstOrDefault()); + base.Loading(false); + } + + private async Task SelecionaCentro(Centro centros) + { + if (centros != null) + { + base.Loading(true); + List centros1 = await (new BaseServico()).BuscarCentroAsync(); + DomainBase.Copy(this.CentrosFiltrados.First((Centro x) => x.get_Id() == centros.get_Id()), centros1.First((Centro x) => x.get_Id() == centros.get_Id())); + this.SelectedCentro = this.CentrosFiltrados.First((Centro x) => x.get_Id() == centros.get_Id()); + base.Loading(false); + } + else + { + base.Alterar(false); + base.EnableMenu = false; + base.EnableAlterar = false; + } + } + + private async Task SelecionaCentro() + { + List centros = await (new BaseServico()).BuscarCentroAsync(); + CentroDeCustoViewmodel list = this; + List centros1 = centros; + IOrderedEnumerable ativo = + from x in centros1 + orderby x.get_Ativo() descending + select x; + IOrderedEnumerable centros2 = ativo.ThenBy((Centro x) => x.get_Descricao()); + list.Centros = centros2.ThenBy((Centro x) => x.get_Descricao()).ToList(); + this.CentrosFiltrados = new ObservableCollection(this.Centros); + } + + public void SelecionaCentroDeCusto(Centro centro) + { + this.SelectedCentro = this.CentrosFiltrados.First((Centro x) => x.get_Id() == centro.get_Id()); + } + + public async Task>> Validate() + { + List> keyValuePairs = new List>(); + bool flag = true; + List centros = await (new BaseServico()).BuscarCentroAsync(); + if (centros.Count > 0) + { + centros.ForEach((Centro x) => { + if (x.get_Id() == this.SelectedCentro.get_Id()) + { + return; + } + if (x.get_Descricao() == this.SelectedCentro.get_Descricao() && x.get_IdEmpresa() == this.SelectedCentro.get_IdEmpresa()) + { + flag = false; + } + }); + } + if (!flag) + { + keyValuePairs.Add(new KeyValuePair("Descricao", "UM CENTRO COM ESSE NOME JÁ EXISTE.")); + } + List> keyValuePairs1 = keyValuePairs; + keyValuePairs = null; + return keyValuePairs1; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/ContasDialogModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/ContasDialogModel.cs new file mode 100644 index 0000000..8e112a4 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/ContasDialogModel.cs @@ -0,0 +1,48 @@ +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Financeiro; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class ContasDialogModel : BaseViewModel + { + private ObservableCollection _contasFiltradas; + + private BancosContas _conta; + + public BancosContas Conta + { + get + { + return this._conta; + } + set + { + this._conta = value; + base.OnPropertyChanged("Conta"); + } + } + + public ObservableCollection ContasFiltradas + { + get + { + return this._contasFiltradas; + } + set + { + this._contasFiltradas = value; + base.OnPropertyChanged("ContasFiltradas"); + } + } + + public ContasDialogModel(List contas) + { + this.ContasFiltradas = new ObservableCollection(contas); + this.Conta = this.ContasFiltradas.FirstOrDefault(); + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/CopiarClienteViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/CopiarClienteViewModel.cs new file mode 100644 index 0000000..3bde895 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/CopiarClienteViewModel.cs @@ -0,0 +1,28 @@ +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Seguros; +using System; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class CopiarClienteViewModel : BaseSegurosViewModel + { + private Cliente _selectedCliente; + + public Cliente SelectedCliente + { + get + { + return this._selectedCliente; + } + set + { + this._selectedCliente = value; + base.OnPropertyChanged("SelectedCliente"); + } + } + + public CopiarClienteViewModel() + { + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/ExtratoContaViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/ExtratoContaViewModel.cs new file mode 100644 index 0000000..114d175 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/ExtratoContaViewModel.cs @@ -0,0 +1,552 @@ +using ClosedXML.Excel; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Helpers; +using Gestor.Model.Common; +using Gestor.Model.Domain.Configuracoes; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Relatorios; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Forms; +using System.Windows.Media; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class ExtratoContaViewModel : BaseFinanceiroViewModel + { + private Geometry _maximizeRestore = Geometry.Parse((string)System.Windows.Application.Current.Resources["Restore"]); + + private string _head; + + private readonly FinanceiroServico _servico; + + private ObservableCollection _contas; + + private ObservableCollection _contasFilter; + + private Gestor.Model.Domain.Financeiro.BancosContas _selectedConta; + + private DateTime? _inicio; + + private DateTime? _fim; + + private static ObservableCollection _bancosContas; + + private string _selectedBancosContas; + + private ObservableCollection _extrato; + + private bool _saldoFinal; + + private bool _naoHaDados; + + public ObservableCollection BancosContas + { + get + { + return ExtratoContaViewModel._bancosContas; + } + set + { + ExtratoContaViewModel._bancosContas = value; + base.OnPropertyChanged("BancosContas"); + } + } + + public ObservableCollection Contas + { + get + { + return this._contas; + } + set + { + this._contas = value; + base.OnPropertyChanged("Contas"); + } + } + + public ObservableCollection ContasFilter + { + get + { + return this._contasFilter; + } + set + { + this._contasFilter = value; + base.OnPropertyChanged("ContasFilter"); + } + } + + public ObservableCollection Extrato + { + get + { + return this._extrato; + } + set + { + this._extrato = value; + this.NaoHaDados = (value == null ? true : value.Count == 0); + base.OnPropertyChanged("Extrato"); + } + } + + public DateTime? Fim + { + get + { + return this._fim; + } + set + { + this._fim = value; + base.OnPropertyChanged("Fim"); + } + } + + public string Head + { + get + { + return this._head; + } + set + { + this._head = value; + base.OnPropertyChanged("Head"); + } + } + + public DateTime? Inicio + { + get + { + return this._inicio; + } + set + { + this._inicio = value; + base.OnPropertyChanged("Inicio"); + } + } + + public Geometry MaximizeRestore + { + get + { + return this._maximizeRestore; + } + set + { + this._maximizeRestore = value; + base.OnPropertyChanged("MaximizeRestore"); + } + } + + public bool NaoHaDados + { + get + { + return this._naoHaDados; + } + set + { + this._naoHaDados = value; + base.OnPropertyChanged("NaoHaDados"); + } + } + + public bool SaldoFinal + { + get + { + return this._saldoFinal; + } + set + { + this._saldoFinal = value; + base.OnPropertyChanged("SaldoFinal"); + } + } + + public string SelectedBancosContas + { + get + { + return this._selectedBancosContas; + } + set + { + this._selectedBancosContas = value; + if (value == null || this.Contas == null || this.Contas.Count <= 0) + { + return; + } + if (value == "TODOS") + { + this.ContasFilter = this.Contas; + } + else if (value == "ATIVOS") + { + this.ContasFilter = new ObservableCollection(( + from x in this.Contas + where x.get_Ativo() + select x).ToList()); + } + else if (value == "INATIVOS") + { + this.ContasFilter = new ObservableCollection(( + from x in this.Contas + where !x.get_Ativo() + select x).ToList()); + } + base.OnPropertyChanged("SelectedBancosContas"); + } + } + + public Gestor.Model.Domain.Financeiro.BancosContas SelectedConta + { + get + { + return this._selectedConta; + } + set + { + this._selectedConta = value; + base.OnPropertyChanged("SelectedConta"); + } + } + + static ExtratoContaViewModel() + { + ExtratoContaViewModel._bancosContas = new ObservableCollection() + { + "TODOS", + "ATIVOS", + "INATIVOS" + }; + } + + public ExtratoContaViewModel(long id) + { + this._maximizeRestore = Geometry.Parse((string)System.Windows.Application.Current.Resources["Restore"]); + DateTime date = Funcoes.GetNetworkTime().Date; + int year = date.Year; + date = Funcoes.GetNetworkTime().Date; + this._inicio = new DateTime?(new DateTime(year, date.Month, 1)); + this._fim = new DateTime?(Funcoes.GetNetworkTime()); + this._selectedBancosContas = "TODOS"; + base(); + this._servico = new FinanceiroServico(); + this.BuscaInicial(id); + } + + private async void BuscaInicial(long id) + { + Gestor.Model.Domain.Financeiro.BancosContas bancosConta; + base.Loading(true); + List bancosContas = await (new BancosContasServico()).BuscarBancos(); + ExtratoContaViewModel observableCollection = this; + List bancosContas1 = bancosContas; + observableCollection.Contas = new ObservableCollection( + from x in bancosContas1 + orderby x.get_Descricao() + select x); + ExtratoContaViewModel extratoContaViewModel = this; + List bancosContas2 = bancosContas; + extratoContaViewModel.ContasFilter = new ObservableCollection( + from x in bancosContas2 + orderby x.get_Descricao() + select x); + ExtratoContaViewModel extratoContaViewModel1 = this; + bancosConta = (id > (long)0 ? this.Contas.FirstOrDefault((Gestor.Model.Domain.Financeiro.BancosContas x) => x.get_Id() == id) : this.Contas.FirstOrDefault()); + extratoContaViewModel1.SelectedConta = bancosConta; + await this.GerarRelatorio(); + base.Loading(false); + } + + public async Task GerarExcel() + { + string str; + string str1; + if (this.Extrato == null || this.Extrato.Count == 0) + { + base.ShowMessage("NÃO HÁ DADOS PARA A IMPRESSÃO EM EXCEL", "OK", "", false); + } + else + { + List list = this.Extrato.ToList(); + string tempPath = ""; + str1 = ""; + List configuracoes = Recursos.Configuracoes; + if (!configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 41)) + { + tempPath = Path.GetTempPath(); + str1 = string.Format("{0}{1}.xlsx", tempPath, Guid.NewGuid()); + } + else + { + using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) + { + if (DialogResult.OK == folderBrowserDialog.ShowDialog()) + { + tempPath = string.Concat(folderBrowserDialog.SelectedPath, "\\"); + Directory.CreateDirectory(tempPath); + } + else + { + str1 = null; + return; + } + } + string[] descricao = new string[] { tempPath, "EXTRATO CONTA - ", this.SelectedConta.get_Descricao(), " ", null, null }; + DateTime date = Functions.GetNetworkTime().Date; + descricao[4] = date.ToShortDateString().Replace("/", ""); + descricao[5] = ".xlsx"; + str1 = string.Concat(descricao); + } + XLWorkbook xLWorkbook = new XLWorkbook(); + string str2 = string.Concat("EXTRATO CONTA - ", this.SelectedConta.get_Descricao()); + str = (str2.Length < 30 ? str2 : str2.Substring(0, 30)); + str2 = str; + await Funcoes.GerarXls(xLWorkbook, str2, list, new List()).SaveAs(str1); + Process.Start(str1); + } + str1 = null; + } + + public async Task GerarRelatorio() + { + DateTime? dataInicio; + bool flag; + Sinal sinal; + Sinal sinal1; + string str; + ExtratoContaViewModel.u003cu003ec__DisplayClass52_0 variable; + if (this.SelectedConta != null && this.SelectedConta.get_Id() != 0) + { + DateTime? inicio = this.Inicio; + if (inicio.HasValue) + { + inicio = this.Fim; + if (inicio.HasValue) + { + BancosContasServico bancosContasServico = new BancosContasServico(); + Saldo saldo = await bancosContasServico.BuscarSaldoInicial(this.SelectedConta.get_Id()); + if (saldo != null) + { + dataInicio = saldo.get_DataInicio(); + } + else + { + dataInicio = null; + } + inicio = dataInicio; + DateTime? fim = this.Inicio; + flag = (inicio.HasValue & fim.HasValue ? inicio.GetValueOrDefault() > fim.GetValueOrDefault() : false); + if (!flag) + { + FinanceiroServico financeiroServico = this._servico; + fim = this.Inicio; + DateTime value = fim.Value; + fim = this.Fim; + List extratoContas2 = await financeiroServico.BuscarLancamentosPorConta(value, fim.Value, this.SelectedConta.get_Id()); + List extratoContas3 = extratoContas2; + BancosContasServico bancosContasServico1 = bancosContasServico; + fim = this.Inicio; + Saldo saldo1 = await bancosContasServico1.BuscarSaldo(fim.Value, this.SelectedConta.get_Id()); + if (extratoContas3.Count != 0) + { + if (saldo1 == null) + { + Saldo saldo2 = new Saldo(); + saldo2.set_Conta(this.SelectedConta); + saldo2.set_DataInicio(this.Inicio); + saldo2.set_ValorInicio(decimal.Zero); + saldo1 = saldo2; + } + fim = this.Inicio; + saldo1.set_DataFinal(new DateTime?(fim.Value)); + decimal num1 = new decimal(); + saldo1.set_ValorFinal(new decimal?(num1)); + saldo1 = await bancosContasServico.FecharSaldo(saldo1); + List extratoContas4 = new List(); + ExtratoConta extratoContum2 = new ExtratoConta(); + fim = this.Inicio; + extratoContum2.set_Baixa(new DateTime?(fim.Value)); + extratoContum2.set_Fornecedor("SALDO INICIAL"); + decimal? valorFinal = saldo1.get_ValorFinal(); + extratoContum2.set_Valor(new decimal?(valorFinal.GetValueOrDefault())); + valorFinal = saldo1.get_ValorFinal(); + sinal = (valorFinal.GetValueOrDefault() < decimal.Zero ? 1 : 0); + extratoContum2.set_Sinal(sinal); + extratoContum2.set_Bold(true); + ExtratoConta extratoContum3 = extratoContum2; + extratoContas4.Add(extratoContum3); + decimal? valor = extratoContum3.get_Valor(); + List extratoContas5 = extratoContas3; + IOrderedEnumerable extratoContas6 = + from x in extratoContas5 + orderby x.get_Baixa() + select x; + ( + from x in extratoContas6 + group x by x.get_Baixa()).ToList>().ForEach((IGrouping g) => { + decimal? nullable; + decimal? nullable1; + List list = extratoContas3.Where((ExtratoConta x) => { + DateTime? baixa = x.get_Baixa(); + DateTime? key = g.Key; + if (baixa.HasValue != key.HasValue) + { + return false; + } + if (!baixa.HasValue) + { + return true; + } + return baixa.GetValueOrDefault() == key.GetValueOrDefault(); + }).ToList(); + ExtratoConta extratoContum = new ExtratoConta(); + extratoContum.set_Baixa(g.Key); + extratoContum.set_Fornecedor("SALDO FINAL DO DIA"); + decimal? nullable2 = valor; + List extratoContas = list; + Func u003cu003e9_524 = ExtratoContaViewModel.u003cu003ec.u003cu003e9__52_4; + if (u003cu003e9_524 == null) + { + u003cu003e9_524 = (ExtratoConta x) => x.get_Valor(); + ExtratoContaViewModel.u003cu003ec.u003cu003e9__52_4 = u003cu003e9_524; + } + decimal? nullable3 = extratoContas.Sum(u003cu003e9_524); + if (nullable2.HasValue & nullable3.HasValue) + { + nullable1 = new decimal?(nullable2.GetValueOrDefault() + nullable3.GetValueOrDefault()); + } + else + { + nullable = null; + nullable1 = nullable; + } + extratoContum.set_Valor(nullable1); + nullable2 = valor; + List extratoContas1 = list; + Func u003cu003e9_525 = ExtratoContaViewModel.u003cu003ec.u003cu003e9__52_5; + if (u003cu003e9_525 == null) + { + u003cu003e9_525 = (ExtratoConta x) => x.get_Valor(); + ExtratoContaViewModel.u003cu003ec.u003cu003e9__52_5 = u003cu003e9_525; + } + nullable = extratoContas1.Sum(u003cu003e9_525); + nullable3 = (nullable2.HasValue & nullable.HasValue ? new decimal?(nullable2.GetValueOrDefault() + nullable.GetValueOrDefault()) : null); + decimal num = new decimal(); + extratoContum.set_Sinal(((nullable3.GetValueOrDefault() < num) & nullable3.HasValue ? 1 : 0)); + extratoContum.set_Bold(true); + ExtratoConta extratoContum1 = extratoContum; + if (!this.SaldoFinal) + { + extratoContas4.AddRange(list); + } + extratoContas4.Add(extratoContum1); + valor = extratoContum1.get_Valor(); + }); + List extratoContas7 = extratoContas4; + ExtratoConta extratoContum4 = new ExtratoConta(); + fim = this.Fim; + extratoContum4.set_Baixa(new DateTime?(fim.Value)); + extratoContum4.set_Fornecedor("SALDO FINAL"); + extratoContum4.set_Valor(valor); + valorFinal = valor; + num1 = new decimal(); + sinal1 = ((valorFinal.GetValueOrDefault() < num1) & valorFinal.HasValue ? 1 : 0); + extratoContum4.set_Sinal(sinal1); + extratoContum4.set_Bold(true); + extratoContas7.Add(extratoContum4); + this.Extrato = new ObservableCollection(extratoContas4); + bancosContasServico = null; + } + else + { + this.NaoHaDados = true; + variable = null; + return; + } + } + else + { + ExtratoContaViewModel extratoContaViewModel = this; + string descricao = saldo.get_Conta().get_Descricao(); + fim = saldo.get_DataInicio(); + if (fim.HasValue) + { + str = fim.GetValueOrDefault().ToString("dd/MM/yyyy"); + } + else + { + str = null; + } + extratoContaViewModel.ShowMessage(string.Concat("DATA DE INÍCIO É MENOR QUE A CRIAÇÃO DA CONTA ", descricao, ",\nDATA DE ABERTURA ", str), "OK", "", false); + this.NaoHaDados = true; + variable = null; + return; + } + } + } + } + variable = null; + } + + public void LimparRelatorio() + { + this.Extrato = null; + } + + public async Task Print() + { + DateTime dateTime; + DateTime dateTime1; + string str; + if (this.Extrato == null || this.Extrato.Count == 0) + { + base.ShowMessage("NÃO HÁ DADOS PARA A IMPRESSÃO", "OK", "", false); + } + else + { + string str1 = await Funcoes.GenerateTable(this.Extrato.ToList(), new List(), false, false, "", null); + TipoRelatorio tipoRelatorio = new TipoRelatorio(); + tipoRelatorio.set_Nome(string.Concat("EXTRATO CONTA - ", this.SelectedConta.get_Descricao())); + DateTime? inicio = this.Inicio; + dateTime = (inicio.HasValue ? inicio.GetValueOrDefault() : DateTime.MinValue); + tipoRelatorio.set_Inicio(dateTime); + inicio = this.Fim; + dateTime1 = (inicio.HasValue ? inicio.GetValueOrDefault() : DateTime.MinValue); + tipoRelatorio.set_Fim(dateTime1); + TipoRelatorio tipoRelatorio1 = tipoRelatorio; + TipoRelatorio tipoRelatorio2 = tipoRelatorio1; + str = (tipoRelatorio1.get_Nome().Length < 30 ? tipoRelatorio1.get_Nome() : tipoRelatorio1.get_Nome().Substring(0, 30)); + tipoRelatorio2.set_Nome(str); + string str2 = Funcoes.ExportarHtml(tipoRelatorio1, str1, "60", "portrait", false, ""); + string tempPath = Path.GetTempPath(); + string str3 = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, (new Regex(string.Concat("[", Regex.Escape(string.Concat(new string(Path.GetInvalidFileNameChars()), new string(Path.GetInvalidPathChars()))), "]"))).Replace(tipoRelatorio1.get_Nome(), ""), Funcoes.GetNetworkTime()); + StreamWriter streamWriter = new StreamWriter(str3, true, Encoding.UTF8); + streamWriter.Write(str2); + streamWriter.Close(); + Process.Start(str3); + } + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/FinanceiroViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/FinanceiroViewModel.cs new file mode 100644 index 0000000..630e3db --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/FinanceiroViewModel.cs @@ -0,0 +1,5973 @@ +using ClosedXML.Excel; +using CsQuery.ExtensionMethods; +using Gestor.Application.Actions; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Application.Views.Relatorios; +using Gestor.Common.Helpers; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Configuracoes; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Relatorios; +using Gestor.Model.Domain.Seguros; +using Gestor.Model.Helper; +using OfxSharpLib; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Forms; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class FinanceiroViewModel : BaseFinanceiroViewModel + { + private readonly FinanceiroServico _servico; + + private bool _enableIncluirNovo; + + private bool _enableChanges; + + private SinteticoFinanceiroTipo _sinteticoTipo; + + private Visibility _isVisibleData; + + private Visibility _isVisibleFornecedor = Visibility.Collapsed; + + private Visibility _isVisiblePersonalizado = Visibility.Collapsed; + + private Visibility _isVisibleFiltros = Visibility.Collapsed; + + private Visibility _isVisibleLancamento; + + private Visibility _isvisibleStatus; + + private FiltroLancamento _selectedFiltro; + + private FiltroLancamentoData _selectedFiltroData; + + private StatusLancamento _selectedStatus; + + private StatusLancamento _selectedStatusImportacao = 2; + + private Visibility _botaoSalvarVisibility; + + private DateTime? _inicio = new DateTime?(Funcoes.GetNetworkTime()); + + private DateTime? _fim = new DateTime?(Funcoes.GetNetworkTime().AddDays(7)); + + private Fornecedor _selectedFornecedor; + + private ObservableCollection _saldos = new ObservableCollection(); + + private Saldo _selectedSaldo = new Saldo(); + + private ObservableCollection _lancamentos = new ObservableCollection(); + + private bool _dontSort; + + private ObservableCollection _lancamentosFiltrados = new ObservableCollection(); + + private ObservableCollection _lancamentosFiltradosCopia = new ObservableCollection(); + + private ObservableCollection _lancamentosVinculo = new ObservableCollection(); + + private Lancamento _lancamentoVinculo; + + private Lancamento _selectedLancamento; + + private Fornecedor _fornecedorInclusao; + + private long _idLancamento; + + private string _historico; + + private string _observacao; + + private string _documento; + + private string _complemento; + + private string _competencia; + + private int _parcela; + + private double _dropDownHeight; + + private int _parcelas; + + public bool VencimentoAlterado; + + private DateTime _vencimento; + + private DateTime? _baixa; + + private DateTime? _pagamento; + + private decimal _valor; + + private decimal? _valorPago; + + private Gestor.Model.Common.Sinal _sinal; + + private Gestor.Model.Domain.Financeiro.Planos _plano; + + private Gestor.Model.Domain.Financeiro.Centro _centro; + + private BancosContas _conta; + + private Gestor.Model.Common.TipoPagamento _tipoPagamento; + + private List _planosFiltro; + + private List _centroFiltro; + + private List _contaFiltro; + + private List _planos; + + private ObservableCollection _planosFiltrados; + + private List _contas; + + private ObservableCollection _contasFiltradas; + + private List _centros; + + private ObservableCollection _centrosFiltrados; + + private ObservableCollection _totalizacao; + + private Visibility _visibilityFornecedor; + + private Visibility _visibilityCentro; + + private Visibility _visibilityConta; + + private Visibility _alterando = Visibility.Collapsed; + + private bool _buscaHabilitada = true; + + private bool _alteracao = true; + + private List _filtroRelatorioPersonalizado; + + private List _filtros; + + private ObservableCollection _personalizadoSelecionado; + + private ObservableCollection _filtroRelatorioSelecionado = new ObservableCollection(); + + private Visibility _visibilitySemValor = Visibility.Collapsed; + + private Gestor.Model.Domain.Relatorios.FiltroPersonalizado _filtro; + + private Type _tipoString = typeof(string); + + private Type _tipoEnum = typeof(Enum); + + private Type _tipoDateTime = typeof(DateTime); + + private Type _tipoDecimal = typeof(decimal); + + private Type _tipoInt = typeof(int); + + private Type _tipoLong = typeof(long); + + private string _valorIncial = ""; + + private string _valorFinal = ""; + + private bool _semValor; + + private List _filtroPersonalizado; + + private ObservableCollection _filtroPersonalizadoSelecionado = new ObservableCollection(); + + private Visibility _visibleFiltros = Visibility.Collapsed; + + private Visibility _visibleOlho = Visibility.Collapsed; + + private bool importando; + + private bool _isExpanded; + + public bool Alteracao + { + get + { + return this._alteracao; + } + set + { + this._alteracao = value; + base.OnPropertyChanged("Alteracao"); + } + } + + public Visibility Alterando + { + get + { + return this._alterando; + } + set + { + this._alterando = value; + base.OnPropertyChanged("Alterando"); + } + } + + public DateTime? Baixa + { + get + { + return this._baixa; + } + set + { + this._baixa = value; + base.OnPropertyChanged("Baixa"); + } + } + + public Visibility BotaoSalvarVisibility + { + get + { + return this._isvisibleStatus; + } + set + { + this._isvisibleStatus = value; + base.OnPropertyChanged("BotaoSalvarVisibility"); + } + } + + public bool BuscaHabilitada + { + get + { + return this._buscaHabilitada; + } + set + { + this._buscaHabilitada = value; + base.OnPropertyChanged("BuscaHabilitada"); + } + } + + private bool Carregar { get; set; } = true; + + public Gestor.Model.Domain.Financeiro.Centro Centro + { + get + { + return this._centro; + } + set + { + this._centro = value; + base.OnPropertyChanged("Centro"); + } + } + + public List CentroFiltro + { + get + { + return this._centroFiltro; + } + set + { + this._centroFiltro = value; + base.OnPropertyChanged("CentroFiltro"); + } + } + + public List Centros + { + get + { + return this._centros; + } + set + { + this._centros = value; + base.OnPropertyChanged("Centros"); + } + } + + public ObservableCollection CentrosFiltrados + { + get + { + return this._centrosFiltrados; + } + set + { + this._centrosFiltrados = value; + base.OnPropertyChanged("CentrosFiltrados"); + } + } + + public string CodigoBanco + { + get; + set; + } + + public string Competencia + { + get + { + return this._competencia; + } + set + { + this._competencia = value; + base.OnPropertyChanged("Competencia"); + } + } + + public string Complemento + { + get + { + return this._complemento; + } + set + { + this._complemento = value; + base.OnPropertyChanged("Complemento"); + } + } + + public BancosContas Conta + { + get + { + return this._conta; + } + set + { + this._conta = value; + base.OnPropertyChanged("Conta"); + } + } + + public List ContaFiltro + { + get + { + return this._contaFiltro; + } + set + { + this._contaFiltro = value; + base.OnPropertyChanged("ContaFiltro"); + } + } + + public List Contas + { + get + { + return this._contas; + } + set + { + this._contas = value; + base.OnPropertyChanged("Contas"); + } + } + + public ObservableCollection ContasFiltradas + { + get + { + return this._contasFiltradas; + } + set + { + this._contasFiltradas = value; + base.OnPropertyChanged("ContasFiltradas"); + } + } + + public string Documento + { + get + { + return this._documento; + } + set + { + this._documento = value; + base.OnPropertyChanged("Documento"); + } + } + + public double DropDownHeight + { + get + { + return this._dropDownHeight; + } + set + { + this._dropDownHeight = value; + base.OnPropertyChanged("DropDownHeight"); + } + } + + public bool EnableChanges + { + get + { + return this._enableChanges; + } + set + { + this._enableChanges = value; + base.OnPropertyChanged("EnableChanges"); + } + } + + public bool EnableIncluirNovo + { + get + { + return this._enableIncluirNovo; + } + set + { + this._enableIncluirNovo = value; + base.OnPropertyChanged("EnableIncluirNovo"); + } + } + + public Gestor.Model.Domain.Relatorios.FiltroPersonalizado Filtro + { + get + { + return this._filtro; + } + set + { + char chr; + this._filtro = value; + this.VisibilitySemValor = (value != null ? Visibility.Visible : Visibility.Collapsed); + base.OnPropertyChanged("Filtro"); + if (value == null) + { + return; + } + string name = value.get_Tipo().Name; + if (name != null) + { + switch (name.Length) + { + case 3: + { + if (name == "int") + { + break; + } + return; + } + case 4: + { + chr = name[0]; + if (chr == 'E') + { + if (name == "Enum") + { + this.ValorInicial = null; + this.ValorFinal = null; + return; + } + return; + } + else + { + if (chr != 'l') + { + return; + } + if (name == "long") + { + break; + } + return; + } + } + case 5: + { + chr = name[3]; + if (chr == '3') + { + if (name == "int32") + { + break; + } + return; + } + else + { + if (chr != '6') + { + return; + } + if (name == "int64") + { + break; + } + return; + } + } + case 6: + { + if (name != "String") + { + return; + } + this.ValorInicial = ""; + this.ValorFinal = ""; + return; + } + case 7: + { + if (name != "Decimal") + { + return; + } + this.ValorInicial = "0,00"; + this.ValorFinal = "0,00"; + return; + } + case 8: + { + if (name == "DateTime") + { + this.ValorInicial = null; + this.ValorFinal = null; + return; + } + return; + } + default: + { + return; + } + } + this.ValorInicial = "0"; + this.ValorFinal = "0"; + } + } + } + + public List FiltroPersonalizado + { + get + { + return this._filtroPersonalizado; + } + set + { + this._filtroPersonalizado = value; + base.OnPropertyChanged("FiltroPersonalizado"); + } + } + + public AutoCompleteFilterPredicate FiltroPersonalizadoItemFilter + { + get + { + AutoCompleteFilterPredicate u003cu003e9_3690 = FinanceiroViewModel.u003cu003ec.u003cu003e9__369_0; + if (u003cu003e9_3690 == null) + { + u003cu003e9_3690 = new AutoCompleteFilterPredicate(FinanceiroViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => ((Gestor.Model.Domain.Financeiro.FiltroPersonalizado)obj).get_Descricao().ToUpper().Contains(searchText.ToUpper())); + FinanceiroViewModel.u003cu003ec.u003cu003e9__369_0 = u003cu003e9_3690; + } + return u003cu003e9_3690; + } + } + + public ObservableCollection FiltroPersonalizadoSelecionado + { + get + { + return this._filtroPersonalizadoSelecionado; + } + set + { + this._filtroPersonalizadoSelecionado = value; + base.OnPropertyChanged("FiltroPersonalizadoSelecionado"); + } + } + + public ObservableCollection FiltroRelatorioSelecionado + { + get + { + return this._filtroRelatorioSelecionado; + } + set + { + this._filtroRelatorioSelecionado = value; + base.OnPropertyChanged("FiltroRelatorioSelecionado"); + } + } + + public List Filtros + { + get + { + return this._filtros; + } + set + { + this._filtros = value; + base.OnPropertyChanged("Filtros"); + } + } + + public DateTime? Fim + { + get + { + return this._fim; + } + set + { + if (value.HasValue && value.Value < new DateTime(1754, 1, 1)) + { + value = new DateTime?(new DateTime(1754, 1, 1)); + } + if (value.HasValue && value.Value > new DateTime(9999, 12, 31)) + { + value = new DateTime?(new DateTime(9999, 12, 31)); + } + this._fim = value; + base.OnPropertyChanged("Fim"); + } + } + + public Fornecedor FornecedorInclusao + { + get + { + return this._fornecedorInclusao; + } + set + { + // + // Current member / type: System.Void Gestor.Application.ViewModels.Financeiro.FinanceiroViewModel::set_FornecedorInclusao(Gestor.Model.Domain.Financeiro.Fornecedor) + // File path: C:\AggerSeguros\Gestor.Application.exe + // + // Product version: 0.0.0.0 + // Exception in: System.Void set_FornecedorInclusao(Gestor.Model.Domain.Financeiro.Fornecedor) + // + // Object reference not set to an instance of an object. + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.FindLowestCommonAncestor(ICollection`1 typeNodes) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 515 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.MergeWithLowestCommonAncestor() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 459 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.ProcessSingleConstraints() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 378 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.InferTypes() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 331 + // at Telerik.JustDecompiler.Decompiler.ExpressionDecompilerStep.Process(DecompilationContext theContext, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\ExpressionDecompilerStep.cs:line 104 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.PropertyDecompiler.DecompileMethod(MethodBody body, MethodSpecificContext& methodContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\PropertyDecompiler.cs:line 347 + // + // mailto: JustDecompilePublicFeedback@telerik.com + + } + } + + public string Historico + { + get + { + return this._historico; + } + set + { + this._historico = value; + base.OnPropertyChanged("Historico"); + } + } + + public long IdLancamento + { + get + { + return this._idLancamento; + } + set + { + this._idLancamento = value; + base.OnPropertyChanged("IdLancamento"); + } + } + + public bool Importando + { + get + { + return this.importando; + } + set + { + this.importando = value; + base.OnPropertyChanged("Importando"); + } + } + + public DateTime? Inicio + { + get + { + return this._inicio; + } + set + { + if (value.HasValue && value.Value < new DateTime(1754, 1, 1)) + { + value = new DateTime?(new DateTime(1754, 1, 1)); + } + if (value.HasValue && value.Value > new DateTime(9999, 12, 31)) + { + value = new DateTime?(new DateTime(9999, 12, 31)); + } + this._inicio = value; + base.OnPropertyChanged("Inicio"); + } + } + + public bool IsExpanded + { + get + { + return this._isExpanded; + } + set + { + this._isExpanded = value; + base.OnPropertyChanged("IsExpanded"); + } + } + + public Visibility IsVisibleData + { + get + { + return this._isVisibleData; + } + set + { + this._isVisibleData = value; + base.OnPropertyChanged("IsVisibleData"); + } + } + + public Visibility IsVisibleFiltros + { + get + { + return this._isVisibleFiltros; + } + set + { + this._isVisibleFiltros = value; + base.OnPropertyChanged("IsVisibleFiltros"); + } + } + + public Visibility IsVisibleFornecedor + { + get + { + return this._isVisibleFornecedor; + } + set + { + this._isVisibleFornecedor = value; + base.OnPropertyChanged("IsVisibleFornecedor"); + } + } + + public Visibility IsVisibleLancamento + { + get + { + return this._isVisibleLancamento; + } + set + { + this._isVisibleLancamento = value; + base.OnPropertyChanged("IsVisibleLancamento"); + } + } + + public Visibility IsVisiblePersonalizado + { + get + { + return this._isVisiblePersonalizado; + } + set + { + this._isVisiblePersonalizado = value; + base.OnPropertyChanged("IsVisiblePersonalizado"); + } + } + + public Visibility IsvisibleStatus + { + get + { + return this._isvisibleStatus; + } + set + { + this._isvisibleStatus = value; + base.OnPropertyChanged("IsvisibleStatus"); + } + } + + public ObservableCollection Lancamentos + { + get + { + return this._lancamentos; + } + set + { + this._lancamentos = value; + base.OnPropertyChanged("Lancamentos"); + } + } + + private Lancamento LancamentoSelecionado + { + get; + set; + } + + public ObservableCollection LancamentosFiltrados + { + get + { + return this._lancamentosFiltrados; + } + set + { + if (!this._dontSort) + { + Action saveSortLancamentos = Gestor.Application.Actions.Actions.SaveSortLancamentos; + if (saveSortLancamentos != null) + { + saveSortLancamentos(); + } + else + { + } + } + this._lancamentosFiltrados = value; + this.Totalizar(); + base.OnPropertyChanged("LancamentosFiltrados"); + if (!this._dontSort) + { + Action sortLancamentos = Gestor.Application.Actions.Actions.SortLancamentos; + if (sortLancamentos == null) + { + return; + } + sortLancamentos(); + } + } + } + + public ObservableCollection LancamentosFiltradosCopia + { + get + { + return this._lancamentosFiltradosCopia; + } + set + { + this._lancamentosFiltradosCopia = value; + base.OnPropertyChanged("LancamentosFiltradosCopia"); + } + } + + public ObservableCollection LancamentosVinculo + { + get + { + return this._lancamentosVinculo; + } + set + { + this._lancamentosVinculo = value; + base.OnPropertyChanged("LancamentosVinculo"); + } + } + + public Lancamento LancamentoVinculo + { + get + { + return this._lancamentoVinculo; + } + set + { + this._lancamentoVinculo = value; + base.OnPropertyChanged("LancamentoVinculo"); + } + } + + public bool NotImportando + { + get + { + return !this.Importando; + } + } + + public string Observacao + { + get + { + return this._observacao; + } + set + { + this._observacao = value; + base.OnPropertyChanged("Observacao"); + } + } + + public DateTime? Pagamento + { + get + { + return this._pagamento; + } + set + { + this._pagamento = value; + base.OnPropertyChanged("Pagamento"); + } + } + + public int Parcela + { + get + { + return this._parcela; + } + set + { + this._parcela = value; + base.OnPropertyChanged("Parcela"); + } + } + + public int Parcelas + { + get + { + return this._parcelas; + } + set + { + this._parcelas = value; + base.OnPropertyChanged("Parcelas"); + } + } + + public ObservableCollection PersonalizadoSelecionado + { + get + { + return this._personalizadoSelecionado; + } + set + { + this._personalizadoSelecionado = value; + base.OnPropertyChanged("PersonalizadoSelecionado"); + } + } + + public Gestor.Model.Domain.Financeiro.Planos Plano + { + get + { + return this._plano; + } + set + { + this._plano = value; + base.OnPropertyChanged("Plano"); + if (value == null || value.get_Id() == 0) + { + return; + } + this.Sinal = (this.importando ? this.Sinal : value.get_Sinal()); + } + } + + public List Planos + { + get + { + return this._planos; + } + set + { + this._planos = value; + base.OnPropertyChanged("Planos"); + } + } + + public ObservableCollection PlanosFiltrados + { + get + { + return this._planosFiltrados; + } + set + { + this._planosFiltrados = value; + base.OnPropertyChanged("PlanosFiltrados"); + } + } + + public List PlanosFiltro + { + get + { + return this._planosFiltro; + } + set + { + this._planosFiltro = value; + base.OnPropertyChanged("PlanosFiltro"); + } + } + + public List RelatorioFiltroPersonalizado + { + get + { + return this._filtroRelatorioPersonalizado; + } + set + { + this._filtroRelatorioPersonalizado = value; + base.OnPropertyChanged("RelatorioFiltroPersonalizado"); + } + } + + public ObservableCollection Saldos + { + get + { + return this._saldos; + } + set + { + this._saldos = value; + base.OnPropertyChanged("Saldos"); + } + } + + private bool Salvando + { + get; + set; + } + + public FiltroLancamento SelectedFiltro + { + get + { + return this._selectedFiltro; + } + set + { + this._selectedFiltro = value; + this.LimparLancamentos(); + base.OnPropertyChanged("SelectedFiltro"); + } + } + + public FiltroLancamentoData SelectedFiltroData + { + get + { + return this._selectedFiltroData; + } + set + { + this._selectedFiltroData = value; + this.LimparLancamentos(); + base.OnPropertyChanged("SelectedFiltroData"); + } + } + + public Fornecedor SelectedFornecedor + { + get + { + return this._selectedFornecedor; + } + set + { + this._selectedFornecedor = value; + this.LimparLancamentos(); + base.OnPropertyChanged("SelectedFornecedor"); + } + } + + public Lancamento SelectedLancamento + { + get + { + return this._selectedLancamento; + } + set + { + bool id; + bool flag; + bool id1; + if (value != null && value.get_Id() != 0) + { + this.IdLancamento = value.get_Id(); + } + else if (this.importando) + { + this.IdLancamento = (long)0; + } + if (value == null || value.get_Id() <= (long)0) + { + id = false; + } + else + { + Usuario usuario = Recursos.Usuario; + if (usuario != null) + { + id = usuario.get_Id() > (long)0; + } + else + { + id = false; + } + } + this.EnableIncluirNovo = id; + this._selectedLancamento = value; + if (value == null || value.get_Id() <= (long)0) + { + flag = false; + } + else + { + Usuario usuario1 = Recursos.Usuario; + if (usuario1 != null) + { + flag = usuario1.get_Id() > (long)0; + } + else + { + flag = false; + } + } + base.EnableButtons = flag; + Usuario usuario2 = Recursos.Usuario; + if (usuario2 != null) + { + id1 = usuario2.get_Id() > (long)0; + } + else + { + id1 = false; + } + this.EnableChanges = id1; + this.Alteracao = (value == null ? false : value.get_Controle().get_Id() > (long)0); + base.OnPropertyChanged("SelectedLancamento"); + this.Feed(value); + if (value == null || value.get_Id() == 0) + { + return; + } + this.LancamentoSelecionado = value; + } + } + + public Saldo SelectedSaldo + { + get + { + return this._selectedSaldo; + } + set + { + this._selectedSaldo = value; + base.OnPropertyChanged("SelectedSaldo"); + } + } + + public StatusLancamento SelectedStatus + { + get + { + return this._selectedStatus; + } + set + { + this._selectedStatus = value; + this.LimparLancamentos(); + base.OnPropertyChanged("SelectedStatus"); + } + } + + public StatusLancamento SelectedStatusImportacao + { + get + { + return this._selectedStatusImportacao; + } + set + { + this._selectedStatusImportacao = value; + base.OnPropertyChanged("SelectedStatusImportacao"); + } + } + + public bool SemValor + { + get + { + return this._semValor; + } + set + { + this._semValor = value; + if (value) + { + this.ValorInicial = null; + this.ValorFinal = null; + } + base.OnPropertyChanged("SemValor"); + } + } + + public Gestor.Model.Common.Sinal Sinal + { + get + { + return this._sinal; + } + set + { + this._sinal = value; + base.OnPropertyChanged("Sinal"); + } + } + + public SinteticoFinanceiroTipo SinteticoTipo + { + get + { + return this._sinteticoTipo; + } + set + { + this._sinteticoTipo = value; + base.OnPropertyChanged("SinteticoTipo"); + } + } + + public Type TipoDateTime + { + get + { + return this._tipoDateTime; + } + set + { + this._tipoDateTime = value; + base.OnPropertyChanged("TipoDateTime"); + } + } + + public Type TipoDecimal + { + get + { + return this._tipoDecimal; + } + set + { + this._tipoDecimal = value; + base.OnPropertyChanged("TipoDecimal"); + } + } + + public Type TipoEnum + { + get + { + return this._tipoEnum; + } + set + { + this._tipoEnum = value; + base.OnPropertyChanged("TipoEnum"); + } + } + + public Type TipoInt + { + get + { + return this._tipoInt; + } + set + { + this._tipoInt = value; + base.OnPropertyChanged("TipoInt"); + } + } + + public Type TipoLong + { + get + { + return this._tipoLong; + } + set + { + this._tipoLong = value; + base.OnPropertyChanged("TipoLong"); + } + } + + public Gestor.Model.Common.TipoPagamento TipoPagamento + { + get + { + return this._tipoPagamento; + } + set + { + this._tipoPagamento = value; + base.OnPropertyChanged("TipoPagamento"); + } + } + + public Type TipoString + { + get + { + return this._tipoString; + } + set + { + this._tipoString = value; + base.OnPropertyChanged("TipoString"); + } + } + + public ObservableCollection Totalizacao + { + get + { + return this._totalizacao; + } + set + { + this._totalizacao = value; + base.OnPropertyChanged("Totalizacao"); + } + } + + public Func>> ValidationEvent + { + get + { + return new Func>>(this.ValidateIncluir); + } + } + + public decimal Valor + { + get + { + return this._valor; + } + set + { + this._valor = value; + if (this.Vencimento <= Funcoes.GetNetworkTime().Date) + { + this.ValorPago = new decimal?(value); + } + base.OnPropertyChanged("Valor"); + } + } + + public string ValorFinal + { + get + { + return this._valorFinal; + } + set + { + this._valorFinal = value; + base.OnPropertyChanged("ValorFinal"); + } + } + + public string ValorInicial + { + get + { + return this._valorIncial; + } + set + { + this._valorIncial = value; + base.OnPropertyChanged("ValorInicial"); + } + } + + public decimal? ValorPago + { + get + { + return this._valorPago; + } + set + { + this._valorPago = value; + base.OnPropertyChanged("ValorPago"); + } + } + + public DateTime Vencimento + { + get + { + return this._vencimento; + } + set + { + if (this.Alterando == Visibility.Visible && value != this.VencimentoAnt) + { + this.VencimentoAlterado = true; + } + this.VencimentoAnt = value; + this._vencimento = value; + base.OnPropertyChanged("Vencimento"); + } + } + + public DateTime VencimentoAnt + { + get; + set; + } + + public Visibility VisibilityCentro + { + get + { + return this._visibilityCentro; + } + set + { + this._visibilityCentro = value; + base.OnPropertyChanged("VisibilityCentro"); + } + } + + public Visibility VisibilityConta + { + get + { + return this._visibilityConta; + } + set + { + this._visibilityConta = value; + base.OnPropertyChanged("VisibilityConta"); + } + } + + public Visibility VisibilityFornecedor + { + get + { + return this._visibilityFornecedor; + } + set + { + this._visibilityFornecedor = value; + base.OnPropertyChanged("VisibilityFornecedor"); + } + } + + public Visibility VisibilitySemValor + { + get + { + return this._visibilitySemValor; + } + set + { + this._visibilitySemValor = value; + base.OnPropertyChanged("VisibilitySemValor"); + } + } + + public Visibility VisibleFiltros + { + get + { + return this._visibleFiltros; + } + set + { + this._visibleFiltros = value; + base.OnPropertyChanged("VisibleFiltros"); + } + } + + public Visibility VisibleOlho + { + get + { + return this._visibleOlho; + } + set + { + this._visibleOlho = value; + base.OnPropertyChanged("VisibleOlho"); + } + } + + public FinanceiroViewModel() + { + this._servico = new FinanceiroServico(); + this.RelatorioFiltroPersonalizado = Funcoes.PopularFiltroFinanceiro(); + this.BuscaInicial(); + } + + public async void AdcionarFiltroPersonalizado() + { + string str; + DateTime dateTime; + decimal num; + int num1; + long num2; + List filtroPersonalizados; + List filtroPersonalizados1; + if (this.Filtro != null) + { + if (this.SemValor) + { + filtroPersonalizados = (this.PersonalizadoSelecionado == null ? new List() : ( + from x in this.PersonalizadoSelecionado + where x.get_Propriedade() == this.Filtro.get_Propriedade() + select x).ToList()); + List filtroPersonalizados2 = filtroPersonalizados; + if (filtroPersonalizados2.Count > 0) + { + filtroPersonalizados2.ForEach((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => this.PersonalizadoSelecionado.Remove(x)); + } + str = string.Concat(this.Filtro.get_Nome(), ": EM BRANCO"); + } + else + { + filtroPersonalizados1 = (this.PersonalizadoSelecionado == null ? new List() : this.PersonalizadoSelecionado.Where((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => { + if (x.get_Propriedade() != this.Filtro.get_Propriedade()) + { + return false; + } + return x.get_SemValor(); + }).ToList()); + List filtroPersonalizados3 = filtroPersonalizados1; + if (filtroPersonalizados3.Count > 0) + { + filtroPersonalizados3.ForEach((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => this.PersonalizadoSelecionado.Remove(x)); + } + string name = this.Filtro.get_Tipo().Name; + if (name == "DateTime") + { + if (!DateTime.TryParse(this.ValorInicial, out dateTime) || !DateTime.TryParse(this.ValorFinal, out dateTime) || DateTime.Parse(this.ValorInicial) > DateTime.Parse(this.ValorFinal)) + { + await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); + return; + } + else + { + str = string.Format("{0}: {1:d} até {2:d}", this.Filtro.get_Nome(), DateTime.Parse(this.ValorInicial), DateTime.Parse(this.ValorFinal)); + } + } + else if (name == "Decimal") + { + if (!decimal.TryParse(this.ValorInicial, out num) || !decimal.TryParse(this.ValorFinal, out num) || Math.Abs(decimal.Parse(this.ValorInicial)) > Math.Abs(decimal.Parse(this.ValorFinal))) + { + await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); + return; + } + else + { + str = string.Format("{0}: {1:n2} até {2:n2}", this.Filtro.get_Nome(), decimal.Parse(this.ValorInicial), decimal.Parse(this.ValorFinal)); + } + } + else if (name == "Int32") + { + if (!int.TryParse(this.ValorInicial, out num1) || !int.TryParse(this.ValorFinal, out num1) || int.Parse(this.ValorInicial) > int.Parse(this.ValorFinal)) + { + await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); + return; + } + else + { + str = string.Format("{0}: {1:n0} até {2:n0}", this.Filtro.get_Nome(), int.Parse(this.ValorInicial), int.Parse(this.ValorFinal)); + } + } + else if (name != "Int64") + { + if (!string.IsNullOrEmpty(this.ValorInicial)) + { + str = string.Concat(this.Filtro.get_Nome(), " = ", this.ValorInicial); + } + else + { + await base.ShowMessage("O VALOR DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); + return; + } + } + else if (!long.TryParse(this.ValorInicial, out num2) || !long.TryParse(this.ValorFinal, out num2) || long.Parse(this.ValorInicial) > (long)int.Parse(this.ValorFinal)) + { + await base.ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE.", "OK", "", false); + return; + } + else + { + str = string.Format("{0}: {1:n0} até {2:n0}", this.Filtro.get_Nome(), long.Parse(this.ValorInicial), long.Parse(this.ValorFinal)); + } + } + if (this.PersonalizadoSelecionado == null) + { + this.PersonalizadoSelecionado = new ObservableCollection(); + } + ObservableCollection personalizadoSelecionado = this.PersonalizadoSelecionado; + Gestor.Model.Domain.Relatorios.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Relatorios.FiltroPersonalizado(); + filtroPersonalizado.set_Nome(this.Filtro.get_Nome()); + filtroPersonalizado.set_Propriedade(this.Filtro.get_Propriedade()); + filtroPersonalizado.set_Tipo(this.Filtro.get_Tipo()); + filtroPersonalizado.set_ValorIncial(this.ValorInicial); + filtroPersonalizado.set_ValorFinal(this.ValorFinal); + filtroPersonalizado.set_SemValor(this.SemValor); + filtroPersonalizado.set_Descricao(str); + personalizadoSelecionado.Add(filtroPersonalizado); + this.Filtro = null; + this.ValorInicial = string.Empty; + this.ValorFinal = string.Empty; + this.PesquisaPersonalizada(); + } + } + + public void AdicionarFiltro(Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtro) + { + if (filtro == null) + { + return; + } + if (this.FiltroPersonalizadoSelecionado == null) + { + this.FiltroPersonalizadoSelecionado = new ObservableCollection(); + } + this.VisibleFiltros = Visibility.Visible; + if (this.FiltroPersonalizadoSelecionado.Any((Gestor.Model.Domain.Financeiro.FiltroPersonalizado x) => { + if (x.get_Id() != filtro.get_Id()) + { + return false; + } + return x.get_Tipo() == filtro.get_Tipo(); + })) + { + return; + } + this.FiltroPersonalizadoSelecionado.Add(filtro); + this.FiltrarPersonalizado(); + } + + public void AdicionarFiltros() + { + ExtensionMethods.ForEach( + from x in this.PlanosFiltro + where x.get_Selecionado() + select x, (Gestor.Model.Domain.Financeiro.Planos x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Id(x.get_Id()); + filtroPersonalizado.set_Tipo(1); + filtroPersonalizado.set_Descricao(x.get_Descricao()); + this.AdicionarFiltro(filtroPersonalizado); + }); + this.PlanosFiltro = new List( + from x in this.Planos + orderby x.get_Descricao() + select x); + ExtensionMethods.ForEach( + from x in this.ContaFiltro + where x.get_Selecionado() + select x, (BancosContas x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Id(x.get_Id()); + filtroPersonalizado.set_Tipo(3); + filtroPersonalizado.set_Descricao(x.get_Descricao()); + this.AdicionarFiltro(filtroPersonalizado); + }); + this.ContaFiltro = new List( + from x in this.Contas + orderby x.get_Descricao() + select x); + ExtensionMethods.ForEach( + from x in this.CentroFiltro + where x.get_Selecionado() + select x, (Gestor.Model.Domain.Financeiro.Centro x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Id(x.get_Id()); + filtroPersonalizado.set_Tipo(2); + filtroPersonalizado.set_Descricao(x.get_Descricao()); + this.AdicionarFiltro(filtroPersonalizado); + x.set_Selecionado(false); + }); + this.CentroFiltro = new List( + from x in this.Centros + orderby x.get_Descricao() + select x); + } + + private async Task AdicionarParcelaRange() + { + base.Loading(true); + List lancamentos = new List(); + ObservableCollection lancamentosFiltrados = this.LancamentosFiltrados; + IEnumerable selecionado = + from x in lancamentosFiltrados + where x.get_Selecionado() + select x; + List list = selecionado.Select((Lancamento x) => { + Lancamento lancamento = new Lancamento(); + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + controleFinanceiro.set_Centro(x.get_Controle().get_Centro()); + controleFinanceiro.set_Fornecedor(x.get_Controle().get_Fornecedor()); + controleFinanceiro.set_Historico(x.get_Controle().get_Historico()); + controleFinanceiro.set_Id(x.get_Controle().get_Id()); + controleFinanceiro.set_Parcelas(x.get_Controle().get_Parcelas() + 1); + controleFinanceiro.set_Plano(x.get_Controle().get_Plano()); + lancamento.set_Controle(controleFinanceiro); + lancamento.set_Historico(x.get_Historico()); + lancamento.set_Observacao(x.get_Observacao()); + lancamento.set_Vencimento(x.get_Vencimento().AddMonths(1)); + lancamento.set_Conta(x.get_Conta()); + lancamento.set_Parcela(x.get_Parcela() + 1); + lancamento.set_Documento(x.get_Documento()); + lancamento.set_Sinal(x.get_Sinal()); + lancamento.set_TipoPagamento(x.get_TipoPagamento()); + lancamento.set_Valor(x.get_Valor()); + return lancamento; + }).ToList(); + foreach (Lancamento lancamento1 in list) + { + if (await this._servico.BuscarLancamento(lancamento1.get_Controle().get_Id(), lancamento1.get_Parcela()) != null) + { + continue; + } + lancamentos.Add(lancamento1); + } + await this._servico.IncluirRange(lancamentos); + if (this._servico.Sucesso) + { + await this.Buscar(); + base.ToggleSnackBar("INCLUSÃO DE PARCELA REALIZADA COM SUCESSO", true); + base.Loading(false); + } + else + { + base.Loading(false); + } + lancamentos = null; + } + + public async Task AlterarLancamentos(Lancamento lancamentoAtual, bool alterarVencimento, bool alterarValores) + { + Func func = null; + List lancamentos = await this._servico.BuscarLancamentosPorControle(lancamentoAtual.get_Controle().get_Id()); + int num = 1; + List lancamentos1 = lancamentos; + Func func1 = func; + if (func1 == null) + { + Func parcela = (Lancamento l) => l.get_Parcela() > lancamentoAtual.get_Parcela(); + Func func2 = parcela; + func = parcela; + func1 = func2; + } + foreach (Lancamento lancamento in lancamentos1.Where(func1)) + { + if (!lancamento.get_Baixado()) + { + if (alterarVencimento) + { + lancamento.set_Vencimento(lancamentoAtual.get_Vencimento().AddMonths(num)); + } + if (alterarValores) + { + lancamento.set_Valor(lancamentoAtual.get_Valor()); + } + await this._servico.Save(lancamento); + } + num++; + } + this.SelectedLancamento = lancamentoAtual; + } + + public async Task Atualizar(List list) + { + DateTime? baixa; + DateTime? nullable; + string str; + bool flag; + base.Loading(true); + List lancamentos = new List(); + List lancamentos1 = new List(); + List lancamentos2 = new List(); + foreach (Lancamento lancamento in list) + { + if (lancamento.get_Baixado()) + { + continue; + } + if (!lancamento.get_Selecionado()) + { + baixa = null; + lancamento.set_Baixa(baixa); + } + baixa = lancamento.get_Baixa(); + if (baixa.HasValue) + { + Saldo saldo = await this.VerificaSaldo(lancamento.get_Conta().get_Id(), false); + if (saldo == null) + { + continue; + } + baixa = saldo.get_DataInicio(); + nullable = lancamento.get_Baixa(); + flag = (baixa.HasValue & nullable.HasValue ? baixa.GetValueOrDefault() > nullable.GetValueOrDefault() : false); + if (flag) + { + continue; + } + } + if (lancamento.get_Selecionado()) + { + str = (lancamento.get_Observacao() == null ? "" : string.Concat("\n ", lancamento.get_Observacao())); + string str1 = str; + Lancamento lancamento1 = lancamento; + object[] id = new object[] { Recursos.Usuario.get_Id(), Recursos.Usuario.get_Nome(), null, null }; + DateTime networkTime = Funcoes.GetNetworkTime(); + id[2] = networkTime.ToString("F").ToUpper(); + id[3] = str1; + lancamento1.set_Observacao(string.Format("BAIXA AGRUPADA REALIZADA PELO USUARIO {0} {1} EM {2}{3}", id)); + } + List> keyValuePairs = lancamento.Validate(); + if (keyValuePairs != null && keyValuePairs.Count > 0) + { + continue; + } + nullable = lancamento.get_Baixa(); + if (!nullable.HasValue) + { + lancamentos.Add(lancamento); + } + else + { + lancamentos1.Add(lancamento); + } + lancamentos2.Add(lancamento); + } + if (lancamentos2.Count != 0) + { + object[] count = new object[] { lancamentos.Count, Environment.NewLine, lancamentos1.Count, Environment.NewLine, Environment.NewLine }; + if (await base.ShowMessage(string.Format("{0} LANÇAMENTOS SERÃO ATUALIZADOS.{1}{2} LANÇAMENTOS SERÃO BAIXADOS.{3}{4}DESEJA REALMENTE PROSSEGUIR?", count), "SIM", "NÃO", false)) + { + await this._servico.Atualizar(lancamentos2); + if (this._servico.Sucesso) + { + if (await base.ShowMessage("DESEJA GERAR O RELATÓRIO NOVAMENTE?", "SIM,", "NÃO", false)) + { + await this.Buscar(); + } + base.ToggleSnackBar("ATUALIZAÇÃO REALIZADA COM SUCESSO", true); + await this.CarregarSaldos(); + base.Loading(false); + } + else + { + base.Loading(false); + } + } + else + { + base.Loading(false); + } + } + else + { + await base.ShowMessage("NÃO HÁ LANÇAMENTOS PARA SEREM ATUALIZADOS.", "OK", "", false); + base.Loading(false); + } + lancamentos = null; + lancamentos1 = null; + lancamentos2 = null; + } + + public void Bind() + { + // + // Current member / type: System.Void Gestor.Application.ViewModels.Financeiro.FinanceiroViewModel::Bind() + // File path: C:\AggerSeguros\Gestor.Application.exe + // + // Product version: 0.0.0.0 + // Exception in: System.Void Bind() + // + // Object reference not set to an instance of an object. + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.FindLowestCommonAncestor(ICollection`1 typeNodes) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 515 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.MergeWithLowestCommonAncestor() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 459 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.ProcessSingleConstraints() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 378 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.InferTypes() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 331 + // at Telerik.JustDecompiler.Decompiler.ExpressionDecompilerStep.Process(DecompilationContext theContext, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\ExpressionDecompilerStep.cs:line 104 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61 + // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 133 + // + // mailto: JustDecompilePublicFeedback@telerik.com + + } + + public void BindImportando() + { + // + // Current member / type: System.Void Gestor.Application.ViewModels.Financeiro.FinanceiroViewModel::BindImportando() + // File path: C:\AggerSeguros\Gestor.Application.exe + // + // Product version: 0.0.0.0 + // Exception in: System.Void BindImportando() + // + // Object reference not set to an instance of an object. + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.FindLowestCommonAncestor(ICollection`1 typeNodes) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 515 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.MergeWithLowestCommonAncestor() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 459 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.ProcessSingleConstraints() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 378 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.InferTypes() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 331 + // at Telerik.JustDecompiler.Decompiler.ExpressionDecompilerStep.Process(DecompilationContext theContext, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\ExpressionDecompilerStep.cs:line 104 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61 + // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 133 + // + // mailto: JustDecompilePublicFeedback@telerik.com + + } + + private async void BuscaInicial() + { + base.Loading(true); + this.Planos = await (new PlanoServico()).BuscarPlanos(); + FinanceiroViewModel observableCollection = this; + List planos = this.Planos; + IEnumerable ativo = + from x in planos + where x.get_Ativo() + select x; + observableCollection.PlanosFiltrados = new ObservableCollection( + from x in ativo + orderby x.get_Descricao() + select x); + this.Contas = await (new BancosContasServico()).BuscarBancos(); + FinanceiroViewModel financeiroViewModel = this; + List contas = this.Contas; + IEnumerable bancosContas = + from x in contas + where x.get_Ativo() + select x; + financeiroViewModel.ContasFiltradas = new ObservableCollection( + from x in bancosContas + orderby x.get_Descricao() + select x); + this.Centros = await (new CentroServico()).BuscarCentros(); + FinanceiroViewModel observableCollection1 = this; + List centros = this.Centros; + IEnumerable ativo1 = + from x in centros + where x.get_Ativo() + select x; + observableCollection1.CentrosFiltrados = new ObservableCollection( + from x in ativo1 + orderby x.get_Descricao() + select x); + FinanceiroViewModel planos1 = this; + List planos2 = this.Planos; + planos1.PlanosFiltro = new List( + from x in planos2 + orderby x.get_Descricao() + select x); + FinanceiroViewModel bancosContas1 = this; + List contas1 = this.Contas; + bancosContas1.ContaFiltro = new List( + from x in contas1 + orderby x.get_Descricao() + select x); + FinanceiroViewModel centros1 = this; + List centros2 = this.Centros; + centros1.CentroFiltro = new List( + from x in centros2 + orderby x.get_Descricao() + select x); + this.PopularFiltro(); + await this.Buscar(); + base.Loading(false); + } + + public async Task Buscar() + { + List list; + bool flag; + List nums; + List list1; + List nums1; + List list2; + List nums2; + this.Importando = false; + DateTime? inicio = this.Inicio; + if (inicio.HasValue) + { + inicio = this.Fim; + if (inicio.HasValue) + { + inicio = this.Inicio; + DateTime? fim = this.Fim; + flag = (inicio.HasValue & fim.HasValue ? inicio.GetValueOrDefault() > fim.GetValueOrDefault() : false); + if (!flag) + { + this.PersonalizadoSelecionado = null; + switch (this.SelectedFiltro) + { + case 1: + { + FinanceiroServico financeiroServico = this._servico; + fim = this.Inicio; + DateTime value = fim.Value; + fim = this.Fim; + list = await financeiroServico.BuscarLancamentosPorBaixa(value, fim.Value); + break; + } + case 2: + { + FinanceiroServico financeiroServico1 = this._servico; + fim = this.Inicio; + DateTime dateTime = fim.Value; + fim = this.Fim; + list = await financeiroServico1.BuscarLancamentosPorPagamento(dateTime, fim.Value); + break; + } + case 3: + { + if (this.SelectedFornecedor != null) + { + list = await this._servico.BuscarLancamentosPorFornecedor(this.SelectedFornecedor.get_Id(), this.SelectedStatus); + break; + } + else + { + return; + } + } + case 4: + { + FinanceiroServico financeiroServico2 = this._servico; + fim = this.Inicio; + DateTime value1 = fim.Value; + fim = this.Fim; + list = await financeiroServico2.BuscarLancamentosPorLancamento(value1, fim.Value, this.SelectedStatus); + break; + } + case 5: + { + FinanceiroServico financeiroServico3 = this._servico; + fim = this.Inicio; + DateTime dateTime1 = fim.Value; + fim = this.Fim; + List lancamentos = await financeiroServico3.BuscarLancamentosPersonalizados(dateTime1, fim.Value, this.SelectedStatus, this.SelectedFiltroData); + if (this.FiltroPersonalizadoSelecionado != null) + { + ObservableCollection filtroPersonalizadoSelecionado = this.FiltroPersonalizadoSelecionado; + IEnumerable tipo = + from x in filtroPersonalizadoSelecionado + where x.get_Tipo() == 0 + select x; + nums = ( + from x in tipo + select x.get_Id()).ToList(); + } + else + { + nums = new List(); + } + List nums3 = nums; + if (this.FiltroPersonalizadoSelecionado != null) + { + ObservableCollection observableCollection = this.FiltroPersonalizadoSelecionado; + IEnumerable filtroPersonalizados = + from x in observableCollection + where x.get_Tipo() == 2 + select x; + list1 = ( + from x in filtroPersonalizados + select x.get_Id()).ToList(); + } + else + { + list1 = new List(); + } + List nums4 = list1; + if (this.FiltroPersonalizadoSelecionado != null) + { + ObservableCollection filtroPersonalizadoSelecionado1 = this.FiltroPersonalizadoSelecionado; + IEnumerable tipo1 = + from x in filtroPersonalizadoSelecionado1 + where x.get_Tipo() == 1 + select x; + nums1 = ( + from x in tipo1 + select x.get_Id()).ToList(); + } + else + { + nums1 = new List(); + } + List nums5 = nums1; + if (this.FiltroPersonalizadoSelecionado != null) + { + ObservableCollection observableCollection1 = this.FiltroPersonalizadoSelecionado; + IEnumerable filtroPersonalizados1 = + from x in observableCollection1 + where x.get_Tipo() == 3 + select x; + list2 = ( + from x in filtroPersonalizados1 + select x.get_Id()).ToList(); + } + else + { + list2 = new List(); + } + List nums6 = list2; + if (this.FiltroPersonalizadoSelecionado != null) + { + ObservableCollection filtroPersonalizadoSelecionado2 = this.FiltroPersonalizadoSelecionado; + IEnumerable tipo2 = + from x in filtroPersonalizadoSelecionado2 + where x.get_Tipo() == 4 + select x; + nums2 = ( + from x in tipo2 + select x.get_Id()).ToList(); + } + else + { + nums2 = new List(); + } + List nums7 = nums2; + list = lancamentos.Where((Lancamento x) => { + if (nums3.Count != 0 && (x.get_Controle().get_Fornecedor() == null || !nums3.Contains(x.get_Controle().get_Fornecedor().get_Id())) || nums4.Count != 0 && (x.get_Controle().get_Centro() == null || !nums4.Contains(x.get_Controle().get_Centro().get_Id())) || nums5.Count != 0 && (x.get_Controle().get_Plano() == null || !nums5.Contains(x.get_Controle().get_Plano().get_Id())) || nums6.Count != 0 && (x.get_Conta() == null || !nums6.Contains(x.get_Conta().get_Id()))) + { + return false; + } + if (nums7.Count == 0) + { + return true; + } + return nums7.Contains((long)x.get_Sinal()); + }).ToList(); + break; + } + default: + { + FinanceiroServico financeiroServico4 = this._servico; + fim = this.Inicio; + DateTime value2 = fim.Value; + fim = this.Fim; + list = await financeiroServico4.BuscarLancamentos(value2, fim.Value, this.SelectedStatus); + break; + } + } + List lancamentos1 = list; + lancamentos1.ForEach((Lancamento x) => x.Initialize()); + this.Lancamentos = new ObservableCollection(list); + this.LancamentosFiltrados = this.Lancamentos; + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + this.SelectedLancamento = this.LancamentosFiltrados.FirstOrDefault(); + await this.CarregarSaldos(); + return; + } + else + { + await base.ShowMessage("A DATA DE INÍCIO NÃO PODE SER SUPERIOR A DATA FINAL.", "OK", "", false); + return; + } + } + } + await base.ShowMessage("NECESSÁRIO PREENCHER TANTO A DATA DE INÍCIO QUANTO A DATA FINAL PARA REALIZAR A PESQUISA.", "OK", "", false); + } + + internal async Task BuscarLancamentosVinculo() + { + DateTime vencimento; + DateTime? dataInicio; + DateTime valueOrDefault; + if (this.SelectedLancamento.get_Conta() != null) + { + Saldo saldo = this.Saldos.FirstOrDefault((Saldo x) => x.get_Id() == this.SelectedLancamento.get_Conta().get_Id()); + if (saldo != null) + { + dataInicio = saldo.get_DataInicio(); + } + else + { + dataInicio = null; + } + } + else + { + vencimento = this.SelectedLancamento.get_Vencimento(); + dataInicio = new DateTime?(vencimento.AddDays(-5)); + } + DateTime? nullable = dataInicio; + if (nullable.HasValue) + { + valueOrDefault = nullable.GetValueOrDefault(); + } + else + { + vencimento = this.SelectedLancamento.get_Vencimento(); + valueOrDefault = vencimento.AddDays(-5); + } + DateTime dateTime = valueOrDefault; + List list = await this._servico.BuscarLancamentosPorFornecedor(this.FornecedorInclusao.get_Id(), dateTime, this.Sinal); + ObservableCollection lancamentos = this.Lancamentos; + List nums = ( + from x in lancamentos + select x.get_Id()).ToList(); + list = ( + from x in list + where !nums.Contains(x.get_Id()) + select x).ToList(); + this.LancamentosVinculo = new ObservableCollection(list); + } + + public void CancelarAlteracao() + { + this.LancamentosFiltrados = this.LancamentosFiltradosCopia; + this.SelectedLancamento = this.LancamentosFiltrados.FirstOrDefault((Lancamento x) => { + long? nullable; + long id = x.get_Id(); + Lancamento lancamentoSelecionado = this.LancamentoSelecionado; + if (lancamentoSelecionado != null) + { + nullable = new long?(lancamentoSelecionado.get_Id()); + } + else + { + nullable = null; + } + long? nullable1 = nullable; + return id == nullable1.GetValueOrDefault() & nullable1.HasValue; + }); + } + + public async Task CarregarSaldos() + { + this.Saldos = new ObservableCollection(); + BancosContasServico bancosContasServico = new BancosContasServico(); + foreach (BancosContas contasFiltrada in this.ContasFiltradas) + { + Saldo saldo = await bancosContasServico.BuscarSaldoAberto(contasFiltrada.get_Id()); + if (saldo == null) + { + continue; + } + DateTime date = Funcoes.GetNetworkTime().Date; + saldo.set_DataFinal(new DateTime?(date.AddDays(1))); + saldo = await bancosContasServico.FecharSaldo(saldo); + this.Saldos.Add(saldo); + } + this.SelectedSaldo = this.Saldos.FirstOrDefault(); + bancosContasServico = null; + } + + private Tuple CorrigeLancamentos(OfxDocument lancamentos, List codigoBanco) + { + DateTime? nullable; + DateTime? nullable1; + DateTime? nullable2; + if (!this.VerificaFiltroErrado(lancamentos)) + { + if (this.VerificaDataInvertida(lancamentos)) + { + return new Tuple(lancamentos.get_StatementEnd(), lancamentos.get_StatementStart()); + } + return new Tuple(lancamentos.get_StatementStart(), lancamentos.get_StatementEnd()); + } + Transaction transaction = ( + from lanc in lancamentos.get_Transactions() + orderby lanc.get_Date() + select lanc).First(); + if (transaction != null) + { + nullable1 = new DateTime?(transaction.get_Date()); + } + else + { + nullable = null; + nullable1 = nullable; + } + nullable = nullable1; + DateTime value = nullable.Value; + Transaction transaction1 = ( + from lanc in lancamentos.get_Transactions() + orderby lanc.get_Date() descending + select lanc).First(); + if (transaction1 != null) + { + nullable2 = new DateTime?(transaction1.get_Date()); + } + else + { + nullable = null; + nullable2 = nullable; + } + nullable = nullable2; + return new Tuple(value, nullable.Value); + } + + public void DeSelecionarLancamento(Lancamento lancamento) + { + Lancamento lancamento1 = (lancamento.get_Id() > (long)0 ? this.LancamentosFiltrados.First((Lancamento x) => x.get_Id() == lancamento.get_Id()) : this.LancamentosFiltrados.First((Lancamento x) => { + long? nullable; + long? nullable1; + long? nullable2; + long? nullable3; + long? nullable4; + if (x.get_Id() == lancamento.get_Id()) + { + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + if (fornecedor != null) + { + nullable1 = new long?(fornecedor.get_Id()); + } + else + { + nullable = null; + nullable1 = nullable; + } + } + else + { + nullable = null; + nullable1 = nullable; + } + long? nullable5 = nullable1; + ControleFinanceiro controleFinanceiro = lancamento.get_Controle(); + if (controleFinanceiro != null) + { + Fornecedor fornecedor1 = controleFinanceiro.get_Fornecedor(); + if (fornecedor1 != null) + { + nullable2 = new long?(fornecedor1.get_Id()); + } + else + { + nullable = null; + nullable2 = nullable; + } + } + else + { + nullable = null; + nullable2 = nullable; + } + long? nullable6 = nullable2; + if (nullable5.GetValueOrDefault() == nullable6.GetValueOrDefault() & nullable5.HasValue == nullable6.HasValue && x.get_Valor() == lancamento.get_Valor() && x.get_Vencimento() == lancamento.get_Vencimento()) + { + ControleFinanceiro controle1 = x.get_Controle(); + if (controle1 != null) + { + Gestor.Model.Domain.Financeiro.Planos plano = controle1.get_Plano(); + if (plano != null) + { + nullable3 = new long?(plano.get_Id()); + } + else + { + nullable = null; + nullable3 = nullable; + } + } + else + { + nullable = null; + nullable3 = nullable; + } + nullable6 = nullable3; + ControleFinanceiro controleFinanceiro1 = lancamento.get_Controle(); + if (controleFinanceiro1 != null) + { + Gestor.Model.Domain.Financeiro.Planos plano1 = controleFinanceiro1.get_Plano(); + if (plano1 != null) + { + nullable4 = new long?(plano1.get_Id()); + } + else + { + nullable = null; + nullable4 = nullable; + } + } + else + { + nullable = null; + nullable4 = nullable; + } + nullable5 = nullable4; + return nullable6.GetValueOrDefault() == nullable5.GetValueOrDefault() & nullable6.HasValue == nullable5.HasValue; + } + } + return false; + })); + lancamento1.set_Selecionado(false); + if (!lancamento1.get_Baixado()) + { + DateTime? nullable7 = null; + lancamento1.set_Baixa(nullable7); + nullable7 = null; + lancamento1.set_Pagamento(nullable7); + lancamento1.set_ValorPago(new decimal?(new decimal())); + } + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + this.Totalizar(); + } + + public async Task Excluir() + { + bool flag; + long? nullable; + object historico; + bool flag1; + long num; + Lancamento lancamento; + if (this.SelectedLancamento != null && this.SelectedLancamento.get_Id() != 0) + { + base.Loading(true); + lancamento = await this._servico.BuscarLancamento(this.SelectedLancamento.get_Id()); + Saldo saldo = await this.VerificaSaldo(this.SelectedLancamento.get_Conta().get_Id(), true); + if (saldo != null) + { + DateTime? dataInicio = saldo.get_DataInicio(); + DateTime? baixa = lancamento.get_Baixa(); + flag = (dataInicio.HasValue & baixa.HasValue ? dataInicio.GetValueOrDefault() > baixa.GetValueOrDefault() : false); + if (flag) + { + await base.ShowMessage("LANÇAMENTO NÃO PODE SER EXCLUÍDO POIS NÃO POSSUI SALDO ABERTO PARA O PERÍODO.", "OK", "", false); + base.Loading(false); + } + else if (!await base.ShowMessage("DESEJA REAMENTE EXCLUIR O LANÇAMENTO SELECIONADO?", "SIM", "NÃO", false)) + { + base.Loading(false); + } + else if (await this._servico.Excluir(this.SelectedLancamento)) + { + FinanceiroViewModel financeiroViewModel = this; + Lancamento selectedLancamento = this.SelectedLancamento; + if (selectedLancamento != null) + { + nullable = new long?(selectedLancamento.get_Id()); + } + else + { + nullable = null; + } + object obj = nullable; + Lancamento selectedLancamento1 = this.SelectedLancamento; + if (selectedLancamento1 != null) + { + historico = selectedLancamento1.get_Historico(); + } + else + { + historico = null; + } + string str = string.Format("EXCLUIU O LANÇAMENTO DO ID {0} HISTORICO: {1}", obj, historico); + Lancamento lancamento1 = this.SelectedLancamento; + if (lancamento1 != null) + { + lancamento1.get_Id(); + flag1 = false; + } + else + { + flag1 = true; + } + num = (flag1 ? (long)0 : this.SelectedLancamento.get_Id()); + financeiroViewModel.RegistrarAcao(str, num, new TipoTela?(25), null); + base.ToggleSnackBar("EXCLUSÃO REALIZADA COM SUCESSO", true); + await this.Buscar(); + base.Loading(false); + } + else + { + base.Loading(false); + } + } + } + lancamento = null; + } + + public async Task ExcluirBaixa() + { + bool flag; + if (this.SelectedLancamento != null && this.SelectedLancamento.get_Id() != 0) + { + base.Loading(true); + DateTime? baixa = await this._servico.BuscarLancamento(this.SelectedLancamento.get_Id()).get_Baixa(); + if (!baixa.HasValue) + { + await base.ShowMessage("LANÇAMENTO AINDA NÃO BAIXADO. PROCESSO INTERROMPIDO", "OK", "", false); + base.Loading(false); + } + else if (await base.ShowMessage("DESEJA REAMENTE EXCLUIR A BAIXA DO LANÇAMENTO SELECIONADO?", "SIM", "NÃO", false)) + { + Saldo saldo = await this.VerificaSaldo(this.SelectedLancamento.get_Conta().get_Id(), true); + if (saldo != null) + { + baixa = saldo.get_DataInicio(); + DateTime? nullable = this.SelectedLancamento.get_Baixa(); + flag = (baixa.HasValue & nullable.HasValue ? baixa.GetValueOrDefault() > nullable.GetValueOrDefault() : false); + if (!flag) + { + nullable = null; + this.SelectedLancamento.set_Baixa(nullable); + this.SelectedLancamento.set_ValorPago(new decimal?(new decimal())); + nullable = null; + this.SelectedLancamento.set_Pagamento(nullable); + this.SelectedLancamento.set_Baixado(false); + this.SelectedLancamento = await this._servico.Save(this.SelectedLancamento); + if (this.importando) + { + this.BindImportando(); + this.LancamentosFiltrados = this.Lancamentos; + base.Loading(false); + } + else if (this._servico.Sucesso) + { + base.ToggleSnackBar("EXCLUSÃO DE BAIXA REALIZADA COM SUCESSO", true); + await this.Buscar(); + base.Loading(false); + } + } + else + { + await base.ShowMessage("LANÇAMENTO NÃO PODE TER SUA BAIXA EXCLUÍDA POIS NÃO POSSUI SALDO ABERTO PARA O PERÍODO.", "OK", "", false); + base.Loading(false); + } + } + } + else + { + base.Loading(false); + } + } + } + + public async Task ExcluirBaixaRange() + { + bool flag; + List lancamentos; + ObservableCollection lancamentosFiltrados = this.LancamentosFiltrados; + List list = lancamentosFiltrados.Where((Lancamento x) => { + if (x.get_Selecionado() && x.get_Controle().get_Plano() != null) + { + return true; + } + if (!x.get_Historico().Equals("TRANSFERÊNCIA ENTRE CONTAS") || !x.get_Selecionado()) + { + return false; + } + return x.get_Controle().get_Plano() == null; + }).ToList(); + if (list.Count == 0) + { + await base.ShowMessage("NÃO HÁ LANÇAMENTOS SELECIONADOS, SELECIONE-OS ANTES DE EXCLUIR A BAIXA.", "OK", "", false); + } + else if (await base.ShowMessage("DESEJA REAMENTE EXCLUIR A BAIXA DOS LANÇAMENTOS SELECIONADOS?", "SIM", "NÃO", false)) + { + base.Loading(true); + lancamentos = new List(); + bool flag1 = false; + foreach (Lancamento lancamento in list) + { + Saldo saldo = await this.VerificaSaldo(lancamento.get_Conta().get_Id(), false); + if (saldo == null || !lancamento.get_Baixado()) + { + continue; + } + DateTime? dataInicio = saldo.get_DataInicio(); + DateTime? baixa = lancamento.get_Baixa(); + flag = (dataInicio.HasValue & baixa.HasValue ? dataInicio.GetValueOrDefault() > baixa.GetValueOrDefault() : false); + if (!flag) + { + baixa = null; + lancamento.set_Baixa(baixa); + lancamento.set_ValorPago(new decimal?(new decimal())); + baixa = null; + lancamento.set_Pagamento(baixa); + lancamentos.Add(lancamento); + lancamento = null; + } + else + { + flag1 = true; + } + } + if (lancamentos.Count != 0) + { + bool flag2 = flag1; + if (flag2) + { + flag2 = !await base.ShowMessage(string.Concat("HÁ LANÇAMENTOS SELECIONADOS QUE NÃO PODERÃO TER A BAIXA EXCLUÍDA. ", Environment.NewLine, "DESEJA PROSSEGUIR COM A EXCLUSÃO DA BAIXA DOS DEMAIS LANÇAMENTOS?"), "SIM", "NÃO", false); + } + if (!flag2) + { + await this._servico.Atualizar(lancamentos); + if (this._servico.Sucesso) + { + base.ToggleSnackBar(string.Format("EXCLUSÃO DE BAIXA DE {0} DO TOTAL DE {1} LANÇAMENTOS SELECIONADOS REALIZADA COM SUCESSO.", lancamentos.Count, list.Count), true); + await this.Buscar(); + base.Loading(false); + } + else + { + base.Loading(false); + } + } + else + { + base.Loading(false); + } + } + else + { + await base.ShowMessage("NÃO FOI POSSÍVEL FAZER A EXCLUSÃO, POIS NÃO HÁ LANÇAMENTOS BAIXADOS DENTRO DO ÚLTIMO SALDO ABERTO. PROCESSO INTERROMPIDO", "OK", "", false); + base.Loading(false); + } + } + list = null; + lancamentos = null; + } + + public void ExcluirFiltro(Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtro) + { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = this.FiltroPersonalizadoSelecionado.First((Gestor.Model.Domain.Financeiro.FiltroPersonalizado x) => { + if (x.get_Id() != filtro.get_Id()) + { + return false; + } + return x.get_Tipo() == filtro.get_Tipo(); + }); + this.FiltroPersonalizadoSelecionado.Remove(filtroPersonalizado); + this.FiltroPersonalizadoSelecionado = new ObservableCollection(this.FiltroPersonalizadoSelecionado); + this.FiltrarPersonalizado(); + } + + public async Task ExcluirRange() + { + int? nullable; + bool flag1; + List lancamentos; + ObservableCollection lancamentosFiltrados = this.LancamentosFiltrados; + List list = ( + from x in lancamentosFiltrados + where x.get_Selecionado() + select x).ToList(); + if (list.Count == 0) + { + await base.ShowMessage("NÃO HÁ LANÇAMENTOS SELECIONADOS, SELECIONE-OS ANTES DE EXCLUIR.", "OK", "", false); + } + else if (await base.ShowMessage("DESEJA REAMENTE EXCLUIR OS LANÇAMENTOS SELECIONADOS? ESSE PROCESSO É IRREVERSÍVEL.", "SIM", "NÃO", false)) + { + base.Loading(true); + List lancamentos1 = new List(); + ObservableCollection observableCollection = this.LancamentosFiltrados; + List list1 = observableCollection.Where((Lancamento x) => { + if (!x.get_Selecionado()) + { + return false; + } + return x.get_Historico().Equals("TRANSFERÊNCIA ENTRE CONTAS"); + }).ToList(); + list1.ForEach((Lancamento x) => { + Lancamento lancamento = list1.FirstOrDefault((Lancamento z) => { + if (z.get_Controle().get_Id() != this.x.get_Controle().get_Id() || !(this.x.get_Valor() == z.get_Valor())) + { + return false; + } + return this.x.get_Sinal() != z.get_Sinal(); + }); + if (lancamento == null || lancamentos1.Where((Lancamento z) => { + if ((object)z == (object)x) + { + return true; + } + return (object)z == (object)lancamento; + }).ToList().Count > 0) + { + return; + } + lancamentos1.AddRange(new List() + { + x, + lancamento + }); + }); + List lancamentos2 = list1; + if (lancamentos2 != null) + { + nullable = new int?(lancamentos2.Count); + } + else + { + nullable = null; + } + int? nullable1 = nullable; + int count = lancamentos1.Count; + bool valueOrDefault = !(nullable1.GetValueOrDefault() == count & nullable1.HasValue); + if (valueOrDefault) + { + valueOrDefault = !await base.ShowMessage(string.Concat("HÁ TRANSFERÊNCIA ENTRE CONTAS SELECIONADOS QUE NÃO PODERÃO TER A BAIXA EXCLUÍDA, PARA EXCLUIR É NECESSÁRIO SELECIONAR O DÉBITO E O CRÉDITO DA TRANSFERENCIA", Environment.NewLine, "DESEJA PROSSEGUIR COM A EXCLUSÃO DOS DEMAIS LANÇAMENTOS?"), "SIM", "NÃO", false); + } + if (!valueOrDefault) + { + bool flag2 = false; + lancamentos = new List(); + List lancamentos3 = list; + IOrderedEnumerable id = + from x in lancamentos3 + orderby x.get_Controle().get_Id() + select x; + foreach (Lancamento lancamento1 in id.ThenByDescending((Lancamento x) => x.get_Parcela()).ToList()) + { + if (lancamento1.get_Baixado()) + { + Saldo saldo = await this.VerificaSaldo(lancamento1.get_Conta().get_Id(), false); + if (saldo == null) + { + continue; + } + DateTime? dataInicio = saldo.get_DataInicio(); + DateTime? baixa = lancamento1.get_Baixa(); + flag1 = (dataInicio.HasValue & baixa.HasValue ? dataInicio.GetValueOrDefault() > baixa.GetValueOrDefault() : false); + if (flag1) + { + flag2 = true; + continue; + } + } + Lancamento lancamento2 = await this._servico.BuscarLancamento(lancamento1.get_Controle().get_Id(), lancamento1.get_Parcela() + 1); + Lancamento lancamento3 = lancamento2; + if (lancamento3 != null) + { + List lancamentos4 = await this._servico.BuscarLancamentosPorControle(lancamento1.get_Controle().get_Id()); + lancamentos = lancamentos4.Where((Lancamento c) => { + if (c.get_Baixado()) + { + return false; + } + return c.get_Parcela() >= lancamento1.get_Parcela() + 1; + }).AsEnumerable().ToList(); + } + if (lancamento3 == null || !lancamentos1.All((Lancamento l) => l.get_Id() != lancamento3.get_Id())) + { + if (lancamento1.get_Controle().get_Plano() != null) + { + lancamentos1.Add(lancamento1); + } + } + else + { + flag2 = true; + } + } + if (lancamentos1.Count != 0 || lancamentos.Count != 0) + { + valueOrDefault = flag2; + if (valueOrDefault) + { + valueOrDefault = !await base.ShowMessage(string.Concat("HÁ LANÇAMENTOS SELECIONADOS QUE NÃO PODERÃO SER EXCLUÍDOS. ", Environment.NewLine, "DESEJA PROSSEGUIR COM A EXCLUSÃO DOS DEMAIS LANÇAMENTOS?"), "SIM", "NÃO", false); + } + if (!valueOrDefault) + { + valueOrDefault = lancamentos.Count > 0; + if (valueOrDefault) + { + valueOrDefault = await base.ShowMessage("DESEJA EXCLUIR LANÇAMENTOS/PARCELAS CADASTRADOS ACIMA DAS SELECIONADAS.", "SIM", "NÃO", false); + } + if (valueOrDefault) + { + lancamentos1.AddRange(lancamentos); + } + if (await this._servico.Excluir(lancamentos1)) + { + if (lancamentos1 != null && lancamentos1.Count > 0) + { + lancamentos1.ForEach((Lancamento x) => { + bool flag; + FinanceiroViewModel u003cu003e4_this = this; + string str = string.Format("EXCLUIU O LANÇAMENTO DO ID {0} HISTORICO: {1}", (x != null ? new long?(x.get_Id()) : null), (x != null ? x.get_Historico() : null)); + if (x != null) + { + x.get_Id(); + flag = false; + } + else + { + flag = true; + } + u003cu003e4_this.RegistrarAcao(str, (flag ? (long)0 : x.get_Id()), new TipoTela?(25), null); + }); + } + base.ToggleSnackBar(string.Format("EXCLUSÃO DE {0} DO TOTAL DE {1} LANÇAMENTOS SELECIONADOS REALIZADA COM SUCESSO.", lancamentos1.Count, list.Count), true); + await this.Buscar(); + base.Loading(false); + } + else + { + base.Loading(false); + } + } + else + { + base.Loading(false); + } + } + else + { + await base.ShowMessage("OS LANÇAMENTOS SELECIONADOS NÃO PODEM SER EXCLUÍDOS. NENHUMA ALTERAÇÃO FOI FEITA", "OK", "", false); + base.Loading(false); + } + } + else + { + base.Loading(false); + } + } + list = null; + lancamentos = null; + } + + public void Feed(Lancamento lancamento) + { + bool id; + Fornecedor fornecedor; + Gestor.Model.Domain.Financeiro.Planos plano; + BancosContas bancosConta; + if (lancamento == null || this.Salvando) + { + return; + } + if (!this.importando && lancamento.get_Controle().get_Plano() == null) + { + return; + } + Fornecedor fornecedor1 = lancamento.get_Controle().get_Fornecedor(); + if (fornecedor1 != null) + { + id = fornecedor1.get_Id() == (long)0; + } + else + { + id = false; + } + if (id) + { + fornecedor = null; + } + else + { + fornecedor = lancamento.get_Controle().get_Fornecedor(); + } + this.FornecedorInclusao = fornecedor; + if (lancamento.get_Controle().get_Plano() != null) + { + plano = this.PlanosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == lancamento.get_Controle().get_Plano().get_Id()); + } + else + { + plano = null; + } + this.Plano = plano; + this.Centro = this.CentrosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Centro x) => x.get_Id() == lancamento.get_Controle().get_Centro().get_Id()); + if (lancamento.get_Conta() != null) + { + bancosConta = this.ContasFiltradas.FirstOrDefault((BancosContas x) => x.get_Id() == lancamento.get_Conta().get_Id()); + } + else + { + bancosConta = null; + } + this.Conta = bancosConta; + this.TipoPagamento = lancamento.get_TipoPagamento(); + this.Historico = lancamento.get_Historico(); + this.Observacao = lancamento.get_Observacao(); + this.Complemento = lancamento.get_Complemento(); + this.Competencia = lancamento.get_Competencia(); + this.Documento = lancamento.get_Documento(); + this.Parcela = lancamento.get_Parcela(); + this.Parcelas = lancamento.get_Controle().get_Parcelas(); + this.Valor = lancamento.get_Valor(); + this.ValorPago = lancamento.get_ValorPago(); + this.Vencimento = lancamento.get_Vencimento(); + this.Pagamento = lancamento.get_Pagamento(); + this.Baixa = lancamento.get_Baixa(); + this.Sinal = lancamento.get_Sinal(); + this.CodigoBanco = lancamento.get_CodigoBanco(); + } + + public void FeedImportando(Lancamento lancamento) + { + BancosContas bancosConta; + Gestor.Model.Domain.Financeiro.Planos plano; + if (lancamento == null || this.Salvando) + { + return; + } + if (!this.importando && lancamento.get_Controle().get_Plano() == null) + { + return; + } + if (this.Conta == null) + { + bancosConta = this.ContasFiltradas.FirstOrDefault((BancosContas x) => x.get_Id() == lancamento.get_Conta().get_Id()); + } + else + { + bancosConta = null; + } + this.Conta = bancosConta; + this.SelectedLancamento.set_Id(lancamento.get_Id()); + this.SelectedLancamento.get_Controle().set_Id(lancamento.get_Controle().get_Id()); + this.SelectedLancamento.get_Controle().set_Historico(lancamento.get_Controle().get_Historico()); + this.SelectedLancamento.set_Baixado(lancamento.get_Baixa().HasValue); + decimal? valorPago = this.SelectedLancamento.get_ValorPago(); + this.IdLancamento = lancamento.get_Id(); + if (lancamento.get_Controle().get_Plano() != null) + { + plano = this.PlanosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == lancamento.get_Controle().get_Plano().get_Id()); + } + else + { + plano = null; + } + this.Plano = plano; + this.Centro = this.CentrosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Centro x) => x.get_Id() == lancamento.get_Controle().get_Centro().get_Id()); + this.TipoPagamento = lancamento.get_TipoPagamento(); + this.Historico = lancamento.get_Historico(); + this.Observacao = lancamento.get_Observacao(); + this.Complemento = lancamento.get_Complemento(); + this.Documento = lancamento.get_Documento(); + this.Parcela = lancamento.get_Parcela(); + this.Parcelas = lancamento.get_Controle().get_Parcelas(); + this.Valor = lancamento.get_Valor(); + this.ValorPago = valorPago; + this.Vencimento = lancamento.get_Vencimento(); + this.Pagamento = (lancamento.get_Pagamento().HasValue ? lancamento.get_Pagamento() : this.Pagamento); + } + + public List Filtrar(string filter) + { + this._dontSort = true; + this.LancamentosFiltrados = (string.IsNullOrWhiteSpace(filter) ? this.Lancamentos : new ObservableCollection(this.Lancamentos.Where((Lancamento x) => { + bool plano; + bool centro; + bool fornecedor; + if ((x.get_Historico() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Historico().Trim()).Contains(filter)) && (x.get_Documento() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Documento().Trim()).Contains(filter)) && (x.get_Competencia() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Competencia().Trim()).Contains(filter)) && (x.get_Complemento() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Complemento().Trim()).Contains(filter)) && (x.get_Observacao() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Observacao().Trim()).Contains(filter)) && !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Vencimento().ToString(CultureInfo.CurrentCulture).Trim()).ToUpper().Contains(filter) && (!x.get_Baixa().HasValue || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Baixa().ToString().Trim()).ToUpper().Contains(filter)) && (!x.get_Pagamento().HasValue || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Pagamento().ToString().Trim()).ToUpper().Contains(filter)) && (x.get_Conta() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Conta().get_Descricao().Trim()).ToUpper().Contains(filter)) && (x.get_Controle().get_Historico() == null || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Controle().get_Historico().Trim()).ToUpper().Contains(filter)) && !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(EnumHelper.GetDescription(x.get_Sinal()).Trim()).Contains(filter)) + { + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = false; + } + if (!plano || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Controle().get_Plano().get_Descricao().Trim()).ToUpper().Contains(filter)) + { + x.get_TipoPagamento(); + if (!Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(EnumHelper.GetDescription(x.get_TipoPagamento()).Trim()).ToUpper().Contains(filter)) + { + ControleFinanceiro controleFinanceiro = x.get_Controle(); + if (controleFinanceiro != null) + { + centro = controleFinanceiro.get_Centro(); + } + else + { + centro = false; + } + if (!centro || !Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Controle().get_Centro().get_Descricao().Trim()).ToUpper().Contains(filter)) + { + ControleFinanceiro controle1 = x.get_Controle(); + if (controle1 != null) + { + fornecedor = controle1.get_Fornecedor(); + } + else + { + fornecedor = false; + } + if (!fornecedor) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Controle().get_Fornecedor().get_Nome().Trim()).ToUpper().Contains(filter); + } + } + } + } + return true; + }))); + this._dontSort = false; + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + return this.LancamentosFiltrados.ToList(); + } + + public List FiltrarLancamento(long id) + { + this.LancamentosFiltrados = new ObservableCollection( + from x in this.Lancamentos + where x.get_Id() == id + select x); + return this.LancamentosFiltrados.ToList(); + } + + public List FiltrarLancamento(Lancamento lancamento) + { + this.LancamentosFiltrados = new ObservableCollection(this.Lancamentos.Where((Lancamento x) => { + if (!(x.get_Valor() == lancamento.get_Valor()) || !(x.get_Vencimento() == lancamento.get_Vencimento())) + { + return false; + } + return x.get_Historico() == lancamento.get_Historico(); + })); + return this.LancamentosFiltrados.ToList(); + } + + public async Task> FiltrarLancamento(string value) + { + List lancamentos = await Task.Run>(() => this.Filtrar(value)); + return lancamentos; + } + + public void FiltrarPersonalizado() + { + List nums = (this.FiltroPersonalizadoSelecionado != null ? ( + from x in this.FiltroPersonalizadoSelecionado + where x.get_Tipo() == 0 + select x.get_Id()).ToList() : new List()); + List nums1 = (this.FiltroPersonalizadoSelecionado != null ? ( + from x in this.FiltroPersonalizadoSelecionado + where x.get_Tipo() == 2 + select x.get_Id()).ToList() : new List()); + List nums2 = (this.FiltroPersonalizadoSelecionado != null ? ( + from x in this.FiltroPersonalizadoSelecionado + where x.get_Tipo() == 1 + select x.get_Id()).ToList() : new List()); + List nums3 = (this.FiltroPersonalizadoSelecionado != null ? ( + from x in this.FiltroPersonalizadoSelecionado + where x.get_Tipo() == 3 + select x.get_Id()).ToList() : new List()); + List nums4 = (this.FiltroPersonalizadoSelecionado != null ? ( + from x in this.FiltroPersonalizadoSelecionado + where x.get_Tipo() == 4 + select x.get_Id()).ToList() : new List()); + List list = this.Lancamentos.Where((Lancamento x) => { + if (nums.Count != 0 && (x.get_Controle().get_Fornecedor() == null || !nums.Contains(x.get_Controle().get_Fornecedor().get_Id())) || nums1.Count != 0 && (x.get_Controle().get_Centro() == null || !nums1.Contains(x.get_Controle().get_Centro().get_Id())) || nums2.Count != 0 && (x.get_Controle().get_Plano() == null || !nums2.Contains(x.get_Controle().get_Plano().get_Id())) || nums3.Count != 0 && (x.get_Conta() == null || !nums3.Contains(x.get_Conta().get_Id()))) + { + return false; + } + if (nums4.Count == 0) + { + return true; + } + return nums4.Contains((long)x.get_Sinal()); + }).ToList(); + this.LancamentosFiltrados = new ObservableCollection(list); + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + this.SelectedLancamento = this.LancamentosFiltrados.FirstOrDefault(); + } + + public List FiltrarPersonalizado(string filter) + { + if (this.FiltroPersonalizado == null) + { + this.PopularFiltro(); + } + return ( + from x in this.FiltroPersonalizado + where Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(filter.ToUpper()) + select x).ToList(); + } + + public void FiltroImportacao() + { + if (!this.importando) + { + return; + } + switch (this.SelectedStatusImportacao) + { + case 0: + { + this.LancamentosFiltrados = new ObservableCollection( + from x in this.Lancamentos + where !x.get_Baixado() + select x); + return; + } + case 1: + { + this.LancamentosFiltrados = new ObservableCollection( + from x in this.Lancamentos + where x.get_Baixado() + select x); + return; + } + case 2: + { + this.LancamentosFiltrados = new ObservableCollection(this.Lancamentos); + return; + } + default: + { + return; + } + } + } + + internal async Task> FiltroPersonalizadoTask(string value) + { + List filtroPersonalizados = await Task.Run>(() => this.FiltrarPersonalizado(value)); + return filtroPersonalizados; + } + + public async Task GerarExcel(List relatorioGrid) + { + List list; + string str1; + FinanceiroViewModel.u003cu003ec__DisplayClass266_0 variable; + bool flag = await base.ShowMessage(string.Concat("DESEJA AGRUPAR POR ", EnumHelper.GetDescription(this.SinteticoTipo)), "SIM", "NÃO", false); + XLWorkbook xLWorkbook = new XLWorkbook(); + string str2 = "LANÇAMENTOS FINANCEIROS"; + List relatorioLancamentos = new List(); + List lancamentos = new List(); + List lancamentos1 = relatorioGrid; + bool flag1 = lancamentos1.Any((Lancamento x) => x.get_Selecionado()); + relatorioGrid.ToList().ForEach((Lancamento lancamentoGrid) => { + decimal? valorPago; + if (flag1 && !lancamentoGrid.get_Selecionado()) + { + return; + } + Lancamento lancamento2 = (Lancamento)lancamentoGrid.Clone(); + lancamento2.set_Valor((lancamento2.get_Sinal() == 1 ? -lancamento2.get_Valor() : lancamento2.get_Valor())); + Lancamento lancamento1 = lancamento2; + if (lancamento2.get_Sinal() == 1) + { + decimal? nullable = lancamento2.get_ValorPago(); + valorPago = (nullable.HasValue ? new decimal?(-nullable.GetValueOrDefault()) : null); + } + else + { + valorPago = lancamento2.get_ValorPago(); + } + lancamento1.set_ValorPago(valorPago); + lancamentos.Add(lancamento2); + }); + IEnumerable> groupings = lancamentos.GroupBy((Lancamento lancamento) => { + object descricao; + if (this.SinteticoTipo == 1) + { + Gestor.Model.Domain.Financeiro.Centro centro = lancamento.get_Controle().get_Centro(); + if (centro != null) + { + descricao = centro.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + descricao = ""; + } + } + else if (this.SinteticoTipo == null) + { + Gestor.Model.Domain.Financeiro.Planos plano = lancamento.get_Controle().get_Plano(); + if (plano != null) + { + descricao = plano.get_Nome(); + } + else + { + descricao = null; + } + if (descricao == null) + { + return ""; + } + } + else + { + if (this.SinteticoTipo != 3) + { + Fornecedor fornecedor = lancamento.get_Controle().get_Fornecedor(); + if (fornecedor != null) + { + return fornecedor.get_Nome(); + } + return null; + } + BancosContas conta = lancamento.get_Conta(); + if (conta != null) + { + descricao = conta.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + return ""; + } + } + return descricao; + }); + List sinteticoFinanceiros = groupings.Select, Gestor.Model.Domain.Relatorios.SinteticoFinanceiro>((IGrouping lancamento) => { + Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sinteticoFinanceiro = new Gestor.Model.Domain.Relatorios.SinteticoFinanceiro(); + sinteticoFinanceiro.set_Agrupamento(lancamento.Key ?? "TRANSFERÊNCIAS"); + sinteticoFinanceiro.set_Valor(new decimal?(lancamento.Sum((Lancamento sintetic) => sintetic.get_Valor()))); + sinteticoFinanceiro.set_ValorPago(new decimal?(lancamento.Sum((Lancamento sintetic) => sintetic.get_ValorPago()).GetValueOrDefault())); + return sinteticoFinanceiro; + }).ToList(); + List sinteticoFinanceiros1 = sinteticoFinanceiros; + sinteticoFinanceiros = ( + from lancamento in sinteticoFinanceiros1 + orderby lancamento.get_Agrupamento() + select lancamento).ToList(); + List sinteticoFinanceiros2 = sinteticoFinanceiros; + Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sinteticoFinanceiro1 = new Gestor.Model.Domain.Relatorios.SinteticoFinanceiro(); + sinteticoFinanceiro1.set_Agrupamento("TOTAL"); + List sinteticoFinanceiros3 = sinteticoFinanceiros; + sinteticoFinanceiro1.set_Valor(sinteticoFinanceiros3.Sum((Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sintetic) => sintetic.get_Valor())); + List sinteticoFinanceiros4 = sinteticoFinanceiros; + sinteticoFinanceiro1.set_ValorPago(sinteticoFinanceiros4.Sum((Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sintetic) => sintetic.get_ValorPago())); + sinteticoFinanceiros2.Add(sinteticoFinanceiro1); + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, "SINTÉTICO", sinteticoFinanceiros, null); + if (!flag) + { + relatorioLancamentos = FinanceiroViewModel.GerarRelatorio(lancamentos); + List relatorioLancamentos1 = relatorioLancamentos; + RelatorioLancamentos relatorioLancamento = new RelatorioLancamentos(); + relatorioLancamento.set_Fornecedor("TOTAL"); + List relatorioLancamentos2 = relatorioLancamentos; + relatorioLancamento.set_Valor(relatorioLancamentos2.Sum((RelatorioLancamentos lancamento) => lancamento.get_Valor())); + List relatorioLancamentos3 = relatorioLancamentos; + relatorioLancamento.set_ValorPago(relatorioLancamentos3.Sum((RelatorioLancamentos lancamento) => lancamento.get_ValorPago())); + relatorioLancamentos1.Add(relatorioLancamento); + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str2, relatorioLancamentos, null); + } + else + { + switch (this.SinteticoTipo) + { + case 0: + { + List lancamentos2 = lancamentos; + list = lancamentos2.Select((Lancamento x) => { + object descricao; + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Planos plano = controle.get_Plano(); + if (plano != null) + { + descricao = plano.get_Descricao(); + } + else + { + descricao = null; + } + } + else + { + descricao = null; + } + if (descricao == null) + { + descricao = ""; + } + return descricao; + }).Distinct().ToList(); + foreach (string str3 in list) + { + List list1 = lancamentos.Where((Lancamento lancamento) => { + string descricao; + string str; + if (string.IsNullOrWhiteSpace(str3)) + { + ControleFinanceiro controle = lancamento.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Planos plano = controle.get_Plano(); + if (plano != null) + { + str = plano.get_Descricao(); + } + else + { + str = null; + } + } + else + { + str = null; + } + return string.IsNullOrEmpty(str); + } + ControleFinanceiro controleFinanceiro = lancamento.get_Controle(); + if (controleFinanceiro != null) + { + Gestor.Model.Domain.Financeiro.Planos plano1 = controleFinanceiro.get_Plano(); + if (plano1 != null) + { + descricao = plano1.get_Descricao(); + } + else + { + descricao = null; + } + } + else + { + descricao = null; + } + return descricao == str3; + }).ToList(); + if (list1.Count == 0) + { + continue; + } + relatorioLancamentos = FinanceiroViewModel.GerarRelatorio(list1); + List relatorioLancamentos4 = relatorioLancamentos; + RelatorioLancamentos relatorioLancamento1 = new RelatorioLancamentos(); + relatorioLancamento1.set_Fornecedor("TOTAL"); + List lancamentos3 = list1; + relatorioLancamento1.set_Valor(lancamentos3.Sum((Lancamento lancamento) => lancamento.get_Valor())); + List lancamentos4 = list1; + relatorioLancamento1.set_ValorPago(lancamentos4.Sum((Lancamento lancamento) => lancamento.get_ValorPago())); + relatorioLancamentos4.Add(relatorioLancamento1); + str1 = (!string.IsNullOrWhiteSpace(str3) ? str3.ValidaNomePlanilha("", 0) : "TRANSFERENCIAS"); + str2 = str1; + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str2, relatorioLancamentos, null); + } + break; + } + case 1: + { + List lancamentos5 = lancamentos; + list = lancamentos5.Select((Lancamento lancamento) => { + object descricao; + ControleFinanceiro controle = lancamento.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Centro centro = controle.get_Centro(); + if (centro != null) + { + descricao = centro.get_Descricao(); + } + else + { + descricao = null; + } + } + else + { + descricao = null; + } + if (descricao == null) + { + descricao = ""; + } + return descricao; + }).Distinct().ToList(); + foreach (string str4 in list) + { + List list2 = lancamentos.Where((Lancamento lanamento) => { + string descricao; + string str; + if (string.IsNullOrWhiteSpace(str4)) + { + ControleFinanceiro controle = lanamento.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Centro centro = controle.get_Centro(); + if (centro != null) + { + str = centro.get_Descricao(); + } + else + { + str = null; + } + } + else + { + str = null; + } + return string.IsNullOrEmpty(str); + } + ControleFinanceiro controleFinanceiro = lanamento.get_Controle(); + if (controleFinanceiro != null) + { + Gestor.Model.Domain.Financeiro.Centro centro1 = controleFinanceiro.get_Centro(); + if (centro1 != null) + { + descricao = centro1.get_Descricao(); + } + else + { + descricao = null; + } + } + else + { + descricao = null; + } + return descricao == str4; + }).ToList(); + if (list2.Count == 0) + { + continue; + } + relatorioLancamentos = FinanceiroViewModel.GerarRelatorio(list2); + List relatorioLancamentos5 = relatorioLancamentos; + RelatorioLancamentos relatorioLancamento2 = new RelatorioLancamentos(); + relatorioLancamento2.set_Fornecedor("TOTAL"); + List lancamentos6 = list2; + relatorioLancamento2.set_Valor(lancamentos6.Sum((Lancamento lancamento) => lancamento.get_Valor())); + List lancamentos7 = list2; + relatorioLancamento2.set_ValorPago(lancamentos7.Sum((Lancamento lancamento) => lancamento.get_ValorPago())); + relatorioLancamentos5.Add(relatorioLancamento2); + str2 = str4.ValidaNomePlanilha("", 0); + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str2, relatorioLancamentos, null); + } + break; + } + case 2: + { + List lancamentos8 = lancamentos; + list = lancamentos8.Select((Lancamento lancamento) => { + object nome; + ControleFinanceiro controle = lancamento.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + if (fornecedor != null) + { + nome = fornecedor.get_Nome(); + } + else + { + nome = null; + } + } + else + { + nome = null; + } + if (nome == null) + { + nome = ""; + } + return nome; + }).Distinct().ToList(); + foreach (string str5 in list) + { + List list3 = lancamentos.Where((Lancamento lancamento) => { + string nome; + string str; + if (string.IsNullOrWhiteSpace(str5)) + { + ControleFinanceiro controle = lancamento.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + if (fornecedor != null) + { + str = fornecedor.get_Nome(); + } + else + { + str = null; + } + } + else + { + str = null; + } + return string.IsNullOrEmpty(str); + } + ControleFinanceiro controleFinanceiro = lancamento.get_Controle(); + if (controleFinanceiro != null) + { + Fornecedor fornecedor1 = controleFinanceiro.get_Fornecedor(); + if (fornecedor1 != null) + { + nome = fornecedor1.get_Nome(); + } + else + { + nome = null; + } + } + else + { + nome = null; + } + return nome == str5; + }).ToList(); + if (list3.Count == 0) + { + continue; + } + relatorioLancamentos = FinanceiroViewModel.GerarRelatorio(list3); + List relatorioLancamentos6 = relatorioLancamentos; + RelatorioLancamentos relatorioLancamento3 = new RelatorioLancamentos(); + relatorioLancamento3.set_Fornecedor("TOTAL"); + List lancamentos9 = list3; + relatorioLancamento3.set_Valor(lancamentos9.Sum((Lancamento lancamento) => lancamento.get_Valor())); + List lancamentos10 = list3; + relatorioLancamento3.set_ValorPago(lancamentos10.Sum((Lancamento lancamento) => lancamento.get_ValorPago())); + relatorioLancamentos6.Add(relatorioLancamento3); + str2 = str5.ValidaNomePlanilha("", 0); + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str2, relatorioLancamentos, null); + } + break; + } + case 3: + { + List lancamentos11 = lancamentos; + list = lancamentos11.Select((Lancamento x) => { + object descricao; + BancosContas conta = x.get_Conta(); + if (conta != null) + { + descricao = conta.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + descricao = ""; + } + return descricao; + }).Distinct().ToList(); + foreach (string str6 in list) + { + if (string.IsNullOrWhiteSpace(str6)) + { + continue; + } + List list4 = lancamentos.Where((Lancamento lancamento) => { + string descricao; + string str; + if (string.IsNullOrWhiteSpace(str6)) + { + BancosContas conta = lancamento.get_Conta(); + if (conta != null) + { + str = conta.get_Descricao(); + } + else + { + str = null; + } + return string.IsNullOrEmpty(str); + } + BancosContas bancosConta = lancamento.get_Conta(); + if (bancosConta != null) + { + descricao = bancosConta.get_Descricao(); + } + else + { + descricao = null; + } + return descricao == str6; + }).ToList(); + if (list4.Count == 0) + { + continue; + } + relatorioLancamentos = FinanceiroViewModel.GerarRelatorio(list4); + List relatorioLancamentos7 = relatorioLancamentos; + RelatorioLancamentos relatorioLancamento4 = new RelatorioLancamentos(); + relatorioLancamento4.set_Fornecedor("TOTAL"); + List lancamentos12 = list4; + relatorioLancamento4.set_Valor(lancamentos12.Sum((Lancamento lancamento) => lancamento.get_Valor())); + List lancamentos13 = list4; + relatorioLancamento4.set_ValorPago(lancamentos13.Sum((Lancamento lancamento) => lancamento.get_ValorPago())); + relatorioLancamentos7.Add(relatorioLancamento4); + str2 = str6.ValidaNomePlanilha("", 0); + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str2, relatorioLancamentos, null); + } + break; + } + } + } + string tempPath = ""; + string str7 = ""; + List configuracoes = Recursos.Configuracoes; + if (!configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 41)) + { + tempPath = Path.GetTempPath(); + str7 = string.Format("{0}{1}.xlsx", tempPath, Guid.NewGuid()); + } + else + { + using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) + { + if (DialogResult.OK == folderBrowserDialog.ShowDialog()) + { + tempPath = string.Concat(folderBrowserDialog.SelectedPath, "\\"); + Directory.CreateDirectory(tempPath); + } + else + { + variable = null; + str2 = null; + return; + } + } + string[] strArrays = new string[] { tempPath, str2, " ", null, null }; + DateTime date = Functions.GetNetworkTime().Date; + strArrays[3] = date.ToShortDateString().Replace("/", ""); + strArrays[4] = ".xlsx"; + str7 = string.Concat(strArrays); + } + xLWorkbook.SaveAs(str7); + Process.Start(str7); + variable = null; + str2 = null; + } + + private async Task GerarHtml(List relatorioGrid, bool posicao = false) + { + DateTime dateTime; + DateTime dateTime1; + int num; + string str1; + TipoRelatorio tipoRelatorio = new TipoRelatorio(); + tipoRelatorio.set_Nome("RELATÓRIO FINANCEIRO"); + DateTime? inicio = this.Inicio; + dateTime = (inicio.HasValue ? inicio.GetValueOrDefault() : DateTime.MinValue); + tipoRelatorio.set_Inicio(dateTime); + inicio = this.Fim; + dateTime1 = (inicio.HasValue ? inicio.GetValueOrDefault() : DateTime.MinValue); + tipoRelatorio.set_Fim(dateTime1); + TipoRelatorio tipoRelatorio1 = tipoRelatorio; + switch (this.SelectedFiltro) + { + case 0: + { + tipoRelatorio1.set_Nome("RELATORIO FINANCEIRO - VENCIMENTO"); + break; + } + case 1: + { + tipoRelatorio1.set_Nome("RELATORIO FINANCEIRO - BAIXA"); + break; + } + case 2: + { + tipoRelatorio1.set_Nome("RELATORIO FINANCEIRO - PAGAMENTO"); + break; + } + case 3: + { + tipoRelatorio1.set_Nome(this.SelectedFornecedor.get_Nome()); + tipoRelatorio1.set_Inicio(DateTime.MinValue); + tipoRelatorio1.set_Fim(DateTime.MinValue); + break; + } + } + List strs = Funcoes.OcultarColunasDescricao(typeof(Sintetico), "FINANCEIRO"); + List lancamentos = new List(); + List lancamentos1 = relatorioGrid; + bool flag = lancamentos1.Any((Lancamento x) => x.get_Selecionado()); + relatorioGrid.ToList().ForEach((Lancamento lancamentoGrid) => { + decimal? valorPago; + if (flag && !lancamentoGrid.get_Selecionado()) + { + return; + } + Lancamento lancamento2 = (Lancamento)lancamentoGrid.Clone(); + lancamento2.set_Valor((lancamento2.get_Sinal() == 1 ? -lancamento2.get_Valor() : lancamento2.get_Valor())); + Lancamento lancamento1 = lancamento2; + if (lancamento2.get_Sinal() == 1) + { + decimal? nullable = lancamento2.get_ValorPago(); + valorPago = (nullable.HasValue ? new decimal?(-nullable.GetValueOrDefault()) : null); + } + else + { + valorPago = lancamento2.get_ValorPago(); + } + lancamento1.set_ValorPago(valorPago); + lancamentos.Add(lancamento2); + }); + IEnumerable> groupings = lancamentos.GroupBy((Lancamento lancamento) => { + object descricao; + if (this.SinteticoTipo == 1) + { + Gestor.Model.Domain.Financeiro.Centro centro = lancamento.get_Controle().get_Centro(); + if (centro != null) + { + descricao = centro.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + descricao = ""; + } + } + else if (this.SinteticoTipo == null) + { + Gestor.Model.Domain.Financeiro.Planos plano = lancamento.get_Controle().get_Plano(); + if (plano != null) + { + descricao = plano.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + return ""; + } + } + else + { + if (this.SinteticoTipo != 3) + { + Fornecedor fornecedor = lancamento.get_Controle().get_Fornecedor(); + if (fornecedor != null) + { + return fornecedor.get_Nome(); + } + return null; + } + BancosContas conta = lancamento.get_Conta(); + if (conta != null) + { + descricao = conta.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + return ""; + } + } + return descricao; + }); + List list = groupings.Select, Gestor.Model.Domain.Relatorios.SinteticoFinanceiro>((IGrouping lancamento) => { + Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sinteticoFinanceiro = new Gestor.Model.Domain.Relatorios.SinteticoFinanceiro(); + sinteticoFinanceiro.set_Agrupamento(lancamento.Key ?? "TRANSFERÊNCIAS"); + sinteticoFinanceiro.set_Valor(new decimal?(lancamento.Sum((Lancamento sintetic) => sintetic.get_Valor()))); + sinteticoFinanceiro.set_ValorPago(new decimal?(lancamento.Sum((Lancamento sintetic) => sintetic.get_ValorPago()).GetValueOrDefault())); + return sinteticoFinanceiro; + }).ToList(); + List sinteticoFinanceiros = list; + list = ( + from lancamento in sinteticoFinanceiros + orderby lancamento.get_Agrupamento() + select lancamento).ToList(); + List sinteticoFinanceiros1 = list; + Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sinteticoFinanceiro1 = new Gestor.Model.Domain.Relatorios.SinteticoFinanceiro(); + sinteticoFinanceiro1.set_Agrupamento("TOTAL"); + List sinteticoFinanceiros2 = list; + sinteticoFinanceiro1.set_Valor(sinteticoFinanceiros2.Sum((Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sintetic) => sintetic.get_Valor())); + List sinteticoFinanceiros3 = list; + sinteticoFinanceiro1.set_ValorPago(sinteticoFinanceiros3.Sum((Gestor.Model.Domain.Relatorios.SinteticoFinanceiro sintetic) => sintetic.get_ValorPago())); + sinteticoFinanceiros1.Add(sinteticoFinanceiro1); + string str2 = await Funcoes.GenerateTable(list, strs, false, false, "", null); + string str3 = Funcoes.CreateCard(string.Concat("SINTÉTICO ", EnumHelper.GetDescription(this.SinteticoTipo)), str2, false); + IEnumerable> groupings1 = lancamentos.GroupBy((Lancamento lancamento) => { + object descricao; + if (this.SinteticoTipo == 1) + { + Gestor.Model.Domain.Financeiro.Centro centro = lancamento.get_Controle().get_Centro(); + if (centro != null) + { + descricao = centro.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + descricao = ""; + } + } + else if (this.SinteticoTipo == null) + { + Gestor.Model.Domain.Financeiro.Planos plano = lancamento.get_Controle().get_Plano(); + if (plano != null) + { + descricao = plano.get_Nome(); + } + else + { + descricao = null; + } + if (descricao == null) + { + return ""; + } + } + else + { + if (this.SinteticoTipo != 3) + { + Fornecedor fornecedor = lancamento.get_Controle().get_Fornecedor(); + if (fornecedor != null) + { + return fornecedor.get_Nome(); + } + return null; + } + BancosContas conta = lancamento.get_Conta(); + if (conta != null) + { + descricao = conta.get_Descricao(); + } + else + { + descricao = null; + } + if (descricao == null) + { + return ""; + } + } + return descricao; + }); + List list1 = ( + from lancamento in groupings1 + select lancamento.Key).Distinct().ToList(); + foreach (string str4 in list1) + { + List list2 = lancamentos.Where((Lancamento lancamento) => { + string descricao; + string nome; + string str; + string nome1; + if (this.SinteticoTipo == 1) + { + Gestor.Model.Domain.Financeiro.Centro centro = lancamento.get_Controle().get_Centro(); + if (centro != null) + { + descricao = centro.get_Descricao(); + } + else + { + descricao = null; + } + return descricao == str4; + } + if (this.SinteticoTipo == null) + { + Gestor.Model.Domain.Financeiro.Planos plano = lancamento.get_Controle().get_Plano(); + if (plano != null) + { + nome = plano.get_Nome(); + } + else + { + nome = null; + } + return nome == str4; + } + if (this.SinteticoTipo == 3) + { + BancosContas conta = lancamento.get_Conta(); + if (conta != null) + { + str = conta.get_Descricao(); + } + else + { + str = null; + } + return str == str4; + } + Fornecedor fornecedor = lancamento.get_Controle().get_Fornecedor(); + if (fornecedor != null) + { + nome1 = fornecedor.get_Nome(); + } + else + { + nome1 = null; + } + return nome1 == str4; + }).ToList(); + if (list2.Count == 0) + { + continue; + } + List lancamentos2 = list2; + Lancamento lancamento3 = new Lancamento(); + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + Fornecedor fornecedor1 = new Fornecedor(); + fornecedor1.set_Nome("TOTAL"); + controleFinanceiro.set_Fornecedor(fornecedor1); + lancamento3.set_Controle(controleFinanceiro); + List lancamentos3 = list2; + lancamento3.set_Valor(lancamentos3.Sum((Lancamento lancamento) => lancamento.get_Valor())); + List lancamentos4 = list2; + lancamento3.set_ValorPago(lancamentos4.Sum((Lancamento lancamento) => lancamento.get_ValorPago())); + lancamentos2.Add(lancamento3); + string str5 = await Funcoes.GenerateTable(FinanceiroViewModel.GerarRelatorio(list2), new List(), false, false, "", null); + str3 = string.Concat(str3, Funcoes.CreateCard(str4, str5, false)); + } + List configuracoes = Recursos.Configuracoes; + num = (configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 14) ? 70 : 50); + int num1 = num; + TipoRelatorio tipoRelatorio2 = tipoRelatorio1; + string str6 = str3; + if (str6 == null) + { + str6 = ""; + } + string str7 = num1.ToString(); + str1 = (posicao ? "landscape" : "portrait"); + string str8 = Funcoes.ExportarHtml(tipoRelatorio2, str6, str7, str1, false, ""); + tipoRelatorio1 = null; + str3 = null; + return str8; + } + + private static List GerarRelatorio(List lancamentos) + { + return lancamentos.Select((Lancamento x) => { + string nome; + string descricao; + string str; + string descricao1; + string str1; + string nome1; + RelatorioLancamentos relatorioLancamento = new RelatorioLancamentos(); + Fornecedor fornecedor = x.get_Controle().get_Fornecedor(); + if (fornecedor != null) + { + nome = fornecedor.get_Nome(); + } + else + { + nome = null; + } + relatorioLancamento.set_Fornecedor(nome); + relatorioLancamento.set_Historico(x.get_Historico()); + relatorioLancamento.set_Observacao(x.get_Observacao()); + relatorioLancamento.set_Documento(x.get_Documento()); + relatorioLancamento.set_Parcela(x.get_Parcela()); + relatorioLancamento.set_Vencimento(x.get_Vencimento()); + relatorioLancamento.set_Valor(x.get_Valor()); + relatorioLancamento.set_Baixa(x.get_Baixa()); + relatorioLancamento.set_ValorPago(x.get_ValorPago()); + relatorioLancamento.set_Pagamento(x.get_Pagamento()); + Gestor.Model.Domain.Financeiro.Planos plano = x.get_Controle().get_Plano(); + if (plano != null) + { + descricao = plano.get_Descricao(); + } + else + { + descricao = null; + } + relatorioLancamento.set_Plano(descricao); + Gestor.Model.Domain.Financeiro.Planos plano1 = x.get_Controle().get_Plano(); + if (plano1 != null) + { + str = plano1.get_Plano().get_Descricao(); + } + else + { + str = null; + } + relatorioLancamento.set_Planos(str); + Gestor.Model.Domain.Financeiro.Centro centro = x.get_Controle().get_Centro(); + if (centro != null) + { + descricao1 = centro.get_Descricao(); + } + else + { + descricao1 = null; + } + relatorioLancamento.set_Centro(descricao1); + BancosContas conta = x.get_Conta(); + if (conta != null) + { + str1 = conta.get_Descricao(); + } + else + { + str1 = null; + } + relatorioLancamento.set_Conta(str1); + Fornecedor fornecedor1 = x.get_Controle().get_Fornecedor(); + if (fornecedor1 != null) + { + nome1 = fornecedor1.get_Nome(); + } + else + { + nome1 = null; + } + relatorioLancamento.set_Sinal((nome1 == "TOTAL" ? "" : EnumHelper.GetDescription(x.get_Sinal()))); + relatorioLancamento.set_Competencia(x.get_Competencia()); + return relatorioLancamento; + }).ToList(); + } + + public void IncluirLancamento() + { + Gestor.Model.Common.TipoPagamento? nullable; + bool hasValue; + bool flag; + bool hasValue1; + Gestor.Model.Common.TipoPagamento? tipoPagamento; + Gestor.Model.Common.Sinal sinal; + this.Alterando = Visibility.Visible; + this.BuscaHabilitada = false; + Fornecedor selectedFornecedor = null; + if (this.SelectedFiltro == 3 && this.SelectedFornecedor != null && this.SelectedFornecedor.get_Id() > (long)0) + { + selectedFornecedor = this.SelectedFornecedor; + } + this.VisibilityFornecedor = (selectedFornecedor == null ? Visibility.Visible : Visibility.Collapsed); + Fornecedor fornecedor = selectedFornecedor; + if (fornecedor != null) + { + hasValue = fornecedor.get_IdPlano().HasValue; + } + else + { + hasValue = false; + } + Gestor.Model.Domain.Financeiro.Planos plano = (hasValue ? this.PlanosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Planos x) => { + long id = x.get_Id(); + long? idPlano = selectedFornecedor.get_IdPlano(); + return id == idPlano.GetValueOrDefault() & idPlano.HasValue; + }) ?? this.PlanosFiltrados.FirstOrDefault() : this.PlanosFiltrados.FirstOrDefault()); + Fornecedor fornecedor1 = selectedFornecedor; + if (fornecedor1 != null) + { + flag = fornecedor1.get_IdConta().HasValue; + } + else + { + flag = false; + } + BancosContas bancosConta = (flag ? this.ContasFiltradas.FirstOrDefault((BancosContas x) => { + long id = x.get_Id(); + long? idConta = selectedFornecedor.get_IdConta(); + return id == idConta.GetValueOrDefault() & idConta.HasValue; + }) ?? this.ContasFiltradas.FirstOrDefault() : this.ContasFiltradas.FirstOrDefault()); + Fornecedor fornecedor2 = selectedFornecedor; + if (fornecedor2 != null) + { + hasValue1 = fornecedor2.get_IdCentro().HasValue; + } + else + { + hasValue1 = false; + } + Gestor.Model.Domain.Financeiro.Centro centro = (hasValue1 ? this.CentrosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Centro x) => { + long id = x.get_Id(); + long? idCentro = selectedFornecedor.get_IdCentro(); + return id == idCentro.GetValueOrDefault() & idCentro.HasValue; + }) ?? this.CentrosFiltrados.FirstOrDefault() : this.CentrosFiltrados.FirstOrDefault()); + Fornecedor fornecedor3 = selectedFornecedor; + if (fornecedor3 != null) + { + tipoPagamento = fornecedor3.get_TipoPagamento(); + } + else + { + nullable = null; + tipoPagamento = nullable; + } + nullable = tipoPagamento; + Gestor.Model.Common.TipoPagamento valueOrDefault = nullable.GetValueOrDefault(); + DateTime date = Funcoes.GetNetworkTime().Date; + Lancamento lancamento = new Lancamento(); + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + controleFinanceiro.set_Fornecedor(selectedFornecedor); + controleFinanceiro.set_Centro(centro); + controleFinanceiro.set_Plano(plano); + controleFinanceiro.set_Parcelas(1); + lancamento.set_Controle(controleFinanceiro); + lancamento.set_Conta(bancosConta); + lancamento.set_Vencimento(date); + lancamento.set_Parcela(1); + lancamento.set_TipoPagamento(valueOrDefault); + this.SelectedLancamento = lancamento; + this.FornecedorInclusao = selectedFornecedor ?? new Fornecedor(); + this.Historico = ""; + this.Documento = ""; + this.Competencia = ""; + this.Complemento = ""; + this.Plano = plano; + this.Centro = centro; + this.Conta = bancosConta; + Gestor.Model.Domain.Financeiro.Planos plano1 = this.Plano; + if (plano1 != null) + { + sinal = plano1.get_Sinal(); + } + else + { + sinal = 0; + } + this.Sinal = sinal; + this.Parcelas = 1; + this.Parcela = 0; + this.Vencimento = date; + this.Valor = decimal.Zero; + DateTime? nullable1 = null; + this.Baixa = nullable1; + this.ValorPago = new decimal?(new decimal()); + nullable1 = null; + this.Pagamento = nullable1; + this.TipoPagamento = valueOrDefault; + this.Observacao = ""; + this.Alteracao = false; + this.VisibilityCentro = (this.CentrosFiltrados.Count > 1 ? Visibility.Visible : Visibility.Collapsed); + this.VisibilityConta = (this.ContasFiltradas.Count > 1 ? Visibility.Visible : Visibility.Collapsed); + } + + public async void IncluirParcela() + { + bool controle; + Visibility visibility; + Visibility visibility1; + ObservableCollection lancamentosFiltrados = this.LancamentosFiltrados; + if (lancamentosFiltrados.Any((Lancamento x) => x.get_Selecionado())) + { + ObservableCollection observableCollection = this.LancamentosFiltrados; + if (observableCollection.Count((Lancamento x) => x.get_Selecionado()) == 1) + { + FinanceiroViewModel financeiroViewModel = this; + ObservableCollection lancamentosFiltrados1 = this.LancamentosFiltrados; + financeiroViewModel.SelectedLancamento = lancamentosFiltrados1.FirstOrDefault((Lancamento x) => x.get_Selecionado()); + } + ObservableCollection observableCollection1 = this.LancamentosFiltrados; + if (observableCollection1.Count((Lancamento x) => x.get_Selecionado()) <= 1) + { + Lancamento selectedLancamento = this.SelectedLancamento; + if (selectedLancamento != null) + { + controle = selectedLancamento.get_Controle(); + } + else + { + controle = false; + } + if (controle && this.SelectedLancamento.get_Controle().get_Id() != 0) + { + this.VisibilityFornecedor = Visibility.Collapsed; + this.Alterando = Visibility.Visible; + this.BuscaHabilitada = false; + Lancamento lancamento = new Lancamento(); + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + controleFinanceiro.set_Centro(this.SelectedLancamento.get_Controle().get_Centro()); + controleFinanceiro.set_Fornecedor(this.SelectedLancamento.get_Controle().get_Fornecedor()); + controleFinanceiro.set_Historico(this.SelectedLancamento.get_Controle().get_Historico()); + controleFinanceiro.set_Id(this.SelectedLancamento.get_Controle().get_Id()); + controleFinanceiro.set_Parcelas(this.SelectedLancamento.get_Controle().get_Parcelas() + 1); + controleFinanceiro.set_Plano(this.SelectedLancamento.get_Controle().get_Plano()); + lancamento.set_Controle(controleFinanceiro); + lancamento.set_Historico(this.SelectedLancamento.get_Historico()); + lancamento.set_Observacao(this.SelectedLancamento.get_Observacao()); + DateTime vencimento = this.SelectedLancamento.get_Vencimento(); + lancamento.set_Vencimento(vencimento.AddMonths(1)); + lancamento.set_Conta(this.SelectedLancamento.get_Conta()); + lancamento.set_Parcela(this.SelectedLancamento.get_Parcela() + 1); + lancamento.set_Documento(this.SelectedLancamento.get_Documento()); + lancamento.set_Sinal(this.SelectedLancamento.get_Sinal()); + lancamento.set_TipoPagamento(this.SelectedLancamento.get_TipoPagamento()); + lancamento.set_Valor(this.SelectedLancamento.get_Valor()); + this.SelectedLancamento = lancamento; + FinanceiroViewModel financeiroViewModel1 = this; + visibility = (this.CentrosFiltrados.Count > 1 ? Visibility.Visible : Visibility.Collapsed); + financeiroViewModel1.VisibilityCentro = visibility; + FinanceiroViewModel financeiroViewModel2 = this; + visibility1 = (this.ContasFiltradas.Count > 1 ? Visibility.Visible : Visibility.Collapsed); + financeiroViewModel2.VisibilityConta = visibility1; + } + } + else if (await base.ShowMessage("HÁ MAIS DE UM LANÇAMENTO SELECIONADO, DESEJA FAZER A INCLUSÃO DE NOVAS PARCELAS PARA TODOS OS LANÇAMENTOS SELECIONADOS?", "SIM", "NÃO", false)) + { + await this.AdicionarParcelaRange(); + } + } + else + { + await base.ShowMessage("NECESSÁRIO SELECIONAR AO MENOS UM LANCAMENTOS PARA INCLUIR UMA NOVA PARCELA.", "OK", "", false); + } + } + + public void LimparFiltros() + { + this.FiltroPersonalizadoSelecionado = null; + this.VisibleFiltros = Visibility.Collapsed; + } + + public void LimparLancamentos() + { + this.Lancamentos = new ObservableCollection(); + this.LancamentosFiltrados = new ObservableCollection(); + this.LimparFiltros(); + } + + public async Task ParseOfx(BancosContas conta) + { + FinanceiroViewModel.u003cu003ec__DisplayClass256_1 variable = null; + Func func2 = null; + this.SelectedStatusImportacao = 2; + this.Importando = true; + this.VisibleFiltros = Visibility.Collapsed; + List ofxDocuments = await base.ImportarOfx(); + if (ofxDocuments == null || ofxDocuments.Count == 0) + { + this.Importando = false; + } + else + { + List strs = new List() + { + "0237", + "033" + }; + List lancamentos = new List(); + foreach (OfxDocument ofxDocument in ofxDocuments) + { + Tuple tuple = this.CorrigeLancamentos(ofxDocument, strs); + ofxDocument.set_StatementStart(tuple.Item1); + ofxDocument.set_StatementEnd(tuple.Item2); + FinanceiroServico financeiroServico = this._servico; + DateTime statementStart = ofxDocument.get_StatementStart(); + DateTime dateTime2 = statementStart.AddDays(-5); + statementStart = ofxDocument.get_StatementEnd(); + List lancamentos1 = await financeiroServico.BuscarLancamentos(dateTime2, statementStart.AddDays(5), conta.get_Id()); + List lancamentos2 = lancamentos1; + ofxDocument.get_Transactions().ForEach((Transaction t) => { + DateTime dateTime1; + bool length; + string str; + string str1; + string str2; + string str3; + string str4; + if (t.get_Date() < ofxDocument.get_StatementStart().AddDays(-5) && t.get_Date() < ofxDocument.get_StatementEnd().AddDays(5)) + { + List cSu0024u003cu003e8_locals1 = strs; + Func u003cu003e9_2 = func2; + if (u003cu003e9_2 == null) + { + FinanceiroViewModel.u003cu003ec__DisplayClass256_1 cSu0024u003cu003e8_locals2 = variable; + Func func = (string c) => c == this.x.get_Account().get_BankId().Trim(); + Func func1 = func; + cSu0024u003cu003e8_locals2.u003cu003e9__2 = func; + u003cu003e9_2 = func1; + } + if (!cSu0024u003cu003e8_locals1.Any(u003cu003e9_2)) + { + return; + } + } + Gestor.Model.Common.Sinal sinal = (t.get_Amount() < decimal.Zero ? 1 : 0); + Lancamento lancamento = lancamentos2.FirstOrDefault((Lancamento l) => { + if ((!l.get_ValorPago().HasValue || !(Math.Abs(l.get_ValorPago().Value) > decimal.Zero) || !(Math.Abs(l.get_ValorPago().Value) == Math.Abs(t.get_Amount()))) && !(Math.Abs(l.get_Valor()) == Math.Abs(t.get_Amount())) || l.get_Sinal() != sinal || l.get_Documento() == null || !t.get_TransactionId().Contains(l.get_Documento())) + { + return false; + } + DateTime? pagamento = l.get_Pagamento(); + DateTime date = t.get_Date(); + if ((pagamento.HasValue ? pagamento.GetValueOrDefault() == date : false) || l.get_Vencimento() == t.get_Date()) + { + return true; + } + DateTime vencimento = l.get_Vencimento(); + date = t.get_Date(); + if (vencimento < date.AddDays(-5)) + { + return false; + } + DateTime dateTime = l.get_Vencimento(); + date = t.get_Date(); + return dateTime <= date.AddDays(5); + }); + Gestor.Model.Common.TipoPagamento tipoPagamento = t.get_TransType().ParseTransactionType(); + string transactionId = t.get_TransactionId(); + length = (transactionId != null ? transactionId.Trim().Length > 50 : false); + if (length) + { + string transactionId1 = t.get_TransactionId(); + if (transactionId1 != null) + { + string str5 = transactionId1.Trim(); + if (str5 != null) + { + str = str5.Substring(0, 50); + } + else + { + str = null; + } + } + else + { + str = null; + } + } + else + { + string transactionId2 = t.get_TransactionId(); + if (transactionId2 != null) + { + str = transactionId2.Trim(); + } + else + { + str = null; + } + } + string str6 = str; + if (lancamento == null) + { + Lancamento lancamento1 = new Lancamento(); + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + controleFinanceiro.set_Fornecedor(null); + controleFinanceiro.set_Centro(this.Centros.FirstOrDefault()); + controleFinanceiro.set_Plano(null); + controleFinanceiro.set_Parcelas(1); + string memo = t.get_Memo(); + if (memo != null) + { + str1 = memo.Trim(); + } + else + { + str1 = null; + } + controleFinanceiro.set_Historico(str1); + lancamento1.set_Controle(controleFinanceiro); + lancamento1.set_Valor(Math.Abs(t.get_Amount())); + lancamento1.set_ValorPago(new decimal?(Math.Abs(t.get_Amount()))); + string memo1 = t.get_Memo(); + if (memo1 != null) + { + str2 = memo1.Trim(); + } + else + { + str2 = null; + } + lancamento1.set_Historico(str2); + lancamento1.set_Sinal((t.get_Amount() < decimal.Zero ? 1 : 0)); + lancamento1.set_Conta(conta); + lancamento1.set_Vencimento(t.get_Date()); + lancamento1.set_Baixa(new DateTime?(t.get_Date())); + lancamento1.set_Pagamento(new DateTime?(t.get_Date())); + string transactionId3 = t.get_TransactionId(); + if (transactionId3 != null) + { + str3 = transactionId3.Trim(); + } + else + { + str3 = null; + } + lancamento1.set_Documento(str3); + lancamento1.set_TipoPagamento(tipoPagamento); + dateTime1 = t.get_Date(); + lancamento1.set_Competencia(dateTime1.ToString("MM/yyyy")); + lancamento1.set_Parcela(1); + string transactionId4 = t.get_TransactionId(); + if (transactionId4 != null) + { + str4 = transactionId4.Trim(); + } + else + { + str4 = null; + } + lancamento1.set_CodigoBanco(str4); + lancamento1.set_Baixado(false); + lancamento = lancamento1; + } + else + { + lancamento.set_Baixado(lancamento.get_Baixa().HasValue); + lancamento.set_Conta(conta); + lancamento.set_ValorPago(new decimal?(Math.Abs(t.get_Amount()))); + dateTime1 = t.get_Date(); + lancamento.set_Competencia(dateTime1.ToString("MM/yyyy")); + lancamento.set_Baixa((!lancamento.get_Baixa().HasValue ? new DateTime?(t.get_Date()) : lancamento.get_Baixa())); + lancamento.set_Pagamento((!lancamento.get_Pagamento().HasValue ? new DateTime?(t.get_Date()) : lancamento.get_Pagamento())); + lancamento.set_Documento(str6); + lancamento.set_CodigoBanco(t.get_TransactionId()); + lancamento.set_TipoPagamento((lancamento.get_TipoPagamento() == null ? tipoPagamento : lancamento.get_TipoPagamento())); + } + lancamentos.Add(lancamento); + }); + } + this.Lancamentos = new ObservableCollection(lancamentos); + this.LancamentosFiltrados = this.Lancamentos; + ExtensionMethods.ForEach(this.LancamentosFiltrados, (Lancamento x) => this.SelecionarLancamento(x)); + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + } + } + + public void PesquisaPersonalizada() + { + List list = ( + from x in this.PersonalizadoSelecionado + where !x.get_Propriedade().Contains(".") + select x).ToList(); + List list1 = this.Lancamentos.ToList().CustomWhere(list, false); + ( + from x in this.PersonalizadoSelecionado + where x.get_Propriedade().Contains(".") + select x).ToList().ForEach((Gestor.Model.Domain.Relatorios.FiltroPersonalizado x) => { + string str = x.get_Nome(); + if (str == "FORNECEDOR") + { + list1 = list1.Where((Lancamento l) => { + bool nomeSocial; + ControleFinanceiro controle = l.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + nomeSocial = (fornecedor != null ? fornecedor.get_NomeSocial() : false); + } + else + { + nomeSocial = false; + } + if (!nomeSocial) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(l.get_Controle().get_Fornecedor().get_NomeSocial().ToLower().Trim()).Contains(Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(x.get_ValorIncial().ToLower().Trim())); + }).ToList(); + return; + } + if (str == "FORNECEDOR ATIVO") + { + if (x.get_ValorIncial().Trim().Equals("SIM")) + { + List lancamentos = list1; + Func u003cu003e9_3584 = FinanceiroViewModel.u003cu003ec.u003cu003e9__358_4; + if (u003cu003e9_3584 == null) + { + u003cu003e9_3584 = (Lancamento l) => { + bool flag; + ControleFinanceiro controle = l.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + if (fornecedor != null) + { + fornecedor.get_Ativo(); + flag = true; + } + else + { + flag = false; + } + } + else + { + flag = false; + } + if (!flag) + { + return false; + } + return l.get_Controle().get_Fornecedor().get_Ativo(); + }; + FinanceiroViewModel.u003cu003ec.u003cu003e9__358_4 = u003cu003e9_3584; + } + list1 = lancamentos.Where(u003cu003e9_3584).ToList(); + return; + } + if (x.get_ValorIncial().Equals("NÃO")) + { + List lancamentos1 = list1; + Func u003cu003e9_3585 = FinanceiroViewModel.u003cu003ec.u003cu003e9__358_5; + if (u003cu003e9_3585 == null) + { + u003cu003e9_3585 = (Lancamento l) => { + bool flag; + ControleFinanceiro controle = l.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + if (fornecedor != null) + { + fornecedor.get_Ativo(); + flag = true; + } + else + { + flag = false; + } + } + else + { + flag = false; + } + if (!flag) + { + return false; + } + return !l.get_Controle().get_Fornecedor().get_Ativo(); + }; + FinanceiroViewModel.u003cu003ec.u003cu003e9__358_5 = u003cu003e9_3585; + } + list1 = lancamentos1.Where(u003cu003e9_3585).ToList(); + return; + } + } + else + { + if (str == "CONTA") + { + list1 = list1.Where((Lancamento l) => { + bool descricao; + BancosContas conta = l.get_Conta(); + descricao = (conta != null ? conta.get_Descricao() : false); + if (!descricao) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(l.get_Conta().get_Descricao().ToLower().Trim()).Contains(Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(x.get_ValorIncial().ToLower().Trim())); + }).ToList(); + return; + } + if (str == "PLANO DE CONTAS") + { + list1 = list1.Where((Lancamento l) => { + bool descricao; + ControleFinanceiro controle = l.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Planos plano = controle.get_Plano(); + descricao = (plano != null ? plano.get_Descricao() : false); + } + else + { + descricao = false; + } + if (!descricao) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(l.get_Controle().get_Plano().get_Descricao().ToLower().Trim()).Contains(Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(x.get_ValorIncial().ToLower().Trim())); + }).ToList(); + return; + } + if (str == "CENTRO DE CUSTO") + { + list1 = list1.Where((Lancamento l) => { + bool descricao; + ControleFinanceiro controle = l.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Centro centro = controle.get_Centro(); + descricao = (centro != null ? centro.get_Descricao() : false); + } + else + { + descricao = false; + } + if (!descricao) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(l.get_Controle().get_Centro().get_Descricao().ToLower().Trim()).Contains(Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(x.get_ValorIncial().ToLower().Trim())); + }).ToList(); + return; + } + if (str != "PLANO") + { + return; + } + list1 = list1.Where((Lancamento l) => { + bool nome; + ControleFinanceiro controle = l.get_Controle(); + if (controle != null) + { + Gestor.Model.Domain.Financeiro.Planos plano = controle.get_Plano(); + nome = (plano != null ? plano.get_Nome() : false); + } + else + { + nome = false; + } + if (!nome) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(l.get_Controle().get_Plano().get_Nome().ToLower().Trim()).Contains(Gestor.Common.Validation.ValidationHelper.AlphanumericAndSpace(x.get_ValorIncial().ToLower().Trim())); + }).ToList(); + } + }); + this.LancamentosFiltrados = new ObservableCollection(list1); + } + + public async void PopularFiltro() + { + if (this.FiltroPersonalizado == null || this.FiltroPersonalizado.Count <= 0) + { + this.FiltroPersonalizado = new List(); + List fornecedors = await (new BaseServico()).BuscarFornecedor(); + List list = fornecedors.Select((Fornecedor x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Tipo(0); + filtroPersonalizado.set_Descricao(string.Concat(x.get_Nome(), " ", x.get_Documento())); + filtroPersonalizado.set_Id(x.get_Id()); + return filtroPersonalizado; + }).ToList(); + this.FiltroPersonalizado.AddRange(list); + List centros = this.Centros; + list = centros.Select((Gestor.Model.Domain.Financeiro.Centro x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Tipo(2); + filtroPersonalizado.set_Descricao(x.get_Descricao()); + filtroPersonalizado.set_Id(x.get_Id()); + return filtroPersonalizado; + }).ToList(); + this.FiltroPersonalizado.AddRange(list); + List planos = this.Planos; + list = planos.Select((Gestor.Model.Domain.Financeiro.Planos x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Tipo(1); + filtroPersonalizado.set_Descricao(x.get_Descricao()); + filtroPersonalizado.set_Id(x.get_Id()); + return filtroPersonalizado; + }).ToList(); + this.FiltroPersonalizado.AddRange(list); + List contas = this.Contas; + list = contas.Select((BancosContas x) => { + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado.set_Tipo(3); + filtroPersonalizado.set_Descricao(x.get_Descricao()); + filtroPersonalizado.set_Id(x.get_Id()); + return filtroPersonalizado; + }).ToList(); + this.FiltroPersonalizado.AddRange(list); + List filtroPersonalizados = this.FiltroPersonalizado; + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado1 = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado1.set_Descricao(EnumHelper.GetDescription(0)); + filtroPersonalizado1.set_Id((long)0); + filtroPersonalizado1.set_Tipo(4); + filtroPersonalizados.Add(filtroPersonalizado1); + List filtroPersonalizados1 = this.FiltroPersonalizado; + Gestor.Model.Domain.Financeiro.FiltroPersonalizado filtroPersonalizado2 = new Gestor.Model.Domain.Financeiro.FiltroPersonalizado(); + filtroPersonalizado2.set_Descricao(EnumHelper.GetDescription(1)); + filtroPersonalizado2.set_Id((long)1); + filtroPersonalizado2.set_Tipo(4); + filtroPersonalizados1.Add(filtroPersonalizado2); + } + } + + public async Task Print(List relatorioGrid, bool posicao = false) + { + string tempPath = Path.GetTempPath(); + string str = await this.GerarHtml(relatorioGrid, posicao); + string str1 = string.Format("{0}RELATORIO FINANCEIRO_{1:ddMMyyyyhhmmss}.html", tempPath, Funcoes.GetNetworkTime()); + StreamWriter streamWriter = new StreamWriter(str1, true, Encoding.UTF8); + streamWriter.Write(str); + streamWriter.Close(); + Process.Start(str1); + tempPath = null; + } + + public async Task>> Salvar(Transferencia transferencia) + { + List> keyValuePairs; + List> keyValuePairs1 = transferencia.Validate(); + List> keyValuePairs2 = keyValuePairs1; + keyValuePairs2.AddRange(await this.Validar(transferencia)); + keyValuePairs2 = null; + if (keyValuePairs1.Count <= 0) + { + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + controleFinanceiro.set_Historico("TRANSFERÊNCIA ENTRE CONTAS"); + controleFinanceiro.set_Parcelas(2); + ControleFinanceiro controleFinanceiro1 = controleFinanceiro; + Lancamento lancamento = new Lancamento(); + lancamento.set_Controle(controleFinanceiro1); + lancamento.set_Historico("TRANSFERÊNCIA ENTRE CONTAS"); + lancamento.set_Vencimento(transferencia.get_Data()); + lancamento.set_Conta(transferencia.get_Origem()); + lancamento.set_Valor(transferencia.get_Valor()); + lancamento.set_ValorPago(new decimal?(transferencia.get_Valor())); + lancamento.set_Pagamento(new DateTime?(transferencia.get_Data())); + lancamento.set_Baixa(new DateTime?(transferencia.get_Data())); + lancamento.set_Parcela(1); + lancamento.set_Sinal(1); + lancamento.set_TipoPagamento(11); + Lancamento lancamento1 = lancamento; + Lancamento lancamento2 = new Lancamento(); + lancamento2.set_Controle(controleFinanceiro1); + lancamento2.set_Historico("TRANSFERÊNCIA ENTRE CONTAS"); + lancamento2.set_Vencimento(transferencia.get_Data()); + lancamento2.set_Conta(transferencia.get_Destino()); + lancamento2.set_Valor(transferencia.get_Valor()); + lancamento2.set_ValorPago(new decimal?(transferencia.get_Valor())); + lancamento2.set_Pagamento(new DateTime?(transferencia.get_Data())); + lancamento2.set_Baixa(new DateTime?(transferencia.get_Data())); + lancamento2.set_Parcela(2); + lancamento2.set_Sinal(0); + lancamento2.set_TipoPagamento(11); + if (await this._servico.Transferir(lancamento1, lancamento2)) + { + await this.CarregarSaldos(); + base.ToggleSnackBar("TRANSFERÊNCIA REALIZADA COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + public async Task>> Salvar() + { + List> keyValuePairs; + DateTime? nullable; + DateTime vencimento; + decimal? nullable1; + DateTime? pagamento; + DateTime? baixa; + string str; + long? nullable2; + object historico; + bool flag; + long num; + List> keyValuePairs1 = this.SelectedLancamento.Validate(); + if (keyValuePairs1 == null) + { + keyValuePairs1 = new List>(); + } + List> keyValuePairs2 = keyValuePairs1; + List> keyValuePairs3 = keyValuePairs2; + keyValuePairs3.AddRange(await this.Validar()); + keyValuePairs3 = null; + if (keyValuePairs2.Count > 0) + { + keyValuePairs = keyValuePairs2; + } + else if (this.SelectedLancamento.get_Controle().get_Id() != (long)0 || this.SelectedLancamento.get_Controle().get_Parcelas() <= 0) + { + if (this.SelectedLancamento.get_Controle().get_Id() == 0) + { + this.VencimentoAlterado = false; + } + this.SelectedLancamento = await this._servico.Save(this.SelectedLancamento); + if (this.VencimentoAlterado && this.SelectedLancamento.get_Controle().get_Parcelas() > 1) + { + if (await base.ShowMessage("DESEJA ALTERAR O VENCIMENTO PARA OS PRÓXIMOS LANÇAMENTOS?", "SIM", "NÃO", false)) + { + await this.AlterarLancamentos(this.SelectedLancamento, true, false); + } + this.VencimentoAlterado = false; + } + if (this.SelectedLancamento.get_Controle().get_Parcelas() > 1) + { + if (await base.ShowMessage("DESEJA ALTERAR O VALOR PARA OS PRÓXIMOS LANÇAMENTOS?", "SIM", "NÃO", false)) + { + await this.AlterarLancamentos(this.SelectedLancamento, false, true); + } + } + if (this._servico.Sucesso) + { + await this.Buscar(); + base.ToggleSnackBar("LANÇAMENTO SALVO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + List lancamentos = new List(); + for (int i = 1; i <= this.SelectedLancamento.get_Controle().get_Parcelas(); i++) + { + Lancamento lancamento = new Lancamento(); + ControleFinanceiro controleFinanceiro = new ControleFinanceiro(); + controleFinanceiro.set_Centro(this.SelectedLancamento.get_Controle().get_Centro()); + controleFinanceiro.set_Fornecedor(this.SelectedLancamento.get_Controle().get_Fornecedor()); + controleFinanceiro.set_Historico(this.SelectedLancamento.get_Controle().get_Historico()); + controleFinanceiro.set_Id(this.SelectedLancamento.get_Controle().get_Id()); + controleFinanceiro.set_Parcelas(this.SelectedLancamento.get_Controle().get_Parcelas()); + controleFinanceiro.set_Plano(this.SelectedLancamento.get_Controle().get_Plano()); + lancamento.set_Controle(controleFinanceiro); + lancamento.set_Historico(this.SelectedLancamento.get_Historico()); + lancamento.set_Observacao(this.SelectedLancamento.get_Observacao()); + lancamento.set_Complemento(this.SelectedLancamento.get_Complemento()); + lancamento.set_Competencia(this.SelectedLancamento.get_Competencia()); + if (i == 1) + { + vencimento = this.SelectedLancamento.get_Vencimento(); + } + else + { + DateTime dateTime = this.SelectedLancamento.get_Vencimento(); + vencimento = dateTime.AddMonths(i - 1); + } + lancamento.set_Vencimento(vencimento); + lancamento.set_Conta(this.SelectedLancamento.get_Conta()); + nullable1 = (i == 1 ? this.SelectedLancamento.get_ValorPago() : new decimal?(new decimal())); + lancamento.set_ValorPago(nullable1); + if (i == 1) + { + pagamento = this.SelectedLancamento.get_Pagamento(); + } + else + { + nullable = null; + pagamento = nullable; + } + lancamento.set_Pagamento(pagamento); + if (i == 1) + { + baixa = this.SelectedLancamento.get_Baixa(); + } + else + { + nullable = null; + baixa = nullable; + } + lancamento.set_Baixa(baixa); + lancamento.set_Parcela(i); + str = (i == 1 ? this.SelectedLancamento.get_Documento() : ""); + lancamento.set_Documento(str); + lancamento.set_Sinal(this.SelectedLancamento.get_Sinal()); + lancamento.set_TipoPagamento(this.SelectedLancamento.get_TipoPagamento()); + lancamento.set_Valor(this.SelectedLancamento.get_Valor()); + lancamentos.Add(lancamento); + } + List lancamentos1 = await this._servico.AddRange(lancamentos); + this.SelectedLancamento = lancamentos1.FirstOrDefault(); + FinanceiroViewModel financeiroViewModel = this; + Lancamento selectedLancamento = this.SelectedLancamento; + if (selectedLancamento != null) + { + nullable2 = new long?(selectedLancamento.get_Id()); + } + else + { + nullable2 = null; + } + object obj = nullable2; + Lancamento selectedLancamento1 = this.SelectedLancamento; + if (selectedLancamento1 != null) + { + historico = selectedLancamento1.get_Historico(); + } + else + { + historico = null; + } + string str1 = string.Format("INSERIU O LANÇAMENTO DO ID {0} HISTORICO: {1}", obj, historico); + Lancamento lancamento1 = this.SelectedLancamento; + if (lancamento1 != null) + { + lancamento1.get_Id(); + flag = false; + } + else + { + flag = true; + } + num = (flag ? (long)0 : this.SelectedLancamento.get_Id()); + financeiroViewModel.RegistrarAcao(str1, num, new TipoTela?(25), null); + this.VencimentoAlterado = false; + keyValuePairs = null; + } + keyValuePairs2 = null; + return keyValuePairs; + } + + public async Task SalvarImportacao(List list) + { + bool flag; + DateTime? baixa; + DateTime? nullable; + string[] strArrays; + bool flag1; + bool flag2; + string historico; + object obj; + bool flag3; + long num; + Lancamento lancamento = null; + List lancamentos = new List(); + List lancamentos1 = new List(); + List lancamentos2 = new List(); + List lancamentos3 = new List(); + foreach (Lancamento lancamento in list) + { + if (lancamento.get_Baixado()) + { + continue; + } + if (!lancamento.get_Selecionado()) + { + baixa = null; + lancamento.set_Baixa(baixa); + } + baixa = lancamento.get_Baixa(); + if (baixa.HasValue) + { + Saldo saldo = await this.VerificaSaldo(lancamento.get_Conta().get_Id(), false); + if (saldo == null) + { + continue; + } + baixa = saldo.get_DataInicio(); + nullable = lancamento.get_Baixa(); + flag1 = (baixa.HasValue & nullable.HasValue ? baixa.GetValueOrDefault() > nullable.GetValueOrDefault() : false); + if (flag1) + { + continue; + } + } + string observacao = lancamento.get_Observacao(); + if (observacao != null) + { + strArrays = observacao.Split(new char[] { '\n' }); + } + else + { + strArrays = null; + } + string[] strArrays1 = strArrays; + StringBuilder stringBuilder = new StringBuilder(); + string str = "IMPORTAÇÃO OFX REALIZADA PELO USUÁRIO"; + if (strArrays1 != null) + { + string[] strArrays2 = strArrays1; + for (int i = 0; i < (int)strArrays2.Length; i++) + { + string str1 = strArrays2[i]; + if (str1.IndexOf(str, StringComparison.InvariantCulture) != 0) + { + stringBuilder.Append(string.Concat(str1, "\n")); + } + } + } + Lancamento lancamento1 = lancamento; + object[] id = new object[] { stringBuilder, Recursos.Usuario.get_Id(), Recursos.Usuario.get_Nome(), null }; + DateTime networkTime = Funcoes.GetNetworkTime(); + id[3] = networkTime.ToString("F").ToUpper(); + lancamento1.set_Observacao(string.Format("{0}IMPORTAÇÃO OFX REALIZADA PELO USUÁRIO {1} {2} EM {3}", id)); + if (lancamento.get_Id() <= (long)0) + { + lancamentos2.Add(lancamento); + } + else + { + nullable = lancamento.get_Baixa(); + if (!nullable.HasValue) + { + lancamentos.Add(lancamento); + } + else + { + lancamentos1.Add(lancamento); + } + } + lancamentos3.Add(lancamento); + } + if (lancamentos3.Count != 0) + { + object[] count = new object[] { lancamentos2.Count, Environment.NewLine, lancamentos.Count, Environment.NewLine, lancamentos1.Count, Environment.NewLine, Environment.NewLine }; + if (await base.ShowMessage(string.Format("{0} LANÇAMENTOS SERÃO CRIADOS.{1}{2} LANÇAMENTOS SERÃO ATUALIZADOS.{3}{4} LANÇAMENTOS SERÃO BAIXADOS.{5}{6}DESEJA REALMENTE PROSSEGUIR?", count), "SIM", "NÃO", false)) + { + bool flag4 = true; + foreach (Lancamento lancamento2 in lancamentos3) + { + await this._servico.Save(lancamento2); + flag4 = (flag4 ? this._servico.Sucesso : false); + flag2 = (lancamento2 == null ? false : lancamento2.get_Id() != (long)0); + if (flag2 & flag4) + { + FinanceiroViewModel financeiroViewModel = this; + object id1 = lancamento2.get_Id(); + Lancamento lancamento3 = lancamento2; + if (lancamento3 != null) + { + obj = lancamento3.get_Historico(); + } + else + { + obj = null; + } + string str2 = string.Format("BAIXOU/ATUALIZOU O LANÇAMENTO DO ID {0}POR IMPORTAÇÃO HISTORICO: {1}", id1, obj); + Lancamento lancamento4 = lancamento2; + if (lancamento4 != null) + { + lancamento4.get_Id(); + flag3 = false; + } + else + { + flag3 = true; + } + num = (flag3 ? (long)0 : lancamento2.get_Id()); + financeiroViewModel.RegistrarAcao(str2, num, new TipoTela?(25), null); + } + else if (lancamento2 != null & flag4) + { + FinanceiroViewModel financeiroViewModel1 = this; + Lancamento lancamento5 = lancamento2; + if (lancamento5 != null) + { + historico = lancamento5.get_Historico(); + } + else + { + historico = null; + } + financeiroViewModel1.RegistrarAcao(string.Concat("INSERIU O LANÇAMENTO POR IMPORTAÇÃO HISTORICO: ", historico), (long)0, new TipoTela?(25), null); + } + } + if (flag4) + { + await this.Buscar(); + base.ToggleSnackBar("ATUALIZAÇÃO REALIZADA COM SUCESSO", true); + await this.CarregarSaldos(); + flag = true; + } + else + { + await base.ShowMessage("HOUVERAM PROBLEMAS AO INCLUIR OU ATUALIZAR LANÇAMENTOS, FAVOR CONFERIR A IMPORTAÇÃO.", "OK", "", false); + flag = false; + } + } + else + { + base.Loading(false); + flag = false; + } + } + else + { + await base.ShowMessage("NÃO HÁ LANÇAMENTOS PARA SEREM ATUALIZADOS.", "OK", "", false); + base.Loading(false); + flag = false; + } + lancamentos = null; + lancamentos1 = null; + lancamentos2 = null; + lancamentos3 = null; + return flag; + } + + public void SelecionarLancamento(Lancamento lancamento) + { + Lancamento lancamento1 = (lancamento.get_Id() > (long)0 ? this.LancamentosFiltrados.First((Lancamento x) => x.get_Id() == lancamento.get_Id()) : this.LancamentosFiltrados.First((Lancamento x) => { + long? nullable; + long? nullable1; + long? nullable2; + long? nullable3; + long? nullable4; + if (x.get_Id() == lancamento.get_Id()) + { + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + Fornecedor fornecedor = controle.get_Fornecedor(); + if (fornecedor != null) + { + nullable1 = new long?(fornecedor.get_Id()); + } + else + { + nullable = null; + nullable1 = nullable; + } + } + else + { + nullable = null; + nullable1 = nullable; + } + long? nullable5 = nullable1; + ControleFinanceiro controleFinanceiro = lancamento.get_Controle(); + if (controleFinanceiro != null) + { + Fornecedor fornecedor1 = controleFinanceiro.get_Fornecedor(); + if (fornecedor1 != null) + { + nullable2 = new long?(fornecedor1.get_Id()); + } + else + { + nullable = null; + nullable2 = nullable; + } + } + else + { + nullable = null; + nullable2 = nullable; + } + long? nullable6 = nullable2; + if (nullable5.GetValueOrDefault() == nullable6.GetValueOrDefault() & nullable5.HasValue == nullable6.HasValue && x.get_Valor() == lancamento.get_Valor() && x.get_Vencimento() == lancamento.get_Vencimento()) + { + ControleFinanceiro controle1 = x.get_Controle(); + if (controle1 != null) + { + Gestor.Model.Domain.Financeiro.Planos plano = controle1.get_Plano(); + if (plano != null) + { + nullable3 = new long?(plano.get_Id()); + } + else + { + nullable = null; + nullable3 = nullable; + } + } + else + { + nullable = null; + nullable3 = nullable; + } + nullable6 = nullable3; + ControleFinanceiro controleFinanceiro1 = lancamento.get_Controle(); + if (controleFinanceiro1 != null) + { + Gestor.Model.Domain.Financeiro.Planos plano1 = controleFinanceiro1.get_Plano(); + if (plano1 != null) + { + nullable4 = new long?(plano1.get_Id()); + } + else + { + nullable = null; + nullable4 = nullable; + } + } + else + { + nullable = null; + nullable4 = nullable; + } + nullable5 = nullable4; + if (nullable6.GetValueOrDefault() == nullable5.GetValueOrDefault() & nullable6.HasValue == nullable5.HasValue) + { + return lancamento.get_Documento() == x.get_Documento(); + } + } + } + return false; + })); + DateTime date = Funcoes.GetNetworkTime().Date; + lancamento1.set_Selecionado(true); + Lancamento lancamento2 = lancamento1; + DateTime? baixa = lancamento1.get_Baixa(); + lancamento2.set_Baixa(new DateTime?((baixa.HasValue ? baixa.GetValueOrDefault() : lancamento1.get_Pagamento().GetValueOrDefault(date)))); + baixa = lancamento1.get_Pagamento(); + lancamento1.set_Pagamento(new DateTime?(baixa.GetValueOrDefault(date))); + Lancamento lancamento3 = lancamento1; + decimal? valorPago = lancamento1.get_ValorPago(); + decimal num = new decimal(); + lancamento3.set_ValorPago(((valorPago.GetValueOrDefault() == num) & valorPago.HasValue ? new decimal?(lancamento.get_Valor()) : lancamento1.get_ValorPago())); + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + this.Totalizar(); + } + + public void SelecionarTodos() + { + List list = this.LancamentosFiltrados.ToList(); + list.ForEach((Lancamento x) => { + DateTime? baixa; + decimal num; + x.set_Selecionado(!x.get_Selecionado()); + if (x.get_Baixado() || this.importando) + { + return; + } + if (!x.get_Selecionado()) + { + baixa = null; + x.set_Baixa(baixa); + baixa = null; + x.set_Pagamento(baixa); + num = new decimal(); + x.set_ValorPago(new decimal?(num)); + return; + } + DateTime date = Funcoes.GetNetworkTime().Date; + Lancamento lancamento = x; + baixa = x.get_Baixa(); + lancamento.set_Baixa((!baixa.HasValue ? new DateTime?(date) : x.get_Baixa())); + x.set_Baixa(new DateTime?(date)); + Lancamento lancamento1 = x; + baixa = x.get_Pagamento(); + lancamento1.set_Pagamento((!baixa.HasValue ? new DateTime?(date) : x.get_Pagamento())); + Lancamento lancamento2 = x; + decimal? valorPago = x.get_ValorPago(); + num = new decimal(); + lancamento2.set_ValorPago(((valorPago.GetValueOrDefault() == num) & valorPago.HasValue ? new decimal?(x.get_Valor()) : x.get_ValorPago())); + }); + this.LancamentosFiltrados = new ObservableCollection(list); + this.LancamentosFiltradosCopia = this.LancamentosFiltrados; + } + + public void Sintetizar() + { + List list; + switch (this.SinteticoTipo) + { + case 1: + { + list = ( + from x in this.LancamentosFiltrados + where x.get_Controle().get_Plano() != null + group x by new { Id = x.get_Controle().get_Centro().get_Id(), Descricao = x.get_Controle().get_Centro().get_Descricao() }).Select((x) => { + Sintetico sintetico = new Sintetico(); + sintetico.set_Agrupamento(x.Key.Descricao); + sintetico.set_Valor(new decimal?(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_Valor(); + } + return -s.get_Valor(); + }))); + sintetico.set_ValorPago(new decimal?(x.Sum((Lancamento s) => { + decimal? valorPago; + decimal? nullable; + if (s.get_Sinal() == null) + { + valorPago = s.get_ValorPago(); + return valorPago.GetValueOrDefault(); + } + decimal? valorPago1 = s.get_ValorPago(); + if (valorPago1.HasValue) + { + nullable = new decimal?(-valorPago1.GetValueOrDefault()); + } + else + { + valorPago = null; + nullable = valorPago; + } + valorPago = nullable; + return valorPago.GetValueOrDefault(); + }))); + return sintetico; + }).ToList(); + break; + } + case 2: + { + list = ( + from x in this.LancamentosFiltrados + where x.get_Controle().get_Plano() != null + group x by new { Id = x.get_Controle().get_Fornecedor().get_Id(), Nome = x.get_Controle().get_Fornecedor().get_Nome() }).Select((x) => { + Sintetico sintetico = new Sintetico(); + sintetico.set_Agrupamento(x.Key.Nome); + sintetico.set_Valor(new decimal?(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_Valor(); + } + return -s.get_Valor(); + }))); + sintetico.set_ValorPago(new decimal?(x.Sum((Lancamento s) => { + decimal? valorPago; + decimal? nullable; + if (s.get_Sinal() == null) + { + valorPago = s.get_ValorPago(); + return valorPago.GetValueOrDefault(); + } + decimal? valorPago1 = s.get_ValorPago(); + if (valorPago1.HasValue) + { + nullable = new decimal?(-valorPago1.GetValueOrDefault()); + } + else + { + valorPago = null; + nullable = valorPago; + } + valorPago = nullable; + return valorPago.GetValueOrDefault(); + }))); + return sintetico; + }).ToList(); + break; + } + case 3: + { + list = ( + from x in this.LancamentosFiltrados + where x.get_Controle().get_Plano() != null + group x by new { Id = x.get_Conta().get_Id(), Descricao = x.get_Conta().get_Descricao() }).Select((x) => { + Sintetico sintetico = new Sintetico(); + sintetico.set_Agrupamento(x.Key.Descricao); + sintetico.set_Valor(new decimal?(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_Valor(); + } + return -s.get_Valor(); + }))); + sintetico.set_ValorPago(new decimal?(x.Sum((Lancamento s) => { + decimal? valorPago; + decimal? nullable; + if (s.get_Sinal() == null) + { + valorPago = s.get_ValorPago(); + return valorPago.GetValueOrDefault(); + } + decimal? valorPago1 = s.get_ValorPago(); + if (valorPago1.HasValue) + { + nullable = new decimal?(-valorPago1.GetValueOrDefault()); + } + else + { + valorPago = null; + nullable = valorPago; + } + valorPago = nullable; + return valorPago.GetValueOrDefault(); + }))); + return sintetico; + }).ToList(); + break; + } + case 4: + { + list = this.LancamentosFiltrados.Where((Lancamento x) => { + if (x.get_Controle().get_Plano() == null) + { + return false; + } + return x.get_Controle().get_Plano().get_Plano() != null; + }).GroupBy((Lancamento x) => new { Id = x.get_Controle().get_Plano().get_Plano().get_Id(), Descricao = x.get_Controle().get_Plano().get_Plano().get_Descricao() }).Select((x) => { + Sintetico sintetico = new Sintetico(); + sintetico.set_Agrupamento(x.Key.Descricao); + sintetico.set_Valor(new decimal?(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_Valor(); + } + return -s.get_Valor(); + }))); + sintetico.set_ValorPago(new decimal?(x.Sum((Lancamento s) => { + decimal? valorPago; + decimal? nullable; + if (s.get_Sinal() == null) + { + valorPago = s.get_ValorPago(); + return valorPago.GetValueOrDefault(); + } + decimal? valorPago1 = s.get_ValorPago(); + if (valorPago1.HasValue) + { + nullable = new decimal?(-valorPago1.GetValueOrDefault()); + } + else + { + valorPago = null; + nullable = valorPago; + } + valorPago = nullable; + return valorPago.GetValueOrDefault(); + }))); + return sintetico; + }).ToList(); + break; + } + default: + { + list = ( + from x in this.LancamentosFiltrados + where x.get_Controle().get_Plano() != null + group x by new { Id = x.get_Controle().get_Plano().get_Id(), Descricao = x.get_Controle().get_Plano().get_Descricao() }).Select((x) => { + Sintetico sintetico = new Sintetico(); + sintetico.set_Agrupamento(x.Key.Descricao); + sintetico.set_Valor(new decimal?(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_Valor(); + } + return -s.get_Valor(); + }))); + sintetico.set_ValorPago(new decimal?(x.Sum((Lancamento s) => { + decimal? valorPago; + decimal? nullable; + if (s.get_Sinal() == null) + { + valorPago = s.get_ValorPago(); + return valorPago.GetValueOrDefault(); + } + decimal? valorPago1 = s.get_ValorPago(); + if (valorPago1.HasValue) + { + nullable = new decimal?(-valorPago1.GetValueOrDefault()); + } + else + { + valorPago = null; + nullable = valorPago; + } + valorPago = nullable; + return valorPago.GetValueOrDefault(); + }))); + return sintetico; + }).ToList(); + break; + } + } + if (list.Count == 0) + { + return; + } + (new SinteticoView(list, "RELATORIO FINANCEIRO", this.Inicio, this.Fim)).Show(); + } + + public void Totalizar() + { + if (this.LancamentosFiltrados == null) + { + this.Totalizacao = null; + return; + } + List list = ( + from x in this.LancamentosFiltrados + where x.get_Conta() != null + group x by new { Id = x.get_Conta().get_Id(), Descricao = x.get_Conta().get_Descricao() }).Select((x) => { + Gestor.Model.Domain.Financeiro.SinteticoFinanceiro sinteticoFinanceiro = new Gestor.Model.Domain.Financeiro.SinteticoFinanceiro(); + BancosContas bancosConta = new BancosContas(); + bancosConta.set_Id(x.Key.Id); + bancosConta.set_Descricao(x.Key.Descricao); + sinteticoFinanceiro.set_Conta(bancosConta); + sinteticoFinanceiro.set_Filtrados(x.Count()); + sinteticoFinanceiro.set_Credito(x.Sum((Lancamento s) => { + if (s.get_Sinal() != null) + { + return decimal.Zero; + } + return s.get_Valor(); + })); + sinteticoFinanceiro.set_Debito(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return decimal.Zero; + } + return -s.get_Valor(); + })); + sinteticoFinanceiro.set_Liquido(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_Valor(); + } + return -s.get_Valor(); + })); + sinteticoFinanceiro.set_LiquidoPago(x.Sum((Lancamento s) => { + if (s.get_Sinal() == null) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + if (!valorPago.HasValue) + { + return null; + } + return new decimal?(-valorPago.GetValueOrDefault()); + }).GetValueOrDefault()); + sinteticoFinanceiro.set_Selecionados(x.Count((Lancamento s) => s.get_Selecionado())); + sinteticoFinanceiro.set_LiquidoSelecionados(( + from s in x + where s.get_Selecionado() + select s).Sum((Lancamento s) => { + decimal? valorPago; + decimal? nullable; + if (s.get_Sinal() == null) + { + valorPago = s.get_ValorPago(); + return valorPago.GetValueOrDefault(); + } + decimal? valorPago1 = s.get_ValorPago(); + if (valorPago1.HasValue) + { + nullable = new decimal?(-valorPago1.GetValueOrDefault()); + } + else + { + valorPago = null; + nullable = valorPago; + } + valorPago = nullable; + return valorPago.GetValueOrDefault(); + })); + return sinteticoFinanceiro; + }).ToList(); + if (list.Count > 1) + { + List sinteticoFinanceiros = list; + Gestor.Model.Domain.Financeiro.SinteticoFinanceiro sinteticoFinanceiro1 = new Gestor.Model.Domain.Financeiro.SinteticoFinanceiro(); + BancosContas bancosConta1 = new BancosContas(); + bancosConta1.set_Id((long)0); + bancosConta1.set_Descricao("TOTAL"); + sinteticoFinanceiro1.set_Conta(bancosConta1); + sinteticoFinanceiro1.set_Filtrados(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_Filtrados())); + sinteticoFinanceiro1.set_Credito(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_Credito())); + sinteticoFinanceiro1.set_Debito(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_Debito())); + sinteticoFinanceiro1.set_Liquido(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_Liquido())); + sinteticoFinanceiro1.set_LiquidoPago(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_LiquidoPago())); + sinteticoFinanceiro1.set_Selecionados(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_Selecionados())); + sinteticoFinanceiro1.set_LiquidoSelecionados(list.Sum((Gestor.Model.Domain.Financeiro.SinteticoFinanceiro x) => x.get_LiquidoSelecionados())); + sinteticoFinanceiros.Add(sinteticoFinanceiro1); + } + this.Totalizacao = new ObservableCollection(list); + } + + private async Task>> Validar(Transferencia transferencia) + { + List> keyValuePairs; + DateTime? dataFinal; + DateTime data; + bool origem; + bool destino; + bool flag; + bool flag1; + bool flag2; + bool hasValue; + List saldos1; + Saldo saldo; + List> keyValuePairs1 = Gestor.Model.Helper.ValidationHelper.AddValue(); + BancosContasServico bancosContasServico = new BancosContasServico(); + Transferencia transferencium = transferencia; + if (transferencium != null) + { + origem = transferencium.get_Origem(); + } + else + { + origem = false; + } + if (origem) + { + Transferencia transferencium1 = transferencia; + if (transferencium1 != null) + { + destino = transferencium1.get_Destino(); + } + else + { + destino = false; + } + if (destino) + { + List nums = new List() + { + transferencia.get_Origem().get_Id(), + transferencia.get_Destino().get_Id() + }; + saldos1 = await bancosContasServico.BuscarSaldoAberto(nums); + saldo = saldos1.FirstOrDefault((Saldo s) => s.get_Conta().get_Id() == transferencia.get_Origem().get_Id()); + if (saldo == null) + { + List saldos2 = await bancosContasServico.BuscarSaldos(transferencia.get_Origem().get_Id()); + List saldos3 = saldos2; + Saldo saldo1 = saldos3.Find((Saldo x) => { + DateTime? dataInicio = x.get_DataInicio(); + List saldos = saldos3; + Func u003cu003e9_3863 = FinanceiroViewModel.u003cu003ec.u003cu003e9__386_3; + if (u003cu003e9_3863 == null) + { + u003cu003e9_3863 = (Saldo r) => r.get_DataInicio(); + FinanceiroViewModel.u003cu003ec.u003cu003e9__386_3 = u003cu003e9_3863; + } + DateTime? nullable = saldos.Max(u003cu003e9_3863); + if (dataInicio.HasValue != nullable.HasValue) + { + return false; + } + if (!dataInicio.HasValue) + { + return true; + } + return dataInicio.GetValueOrDefault() == nullable.GetValueOrDefault(); + }); + dataFinal = saldo1.get_DataInicio(); + data = transferencia.get_Data(); + flag2 = (dataFinal.HasValue ? dataFinal.GetValueOrDefault() <= data : false); + if (!flag2) + { + hasValue = false; + } + else + { + dataFinal = saldo1.get_DataFinal(); + hasValue = dataFinal.HasValue; + } + bool flag3 = hasValue; + if (flag3) + { + flag3 = await base.ShowMessage("O ÚLTIMO SALDO NÃO ESTÁ ABERTO. DESEJA ABRÍ-LO AGORA E CONTINUAR?", "SIM", "NÃO", false); + } + if (flag3) + { + dataFinal = null; + saldo1.set_DataFinal(dataFinal); + saldo1.set_ValorFinal(null); + saldo = await bancosContasServico.Save(saldo1); + } + saldo1 = null; + } + if (saldo != null) + { + dataFinal = saldo.get_DataInicio(); + data = transferencia.get_Data(); + flag1 = (dataFinal.HasValue ? dataFinal.GetValueOrDefault() > data : false); + if (!flag1) + { + goto Label0; + } + } + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs1, "SALDO", string.Concat("NÃO É POSSÍVEL REALIZAR A BAIXA DO LANÇAMENTO POIS NÃO HÁ SALDO ABERTO NO PERÍODO PARA A CONTA ", transferencia.get_Origem().get_Descricao(), "."), true); + Label0: + saldo = saldos1.FirstOrDefault((Saldo s) => s.get_Conta().get_Id() == transferencia.get_Destino().get_Id()); + if (saldo != null) + { + dataFinal = saldo.get_DataInicio(); + data = transferencia.get_Data(); + flag = (dataFinal.HasValue ? dataFinal.GetValueOrDefault() > data : false); + if (!flag) + { + goto Label1; + } + } + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs1, "SALDO", string.Concat("NÃO É POSSÍVEL REALIZAR A BAIXA DO LANÇAMENTO POIS NÃO HÁ SALDO ABERTO NO PERÍODO PARA A CONTA ", transferencia.get_Destino().get_Descricao(), "."), true); + Label1: + keyValuePairs = keyValuePairs1; + } + else + { + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs1, "DESTINO", "NÃO É POSSÍVEL FAZER UMA TRANSFERÊNCIA SEM BANDO DESTINO", true); + keyValuePairs = keyValuePairs1; + } + } + else + { + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs1, "ORIGEM", "NÃO É POSSÍVEL FAZER UMA TRANSFERÊNCIA SEM BANDO ORIGEM", true); + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + bancosContasServico = null; + saldos1 = null; + saldo = null; + return keyValuePairs; + } + + private async Task>> Validar() + { + List> keyValuePairs; + DateTime? baixa; + DateTime? dataFinal; + bool flag; + bool flag1; + bool flag2; + bool hasValue; + List> keyValuePairs1 = Gestor.Model.Helper.ValidationHelper.AddValue(); + BancosContasServico bancosContasServico = new BancosContasServico(); + BancosContasServico bancosContasServico1 = bancosContasServico; + List contas = this.Contas; + List saldos1 = await bancosContasServico1.BuscarSaldoAberto(( + from x in contas + select x.get_Id()).ToList()); + Saldo saldo = saldos1.FirstOrDefault((Saldo s) => { + long? nullable; + long? nullable1; + long id = s.get_Conta().get_Id(); + Lancamento selectedLancamento = this.SelectedLancamento; + if (selectedLancamento != null) + { + BancosContas conta = selectedLancamento.get_Conta(); + if (conta != null) + { + nullable1 = new long?(conta.get_Id()); + } + else + { + nullable = null; + nullable1 = nullable; + } + } + else + { + nullable = null; + nullable1 = nullable; + } + long? nullable2 = nullable1; + return id == nullable2.GetValueOrDefault() & nullable2.HasValue; + }); + if (saldo == null) + { + Lancamento lancamento = this.SelectedLancamento; + if (lancamento != null) + { + flag1 = lancamento.get_Conta(); + } + else + { + flag1 = false; + } + if (flag1) + { + List saldos2 = await bancosContasServico.BuscarSaldos(this.SelectedLancamento.get_Conta().get_Id()); + List saldos3 = saldos2; + Saldo saldo1 = saldos3.Find((Saldo x) => { + DateTime? dataInicio = x.get_DataInicio(); + List saldos = saldos3; + Func u003cu003e9_3893 = FinanceiroViewModel.u003cu003ec.u003cu003e9__389_3; + if (u003cu003e9_3893 == null) + { + u003cu003e9_3893 = (Saldo r) => r.get_DataInicio(); + FinanceiroViewModel.u003cu003ec.u003cu003e9__389_3 = u003cu003e9_3893; + } + DateTime? nullable = saldos.Max(u003cu003e9_3893); + if (dataInicio.HasValue != nullable.HasValue) + { + return false; + } + if (!dataInicio.HasValue) + { + return true; + } + return dataInicio.GetValueOrDefault() == nullable.GetValueOrDefault(); + }); + baixa = saldo1.get_DataInicio(); + dataFinal = this.SelectedLancamento.get_Baixa(); + flag2 = (baixa.HasValue & dataFinal.HasValue ? baixa.GetValueOrDefault() <= dataFinal.GetValueOrDefault() : false); + if (!flag2) + { + hasValue = false; + } + else + { + dataFinal = saldo1.get_DataFinal(); + hasValue = dataFinal.HasValue; + } + bool flag3 = hasValue; + if (flag3) + { + flag3 = await base.ShowMessage("O ÚLTIMO SALDO NÃO ESTÁ ABERTO. DESEJA ABRÍ-LO AGORA E CONTINUAR?", "SIM", "NÃO", false); + } + if (flag3) + { + dataFinal = null; + saldo1.set_DataFinal(dataFinal); + saldo1.set_ValorFinal(null); + saldo = await bancosContasServico.Save(saldo1); + } + saldo1 = null; + } + } + if (saldo != null) + { + dataFinal = saldo.get_DataInicio(); + baixa = this.SelectedLancamento.get_Baixa(); + flag = (dataFinal.HasValue & baixa.HasValue ? dataFinal.GetValueOrDefault() > baixa.GetValueOrDefault() : false); + if (!flag) + { + keyValuePairs = new List>(); + keyValuePairs1 = null; + bancosContasServico = null; + saldo = null; + return keyValuePairs; + } + } + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs1, "SALDO", "NÃO É POSSÍVEL REALIZAR A BAIXA DO LANÇAMENTO POIS NÃO HÁ SALDO ABERTO NO PERÍODO.", true); + keyValuePairs = keyValuePairs1; + keyValuePairs1 = null; + bancosContasServico = null; + saldo = null; + return keyValuePairs; + } + + public List> ValidateIncluir() + { + // + // Current member / type: System.Collections.Generic.List`1> Gestor.Application.ViewModels.Financeiro.FinanceiroViewModel::ValidateIncluir() + // File path: C:\AggerSeguros\Gestor.Application.exe + // + // Product version: 0.0.0.0 + // Exception in: System.Collections.Generic.List> ValidateIncluir() + // + // Object reference not set to an instance of an object. + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.FindLowestCommonAncestor(ICollection`1 typeNodes) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 515 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.MergeWithLowestCommonAncestor() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 459 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.ProcessSingleConstraints() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 378 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.InferTypes() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 331 + // at Telerik.JustDecompiler.Decompiler.ExpressionDecompilerStep.Process(DecompilationContext theContext, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\ExpressionDecompilerStep.cs:line 104 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61 + // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 133 + // + // mailto: JustDecompilePublicFeedback@telerik.com + + } + + private bool VerificaDataInvertida(OfxDocument lancamentos) + { + List strs = new List() + { + "0104" + }; + if (lancamentos.get_StatementStart() <= lancamentos.get_StatementEnd()) + { + return false; + } + return strs.Any((string banco) => banco == lancamentos.get_Account().get_BankId()); + } + + private bool VerificaFiltroErrado(OfxDocument lancamentos) + { + List strs = new List() + { + "0237", + "756" + }; + if (lancamentos.get_StatementStart() != lancamentos.get_StatementEnd()) + { + return false; + } + return strs.Any((string idbanco) => idbanco == lancamentos.get_Account().get_BankId()); + } + + private async Task VerificaSaldo(long contaId, bool reabrirSaldo) + { + BancosContasServico bancosContasServico = new BancosContasServico(); + List contas = this.Contas; + List saldos = await bancosContasServico.BuscarSaldoAberto(( + from x in contas + select x.get_Id()).ToList()); + Saldo saldo = saldos.FirstOrDefault((Saldo s) => s.get_Conta().get_Id() == contaId); + if (saldo == null & reabrirSaldo) + { + await base.ShowMessage("NÃO FOI ENCONTRADO UM SALDO ABERTO PARA FAZER A EXCLUSÃO.", "OK", "", false); + } + Saldo saldo1 = saldo; + saldo = null; + return saldo1; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/FornecedorViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/FornecedorViewModel.cs new file mode 100644 index 0000000..6d1dc77 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/FornecedorViewModel.cs @@ -0,0 +1,780 @@ +using Assinador.Infrastructure.Helpers; +using ClosedXML.Excel; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Configuracoes; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; +using Gestor.Model.Helper; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class FornecedorViewModel : BaseFinanceiroViewModel + { + private readonly FornecedorServico _servico; + + private List _planos; + + private ObservableCollection _planosFiltrados; + + private List _contas; + + private ObservableCollection _contasFiltradas; + + private List _centros; + + private ObservableCollection _centrosFiltrados; + + private ObservableCollection _fornecedorFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + private Gestor.Model.Domain.Financeiro.Fornecedor _selectedFornecedor; + + private string _anotacoes; + + private long _ultimoId; + + public Gestor.Model.Domain.Financeiro.Fornecedor CancelProduto; + + public string Anotacoes + { + get + { + return this._anotacoes; + } + set + { + this._anotacoes = value; + base.OnPropertyChanged("Anotacoes"); + } + } + + public List Centros + { + get + { + return this._centros; + } + set + { + this._centros = value; + base.OnPropertyChanged("Centros"); + } + } + + public ObservableCollection CentrosFiltrados + { + get + { + return this._centrosFiltrados; + } + set + { + this._centrosFiltrados = value; + base.OnPropertyChanged("CentrosFiltrados"); + } + } + + public List Contas + { + get + { + return this._contas; + } + set + { + this._contas = value; + base.OnPropertyChanged("Contas"); + } + } + + public ObservableCollection ContasFiltradas + { + get + { + return this._contasFiltradas; + } + set + { + this._contasFiltradas = value; + base.OnPropertyChanged("ContasFiltradas"); + } + } + + public List Fornecedor + { + get; + set; + } + + public ObservableCollection FornecedorFiltrados + { + get + { + return this._fornecedorFiltrados; + } + set + { + this._fornecedorFiltrados = value; + this.IsExpanded = (value != null ? value.Count > 0 : false); + base.OnPropertyChanged("FornecedorFiltrados"); + } + } + + public bool IsExpanded + { + get + { + return this._isExpanded; + } + set + { + this._isExpanded = value; + base.OnPropertyChanged("IsExpanded"); + } + } + + public List Planos + { + get + { + return this._planos; + } + set + { + this._planos = value; + base.OnPropertyChanged("Planos"); + } + } + + public ObservableCollection PlanosFiltrados + { + get + { + return this._planosFiltrados; + } + set + { + this._planosFiltrados = value; + base.OnPropertyChanged("PlanosFiltrados"); + } + } + + public Gestor.Model.Domain.Financeiro.Fornecedor SelectedFornecedor + { + get + { + return this._selectedFornecedor; + } + set + { + long? nullable; + this._selectedFornecedor = value; + if (value != null) + { + nullable = new long?(value.get_Id()); + } + else + { + nullable = null; + } + base.VerificarEnables(nullable); + this.Anotacoes = string.Empty; + this._ultimoId = (value == null || value.get_Id() <= (long)0 ? this._ultimoId : value.get_Id()); + base.OnPropertyChanged("SelectedFornecedor"); + } + } + + public FornecedorViewModel() + { + this._servico = new FornecedorServico(); + base.EnableMenu = true; + this.BuscaIncial(); + } + + private async void BuscaIncial() + { + base.Loading(true); + await base.PermissaoTela(24); + this.Planos = await (new PlanoServico()).BuscarPlanos(); + FornecedorViewModel observableCollection = this; + List planos = this.Planos; + IEnumerable ativo = + from x in planos + where x.get_Ativo() + select x; + observableCollection.PlanosFiltrados = new ObservableCollection( + from x in ativo + orderby x.get_Descricao() + select x); + this.Contas = await (new BancosContasServico()).BuscarBancos(); + FornecedorViewModel fornecedorViewModel = this; + List contas = this.Contas; + IEnumerable bancosContas = + from x in contas + where x.get_Ativo() + select x; + fornecedorViewModel.ContasFiltradas = new ObservableCollection( + from x in bancosContas + orderby x.get_Descricao() + select x); + this.Centros = await (new CentroServico()).BuscarCentros(); + FornecedorViewModel observableCollection1 = this; + List centros = this.Centros; + IEnumerable ativo1 = + from x in centros + where x.get_Ativo() + select x; + observableCollection1.CentrosFiltrados = new ObservableCollection( + from x in ativo1 + orderby x.get_Descricao() + select x); + await this.SelecionaFornecedor(); + this.SelectedFornecedor = this.FornecedorFiltrados.FirstOrDefault(); + base.Loading(false); + } + + public async void CancelarAlteracao() + { + base.Loading(true); + base.Alterar(false); + if (this.SelectedFornecedor.get_Id() > (long)0) + { + await this.SelecionaFornecedor(); + } + this.SelectedFornecedor = this.FornecedorFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Fornecedor x) => x.get_Id() == this._ultimoId); + base.Loading(false); + } + + public void Copiar(Cliente cliente) + { + TipoTelefone? nullable; + string str; + string str1; + string str2; + string str3; + string str4; + string str5; + string str6; + TipoTelefone? tipo; + string str7; + string str8; + TipoTelefone? tipo1; + string str9; + string str10; + string str11; + if (this.SelectedFornecedor == null) + { + this.Incluir(); + } + this.SelectedFornecedor.set_Nome(cliente.get_Nome()); + this.SelectedFornecedor.set_Documento(cliente.get_Documento()); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str = null; + } + else + { + ClienteEndereco clienteEndereco = cliente.get_Enderecos().First(); + if (clienteEndereco != null) + { + string cep = clienteEndereco.get_Cep(); + if (cep != null) + { + str = cep.Trim(); + } + else + { + str = null; + } + } + else + { + str = null; + } + } + selectedFornecedor.set_Cep(str); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str1 = null; + } + else + { + ClienteEndereco clienteEndereco1 = cliente.get_Enderecos().First(); + if (clienteEndereco1 != null) + { + string endereco = clienteEndereco1.get_Endereco(); + if (endereco != null) + { + str1 = endereco.Trim(); + } + else + { + str1 = null; + } + } + else + { + str1 = null; + } + } + fornecedor.set_Endereco(str1); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor1 = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str2 = null; + } + else + { + ClienteEndereco clienteEndereco2 = cliente.get_Enderecos().First(); + if (clienteEndereco2 != null) + { + string numero = clienteEndereco2.get_Numero(); + if (numero != null) + { + str2 = numero.Trim(); + } + else + { + str2 = null; + } + } + else + { + str2 = null; + } + } + selectedFornecedor1.set_Numero(str2); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor1 = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str3 = null; + } + else + { + ClienteEndereco clienteEndereco3 = cliente.get_Enderecos().First(); + if (clienteEndereco3 != null) + { + string complemento = clienteEndereco3.get_Complemento(); + if (complemento != null) + { + str3 = complemento.Trim(); + } + else + { + str3 = null; + } + } + else + { + str3 = null; + } + } + fornecedor1.set_Complemento(str3); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor2 = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str4 = null; + } + else + { + ClienteEndereco clienteEndereco4 = cliente.get_Enderecos().First(); + if (clienteEndereco4 != null) + { + string bairro = clienteEndereco4.get_Bairro(); + if (bairro != null) + { + str4 = bairro.Trim(); + } + else + { + str4 = null; + } + } + else + { + str4 = null; + } + } + selectedFornecedor2.set_Bairro(str4); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor2 = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str5 = null; + } + else + { + ClienteEndereco clienteEndereco5 = cliente.get_Enderecos().First(); + if (clienteEndereco5 != null) + { + string cidade = clienteEndereco5.get_Cidade(); + if (cidade != null) + { + str5 = cidade.Trim(); + } + else + { + str5 = null; + } + } + else + { + str5 = null; + } + } + fornecedor2.set_Cidade(str5); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor3 = this.SelectedFornecedor; + if (cliente.get_Enderecos() == null || !cliente.get_Enderecos().Any()) + { + str6 = null; + } + else + { + ClienteEndereco clienteEndereco6 = cliente.get_Enderecos().First(); + if (clienteEndereco6 != null) + { + string estado = clienteEndereco6.get_Estado(); + if (estado != null) + { + str6 = estado.Trim(); + } + else + { + str6 = null; + } + } + else + { + str6 = null; + } + } + selectedFornecedor3.set_Estado(str6); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor3 = this.SelectedFornecedor; + if (cliente.get_Telefones() == null || !cliente.get_Telefones().Any()) + { + nullable = null; + tipo = nullable; + } + else + { + tipo = cliente.get_Telefones().First().get_Tipo(); + } + fornecedor3.set_TipoTelefone1(tipo); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor4 = this.SelectedFornecedor; + if (cliente.get_Telefones() == null || !cliente.get_Telefones().Any()) + { + str7 = null; + } + else + { + string prefixo = cliente.get_Telefones().First().get_Prefixo(); + if (prefixo != null) + { + str7 = prefixo.Trim(); + } + else + { + str7 = null; + } + } + selectedFornecedor4.set_Prefixo1(str7); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor4 = this.SelectedFornecedor; + if (cliente.get_Telefones() == null || !cliente.get_Telefones().Any()) + { + str8 = null; + } + else + { + string numero1 = cliente.get_Telefones().First().get_Numero(); + if (numero1 != null) + { + str8 = numero1.Trim(); + } + else + { + str8 = null; + } + } + fornecedor4.set_Telefone1(str8); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor5 = this.SelectedFornecedor; + if (cliente.get_Telefones() == null || !cliente.get_Telefones().Any() || cliente.get_Telefones().Count <= 2) + { + nullable = null; + tipo1 = nullable; + } + else + { + tipo1 = cliente.get_Telefones()[1].get_Tipo(); + } + selectedFornecedor5.set_TipoTelefone2(tipo1); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor5 = this.SelectedFornecedor; + if (cliente.get_Telefones() == null || cliente.get_Telefones().Count <= 2) + { + str9 = null; + } + else + { + string prefixo1 = cliente.get_Telefones()[1].get_Prefixo(); + if (prefixo1 != null) + { + str9 = prefixo1.Trim(); + } + else + { + str9 = null; + } + } + fornecedor5.set_Prefixo2(str9); + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor6 = this.SelectedFornecedor; + if (cliente.get_Telefones() == null || cliente.get_Telefones().Count <= 2) + { + str10 = null; + } + else + { + string numero2 = cliente.get_Telefones()[1].get_Numero(); + if (numero2 != null) + { + str10 = numero2.Trim(); + } + else + { + str10 = null; + } + } + selectedFornecedor6.set_Telefone2(str10); + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor6 = this.SelectedFornecedor; + if (cliente.get_Emails() == null || !cliente.get_Emails().Any() || cliente.get_Emails().Count <= 0) + { + str11 = null; + } + else + { + string email = cliente.get_Emails().First().get_Email(); + if (email != null) + { + str11 = email.Trim(); + } + else + { + str11 = null; + } + } + fornecedor6.set_Email(str11); + base.OnPropertyChanged("SelectedFornecedor"); + } + + public async Task Delete() + { + if (this.SelectedFornecedor != null && this.SelectedFornecedor.get_Id() != 0) + { + if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR O FORNECEDOR ", this.SelectedFornecedor.get_Nome(), "?"), "SIM", "NÃO", false)) + { + base.Loading(true); + if (await (new FinanceiroServico()).TemLancamentosPorFornecedor(this.SelectedFornecedor.get_Id())) + { + await base.ShowMessage("IMPOSSÍVEL REAIZAR A EXCLUSÃO POIS EXISTEM LANCAMENTOS PARA ESSE FORNECEDOR. PROCESSO INTERROMPIDO", "OK", "", false); + base.Loading(false); + } + else if (await this._servico.Delete(this.SelectedFornecedor)) + { + await this.SelecionaFornecedor(); + this.SelectedFornecedor = this.FornecedorFiltrados.FirstOrDefault(); + base.ToggleSnackBar("FORNECEDOR EXCLUÍDO COM SUCESSO", true); + base.Loading(false); + } + else + { + base.Loading(false); + } + } + } + } + + public async void Excel() + { + XLWorkbook xLWorkbook = new XLWorkbook(); + string str = "RELAÓRIO DE FORNECEDOR"; + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str, this.FornecedorFiltrados.ToList(), null); + string tempPath = ""; + string str1 = ""; + List configuracoes = Recursos.Configuracoes; + if (!configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 41)) + { + tempPath = Path.GetTempPath(); + str1 = string.Format("{0}{1}.xlsx", tempPath, Guid.NewGuid()); + } + else + { + using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) + { + if (DialogResult.OK == folderBrowserDialog.ShowDialog()) + { + tempPath = string.Concat(folderBrowserDialog.SelectedPath, "\\"); + Directory.CreateDirectory(tempPath); + } + else + { + str = null; + return; + } + } + string[] strArrays = new string[] { tempPath, str, " ", null, null }; + DateTime date = Functions.GetNetworkTime().Date; + strArrays[3] = date.ToShortDateString().Replace("/", ""); + strArrays[4] = ".xlsx"; + str1 = string.Concat(strArrays); + } + xLWorkbook.SaveAs(str1); + Process.Start(str1); + str = null; + } + + internal async Task> Filtrar(string value) + { + List fornecedors = await Task.Run>(() => this.FiltrarFornecedor(value)); + return fornecedors; + } + + public List FiltrarFornecedor(string filter) + { + this.FornecedorFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Fornecedor) : new ObservableCollection(this.Fornecedor.Where((Gestor.Model.Domain.Financeiro.Fornecedor x) => { + if (Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(filter)) || x.get_Documento() != null && Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Documento().Trim()).Contains(filter) || x.get_Telefone1() != null && Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Telefone1().Trim()).Contains(filter) || x.get_Telefone2() != null && Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Telefone2().Trim()).Contains(filter)) + { + return true; + } + if (x.get_Email() == null) + { + return false; + } + return Gestor.Common.Validation.ValidationHelper.RemoveDiacritics(x.get_Email().Trim()).Contains(filter); + }).OrderByDescending((Gestor.Model.Domain.Financeiro.Fornecedor x) => x.get_Nome()))); + if (this.FornecedorFiltrados.Count == 1) + { + this.SelectedFornecedor = this.FornecedorFiltrados.First(); + } + return this.FornecedorFiltrados.ToList(); + } + + public async void Imprimir() + { + await base.ImprimirFornecedor(this.FornecedorFiltrados.ToList()); + } + + public void Incluir() + { + long id; + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor = this.SelectedFornecedor; + if (selectedFornecedor != null) + { + id = selectedFornecedor.get_Id(); + } + else + { + id = (long)0; + } + this._ultimoId = id; + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor = new Gestor.Model.Domain.Financeiro.Fornecedor(); + fornecedor.set_IdEmpresa((long)1); + fornecedor.set_Ativo(true); + this.SelectedFornecedor = fornecedor; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + List> keyValuePairs1 = this.SelectedFornecedor.Validate(); + List> keyValuePairs2 = keyValuePairs1; + keyValuePairs2.AddRange(await this.Validate()); + keyValuePairs2 = null; + if (keyValuePairs1.Count <= 0) + { + if (!this.SelectedFornecedor.get_TipoPagamento().HasValue) + { + this.SelectedFornecedor.set_TipoPagamento(new TipoPagamento?(12)); + } + if (!string.IsNullOrWhiteSpace(this.Anotacoes)) + { + Gestor.Model.Domain.Financeiro.Fornecedor selectedFornecedor = this.SelectedFornecedor; + object[] nome = new object[] { Recursos.Usuario.get_Nome(), Recursos.Usuario.get_Id(), Funcoes.GetNetworkTime(), Environment.NewLine, this.Anotacoes, Environment.NewLine, Environment.NewLine, this.SelectedFornecedor.get_Observacao() }; + selectedFornecedor.set_Observacao(string.Format("{0}, ID: {1}, {2:g}{3}{4}{5}{6}{7}", nome)); + } + Gestor.Model.Domain.Financeiro.Fornecedor fornecedor = await this._servico.Save(this.SelectedFornecedor); + if (this._servico.Sucesso) + { + await this.SelecionaFornecedor(); + this.SelectedFornecedor = this.FornecedorFiltrados.First((Gestor.Model.Domain.Financeiro.Fornecedor x) => x.get_Id() == fornecedor.get_Id()); + base.ToggleSnackBar("FORNECEDOR SALVO COM SUCESSO", true); + base.Alterar(false); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + private async Task SelecionaFornecedor() + { + this.Fornecedor = await this._servico.BuscarFornecedores(); + FornecedorViewModel observableCollection = this; + List fornecedor = this.Fornecedor; + observableCollection.FornecedorFiltrados = new ObservableCollection( + from x in fornecedor + orderby x.get_Nome() + select x); + } + + public async Task>> Validate() + { + List> keyValuePairs = Gestor.Model.Helper.ValidationHelper.AddValue(); + if (!string.IsNullOrWhiteSpace(this.SelectedFornecedor.get_Documento())) + { + List list = await this._servico.BuscarFornecedores(); + list = list.Where((Gestor.Model.Domain.Financeiro.Fornecedor x) => { + if (x.get_Id() == this.SelectedFornecedor.get_Id()) + { + return false; + } + return Gestor.Model.Helper.ValidationHelper.DocumentoFornecedor(x.get_Documento()) == Gestor.Model.Helper.ValidationHelper.DocumentoFornecedor(this.SelectedFornecedor.get_Documento()); + }).ToList(); + if (list.Count > 0) + { + List> keyValuePairs1 = keyValuePairs; + List fornecedors = list; + Gestor.Model.Helper.ValidationHelper.AddValue(keyValuePairs1, "DOCUMENTO", string.Concat("DOCUMENTO JÁ CADASTRADO PARA OUTROS FORNECEDORES ", string.Join(" | ", + from x in fornecedors + select x.get_Nome())), true); + } + } + List> keyValuePairs2 = keyValuePairs; + keyValuePairs = null; + return keyValuePairs2; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/InfoExtratoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/InfoExtratoViewModel.cs new file mode 100644 index 0000000..d1a0c38 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/InfoExtratoViewModel.cs @@ -0,0 +1,81 @@ +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class InfoExtratoViewModel : BaseFinanceiroViewModel + { + private readonly BancosContasServico _saldoServico; + + private Saldo _selectedSaldo; + + public bool _telaBancos + { + get; + set; + } + + public Saldo SelectedSaldo + { + get + { + return this._selectedSaldo; + } + set + { + if (value != null && !this._telaBancos) + { + value.set_DataFinal(null); + value.set_ValorFinal(null); + } + this._selectedSaldo = value; + base.OnPropertyChanged("SelectedSaldo"); + this.SelectedSaldo.Initialize(); + } + } + + public InfoExtratoViewModel(bool telaBancos) + { + this._telaBancos = telaBancos; + this._saldoServico = new BancosContasServico(); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + List> keyValuePairs1 = this.SelectedSaldo.Validate(); + if (keyValuePairs1.Count <= 0) + { + if (!this._telaBancos) + { + this.SelectedSaldo.set_DataFinal(null); + this.SelectedSaldo.set_ValorFinal(null); + } + this.SelectedSaldo = await this._saldoServico.Save(this.SelectedSaldo); + if (this._saldoServico.Sucesso) + { + base.Alterar(false); + base.ToggleSnackBar("SALDO SALVO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + return keyValuePairs; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/MenuFinanceiroViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/MenuFinanceiroViewModel.cs new file mode 100644 index 0000000..9c1bdee --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/MenuFinanceiroViewModel.cs @@ -0,0 +1,30 @@ +using Gestor.Application.ViewModels.Generic; +using Gestor.Application.Views.Financeiro; +using System; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class MenuFinanceiroViewModel : BaseViewModel + { + private object _content; + + public Gestor.Application.Views.Financeiro.FinanceiroView FinanceiroView; + + public object Content + { + get + { + return this._content; + } + set + { + this._content = value; + base.OnPropertyChanged("Content"); + } + } + + public MenuFinanceiroViewModel() + { + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs new file mode 100644 index 0000000..e62f957 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs @@ -0,0 +1,147 @@ +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class PlanoViewModel : BaseFinanceiroViewModel + { + private readonly PlanoServico _planoServico; + + private Plano _selectedPlano; + + public Plano Cancel; + + public Plano SelectedPlano + { + get + { + return this._selectedPlano; + } + set + { + long? nullable; + this._selectedPlano = value; + if (value != null) + { + nullable = new long?(value.get_Id()); + } + else + { + nullable = null; + } + base.VerificarEnables(nullable); + base.OnPropertyChanged("SelectedPlano"); + } + } + + public PlanoViewModel(Plano plano) + { + this._planoServico = new PlanoServico(); + this.Seleciona(plano); + } + + public void Cancelar() + { + base.Loading(true); + if (this.SelectedPlano.get_Id() != 0) + { + base.Alterar(false); + base.Loading(false); + return; + } + this.SelectedPlano = new Plano(); + base.Alterar(false); + base.Loading(false); + } + + public void Incluir() + { + Plano plano = new Plano(); + plano.set_Ativo(true); + this.SelectedPlano = plano; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + List> keyValuePairs1 = this.SelectedPlano.Validate(); + List> keyValuePairs2 = keyValuePairs1; + keyValuePairs2.AddRange(await this.Validate()); + keyValuePairs2 = null; + if (keyValuePairs1.Count <= 0) + { + this.SelectedPlano = await this._planoServico.Save(this.SelectedPlano); + if (this._planoServico.Sucesso) + { + base.Alterar(false); + base.ToggleSnackBar("PLANO SALVO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + private async void Seleciona(Plano plano) + { + base.Loading(true); + await base.PermissaoTela(27); + if (plano != null) + { + this.SelectedPlano = plano; + } + else + { + Plano plano1 = new Plano(); + plano1.set_Descricao(""); + plano1.set_Ativo(true); + this.SelectedPlano = plano1; + } + base.Loading(false); + } + + public async Task>> Validate() + { + List> keyValuePairs = new List>(); + bool flag = true; + List planos = await (new BaseServico()).BuscarPlanoAsync(); + if (planos.Count > 0) + { + planos.ForEach((Plano x) => { + if (x.get_Id() == this.SelectedPlano.get_Id()) + { + return; + } + if (x.get_Descricao() == this.SelectedPlano.get_Descricao()) + { + flag = false; + } + }); + } + if (!flag) + { + keyValuePairs.Add(new KeyValuePair("Descricao", "UM PLANO COM ESSE NOME JÁ EXISTE.")); + } + List> keyValuePairs1 = keyValuePairs; + keyValuePairs = null; + return keyValuePairs1; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/PlanosViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/PlanosViewModel.cs new file mode 100644 index 0000000..e2251f3 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/PlanosViewModel.cs @@ -0,0 +1,330 @@ +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class PlanosViewModel : BaseFinanceiroViewModel + { + private readonly PlanosServico _planosServico; + + private ObservableCollection _plano = new ObservableCollection(); + + private ObservableCollection _planosFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + private Gestor.Model.Domain.Financeiro.Planos _selectedPlanos; + + private Gestor.Model.Domain.Financeiro.Plano _selectedPlano; + + private bool _ativo; + + private long _ultimoId; + + public bool Ativo + { + get + { + return this._ativo; + } + set + { + this._ativo = value; + base.OnPropertyChanged("Ativo"); + } + } + + public bool IsExpanded + { + get + { + return this._isExpanded; + } + set + { + this._isExpanded = value; + base.OnPropertyChanged("IsExpanded"); + } + } + + public ObservableCollection Plano + { + get + { + return this._plano; + } + set + { + this._plano = value; + base.OnPropertyChanged("Plano"); + } + } + + public List Planos + { + get; + set; + } + + public ObservableCollection PlanosFiltrados + { + get + { + return this._planosFiltrados; + } + set + { + this._planosFiltrados = value; + this.IsExpanded = (value != null ? value.Count > 0 : false); + base.OnPropertyChanged("PlanosFiltrados"); + } + } + + public Gestor.Model.Domain.Financeiro.Plano SelectedPlano + { + get + { + return this._selectedPlano; + } + set + { + this._selectedPlano = value; + base.OnPropertyChanged("SelectedPlano"); + } + } + + public Gestor.Model.Domain.Financeiro.Planos SelectedPlanos + { + get + { + return this._selectedPlanos; + } + set + { + bool plano; + Gestor.Model.Domain.Financeiro.Plano plano1; + bool id; + long? nullable; + this._selectedPlanos = value; + Gestor.Model.Domain.Financeiro.Planos plano2 = value; + if (plano2 != null) + { + plano = plano2.get_Plano(); + } + else + { + plano = false; + } + if (plano) + { + plano1 = this.Plano.FirstOrDefault((Gestor.Model.Domain.Financeiro.Plano x) => x.get_Id() == value.get_Plano().get_Id()); + } + else + { + plano1 = null; + } + this.SelectedPlano = plano1; + Gestor.Model.Domain.Financeiro.Planos plano3 = value; + if (plano3 != null) + { + id = plano3.get_Id() > (long)0; + } + else + { + id = false; + } + if (id) + { + this._ultimoId = value.get_Id(); + } + Gestor.Model.Domain.Financeiro.Planos plano4 = value; + if (plano4 != null) + { + nullable = new long?(plano4.get_Id()); + } + else + { + nullable = null; + } + base.VerificarEnables(nullable); + base.OnPropertyChanged("SelectedPlanos"); + } + } + + public PlanosViewModel() + { + this._planosServico = new PlanosServico(); + base.EnableMenu = true; + this.Seleciona(); + } + + public async void CancelarAlteracao() + { + base.Loading(true); + base.Alterar(false); + if (this.SelectedPlanos.get_Id() > (long)0) + { + await this.SelecionaPlanos(); + } + await this.SelecionaPlanos(this.PlanosFiltrados.FirstOrDefault((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == this._ultimoId)); + base.Loading(false); + } + + public async Task> Filtrar(string value) + { + ObservableCollection observableCollection = await Task.Run>(() => this.FiltrarPlanos(value)); + return observableCollection; + } + + public ObservableCollection FiltrarPlanos(string filter) + { + this.PlanosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Planos) : new ObservableCollection( + from x in this.Planos + where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby this.Ativo descending, x.get_Descricao() + select x)); + return this.PlanosFiltrados; + } + + public void Incluir() + { + Gestor.Model.Domain.Financeiro.Planos plano = new Gestor.Model.Domain.Financeiro.Planos(); + plano.set_Plano(this.SelectedPlano); + this.SelectedPlanos = plano; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + this.SelectedPlanos.set_Plano(this.SelectedPlano); + List> keyValuePairs1 = this.SelectedPlanos.Validate(); + List> keyValuePairs2 = keyValuePairs1; + keyValuePairs2.AddRange(await this.Validate()); + keyValuePairs2 = null; + if (keyValuePairs1.Count <= 0) + { + this.SelectedPlanos.set_Plano(this.SelectedPlano); + this.SelectedPlanos = await this._planosServico.Save(this.SelectedPlanos); + if (this._planosServico.Sucesso) + { + await this.SelecionaPlanos(); + await this.SelecionaPlanos(this.PlanosFiltrados.First((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == this.SelectedPlanos.get_Id())); + base.Alterar(false); + base.ToggleSnackBar("SUBNÍVEL SALVO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + private async void Seleciona() + { + base.Loading(true); + await base.PermissaoTela(28); + await this.SelecionaPlanos(); + await this.SelecionaPlanos(this.PlanosFiltrados.FirstOrDefault()); + base.Loading(false); + } + + private async Task SelecionaPlanos() + { + List planos = await (new BaseServico()).BuscarPlanosAsync(); + PlanosViewModel list = this; + List planos1 = planos; + IOrderedEnumerable ativo = + from x in planos1 + orderby x.get_Ativo() descending + select x; + IOrderedEnumerable planos2 = ativo.ThenBy((Gestor.Model.Domain.Financeiro.Planos x) => { + Gestor.Model.Domain.Financeiro.Plano plano = x.get_Plano(); + if (plano != null) + { + return plano.get_Descricao(); + } + return null; + }); + list.Planos = planos2.ThenBy((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Descricao()).ToList(); + this.PlanosFiltrados = new ObservableCollection(this.Planos); + } + + public async Task SelecionaPlanos(Gestor.Model.Domain.Financeiro.Planos planos) + { + if (planos != null) + { + base.Loading(true); + ObservableCollection observableCollection = await this._planosServico.BuscarPlanos(); + DomainBase.Copy(this.PlanosFiltrados.First((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == planos.get_Id()), observableCollection.First((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == planos.get_Id())); + if (this.Plano == null) + { + List planos1 = await (new BaseServico()).BuscarPlanoAsync(); + PlanosViewModel planosViewModel = this; + List planos2 = planos1; + IOrderedEnumerable ativo = + from x in planos2 + orderby x.get_Ativo() descending + select x; + planosViewModel.Plano = new ObservableCollection(ativo.ThenBy((Gestor.Model.Domain.Financeiro.Plano x) => x.get_Descricao()).ToList()); + } + this.SelectedPlanos = this.PlanosFiltrados.First((Gestor.Model.Domain.Financeiro.Planos x) => x.get_Id() == planos.get_Id()); + base.Loading(false); + } + else + { + base.Alterar(false); + base.EnableMenu = false; + base.EnableAlterar = false; + } + } + + public async Task>> Validate() + { + List> keyValuePairs = new List>(); + bool flag = true; + List planos = await (new BaseServico()).BuscarPlanosAsync(); + if (planos != null) + { + planos.ForEach((Gestor.Model.Domain.Financeiro.Planos x) => { + if (x.get_Id() == this.SelectedPlanos.get_Id()) + { + return; + } + if (x.get_Descricao() == this.SelectedPlanos.get_Descricao()) + { + flag = false; + } + }); + } + else + { + } + if (!flag) + { + keyValuePairs.Add(new KeyValuePair("Descricao", "UM SUBNÍVEL COM ESSE NOME JÁ EXISTE.")); + } + List> keyValuePairs1 = keyValuePairs; + keyValuePairs = null; + return keyValuePairs1; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/Relatorios/FechamentoFinanceiroViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/Relatorios/FechamentoFinanceiroViewModel.cs new file mode 100644 index 0000000..084c527 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/Relatorios/FechamentoFinanceiroViewModel.cs @@ -0,0 +1,2746 @@ +using ClosedXML.Excel; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Helpers; +using Gestor.Model.Common; +using Gestor.Model.Domain.Configuracoes; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Financeiro.Relatorios; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Relatorios; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Gestor.Application.ViewModels.Financeiro.Relatorios +{ + public class FechamentoFinanceiroViewModel : BaseViewModel + { + private readonly FinanceiroServico _servico; + + private bool _isExpanded; + + private bool _analitico; + + private List _plano; + + private List _planos; + + private List _centro; + + private List _conta; + + private DateTime? _inicio; + + private DateTime? _fim; + + private List _fechamento; + + private List _fechamentoAnalitico; + + private string _htmlContent; + + private bool _print; + + public bool Analitico + { + get + { + return this._analitico; + } + set + { + this._analitico = value; + base.OnPropertyChanged("Analitico"); + } + } + + public List Centro + { + get + { + return this._centro; + } + set + { + this._centro = value; + base.OnPropertyChanged("Centro"); + } + } + + public List Conta + { + get + { + return this._conta; + } + set + { + this._conta = value; + base.OnPropertyChanged("Conta"); + } + } + + public List Fechamento + { + get + { + return this._fechamento; + } + set + { + this._fechamento = value; + base.OnPropertyChanged("Fechamento"); + } + } + + public List FechamentoAnalitico + { + get + { + return this._fechamentoAnalitico; + } + set + { + this._fechamentoAnalitico = value; + base.OnPropertyChanged("FechamentoAnalitico"); + } + } + + public DateTime? Fim + { + get + { + return this._fim; + } + set + { + this._fim = value; + base.OnPropertyChanged("Fim"); + } + } + + public string HtmlContent + { + get + { + return this._htmlContent; + } + set + { + this._htmlContent = value; + this.IsPrintable = !string.IsNullOrWhiteSpace(this._htmlContent); + base.OnPropertyChanged("HtmlContent"); + } + } + + public DateTime? Inicio + { + get + { + return this._inicio; + } + set + { + this._inicio = value; + base.OnPropertyChanged("Inicio"); + } + } + + public bool IsExpanded + { + get + { + return this._isExpanded; + } + set + { + this._isExpanded = value; + base.OnPropertyChanged("IsExpanded"); + } + } + + public bool IsPrintable + { + get + { + return this._print; + } + set + { + this._print = value; + base.OnPropertyChanged("IsPrintable"); + } + } + + public List Plano + { + get + { + return this._plano; + } + set + { + this._plano = value; + base.OnPropertyChanged("Plano"); + } + } + + public List Planos + { + get + { + return this._planos; + } + set + { + this._planos = value; + base.OnPropertyChanged("Planos"); + } + } + + public FechamentoFinanceiroViewModel() + { + DateTime date = Funcoes.GetNetworkTime().Date; + int year = date.Year; + date = Funcoes.GetNetworkTime().Date; + this._inicio = new DateTime?(new DateTime(year, date.Month, 1)); + this._fim = new DateTime?(Funcoes.GetNetworkTime()); + base(); + this._servico = new FinanceiroServico(); + this.LoadInicial(); + } + + public async Task GerarExcel() + { + string tempPath = ""; + string str = ""; + List configuracoes = Recursos.Configuracoes; + if (!configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 41)) + { + tempPath = Path.GetTempPath(); + str = string.Format("{0}{1}.xlsx", tempPath, Guid.NewGuid()); + } + else + { + using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) + { + if (DialogResult.OK == folderBrowserDialog.ShowDialog()) + { + tempPath = string.Concat(folderBrowserDialog.SelectedPath, "\\"); + Directory.CreateDirectory(tempPath); + } + else + { + str = null; + return; + } + } + DateTime date = Functions.GetNetworkTime().Date; + str = string.Concat(tempPath, "FECHAMENTO ", date.ToShortDateString().Replace("/", ""), ".xlsx"); + } + XLWorkbook xLWorkbook = new XLWorkbook(); + int num = 1; + if (this.Analitico) + { + if (this.FechamentoAnalitico == null || this.FechamentoAnalitico.Count == 0) + { + str = null; + return; + } + else + { + foreach (FechamentoFinanceiroAnalitico fechamentoAnalitico in this.FechamentoAnalitico) + { + string str1 = string.Format("{0}_{1}", num, fechamentoAnalitico.get_NomeConta()); + while (str1.Replace("/", "_").Trim().Length > 30) + { + str1 = Regex.Replace(str1.Trim(), "[^\\s]*$", ""); + } + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str1.Replace("/", "_"), fechamentoAnalitico.get_Dados().ToList(), null); + } + } + } + else if (this.Fechamento == null || this.Fechamento.Count == 0) + { + str = null; + return; + } + else + { + List fechamentoFinanceiros = new List(); + fechamentoFinanceiros.AddRange(this.Fechamento); + List fechamentoFinanceiros1 = fechamentoFinanceiros; + FechamentoFinanceiro fechamentoFinanceiro = new FechamentoFinanceiro(); + fechamentoFinanceiro.set_Plano("TOTAL NO PERÍODO"); + List dadosFechamentos = new List(); + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos("TOTAL"); + List fechamento = this.Fechamento; + IEnumerable plano = + from x in fechamento + where x.get_Plano() == "TIPO PAGAMENTO" + select x; + dadosFechamento.set_Soma(plano.Sum((FechamentoFinanceiro x) => x.get_Dados().Sum((DadosFechamento y) => y.get_Soma()))); + dadosFechamentos.Add(dadosFechamento); + fechamentoFinanceiro.set_Dados(dadosFechamentos); + fechamentoFinanceiros1.Add(fechamentoFinanceiro); + num = 1; + foreach (FechamentoFinanceiro fechamentoFinanceiro1 in fechamentoFinanceiros) + { + string str2 = string.Format("{0}_{1}", num, fechamentoFinanceiro1.get_Plano()); + num++; + while (str2.Replace("/", "_").Trim().Length > 30) + { + str2 = Regex.Replace(str2.Trim(), "[^\\s]*$", ""); + } + xLWorkbook = await Funcoes.GerarXls(xLWorkbook, str2.Replace("/", "_"), fechamentoFinanceiro1.get_Dados().ToList(), null); + } + } + base.RegistrarAcao(string.Format("EMITIU EXCEL DO RELATÓRIO PERÍODO ENTRE {0:d} E {1:d}", this.Inicio, this.Fim), new Relatorio?(11), null); + xLWorkbook.SaveAs(str); + Process.Start(str); + str = null; + } + + private async Task GerarHtml(bool screen) + { + string str; + string str1 = ""; + if (!this.Analitico) + { + foreach (FechamentoFinanceiro fechamento in this.Fechamento) + { + List dados = fechamento.get_Dados(); + List strs = new List() + { + "TOTAL CRÉDITO - TOTAL DÉBITO", + "% TOTAL DE CRÉDITO - % TOTAL DE DÉBITO" + }; + string str2 = await Funcoes.GenerateTable(dados, strs, false, screen, "", null); + str1 = string.Concat(str1, Funcoes.CreateCard(fechamento.get_Plano(), str2, false)); + } + FechamentoFinanceiro fechamentoFinanceiro = new FechamentoFinanceiro(); + fechamentoFinanceiro.set_Plano("TOTAL NO PERÍODO"); + List dadosFechamentos = new List(); + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos("TOTAL"); + List fechamentoFinanceiros = this.Fechamento; + IEnumerable plano = + from x in fechamentoFinanceiros + where x.get_Plano() == "TIPO PAGAMENTO" + select x; + dadosFechamento.set_Soma(plano.Sum((FechamentoFinanceiro x) => x.get_Dados().Sum((DadosFechamento y) => y.get_Soma()))); + List fechamento1 = this.Fechamento; + IEnumerable plano1 = + from x in fechamento1 + where x.get_Plano() == "TIPO PAGAMENTO" + select x; + dadosFechamento.set_SomaPercentual(plano1.Sum((FechamentoFinanceiro x) => x.get_Dados().Sum((DadosFechamento y) => y.get_SomaPercentual()))); + dadosFechamentos.Add(dadosFechamento); + fechamentoFinanceiro.set_Dados(dadosFechamentos); + FechamentoFinanceiro fechamentoFinanceiro1 = fechamentoFinanceiro; + List dados1 = fechamentoFinanceiro1.get_Dados(); + List strs1 = new List() + { + "TOTAL CRÉDITO", + "TOTAL DÉBITO", + "% CRÉDITO", + "% DÉBITO" + }; + string str3 = await Funcoes.GenerateTable(dados1, strs1, false, screen, "", null); + str1 = string.Concat(str1, Funcoes.CreateCard(fechamentoFinanceiro1.get_Plano(), str3, false)); + fechamentoFinanceiro1 = null; + } + else + { + foreach (FechamentoFinanceiroAnalitico fechamentoAnalitico in this.FechamentoAnalitico) + { + string str4 = await Funcoes.GenerateTable(fechamentoAnalitico.get_Dados(), new List(), false, screen, "", null); + str1 = string.Concat(str1, Funcoes.CreateCard(fechamentoAnalitico.get_NomeConta(), str4, false)); + } + } + if (!this.Inicio.HasValue || !this.Fim.HasValue) + { + str = null; + } + else + { + TipoRelatorio tipoRelatorio = new TipoRelatorio(); + tipoRelatorio.set_Nome((this.Analitico ? "RELATÓRIO FECHAMENTO FINANCEIRO ANALÍTICO" : "RELATÓRIO FECHAMENTO FINANCEIRO")); + tipoRelatorio.set_Inicio(this.Inicio.Value); + tipoRelatorio.set_Fim(this.Fim.Value); + str = Funcoes.ExportarHtml(tipoRelatorio, str1, "50", "portrait", false, ""); + } + str1 = null; + return str; + } + + public async Task GerarRelatorio() + { + decimal num7; + decimal num8; + decimal num9; + decimal num10; + decimal num11; + decimal num12; + decimal num13; + decimal num14; + decimal num15; + decimal num16; + decimal num17; + Func func8 = null; + Func func9 = null; + Func func10 = null; + Func func11 = null; + Func func12 = null; + Func func13 = null; + Func func14 = null; + Func func15 = null; + Func func16 = null; + Func func17 = null; + Func func18 = null; + Func func19 = null; + if (this.Inicio.HasValue && this.Fim.HasValue) + { + List planos = this.Plano; + IEnumerable selecionado = + from x in planos + where x.get_Selecionado() + select x; + List nums20 = ( + from x in selecionado + select x.get_Id()).ToList(); + List planos1 = this.Planos; + IEnumerable selecionado1 = + from x in planos1 + where x.get_Selecionado() + select x; + List nums21 = ( + from x in selecionado1 + select x.get_Id()).ToList(); + List centro = this.Centro; + IEnumerable centros = + from x in centro + where x.get_Selecionado() + select x; + List nums22 = ( + from x in centros + select x.get_Id()).ToList(); + List conta = this.Conta; + IEnumerable bancosContas = + from x in conta + where x.get_Selecionado() + select x; + List nums23 = ( + from x in bancosContas + select x.get_Id()).ToList(); + FiltroFinanceiro filtroFinanceiro = new FiltroFinanceiro(); + filtroFinanceiro.set_Inicio(this.Inicio.Value); + filtroFinanceiro.set_Fim(this.Fim.Value); + filtroFinanceiro.set_Plano(nums20); + filtroFinanceiro.set_Planos(nums21); + filtroFinanceiro.set_Centro(nums22); + filtroFinanceiro.set_Conta(nums23); + filtroFinanceiro.set_Referencia("l.dtbaixa"); + FiltroFinanceiro filtroFinanceiro1 = filtroFinanceiro; + List lancamentos13 = await this._servico.BuscarFechamento(filtroFinanceiro1); + if (!this.Analitico) + { + this.Fechamento = new List(); + List lancamentos14 = lancamentos13; + IEnumerable lancamentos15 = lancamentos14.Where((Lancamento x) => { + object plano; + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = null; + } + return plano != null; + }); + IOrderedEnumerable nome = + from x in lancamentos15 + orderby x.get_Controle().get_Plano().get_Nome() + select x; + ( + from x in nome + group x by x.get_Controle().get_Plano().get_Plano().get_Id()).ToList>().ForEach((IGrouping x) => { + decimal num3; + decimal num4; + FechamentoFinanceiro fechamentoFinanceiro = new FechamentoFinanceiro(); + fechamentoFinanceiro.set_Plano(x.First().get_Controle().get_Plano().get_Nome().ToUpper()); + IGrouping nums8 = x; + Func u003cu003e9_5197 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_97; + if (u003cu003e9_5197 == null) + { + u003cu003e9_5197 = (Lancamento f) => f.get_Controle().get_Plano().get_Nome(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_97 = u003cu003e9_5197; + } + IOrderedEnumerable lancamentos8 = nums8.OrderBy(u003cu003e9_5197); + Func u003cu003e9_5198 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_98; + if (u003cu003e9_5198 == null) + { + u003cu003e9_5198 = (Lancamento f) => f.get_Controle().get_Plano().get_Id(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_98 = u003cu003e9_5198; + } + fechamentoFinanceiro.set_Dados(lancamentos8.GroupBy(u003cu003e9_5198).Select, DadosFechamento>((IGrouping f) => { + decimal zero; + decimal num; + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos(f.First().get_Controle().get_Plano().get_Descricao()); + IGrouping nums = f; + Func u003cu003e9_51100 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_100; + if (u003cu003e9_51100 == null) + { + u003cu003e9_51100 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_100 = u003cu003e9_51100; + } + IEnumerable lancamentos = nums.Where(u003cu003e9_51100); + Func u003cu003e9_51101 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_101; + if (u003cu003e9_51101 == null) + { + u003cu003e9_51101 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_101 = u003cu003e9_51101; + } + dadosFechamento.set_Credito(lancamentos.Sum(u003cu003e9_51101)); + IGrouping nums1 = f; + Func u003cu003e9_51102 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_102; + if (u003cu003e9_51102 == null) + { + u003cu003e9_51102 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_102 = u003cu003e9_51102; + } + IEnumerable lancamentos1 = nums1.Where(u003cu003e9_51102); + Func u003cu003e9_51103 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_103; + if (u003cu003e9_51103 == null) + { + u003cu003e9_51103 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_103 = u003cu003e9_51103; + } + if (lancamentos1.Sum(u003cu003e9_51103) == decimal.Zero) + { + zero = decimal.Zero; + } + else + { + IGrouping nums2 = f; + Func u003cu003e9_51104 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_104; + if (u003cu003e9_51104 == null) + { + u003cu003e9_51104 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_104 = u003cu003e9_51104; + } + IEnumerable lancamentos2 = nums2.Where(u003cu003e9_51104); + Func u003cu003e9_51105 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_105; + if (u003cu003e9_51105 == null) + { + u003cu003e9_51105 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_105 = u003cu003e9_51105; + } + decimal num1 = lancamentos2.Sum(u003cu003e9_51105); + IGrouping nums3 = x; + Func u003cu003e9_51106 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_106; + if (u003cu003e9_51106 == null) + { + u003cu003e9_51106 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_106 = u003cu003e9_51106; + } + IEnumerable lancamentos3 = nums3.Where(u003cu003e9_51106); + Func u003cu003e9_51107 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_107; + if (u003cu003e9_51107 == null) + { + u003cu003e9_51107 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_107 = u003cu003e9_51107; + } + zero = (num1 / lancamentos3.Sum(u003cu003e9_51107)) * new decimal(100); + } + dadosFechamento.set_PercentualCredito(zero); + IGrouping nums4 = f; + Func u003cu003e9_51108 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_108; + if (u003cu003e9_51108 == null) + { + u003cu003e9_51108 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_108 = u003cu003e9_51108; + } + IEnumerable lancamentos4 = nums4.Where(u003cu003e9_51108); + Func u003cu003e9_51109 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_109; + if (u003cu003e9_51109 == null) + { + u003cu003e9_51109 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_109 = u003cu003e9_51109; + } + dadosFechamento.set_Debito(lancamentos4.Sum(u003cu003e9_51109)); + IGrouping nums5 = f; + Func u003cu003e9_51110 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_110; + if (u003cu003e9_51110 == null) + { + u003cu003e9_51110 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_110 = u003cu003e9_51110; + } + IEnumerable lancamentos5 = nums5.Where(u003cu003e9_51110); + Func u003cu003e9_51111 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_111; + if (u003cu003e9_51111 == null) + { + u003cu003e9_51111 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_111 = u003cu003e9_51111; + } + if (lancamentos5.Sum(u003cu003e9_51111) == decimal.Zero) + { + num = decimal.Zero; + } + else + { + IGrouping nums6 = f; + Func u003cu003e9_51112 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_112; + if (u003cu003e9_51112 == null) + { + u003cu003e9_51112 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_112 = u003cu003e9_51112; + } + IEnumerable lancamentos6 = nums6.Where(u003cu003e9_51112); + Func u003cu003e9_51113 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_113; + if (u003cu003e9_51113 == null) + { + u003cu003e9_51113 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_113 = u003cu003e9_51113; + } + decimal num2 = lancamentos6.Sum(u003cu003e9_51113); + IGrouping nums7 = x; + Func u003cu003e9_51114 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_114; + if (u003cu003e9_51114 == null) + { + u003cu003e9_51114 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_114 = u003cu003e9_51114; + } + IEnumerable lancamentos7 = nums7.Where(u003cu003e9_51114); + Func u003cu003e9_51115 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_115; + if (u003cu003e9_51115 == null) + { + u003cu003e9_51115 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_115 = u003cu003e9_51115; + } + num = (num2 / lancamentos7.Sum(u003cu003e9_51115)) * new decimal(100); + } + dadosFechamento.set_PercentualDebito(num); + return dadosFechamento; + }).ToList()); + FechamentoFinanceiro fechamentoFinanceiro1 = fechamentoFinanceiro; + List dados = fechamentoFinanceiro1.get_Dados(); + DadosFechamento dadosFechamento1 = new DadosFechamento(); + dadosFechamento1.set_Planos("TOTAL"); + List dadosFechamentos = fechamentoFinanceiro1.get_Dados(); + Func u003cu003e9_51116 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_116; + if (u003cu003e9_51116 == null) + { + u003cu003e9_51116 = (DadosFechamento t) => t.get_Credito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_116 = u003cu003e9_51116; + } + dadosFechamento1.set_Credito(dadosFechamentos.Sum(u003cu003e9_51116)); + List dados1 = fechamentoFinanceiro1.get_Dados(); + Func u003cu003e9_51117 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_117; + if (u003cu003e9_51117 == null) + { + u003cu003e9_51117 = (DadosFechamento t) => t.get_Debito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_117 = u003cu003e9_51117; + } + dadosFechamento1.set_Debito(dados1.Sum(u003cu003e9_51117)); + List dadosFechamentos1 = fechamentoFinanceiro1.get_Dados(); + Func u003cu003e9_51118 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_118; + if (u003cu003e9_51118 == null) + { + u003cu003e9_51118 = (DadosFechamento t) => t.get_Credito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_118 = u003cu003e9_51118; + } + if (dadosFechamentos1.Sum(u003cu003e9_51118) == decimal.Zero) + { + num3 = decimal.Zero; + } + else + { + List dados2 = fechamentoFinanceiro1.get_Dados(); + Func u003cu003e9_51119 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_119; + if (u003cu003e9_51119 == null) + { + u003cu003e9_51119 = (DadosFechamento t) => t.get_Credito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_119 = u003cu003e9_51119; + } + decimal num5 = dados2.Sum(u003cu003e9_51119); + List lancamentos9 = lancamentos13; + Func u003cu003e9_51120 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_120; + if (u003cu003e9_51120 == null) + { + u003cu003e9_51120 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_120 = u003cu003e9_51120; + } + IEnumerable lancamentos10 = lancamentos9.Where(u003cu003e9_51120); + Func u003cu003e9_51121 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_121; + if (u003cu003e9_51121 == null) + { + u003cu003e9_51121 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_121 = u003cu003e9_51121; + } + num3 = (num5 / lancamentos10.Sum(u003cu003e9_51121)) * new decimal(100); + } + dadosFechamento1.set_PercentualCredito(num3); + List dadosFechamentos2 = fechamentoFinanceiro1.get_Dados(); + Func u003cu003e9_51122 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_122; + if (u003cu003e9_51122 == null) + { + u003cu003e9_51122 = (DadosFechamento t) => t.get_Debito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_122 = u003cu003e9_51122; + } + if (dadosFechamentos2.Sum(u003cu003e9_51122) == decimal.Zero) + { + num4 = decimal.Zero; + } + else + { + List dados3 = fechamentoFinanceiro1.get_Dados(); + Func u003cu003e9_51123 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_123; + if (u003cu003e9_51123 == null) + { + u003cu003e9_51123 = (DadosFechamento t) => t.get_Debito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_123 = u003cu003e9_51123; + } + decimal num6 = dados3.Sum(u003cu003e9_51123); + List lancamentos11 = lancamentos13; + Func u003cu003e9_51124 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_124; + if (u003cu003e9_51124 == null) + { + u003cu003e9_51124 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_124 = u003cu003e9_51124; + } + IEnumerable lancamentos12 = lancamentos11.Where(u003cu003e9_51124); + Func u003cu003e9_51125 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_125; + if (u003cu003e9_51125 == null) + { + u003cu003e9_51125 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_125 = u003cu003e9_51125; + } + num4 = (num6 / lancamentos12.Sum(u003cu003e9_51125)) * new decimal(100); + } + dadosFechamento1.set_PercentualDebito(num4); + dados.Add(dadosFechamento1); + this.Fechamento.Add(fechamentoFinanceiro1); + }); + FechamentoFinanceiro fechamentoFinanceiro2 = new FechamentoFinanceiro(); + fechamentoFinanceiro2.set_Plano("CONTA CORRENTE"); + List lancamentos16 = lancamentos13; + IEnumerable lancamentos17 = lancamentos16.Where((Lancamento x) => { + object plano; + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = null; + } + return plano != null; + }); + IOrderedEnumerable descricao = + from x in lancamentos17 + orderby x.get_Conta().get_Descricao() + select x; + fechamentoFinanceiro2.set_Dados(( + from x in descricao + group x by x.get_Conta().get_Id()).Select, DadosFechamento>((IGrouping f) => { + decimal zero; + decimal num; + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos(f.First().get_Conta().get_Descricao()); + IGrouping nums = f; + Func u003cu003e9_51130 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_130; + if (u003cu003e9_51130 == null) + { + u003cu003e9_51130 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_130 = u003cu003e9_51130; + } + IEnumerable lancamentos = nums.Where(u003cu003e9_51130); + Func u003cu003e9_51131 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_131; + if (u003cu003e9_51131 == null) + { + u003cu003e9_51131 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_131 = u003cu003e9_51131; + } + dadosFechamento.set_Credito(lancamentos.Sum(u003cu003e9_51131)); + IGrouping nums1 = f; + Func u003cu003e9_51132 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_132; + if (u003cu003e9_51132 == null) + { + u003cu003e9_51132 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_132 = u003cu003e9_51132; + } + IEnumerable lancamentos1 = nums1.Where(u003cu003e9_51132); + Func u003cu003e9_51133 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_133; + if (u003cu003e9_51133 == null) + { + u003cu003e9_51133 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_133 = u003cu003e9_51133; + } + if (lancamentos1.Sum(u003cu003e9_51133) == decimal.Zero) + { + zero = decimal.Zero; + } + else + { + IGrouping nums2 = f; + Func u003cu003e9_51134 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_134; + if (u003cu003e9_51134 == null) + { + u003cu003e9_51134 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_134 = u003cu003e9_51134; + } + IEnumerable lancamentos2 = nums2.Where(u003cu003e9_51134); + Func u003cu003e9_51135 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_135; + if (u003cu003e9_51135 == null) + { + u003cu003e9_51135 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_135 = u003cu003e9_51135; + } + decimal num1 = lancamentos2.Sum(u003cu003e9_51135); + List lancamentos3 = lancamentos13; + Func u003cu003e9_51136 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_136; + if (u003cu003e9_51136 == null) + { + u003cu003e9_51136 = (Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 0; + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_136 = u003cu003e9_51136; + } + IEnumerable lancamentos4 = lancamentos3.Where(u003cu003e9_51136); + Func u003cu003e9_51137 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_137; + if (u003cu003e9_51137 == null) + { + u003cu003e9_51137 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_137 = u003cu003e9_51137; + } + zero = (num1 / lancamentos4.Sum(u003cu003e9_51137)) * new decimal(100); + } + dadosFechamento.set_PercentualCredito(zero); + IGrouping nums3 = f; + Func u003cu003e9_51138 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_138; + if (u003cu003e9_51138 == null) + { + u003cu003e9_51138 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_138 = u003cu003e9_51138; + } + IEnumerable lancamentos5 = nums3.Where(u003cu003e9_51138); + Func u003cu003e9_51139 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_139; + if (u003cu003e9_51139 == null) + { + u003cu003e9_51139 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_139 = u003cu003e9_51139; + } + dadosFechamento.set_Debito(lancamentos5.Sum(u003cu003e9_51139)); + IGrouping nums4 = f; + Func u003cu003e9_51140 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_140; + if (u003cu003e9_51140 == null) + { + u003cu003e9_51140 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_140 = u003cu003e9_51140; + } + IEnumerable lancamentos6 = nums4.Where(u003cu003e9_51140); + Func u003cu003e9_51141 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_141; + if (u003cu003e9_51141 == null) + { + u003cu003e9_51141 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_141 = u003cu003e9_51141; + } + if (lancamentos6.Sum(u003cu003e9_51141) == decimal.Zero) + { + num = decimal.Zero; + } + else + { + IGrouping nums5 = f; + Func u003cu003e9_51142 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_142; + if (u003cu003e9_51142 == null) + { + u003cu003e9_51142 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_142 = u003cu003e9_51142; + } + IEnumerable lancamentos7 = nums5.Where(u003cu003e9_51142); + Func u003cu003e9_51143 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_143; + if (u003cu003e9_51143 == null) + { + u003cu003e9_51143 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_143 = u003cu003e9_51143; + } + decimal num2 = lancamentos7.Sum(u003cu003e9_51143); + List lancamentos8 = lancamentos13; + Func u003cu003e9_51144 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_144; + if (u003cu003e9_51144 == null) + { + u003cu003e9_51144 = (Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 1; + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_144 = u003cu003e9_51144; + } + IEnumerable lancamentos9 = lancamentos8.Where(u003cu003e9_51144); + Func u003cu003e9_51145 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_145; + if (u003cu003e9_51145 == null) + { + u003cu003e9_51145 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_145 = u003cu003e9_51145; + } + num = (num2 / lancamentos9.Sum(u003cu003e9_51145)) * new decimal(100); + } + dadosFechamento.set_PercentualDebito(num); + return dadosFechamento; + }).ToList()); + FechamentoFinanceiro fechamentoFinanceiro3 = fechamentoFinanceiro2; + List dadosFechamentos3 = fechamentoFinanceiro3.get_Dados(); + DadosFechamento dadosFechamento2 = new DadosFechamento(); + dadosFechamento2.set_Planos("TOTAL"); + List dadosFechamentos4 = fechamentoFinanceiro3.get_Dados(); + dadosFechamento2.set_Credito(dadosFechamentos4.Sum((DadosFechamento t) => t.get_Credito())); + List dadosFechamentos5 = fechamentoFinanceiro3.get_Dados(); + dadosFechamento2.set_Debito(dadosFechamentos5.Sum((DadosFechamento t) => t.get_Debito())); + List dadosFechamentos6 = fechamentoFinanceiro3.get_Dados(); + if (dadosFechamentos6.Sum((DadosFechamento t) => t.get_Credito()) == decimal.Zero) + { + num7 = decimal.Zero; + } + else + { + List dadosFechamentos7 = fechamentoFinanceiro3.get_Dados(); + decimal num18 = dadosFechamentos7.Sum((DadosFechamento t) => t.get_Credito()); + List lancamentos18 = lancamentos13; + IEnumerable lancamentos19 = lancamentos18.Where((Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 0; + }); + num7 = (num18 / lancamentos19.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento2.set_PercentualCredito(num7); + List dadosFechamentos8 = fechamentoFinanceiro3.get_Dados(); + if (dadosFechamentos8.Sum((DadosFechamento t) => t.get_Debito()) == decimal.Zero) + { + num8 = decimal.Zero; + } + else + { + List dadosFechamentos9 = fechamentoFinanceiro3.get_Dados(); + decimal num19 = dadosFechamentos9.Sum((DadosFechamento t) => t.get_Debito()); + List lancamentos20 = lancamentos13; + IEnumerable lancamentos21 = lancamentos20.Where((Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 1; + }); + num8 = (num19 / lancamentos21.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento2.set_PercentualDebito(num8); + dadosFechamentos3.Add(dadosFechamento2); + this.Fechamento.Add(fechamentoFinanceiro3); + FechamentoFinanceiro fechamentoFinanceiro4 = new FechamentoFinanceiro(); + fechamentoFinanceiro4.set_Plano("TRANSFERÊNCIA"); + List lancamentos22 = lancamentos13; + IEnumerable lancamentos23 = lancamentos22.Where((Lancamento x) => { + object plano; + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = null; + } + return plano == null; + }); + IOrderedEnumerable descricao1 = + from x in lancamentos23 + orderby x.get_Conta().get_Descricao() + select x; + IEnumerable> id = + from x in descricao1 + group x by x.get_Conta().get_Id(); + fechamentoFinanceiro4.set_Dados(id.Select, DadosFechamento>((IGrouping f) => { + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos(f.First().get_Conta().get_Descricao()); + dadosFechamento.set_Credito(( + from s in f + where s.get_Sinal() == 0 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())); + dadosFechamento.set_PercentualCredito((( + from s in f + where s.get_Sinal() == 0 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault()) == decimal.Zero ? decimal.Zero : (( + from s in f + where s.get_Sinal() == 0 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault()) / ( + from s in f + where s.get_Sinal() == 0 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100))); + dadosFechamento.set_Debito(( + from s in f + where s.get_Sinal() == 1 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())); + dadosFechamento.set_PercentualDebito((( + from s in f + where s.get_Sinal() == 1 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault()) == decimal.Zero ? decimal.Zero : (( + from s in f + where s.get_Sinal() == 1 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault()) / ( + from s in f + where s.get_Sinal() == 1 + select s).Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100))); + return dadosFechamento; + }).ToList()); + FechamentoFinanceiro fechamentoFinanceiro5 = fechamentoFinanceiro4; + List dadosFechamentos10 = fechamentoFinanceiro5.get_Dados(); + DadosFechamento dadosFechamento3 = new DadosFechamento(); + dadosFechamento3.set_Planos("TOTAL"); + List dadosFechamentos11 = fechamentoFinanceiro5.get_Dados(); + dadosFechamento3.set_Credito(dadosFechamentos11.Sum((DadosFechamento t) => t.get_Credito())); + List dadosFechamentos12 = fechamentoFinanceiro5.get_Dados(); + dadosFechamento3.set_Debito(dadosFechamentos12.Sum((DadosFechamento t) => t.get_Debito())); + List dadosFechamentos13 = fechamentoFinanceiro5.get_Dados(); + if (dadosFechamentos13.Sum((DadosFechamento t) => t.get_Credito()) == decimal.Zero) + { + num9 = decimal.Zero; + } + else + { + List dadosFechamentos14 = fechamentoFinanceiro5.get_Dados(); + decimal num20 = dadosFechamentos14.Sum((DadosFechamento t) => t.get_Credito()); + List lancamentos24 = lancamentos13; + IEnumerable lancamentos25 = lancamentos24.Where((Lancamento s) => { + bool plano; + ControleFinanceiro controle = s.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = false; + } + if (plano) + { + return false; + } + return s.get_Sinal() == 0; + }); + num9 = (num20 / lancamentos25.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento3.set_PercentualCredito(num9); + List dadosFechamentos15 = fechamentoFinanceiro5.get_Dados(); + if (dadosFechamentos15.Sum((DadosFechamento t) => t.get_Debito()) == decimal.Zero) + { + num10 = decimal.Zero; + } + else + { + List dadosFechamentos16 = fechamentoFinanceiro5.get_Dados(); + decimal num21 = dadosFechamentos16.Sum((DadosFechamento t) => t.get_Debito()); + List lancamentos26 = lancamentos13; + IEnumerable lancamentos27 = lancamentos26.Where((Lancamento s) => { + bool plano; + ControleFinanceiro controle = s.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = false; + } + if (plano) + { + return false; + } + return s.get_Sinal() == 1; + }); + num10 = (num21 / lancamentos27.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento3.set_PercentualDebito(num10); + dadosFechamentos10.Add(dadosFechamento3); + this.Fechamento.Add(fechamentoFinanceiro5); + FechamentoFinanceiro fechamentoFinanceiro6 = new FechamentoFinanceiro(); + fechamentoFinanceiro6.set_Plano("CONTA CORRENTE + TRANSFERÊNCIA"); + List lancamentos28 = lancamentos13; + IOrderedEnumerable descricao2 = + from x in lancamentos28 + orderby x.get_Conta().get_Descricao() + select x; + fechamentoFinanceiro6.set_Dados(( + from x in descricao2 + group x by x.get_Conta().get_Id()).Select, DadosFechamento>((IGrouping f) => { + decimal zero; + decimal num; + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos(f.First().get_Conta().get_Descricao()); + IGrouping nums = f; + Func u003cu003e9_51189 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_189; + if (u003cu003e9_51189 == null) + { + u003cu003e9_51189 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_189 = u003cu003e9_51189; + } + IEnumerable lancamentos = nums.Where(u003cu003e9_51189); + Func u003cu003e9_51190 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_190; + if (u003cu003e9_51190 == null) + { + u003cu003e9_51190 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_190 = u003cu003e9_51190; + } + dadosFechamento.set_Credito(lancamentos.Sum(u003cu003e9_51190)); + IGrouping nums1 = f; + Func u003cu003e9_51191 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_191; + if (u003cu003e9_51191 == null) + { + u003cu003e9_51191 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_191 = u003cu003e9_51191; + } + IEnumerable lancamentos1 = nums1.Where(u003cu003e9_51191); + Func u003cu003e9_51192 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_192; + if (u003cu003e9_51192 == null) + { + u003cu003e9_51192 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_192 = u003cu003e9_51192; + } + if (lancamentos1.Sum(u003cu003e9_51192) == decimal.Zero) + { + zero = decimal.Zero; + } + else + { + IGrouping nums2 = f; + Func u003cu003e9_51193 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_193; + if (u003cu003e9_51193 == null) + { + u003cu003e9_51193 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_193 = u003cu003e9_51193; + } + IEnumerable lancamentos2 = nums2.Where(u003cu003e9_51193); + Func u003cu003e9_51194 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_194; + if (u003cu003e9_51194 == null) + { + u003cu003e9_51194 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_194 = u003cu003e9_51194; + } + decimal num1 = lancamentos2.Sum(u003cu003e9_51194); + List lancamentos3 = lancamentos13; + Func u003cu003e9_51195 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_195; + if (u003cu003e9_51195 == null) + { + u003cu003e9_51195 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_195 = u003cu003e9_51195; + } + IEnumerable lancamentos4 = lancamentos3.Where(u003cu003e9_51195); + Func u003cu003e9_51196 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_196; + if (u003cu003e9_51196 == null) + { + u003cu003e9_51196 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_196 = u003cu003e9_51196; + } + zero = (num1 / lancamentos4.Sum(u003cu003e9_51196)) * new decimal(100); + } + dadosFechamento.set_PercentualCredito(zero); + IGrouping nums3 = f; + Func u003cu003e9_51197 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_197; + if (u003cu003e9_51197 == null) + { + u003cu003e9_51197 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_197 = u003cu003e9_51197; + } + IEnumerable lancamentos5 = nums3.Where(u003cu003e9_51197); + Func u003cu003e9_51198 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_198; + if (u003cu003e9_51198 == null) + { + u003cu003e9_51198 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_198 = u003cu003e9_51198; + } + dadosFechamento.set_Debito(lancamentos5.Sum(u003cu003e9_51198)); + IGrouping nums4 = f; + Func u003cu003e9_51199 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_199; + if (u003cu003e9_51199 == null) + { + u003cu003e9_51199 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_199 = u003cu003e9_51199; + } + IEnumerable lancamentos6 = nums4.Where(u003cu003e9_51199); + Func u003cu003e9_51200 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_200; + if (u003cu003e9_51200 == null) + { + u003cu003e9_51200 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_200 = u003cu003e9_51200; + } + if (lancamentos6.Sum(u003cu003e9_51200) == decimal.Zero) + { + num = decimal.Zero; + } + else + { + IGrouping nums5 = f; + Func u003cu003e9_51201 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_201; + if (u003cu003e9_51201 == null) + { + u003cu003e9_51201 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_201 = u003cu003e9_51201; + } + IEnumerable lancamentos7 = nums5.Where(u003cu003e9_51201); + Func u003cu003e9_51202 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_202; + if (u003cu003e9_51202 == null) + { + u003cu003e9_51202 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_202 = u003cu003e9_51202; + } + decimal num2 = lancamentos7.Sum(u003cu003e9_51202); + List lancamentos8 = lancamentos13; + Func u003cu003e9_51203 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_203; + if (u003cu003e9_51203 == null) + { + u003cu003e9_51203 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_203 = u003cu003e9_51203; + } + IEnumerable lancamentos9 = lancamentos8.Where(u003cu003e9_51203); + Func u003cu003e9_51204 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_204; + if (u003cu003e9_51204 == null) + { + u003cu003e9_51204 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_204 = u003cu003e9_51204; + } + num = (num2 / lancamentos9.Sum(u003cu003e9_51204)) * new decimal(100); + } + dadosFechamento.set_PercentualDebito(num); + return dadosFechamento; + }).ToList()); + FechamentoFinanceiro fechamentoFinanceiro7 = fechamentoFinanceiro6; + List dadosFechamentos17 = fechamentoFinanceiro7.get_Dados(); + DadosFechamento dadosFechamento4 = new DadosFechamento(); + dadosFechamento4.set_Planos("TOTAL"); + List dadosFechamentos18 = fechamentoFinanceiro7.get_Dados(); + dadosFechamento4.set_Credito(dadosFechamentos18.Sum((DadosFechamento t) => t.get_Credito())); + List dadosFechamentos19 = fechamentoFinanceiro7.get_Dados(); + dadosFechamento4.set_Debito(dadosFechamentos19.Sum((DadosFechamento t) => t.get_Debito())); + List dadosFechamentos20 = fechamentoFinanceiro7.get_Dados(); + if (dadosFechamentos20.Sum((DadosFechamento t) => t.get_Credito()) == decimal.Zero) + { + num11 = decimal.Zero; + } + else + { + List dadosFechamentos21 = fechamentoFinanceiro7.get_Dados(); + decimal num22 = dadosFechamentos21.Sum((DadosFechamento t) => t.get_Credito()); + List lancamentos29 = lancamentos13; + IEnumerable sinal = + from s in lancamentos29 + where s.get_Sinal() == 0 + select s; + num11 = (num22 / sinal.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento4.set_PercentualCredito(num11); + List dadosFechamentos22 = fechamentoFinanceiro7.get_Dados(); + if (dadosFechamentos22.Sum((DadosFechamento t) => t.get_Debito()) == decimal.Zero) + { + num12 = decimal.Zero; + } + else + { + List dadosFechamentos23 = fechamentoFinanceiro7.get_Dados(); + decimal num23 = dadosFechamentos23.Sum((DadosFechamento t) => t.get_Debito()); + List lancamentos30 = lancamentos13; + IEnumerable sinal1 = + from s in lancamentos30 + where s.get_Sinal() == 1 + select s; + num12 = (num23 / sinal1.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento4.set_PercentualDebito(num12); + dadosFechamentos17.Add(dadosFechamento4); + this.Fechamento.Add(fechamentoFinanceiro7); + FechamentoFinanceiro fechamentoFinanceiro8 = new FechamentoFinanceiro(); + fechamentoFinanceiro8.set_Plano("CENTRO DE CUSTO"); + List lancamentos31 = lancamentos13; + IEnumerable lancamentos32 = lancamentos31.Where((Lancamento x) => { + object plano; + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = null; + } + return plano != null; + }); + IOrderedEnumerable descricao3 = + from x in lancamentos32 + orderby x.get_Controle().get_Centro().get_Descricao() + select x; + fechamentoFinanceiro8.set_Dados(( + from x in descricao3 + group x by x.get_Controle().get_Centro().get_Id()).Select, DadosFechamento>((IGrouping f) => { + decimal zero; + decimal num; + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos(f.First().get_Controle().get_Centro().get_Descricao()); + IGrouping nums = f; + Func u003cu003e9_51219 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_219; + if (u003cu003e9_51219 == null) + { + u003cu003e9_51219 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_219 = u003cu003e9_51219; + } + IEnumerable lancamentos = nums.Where(u003cu003e9_51219); + Func u003cu003e9_51220 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_220; + if (u003cu003e9_51220 == null) + { + u003cu003e9_51220 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_220 = u003cu003e9_51220; + } + dadosFechamento.set_Credito(lancamentos.Sum(u003cu003e9_51220)); + IGrouping nums1 = f; + Func u003cu003e9_51221 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_221; + if (u003cu003e9_51221 == null) + { + u003cu003e9_51221 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_221 = u003cu003e9_51221; + } + IEnumerable lancamentos1 = nums1.Where(u003cu003e9_51221); + Func u003cu003e9_51222 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_222; + if (u003cu003e9_51222 == null) + { + u003cu003e9_51222 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_222 = u003cu003e9_51222; + } + if (lancamentos1.Sum(u003cu003e9_51222) == decimal.Zero) + { + zero = decimal.Zero; + } + else + { + IGrouping nums2 = f; + Func u003cu003e9_51223 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_223; + if (u003cu003e9_51223 == null) + { + u003cu003e9_51223 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_223 = u003cu003e9_51223; + } + IEnumerable lancamentos2 = nums2.Where(u003cu003e9_51223); + Func u003cu003e9_51224 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_224; + if (u003cu003e9_51224 == null) + { + u003cu003e9_51224 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_224 = u003cu003e9_51224; + } + decimal num1 = lancamentos2.Sum(u003cu003e9_51224); + List lancamentos3 = lancamentos13; + Func u003cu003e9_51225 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_225; + if (u003cu003e9_51225 == null) + { + u003cu003e9_51225 = (Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 0; + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_225 = u003cu003e9_51225; + } + IEnumerable lancamentos4 = lancamentos3.Where(u003cu003e9_51225); + Func u003cu003e9_51226 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_226; + if (u003cu003e9_51226 == null) + { + u003cu003e9_51226 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_226 = u003cu003e9_51226; + } + zero = (num1 / lancamentos4.Sum(u003cu003e9_51226)) * new decimal(100); + } + dadosFechamento.set_PercentualCredito(zero); + IGrouping nums3 = f; + Func u003cu003e9_51227 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_227; + if (u003cu003e9_51227 == null) + { + u003cu003e9_51227 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_227 = u003cu003e9_51227; + } + IEnumerable lancamentos5 = nums3.Where(u003cu003e9_51227); + Func u003cu003e9_51228 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_228; + if (u003cu003e9_51228 == null) + { + u003cu003e9_51228 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_228 = u003cu003e9_51228; + } + dadosFechamento.set_Debito(lancamentos5.Sum(u003cu003e9_51228)); + IGrouping nums4 = f; + Func u003cu003e9_51229 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_229; + if (u003cu003e9_51229 == null) + { + u003cu003e9_51229 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_229 = u003cu003e9_51229; + } + IEnumerable lancamentos6 = nums4.Where(u003cu003e9_51229); + Func u003cu003e9_51230 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_230; + if (u003cu003e9_51230 == null) + { + u003cu003e9_51230 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_230 = u003cu003e9_51230; + } + if (lancamentos6.Sum(u003cu003e9_51230) == decimal.Zero) + { + num = decimal.Zero; + } + else + { + IGrouping nums5 = f; + Func u003cu003e9_51231 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_231; + if (u003cu003e9_51231 == null) + { + u003cu003e9_51231 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_231 = u003cu003e9_51231; + } + IEnumerable lancamentos7 = nums5.Where(u003cu003e9_51231); + Func u003cu003e9_51232 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_232; + if (u003cu003e9_51232 == null) + { + u003cu003e9_51232 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_232 = u003cu003e9_51232; + } + decimal num2 = lancamentos7.Sum(u003cu003e9_51232); + List lancamentos8 = lancamentos13; + Func u003cu003e9_51233 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_233; + if (u003cu003e9_51233 == null) + { + u003cu003e9_51233 = (Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 1; + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_233 = u003cu003e9_51233; + } + IEnumerable lancamentos9 = lancamentos8.Where(u003cu003e9_51233); + Func u003cu003e9_51234 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_234; + if (u003cu003e9_51234 == null) + { + u003cu003e9_51234 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_234 = u003cu003e9_51234; + } + num = (num2 / lancamentos9.Sum(u003cu003e9_51234)) * new decimal(100); + } + dadosFechamento.set_PercentualDebito(num); + return dadosFechamento; + }).ToList()); + FechamentoFinanceiro fechamentoFinanceiro9 = fechamentoFinanceiro8; + List dadosFechamentos24 = fechamentoFinanceiro9.get_Dados(); + DadosFechamento dadosFechamento5 = new DadosFechamento(); + dadosFechamento5.set_Planos("TOTAL"); + List dadosFechamentos25 = fechamentoFinanceiro9.get_Dados(); + dadosFechamento5.set_Credito(dadosFechamentos25.Sum((DadosFechamento t) => t.get_Credito())); + List dadosFechamentos26 = fechamentoFinanceiro9.get_Dados(); + dadosFechamento5.set_Debito(dadosFechamentos26.Sum((DadosFechamento t) => t.get_Debito())); + List dadosFechamentos27 = fechamentoFinanceiro9.get_Dados(); + if (dadosFechamentos27.Sum((DadosFechamento t) => t.get_Credito()) == decimal.Zero) + { + num13 = decimal.Zero; + } + else + { + List dadosFechamentos28 = fechamentoFinanceiro9.get_Dados(); + decimal num24 = dadosFechamentos28.Sum((DadosFechamento t) => t.get_Credito()); + List lancamentos33 = lancamentos13; + IEnumerable lancamentos34 = lancamentos33.Where((Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 0; + }); + num13 = (num24 / lancamentos34.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento5.set_PercentualCredito(num13); + List dadosFechamentos29 = fechamentoFinanceiro9.get_Dados(); + if (dadosFechamentos29.Sum((DadosFechamento t) => t.get_Debito()) == decimal.Zero) + { + num14 = decimal.Zero; + } + else + { + List dadosFechamentos30 = fechamentoFinanceiro9.get_Dados(); + decimal num25 = dadosFechamentos30.Sum((DadosFechamento t) => t.get_Debito()); + List lancamentos35 = lancamentos13; + IEnumerable lancamentos36 = lancamentos35.Where((Lancamento s) => { + if (s.get_Controle() == null) + { + return false; + } + return s.get_Sinal() == 1; + }); + num14 = (num25 / lancamentos36.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento5.set_PercentualDebito(num14); + dadosFechamentos24.Add(dadosFechamento5); + this.Fechamento.Add(fechamentoFinanceiro9); + FechamentoFinanceiro fechamentoFinanceiro10 = new FechamentoFinanceiro(); + fechamentoFinanceiro10.set_Plano("TIPO PAGAMENTO"); + List lancamentos37 = lancamentos13; + IOrderedEnumerable description = + from x in lancamentos37 + orderby EnumHelper.GetDescription(x.get_TipoPagamento()) + select x; + fechamentoFinanceiro10.set_Dados(( + from x in description + group x by x.get_TipoPagamento()).Select, DadosFechamento>((IGrouping f) => { + decimal zero; + decimal num; + DadosFechamento dadosFechamento = new DadosFechamento(); + dadosFechamento.set_Planos(EnumHelper.GetDescription(f.First().get_TipoPagamento())); + IGrouping tipoPagamentos = f; + Func u003cu003e9_51248 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_248; + if (u003cu003e9_51248 == null) + { + u003cu003e9_51248 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_248 = u003cu003e9_51248; + } + IEnumerable lancamentos = tipoPagamentos.Where(u003cu003e9_51248); + Func u003cu003e9_51249 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_249; + if (u003cu003e9_51249 == null) + { + u003cu003e9_51249 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_249 = u003cu003e9_51249; + } + dadosFechamento.set_Credito(lancamentos.Sum(u003cu003e9_51249)); + IGrouping tipoPagamentos1 = f; + Func u003cu003e9_51250 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_250; + if (u003cu003e9_51250 == null) + { + u003cu003e9_51250 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_250 = u003cu003e9_51250; + } + IEnumerable lancamentos1 = tipoPagamentos1.Where(u003cu003e9_51250); + Func u003cu003e9_51251 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_251; + if (u003cu003e9_51251 == null) + { + u003cu003e9_51251 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_251 = u003cu003e9_51251; + } + if (lancamentos1.Sum(u003cu003e9_51251) == decimal.Zero) + { + zero = decimal.Zero; + } + else + { + IGrouping tipoPagamentos2 = f; + Func u003cu003e9_51252 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_252; + if (u003cu003e9_51252 == null) + { + u003cu003e9_51252 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_252 = u003cu003e9_51252; + } + IEnumerable lancamentos2 = tipoPagamentos2.Where(u003cu003e9_51252); + Func u003cu003e9_51253 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_253; + if (u003cu003e9_51253 == null) + { + u003cu003e9_51253 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_253 = u003cu003e9_51253; + } + decimal num1 = lancamentos2.Sum(u003cu003e9_51253); + List lancamentos3 = lancamentos13; + Func u003cu003e9_51254 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_254; + if (u003cu003e9_51254 == null) + { + u003cu003e9_51254 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_254 = u003cu003e9_51254; + } + IEnumerable lancamentos4 = lancamentos3.Where(u003cu003e9_51254); + Func u003cu003e9_51255 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_255; + if (u003cu003e9_51255 == null) + { + u003cu003e9_51255 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_255 = u003cu003e9_51255; + } + zero = (num1 / lancamentos4.Sum(u003cu003e9_51255)) * new decimal(100); + } + dadosFechamento.set_PercentualCredito(zero); + IGrouping tipoPagamentos3 = f; + Func u003cu003e9_51256 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_256; + if (u003cu003e9_51256 == null) + { + u003cu003e9_51256 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_256 = u003cu003e9_51256; + } + IEnumerable lancamentos5 = tipoPagamentos3.Where(u003cu003e9_51256); + Func u003cu003e9_51257 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_257; + if (u003cu003e9_51257 == null) + { + u003cu003e9_51257 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_257 = u003cu003e9_51257; + } + dadosFechamento.set_Debito(lancamentos5.Sum(u003cu003e9_51257)); + IGrouping tipoPagamentos4 = f; + Func u003cu003e9_51258 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_258; + if (u003cu003e9_51258 == null) + { + u003cu003e9_51258 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_258 = u003cu003e9_51258; + } + IEnumerable lancamentos6 = tipoPagamentos4.Where(u003cu003e9_51258); + Func u003cu003e9_51259 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_259; + if (u003cu003e9_51259 == null) + { + u003cu003e9_51259 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_259 = u003cu003e9_51259; + } + if (lancamentos6.Sum(u003cu003e9_51259) == decimal.Zero) + { + num = decimal.Zero; + } + else + { + IGrouping tipoPagamentos5 = f; + Func u003cu003e9_51260 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_260; + if (u003cu003e9_51260 == null) + { + u003cu003e9_51260 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_260 = u003cu003e9_51260; + } + IEnumerable lancamentos7 = tipoPagamentos5.Where(u003cu003e9_51260); + Func u003cu003e9_51261 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_261; + if (u003cu003e9_51261 == null) + { + u003cu003e9_51261 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_261 = u003cu003e9_51261; + } + decimal num2 = lancamentos7.Sum(u003cu003e9_51261); + List lancamentos8 = lancamentos13; + Func u003cu003e9_51262 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_262; + if (u003cu003e9_51262 == null) + { + u003cu003e9_51262 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_262 = u003cu003e9_51262; + } + IEnumerable lancamentos9 = lancamentos8.Where(u003cu003e9_51262); + Func u003cu003e9_51263 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_263; + if (u003cu003e9_51263 == null) + { + u003cu003e9_51263 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_263 = u003cu003e9_51263; + } + num = (num2 / lancamentos9.Sum(u003cu003e9_51263)) * new decimal(100); + } + dadosFechamento.set_PercentualDebito(num); + return dadosFechamento; + }).ToList()); + FechamentoFinanceiro fechamentoFinanceiro11 = fechamentoFinanceiro10; + List dadosFechamentos31 = fechamentoFinanceiro11.get_Dados(); + DadosFechamento dadosFechamento6 = new DadosFechamento(); + dadosFechamento6.set_Planos("TOTAL"); + List dadosFechamentos32 = fechamentoFinanceiro11.get_Dados(); + dadosFechamento6.set_Credito(dadosFechamentos32.Sum((DadosFechamento t) => t.get_Credito())); + List dadosFechamentos33 = fechamentoFinanceiro11.get_Dados(); + dadosFechamento6.set_Debito(dadosFechamentos33.Sum((DadosFechamento t) => t.get_Debito())); + List dadosFechamentos34 = fechamentoFinanceiro11.get_Dados(); + if (dadosFechamentos34.Sum((DadosFechamento t) => t.get_Credito()) == decimal.Zero) + { + num15 = decimal.Zero; + } + else + { + List dadosFechamentos35 = fechamentoFinanceiro11.get_Dados(); + decimal num26 = dadosFechamentos35.Sum((DadosFechamento t) => t.get_Credito()); + List lancamentos38 = lancamentos13; + IEnumerable sinal2 = + from s in lancamentos38 + where s.get_Sinal() == 0 + select s; + num15 = (num26 / sinal2.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento6.set_PercentualCredito(num15); + List dadosFechamentos36 = fechamentoFinanceiro11.get_Dados(); + if (dadosFechamentos36.Sum((DadosFechamento t) => t.get_Debito()) == decimal.Zero) + { + num16 = decimal.Zero; + } + else + { + List dadosFechamentos37 = fechamentoFinanceiro11.get_Dados(); + decimal num27 = dadosFechamentos37.Sum((DadosFechamento t) => t.get_Debito()); + List lancamentos39 = lancamentos13; + IEnumerable sinal3 = + from s in lancamentos39 + where s.get_Sinal() == 1 + select s; + num16 = (num27 / sinal3.Sum((Lancamento s) => s.get_ValorPago().GetValueOrDefault())) * new decimal(100); + } + dadosFechamento6.set_PercentualDebito(num16); + List dadosFechamentos38 = fechamentoFinanceiro11.get_Dados(); + decimal num28 = dadosFechamentos38.Sum((DadosFechamento t) => t.get_Credito()); + List dadosFechamentos39 = fechamentoFinanceiro11.get_Dados(); + dadosFechamento6.set_Soma(num28 - dadosFechamentos39.Sum((DadosFechamento t) => t.get_Debito())); + List dadosFechamentos40 = fechamentoFinanceiro11.get_Dados(); + decimal num29 = dadosFechamentos40.Sum((DadosFechamento t) => t.get_Credito()); + List dadosFechamentos41 = fechamentoFinanceiro11.get_Dados(); + if ((num29 + dadosFechamentos41.Sum((DadosFechamento t) => t.get_Debito())) == decimal.Zero) + { + num17 = decimal.Zero; + } + else + { + List dadosFechamentos42 = fechamentoFinanceiro11.get_Dados(); + decimal num30 = dadosFechamentos42.Sum((DadosFechamento t) => t.get_Credito()); + List dadosFechamentos43 = fechamentoFinanceiro11.get_Dados(); + decimal num31 = (num30 - dadosFechamentos43.Sum((DadosFechamento t) => t.get_Debito())) * new decimal(100); + List dadosFechamentos44 = fechamentoFinanceiro11.get_Dados(); + decimal num32 = dadosFechamentos44.Sum((DadosFechamento t) => t.get_Credito()); + List dadosFechamentos45 = fechamentoFinanceiro11.get_Dados(); + num17 = num31 / (num32 + dadosFechamentos45.Sum((DadosFechamento t) => t.get_Debito())); + } + dadosFechamento6.set_SomaPercentual(num17); + dadosFechamentos31.Add(dadosFechamento6); + this.Fechamento.Add(fechamentoFinanceiro11); + } + else + { + this.FechamentoAnalitico = new List(); + List lancamentos40 = lancamentos13; + IEnumerable lancamentos41 = lancamentos40.Where((Lancamento x) => { + object plano; + ControleFinanceiro controle = x.get_Controle(); + if (controle != null) + { + plano = controle.get_Plano(); + } + else + { + plano = null; + } + return plano != null; + }); + IOrderedEnumerable nome1 = + from x in lancamentos41 + orderby x.get_Controle().get_Plano().get_Nome() + select x; + ( + from x in nome1 + group x by x.get_Controle().get_Plano().get_Plano().get_Id()).ToList>().ForEach((IGrouping x) => { + FechamentoFinanceiroAnalitico fechamentoFinanceiroAnalitico = new FechamentoFinanceiroAnalitico(); + fechamentoFinanceiroAnalitico.set_NomeConta(x.First().get_Controle().get_Plano().get_Plano().get_Descricao().ToUpper()); + IGrouping nums19 = x; + Func u003cu003e9_5112 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_12; + if (u003cu003e9_5112 == null) + { + u003cu003e9_5112 = (Lancamento f) => f.get_Controle().get_Plano().get_Id(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_12 = u003cu003e9_5112; + } + IOrderedEnumerable lancamentos12 = nums19.OrderBy(u003cu003e9_5112); + Func u003cu003e9_5113 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_13; + if (u003cu003e9_5113 == null) + { + u003cu003e9_5113 = (Lancamento f) => f.get_Controle().get_Plano().get_Id(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_13 = u003cu003e9_5113; + } + fechamentoFinanceiroAnalitico.set_Dados(lancamentos12.GroupBy(u003cu003e9_5113).Select, DadosFechamentoAnalitico>((IGrouping f) => { + Func func; + decimal zero; + decimal zero1; + DadosFechamentoAnalitico dadosFechamentoAnalitico = new DadosFechamentoAnalitico(); + dadosFechamentoAnalitico.set_Nome(f.First().get_Controle().get_Plano().get_Descricao()); + IGrouping nums = f; + Func u003cu003e9_15 = func8; + if (u003cu003e9_15 == null) + { + Func cSu0024u003cu003e8_locals11 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 1, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 1, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = cSu0024u003cu003e8_locals11; + func8 = cSu0024u003cu003e8_locals11; + u003cu003e9_15 = func; + } + List list = nums.Where(u003cu003e9_15).ToList(); + Func u003cu003e9_5116 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_16; + if (u003cu003e9_5116 == null) + { + u003cu003e9_5116 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_16 = u003cu003e9_5116; + } + dadosFechamentoAnalitico.set_Jan(list.Sum(u003cu003e9_5116)); + IGrouping nums1 = f; + Func u003cu003e9_17 = func9; + if (u003cu003e9_17 == null) + { + Func func1 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 2, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + int year = filtroFinanceiro1.get_Inicio().Year; + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(year, 2, DateTime.DaysInMonth(inicio.Year, 2)); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func1; + func9 = func1; + u003cu003e9_17 = func; + } + List lancamentos = nums1.Where(u003cu003e9_17).ToList(); + Func u003cu003e9_5118 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_18; + if (u003cu003e9_5118 == null) + { + u003cu003e9_5118 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_18 = u003cu003e9_5118; + } + dadosFechamentoAnalitico.set_Fev(lancamentos.Sum(u003cu003e9_5118)); + IGrouping nums2 = f; + Func u003cu003e9_19 = func10; + if (u003cu003e9_19 == null) + { + Func cSu0024u003cu003e8_locals12 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 3, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 3, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = cSu0024u003cu003e8_locals12; + func10 = cSu0024u003cu003e8_locals12; + u003cu003e9_19 = func; + } + List list1 = nums2.Where(u003cu003e9_19).ToList(); + Func u003cu003e9_5120 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_20; + if (u003cu003e9_5120 == null) + { + u003cu003e9_5120 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_20 = u003cu003e9_5120; + } + dadosFechamentoAnalitico.set_Mar(list1.Sum(u003cu003e9_5120)); + IGrouping nums3 = f; + Func u003cu003e9_21 = func11; + if (u003cu003e9_21 == null) + { + Func func2 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 4, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 4, 30); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func2; + func11 = func2; + u003cu003e9_21 = func; + } + List lancamentos1 = nums3.Where(u003cu003e9_21).ToList(); + Func u003cu003e9_5122 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_22; + if (u003cu003e9_5122 == null) + { + u003cu003e9_5122 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_22 = u003cu003e9_5122; + } + dadosFechamentoAnalitico.set_Abr(lancamentos1.Sum(u003cu003e9_5122)); + IGrouping nums4 = f; + Func u003cu003e9_23 = func12; + if (u003cu003e9_23 == null) + { + Func func3 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 5, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 5, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func3; + func12 = func3; + u003cu003e9_23 = func; + } + List list2 = nums4.Where(u003cu003e9_23).ToList(); + Func u003cu003e9_5124 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_24; + if (u003cu003e9_5124 == null) + { + u003cu003e9_5124 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_24 = u003cu003e9_5124; + } + dadosFechamentoAnalitico.set_Mai(list2.Sum(u003cu003e9_5124)); + IGrouping nums5 = f; + Func u003cu003e9_25 = func13; + if (u003cu003e9_25 == null) + { + Func cSu0024u003cu003e8_locals14 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 6, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 6, 30); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = cSu0024u003cu003e8_locals14; + func13 = cSu0024u003cu003e8_locals14; + u003cu003e9_25 = func; + } + List lancamentos2 = nums5.Where(u003cu003e9_25).ToList(); + Func u003cu003e9_5126 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_26; + if (u003cu003e9_5126 == null) + { + u003cu003e9_5126 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_26 = u003cu003e9_5126; + } + dadosFechamentoAnalitico.set_Jun(lancamentos2.Sum(u003cu003e9_5126)); + IGrouping nums6 = f; + Func u003cu003e9_27 = func14; + if (u003cu003e9_27 == null) + { + Func func4 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 7, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 7, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func4; + func14 = func4; + u003cu003e9_27 = func; + } + List list3 = nums6.Where(u003cu003e9_27).ToList(); + Func u003cu003e9_5128 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_28; + if (u003cu003e9_5128 == null) + { + u003cu003e9_5128 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_28 = u003cu003e9_5128; + } + dadosFechamentoAnalitico.set_Jul(list3.Sum(u003cu003e9_5128)); + IGrouping nums7 = f; + Func u003cu003e9_29 = func15; + if (u003cu003e9_29 == null) + { + Func func5 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 8, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 8, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func5; + func15 = func5; + u003cu003e9_29 = func; + } + List lancamentos3 = nums7.Where(u003cu003e9_29).ToList(); + Func u003cu003e9_5130 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_30; + if (u003cu003e9_5130 == null) + { + u003cu003e9_5130 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_30 = u003cu003e9_5130; + } + dadosFechamentoAnalitico.set_Ago(lancamentos3.Sum(u003cu003e9_5130)); + IGrouping nums8 = f; + Func u003cu003e9_31 = func16; + if (u003cu003e9_31 == null) + { + Func cSu0024u003cu003e8_locals16 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 9, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 9, 30); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = cSu0024u003cu003e8_locals16; + func16 = cSu0024u003cu003e8_locals16; + u003cu003e9_31 = func; + } + List list4 = nums8.Where(u003cu003e9_31).ToList(); + Func u003cu003e9_5132 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_32; + if (u003cu003e9_5132 == null) + { + u003cu003e9_5132 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_32 = u003cu003e9_5132; + } + dadosFechamentoAnalitico.set_Set(list4.Sum(u003cu003e9_5132)); + IGrouping nums9 = f; + Func u003cu003e9_33 = func17; + if (u003cu003e9_33 == null) + { + Func func6 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 10, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 10, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func6; + func17 = func6; + u003cu003e9_33 = func; + } + List lancamentos4 = nums9.Where(u003cu003e9_33).ToList(); + Func u003cu003e9_5134 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_34; + if (u003cu003e9_5134 == null) + { + u003cu003e9_5134 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_34 = u003cu003e9_5134; + } + dadosFechamentoAnalitico.set_Out(lancamentos4.Sum(u003cu003e9_5134)); + IGrouping nums10 = f; + Func u003cu003e9_35 = func18; + if (u003cu003e9_35 == null) + { + Func func7 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 11, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 11, 30); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = func7; + func18 = func7; + u003cu003e9_35 = func; + } + List list5 = nums10.Where(u003cu003e9_35).ToList(); + Func u003cu003e9_5136 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_36; + if (u003cu003e9_5136 == null) + { + u003cu003e9_5136 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_36 = u003cu003e9_5136; + } + dadosFechamentoAnalitico.set_Nov(list5.Sum(u003cu003e9_5136)); + IGrouping nums11 = f; + Func u003cu003e9_37 = func19; + if (u003cu003e9_37 == null) + { + Func cSu0024u003cu003e8_locals18 = (Lancamento s) => { + DateTime? baixa = s.get_Baixa(); + DateTime inicio = filtroFinanceiro1.get_Inicio(); + DateTime dateTime = new DateTime(inicio.Year, 12, 1); + if ((baixa.HasValue ? baixa.GetValueOrDefault() < dateTime : true)) + { + return false; + } + baixa = s.get_Baixa(); + inicio = filtroFinanceiro1.get_Inicio(); + dateTime = new DateTime(inicio.Year, 12, 31); + if (!baixa.HasValue) + { + return false; + } + return baixa.GetValueOrDefault() <= dateTime; + }; + func = cSu0024u003cu003e8_locals18; + func19 = cSu0024u003cu003e8_locals18; + u003cu003e9_37 = func; + } + List lancamentos5 = nums11.Where(u003cu003e9_37).ToList(); + Func u003cu003e9_5138 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_38; + if (u003cu003e9_5138 == null) + { + u003cu003e9_5138 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_38 = u003cu003e9_5138; + } + dadosFechamentoAnalitico.set_Dez(lancamentos5.Sum(u003cu003e9_5138)); + IGrouping nums12 = f; + Func u003cu003e9_5139 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_39; + if (u003cu003e9_5139 == null) + { + u003cu003e9_5139 = (Lancamento s) => { + if (s.get_Sinal() != 1) + { + return s.get_ValorPago(); + } + decimal? valorPago = s.get_ValorPago(); + decimal num = 2; + decimal? nullable = s.get_ValorPago(); + decimal? nullable1 = (nullable.HasValue ? new decimal?(num * nullable.GetValueOrDefault()) : null); + if (!valorPago.HasValue | !nullable1.HasValue) + { + nullable = null; + return nullable; + } + return new decimal?(valorPago.GetValueOrDefault() - nullable1.GetValueOrDefault()); + }; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_39 = u003cu003e9_5139; + } + dadosFechamentoAnalitico.set_Total(nums12.Sum(u003cu003e9_5139)); + IGrouping nums13 = f; + Func u003cu003e9_5140 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_40; + if (u003cu003e9_5140 == null) + { + u003cu003e9_5140 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_40 = u003cu003e9_5140; + } + IEnumerable lancamentos6 = nums13.Where(u003cu003e9_5140); + Func u003cu003e9_5141 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_41; + if (u003cu003e9_5141 == null) + { + u003cu003e9_5141 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_41 = u003cu003e9_5141; + } + if (lancamentos6.Sum(u003cu003e9_5141) == decimal.Zero) + { + zero = decimal.Zero; + } + else + { + IGrouping nums14 = f; + Func u003cu003e9_5142 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_42; + if (u003cu003e9_5142 == null) + { + u003cu003e9_5142 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_42 = u003cu003e9_5142; + } + IEnumerable lancamentos7 = nums14.Where(u003cu003e9_5142); + Func u003cu003e9_5143 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_43; + if (u003cu003e9_5143 == null) + { + u003cu003e9_5143 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_43 = u003cu003e9_5143; + } + decimal num1 = lancamentos7.Sum(u003cu003e9_5143); + IGrouping nums15 = x; + Func u003cu003e9_5144 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_44; + if (u003cu003e9_5144 == null) + { + u003cu003e9_5144 = (Lancamento s) => s.get_Sinal() == 0; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_44 = u003cu003e9_5144; + } + IEnumerable lancamentos8 = nums15.Where(u003cu003e9_5144); + Func u003cu003e9_5145 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_45; + if (u003cu003e9_5145 == null) + { + u003cu003e9_5145 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_45 = u003cu003e9_5145; + } + zero = (num1 / lancamentos8.Sum(u003cu003e9_5145)) * new decimal(100); + } + dadosFechamentoAnalitico.set_PercentualCredito(zero); + IGrouping nums16 = f; + Func u003cu003e9_5146 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_46; + if (u003cu003e9_5146 == null) + { + u003cu003e9_5146 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_46 = u003cu003e9_5146; + } + IEnumerable lancamentos9 = nums16.Where(u003cu003e9_5146); + Func u003cu003e9_5147 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_47; + if (u003cu003e9_5147 == null) + { + u003cu003e9_5147 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_47 = u003cu003e9_5147; + } + if (lancamentos9.Sum(u003cu003e9_5147) == decimal.Zero) + { + zero1 = decimal.Zero; + } + else + { + IGrouping nums17 = f; + Func u003cu003e9_5148 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_48; + if (u003cu003e9_5148 == null) + { + u003cu003e9_5148 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_48 = u003cu003e9_5148; + } + IEnumerable lancamentos10 = nums17.Where(u003cu003e9_5148); + Func u003cu003e9_5149 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_49; + if (u003cu003e9_5149 == null) + { + u003cu003e9_5149 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_49 = u003cu003e9_5149; + } + decimal num2 = lancamentos10.Sum(u003cu003e9_5149); + IGrouping nums18 = x; + Func u003cu003e9_5150 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_50; + if (u003cu003e9_5150 == null) + { + u003cu003e9_5150 = (Lancamento s) => s.get_Sinal() == 1; + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_50 = u003cu003e9_5150; + } + IEnumerable lancamentos11 = nums18.Where(u003cu003e9_5150); + Func u003cu003e9_5151 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_51; + if (u003cu003e9_5151 == null) + { + u003cu003e9_5151 = (Lancamento s) => s.get_ValorPago().GetValueOrDefault(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_51 = u003cu003e9_5151; + } + zero1 = (num2 / lancamentos11.Sum(u003cu003e9_5151)) * new decimal(100); + } + dadosFechamentoAnalitico.set_PercentualDebito(zero1); + return dadosFechamentoAnalitico; + }).ToList()); + FechamentoFinanceiroAnalitico fechamentoFinanceiroAnalitico1 = fechamentoFinanceiroAnalitico; + List dados = fechamentoFinanceiroAnalitico1.get_Dados(); + DadosFechamentoAnalitico dadosFechamentoAnalitico1 = new DadosFechamentoAnalitico(); + dadosFechamentoAnalitico1.set_Nome("TOTAL"); + List dadosFechamentoAnaliticos = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5152 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_52; + if (u003cu003e9_5152 == null) + { + u003cu003e9_5152 = (DadosFechamentoAnalitico t) => t.get_Jan(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_52 = u003cu003e9_5152; + } + dadosFechamentoAnalitico1.set_Jan(dadosFechamentoAnaliticos.Sum(u003cu003e9_5152)); + List dados1 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5153 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_53; + if (u003cu003e9_5153 == null) + { + u003cu003e9_5153 = (DadosFechamentoAnalitico t) => t.get_Fev(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_53 = u003cu003e9_5153; + } + dadosFechamentoAnalitico1.set_Fev(dados1.Sum(u003cu003e9_5153)); + List dadosFechamentoAnaliticos1 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5154 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_54; + if (u003cu003e9_5154 == null) + { + u003cu003e9_5154 = (DadosFechamentoAnalitico t) => t.get_Mar(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_54 = u003cu003e9_5154; + } + dadosFechamentoAnalitico1.set_Mar(dadosFechamentoAnaliticos1.Sum(u003cu003e9_5154)); + List dados2 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5155 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_55; + if (u003cu003e9_5155 == null) + { + u003cu003e9_5155 = (DadosFechamentoAnalitico t) => t.get_Abr(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_55 = u003cu003e9_5155; + } + dadosFechamentoAnalitico1.set_Abr(dados2.Sum(u003cu003e9_5155)); + List dadosFechamentoAnaliticos2 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5156 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_56; + if (u003cu003e9_5156 == null) + { + u003cu003e9_5156 = (DadosFechamentoAnalitico t) => t.get_Mai(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_56 = u003cu003e9_5156; + } + dadosFechamentoAnalitico1.set_Mai(dadosFechamentoAnaliticos2.Sum(u003cu003e9_5156)); + List dados3 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5157 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_57; + if (u003cu003e9_5157 == null) + { + u003cu003e9_5157 = (DadosFechamentoAnalitico t) => t.get_Jun(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_57 = u003cu003e9_5157; + } + dadosFechamentoAnalitico1.set_Jun(dados3.Sum(u003cu003e9_5157)); + List dadosFechamentoAnaliticos3 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5158 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_58; + if (u003cu003e9_5158 == null) + { + u003cu003e9_5158 = (DadosFechamentoAnalitico t) => t.get_Jul(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_58 = u003cu003e9_5158; + } + dadosFechamentoAnalitico1.set_Jul(dadosFechamentoAnaliticos3.Sum(u003cu003e9_5158)); + List dados4 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5159 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_59; + if (u003cu003e9_5159 == null) + { + u003cu003e9_5159 = (DadosFechamentoAnalitico t) => t.get_Ago(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_59 = u003cu003e9_5159; + } + dadosFechamentoAnalitico1.set_Ago(dados4.Sum(u003cu003e9_5159)); + List dadosFechamentoAnaliticos4 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5160 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_60; + if (u003cu003e9_5160 == null) + { + u003cu003e9_5160 = (DadosFechamentoAnalitico t) => t.get_Set(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_60 = u003cu003e9_5160; + } + dadosFechamentoAnalitico1.set_Set(dadosFechamentoAnaliticos4.Sum(u003cu003e9_5160)); + List dados5 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5161 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_61; + if (u003cu003e9_5161 == null) + { + u003cu003e9_5161 = (DadosFechamentoAnalitico t) => t.get_Out(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_61 = u003cu003e9_5161; + } + dadosFechamentoAnalitico1.set_Out(dados5.Sum(u003cu003e9_5161)); + List dadosFechamentoAnaliticos5 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5162 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_62; + if (u003cu003e9_5162 == null) + { + u003cu003e9_5162 = (DadosFechamentoAnalitico t) => t.get_Nov(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_62 = u003cu003e9_5162; + } + dadosFechamentoAnalitico1.set_Nov(dadosFechamentoAnaliticos5.Sum(u003cu003e9_5162)); + List dados6 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5163 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_63; + if (u003cu003e9_5163 == null) + { + u003cu003e9_5163 = (DadosFechamentoAnalitico t) => t.get_Dez(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_63 = u003cu003e9_5163; + } + dadosFechamentoAnalitico1.set_Dez(dados6.Sum(u003cu003e9_5163)); + List dadosFechamentoAnaliticos6 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5164 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_64; + if (u003cu003e9_5164 == null) + { + u003cu003e9_5164 = (DadosFechamentoAnalitico t) => t.get_Total(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_64 = u003cu003e9_5164; + } + dadosFechamentoAnalitico1.set_Total(dadosFechamentoAnaliticos6.Sum(u003cu003e9_5164)); + List dados7 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5165 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_65; + if (u003cu003e9_5165 == null) + { + u003cu003e9_5165 = (DadosFechamentoAnalitico t) => t.get_PercentualCredito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_65 = u003cu003e9_5165; + } + dadosFechamentoAnalitico1.set_PercentualCredito(dados7.Sum(u003cu003e9_5165)); + List dadosFechamentoAnaliticos7 = fechamentoFinanceiroAnalitico1.get_Dados(); + Func u003cu003e9_5166 = FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_66; + if (u003cu003e9_5166 == null) + { + u003cu003e9_5166 = (DadosFechamentoAnalitico t) => t.get_PercentualDebito(); + FechamentoFinanceiroViewModel.u003cu003ec.u003cu003e9__51_66 = u003cu003e9_5166; + } + dadosFechamentoAnalitico1.set_PercentualDebito(dadosFechamentoAnaliticos7.Sum(u003cu003e9_5166)); + dados.Add(dadosFechamentoAnalitico1); + this.FechamentoAnalitico.Add(fechamentoFinanceiroAnalitico1); + }); + FechamentoFinanceiroAnalitico fechamentoFinanceiroAnalitico2 = new FechamentoFinanceiroAnalitico(); + fechamentoFinanceiroAnalitico2.set_NomeConta("TOTAL NO PERÍODO"); + fechamentoFinanceiroAnalitico2.set_Dados(new List()); + FechamentoFinanceiroAnalitico fechamentoFinanceiroAnalitico3 = fechamentoFinanceiroAnalitico2; + List dadosFechamentoAnaliticos8 = fechamentoFinanceiroAnalitico3.get_Dados(); + DadosFechamentoAnalitico dadosFechamentoAnalitico2 = new DadosFechamentoAnalitico(); + dadosFechamentoAnalitico2.set_Nome("TOTAL"); + List fechamentoAnalitico = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Jan(fechamentoAnalitico.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Jan(); + } + return new decimal?(new decimal()); + }))); + List fechamentoFinanceiroAnaliticos = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Fev(fechamentoFinanceiroAnaliticos.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Fev(); + } + return new decimal?(new decimal()); + }))); + List fechamentoAnalitico1 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Mar(fechamentoAnalitico1.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Mar(); + } + return new decimal?(new decimal()); + }))); + List fechamentoFinanceiroAnaliticos1 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Abr(fechamentoFinanceiroAnaliticos1.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Abr(); + } + return new decimal?(new decimal()); + }))); + List fechamentoAnalitico2 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Mai(fechamentoAnalitico2.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Mai(); + } + return new decimal?(new decimal()); + }))); + List fechamentoFinanceiroAnaliticos2 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Jun(fechamentoFinanceiroAnaliticos2.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Jun(); + } + return new decimal?(new decimal()); + }))); + List fechamentoAnalitico3 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Jul(fechamentoAnalitico3.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Jul(); + } + return new decimal?(new decimal()); + }))); + List fechamentoFinanceiroAnaliticos3 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Ago(fechamentoFinanceiroAnaliticos3.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Ago(); + } + return new decimal?(new decimal()); + }))); + List fechamentoAnalitico4 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Set(fechamentoAnalitico4.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Set(); + } + return new decimal?(new decimal()); + }))); + List fechamentoFinanceiroAnaliticos4 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Out(fechamentoFinanceiroAnaliticos4.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Out(); + } + return new decimal?(new decimal()); + }))); + List fechamentoAnalitico5 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Nov(fechamentoAnalitico5.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Nov(); + } + return new decimal?(new decimal()); + }))); + List fechamentoFinanceiroAnaliticos5 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Dez(fechamentoFinanceiroAnaliticos5.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Dez(); + } + return new decimal?(new decimal()); + }))); + List fechamentoAnalitico6 = this.FechamentoAnalitico; + dadosFechamentoAnalitico2.set_Total(fechamentoAnalitico6.Sum((FechamentoFinanceiroAnalitico x) => x.get_Dados().Sum((DadosFechamentoAnalitico y) => { + if (y.get_Nome() != "TOTAL") + { + return y.get_Total(); + } + return new decimal?(new decimal()); + }))); + dadosFechamentoAnalitico2.set_PercentualCredito(new decimal(100)); + dadosFechamentoAnalitico2.set_PercentualDebito(new decimal(100)); + dadosFechamentoAnaliticos8.Add(dadosFechamentoAnalitico2); + this.FechamentoAnalitico.Add(fechamentoFinanceiroAnalitico3); + } + this.HtmlContent = await this.GerarHtml(true); + } + } + + private async void LoadInicial() + { + this.Plano = await this._servico.BuscarPlanoAsync(); + this.Planos = await this._servico.BuscarPlanosAsync(); + this.Centro = await this._servico.BuscarCentroAsync(); + this.Conta = await (new BancosContasServico()).BuscarBancos(); + } + + public async Task Print() + { + string tempPath = Path.GetTempPath(); + string str = await this.GerarHtml(false); + string str1 = string.Format("{0}FECHAMENTO_FINANCEIRO_{1:ddMMyyyyhhmmss}.html", tempPath, Funcoes.GetNetworkTime()); + StreamWriter streamWriter = new StreamWriter(str1, true, Encoding.UTF8); + streamWriter.Write(str); + streamWriter.Close(); + Process.Start(str1); + tempPath = null; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/TranferenciaViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/TranferenciaViewModel.cs new file mode 100644 index 0000000..d4e189a --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/TranferenciaViewModel.cs @@ -0,0 +1,99 @@ +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class TranferenciaViewModel : BaseViewModel + { + private Gestor.Model.Domain.Financeiro.Transferencia _transferencia; + + private ObservableCollection _contas; + + private BancosContasServico _servico + { + get; + set; + } + + public ObservableCollection Contas + { + get + { + return this._contas; + } + set + { + this._contas = value; + base.OnPropertyChanged("Contas"); + } + } + + public Gestor.Model.Domain.Financeiro.Transferencia Transferencia + { + get + { + return this._transferencia; + } + set + { + this._transferencia = value; + base.OnPropertyChanged("Transferencia"); + } + } + + public TranferenciaViewModel(Gestor.Model.Domain.Financeiro.Transferencia transferencia) + { + this._servico = new BancosContasServico(); + this.Carregar(transferencia); + } + + private async void Carregar(Gestor.Model.Domain.Financeiro.Transferencia transferencia) + { + BancosContas bancosConta; + BancosContas bancosConta1; + List bancosContas = await this._servico.BuscarBancos(); + TranferenciaViewModel observableCollection = this; + List bancosContas1 = bancosContas; + IEnumerable ativo = + from x in bancosContas1 + where x.get_Ativo() + select x; + observableCollection.Contas = new ObservableCollection( + from x in ativo + orderby x.get_Descricao() + select x); + TranferenciaViewModel tranferenciaViewModel = this; + Gestor.Model.Domain.Financeiro.Transferencia transferencium = new Gestor.Model.Domain.Financeiro.Transferencia(); + if (transferencia.get_Origem() != null) + { + bancosConta = bancosContas.First((BancosContas x) => x.get_Id() == transferencia.get_Origem().get_Id()); + } + else + { + bancosConta = null; + } + transferencium.set_Origem(bancosConta); + transferencium.set_Data(transferencia.get_Data()); + transferencium.set_Valor(transferencia.get_Valor()); + if (transferencia.get_Destino() != null) + { + bancosConta1 = bancosContas.First((BancosContas x) => x.get_Id() == transferencia.get_Destino().get_Id()); + } + else + { + bancosConta1 = null; + } + transferencium.set_Destino(bancosConta1); + tranferenciaViewModel.Transferencia = transferencium; + } + } +} \ No newline at end of file -- cgit v1.2.3