using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; using CsQuery.ExtensionMethods; using Gestor.Application.Helpers; using Gestor.Application.Servicos; using Gestor.Application.Servicos.Ferramentas; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Ferramentas; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Relatorios; using Gestor.Model.Domain.Seguros; namespace Gestor.Application.ViewModels.Ferramentas; public class ManutencaoPagamentosViewModel : BaseSegurosViewModel { private Visibility _filtrosPersonalizados = (Visibility)2; private Visibility _visibilityFiltroPersonalizado = (Visibility)2; private List _filtroRelatorioPersonalizado; private FiltroPersonalizado _filtroPersonalizado; 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 Visibility _visibilitySemValor = (Visibility)2; private ObservableCollection _filtroPersonalizadoSelecionado; private ObservableCollection _filtroRelatorioSelecionado = new ObservableCollection(); private ObservableCollection _vendedores = new ObservableCollection(); private Vendedor _selectedVendedor; private bool _enableExcluirManutPagamento; private ObservableCollection _pagamentos; private ListCollectionView _view; private bool _allSelected; private string _selectedFiltro; private ObservableCollection _filtros; private DateTime? _inicio; private DateTime? _fim; private List _todosPagamentos; public Visibility FiltrosPersonalizados { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _filtrosPersonalizados; } set { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) _filtrosPersonalizados = value; OnPropertyChanged("FiltrosPersonalizados"); } } public Visibility VisibilityFiltroPersonalizado { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _visibilityFiltroPersonalizado; } set { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) _visibilityFiltroPersonalizado = value; OnPropertyChanged("VisibilityFiltroPersonalizado"); } } public List RelatorioFiltroPersonalizado { get { return _filtroRelatorioPersonalizado; } set { _filtroRelatorioPersonalizado = value; OnPropertyChanged("RelatorioFiltroPersonalizado"); } } public FiltroPersonalizado FiltroPersonalizado { get { return _filtroPersonalizado; } set { _filtroPersonalizado = value; VisibilitySemValor = (Visibility)((value == null) ? 2 : 0); OnPropertyChanged("FiltroPersonalizado"); if (value == null) { return; } string name = value.Tipo.Name; if (name == null) { return; } switch (name.Length) { default: return; case 4: { char c = name[0]; if (c != 'E') { if (c != 'l' || !(name == "long")) { return; } break; } if (!(name == "Enum")) { return; } goto IL_0121; } case 5: switch (name[3]) { default: return; case '3': if (!(name == "int32")) { return; } break; case '6': if (!(name == "int64")) { return; } break; } break; case 6: if (name == "String") { ValorInicial = ""; ValorFinal = ""; } return; case 7: if (name == "Decimal") { ValorInicial = "0,00"; ValorFinal = "0,00"; } return; case 8: if (!(name == "DateTime")) { return; } goto IL_0121; case 3: { if (!(name == "int")) { return; } break; } IL_0121: ValorInicial = null; ValorFinal = null; return; } ValorInicial = "0"; ValorFinal = "0"; } } public Type TipoString { get { return _tipoString; } set { _tipoString = value; OnPropertyChanged("TipoString"); } } public Type TipoEnum { get { return _tipoEnum; } set { _tipoEnum = value; OnPropertyChanged("TipoEnum"); } } public Type TipoDateTime { get { return _tipoDateTime; } set { _tipoDateTime = value; OnPropertyChanged("TipoDateTime"); } } public Type TipoDecimal { get { return _tipoDecimal; } set { _tipoDecimal = value; OnPropertyChanged("TipoDecimal"); } } public Type TipoInt { get { return _tipoInt; } set { _tipoInt = value; OnPropertyChanged("TipoInt"); } } public Type TipoLong { get { return _tipoLong; } set { _tipoLong = value; OnPropertyChanged("TipoLong"); } } public string ValorInicial { get { return _valorIncial; } set { _valorIncial = value; OnPropertyChanged("ValorInicial"); } } public string ValorFinal { get { return _valorFinal; } set { _valorFinal = value; OnPropertyChanged("ValorFinal"); } } public bool SemValor { get { return _semValor; } set { _semValor = value; if (value) { ValorInicial = null; ValorFinal = null; } OnPropertyChanged("SemValor"); } } public Visibility VisibilitySemValor { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _visibilitySemValor; } set { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) _visibilitySemValor = value; OnPropertyChanged("VisibilitySemValor"); } } public ObservableCollection FiltroPersonalizadoSelecionado { get { return _filtroPersonalizadoSelecionado; } set { _filtroPersonalizadoSelecionado = value; OnPropertyChanged("FiltroPersonalizadoSelecionado"); } } public ObservableCollection FiltroRelatorioSelecionado { get { return _filtroRelatorioSelecionado; } set { _filtroRelatorioSelecionado = value; OnPropertyChanged("FiltroRelatorioSelecionado"); } } public ObservableCollection Vendedores { get { return _vendedores; } set { _vendedores = value; SelectedVendedor = SelectedVendedor ?? value.FirstOrDefault(); OnPropertyChanged("Vendedores"); } } public Vendedor SelectedVendedor { get { return _selectedVendedor; } set { _selectedVendedor = value; OnPropertyChanged("SelectedVendedor"); } } public bool EnableExcluirManutPagamento { get { return _enableExcluirManutPagamento; } set { _enableExcluirManutPagamento = value; OnPropertyChanged("EnableExcluirManutPagamento"); } } public ObservableCollection Pagamentos { get { return _pagamentos; } set { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown _pagamentos = value; View = new ListCollectionView((IList)value); ((CollectionView)View).GroupDescriptions.Add((GroupDescription)new PropertyGroupDescription("Pagamento")); ((CollectionView)View).GroupDescriptions.Add((GroupDescription)new PropertyGroupDescription("Vendedor")); OnPropertyChanged("Pagamentos"); } } public ListCollectionView View { get { return _view; } set { _view = value; OnPropertyChanged("View"); } } public bool AllSelected { get { return _allSelected; } set { _allSelected = value; OnPropertyChanged("AllSelected"); Selecionar(value); } } public string SelectedFiltro { get { return _selectedFiltro; } set { _selectedFiltro = value; OnPropertyChanged("SelectedFiltro"); } } public ObservableCollection Filtros { get { return _filtros; } set { _filtros = value; OnPropertyChanged("Filtros"); } } public DateTime? Inicio { get { return _inicio; } set { if (value.HasValue && value.Value < new DateTime(1754, 1, 1)) { value = new DateTime(1754, 1, 1); } if (value.HasValue && value.Value > new DateTime(9999, 12, 31)) { value = new DateTime(9999, 12, 31); } _inicio = value; OnPropertyChanged("Inicio"); } } public DateTime? Fim { get { return _fim; } set { if (value.HasValue && value.Value < new DateTime(1754, 1, 1)) { value = new DateTime(1754, 1, 1); } if (value.HasValue && value.Value > new DateTime(9999, 12, 31)) { value = new DateTime(9999, 12, 31); } _fim = value; OnPropertyChanged("Fim"); } } private List TodosPagamentos { get { return _todosPagamentos; } set { FiltrosPersonalizados = (Visibility)((value == null || !value.Any()) ? 2 : 0); _todosPagamentos = value; } } public ManutencaoPagamentosViewModel() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Expected O, but got Unknown Usuario usuario = Recursos.Usuario; _enableExcluirManutPagamento = usuario != null && ((DomainBase)usuario).Id > 0; _inicio = Funcoes.GetNetworkTime(); _fim = Funcoes.GetNetworkTime().AddDays(7.0); base._002Ector(); Filtros = new ObservableCollection { "DATA DE EMISSÃO DO RECEBIMENTO", "DATA DE EMISSÃO DO RECIBO DE PAGAMENTO" }; SelectedFiltro = Filtros.First(); List list = (from x in Recursos.Vendedores where x.Ativo orderby x.Nome select x).ToList(); list.Insert(0, new Vendedor { Id = 0L, Nome = "TODAS OS VENDEDORES" }); Vendedores = new ObservableCollection(list); RelatorioFiltroPersonalizado = Funcoes.PopularFiltroPersonalizado(); } public void Selecionar(bool value) { if (Pagamentos != null && Pagamentos.Count != 0) { ExtensionMethods.ForEach((IEnumerable)Pagamentos, (Action)delegate(ManutencaoPagamentos x) { x.Selecionado = value; }); } } public async Task Buscar() { if (Inicio.HasValue && Fim.HasValue) { FiltroPersonalizadoSelecionado = null; VisibilityFiltroPersonalizado = (Visibility)0; Filtros val = new Filtros { Inicio = Inicio.Value, Fim = Fim.Value }; if (((DomainBase)SelectedVendedor).Id > 0) { val.Vendedores = new List { ((DomainBase)SelectedVendedor).Id }; } if (!(SelectedFiltro == "DATA DE EMISSÃO DO RECEBIMENTO")) { val.Referencia = "DATA PAGAMENTO"; } else { val.Referencia = "DATA PREVISÃO"; } TodosPagamentos = await new VendedorServico().BuscarPagos(val); Pagamentos = new ObservableCollection(TodosPagamentos); RegistrarAcao("CONSULTOU OS PAGAMENTOS DE \"" + Inicio.Value.ToShortDateString() + "\" A \"" + Fim.Value.ToShortDateString() + "\" POR " + SelectedFiltro, 0L, (TipoTela)58); } } public async Task Excluir() { List selecionados = Pagamentos.Where((ManutencaoPagamentos x) => x.Selecionado).ToList(); if (selecionados.Count == 0) { return; } string log = "PAGAMENTOS EXCLUÍDOS:"; foreach (ManutencaoPagamentos item in selecionados) { log += $"\nID: {item.Id}, NÚMERO: {item.Parcela}, ID DOCUMENTO: {item.IdDocumento}"; VendedorParcela val = await new VendedorServico().BuscarVendedorParcelaCompleto(item.Id); val.DataPagamento = null; await new ParcelaServico().Save(val); } RegistrarAcao(string.Format("EXCLUIU {0} PAGAMENTO{1}", selecionados.Count, (selecionados.Count > 1) ? "S" : ""), 0L, (TipoTela)58, log); for (int num = Pagamentos.Count - 1; num >= 0; num--) { if (Pagamentos[num].Selecionado) { Pagamentos.RemoveAt(num); } } ToggleSnackBar("PAGAMENTOS EXCLUÍDOS COM SUCESSO."); } public async void AdcionarFiltroPersonalizado() { if (FiltroPersonalizado == null) { return; } string descricao; if (!SemValor) { List list = ((FiltroPersonalizadoSelecionado == null) ? new List() : FiltroPersonalizadoSelecionado.Where((FiltroPersonalizado x) => x.Propriedade == FiltroPersonalizado.Propriedade && x.SemValor).ToList()); if (list.Count > 0) { list.ForEach(delegate(FiltroPersonalizado x) { FiltroPersonalizadoSelecionado.Remove(x); }); } switch (FiltroPersonalizado.Tipo.Name) { default: if (string.IsNullOrEmpty(ValorInicial)) { await ShowMessage("O VALOR DEVE SER PREENCHIDO CORRETAMENTE."); return; } descricao = FiltroPersonalizado.Nome + " = " + ValorInicial; break; case "DateTime": { if (!DateTime.TryParse(ValorInicial, out var result3) || !DateTime.TryParse(ValorFinal, out result3) || DateTime.Parse(ValorInicial) > DateTime.Parse(ValorFinal)) { await ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE."); return; } descricao = $"{FiltroPersonalizado.Nome}: {DateTime.Parse(ValorInicial):d} até {DateTime.Parse(ValorFinal):d}"; break; } case "Decimal": { if (!decimal.TryParse(ValorInicial, out var result2) || !decimal.TryParse(ValorFinal, out result2) || Math.Abs(decimal.Parse(ValorInicial)) > Math.Abs(decimal.Parse(ValorFinal))) { await ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE."); return; } descricao = $"{FiltroPersonalizado.Nome}: {decimal.Parse(ValorInicial):n2} até {decimal.Parse(ValorFinal):n2}"; break; } case "Int32": { if (!int.TryParse(ValorInicial, out var result4) || !int.TryParse(ValorFinal, out result4) || int.Parse(ValorInicial) > int.Parse(ValorFinal)) { await ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE."); return; } descricao = $"{FiltroPersonalizado.Nome}: {int.Parse(ValorInicial):n0} até {int.Parse(ValorFinal):n0}"; break; } case "Int64": { if (!long.TryParse(ValorInicial, out var result) || !long.TryParse(ValorFinal, out result) || long.Parse(ValorInicial) > int.Parse(ValorFinal)) { await ShowMessage("O VALOR DE INTERVALO DEVE SER PREENCHIDO CORRETAMENTE."); return; } descricao = $"{FiltroPersonalizado.Nome}: {long.Parse(ValorInicial):n0} até {long.Parse(ValorFinal):n0}"; break; } } } else { List list2 = ((FiltroPersonalizadoSelecionado == null) ? new List() : FiltroPersonalizadoSelecionado.Where((FiltroPersonalizado x) => x.Propriedade == FiltroPersonalizado.Propriedade).ToList()); if (list2.Count > 0) { list2.ForEach(delegate(FiltroPersonalizado x) { FiltroPersonalizadoSelecionado.Remove(x); }); } descricao = FiltroPersonalizado.Nome + ": EM BRANCO"; } if (FiltroPersonalizadoSelecionado == null) { FiltroPersonalizadoSelecionado = new ObservableCollection(); } FiltroPersonalizadoSelecionado.Add(new FiltroPersonalizado { Nome = FiltroPersonalizado.Nome, Propriedade = FiltroPersonalizado.Propriedade, Tipo = FiltroPersonalizado.Tipo, ValorIncial = ValorInicial, ValorFinal = ValorFinal, SemValor = SemValor, Descricao = descricao }); FiltroPersonalizado = null; ValorInicial = string.Empty; ValorFinal = string.Empty; PesquisaPersonalizada(); } public void PesquisaPersonalizada() { Pagamentos = new ObservableCollection(TodosPagamentos.CustomWhere(FiltroPersonalizadoSelecionado.ToList())); } }