summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs925
1 files changed, 925 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs b/Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs
new file mode 100644
index 0000000..be683d2
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs
@@ -0,0 +1,925 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Seguros;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Configuracoes;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Relatorios;
+using Gestor.Model.Domain.Relatorios.ClientesAtivosInativos;
+using Gestor.Model.Domain.Relatorios.Dashboard;
+using Gestor.Model.Domain.Relatorios.Renovacao;
+using Gestor.Model.Domain.Seguros;
+
+namespace Gestor.Application.ViewModels;
+
+public class DashboardViewModel : BaseSegurosViewModel
+{
+ private readonly TarefaServico _servico;
+
+ private readonly ApoliceServico _apoliceServico;
+
+ private readonly ClienteServico _clienteServico;
+
+ private readonly SinistroServico _sinitrosServico;
+
+ private readonly TarefaServico _tarefaServico;
+
+ private bool _renovacoesEnabled;
+
+ private bool _tarefasEnabled;
+
+ private bool _aniversariantesEnabled;
+
+ private bool _sinistrosEnabled;
+
+ private bool _prospeccoesEnabled;
+
+ private bool _notasEnabled;
+
+ private bool _publica;
+
+ private string _quantidadeRenovacoes = "0";
+
+ private string _quantidadeAniversariantes = "0";
+
+ private string _quantidadeProspeccao = "0";
+
+ private string _quantidadeSinisto = "0";
+
+ private string _quantidadeTarefas = "0";
+
+ private List<string> _intervalo = new List<string> { "HOJE", "PRÓXIMOS 3 DIAS", "PRÓXIMOS 7 DIAS" };
+
+ private string _intervaloSelecionado = "HOJE";
+
+ private bool _isProspectar;
+
+ private ObservableCollection<Tarefa> _notas;
+
+ private ObservableCollection<ClienteTelefone> _telefones = new ObservableCollection<ClienteTelefone>();
+
+ private string _anotacoes = "";
+
+ private ObservableCollection<Prospectar> _prospeccoes;
+
+ private ObservableCollection<ClientesAtivosInativos> _aniversariantes;
+
+ private ObservableCollection<Sinistro> _sinistros;
+
+ private ObservableCollection<Renovacao> _renovacaoFiltrado;
+
+ private ObservableCollection<Tarefa> _tarefas = new ObservableCollection<Tarefa>();
+
+ private List<Ramo> _ramos;
+
+ private Ramo _selectedRamo;
+
+ private List<string> _referencias = new List<string> { "VENCIMENTO DA ÚLTIMA PARCELA", "VIGÊNCIA INICIAL", "VIGÊNCIA FINAL" };
+
+ private string _referencia = "VENCIMENTO DA ÚLTIMA PARCELA";
+
+ private int _selectedTile = 1;
+
+ private string _labelProspeccao;
+
+ private List<string> _filtroCliente = new List<string> { "AMBOS", "CNPJ", "CPF" };
+
+ private string _filtroClientes;
+
+ public bool RenovacoesEnabled
+ {
+ get
+ {
+ return _renovacoesEnabled;
+ }
+ set
+ {
+ _renovacoesEnabled = value;
+ OnPropertyChanged("RenovacoesEnabled");
+ }
+ }
+
+ public bool TarefasEnabled
+ {
+ get
+ {
+ return _tarefasEnabled;
+ }
+ set
+ {
+ _tarefasEnabled = value;
+ OnPropertyChanged("TarefasEnabled");
+ }
+ }
+
+ public bool AniversariantesEnabled
+ {
+ get
+ {
+ return _aniversariantesEnabled;
+ }
+ set
+ {
+ _aniversariantesEnabled = value;
+ OnPropertyChanged("AniversariantesEnabled");
+ }
+ }
+
+ public bool SinistrosEnabled
+ {
+ get
+ {
+ return _sinistrosEnabled;
+ }
+ set
+ {
+ _sinistrosEnabled = value;
+ OnPropertyChanged("SinistrosEnabled");
+ }
+ }
+
+ public bool ProspeccoesEnabled
+ {
+ get
+ {
+ return _prospeccoesEnabled;
+ }
+ set
+ {
+ _prospeccoesEnabled = value;
+ OnPropertyChanged("ProspeccoesEnabled");
+ }
+ }
+
+ public bool NotasEnabled
+ {
+ get
+ {
+ return _notasEnabled;
+ }
+ set
+ {
+ _notasEnabled = value;
+ OnPropertyChanged("NotasEnabled");
+ }
+ }
+
+ public bool Load { get; set; } = true;
+
+
+ public int SelectedTile
+ {
+ get
+ {
+ return _selectedTile;
+ }
+ set
+ {
+ _selectedTile = value;
+ IsProspectar = value == 4 || value == 5;
+ }
+ }
+
+ public bool Publica
+ {
+ get
+ {
+ return _publica;
+ }
+ set
+ {
+ _publica = value;
+ OnPropertyChanged("Publica");
+ }
+ }
+
+ public string QuantidadeRenovacoes
+ {
+ get
+ {
+ return _quantidadeRenovacoes;
+ }
+ set
+ {
+ _quantidadeRenovacoes = value;
+ OnPropertyChanged("QuantidadeRenovacoes");
+ }
+ }
+
+ public string QuantidadeAniversariantes
+ {
+ get
+ {
+ return _quantidadeAniversariantes;
+ }
+ set
+ {
+ _quantidadeAniversariantes = value;
+ OnPropertyChanged("QuantidadeAniversariantes");
+ }
+ }
+
+ public string QuantidadeProspeccao
+ {
+ get
+ {
+ return _quantidadeProspeccao;
+ }
+ set
+ {
+ _quantidadeProspeccao = value;
+ OnPropertyChanged("QuantidadeProspeccao");
+ }
+ }
+
+ public string QuantidadeSinistro
+ {
+ get
+ {
+ return _quantidadeSinisto;
+ }
+ set
+ {
+ _quantidadeSinisto = value;
+ OnPropertyChanged("QuantidadeSinistro");
+ }
+ }
+
+ public string QuantidadeTarefas
+ {
+ get
+ {
+ return _quantidadeTarefas;
+ }
+ set
+ {
+ _quantidadeTarefas = value;
+ OnPropertyChanged("QuantidadeTarefas");
+ }
+ }
+
+ public List<string> Intervalo
+ {
+ get
+ {
+ return _intervalo;
+ }
+ set
+ {
+ _intervalo = value;
+ OnPropertyChanged("Intervalo");
+ }
+ }
+
+ public string IntervaloSelecionado
+ {
+ get
+ {
+ return _intervaloSelecionado;
+ }
+ set
+ {
+ _intervaloSelecionado = value;
+ OnPropertyChanged("IntervaloSelecionado");
+ }
+ }
+
+ public bool IsProspectar
+ {
+ get
+ {
+ return _isProspectar;
+ }
+ set
+ {
+ _isProspectar = value;
+ OnPropertyChanged("IsProspectar");
+ }
+ }
+
+ public ObservableCollection<Tarefa> Notas
+ {
+ get
+ {
+ return _notas;
+ }
+ set
+ {
+ _notas = value;
+ OnPropertyChanged("Notas");
+ }
+ }
+
+ public ObservableCollection<ClienteTelefone> Telefones
+ {
+ get
+ {
+ return _telefones;
+ }
+ set
+ {
+ _telefones = value;
+ OnPropertyChanged("Telefones");
+ }
+ }
+
+ public new string Anotacoes
+ {
+ get
+ {
+ return _anotacoes;
+ }
+ set
+ {
+ _anotacoes = value;
+ OnPropertyChanged("Anotacoes");
+ }
+ }
+
+ public ObservableCollection<Prospectar> Prospeccoes
+ {
+ get
+ {
+ return _prospeccoes;
+ }
+ set
+ {
+ _prospeccoes = value;
+ OnPropertyChanged("Prospeccoes");
+ }
+ }
+
+ public List<RestricaoUsuario> Restricoes { get; set; }
+
+ public List<PermissaoUsuario> Permissoes { get; set; }
+
+ public ObservableCollection<ClientesAtivosInativos> Aniversariantes
+ {
+ get
+ {
+ return _aniversariantes;
+ }
+ set
+ {
+ _aniversariantes = value;
+ OnPropertyChanged("Aniversariantes");
+ }
+ }
+
+ public ObservableCollection<Sinistro> Sinistros
+ {
+ get
+ {
+ return _sinistros;
+ }
+ set
+ {
+ _sinistros = value;
+ OnPropertyChanged("Sinistros");
+ }
+ }
+
+ public Filtros Filtros { get; set; }
+
+ private Filtros _filtroRenovacao { get; set; }
+
+ private Filtros _filtroAniversariantes { get; set; }
+
+ private Filtros _filtroTarefas { get; set; }
+
+ private Filtros _filtroSinistros { get; set; }
+
+ public ObservableCollection<Renovacao> RenovacaoFiltrado
+ {
+ get
+ {
+ return _renovacaoFiltrado;
+ }
+ set
+ {
+ _renovacaoFiltrado = value;
+ OnPropertyChanged("RenovacaoFiltrado");
+ }
+ }
+
+ public ObservableCollection<Tarefa> Tarefas
+ {
+ get
+ {
+ return _tarefas;
+ }
+ set
+ {
+ _tarefas = value;
+ OnPropertyChanged("Tarefas");
+ }
+ }
+
+ private Filtros _filtroProspectar { get; set; }
+
+ public List<Ramo> Ramos
+ {
+ get
+ {
+ return _ramos;
+ }
+ set
+ {
+ _ramos = value;
+ OnPropertyChanged("Ramos");
+ }
+ }
+
+ public Ramo SelectedRamo
+ {
+ get
+ {
+ return _selectedRamo;
+ }
+ set
+ {
+ _selectedRamo = value;
+ OnPropertyChanged("SelectedRamo");
+ }
+ }
+
+ public List<string> Referencias
+ {
+ get
+ {
+ return _referencias;
+ }
+ set
+ {
+ _referencias = value;
+ OnPropertyChanged("Referencias");
+ }
+ }
+
+ public string Referencia
+ {
+ get
+ {
+ return _referencia;
+ }
+ set
+ {
+ _referencia = value;
+ OnPropertyChanged("Referencia");
+ }
+ }
+
+ public string LabelProspeccao
+ {
+ get
+ {
+ return _labelProspeccao;
+ }
+ set
+ {
+ _labelProspeccao = value;
+ OnPropertyChanged("LabelProspeccao");
+ }
+ }
+
+ public List<string> FiltroCliente
+ {
+ get
+ {
+ return _filtroCliente;
+ }
+ set
+ {
+ _filtroCliente = value;
+ OnPropertyChanged("FiltroCliente");
+ }
+ }
+
+ public string FiltroClientes
+ {
+ get
+ {
+ return _filtroClientes;
+ }
+ set
+ {
+ _filtroClientes = value;
+ OnPropertyChanged("FiltroClientes");
+ }
+ }
+
+ public DashboardViewModel()
+ {
+ _servico = new TarefaServico();
+ _apoliceServico = new ApoliceServico();
+ _clienteServico = new ClienteServico();
+ _tarefaServico = new TarefaServico();
+ _sinitrosServico = new SinistroServico();
+ }
+
+ public async Task BuscarRestricoes()
+ {
+ Restricoes = await ServicoRestriUsuario.BuscarRestricoes(((DomainBase)Recursos.Usuario).Id);
+ Permissoes = new List<PermissaoUsuario>();
+ PermissaoUsuario val = await ServicoPermissUsuario.VerificarPermissao(Recursos.Usuario, (TipoTela)38);
+ if (val != null)
+ {
+ Permissoes.Add(val);
+ }
+ }
+
+ public async Task CarregarAniversariantes(bool force = false)
+ {
+ AniversariantesEnabled = false;
+ if (!force && CompararFiltros(_filtroAniversariantes))
+ {
+ AniversariantesEnabled = true;
+ return;
+ }
+ _filtroAniversariantes = Filtros;
+ List<VendedorUsuario> list = await VerificaVinculoVendedor(Recursos.Usuario);
+ List<long> vinculoVendedores = new List<long>();
+ list.ForEach(delegate(VendedorUsuario v)
+ {
+ vinculoVendedores.Add(((DomainBase)v.Vendedor).Id);
+ });
+ List<ClientesAtivosInativos> list2 = ((list.Count <= 0) ? (await _clienteServico.BuscarAniversariantes(Filtros)) : (await _clienteServico.BuscarAniversariantesVinculo(Filtros, list)));
+ List<ClientesAtivosInativos> list3 = list2;
+ QuantidadeAniversariantes = list3.Count.ToString();
+ if (list3.Count == 0)
+ {
+ Aniversariantes = null;
+ AniversariantesEnabled = true;
+ }
+ else
+ {
+ Aniversariantes = new ObservableCollection<ClientesAtivosInativos>(list3);
+ AniversariantesEnabled = true;
+ }
+ }
+
+ public async Task CarregarSinistros(bool force = false)
+ {
+ SinistrosEnabled = false;
+ if (!force && CompararFiltros(_filtroSinistros))
+ {
+ SinistrosEnabled = true;
+ return;
+ }
+ _filtroSinistros = Filtros;
+ List<Sinistro> list = await _sinitrosServico.BuscarSinistroPendente(Filtros);
+ QuantidadeSinistro = list.Count.ToString();
+ if (list.Count == 0)
+ {
+ Sinistros = null;
+ SinistrosEnabled = true;
+ }
+ else
+ {
+ Sinistros = new ObservableCollection<Sinistro>(list);
+ SinistrosEnabled = true;
+ }
+ }
+
+ public async Task CarregarSinistros(DateTime inicio, DateTime fim)
+ {
+ _filtroSinistros.Fim = fim;
+ _filtroSinistros.Inicio = inicio;
+ List<Sinistro> list = await _sinitrosServico.BuscarSinistroPendente(_filtroSinistros);
+ QuantidadeSinistro = list.Count.ToString();
+ Sinistros = new ObservableCollection<Sinistro>(list);
+ }
+
+ public async Task CarregarFiltros()
+ {
+ List<long> vendedores = new List<long>();
+ List<VendedorUsuario> list = await VerificaVinculoVendedor(Recursos.Usuario);
+ if (list.Count > 0)
+ {
+ list.ForEach(delegate(VendedorUsuario x)
+ {
+ vendedores.Add(((DomainBase)x.Vendedor).Id);
+ });
+ }
+ DateTime today = DateTime.Today;
+ DateTime fim = DateTime.Today;
+ string intervaloSelecionado = IntervaloSelecionado;
+ if (!(intervaloSelecionado == "PRÓXIMOS 3 DIAS"))
+ {
+ if (intervaloSelecionado == "PRÓXIMOS 7 DIAS")
+ {
+ fim = today.AddDays(7.0);
+ }
+ }
+ else
+ {
+ fim = today.AddDays(3.0);
+ }
+ Filtros = new Filtros
+ {
+ Inicio = today,
+ Fim = fim,
+ Vendedores = vendedores,
+ IdEmpresa = ((Recursos.Usuario.IdEmpresa > 1) ? Recursos.Usuario.IdEmpresa : 0),
+ Status = new List<long> { 1L, 2L }
+ };
+ }
+
+ private bool CompararFiltros(Filtros comparacao)
+ {
+ if (comparacao == null)
+ {
+ return false;
+ }
+ if (Filtros == null)
+ {
+ return false;
+ }
+ if (comparacao.Inicio != Filtros.Inicio)
+ {
+ return false;
+ }
+ if (comparacao.Fim != Filtros.Fim)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public async Task CarregarRenovacoes(bool force = false)
+ {
+ RenovacoesEnabled = false;
+ if (!force && CompararFiltros(_filtroRenovacao))
+ {
+ RenovacoesEnabled = true;
+ return;
+ }
+ _filtroRenovacao = Filtros;
+ List<Renovacao> analiticoRenovacao = (await _apoliceServico.BuscarApolicesVigenciaFinal(Filtros)).Where((Documento x) => x.Tipo != 3).Select((Func<Documento, Renovacao>)delegate(Documento x)
+ {
+ //IL_000d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0012: Unknown result type (might be due to invalid IL or missing references)
+ //IL_003d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0057: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0068: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0079: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0094: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b1: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00c2: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ed: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0111: Unknown result type (might be due to invalid IL or missing references)
+ //IL_015f: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0166: Unknown result type (might be due to invalid IL or missing references)
+ //IL_016c: Invalid comparison between Unknown and I4
+ //IL_0174: Unknown result type (might be due to invalid IL or missing references)
+ //IL_017a: Invalid comparison between Unknown and I4
+ //IL_01a6: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0182: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01c3: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01e9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_024e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_025f: Unknown result type (might be due to invalid IL or missing references)
+ //IL_026b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_027c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_02df: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0313: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0332: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0343: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0369: Unknown result type (might be due to invalid IL or missing references)
+ //IL_037f: Unknown result type (might be due to invalid IL or missing references)
+ //IL_03a7: Unknown result type (might be due to invalid IL or missing references)
+ //IL_03dc: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0402: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0413: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0424: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0435: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0450: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0462: Expected O, but got Unknown
+ Renovacao val2 = new Renovacao();
+ Cliente cliente = x.Controle.Cliente;
+ val2.Cliente = ((cliente != null) ? cliente.Nome : null) ?? "";
+ val2.Apolice = x.Apolice ?? "";
+ val2.PremioLiquido = x.PremioLiquido;
+ val2.PremioTotal = x.PremioTotal;
+ Negocio? negocio = x.Negocio;
+ val2.Negocio = (negocio.HasValue ? ValidationHelper.GetDescription((Enum)(object)negocio.GetValueOrDefault()) : null) ?? "";
+ val2.VigenciaFinal = x.Vigencia2;
+ Produto produto2 = x.Controle.Produto;
+ val2.Produto = ((produto2 != null) ? produto2.Nome : null) ?? "";
+ val2.Ramo = x.Controle.Ramo.Nome ?? "";
+ val2.Seguradora = ((!string.IsNullOrWhiteSpace(x.Controle.Seguradora.NomeSocial)) ? x.Controle.Seguradora.NomeSocial : x.Controle.Seguradora.Nome);
+ val2.Status = (((int)x.Situacao == 1 || (int)x.Situacao == 2) ? "NÃO TRABALHADO" : (ValidationHelper.GetDescription((Enum)(object)x.Situacao) ?? ""));
+ Vendedor vendedorPrincipal = x.VendedorPrincipal;
+ val2.Vendedor = ((vendedorPrincipal != null) ? vendedorPrincipal.Nome : null);
+ Estipulante estipulante = x.Estipulante1;
+ val2.Estipulante = ((estipulante != null) ? estipulante.Nome : null) ?? "";
+ val2.TodosVendedores = ((x.Vendedores == null || x.Vendedores.Count == 0) ? "" : string.Join("; ", x.Vendedores.Select((Vendedor v) => v.Nome)));
+ val2.Tipo = x.Tipo;
+ val2.Documento = x;
+ val2.Comissao = x.Comissao;
+ val2.Item = ((x.ItensAtivo == null) ? "" : ((x.ItensAtivo.Count > 1) ? "APÓLICE COLETIVA" : ((x.ItensAtivo.Count == 1) ? x.ItensAtivo.First().Descricao : "")));
+ val2.TipoDocumento = ((x.Tipo == 0) ? "APÓLICE" : ((x.Tipo == 1) ? "ENDOSSO" : ""));
+ val2.Sinistro = (x.Sinistro ? "SIM" : "NÃO");
+ val2.DataControle = x.DataControle;
+ Status status2 = x.Status;
+ val2.StatusApolice = ((status2 != null) ? status2.Nome : null) ?? "";
+ val2.IdEmpresa = x.Controle.IdEmpresa;
+ Empresa? obj = ((IEnumerable<Empresa>)Recursos.Empresas).FirstOrDefault((Func<Empresa, bool>)((Empresa e) => ((DomainBase)e).Id == x.Controle.IdEmpresa));
+ val2.Empresa = ((obj != null) ? obj.Nome : null);
+ val2.QtdSinistro = x.ItensAtivo.Sum((Item s) => s.Sinistros.Count);
+ Banco banco = x.Banco;
+ val2.Banco = ((banco != null) ? banco.Nome : null) ?? "";
+ val2.Conta = x.Conta;
+ val2.Agencia = x.Agencia;
+ val2.Pasta = x.Pasta;
+ val2.PastaCliente = x.Controle.Cliente.Pasta;
+ val2.Calculos = x.Calculos;
+ return val2;
+ }).ToList();
+ List<Renovacao> collection = (await new ProspeccaoServico().BuscarProspeccoes(Filtros)).Where((Prospeccao x) => x.Renovacao).Select(delegate(Prospeccao x)
+ {
+ //IL_0000: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0006: Expected O, but got Unknown
+ //IL_0048: Unknown result type (might be due to invalid IL or missing references)
+ Renovacao val = new Renovacao();
+ val.Cliente = x.Nome ?? "";
+ val.Apolice = "PROSPECÇÃO";
+ val.VigenciaFinal = x.VigenciaFinal;
+ StatusProspeccao? status = x.Status;
+ val.Status = (status.HasValue ? ValidationHelper.GetDescription((Enum)(object)status.GetValueOrDefault()) : null) ?? "";
+ Vendedor vendedor = x.Vendedor;
+ val.Vendedor = ((vendedor != null) ? vendedor.Nome : null);
+ Vendedor vendedor2 = x.Vendedor;
+ val.TodosVendedores = ((vendedor2 != null) ? vendedor2.Nome : null);
+ val.Telefone = x.Prefixo1 + " " + x.Telefone1 + " | " + x.Prefixo2 + " " + x.Telefone2;
+ val.Tipo = 3;
+ val.TipoDocumento = "PROSPECÇÃO";
+ val.Item = x.Item;
+ Produto produto = x.Produto;
+ val.Produto = ((produto != null) ? produto.Nome : null);
+ val.Prospeccao = x;
+ return val;
+ }).ToList();
+ analiticoRenovacao.AddRange(collection);
+ QuantidadeRenovacoes = analiticoRenovacao.Count.ToString();
+ if (analiticoRenovacao.Count == 0)
+ {
+ RenovacaoFiltrado = null;
+ RenovacoesEnabled = true;
+ return;
+ }
+ RenovacaoFiltrado = new ObservableCollection<Renovacao>(analiticoRenovacao.OrderBy((Renovacao x) => x.VigenciaFinal).ToList());
+ RenovacoesEnabled = true;
+ }
+
+ public async Task CarregarNotas()
+ {
+ NotasEnabled = false;
+ Notas = new ObservableCollection<Tarefa>(await _servico.BuscarNotas(((DomainBase)Recursos.Usuario).Id));
+ NotasEnabled = true;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar(Tarefa destino)
+ {
+ destino.AgendamentoRetroativo = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 45);
+ List<KeyValuePair<string, string>> list = destino.Validate();
+ if (list.Count > 0)
+ {
+ return list;
+ }
+ await _servico.Salvar(destino);
+ if (!_servico.Sucesso)
+ {
+ return null;
+ }
+ if (Publica)
+ {
+ long id = ((DomainBase)destino.Usuario).Id;
+ List<Usuario> usuarios = Recursos.Usuarios;
+ List<Task> list2 = new List<Task>();
+ foreach (Usuario item in usuarios)
+ {
+ if (id != ((DomainBase)item).Id)
+ {
+ Tarefa val = (Tarefa)((DomainBase)destino).Clone();
+ ((DomainBase)val).Id = 0L;
+ val.Usuario = item;
+ list2.Add(_servico.Salvar(val));
+ }
+ }
+ await Task.WhenAll(list2);
+ }
+ await CarregarNotas();
+ return null;
+ }
+
+ public async Task<Tarefa> SalvarNota(Tarefa nota)
+ {
+ return await _servico.Salvar(nota);
+ }
+
+ public async Task ExcluirNota(Tarefa nota)
+ {
+ await _servico.Excluir(((DomainBase)nota).Id);
+ }
+
+ public async Task CarregarTarefas(bool force = false)
+ {
+ TarefasEnabled = false;
+ if (!force && CompararFiltros(_filtroTarefas))
+ {
+ TarefasEnabled = true;
+ return;
+ }
+ _filtroTarefas = Filtros;
+ List<Tarefa> list = await _tarefaServico.BuscarTarefas(((DomainBase)Recursos.Usuario).Id, _filtroTarefas.Inicio, _filtroTarefas.Fim, false);
+ QuantidadeTarefas = list.Count.ToString();
+ if (list.Count == 0)
+ {
+ Tarefas = null;
+ TarefasEnabled = true;
+ return;
+ }
+ Tarefas = new ObservableCollection<Tarefa>(from x in list
+ where (int)x.Entidade != 1
+ orderby x.Agendamento
+ select x);
+ TarefasEnabled = true;
+ }
+
+ public async Task CarregarProspect(DateTime inicio, DateTime fim)
+ {
+ ProspeccoesEnabled = false;
+ Filtros val = new Filtros
+ {
+ Inicio = inicio,
+ Fim = fim,
+ Ramos = new List<long> { ((DomainBase)SelectedRamo).Id },
+ Vendedores = Filtros.Vendedores,
+ Referencia = Referencia,
+ FiltrarDocumento = FiltroClientes
+ };
+ LabelProspeccao = "CLIENTES QUE NÃO POSSUEM SEGUROS DO RAMO " + SelectedRamo.Nome + " ";
+ string referencia = Referencia;
+ if (!(referencia == "VIGÊNCIA INICIAL"))
+ {
+ if (!(referencia == "VIGÊNCIA FINAL"))
+ {
+ LabelProspeccao += "E QUE ESTÃO COM A ULTIMA PARCELA VENCENDO NO PERÍODO";
+ }
+ else
+ {
+ LabelProspeccao += "E QUE ESTÃO COM UMA APÓLICE VENCENDO NO PERÍODO";
+ }
+ }
+ else
+ {
+ LabelProspeccao += "E QUE ESTÃO COM UMA APÓLICE INICIANDO NO PERÍODO";
+ }
+ if (_filtroProspectar != null && _filtroProspectar.Inicio == val.Inicio && _filtroProspectar.Fim == val.Fim && _filtroProspectar.Ramos == val.Ramos && _filtroProspectar.Referencia == val.Referencia)
+ {
+ ProspeccoesEnabled = true;
+ return;
+ }
+ _filtroProspectar = val;
+ List<Prospectar> list = await _clienteServico.BuscarProspect(val);
+ QuantidadeProspeccao = list.Count.ToString();
+ if (list.Count == 0)
+ {
+ LabelProspeccao = "NÃO HÁ CLIENTES PARA PROSPECTAR";
+ }
+ Prospeccoes = new ObservableCollection<Prospectar>(list);
+ ProspeccoesEnabled = true;
+ }
+
+ public void LimparProspeccao()
+ {
+ }
+
+ public void CarregarRamos()
+ {
+ List<long> ids = new List<long> { 1L, 2L, 6L, 7L };
+ Ramos = Recursos.Ramos.Where((Ramo x) => ids.Contains(((DomainBase)x).Id)).ToList();
+ SelectedRamo = Ramos.Find((Ramo x) => ((DomainBase)x).Id == 1);
+ }
+
+ public async Task<bool> GerarCsv()
+ {
+ string fileName = Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".csv";
+ File.WriteAllText(fileName, (await Funcoes.GerarCsv(Prospeccoes.ToList(), new List<string> { "Nome", "Documento", "Telefone" })).ToString(), Encoding.UTF8);
+ Process.Start(fileName);
+ return true;
+ }
+}