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/FinanceiroViewModel.cs | 5973 ++++++++++++++++++++ 1 file changed, 5973 insertions(+) create mode 100644 Codemerx/Gestor.Application/ViewModels/Financeiro/FinanceiroViewModel.cs (limited to 'Codemerx/Gestor.Application/ViewModels/Financeiro/FinanceiroViewModel.cs') 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 -- cgit v1.2.3