diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 15:29:41 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 15:29:41 +0000 |
| commit | 225aa1499e37faf9d38257caabbadc68d78b427e (patch) | |
| tree | 102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.Seguros/CriticaApoliceViewModel.cs | |
| parent | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff) | |
| download | gestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip | |
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Seguros/CriticaApoliceViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels.Seguros/CriticaApoliceViewModel.cs | 1109 |
1 files changed, 1109 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Seguros/CriticaApoliceViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Seguros/CriticaApoliceViewModel.cs new file mode 100644 index 0000000..1bc6e72 --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Seguros/CriticaApoliceViewModel.cs @@ -0,0 +1,1109 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Seguros; +using Gestor.Application.Servicos.Seguros.Itens; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Configuracoes; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.ViewModels.Seguros; + +public class CriticaApoliceViewModel : BaseApoliceViewModel +{ + private readonly CriticaApoliceServico _criticaServico; + + private readonly ClienteServico _clienteServico; + + private readonly ItemServico _itemServico; + + private List<VendedorUsuario> Vinculos; + + private ObservableCollection<Usuario> _usuarios = new ObservableCollection<Usuario>(); + + private ObservableCollection<Seguradora> _seguradorasFiltro = new ObservableCollection<Seguradora>(); + + private string _fieldNascimento = "NASCIMENTO"; + + private bool _isExpanded = true; + + private DateTime _inicio = Funcoes.GetNetworkTime().Date.AddDays(-7.0); + + private DateTime _fim = Funcoes.GetNetworkTime().Date; + + private Usuario _selectedUsuario; + + private Seguradora _selectedSeguradora; + + private bool _criticado; + + private ObservableCollection<CriticaApolice> _criticas = new ObservableCollection<CriticaApolice>(); + + private ObservableCollection<CriticaApolice> _criticaFiltrada = new ObservableCollection<CriticaApolice>(); + + private bool _isCriticaSelected; + + private CriticaApolice _selectedCritica; + + private bool _hasChange; + + private bool _isParcela; + + private DateTime? _emissaoCritica; + + private DateTime? _transmissaoCritica; + + private DateTime? _nascimentoCritica; + + private TipoSeguro? _situacao; + + private Cliente _selectedCliente; + + private string _documentoPrincipal; + + private Visibility _visibilityFisica = (Visibility)2; + + private ObservableCollection<ClienteTelefone> _telefones = new ObservableCollection<ClienteTelefone>(); + + private ObservableCollection<ClienteEmail> _emails = new ObservableCollection<ClienteEmail>(); + + private ObservableCollection<Item> _itens = new ObservableCollection<Item>(); + + private bool _enableGrid = true; + + private string _pesquisa = ""; + + private ObservableCollection<string> _pesquisaCritica = new ObservableCollection<string>(); + + private string _profissaoText; + + private string _atividadeText; + + private Visibility _visibilityJuridica = (Visibility)2; + + private string _fieldDocumento = "CPF"; + + private Visibility _valorComissao; + + public ObservableCollection<Usuario> Usuarios + { + get + { + return _usuarios; + } + set + { + _usuarios = value; + SelectedUsuario = SelectedUsuario ?? value.FirstOrDefault(); + OnPropertyChanged("Usuarios"); + } + } + + public ObservableCollection<Seguradora> SeguradorasFiltro + { + get + { + return _seguradorasFiltro; + } + set + { + _seguradorasFiltro = value; + SelectedSeguradora = SelectedSeguradora ?? value.FirstOrDefault(); + OnPropertyChanged("SeguradorasFiltro"); + } + } + + public string FieldNascimento + { + get + { + return _fieldNascimento; + } + set + { + _fieldNascimento = value; + OnPropertyChanged("FieldNascimento"); + } + } + + public bool IsExpanded + { + get + { + return _isExpanded; + } + set + { + _isExpanded = value; + OnPropertyChanged("IsExpanded"); + } + } + + public DateTime Inicio + { + get + { + return _inicio; + } + set + { + _inicio = value; + OnPropertyChanged("Inicio"); + } + } + + public DateTime Fim + { + get + { + return _fim; + } + set + { + _fim = value; + OnPropertyChanged("Fim"); + } + } + + public Usuario SelectedUsuario + { + get + { + return _selectedUsuario; + } + set + { + _selectedUsuario = value; + OnPropertyChanged("SelectedUsuario"); + } + } + + public Seguradora SelectedSeguradora + { + get + { + return _selectedSeguradora; + } + set + { + _selectedSeguradora = value; + OnPropertyChanged("SelectedSeguradora"); + } + } + + public bool Criticado + { + get + { + return _criticado; + } + set + { + _criticado = value; + OnPropertyChanged("Criticado"); + } + } + + public ObservableCollection<CriticaApolice> Criticas + { + get + { + return _criticas; + } + set + { + _criticas = value; + OnPropertyChanged("Criticas"); + } + } + + public ObservableCollection<CriticaApolice> CriticaFiltrada + { + get + { + return _criticaFiltrada; + } + set + { + _criticaFiltrada = value; + OnPropertyChanged("CriticaFiltrada"); + } + } + + public bool IsCriticaSelected + { + get + { + return _isCriticaSelected; + } + set + { + _isCriticaSelected = value; + OnPropertyChanged("IsCriticaSelected"); + } + } + + public CriticaApolice SelectedCritica + { + get + { + return _selectedCritica; + } + set + { + _selectedCritica = value; + IsCriticaSelected = value != null; + OnPropertyChanged("SelectedCritica"); + } + } + + public bool HasChange + { + get + { + return _hasChange; + } + set + { + _hasChange = value; + OnPropertyChanged("HasChange"); + } + } + + public bool IsParcela + { + get + { + return _isParcela; + } + set + { + _isParcela = value; + OnPropertyChanged("IsParcela"); + } + } + + public DateTime? EmissaoCritica + { + get + { + return _emissaoCritica; + } + set + { + _emissaoCritica = value; + OnPropertyChanged("EmissaoCritica"); + } + } + + public DateTime? TransmissaoCritica + { + get + { + return _transmissaoCritica; + } + set + { + _transmissaoCritica = value; + OnPropertyChanged("TransmissaoCritica"); + } + } + + public DateTime? NascimentoCritica + { + get + { + return _nascimentoCritica; + } + set + { + _nascimentoCritica = value; + OnPropertyChanged("NascimentoCritica"); + } + } + + public bool BuscaInicial { get; set; } = true; + + + public bool SeguroCombinado { get; set; } + + public bool IsLoading { get; set; } + + public TipoSeguro? StatusDocumento + { + get + { + return _situacao; + } + set + { + _situacao = value; + OnPropertyChanged("StatusDocumento"); + } + } + + public Cliente SelectedCliente + { + get + { + return _selectedCliente; + } + set + { + _selectedCliente = value; + OnPropertyChanged("SelectedCliente"); + } + } + + public string DocumentoPrincipal + { + get + { + return _documentoPrincipal; + } + set + { + //IL_005e: Unknown result type (might be due to invalid IL or missing references) + //IL_0063: Unknown result type (might be due to invalid IL or missing references) + //IL_0064: Unknown result type (might be due to invalid IL or missing references) + //IL_0066: Invalid comparison between Unknown and I4 + //IL_0068: Unknown result type (might be due to invalid IL or missing references) + //IL_006a: Invalid comparison between Unknown and I4 + if (value == null || ValidationHelper.OnlyNumber(value).Length > 11) + { + VisibilityFisica = (Visibility)2; + FieldNascimento = "FUNDAÇÃO"; + } + else + { + VisibilityFisica = (Visibility)0; + FieldNascimento = "NASCIMENTO"; + } + _documentoPrincipal = value; + if (SelectedCliente != null) + { + TipoDocumento? documentoPrincipal = SelectedCliente.DocumentoPrincipal; + if (!documentoPrincipal.HasValue) + { + goto IL_006c; + } + TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); + if ((int)valueOrDefault != 1) + { + if ((int)valueOrDefault != 2) + { + goto IL_006c; + } + SelectedCliente.Cei = value; + } + else + { + SelectedCliente.Rne = value; + } + } + goto IL_0094; + IL_006c: + SelectedCliente.Documento = value; + goto IL_0094; + IL_0094: + OnPropertyChanged("DocumentoPrincipal"); + } + } + + public Visibility VisibilityFisica + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _visibilityFisica; + } + 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) + _visibilityFisica = value; + OnPropertyChanged("VisibilityFisica"); + } + } + + public ObservableCollection<ClienteTelefone> Telefones + { + get + { + return _telefones; + } + set + { + _telefones = value; + OnPropertyChanged("Telefones"); + } + } + + public ObservableCollection<ClienteEmail> Emails + { + get + { + return _emails; + } + set + { + _emails = value; + OnPropertyChanged("Emails"); + } + } + + public ObservableCollection<Item> Itens + { + get + { + return _itens; + } + set + { + _itens = value; + OnPropertyChanged("Itens"); + } + } + + public int Index { get; set; } = -1; + + + public bool EnableGrid + { + get + { + return _enableGrid; + } + set + { + _enableGrid = value; + OnPropertyChanged("EnableGrid"); + } + } + + public string Pesquisa + { + get + { + return _pesquisa; + } + set + { + _pesquisa = value; + OnPropertyChanged("Pesquisa"); + } + } + + public ObservableCollection<string> PesquisaCritica + { + get + { + return _pesquisaCritica; + } + set + { + _pesquisaCritica = value; + OnPropertyChanged("PesquisaCritica"); + } + } + + public string ProfissaoText + { + get + { + return _profissaoText; + } + set + { + _profissaoText = value; + OnPropertyChanged("ProfissaoText"); + } + } + + public string AtividadeText + { + get + { + return _atividadeText; + } + set + { + _atividadeText = value; + OnPropertyChanged("AtividadeText"); + } + } + + public Visibility VisibilityJuridica + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _visibilityJuridica; + } + 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) + _visibilityJuridica = value; + OnPropertyChanged("VisibilityJuridica"); + } + } + + public string FieldDocumento + { + get + { + return _fieldDocumento; + } + set + { + _fieldDocumento = value; + OnPropertyChanged("FieldDocumento"); + } + } + + public Visibility ValorComissao + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _valorComissao; + } + 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) + _valorComissao = value; + OnPropertyChanged("ValorComissao"); + } + } + + public CriticaApoliceViewModel() + { + //IL_007e: Unknown result type (might be due to invalid IL or missing references) + //IL_00ca: Unknown result type (might be due to invalid IL or missing references) + base.Invoke = false; + _criticaServico = new CriticaApoliceServico(); + _clienteServico = new ClienteServico(); + _itemServico = new ItemServico(); + } + + public async Task InitialLoad() + { + IsLoading = true; + Loading(isLoading: true); + await PermissaoTela((TipoTela)2); + await SelecionaUsuario(); + await CarregarUsuarios(0L); + await CarregarSeguradoras(); + CriticaApoliceViewModel criticaApoliceViewModel = this; + Usuario selectedUsuario = SelectedUsuario; + await criticaApoliceViewModel.CarregaCritica((selectedUsuario != null) ? ((DomainBase)selectedUsuario).Id : 0, 0L); + Loading(isLoading: false); + IsLoading = false; + } + + public async Task SelecionaUsuario() + { + IsLoading = true; + if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 38 || (int)x.Configuracao == 43) && ((DomainBase)Recursos.Usuario).Id != 0L) + { + Vinculos = await VerificaVinculoVendedor(Recursos.Usuario); + } + IsLoading = false; + } + + public async Task CarregarUsuarios(long selected = 0L, bool criticado = false) + { + IsLoading = true; + Criticado = criticado; + List<Usuario> list = new List<Usuario>(); + List<VendedorUsuario> vinculos = Vinculos; + if (vinculos != null && vinculos.Count > 0) + { + list.Insert(0, new Usuario + { + Id = ((DomainBase)Recursos.Usuario).Id, + Nome = Recursos.Usuario.Nome + }); + } + else + { + list = await _criticaServico.BuscarUsuarioCritica(Inicio, Fim, Criticado); + list.Insert(0, new Usuario + { + Id = 0L, + Nome = "TODOS OS USUÁRIOS" + }); + } + Usuarios = new ObservableCollection<Usuario>(list); + SelectedUsuario = ((IEnumerable<Usuario>)Usuarios).FirstOrDefault((Func<Usuario, bool>)((Usuario x) => ((DomainBase)x).Id == selected)) ?? Usuarios.FirstOrDefault(); + IsLoading = false; + } + + public async Task CarregarSeguradoras() + { + IsLoading = true; + List<Seguradora> list = (await _criticaServico.BuscarSeguradorasAsync()).OrderBy((Seguradora x) => x.Nome).ToList(); + list.Insert(0, new Seguradora + { + Id = 0L, + Nome = "TODAS AS SEGURADORAS", + Ativo = true + }); + SeguradorasFiltro = new ObservableCollection<Seguradora>(list.Where((Seguradora x) => x.Ativo)); + SelectedSeguradora = SeguradorasFiltro.FirstOrDefault(); + IsLoading = false; + } + + public async Task CarregaCritica(long usuario, long seguradora, bool criticado = false) + { + if (!IsLoading || BuscaInicial) + { + BuscaInicial = false; + EnableGrid = false; + Loading(isLoading: true); + Criticado = criticado; + await CarregarUsuarios(usuario, Criticado); + Criticas = new ObservableCollection<CriticaApolice>(from x in await _criticaServico.BuscarCritica(usuario, Inicio, Fim, 0L, Criticado, Vinculos) + where (usuario == 0L || ((DomainBase)x.UsuarioImportacao).Id == usuario) && (seguradora == 0L || ((DomainBase)x.Documento.Controle.Seguradora).Id == seguradora) + orderby x.DataImportacao, x.Documento.Controle.Cliente.Nome descending + select x); + CriticaFiltrada = Criticas; + if (CriticaFiltrada != null && CriticaFiltrada.Count > 0) + { + await SelecionaCritica(CriticaFiltrada.First()); + } + else + { + IsCriticaSelected = false; + } + CriticaApoliceViewModel criticaApoliceViewModel = this; + ObservableCollection<CriticaApolice> criticaFiltrada = CriticaFiltrada; + criticaApoliceViewModel.IsExpanded = criticaFiltrada != null && criticaFiltrada.Count > 0; + Loading(isLoading: false); + Usuario val = Usuarios?.FirstOrDefault((Func<Usuario, bool>)((Usuario x) => ((DomainBase)x).Id == usuario)); + Seguradora val2 = base.Seguradoras?.FirstOrDefault((Func<Seguradora, bool>)((Seguradora x) => ((DomainBase)x).Id == seguradora)); + RegistrarAcao($"CONSULTOU CRÍTICAS NO PERÍODO ENTRE {Inicio:d} E {Fim:d}", 0L, (TipoTela)20, (PesquisaCritica != null && PesquisaCritica.Count > 0) ? string.Format("USUÁRIO IMPORTAÇÃO: {0} ({1})\nSEGURADORA: {2} ({3})\nCRITICADOS: {4}\nPESQUISA PERSONALIZADA: \"{5}\"", ((val != null) ? val.Nome : null) ?? "TODOS USUÁRIOS", (val != null) ? ((DomainBase)val).Id : 0, ((val2 != null) ? val2.Nome : null) ?? "TODAS AS SEGURADORAS", (val2 != null) ? ((DomainBase)val2).Id : 0, Criticado ? "SIM" : "NÃO", ValidationHelper.Join((IEnumerable<string>)PesquisaCritica, ", ")) : string.Format("USUÁRIO IMPORTAÇÃO: {0} ({1})\nSEGURADORA: {2} ({3})\nCRITICADOS: {4}", ((val != null) ? val.Nome : null) ?? "TODOS USUÁRIOS", (val != null) ? ((DomainBase)val).Id : 0, ((val2 != null) ? val2.Nome : null) ?? "TODAS AS SEGURADORAS", (val2 != null) ? ((DomainBase)val2).Id : 0, Criticado ? "SIM" : "NÃO")); + EnableGrid = true; + } + } + + public async Task SelecionaCritica(CriticaApolice critica) + { + if (critica != null && !IsLoading) + { + IsLoading = true; + Loading(isLoading: true); + critica.Documento = await Servico.BuscarApoliceAsync(((DomainBase)critica.Documento).Id); + base.SelectedDocumento = null; + base.Repasses = null; + base.Parcelas = null; + base.Pagamentos = null; + base.SelectedParcela = null; + base.SelectedPagamento = null; + SelectedCritica = critica; + await SelecionaDocumento(critica.Documento); + EmissaoCritica = ((critica.Documento != null && critica.Documento.Emissao.HasValue) ? critica.Documento.Emissao : new DateTime?(Funcoes.GetNetworkTime().Date)); + TransmissaoCritica = ((critica.Documento != null && critica.Documento.Remessa.HasValue) ? critica.Documento.Remessa : new DateTime?(Funcoes.GetNetworkTime().Date)); + StatusDocumento = (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 3) ? new TipoSeguro?(base.SelectedDocumento.Situacao) : null); + if (base.SelectedDocumento == null) + { + IsParcela = true; + HasChange = false; + Loading(isLoading: false); + return; + } + IsParcela = (int)base.SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1; + await SelecionaCliente(base.SelectedDocumento.Controle.Cliente); + await SelecionaItens(((DomainBase)base.SelectedDocumento.Controle).Id); + HasChange = false; + Loading(isLoading: false); + IsLoading = false; + } + } + + public async Task SelecionaItens(long id) + { + Itens = await _itemServico.BuscarItens(id, (StatusItem)0); + } + + public async Task SelecionaCliente(Cliente cliente) + { + TipoDocumento? documentoPrincipal = cliente.DocumentoPrincipal; + if (!documentoPrincipal.HasValue) + { + goto IL_0040; + } + TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); + if ((int)valueOrDefault != 1) + { + if ((int)valueOrDefault != 2) + { + goto IL_0040; + } + DocumentoPrincipal = cliente.Cei; + } + else + { + DocumentoPrincipal = cliente.Rne; + } + goto IL_0088; + IL_0088: + NascimentoCritica = ((cliente != null && cliente.Nascimento.HasValue) ? cliente.Nascimento : new DateTime?(Funcoes.GetNetworkTime().Date)); + SelectedCliente = cliente; + ((DomainBase)SelectedCliente).Initialize(); + Telefones = await _clienteServico.BuscarTelefonesAsync(((DomainBase)SelectedCliente).Id); + if (Telefones.Count == 0) + { + Telefones.Add(new ClienteTelefone + { + Cliente = SelectedCliente + }); + } + Telefones.ToList().ForEach(delegate(ClienteTelefone x) + { + ((DomainBase)x).Initialize(); + }); + Emails = await _clienteServico.BuscarEmailsAsync(((DomainBase)SelectedCliente).Id); + if (Emails.Count == 0) + { + Emails.Add(new ClienteEmail + { + Cliente = SelectedCliente + }); + } + Emails.ToList().ForEach(delegate(ClienteEmail x) + { + ((DomainBase)x).Initialize(); + }); + return; + IL_0040: + DocumentoPrincipal = cliente.Documento; + cliente.DocumentoPrincipal = (TipoDocumento)0; + goto IL_0088; + } + + public async Task ConcluirCritica() + { + DateTime now = Funcoes.GetNetworkTime(); + SelectedCritica.Critica = true; + SelectedCritica.DataCritica = now; + SelectedCritica.UsuarioCritica = ((DomainBase)Recursos.Usuario).Id; + foreach (CriticaApolice item2 in await _criticaServico.BuscarCritica(((DomainBase)SelectedCritica.Documento).Id)) + { + item2.Critica = true; + item2.DataCritica = now; + item2.UsuarioCritica = ((DomainBase)Recursos.Usuario).Id; + await _criticaServico.Save(item2); + } + if (SeguroCombinado) + { + List<CriticaApolice> list = (await _criticaServico.BuscarSeguroCombinado(((DomainBase)SelectedCritica.Documento.Controle.Cliente).Id, SelectedCritica.Documento.Vigencia1)).Where(delegate(CriticaApolice duo) + { + if (((DomainBase)duo.Documento.Controle.Seguradora).Id == ((DomainBase)SelectedCritica.Documento.Controle.Seguradora).Id && ((DomainBase)duo.Documento.Controle.Cliente).Id == ((DomainBase)SelectedCritica.Documento.Controle.Cliente).Id && duo.Documento.Vigencia1 == SelectedCritica.Documento.Vigencia1) + { + DateTime? vigencia = duo.Documento.Vigencia2; + DateTime? vigencia2 = SelectedCritica.Documento.Vigencia2; + if (vigencia.HasValue == vigencia2.HasValue && (!vigencia.HasValue || vigencia.GetValueOrDefault() == vigencia2.GetValueOrDefault()) && ((DomainBase)duo.Documento).Id != ((DomainBase)SelectedCritica.Documento).Id && duo.Documento.Apolice == SelectedCritica.Documento.Apolice && duo.Documento.Proposta == null) + { + return true; + } + } + return Regex.Replace(duo.Documento.Proposta, "[^.'-,/]", "") == Regex.Replace(SelectedCritica.Documento.Proposta, "[^.'-,/]", ""); + }).ToList(); + List<CriticaApolice> list2 = ((list == null || list.Count() <= 0) ? null : (await _criticaServico.BuscarCritica(((DomainBase)list.FirstOrDefault().Documento).Id))); + list = list2; + if (list != null && list.Any()) + { + foreach (CriticaApolice seguroduo in list) + { + seguroduo.Critica = true; + seguroduo.DataCritica = now; + seguroduo.Documento.PremioLiquido = 0.01m; + seguroduo.Documento.PremioTotal = 0.01m; + seguroduo.Documento.Comissao = 0.01m; + seguroduo.UsuarioCritica = ((DomainBase)Recursos.Usuario).Id; + await _criticaServico.Save(seguroduo); + await Servico.Save(seguroduo.Documento, updateParcelas: false, criarParcelas: false); + } + } + } + string text = ((SelectedCritica.Tipo == "0") ? ("A PROPOSTA \"" + CancelDocumento.Proposta + "\"") : ((SelectedCritica.Tipo == "1") ? ("A APÓLICE \"" + CancelDocumento.Apolice + "\"") : ("O ENDOSSO \"" + CancelDocumento.Endosso + "\""))); + RegistrarAcao("CONCLUIU A CRÍTICA D" + text, ((DomainBase)SelectedCritica).Id, (TipoTela)20); + object obj2; + if (Itens != null) + { + if (Itens.Count <= 1) + { + Item? obj = Itens.FirstOrDefault(); + obj2 = ((obj != null) ? obj.Descricao : null); + } + else + { + obj2 = "APÓLICE COLETIVA"; + } + } + else + { + obj2 = ""; + } + string item = (string)obj2; + try + { + if (string.IsNullOrEmpty(base.SelectedDocumento.Controle.AssistenciaId)) + { + await CreateLinkAssistencia(base.SelectedDocumento, item, retorno: false); + } + } + catch (Exception) + { + } + base.SelectedDocumento = null; + SelectedCliente = null; + Telefones = null; + Emails = null; + Itens = null; + await CarregaCritica(((DomainBase)SelectedUsuario).Id, ((DomainBase)SelectedSeguradora).Id, Criticado); + } + + public async void ExcluirTelefone(ClienteTelefone telefone) + { + if (Telefones.Count < 2) + { + await ShowMessage("É NECESSÁRIO TER AO MENOS UM TELEFONE CADASTRADO."); + return; + } + HasChange = true; + bool num = telefone.Ordem != Telefones.Count; + int quantidate = Telefones.Count; + Telefones.Remove(telefone); + if (num && ((IEnumerable<ClienteTelefone>)Telefones).FirstOrDefault((Func<ClienteTelefone, bool>)((ClienteTelefone x) => x.Ordem == quantidate)) != null) + { + Telefones.First((ClienteTelefone x) => x.Ordem == quantidate).Ordem = telefone.Ordem; + Telefones = new ObservableCollection<ClienteTelefone>(Telefones.OrderBy((ClienteTelefone x) => x.Ordem)); + } + } + + public async void ExcluirEmail(ClienteEmail email) + { + if (Emails.Count < 2) + { + await ShowMessage("É NECESSÁRIO TER AO MENOS UM CONTATO DE E-MAIL CADASTRADO."); + return; + } + HasChange = true; + bool num = email.Ordem != Emails.Count; + int quantidate = Emails.Count; + Emails.Remove(email); + if (num && ((IEnumerable<ClienteEmail>)Emails).FirstOrDefault((Func<ClienteEmail, bool>)((ClienteEmail x) => x.Ordem == quantidate)) != null) + { + Emails.First((ClienteEmail x) => x.Ordem == quantidate).Ordem = email.Ordem; + Emails = new ObservableCollection<ClienteEmail>(Emails.OrderBy((ClienteEmail x) => x.Ordem)); + } + } + + public async Task<List<KeyValuePair<string, string>>> SalvarCliente() + { + if (!HasChange && !((DomainBase)SelectedCliente).HasChange() && Telefones.All((ClienteTelefone x) => !((DomainBase)x).HasChange()) && Emails.All((ClienteEmail x) => !((DomainBase)x).HasChange())) + { + return null; + } + List<ClienteTelefone> list = Telefones.Where((ClienteTelefone x) => !string.IsNullOrEmpty(((TelefoneBase)x).Numero)).ToList(); + List<ClienteEmail> list2 = Emails.Where((ClienteEmail x) => !string.IsNullOrEmpty(((EmailBase)x).Email)).ToList(); + SelectedCliente.Telefones = new ObservableCollection<ClienteTelefone>(list); + SelectedCliente.Emails = new ObservableCollection<ClienteEmail>(list2); + TipoDocumento? documentoPrincipal = SelectedCliente.DocumentoPrincipal; + if (!documentoPrincipal.HasValue) + { + goto IL_0147; + } + TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); + if ((int)valueOrDefault != 1) + { + if ((int)valueOrDefault != 2) + { + goto IL_0147; + } + SelectedCliente.Cei = DocumentoPrincipal; + } + else + { + SelectedCliente.Rne = DocumentoPrincipal; + } + goto IL_017e; + IL_017e: + List<KeyValuePair<string, string>> errorMessages = SelectedCliente.Validate(); + list.ForEach(delegate(ClienteTelefone x) + { + errorMessages.AddRange(x.Validate()); + }); + list2.ForEach(delegate(ClienteEmail x) + { + errorMessages.AddRange(x.Validate()); + }); + List<KeyValuePair<string, string>> list3 = errorMessages; + list3.AddRange(await Validate()); + if (errorMessages.Count > 0) + { + return errorMessages; + } + await _clienteServico.Save(SelectedCliente); + return null; + IL_0147: + SelectedCliente.Documento = DocumentoPrincipal; + goto IL_017e; + } + + private async Task<List<KeyValuePair<string, string>>> Validate() + { + List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>(); + bool valida = !string.IsNullOrEmpty(SelectedCliente.Nome); + switch (SelectedCliente.DocumentoPrincipal) + { + case 0L: + if (!ValidationHelper.ValidateDocument(SelectedCliente.Documento)) + { + valida = false; + } + break; + case 1L: + if (!ValidationHelper.ValidateRne(SelectedCliente.Rne)) + { + valida = false; + } + break; + case 2L: + if (!ValidationHelper.ValidateCei(SelectedCliente.Cei)) + { + valida = false; + } + break; + } + List<Cliente> list = ((!ValidationHelper.ValidateDocument(SelectedCliente.Documento)) ? new List<Cliente>() : (await new ClienteServico().BuscarClientePorDocumento(SelectedCliente.Documento))); + List<Cliente> list2 = list; + string nome = ""; + if (list2.Count > 0) + { + list2.ForEach(delegate(Cliente x) + { + if (((DomainBase)x).Id != ((DomainBase)SelectedCliente).Id && SelectedCliente.IdEmpresa == x.IdEmpresa && !string.IsNullOrEmpty(SelectedCliente.Documento) && x.Documento == SelectedCliente.Documento) + { + valida = false; + nome = x.Nome; + } + }); + } + if (!valida) + { + errors.Add(new KeyValuePair<string, string>("Documento", "O DOCUMENTO JÁ ESTÁ CADASTRADO PARA O CLIENTE " + nome + ".")); + } + if (SelectedCliente.Telefones == null || SelectedCliente.Telefones.Count == 0) + { + errors.Add(new KeyValuePair<string, string>("Telefones", "NECESSITA-SE AO MENOS UM TELEFONE VÁLIDO.")); + } + if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 29) && (SelectedCliente.Emails == null || SelectedCliente.Emails.Count == 0)) + { + errors.Add(new KeyValuePair<string, string>("Emails", "NECESSITA-SE AO MENOS UM E-MAIL VÁLIDO.")); + } + return errors; + } + + public void AlteraDocumentoPrincipal() + { + //IL_0020: Unknown result type (might be due to invalid IL or missing references) + //IL_0025: Unknown result type (might be due to invalid IL or missing references) + //IL_0026: Unknown result type (might be due to invalid IL or missing references) + //IL_0028: Invalid comparison between Unknown and I4 + //IL_002a: Unknown result type (might be due to invalid IL or missing references) + //IL_002c: Invalid comparison between Unknown and I4 + if (SelectedCliente == null) + { + return; + } + TipoDocumento? documentoPrincipal = SelectedCliente.DocumentoPrincipal; + if (documentoPrincipal.HasValue) + { + TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); + if ((int)valueOrDefault == 1) + { + DocumentoPrincipal = SelectedCliente.Rne; + return; + } + if ((int)valueOrDefault == 2) + { + DocumentoPrincipal = SelectedCliente.Cei; + return; + } + } + DocumentoPrincipal = SelectedCliente.Documento; + SelectedCliente.DocumentoPrincipal = (TipoDocumento)0; + } + + public void AdcionarFiltro() + { + if (!string.IsNullOrEmpty(Pesquisa) && !string.IsNullOrWhiteSpace(Pesquisa.Replace("+", ""))) + { + if (PesquisaCritica == null) + { + PesquisaCritica = new ObservableCollection<string>(); + } + PesquisaCritica.Add(Pesquisa); + Pesquisa = string.Empty; + Pesquisar(); + } + } + + public async void Pesquisar() + { + EnableGrid = false; + if (PesquisaCritica == null || PesquisaCritica.Count == 0) + { + CriticaFiltrada = new ObservableCollection<CriticaApolice>(Criticas); + } + else + { + CriticaFiltrada = new ObservableCollection<CriticaApolice>(from x in Criticas + where PesquisaCritica.All((string s) => (from f in s.Split(new char[1] { '+' }).ToList() + where !string.IsNullOrWhiteSpace(f) + select f).Any((string f) => ValidationHelper.RemoveDiacritics(x.Documento.Controle.Cliente.Nome).ToUpper().Contains(ValidationHelper.RemoveDiacritics(f)) || (x.Documento.Controle.Cliente.Documento != null && x.Documento.Controle.Cliente.Documento.Contains(f)) || (x.Documento.Controle.Cliente.Cei != null && x.Documento.Controle.Cliente.Cei.Contains(f)) || (x.Documento.Controle.Cliente.Rne != null && x.Documento.Controle.Cliente.Rne.Contains(f)) || (x.UsuarioImportacao != null && x.UsuarioImportacao.Nome.Contains(f)) || (x.DataImportacao.HasValue && x.DataImportacao.ToString().Contains(f)) || (x.Documento.Apolice != null && x.Documento.Apolice.ToUpper().Contains(f.ToUpper())) || (x.Documento.Proposta != null && x.Documento.Proposta.ToUpper().Contains(f.ToUpper())))) + orderby x.DataImportacao, x.Documento.Controle.Cliente.Nome descending + select x); + } + await SelecionaCritica(CriticaFiltrada.FirstOrDefault()); + EnableGrid = true; + } + + public void JuridicaouFisica(string documento) + { + if (SelectedCliente != null) + { + ProfissaoText = ""; + AtividadeText = ""; + if (documento == null || ValidationHelper.OnlyNumber(documento).Length > 11) + { + VisibilityJuridica = (Visibility)0; + VisibilityFisica = (Visibility)2; + FieldNascimento = "FUNDAÇÃO"; + FieldDocumento = "CNPJ"; + SelectedCliente.Profissao = null; + } + else + { + VisibilityJuridica = (Visibility)2; + VisibilityFisica = (Visibility)0; + FieldNascimento = "NASCIMENTO"; + FieldDocumento = "CPF"; + SelectedCliente.Atividade = null; + } + } + } +} |